2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
3 Copyright 1991 University of Cambridge
5 First-Order Logic: the 'if' example.
8 theory If imports FOL begin
10 definition "if" :: "[o,o,o]=>o" where
11 "if(P,Q,R) == P&Q | ~P&R"
14 "[| P ==> Q; ~P ==> R |] ==> if(P,Q,R)"
15 --{* @{subgoals[display,indent=0,margin=65]} *}
16 apply (simp add: if_def)
17 --{* @{subgoals[display,indent=0,margin=65]} *}
22 "[| if(P,Q,R); [| P; Q |] ==> S; [| ~P; R |] ==> S |] ==> S"
23 --{* @{subgoals[display,indent=0,margin=65]} *}
24 apply (simp add: if_def)
25 --{* @{subgoals[display,indent=0,margin=65]} *}
29 lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
30 --{* @{subgoals[display,indent=0,margin=65]} *}
32 --{* @{subgoals[display,indent=0,margin=65]} *}
34 --{* @{subgoals[display,indent=0,margin=65]} *}
36 --{* @{subgoals[display,indent=0,margin=65]} *}
38 --{* @{subgoals[display,indent=0,margin=65]} *}
40 --{* @{subgoals[display,indent=0,margin=65]} *}
43 text{*Trying again from the beginning in order to use @{text blast}*}
47 lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
51 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
52 --{* @{subgoals[display,indent=0,margin=65]} *}
55 text{*Trying again from the beginning in order to prove from the definitions*}
56 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
57 --{* @{subgoals[display,indent=0,margin=65]} *}
58 apply (simp add: if_def)
59 --{* @{subgoals[display,indent=0,margin=65]} *}
64 text{*An invalid formula. High-level rules permit a simpler diagnosis*}
65 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
66 --{* @{subgoals[display,indent=0,margin=65]} *}
68 --{* @{subgoals[display,indent=0,margin=65]} *}
69 (*The next step will fail unless subgoals remain*)
70 apply (tactic all_tac)
73 text{*Trying again from the beginning in order to prove from the definitions*}
74 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
75 --{* @{subgoals[display,indent=0,margin=65]} *}
76 apply (simp add: if_def)
77 --{* @{subgoals[display,indent=0,margin=65]} *}
79 --{* @{subgoals[display,indent=0,margin=65]} *}
80 (*The next step will fail unless subgoals remain*)
81 apply (tactic all_tac)