3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1991 University of Cambridge
6 First-Order Logic: the 'if' example.
9 theory If imports FOL begin
11 definition "if" :: "[o,o,o]=>o" where
12 "if(P,Q,R) == P&Q | ~P&R"
15 "[| P ==> Q; ~P ==> R |] ==> if(P,Q,R)"
16 --{* @{subgoals[display,indent=0,margin=65]} *}
17 apply (simp add: if_def)
18 --{* @{subgoals[display,indent=0,margin=65]} *}
23 "[| if(P,Q,R); [| P; Q |] ==> S; [| ~P; R |] ==> S |] ==> S"
24 --{* @{subgoals[display,indent=0,margin=65]} *}
25 apply (simp add: if_def)
26 --{* @{subgoals[display,indent=0,margin=65]} *}
30 lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
31 --{* @{subgoals[display,indent=0,margin=65]} *}
33 --{* @{subgoals[display,indent=0,margin=65]} *}
35 --{* @{subgoals[display,indent=0,margin=65]} *}
37 --{* @{subgoals[display,indent=0,margin=65]} *}
39 --{* @{subgoals[display,indent=0,margin=65]} *}
41 --{* @{subgoals[display,indent=0,margin=65]} *}
44 text{*Trying again from the beginning in order to use @{text blast}*}
48 lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
52 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
53 --{* @{subgoals[display,indent=0,margin=65]} *}
56 text{*Trying again from the beginning in order to prove from the definitions*}
57 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
58 --{* @{subgoals[display,indent=0,margin=65]} *}
59 apply (simp add: if_def)
60 --{* @{subgoals[display,indent=0,margin=65]} *}
65 text{*An invalid formula. High-level rules permit a simpler diagnosis*}
66 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
67 --{* @{subgoals[display,indent=0,margin=65]} *}
69 --{* @{subgoals[display,indent=0,margin=65]} *}
70 (*The next step will fail unless subgoals remain*)
71 apply (tactic all_tac)
74 text{*Trying again from the beginning in order to prove from the definitions*}
75 lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
76 --{* @{subgoals[display,indent=0,margin=65]} *}
77 apply (simp add: if_def)
78 --{* @{subgoals[display,indent=0,margin=65]} *}
80 --{* @{subgoals[display,indent=0,margin=65]} *}
81 (*The next step will fail unless subgoals remain*)
82 apply (tactic all_tac)