Predicate Logic for Software Engineering

advertisement
Predicate Logic for Software Engineering
David Lorge Parnas, Senior Member, IEEE
Tenghui Zhu
Predicate Logic for software Engineers
Why logic in software engineering?
•Engineers need mathematical tools.
•Theoretical, yet quantitative study of software.
Problems with existing logic
•Lacks precise meaning for logical expression. (* means “maybe”, besides true and
false)
•Complexity of expressions.
•Assumption of total functions.
Fig.1
Parnas Proposes….
•Use partial functions.
•Make use of bounded quantification optional.
IV. Basic Concepts
Basics
•Predicate – A predicate is a feature which we can use to make a statement about
“Peter is tall”
something.
•The property that an animal is a dog can be expressed by the predicate:
dog(x)
This predicate holds for all animals x which are dogs. For other animals, the
predicate is false
Propositional Logic
•A proposition is a language construct which can be assigned a truth value
•More complex propositions can be formed by applying the logical operators (¬, ,
, etc..)
•Propositional logic formula
–Eg.
¬((a  b)  c)
Predicate Logic
•Predicate logic
is a more powerful formalism which is obtained by extending
propositional logic with
•“Predicates”
which describe properties or relations of objects in a certain
domain ;
•“variables” ranging over arbitrary domains;
•the possibility to quantify over “variables”.
Quantifiers
•We distinguish two quantifiers:
–universal quantifier: 
–existential quantifier: 
•Example:
–There exists an integer x divisible by 5.
x | divisible_by(x,5)
–All integers y are divisible by 1.
y | divisible_by(y,1)
Tuples
•U = {true, false}
•Simple n-tuple
–Ordered list of n members of U
Eg. <true, false, true, true>
•n-tuple
–Ordered list of n simple tuples
Eg. <<true, false>, true, <false, true>>
Relations and Functions
•Difference?
–Function can’t be one-to-many.
•Partial vs. Total Functions
–Partial functions not defined for all values in domain
e.g. Division over integer domain not defined for 0
V. The syntax of logical expression
Predicates Revisited
•Predicate – a function whose range contains no member other than true and
false
•Characteristic Predicate (R)
–X=set of simple tuples
[Goal Set]
–Sk=set of all simple k-tuples
–S=S1S2 …….. Su , u=length of largest tuple in X
–R is a predicate whose domain is S and for every b  X the value of R is true
–R (tuple) -> true/false
Primitive Expressions
•Primitive Expression is a string of the form R(V)
–R is a characteristic predicate
–V is a list of comma separated terms (called arguments)
e.g. divisible_by(x, 5)
•All primitive expressions are predicate expressions.
•If P, Q: predicate expressions, x: variable, then following are also predicate
expressions:
–(x , P)
–(P)  (Q)
–¬(P)
– (P)
– (P)  (Q)
•There are no other predicate expressions.
–What about (x , P)
!!!
VI The meaning of logical expression.
The idea is how to evaluate such function and expressions. Basically, it is totally the
same as what we have learned before.
VII Examples
Use in Documentation
See Fig 3.
See Fig 6.
Note:
1. When out of domain, f(x)==f(x) is always false.
2. Only one column will be considered.
VIII. Conclusion
•Keep it Simple
–Was the use of this type of logic useful?
–What about more complicated programs?
–Was it more precise?
–Was it easier to understand?
Download