paulson@14205
|
1 |
(* Title: FOL/ex/If.ML
|
paulson@14205
|
2 |
ID: $Id$
|
paulson@14205
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
paulson@14205
|
4 |
Copyright 1991 University of Cambridge
|
paulson@14205
|
5 |
|
paulson@14205
|
6 |
First-Order Logic: the 'if' example.
|
paulson@14205
|
7 |
*)
|
paulson@14205
|
8 |
|
haftmann@16417
|
9 |
theory If imports FOL begin
|
paulson@14205
|
10 |
|
haftmann@35413
|
11 |
definition "if" :: "[o,o,o]=>o" where
|
wenzelm@19792
|
12 |
"if(P,Q,R) == P&Q | ~P&R"
|
paulson@14205
|
13 |
|
paulson@14205
|
14 |
lemma ifI:
|
paulson@14205
|
15 |
"[| P ==> Q; ~P ==> R |] ==> if(P,Q,R)"
|
paulson@14205
|
16 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
17 |
apply (simp add: if_def)
|
paulson@14205
|
18 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
19 |
apply blast
|
paulson@14205
|
20 |
done
|
paulson@14205
|
21 |
|
paulson@14205
|
22 |
lemma ifE:
|
paulson@14205
|
23 |
"[| if(P,Q,R); [| P; Q |] ==> S; [| ~P; R |] ==> S |] ==> S"
|
paulson@14205
|
24 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
25 |
apply (simp add: if_def)
|
paulson@14205
|
26 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
27 |
apply blast
|
paulson@14205
|
28 |
done
|
paulson@14205
|
29 |
|
paulson@14205
|
30 |
lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
|
paulson@14205
|
31 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
32 |
apply (rule iffI)
|
paulson@14205
|
33 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
34 |
apply (erule ifE)
|
paulson@14205
|
35 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
36 |
apply (erule ifE)
|
paulson@14205
|
37 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
38 |
apply (rule ifI)
|
paulson@14205
|
39 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
40 |
apply (rule ifI)
|
paulson@14205
|
41 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
42 |
oops
|
paulson@14205
|
43 |
|
paulson@14205
|
44 |
text{*Trying again from the beginning in order to use @{text blast}*}
|
paulson@14205
|
45 |
declare ifI [intro!]
|
paulson@14205
|
46 |
declare ifE [elim!]
|
paulson@14205
|
47 |
|
paulson@14205
|
48 |
lemma if_commute: "if(P, if(Q,A,B), if(Q,C,D)) <-> if(Q, if(P,A,C), if(P,B,D))"
|
paulson@14205
|
49 |
by blast
|
paulson@14205
|
50 |
|
paulson@14205
|
51 |
|
paulson@14205
|
52 |
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
|
paulson@14205
|
53 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
54 |
by blast
|
paulson@14205
|
55 |
|
paulson@14205
|
56 |
text{*Trying again from the beginning in order to prove from the definitions*}
|
paulson@14205
|
57 |
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,A,B))"
|
paulson@14205
|
58 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
59 |
apply (simp add: if_def)
|
paulson@14205
|
60 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
61 |
apply blast
|
paulson@14205
|
62 |
done
|
paulson@14205
|
63 |
|
paulson@14205
|
64 |
|
paulson@14205
|
65 |
text{*An invalid formula. High-level rules permit a simpler diagnosis*}
|
paulson@14205
|
66 |
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
|
paulson@14205
|
67 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
68 |
apply auto
|
paulson@14205
|
69 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
70 |
(*The next step will fail unless subgoals remain*)
|
paulson@14205
|
71 |
apply (tactic all_tac)
|
paulson@14205
|
72 |
oops
|
paulson@14205
|
73 |
|
paulson@14205
|
74 |
text{*Trying again from the beginning in order to prove from the definitions*}
|
paulson@14205
|
75 |
lemma "if(if(P,Q,R), A, B) <-> if(P, if(Q,A,B), if(R,B,A))"
|
paulson@14205
|
76 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
77 |
apply (simp add: if_def)
|
paulson@14205
|
78 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
79 |
apply (auto)
|
paulson@14205
|
80 |
--{* @{subgoals[display,indent=0,margin=65]} *}
|
paulson@14205
|
81 |
(*The next step will fail unless subgoals remain*)
|
paulson@14205
|
82 |
apply (tactic all_tac)
|
paulson@14205
|
83 |
oops
|
paulson@14205
|
84 |
|
paulson@14205
|
85 |
|
paulson@14205
|
86 |
end
|