Formal Program Specification: Logic, Sets, Relations, Functions, and Predicate Calculus - , Study notes of Engineering

A formal program specification prepared by dr. Stephen m. Thebaut from the university of florida for a lecture on software testing and verification. It covers the basics of propositions, propositional logic, sets, relations, functions, and predicate calculus. Explanations, examples, and exercises to help students understand these concepts.

Typology: Study notes

Pre 2010

Uploaded on 09/17/2009

koofers-user-cep
koofers-user-cep 🇺🇸

4

(2)

10 documents

1 / 36

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Formal Program Specification
Prepared by
Stephen M. Thebaut, Ph.D.
University of Florida
Software Testing and Verification
Lecture 16
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Formal Program Specification: Logic, Sets, Relations, Functions, and Predicate Calculus - and more Study notes Engineering in PDF only on Docsity!

Formal Program Specification

Prepared by Stephen M. Thebaut, Ph.D.

University of Florida

Software Testing and Verification

Lecture 16

Overview •^

Review of Basics –^ Propositions, propositional logic,predicates, predicate calculus

-^ Sets, Relations, and Functions -^ Specification via pre- and post-conditions -^ Specifications via functions

Propositions and Propositional Logic(cont’d) • Propositional Logic

is a formal language

that allows us to reason aboutpropositions. The alphabet of thislanguage is:

{P, Q, R, …
, V,

where P, Q, R, … are propositions, andthe other symbols, usually referred to as^ connectives

, provide ways in which

compound propositions can be built fromsimpler ones.

Truth Tables • Truth tables

provide a concise way of

giving the meaning of compound formsin a tabular form.Example: construct a truth table to showall possible interpretation for thefollowing sentences:

A V B, A
⇒^

B, and A

⇔^
B

Equivalence^ •^ Two sentences are said to be

equivalent

if and only if their truth values are thesame under every interpretation. • If A is equivalent to B, we write

A^ ≡
B.

Exercise: Use a truth table to show:

(P^ ⇒
Q)
≡^ (Q V
¬P)

Equivalence (cont’d) •^ Many users of logic slip into the habit ofusing

⇔^

and

≡^ interchangeably.

-^ However,

A⇔

B^ is written down in the full

knowledge that it may denote either true

or^

false

in some interpretation,

whereas

A≡

B is an expression of fact

(i.e., the writer thinks it is true).

Predicates (cont’d) •^ Note that a predicate itself has

no

truth

value; it expresses a property or relationusing

variables.

Predicates (cont’d) •^ There are TWO ways in which predicatescan give rise to propositions:

-^ As illustrated above, their freevariables may be

instantiated

with the

names of specific objects, and – They may be

quantified

Quantification introduces twoadditional symbols:

∀^ and

Predicates (cont’d) •^ For a predicate with two free variables,quantifying over one of them yieldsanother predicate with one freevariable, as in

∀x • Q(x,y)

or

∃x • Q(x,y)

Predicates (cont’d)^ •^ Where appropriate, a

domain of interest

may be specified which contains the objectsfor which the quantifier applies. Forexample,

∀i∈

{1,2,…,N} • A[i]>

represents the predicate “the first Nelements of array A are all greater than 0.”

Predicate Calculus (cont’d) •^ A

rule of inference

is expressed in the

form:

A, A^1
, …, A 2

n C

and is interpreted to mean

(A^1
A

2

…^

A)n

⇒^
C

Predicate Calculus (cont’d) •^ Examples of deductive rules:

A^
B A
A A V B
A A
A, A
⇒^ B B

Sets and Relations •^ A

set

is any well-defined collection of objects, called members or elements. • The relation of

membership

between a

member, m, and a set, S, is written:

m^ ∈

S

-^ If m is not a member of S, we write:

m^ ∉

S

Sets and Relations (cont’d) •^ A

relation

, r, is a set whose members (if

any) are all ordered pairs. • The set composed of the first member ofeach pair is called the

domain

of r and is

denoted D(r). Members of D(r) arecalled

arguments

of r.

-^ The set composed of the secondmember of each pair is called the rangeof r and is denoted R(r). Members ofR(r) are called

values

of r.