168
|
1 |
(* Title: HOL/IOA/example/Lemmas.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Konrad Slind
|
|
4 |
Copyright 1994 TU Muenchen
|
|
5 |
|
|
6 |
(Mostly) Arithmetic lemmas
|
|
7 |
Should realy go in Arith.ML.
|
|
8 |
Also: Get rid of all the --> in favour of ==> !!!
|
|
9 |
*)
|
|
10 |
|
156
|
11 |
(* Logic *)
|
|
12 |
val prems = goal HOL.thy "(P ==> Q-->R) ==> P&Q --> R";
|
|
13 |
by(fast_tac (HOL_cs addDs prems) 1);
|
171
|
14 |
qed "imp_conj_lemma";
|
156
|
15 |
|
|
16 |
goal HOL.thy "(P --> (? x. Q(x))) = (? x. P --> Q(x))";
|
|
17 |
by(fast_tac HOL_cs 1);
|
171
|
18 |
qed "imp_ex_equiv";
|
156
|
19 |
|
|
20 |
goal HOL.thy "(A --> B & C) = ((A --> B) & (A --> C))";
|
|
21 |
by (fast_tac HOL_cs 1);
|
171
|
22 |
qed "fork_lemma";
|
156
|
23 |
|
|
24 |
goal HOL.thy "((A --> B) & (C --> B)) = ((A | C) --> B)";
|
|
25 |
by (fast_tac HOL_cs 1);
|
171
|
26 |
qed "imp_or_lem";
|
156
|
27 |
|
|
28 |
goal HOL.thy "(X = (~ Y)) = ((~X) = Y)";
|
|
29 |
by (fast_tac HOL_cs 1);
|
171
|
30 |
qed "neg_flip";
|
156
|
31 |
|
|
32 |
goal HOL.thy "P --> Q(M) --> Q(if(P,M,N))";
|
|
33 |
by (rtac impI 1);
|
|
34 |
by (rtac impI 1);
|
|
35 |
by (rtac (expand_if RS iffD2) 1);
|
|
36 |
by (fast_tac HOL_cs 1);
|
171
|
37 |
qed "imp_true_decompose";
|
156
|
38 |
|
|
39 |
goal HOL.thy "(~P) --> Q(N) --> Q(if(P,M,N))";
|
|
40 |
by (rtac impI 1);
|
|
41 |
by (rtac impI 1);
|
|
42 |
by (rtac (expand_if RS iffD2) 1);
|
|
43 |
by (fast_tac HOL_cs 1);
|
171
|
44 |
qed "imp_false_decompose";
|
156
|
45 |
|
|
46 |
|
|
47 |
(* Sets *)
|
|
48 |
val set_lemmas =
|
|
49 |
map (fn s => prove_goal Set.thy s (fn _ => [fast_tac set_cs 1]))
|
|
50 |
["f(x) : (UN x. {f(x)})",
|
|
51 |
"f(x,y) : (UN x y. {f(x,y)})",
|
|
52 |
"!!a. (!x. a ~= f(x)) ==> a ~: (UN x. {f(x)})",
|
|
53 |
"!!a. (!x y. a ~= f(x,y)) ==> a ~: (UN x y. {f(x,y)})"];
|
|
54 |
|
|
55 |
|
|
56 |
(* Arithmetic *)
|
|
57 |
goal Arith.thy "n ~= 0 --> Suc(m+pred(n)) = m+n";
|
|
58 |
by (nat_ind_tac "n" 1);
|
|
59 |
by (REPEAT(simp_tac arith_ss 1));
|
171
|
60 |
val Suc_pred_lemma = store_thm("Suc_pred_lemma", result() RS mp);
|
156
|
61 |
|
|
62 |
goal Arith.thy "x <= y --> x <= Suc(y)";
|
|
63 |
by (rtac impI 1);
|
|
64 |
by (rtac (le_eq_less_or_eq RS iffD2) 1);
|
|
65 |
by (rtac disjI1 1);
|
|
66 |
by (dtac (le_eq_less_or_eq RS iffD1) 1);
|
|
67 |
by (etac disjE 1);
|
|
68 |
by (etac less_SucI 1);
|
|
69 |
by (asm_simp_tac nat_ss 1);
|
171
|
70 |
val leq_imp_leq_suc = store_thm("leq_imp_leq_suc", result() RS mp);
|
156
|
71 |
|
|
72 |
(* Same as previous! *)
|
|
73 |
goal Arith.thy "(x::nat)<=y --> x<=Suc(y)";
|
|
74 |
by (simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
|
171
|
75 |
qed "leq_suc";
|
156
|
76 |
|
|
77 |
goal Arith.thy "((m::nat) + n = m + p) = (n = p)";
|
|
78 |
by (nat_ind_tac "m" 1);
|
|
79 |
by (simp_tac arith_ss 1);
|
|
80 |
by (asm_simp_tac arith_ss 1);
|
171
|
81 |
qed "left_plus_cancel";
|
156
|
82 |
|
|
83 |
goal Arith.thy "((x::nat) + y = Suc(x + z)) = (y = Suc(z))";
|
|
84 |
by (nat_ind_tac "x" 1);
|
|
85 |
by (simp_tac arith_ss 1);
|
|
86 |
by (asm_simp_tac arith_ss 1);
|
171
|
87 |
qed "left_plus_cancel_inside_succ";
|
156
|
88 |
|
|
89 |
goal Arith.thy "(x ~= 0) = (? y. x = Suc(y))";
|
|
90 |
by (nat_ind_tac "x" 1);
|
|
91 |
by (simp_tac arith_ss 1);
|
|
92 |
by (asm_simp_tac arith_ss 1);
|
|
93 |
by (fast_tac HOL_cs 1);
|
171
|
94 |
qed "nonzero_is_succ";
|
156
|
95 |
|
|
96 |
goal Arith.thy "(m::nat) < n --> m + p < n + p";
|
|
97 |
by (nat_ind_tac "p" 1);
|
|
98 |
by (simp_tac arith_ss 1);
|
|
99 |
by (asm_simp_tac arith_ss 1);
|
171
|
100 |
qed "less_add_same_less";
|
156
|
101 |
|
|
102 |
goal Arith.thy "(x::nat)<= y --> x<=y+k";
|
|
103 |
by (nat_ind_tac "k" 1);
|
|
104 |
by (simp_tac arith_ss 1);
|
|
105 |
by (asm_full_simp_tac (arith_ss addsimps [leq_suc]) 1);
|
171
|
106 |
qed "leq_add_leq";
|
156
|
107 |
|
|
108 |
goal Arith.thy "(x::nat) + y <= z --> x <= z";
|
|
109 |
by (nat_ind_tac "y" 1);
|
|
110 |
by (simp_tac arith_ss 1);
|
|
111 |
by (asm_simp_tac arith_ss 1);
|
|
112 |
by (rtac impI 1);
|
|
113 |
by (dtac Suc_leD 1);
|
|
114 |
by (fast_tac HOL_cs 1);
|
171
|
115 |
qed "left_add_leq";
|
156
|
116 |
|
|
117 |
goal Arith.thy "(A::nat) < B --> C < D --> A + C < B + D";
|
|
118 |
by (rtac impI 1);
|
|
119 |
by (rtac impI 1);
|
|
120 |
by (rtac less_trans 1);
|
|
121 |
by (rtac (less_add_same_less RS mp) 1);
|
|
122 |
by (assume_tac 1);
|
|
123 |
by (rtac (add_commute RS ssubst)1);;
|
|
124 |
by (res_inst_tac [("m1","B")] (add_commute RS ssubst) 1);
|
|
125 |
by (rtac (less_add_same_less RS mp) 1);
|
|
126 |
by (assume_tac 1);
|
171
|
127 |
qed "less_add_cong";
|
156
|
128 |
|
|
129 |
goal Nat.thy "!!i. [| i < j; j <= k |] ==> i < (k::nat)";
|
|
130 |
by (dtac le_imp_less_or_eq 1);
|
|
131 |
by (fast_tac (HOL_cs addIs [less_trans]) 1);
|
171
|
132 |
qed "less_leq_less";
|
156
|
133 |
|
|
134 |
goal Arith.thy "(A::nat) <= B --> C <= D --> A + C <= B + D";
|
|
135 |
by (rtac impI 1);
|
|
136 |
by (rtac impI 1);
|
|
137 |
by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
|
|
138 |
by (safe_tac HOL_cs);
|
|
139 |
by (rtac (less_add_cong RS mp RS mp) 1);
|
|
140 |
by (assume_tac 1);
|
|
141 |
by (assume_tac 1);
|
|
142 |
by (rtac (less_add_same_less RS mp) 1);
|
|
143 |
by (assume_tac 1);
|
|
144 |
by (rtac (add_commute RS ssubst)1);;
|
|
145 |
by (res_inst_tac [("m1","B")] (add_commute RS ssubst) 1);
|
|
146 |
by (rtac (less_add_same_less RS mp) 1);
|
|
147 |
by (assume_tac 1);
|
171
|
148 |
qed "less_eq_add_cong";
|
156
|
149 |
|
|
150 |
goal Arith.thy "(w <= y) --> ((x::nat) + y <= z) --> (x + w <= z)";
|
|
151 |
by (rtac impI 1);
|
|
152 |
by (dtac (less_eq_add_cong RS mp) 1);
|
|
153 |
by (cut_facts_tac [le_refl] 1);
|
|
154 |
by (dres_inst_tac [("P","x<=x")] mp 1);by (assume_tac 1);
|
|
155 |
by (asm_full_simp_tac (HOL_ss addsimps [add_commute]) 1);
|
|
156 |
by (rtac impI 1);
|
|
157 |
by (etac le_trans 1);
|
|
158 |
by (assume_tac 1);
|
171
|
159 |
qed "leq_add_left_cong";
|
156
|
160 |
|
|
161 |
goal Arith.thy "(? x. y = Suc(x)) = (~(y = 0))";
|
|
162 |
by (nat_ind_tac "y" 1);
|
|
163 |
by (simp_tac arith_ss 1);
|
|
164 |
by (rtac iffI 1);
|
|
165 |
by (asm_full_simp_tac arith_ss 1);
|
|
166 |
by (fast_tac HOL_cs 1);
|
171
|
167 |
qed "suc_not_zero";
|
156
|
168 |
|
|
169 |
goal Arith.thy "Suc(x) <= y --> (? z. y = Suc(z))";
|
|
170 |
by (rtac impI 1);
|
|
171 |
by (asm_full_simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
|
|
172 |
by (safe_tac HOL_cs);
|
|
173 |
by (fast_tac HOL_cs 2);
|
|
174 |
by (asm_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
|
|
175 |
by (rtac ccontr 1);
|
|
176 |
by (asm_full_simp_tac (arith_ss addsimps [suc_not_zero]) 1);
|
|
177 |
by (hyp_subst_tac 1);
|
|
178 |
by (asm_full_simp_tac arith_ss 1);
|
171
|
179 |
qed "suc_leq_suc";
|
156
|
180 |
|
|
181 |
goal Arith.thy "~0<n --> n = 0";
|
|
182 |
by (nat_ind_tac "n" 1);
|
|
183 |
by (asm_simp_tac arith_ss 1);
|
|
184 |
by (safe_tac HOL_cs);
|
|
185 |
by (asm_full_simp_tac arith_ss 1);
|
|
186 |
by (asm_full_simp_tac arith_ss 1);
|
171
|
187 |
qed "zero_eq";
|
156
|
188 |
|
|
189 |
goal Arith.thy "x < Suc(y) --> x<=y";
|
|
190 |
by (nat_ind_tac "n" 1);
|
|
191 |
by (asm_simp_tac arith_ss 1);
|
|
192 |
by (safe_tac HOL_cs);
|
|
193 |
by (etac less_imp_le 1);
|
171
|
194 |
qed "less_suc_imp_leq";
|
156
|
195 |
|
|
196 |
goal Arith.thy "0<x --> Suc(pred(x)) = x";
|
|
197 |
by (nat_ind_tac "x" 1);
|
|
198 |
by (simp_tac arith_ss 1);
|
|
199 |
by (asm_simp_tac arith_ss 1);
|
171
|
200 |
qed "suc_pred_id";
|
156
|
201 |
|
|
202 |
goal Arith.thy "0<x --> (pred(x) = y) = (x = Suc(y))";
|
|
203 |
by (nat_ind_tac "x" 1);
|
|
204 |
by (simp_tac arith_ss 1);
|
|
205 |
by (asm_simp_tac arith_ss 1);
|
171
|
206 |
qed "pred_suc";
|
156
|
207 |
|
|
208 |
goal Arith.thy "(x ~= 0) = (0<x)";
|
|
209 |
by (nat_ind_tac "x" 1);
|
|
210 |
by (simp_tac arith_ss 1);
|
|
211 |
by (asm_simp_tac arith_ss 1);
|
171
|
212 |
qed "unzero_less";
|
156
|
213 |
|
|
214 |
(* Duplicate of earlier lemma! *)
|
|
215 |
goal Arith.thy "x<(y::nat) --> y<=z --> x<(z::nat)";
|
|
216 |
by (rtac impI 1); by (rtac impI 1);
|
|
217 |
by (dtac le_imp_less_or_eq 1);
|
|
218 |
by (fast_tac (HOL_cs addIs [less_trans]) 1);
|
171
|
219 |
qed "less_leq_less";
|
156
|
220 |
|
|
221 |
goal Arith.thy "(Suc(n) <= Suc(m)) = (n <= m)";
|
|
222 |
by (simp_tac (arith_ss addsimps [le_eq_less_or_eq]) 1);
|
171
|
223 |
qed "succ_leq_mono";
|
156
|
224 |
|
|
225 |
(* Odd proof. Why do induction? *)
|
|
226 |
goal Arith.thy "((x::nat) = y + z) --> (y <= x)";
|
|
227 |
by (nat_ind_tac "y" 1);
|
|
228 |
by (simp_tac arith_ss 1);
|
|
229 |
by (simp_tac (arith_ss addsimps
|
|
230 |
[succ_leq_mono, le_refl RS (leq_add_leq RS mp)]) 1);
|
171
|
231 |
qed "plus_leq_lem";
|
156
|
232 |
|
|
233 |
(* Lists *)
|
|
234 |
|
193
|
235 |
goal List.thy "(xs @ (y#ys)) ~= []";
|
|
236 |
by (list.induct_tac "xs" 1);
|
156
|
237 |
by (simp_tac list_ss 1);
|
|
238 |
by (asm_simp_tac list_ss 1);
|
171
|
239 |
qed "append_cons";
|
156
|
240 |
|
193
|
241 |
goal List.thy "(x ~= hd(xs@ys)) = (x ~= if(xs = [], hd(ys), hd(xs)))";
|
|
242 |
by (list.induct_tac "xs" 1);
|
156
|
243 |
by (simp_tac list_ss 1);
|
|
244 |
by (asm_full_simp_tac list_ss 1);
|
171
|
245 |
qed "not_hd_append";
|
156
|
246 |
|
|
247 |
goal List.thy "(L = (x#rst)) --> (L = []) --> P";
|
|
248 |
by (simp_tac list_ss 1);
|
171
|
249 |
qed "list_cases";
|
156
|
250 |
|
|
251 |
goal List.thy "(? L2. L1 = x#L2) --> (L1 ~= [])";
|
|
252 |
by (strip_tac 1);
|
|
253 |
by (etac exE 1);
|
|
254 |
by (asm_simp_tac list_ss 1);
|
171
|
255 |
qed "cons_imp_not_null";
|