Professional Documents
Culture Documents
04 Proving Fol
04 Proving Fol
04 Proving Fol
Bernhard Beckert
Based on a lecture by Wolfgang Ahrendt and Reiner H ahnle at Chalmers University, G oteborg
B. Beckert
1 / 39
Syntax
Formula/Program
Semantics valid
Calculus Derivable
B. Beckert
2 / 39
Syntax
Formula/Program
x
Completeness
Semantics valid
Calculus Derivable
B. Beckert
2 / 39
Syntax
Formula/Program
x
Completeness
Semantics valid
Soundness
Calculus Derivable
B. Beckert
2 / 39
B. Beckert
3 / 39
Consider antecedent/succedent as sets of formulas, may be empty Schema Variables , , . . . match formulas, , , . . . match sets of formulas Characterize innitely many sequents with a single schematic sequent = , &
Matches any sequent with occurrence of conjunction in succedent Call & main formula and , side formulas of sequent Any sequent of the form , = , is logically valid: axiom
Formal Specication and Verication: Proving B. Beckert 3 / 39
RuleName
1 = 1
=
Conclusion
r = r
B. Beckert
4 / 39
RuleName
1 = 1
=
Conclusion
r = r
Example
andRight
= ,
= ,
= & ,
B. Beckert
4 / 39
RuleName
1 = 1
=
Conclusion
r = r
Example
andRight
= ,
= ,
B. Beckert
4 / 39
RuleName
1 = 1
=
Conclusion
r = r
Example
andRight
= ,
= ,
Complete rule (desirable): |= ( = ) > (1 = 1 & & r = r ) Admissible to have no premisses (i conclusion is valid, eg axiom)
Formal Specication and Verication: Proving B. Beckert
4 / 39
B. Beckert
5 / 39
and
= & ,
B. Beckert
5 / 39
and
= & , = , , = | ,
or
, | =
B. Beckert
5 / 39
and
= & , = , , = | , , = , = > ,
or
, | = = , , =
imp
, >=
B. Beckert
5 / 39
and
or
, | = = , , =
imp
close
, >= , = ,
true
, false =
B. Beckert
5 / 39
\predicates {
p; q; }
\problem {
(p & (p -> q)) -> q }
Demo
Examples/lect09/prop.key
Formal Specication and Verication: Proving B. Beckert 7 / 39
Proving Validity of First-Order Formulas Proving a universally quantied formula T x ; is true in any model M How is such a claim proven in mathematics?
B. Beckert
8 / 39
Proving Validity of First-Order Formulas Proving a universally quantied formula T x ; is true in any model M How is such a claim proven in mathematics? All even numbers are divisible by 2 int x ; (even(x ) > divByTwo(x ))
B. Beckert
8 / 39
Proving Validity of First-Order Formulas Proving a universally quantied formula T x ; is true in any model M How is such a claim proven in mathematics? All even numbers are divisible by 2 int x ; (even(x ) > divByTwo(x )) Let c be an arbitrary number Declare unused constant int c
B. Beckert
8 / 39
Proving Validity of First-Order Formulas Proving a universally quantied formula T x ; is true in any model M How is such a claim proven in mathematics? All even numbers are divisible by 2 int x ; (even(x ) > divByTwo(x )) Let c be an arbitrary number The even number c is divisible by 2 Declare unused constant int c even(c ) > divByTwo(c )
B. Beckert
8 / 39
Proving Validity of First-Order Formulas Proving a universally quantied formula T x ; is true in any model M How is such a claim proven in mathematics? All even numbers are divisible by 2 int x ; (even(x ) > divByTwo(x )) Let c be an arbitrary number The even number c is divisible by 2 Sequent rule -right
forallRight
= [x /c ] , = T x ; ,
Proving Validity of First-Order Formulas Contd Proving an existentially quantied formula T x ; is true in any model M How is such a claim proven in mathematics?
B. Beckert
9 / 39
Proving Validity of First-Order Formulas Contd Proving an existentially quantied formula T x ; is true in any model M How is such a claim proven in mathematics? There is at least one prime number int x ; prime(x )
B. Beckert
9 / 39
Proving Validity of First-Order Formulas Contd Proving an existentially quantied formula T x ; is true in any model M How is such a claim proven in mathematics? There is at least one prime number int x ; prime(x ) Provide any witness, say, 7 Use variable-free term int 7
B. Beckert
9 / 39
Proving Validity of First-Order Formulas Contd Proving an existentially quantied formula T x ; is true in any model M How is such a claim proven in mathematics? There is at least one prime number int x ; prime(x ) Provide any witness, say, 7 7 is a prime number Use variable-free term int 7 prime(7)
B. Beckert
9 / 39
Proving Validity of First-Order Formulas Contd Proving an existentially quantied formula T x ; is true in any model M How is such a claim proven in mathematics? There is at least one prime number int x ; prime(x ) Provide any witness, say, 7 7 is a prime number Sequent rule -right
existsRight
= [x /t ] , T x ; , = T x ; ,
t any variable-free term with declared type T T Proof might not work with t ! Need to keep premise to try again
Formal Specication and Verication: Proving B. Beckert 9 / 39
Proving Validity of First-Order Formulas Contd Using a universally quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof?
B. Beckert
10 / 39
Proving Validity of First-Order Formulas Contd Using a universally quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? We know that all primes are odd int x ; (prime(x ) > odd(x ))
B. Beckert
10 / 39
Proving Validity of First-Order Formulas Contd Using a universally quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? We know that all primes are odd int x ; (prime(x ) > odd(x )) In particular, this holds for 17 Use variable-free term int 17
B. Beckert
10 / 39
Proving Validity of First-Order Formulas Contd Using a universally quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? We know that all primes are odd int x ; (prime(x ) > odd(x )) In particular, this holds for 17 We know: if 17 is prime it is odd Use variable-free term int 17 prime(17) > odd(17)
B. Beckert
10 / 39
Proving Validity of First-Order Formulas Contd Using a universally quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? We know that all primes are odd int x ; (prime(x ) > odd(x )) In particular, this holds for 17 We know: if 17 is prime it is odd Sequent rule -left
forallLeft
, T x ; , [x /t ] = , T x ; =
t any variable-free term with declared type T T We might need other instances besides t ! Keep premise
Formal Specication and Verication: Proving B. Beckert 10 / 39
Proving Validity of First-Order Formulas Contd Using an existentially quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof?
B. Beckert
11 / 39
Proving Validity of First-Order Formulas Contd Using an existentially quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? Every set s can be well-ordered Set x ; (sameElem(s , x ) & wellOrder(x ))
B. Beckert
11 / 39
Proving Validity of First-Order Formulas Contd Using an existentially quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? Every set s can be well-ordered Set x ; (sameElem(s , x ) & wellOrder(x )) Let s be a well-order of s s new constant of type OrdSet
B. Beckert
11 / 39
Proving Validity of First-Order Formulas Contd Using an existentially quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? Every set s can be well-ordered Set x ; (sameElem(s , x ) & wellOrder(x )) Let s be a well-order of s We know: s is well-order of s s new constant of type OrdSet sameElem(s , s ) & wellOrder(s )
B. Beckert
11 / 39
Proving Validity of First-Order Formulas Contd Using an existentially quantied formula T x ; is true in any model M How is such a fact used in a mathematical proof? Every set s can be well-ordered Set x ; (sameElem(s , x ) & wellOrder(x )) Let s be a well-order of s We know: s is well-order of s Sequent rule -left
existsLeft
, [x /c ] = , T x ; =
B. Beckert
11 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations)
x ; y ; p (x , y ) = y ; x ; p (x , y )
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations)
y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
for x
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations)
y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
for y
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations)
p (c , d ), y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
for y , choose d
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations)
p (c , d ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations) p (c , d ) = p (c , d ), x ; p (x , y ) p (c , d ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
for x , choose c
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations) p (c , d ) = p (c , d ) p (c , d ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations) p (c , d ) = p (c , d ) p (c , d ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
Close
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Example (A simple theorem about binary relations) p (c , d ) = p (c , d ) p (c , d ) = x ; p (x , d ) y ; p (c , y ) = x ; p (x , d ) y ; p (c , y ) = y ; x ; p (x , y ) x ; y ; p (x , y ) = y ; x ; p (x , y )
Demo
Examples/lect09/relSimple.key
B. Beckert
12 / 39
Proving Validity of First-Order Formulas Contd Using an equation between terms . t = t is true in any model M How is such a fact used in a mathematical proof?
B. Beckert
13 / 39
Proving Validity of First-Order Formulas Contd Using an equation between terms . t = t is true in any model M How is such a fact used in a mathematical proof? . . . Use x = y 1 to simplify x +1/y x = y 1 = 1 = x +1/y
B. Beckert
13 / 39
Proving Validity of First-Order Formulas Contd Using an equation between terms . t = t is true in any model M How is such a fact used in a mathematical proof? . . . Use x = y 1 to simplify x +1/y x = y 1 = 1 = x +1/y Replace x in conclusion with right-hand side of equation
B. Beckert
13 / 39
Proving Validity of First-Order Formulas Contd Using an equation between terms . t = t is true in any model M How is such a fact used in a mathematical proof? . . . Use x = y 1 to simplify x +1/y x = y 1 = 1 = x +1/y Replace x in conclusion with right-hand side of equation . . We know: x +1/y equal to y 1+1/y x = y 1 = 1 = y 1+1/y
B. Beckert
13 / 39
Proving Validity of First-Order Formulas Contd Using an equation between terms . t = t is true in any model M How is such a fact used in a mathematical proof? . . . Use x = y 1 to simplify x +1/y x = y 1 = 1 = x +1/y Replace x in conclusion with right-hand side of equation . . We know: x +1/y equal to y 1+1/y x = y 1 = 1 = y 1+1/y . Sequent rule =-left
applyEq
. , t = t , [t /t ] = [t /t ] , . , t = t , = ,
Always replace left- with right-hand side (use eqSymm if necessary) Replacing term must be type-compatible wity replaced term t any variable-free term with declared type T , t with type T T
Formal Specication and Verication: Proving B. Beckert 13 / 39
Proving Validity of First-Order Formulas Contd Closing a subgoal in a proof We derived a sequent that is obviously valid
close
, = ,
true
= true,
false
, false =
. = t = t,
B. Beckert
14 / 39
B. Beckert
15 / 39
Sequent Calculus for FOL at One Glance left side, antecedent right side, succedent . = , T x ; , [x /t ] = , T x ; = , [x /c ] = , T x ; = . , t = t , [t /t ] = [t /t ] , . , , t = t , = = [x /c ] , = T x ; , = [x /t ] , T x ; , = T x ; , . = t = t,
[t /t ] is result of replacing each occurrence of t in with t t any variable-free term with declared type T t any variable-free term with declared type T T c new constant of type T (occurs not on current proof branch) Equations can be reversed by commutativity
Formal Specication and Verication: Proving B. Beckert 16 / 39
\problem { // Formula to be proven valid \forall Person son; \forall Person father;
(parent(father,son) -> age(father) > age(son)) }
B. Beckert
18 / 39
B. Beckert
20 / 39
Rules for Type Casts and Type Predicates Type predicate formulas t T true i dynamic type (valM (t )) is subtype of T Type cast terms (T )t yields valM (t ) (identity) if cast succeeds, arb. element otherwise Typical typing rule The run-time type of a term is always compatible to its declared type
typeStatic
, t T = =
T declared type of t
Ensures type-safety of typed rst-order logic KeY rst-order strategy applies suitable typing rules automatically All rules in KeY-Book Chapter 2, p59 (wont be asked in exam)
Formal Specication and Verication: Proving B. Beckert 21 / 39
Schuberts Steamroller
Wolves, foxes, birds, caterpillars, and snails are animals, and there are some of each of them. Also, there are some grains, and grains are plants. Every animal either likes to eat all plants or all animals much smaller than itself that like to eat some plants. Caterpillars and snails are much smaller than birds, which are much smaller than foxes, which in turn are much smaller than wolves. Wolves do not like to eat foxes or grains, while birds like to eat caterpillars but not snails. Caterpillars and snails like to eat some plants. Therefore, there is an animal that likes to eat a grain-eating animal.
B. Beckert
22 / 39
Grain
Bird
Fox
Wolf
Snail
Caterpillar
\sorts { Animal; Wolf \extends Animal; Bird \extends Animal; Fox \extends Animal; Caterpillar \extends Animal; Snail \extends Animal;
Plant; Grain \extends Plant; }
Formal Specication and Verication: Proving B. Beckert 24 / 39
\predicates {
eats(Animal,any); smaller(any,any); }
B. Beckert
26 / 39
Caterpillar c; \forall Bird b; smaller(c,b)) & Snail s; \forall Bird b; smaller(s,b)) & Bird b; \forall Fox f; smaller(b,f)) & Fox f; \forall Wolf w; smaller(f,w))
B. Beckert 28 / 39
Bird b; \forall Caterpillar c; eats(b,c)) & Caterpillar c; \exists Plant p; eats(c,p)) & Snail s; \exists Plant p; eats(s,p)) & Wolf w; \forall Fox f; !eats(w,f)) & Wolf w; \forall Grain g; !eats(w,g)) & Bird b; \forall Snail s; !eats(b,s))
B. Beckert 30 / 39
(\forall Animal a; ((\forall Plant p; eats(a,p)) | (\forall Animal as; ((smaller(as,a) & \exists Plant p; eats(as,p)) -> eats(a,as)))))
Formal Specication and Verication: Proving B. Beckert 32 / 39
( ... ) -> (\exists Animal a; \exists Animal ga; ((\exists Grain g; eats(ga,g)) & eats(a,ga)))
B. Beckert
34 / 39
( ... ) -> (\exists Animal a; \exists Animal ga; ((\exists Grain g; eats(ga,g)) & eats(a,ga)))
Demo
Examples/lect09/sr.key
Formal Specication and Verication: Proving B. Beckert 34 / 39
B. Beckert
35 / 39
B. Beckert
35 / 39
Failed Proofs
Reasons for failed proofs The automatic proof strategy of KeY is too weak (did you check FOL?) When trying manually:
Did you use the right instantiations? Perhaps you need to apply an equality?
Your goal is not a valid formula! An unsuccessful proof can give important clues why!
B. Beckert
36 / 39
Theorem Let the formula G be the goal of a sequent proof. Assume there is an open leaf L = = in a sequent proof such that: 1. L is not closed 2. There is a rst-order model M that:
M |= for all M |= ! for all
Then M |= ! G , i.e., M is a counter example for G . NOTE: This only holds as long as no hiding or weaking rules are used that destroy proof conuence (e.g., the invariant rule for loops).
B. Beckert
37 / 39
How to proceed 1. Java DL Proof Search Strategy with Quantier Treatment unrestricted 2. Run prover, inspect open Goals L 3. If necessary, instantiate -left, -right by hand 4. Find model that makes Ls antecedent true and succedent false 5. Go back to G and nd out was was wrong Often, the patch is to add a L or a ! L to the premise of G
B. Beckert
38 / 39
How to proceed 1. Java DL Proof Search Strategy with Quantier Treatment unrestricted 2. Run prover, inspect open Goals L 3. If necessary, instantiate -left, -right by hand 4. Find model that makes Ls antecedent true and succedent false 5. Go back to G and nd out was was wrong Often, the patch is to add a L or a ! L to the premise of G
Demo
Examples/lect09/model.key
B. Beckert
38 / 39
Recommended/Background Huth & Ryan Logic in Computer Science, 2nd edn., Cambridge University Press, 2004 Fitting First-Order Logic and Automated Theorem Proving, 2nd edn., Springer 1996
B. Beckert
39 / 39