|
23462
|
1 |
(* Title: HOL/Arith_Tools.thy
|
|
|
2 |
ID: $Id$
|
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
|
4 |
Author: Amine Chaieb, TU Muenchen
|
|
|
5 |
*)
|
|
|
6 |
|
|
|
7 |
header {* Setup of arithmetic tools *}
|
|
|
8 |
|
|
|
9 |
theory Arith_Tools
|
|
|
10 |
imports Groebner_Basis Dense_Linear_Order SetInterval
|
|
|
11 |
uses
|
|
|
12 |
"~~/src/Provers/Arith/cancel_numeral_factor.ML"
|
|
|
13 |
"~~/src/Provers/Arith/extract_common_term.ML"
|
|
|
14 |
"int_factor_simprocs.ML"
|
|
|
15 |
"nat_simprocs.ML"
|
|
|
16 |
"Tools/Presburger/cooper_data.ML"
|
|
|
17 |
"Tools/Presburger/generated_cooper.ML"
|
|
|
18 |
("Tools/Presburger/cooper.ML")
|
|
|
19 |
("Tools/Presburger/presburger.ML")
|
|
|
20 |
begin
|
|
|
21 |
|
|
|
22 |
subsection {* Simprocs for the Naturals *}
|
|
|
23 |
|
|
|
24 |
setup nat_simprocs_setup
|
|
|
25 |
|
|
|
26 |
subsubsection{*For simplifying @{term "Suc m - K"} and @{term "K - Suc m"}*}
|
|
|
27 |
|
|
|
28 |
text{*Where K above is a literal*}
|
|
|
29 |
|
|
|
30 |
lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)"
|
|
|
31 |
by (simp add: numeral_0_eq_0 numeral_1_eq_1 split add: nat_diff_split)
|
|
|
32 |
|
|
|
33 |
text {*Now just instantiating @{text n} to @{text "number_of v"} does
|
|
|
34 |
the right simplification, but with some redundant inequality
|
|
|
35 |
tests.*}
|
|
|
36 |
lemma neg_number_of_pred_iff_0:
|
|
|
37 |
"neg (number_of (Numeral.pred v)::int) = (number_of v = (0::nat))"
|
|
|
38 |
apply (subgoal_tac "neg (number_of (Numeral.pred v)) = (number_of v < Suc 0) ")
|
|
|
39 |
apply (simp only: less_Suc_eq_le le_0_eq)
|
|
|
40 |
apply (subst less_number_of_Suc, simp)
|
|
|
41 |
done
|
|
|
42 |
|
|
|
43 |
text{*No longer required as a simprule because of the @{text inverse_fold}
|
|
|
44 |
simproc*}
|
|
|
45 |
lemma Suc_diff_number_of:
|
|
|
46 |
"neg (number_of (uminus v)::int) ==>
|
|
|
47 |
Suc m - (number_of v) = m - (number_of (Numeral.pred v))"
|
|
|
48 |
apply (subst Suc_diff_eq_diff_pred)
|
|
|
49 |
apply simp
|
|
|
50 |
apply (simp del: nat_numeral_1_eq_1)
|
|
|
51 |
apply (auto simp only: diff_nat_number_of less_0_number_of [symmetric]
|
|
|
52 |
neg_number_of_pred_iff_0)
|
|
|
53 |
done
|
|
|
54 |
|
|
|
55 |
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n"
|
|
|
56 |
by (simp add: numerals split add: nat_diff_split)
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
subsubsection{*For @{term nat_case} and @{term nat_rec}*}
|
|
|
60 |
|
|
|
61 |
lemma nat_case_number_of [simp]:
|
|
|
62 |
"nat_case a f (number_of v) =
|
|
|
63 |
(let pv = number_of (Numeral.pred v) in
|
|
|
64 |
if neg pv then a else f (nat pv))"
|
|
|
65 |
by (simp split add: nat.split add: Let_def neg_number_of_pred_iff_0)
|
|
|
66 |
|
|
|
67 |
lemma nat_case_add_eq_if [simp]:
|
|
|
68 |
"nat_case a f ((number_of v) + n) =
|
|
|
69 |
(let pv = number_of (Numeral.pred v) in
|
|
|
70 |
if neg pv then nat_case a f n else f (nat pv + n))"
|
|
|
71 |
apply (subst add_eq_if)
|
|
|
72 |
apply (simp split add: nat.split
|
|
|
73 |
del: nat_numeral_1_eq_1
|
|
|
74 |
add: numeral_1_eq_Suc_0 [symmetric] Let_def
|
|
|
75 |
neg_imp_number_of_eq_0 neg_number_of_pred_iff_0)
|
|
|
76 |
done
|
|
|
77 |
|
|
|
78 |
lemma nat_rec_number_of [simp]:
|
|
|
79 |
"nat_rec a f (number_of v) =
|
|
|
80 |
(let pv = number_of (Numeral.pred v) in
|
|
|
81 |
if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))"
|
|
|
82 |
apply (case_tac " (number_of v) ::nat")
|
|
|
83 |
apply (simp_all (no_asm_simp) add: Let_def neg_number_of_pred_iff_0)
|
|
|
84 |
apply (simp split add: split_if_asm)
|
|
|
85 |
done
|
|
|
86 |
|
|
|
87 |
lemma nat_rec_add_eq_if [simp]:
|
|
|
88 |
"nat_rec a f (number_of v + n) =
|
|
|
89 |
(let pv = number_of (Numeral.pred v) in
|
|
|
90 |
if neg pv then nat_rec a f n
|
|
|
91 |
else f (nat pv + n) (nat_rec a f (nat pv + n)))"
|
|
|
92 |
apply (subst add_eq_if)
|
|
|
93 |
apply (simp split add: nat.split
|
|
|
94 |
del: nat_numeral_1_eq_1
|
|
|
95 |
add: numeral_1_eq_Suc_0 [symmetric] Let_def neg_imp_number_of_eq_0
|
|
|
96 |
neg_number_of_pred_iff_0)
|
|
|
97 |
done
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
subsubsection{*Various Other Lemmas*}
|
|
|
101 |
|
|
|
102 |
text {*Evens and Odds, for Mutilated Chess Board*}
|
|
|
103 |
|
|
|
104 |
text{*Lemmas for specialist use, NOT as default simprules*}
|
|
|
105 |
lemma nat_mult_2: "2 * z = (z+z::nat)"
|
|
|
106 |
proof -
|
|
|
107 |
have "2*z = (1 + 1)*z" by simp
|
|
|
108 |
also have "... = z+z" by (simp add: left_distrib)
|
|
|
109 |
finally show ?thesis .
|
|
|
110 |
qed
|
|
|
111 |
|
|
|
112 |
lemma nat_mult_2_right: "z * 2 = (z+z::nat)"
|
|
|
113 |
by (subst mult_commute, rule nat_mult_2)
|
|
|
114 |
|
|
|
115 |
text{*Case analysis on @{term "n<2"}*}
|
|
|
116 |
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0"
|
|
|
117 |
by arith
|
|
|
118 |
|
|
|
119 |
lemma div2_Suc_Suc [simp]: "Suc(Suc m) div 2 = Suc (m div 2)"
|
|
|
120 |
by arith
|
|
|
121 |
|
|
|
122 |
lemma add_self_div_2 [simp]: "(m + m) div 2 = (m::nat)"
|
|
|
123 |
by (simp add: nat_mult_2 [symmetric])
|
|
|
124 |
|
|
|
125 |
lemma mod2_Suc_Suc [simp]: "Suc(Suc(m)) mod 2 = m mod 2"
|
|
|
126 |
apply (subgoal_tac "m mod 2 < 2")
|
|
|
127 |
apply (erule less_2_cases [THEN disjE])
|
|
|
128 |
apply (simp_all (no_asm_simp) add: Let_def mod_Suc nat_1)
|
|
|
129 |
done
|
|
|
130 |
|
|
|
131 |
lemma mod2_gr_0 [simp]: "!!m::nat. (0 < m mod 2) = (m mod 2 = 1)"
|
|
|
132 |
apply (subgoal_tac "m mod 2 < 2")
|
|
|
133 |
apply (force simp del: mod_less_divisor, simp)
|
|
|
134 |
done
|
|
|
135 |
|
|
|
136 |
text{*Removal of Small Numerals: 0, 1 and (in additive positions) 2*}
|
|
|
137 |
|
|
|
138 |
lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)"
|
|
|
139 |
by simp
|
|
|
140 |
|
|
|
141 |
lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)"
|
|
|
142 |
by simp
|
|
|
143 |
|
|
|
144 |
text{*Can be used to eliminate long strings of Sucs, but not by default*}
|
|
|
145 |
lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n"
|
|
|
146 |
by simp
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
text{*These lemmas collapse some needless occurrences of Suc:
|
|
|
150 |
at least three Sucs, since two and fewer are rewritten back to Suc again!
|
|
|
151 |
We already have some rules to simplify operands smaller than 3.*}
|
|
|
152 |
|
|
|
153 |
lemma div_Suc_eq_div_add3 [simp]: "m div (Suc (Suc (Suc n))) = m div (3+n)"
|
|
|
154 |
by (simp add: Suc3_eq_add_3)
|
|
|
155 |
|
|
|
156 |
lemma mod_Suc_eq_mod_add3 [simp]: "m mod (Suc (Suc (Suc n))) = m mod (3+n)"
|
|
|
157 |
by (simp add: Suc3_eq_add_3)
|
|
|
158 |
|
|
|
159 |
lemma Suc_div_eq_add3_div: "(Suc (Suc (Suc m))) div n = (3+m) div n"
|
|
|
160 |
by (simp add: Suc3_eq_add_3)
|
|
|
161 |
|
|
|
162 |
lemma Suc_mod_eq_add3_mod: "(Suc (Suc (Suc m))) mod n = (3+m) mod n"
|
|
|
163 |
by (simp add: Suc3_eq_add_3)
|
|
|
164 |
|
|
|
165 |
lemmas Suc_div_eq_add3_div_number_of =
|
|
|
166 |
Suc_div_eq_add3_div [of _ "number_of v", standard]
|
|
|
167 |
declare Suc_div_eq_add3_div_number_of [simp]
|
|
|
168 |
|
|
|
169 |
lemmas Suc_mod_eq_add3_mod_number_of =
|
|
|
170 |
Suc_mod_eq_add3_mod [of _ "number_of v", standard]
|
|
|
171 |
declare Suc_mod_eq_add3_mod_number_of [simp]
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
subsubsection{*Special Simplification for Constants*}
|
|
|
175 |
|
|
|
176 |
text{*These belong here, late in the development of HOL, to prevent their
|
|
|
177 |
interfering with proofs of abstract properties of instances of the function
|
|
|
178 |
@{term number_of}*}
|
|
|
179 |
|
|
|
180 |
text{*These distributive laws move literals inside sums and differences.*}
|
|
|
181 |
lemmas left_distrib_number_of = left_distrib [of _ _ "number_of v", standard]
|
|
|
182 |
declare left_distrib_number_of [simp]
|
|
|
183 |
|
|
|
184 |
lemmas right_distrib_number_of = right_distrib [of "number_of v", standard]
|
|
|
185 |
declare right_distrib_number_of [simp]
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
lemmas left_diff_distrib_number_of =
|
|
|
189 |
left_diff_distrib [of _ _ "number_of v", standard]
|
|
|
190 |
declare left_diff_distrib_number_of [simp]
|
|
|
191 |
|
|
|
192 |
lemmas right_diff_distrib_number_of =
|
|
|
193 |
right_diff_distrib [of "number_of v", standard]
|
|
|
194 |
declare right_diff_distrib_number_of [simp]
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
text{*These are actually for fields, like real: but where else to put them?*}
|
|
|
198 |
lemmas zero_less_divide_iff_number_of =
|
|
|
199 |
zero_less_divide_iff [of "number_of w", standard]
|
|
|
200 |
declare zero_less_divide_iff_number_of [simp]
|
|
|
201 |
|
|
|
202 |
lemmas divide_less_0_iff_number_of =
|
|
|
203 |
divide_less_0_iff [of "number_of w", standard]
|
|
|
204 |
declare divide_less_0_iff_number_of [simp]
|
|
|
205 |
|
|
|
206 |
lemmas zero_le_divide_iff_number_of =
|
|
|
207 |
zero_le_divide_iff [of "number_of w", standard]
|
|
|
208 |
declare zero_le_divide_iff_number_of [simp]
|
|
|
209 |
|
|
|
210 |
lemmas divide_le_0_iff_number_of =
|
|
|
211 |
divide_le_0_iff [of "number_of w", standard]
|
|
|
212 |
declare divide_le_0_iff_number_of [simp]
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
(****
|
|
|
216 |
IF times_divide_eq_right and times_divide_eq_left are removed as simprules,
|
|
|
217 |
then these special-case declarations may be useful.
|
|
|
218 |
|
|
|
219 |
text{*These simprules move numerals into numerators and denominators.*}
|
|
|
220 |
lemma times_recip_eq_right [simp]: "a * (1/c) = a / (c::'a::field)"
|
|
|
221 |
by (simp add: times_divide_eq)
|
|
|
222 |
|
|
|
223 |
lemma times_recip_eq_left [simp]: "(1/c) * a = a / (c::'a::field)"
|
|
|
224 |
by (simp add: times_divide_eq)
|
|
|
225 |
|
|
|
226 |
lemmas times_divide_eq_right_number_of =
|
|
|
227 |
times_divide_eq_right [of "number_of w", standard]
|
|
|
228 |
declare times_divide_eq_right_number_of [simp]
|
|
|
229 |
|
|
|
230 |
lemmas times_divide_eq_right_number_of =
|
|
|
231 |
times_divide_eq_right [of _ _ "number_of w", standard]
|
|
|
232 |
declare times_divide_eq_right_number_of [simp]
|
|
|
233 |
|
|
|
234 |
lemmas times_divide_eq_left_number_of =
|
|
|
235 |
times_divide_eq_left [of _ "number_of w", standard]
|
|
|
236 |
declare times_divide_eq_left_number_of [simp]
|
|
|
237 |
|
|
|
238 |
lemmas times_divide_eq_left_number_of =
|
|
|
239 |
times_divide_eq_left [of _ _ "number_of w", standard]
|
|
|
240 |
declare times_divide_eq_left_number_of [simp]
|
|
|
241 |
|
|
|
242 |
****)
|
|
|
243 |
|
|
|
244 |
text {*Replaces @{text "inverse #nn"} by @{text "1/#nn"}. It looks
|
|
|
245 |
strange, but then other simprocs simplify the quotient.*}
|
|
|
246 |
|
|
|
247 |
lemmas inverse_eq_divide_number_of =
|
|
|
248 |
inverse_eq_divide [of "number_of w", standard]
|
|
|
249 |
declare inverse_eq_divide_number_of [simp]
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
text {*These laws simplify inequalities, moving unary minus from a term
|
|
|
253 |
into the literal.*}
|
|
|
254 |
lemmas less_minus_iff_number_of =
|
|
|
255 |
less_minus_iff [of "number_of v", standard]
|
|
|
256 |
declare less_minus_iff_number_of [simp]
|
|
|
257 |
|
|
|
258 |
lemmas le_minus_iff_number_of =
|
|
|
259 |
le_minus_iff [of "number_of v", standard]
|
|
|
260 |
declare le_minus_iff_number_of [simp]
|
|
|
261 |
|
|
|
262 |
lemmas equation_minus_iff_number_of =
|
|
|
263 |
equation_minus_iff [of "number_of v", standard]
|
|
|
264 |
declare equation_minus_iff_number_of [simp]
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
lemmas minus_less_iff_number_of =
|
|
|
268 |
minus_less_iff [of _ "number_of v", standard]
|
|
|
269 |
declare minus_less_iff_number_of [simp]
|
|
|
270 |
|
|
|
271 |
lemmas minus_le_iff_number_of =
|
|
|
272 |
minus_le_iff [of _ "number_of v", standard]
|
|
|
273 |
declare minus_le_iff_number_of [simp]
|
|
|
274 |
|
|
|
275 |
lemmas minus_equation_iff_number_of =
|
|
|
276 |
minus_equation_iff [of _ "number_of v", standard]
|
|
|
277 |
declare minus_equation_iff_number_of [simp]
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
text{*To Simplify Inequalities Where One Side is the Constant 1*}
|
|
|
281 |
|
|
|
282 |
lemma less_minus_iff_1 [simp]:
|
|
|
283 |
fixes b::"'b::{ordered_idom,number_ring}"
|
|
|
284 |
shows "(1 < - b) = (b < -1)"
|
|
|
285 |
by auto
|
|
|
286 |
|
|
|
287 |
lemma le_minus_iff_1 [simp]:
|
|
|
288 |
fixes b::"'b::{ordered_idom,number_ring}"
|
|
|
289 |
shows "(1 \<le> - b) = (b \<le> -1)"
|
|
|
290 |
by auto
|
|
|
291 |
|
|
|
292 |
lemma equation_minus_iff_1 [simp]:
|
|
|
293 |
fixes b::"'b::number_ring"
|
|
|
294 |
shows "(1 = - b) = (b = -1)"
|
|
|
295 |
by (subst equation_minus_iff, auto)
|
|
|
296 |
|
|
|
297 |
lemma minus_less_iff_1 [simp]:
|
|
|
298 |
fixes a::"'b::{ordered_idom,number_ring}"
|
|
|
299 |
shows "(- a < 1) = (-1 < a)"
|
|
|
300 |
by auto
|
|
|
301 |
|
|
|
302 |
lemma minus_le_iff_1 [simp]:
|
|
|
303 |
fixes a::"'b::{ordered_idom,number_ring}"
|
|
|
304 |
shows "(- a \<le> 1) = (-1 \<le> a)"
|
|
|
305 |
by auto
|
|
|
306 |
|
|
|
307 |
lemma minus_equation_iff_1 [simp]:
|
|
|
308 |
fixes a::"'b::number_ring"
|
|
|
309 |
shows "(- a = 1) = (a = -1)"
|
|
|
310 |
by (subst minus_equation_iff, auto)
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
text {*Cancellation of constant factors in comparisons (@{text "<"} and @{text "\<le>"}) *}
|
|
|
314 |
|
|
|
315 |
lemmas mult_less_cancel_left_number_of =
|
|
|
316 |
mult_less_cancel_left [of "number_of v", standard]
|
|
|
317 |
declare mult_less_cancel_left_number_of [simp]
|
|
|
318 |
|
|
|
319 |
lemmas mult_less_cancel_right_number_of =
|
|
|
320 |
mult_less_cancel_right [of _ "number_of v", standard]
|
|
|
321 |
declare mult_less_cancel_right_number_of [simp]
|
|
|
322 |
|
|
|
323 |
lemmas mult_le_cancel_left_number_of =
|
|
|
324 |
mult_le_cancel_left [of "number_of v", standard]
|
|
|
325 |
declare mult_le_cancel_left_number_of [simp]
|
|
|
326 |
|
|
|
327 |
lemmas mult_le_cancel_right_number_of =
|
|
|
328 |
mult_le_cancel_right [of _ "number_of v", standard]
|
|
|
329 |
declare mult_le_cancel_right_number_of [simp]
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
text {*Multiplying out constant divisors in comparisons (@{text "<"}, @{text "\<le>"} and @{text "="}) *}
|
|
|
333 |
|
|
|
334 |
lemmas le_divide_eq_number_of = le_divide_eq [of _ _ "number_of w", standard]
|
|
|
335 |
declare le_divide_eq_number_of [simp]
|
|
|
336 |
|
|
|
337 |
lemmas divide_le_eq_number_of = divide_le_eq [of _ "number_of w", standard]
|
|
|
338 |
declare divide_le_eq_number_of [simp]
|
|
|
339 |
|
|
|
340 |
lemmas less_divide_eq_number_of = less_divide_eq [of _ _ "number_of w", standard]
|
|
|
341 |
declare less_divide_eq_number_of [simp]
|
|
|
342 |
|
|
|
343 |
lemmas divide_less_eq_number_of = divide_less_eq [of _ "number_of w", standard]
|
|
|
344 |
declare divide_less_eq_number_of [simp]
|
|
|
345 |
|
|
|
346 |
lemmas eq_divide_eq_number_of = eq_divide_eq [of _ _ "number_of w", standard]
|
|
|
347 |
declare eq_divide_eq_number_of [simp]
|
|
|
348 |
|
|
|
349 |
lemmas divide_eq_eq_number_of = divide_eq_eq [of _ "number_of w", standard]
|
|
|
350 |
declare divide_eq_eq_number_of [simp]
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
subsubsection{*Optional Simplification Rules Involving Constants*}
|
|
|
355 |
|
|
|
356 |
text{*Simplify quotients that are compared with a literal constant.*}
|
|
|
357 |
|
|
|
358 |
lemmas le_divide_eq_number_of = le_divide_eq [of "number_of w", standard]
|
|
|
359 |
lemmas divide_le_eq_number_of = divide_le_eq [of _ _ "number_of w", standard]
|
|
|
360 |
lemmas less_divide_eq_number_of = less_divide_eq [of "number_of w", standard]
|
|
|
361 |
lemmas divide_less_eq_number_of = divide_less_eq [of _ _ "number_of w", standard]
|
|
|
362 |
lemmas eq_divide_eq_number_of = eq_divide_eq [of "number_of w", standard]
|
|
|
363 |
lemmas divide_eq_eq_number_of = divide_eq_eq [of _ _ "number_of w", standard]
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
text{*Not good as automatic simprules because they cause case splits.*}
|
|
|
367 |
lemmas divide_const_simps =
|
|
|
368 |
le_divide_eq_number_of divide_le_eq_number_of less_divide_eq_number_of
|
|
|
369 |
divide_less_eq_number_of eq_divide_eq_number_of divide_eq_eq_number_of
|
|
|
370 |
le_divide_eq_1 divide_le_eq_1 less_divide_eq_1 divide_less_eq_1
|
|
|
371 |
|
|
|
372 |
text{*Division By @{text "-1"}*}
|
|
|
373 |
|
|
|
374 |
lemma divide_minus1 [simp]:
|
|
|
375 |
"x/-1 = -(x::'a::{field,division_by_zero,number_ring})"
|
|
|
376 |
by simp
|
|
|
377 |
|
|
|
378 |
lemma minus1_divide [simp]:
|
|
|
379 |
"-1 / (x::'a::{field,division_by_zero,number_ring}) = - (1/x)"
|
|
|
380 |
by (simp add: divide_inverse inverse_minus_eq)
|
|
|
381 |
|
|
|
382 |
lemma half_gt_zero_iff:
|
|
|
383 |
"(0 < r/2) = (0 < (r::'a::{ordered_field,division_by_zero,number_ring}))"
|
|
|
384 |
by auto
|
|
|
385 |
|
|
|
386 |
lemmas half_gt_zero = half_gt_zero_iff [THEN iffD2, standard]
|
|
|
387 |
declare half_gt_zero [simp]
|
|
|
388 |
|
|
|
389 |
(* The following lemma should appear in Divides.thy, but there the proof
|
|
|
390 |
doesn't work. *)
|
|
|
391 |
|
|
|
392 |
lemma nat_dvd_not_less:
|
|
|
393 |
"[| 0 < m; m < n |] ==> \<not> n dvd (m::nat)"
|
|
|
394 |
by (unfold dvd_def) auto
|
|
|
395 |
|
|
|
396 |
ML {*
|
|
|
397 |
val divide_minus1 = @{thm divide_minus1};
|
|
|
398 |
val minus1_divide = @{thm minus1_divide};
|
|
|
399 |
*}
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
subsection{* Groebner Bases for fields *}
|
|
|
403 |
|
|
|
404 |
interpretation class_fieldgb:
|
|
|
405 |
fieldgb["op +" "op *" "op ^" "0::'a::{field,recpower,number_ring}" "1" "op -" "uminus" "op /" "inverse"] apply (unfold_locales) by (simp_all add: divide_inverse)
|
|
|
406 |
|
|
|
407 |
lemma divide_Numeral1: "(x::'a::{field,number_ring}) / Numeral1 = x" by simp
|
|
|
408 |
lemma divide_Numeral0: "(x::'a::{field,number_ring, division_by_zero}) / Numeral0 = 0"
|
|
|
409 |
by simp
|
|
|
410 |
lemma mult_frac_frac: "((x::'a::{field,division_by_zero}) / y) * (z / w) = (x*z) / (y*w)"
|
|
|
411 |
by simp
|
|
|
412 |
lemma mult_frac_num: "((x::'a::{field, division_by_zero}) / y) * z = (x*z) / y"
|
|
|
413 |
by simp
|
|
|
414 |
lemma mult_num_frac: "((x::'a::{field, division_by_zero}) / y) * z = (x*z) / y"
|
|
|
415 |
by simp
|
|
|
416 |
|
|
|
417 |
lemma Numeral1_eq1_nat: "(1::nat) = Numeral1" by simp
|
|
|
418 |
|
|
|
419 |
lemma add_frac_num: "y\<noteq> 0 \<Longrightarrow> (x::'a::{field, division_by_zero}) / y + z = (x + z*y) / y"
|
|
|
420 |
by (simp add: add_divide_distrib)
|
|
|
421 |
lemma add_num_frac: "y\<noteq> 0 \<Longrightarrow> z + (x::'a::{field, division_by_zero}) / y = (x + z*y) / y"
|
|
|
422 |
by (simp add: add_divide_distrib)
|
|
|
423 |
|
|
|
424 |
declaration{*
|
|
|
425 |
let
|
|
|
426 |
val zr = @{cpat "0"}
|
|
|
427 |
val zT = ctyp_of_term zr
|
|
|
428 |
val geq = @{cpat "op ="}
|
|
|
429 |
val eqT = Thm.dest_ctyp (ctyp_of_term geq) |> hd
|
|
|
430 |
val add_frac_eq = mk_meta_eq @{thm "add_frac_eq"}
|
|
|
431 |
val add_frac_num = mk_meta_eq @{thm "add_frac_num"}
|
|
|
432 |
val add_num_frac = mk_meta_eq @{thm "add_num_frac"}
|
|
|
433 |
|
|
|
434 |
fun prove_nz ctxt =
|
|
|
435 |
let val ss = local_simpset_of ctxt
|
|
|
436 |
in fn T => fn t =>
|
|
|
437 |
let
|
|
|
438 |
val z = instantiate_cterm ([(zT,T)],[]) zr
|
|
|
439 |
val eq = instantiate_cterm ([(eqT,T)],[]) geq
|
|
|
440 |
val th = Simplifier.rewrite (ss addsimps simp_thms)
|
|
|
441 |
(Thm.capply @{cterm "Trueprop"} (Thm.capply @{cterm "Not"}
|
|
|
442 |
(Thm.capply (Thm.capply eq t) z)))
|
|
|
443 |
in equal_elim (symmetric th) TrueI
|
|
|
444 |
end
|
|
|
445 |
end
|
|
|
446 |
|
|
|
447 |
fun proc ctxt phi ss ct =
|
|
|
448 |
let
|
|
|
449 |
val ((x,y),(w,z)) =
|
|
|
450 |
(Thm.dest_binop #> (fn (a,b) => (Thm.dest_binop a, Thm.dest_binop b))) ct
|
|
|
451 |
val _ = map (HOLogic.dest_number o term_of) [x,y,z,w]
|
|
|
452 |
val T = ctyp_of_term x
|
|
|
453 |
val [y_nz, z_nz] = map (prove_nz ctxt T) [y, z]
|
|
|
454 |
val th = instantiate' [SOME T] (map SOME [y,z,x,w]) add_frac_eq
|
|
|
455 |
in SOME (implies_elim (implies_elim th y_nz) z_nz)
|
|
|
456 |
end
|
|
|
457 |
handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
|
|
|
458 |
|
|
|
459 |
fun proc2 ctxt phi ss ct =
|
|
|
460 |
let
|
|
|
461 |
val (l,r) = Thm.dest_binop ct
|
|
|
462 |
val T = ctyp_of_term l
|
|
|
463 |
in (case (term_of l, term_of r) of
|
|
|
464 |
(Const(@{const_name "HOL.divide"},_)$_$_, _) =>
|
|
|
465 |
let val (x,y) = Thm.dest_binop l val z = r
|
|
|
466 |
val _ = map (HOLogic.dest_number o term_of) [x,y,z]
|
|
|
467 |
val ynz = prove_nz ctxt T y
|
|
|
468 |
in SOME (implies_elim (instantiate' [SOME T] (map SOME [y,x,z]) add_frac_num) ynz)
|
|
|
469 |
end
|
|
|
470 |
| (_, Const (@{const_name "HOL.divide"},_)$_$_) =>
|
|
|
471 |
let val (x,y) = Thm.dest_binop r val z = l
|
|
|
472 |
val _ = map (HOLogic.dest_number o term_of) [x,y,z]
|
|
|
473 |
val ynz = prove_nz ctxt T y
|
|
|
474 |
in SOME (implies_elim (instantiate' [SOME T] (map SOME [y,z,x]) add_num_frac) ynz)
|
|
|
475 |
end
|
|
|
476 |
| _ => NONE)
|
|
|
477 |
end
|
|
|
478 |
handle CTERM _ => NONE | TERM _ => NONE | THM _ => NONE
|
|
|
479 |
|
|
|
480 |
fun is_number (Const(@{const_name "HOL.divide"},_)$a$b) = is_number a andalso is_number b
|
|
|
481 |
| is_number t = can HOLogic.dest_number t
|
|
|
482 |
|
|
|
483 |
val is_number = is_number o term_of
|
|
|
484 |
|
|
|
485 |
fun proc3 phi ss ct =
|
|
|
486 |
(case term_of ct of
|
|
|
487 |
Const(@{const_name "Orderings.less"},_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
|
|
|
488 |
let
|
|
|
489 |
val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
|
|
|
490 |
val _ = map is_number [a,b,c]
|
|
|
491 |
val T = ctyp_of_term c
|
|
|
492 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_less_eq"}
|
|
|
493 |
in SOME (mk_meta_eq th) end
|
|
|
494 |
| Const(@{const_name "Orderings.less_eq"},_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
|
|
|
495 |
let
|
|
|
496 |
val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
|
|
|
497 |
val _ = map is_number [a,b,c]
|
|
|
498 |
val T = ctyp_of_term c
|
|
|
499 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_le_eq"}
|
|
|
500 |
in SOME (mk_meta_eq th) end
|
|
|
501 |
| Const("op =",_)$(Const(@{const_name "HOL.divide"},_)$_$_)$_ =>
|
|
|
502 |
let
|
|
|
503 |
val ((a,b),c) = Thm.dest_binop ct |>> Thm.dest_binop
|
|
|
504 |
val _ = map is_number [a,b,c]
|
|
|
505 |
val T = ctyp_of_term c
|
|
|
506 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "divide_eq_eq"}
|
|
|
507 |
in SOME (mk_meta_eq th) end
|
|
|
508 |
| Const(@{const_name "Orderings.less"},_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
|
|
|
509 |
let
|
|
|
510 |
val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
|
|
|
511 |
val _ = map is_number [a,b,c]
|
|
|
512 |
val T = ctyp_of_term c
|
|
|
513 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "less_divide_eq"}
|
|
|
514 |
in SOME (mk_meta_eq th) end
|
|
|
515 |
| Const(@{const_name "Orderings.less_eq"},_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
|
|
|
516 |
let
|
|
|
517 |
val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
|
|
|
518 |
val _ = map is_number [a,b,c]
|
|
|
519 |
val T = ctyp_of_term c
|
|
|
520 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "le_divide_eq"}
|
|
|
521 |
in SOME (mk_meta_eq th) end
|
|
|
522 |
| Const("op =",_)$_$(Const(@{const_name "HOL.divide"},_)$_$_) =>
|
|
|
523 |
let
|
|
|
524 |
val (a,(b,c)) = Thm.dest_binop ct ||> Thm.dest_binop
|
|
|
525 |
val _ = map is_number [a,b,c]
|
|
|
526 |
val T = ctyp_of_term c
|
|
|
527 |
val th = instantiate' [SOME T] (map SOME [a,b,c]) @{thm "eq_divide_eq"}
|
|
|
528 |
in SOME (mk_meta_eq th) end
|
|
|
529 |
| _ => NONE)
|
|
|
530 |
handle TERM _ => NONE | CTERM _ => NONE | THM _ => NONE
|
|
|
531 |
|
|
|
532 |
fun add_frac_frac_simproc ctxt =
|
|
|
533 |
make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + (?w::?'a::field)/?z"}],
|
|
|
534 |
name = "add_frac_frac_simproc",
|
|
|
535 |
proc = proc ctxt, identifier = []}
|
|
|
536 |
|
|
|
537 |
fun add_frac_num_simproc ctxt =
|
|
|
538 |
make_simproc {lhss = [@{cpat "(?x::?'a::field)/?y + ?z"}, @{cpat "?z + (?x::?'a::field)/?y"}],
|
|
|
539 |
name = "add_frac_num_simproc",
|
|
|
540 |
proc = proc2 ctxt, identifier = []}
|
|
|
541 |
|
|
|
542 |
val ord_frac_simproc =
|
|
|
543 |
make_simproc
|
|
|
544 |
{lhss = [@{cpat "(?a::(?'a::{field, ord}))/?b < ?c"},
|
|
|
545 |
@{cpat "(?a::(?'a::{field, ord}))/?b \<le> ?c"},
|
|
|
546 |
@{cpat "?c < (?a::(?'a::{field, ord}))/?b"},
|
|
|
547 |
@{cpat "?c \<le> (?a::(?'a::{field, ord}))/?b"},
|
|
|
548 |
@{cpat "?c = ((?a::(?'a::{field, ord}))/?b)"},
|
|
|
549 |
@{cpat "((?a::(?'a::{field, ord}))/ ?b) = ?c"}],
|
|
|
550 |
name = "ord_frac_simproc", proc = proc3, identifier = []}
|
|
|
551 |
|
|
|
552 |
val nat_arith = map thm ["add_nat_number_of", "diff_nat_number_of",
|
|
|
553 |
"mult_nat_number_of", "eq_nat_number_of", "less_nat_number_of"]
|
|
|
554 |
|
|
|
555 |
val comp_arith = (map thm ["Let_def", "if_False", "if_True", "add_0",
|
|
|
556 |
"add_Suc", "add_number_of_left", "mult_number_of_left",
|
|
|
557 |
"Suc_eq_add_numeral_1"])@
|
|
|
558 |
(map (fn s => thm s RS sym) ["numeral_1_eq_1", "numeral_0_eq_0"])
|
|
|
559 |
@ arith_simps@ nat_arith @ rel_simps
|
|
|
560 |
val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"},
|
|
|
561 |
@{thm "divide_Numeral1"},
|
|
|
562 |
@{thm "Ring_and_Field.divide_zero"}, @{thm "divide_Numeral0"},
|
|
|
563 |
@{thm "divide_divide_eq_left"}, @{thm "mult_frac_frac"},
|
|
|
564 |
@{thm "mult_num_frac"}, @{thm "mult_frac_num"},
|
|
|
565 |
@{thm "mult_frac_frac"}, @{thm "times_divide_eq_right"},
|
|
|
566 |
@{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"},
|
|
|
567 |
@{thm "diff_def"}, @{thm "minus_divide_left"},
|
|
|
568 |
@{thm "Numeral1_eq1_nat"}, @{thm "add_divide_distrib"} RS sym]
|
|
|
569 |
|
|
|
570 |
local
|
|
|
571 |
open Conv
|
|
|
572 |
in
|
|
|
573 |
fun comp_conv ctxt = (Simplifier.rewrite
|
|
|
574 |
(HOL_basic_ss addsimps @{thms "Groebner_Basis.comp_arith"}
|
|
|
575 |
addsimps ths addsimps comp_arith addsimps simp_thms
|
|
|
576 |
addsimprocs field_cancel_numeral_factors
|
|
|
577 |
addsimprocs [add_frac_frac_simproc ctxt, add_frac_num_simproc ctxt,
|
|
|
578 |
ord_frac_simproc]
|
|
|
579 |
addcongs [@{thm "if_weak_cong"}]))
|
|
|
580 |
then_conv (Simplifier.rewrite (HOL_basic_ss addsimps
|
|
|
581 |
[@{thm numeral_1_eq_1},@{thm numeral_0_eq_0}] @ @{thms numerals(1-2)}))
|
|
|
582 |
end
|
|
|
583 |
|
|
|
584 |
fun numeral_is_const ct =
|
|
|
585 |
case term_of ct of
|
|
|
586 |
Const (@{const_name "HOL.divide"},_) $ a $ b =>
|
|
|
587 |
numeral_is_const (Thm.dest_arg1 ct) andalso numeral_is_const (Thm.dest_arg ct)
|
|
|
588 |
| Const (@{const_name "HOL.uminus"},_)$t => numeral_is_const (Thm.dest_arg ct)
|
|
|
589 |
| t => can HOLogic.dest_number t
|
|
|
590 |
|
|
|
591 |
fun dest_const ct = case term_of ct of
|
|
|
592 |
Const (@{const_name "HOL.divide"},_) $ a $ b=>
|
|
|
593 |
Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
|
|
|
594 |
| t => Rat.rat_of_int (snd (HOLogic.dest_number t))
|
|
|
595 |
|
|
|
596 |
fun mk_const phi cT x =
|
|
|
597 |
let val (a, b) = Rat.quotient_of_rat x
|
|
|
598 |
in if b = 1 then Normalizer.mk_cnumber cT a
|
|
|
599 |
else Thm.capply
|
|
|
600 |
(Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
|
|
|
601 |
(Normalizer.mk_cnumber cT a))
|
|
|
602 |
(Normalizer.mk_cnumber cT b)
|
|
|
603 |
end
|
|
|
604 |
|
|
|
605 |
in
|
|
|
606 |
NormalizerData.funs @{thm class_fieldgb.axioms}
|
|
|
607 |
{is_const = K numeral_is_const,
|
|
|
608 |
dest_const = K dest_const,
|
|
|
609 |
mk_const = mk_const,
|
|
|
610 |
conv = K comp_conv}
|
|
|
611 |
end
|
|
|
612 |
|
|
|
613 |
*}
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
subsection {* Ferrante and Rackoff algorithm over ordered fields *}
|
|
|
617 |
|
|
|
618 |
lemma neg_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x < 0) == (x > 0))"
|
|
|
619 |
proof-
|
|
|
620 |
assume H: "c < 0"
|
|
|
621 |
have "c*x < 0 = (0/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_eq_simps)
|
|
|
622 |
also have "\<dots> = (0 < x)" by simp
|
|
|
623 |
finally show "(c*x < 0) == (x > 0)" by simp
|
|
|
624 |
qed
|
|
|
625 |
|
|
|
626 |
lemma pos_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x < 0) == (x < 0))"
|
|
|
627 |
proof-
|
|
|
628 |
assume H: "c > 0"
|
|
|
629 |
hence "c*x < 0 = (0/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_eq_simps)
|
|
|
630 |
also have "\<dots> = (0 > x)" by simp
|
|
|
631 |
finally show "(c*x < 0) == (x < 0)" by simp
|
|
|
632 |
qed
|
|
|
633 |
|
|
|
634 |
lemma neg_prod_sum_lt: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t< 0) == (x > (- 1/c)*t))"
|
|
|
635 |
proof-
|
|
|
636 |
assume H: "c < 0"
|
|
|
637 |
have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
|
|
|
638 |
also have "\<dots> = (-t/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_eq_simps)
|
|
|
639 |
also have "\<dots> = ((- 1/c)*t < x)" by simp
|
|
|
640 |
finally show "(c*x + t < 0) == (x > (- 1/c)*t)" by simp
|
|
|
641 |
qed
|
|
|
642 |
|
|
|
643 |
lemma pos_prod_sum_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t < 0) == (x < (- 1/c)*t))"
|
|
|
644 |
proof-
|
|
|
645 |
assume H: "c > 0"
|
|
|
646 |
have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
|
|
|
647 |
also have "\<dots> = (-t/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_eq_simps)
|
|
|
648 |
also have "\<dots> = ((- 1/c)*t > x)" by simp
|
|
|
649 |
finally show "(c*x + t < 0) == (x < (- 1/c)*t)" by simp
|
|
|
650 |
qed
|
|
|
651 |
|
|
|
652 |
lemma sum_lt:"((x::'a::pordered_ab_group_add) + t < 0) == (x < - t)"
|
|
|
653 |
using less_diff_eq[where a= x and b=t and c=0] by simp
|
|
|
654 |
|
|
|
655 |
lemma neg_prod_le:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x <= 0) == (x >= 0))"
|
|
|
656 |
proof-
|
|
|
657 |
assume H: "c < 0"
|
|
|
658 |
have "c*x <= 0 = (0/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_eq_simps)
|
|
|
659 |
also have "\<dots> = (0 <= x)" by simp
|
|
|
660 |
finally show "(c*x <= 0) == (x >= 0)" by simp
|
|
|
661 |
qed
|
|
|
662 |
|
|
|
663 |
lemma pos_prod_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x <= 0) == (x <= 0))"
|
|
|
664 |
proof-
|
|
|
665 |
assume H: "c > 0"
|
|
|
666 |
hence "c*x <= 0 = (0/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_eq_simps)
|
|
|
667 |
also have "\<dots> = (0 >= x)" by simp
|
|
|
668 |
finally show "(c*x <= 0) == (x <= 0)" by simp
|
|
|
669 |
qed
|
|
|
670 |
|
|
|
671 |
lemma neg_prod_sum_le: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t <= 0) == (x >= (- 1/c)*t))"
|
|
|
672 |
proof-
|
|
|
673 |
assume H: "c < 0"
|
|
|
674 |
have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
|
|
|
675 |
also have "\<dots> = (-t/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_eq_simps)
|
|
|
676 |
also have "\<dots> = ((- 1/c)*t <= x)" by simp
|
|
|
677 |
finally show "(c*x + t <= 0) == (x >= (- 1/c)*t)" by simp
|
|
|
678 |
qed
|
|
|
679 |
|
|
|
680 |
lemma pos_prod_sum_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t <= 0) == (x <= (- 1/c)*t))"
|
|
|
681 |
proof-
|
|
|
682 |
assume H: "c > 0"
|
|
|
683 |
have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
|
|
|
684 |
also have "\<dots> = (-t/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_eq_simps)
|
|
|
685 |
also have "\<dots> = ((- 1/c)*t >= x)" by simp
|
|
|
686 |
finally show "(c*x + t <= 0) == (x <= (- 1/c)*t)" by simp
|
|
|
687 |
qed
|
|
|
688 |
|
|
|
689 |
lemma sum_le:"((x::'a::pordered_ab_group_add) + t <= 0) == (x <= - t)"
|
|
|
690 |
using le_diff_eq[where a= x and b=t and c=0] by simp
|
|
|
691 |
|
|
|
692 |
lemma nz_prod_eq:"(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x = 0) == (x = 0))" by simp
|
|
|
693 |
lemma nz_prod_sum_eq: "(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x + t = 0) == (x = (- 1/c)*t))"
|
|
|
694 |
proof-
|
|
|
695 |
assume H: "c \<noteq> 0"
|
|
|
696 |
have "c*x + t = 0 = (c*x = -t)" by (subst eq_iff_diff_eq_0 [of "c*x" "-t"], simp)
|
|
|
697 |
also have "\<dots> = (x = -t/c)" by (simp only: nonzero_eq_divide_eq[OF H] ring_eq_simps)
|
|
|
698 |
finally show "(c*x + t = 0) == (x = (- 1/c)*t)" by simp
|
|
|
699 |
qed
|
|
|
700 |
lemma sum_eq:"((x::'a::pordered_ab_group_add) + t = 0) == (x = - t)"
|
|
|
701 |
using eq_diff_eq[where a= x and b=t and c=0] by simp
|
|
|
702 |
|
|
|
703 |
|
|
|
704 |
interpretation class_ordered_field_dense_linear_order: dense_linear_order
|
|
|
705 |
["op <=" "op <"
|
|
|
706 |
"\<lambda> x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)"]
|
|
|
707 |
proof (unfold_locales,
|
|
|
708 |
simp_all only: ordered_field_no_ub ordered_field_no_lb,
|
|
|
709 |
auto simp add: linorder_not_le)
|
|
|
710 |
fix x y::'a assume lt: "x < y"
|
|
|
711 |
from less_half_sum[OF lt] show "x < (x + y) /2" by simp
|
|
|
712 |
next
|
|
|
713 |
fix x y::'a assume lt: "x < y"
|
|
|
714 |
from gt_half_sum[OF lt] show "(x + y) /2 < y" by simp
|
|
|
715 |
qed
|
|
|
716 |
|
|
|
717 |
declaration{*
|
|
|
718 |
let
|
|
|
719 |
fun earlier [] x y = false
|
|
|
720 |
| earlier (h::t) x y =
|
|
|
721 |
if h aconvc y then false else if h aconvc x then true else earlier t x y;
|
|
|
722 |
|
|
|
723 |
fun dest_frac ct = case term_of ct of
|
|
|
724 |
Const (@{const_name "HOL.divide"},_) $ a $ b=>
|
|
|
725 |
Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
|
|
|
726 |
| t => Rat.rat_of_int (snd (HOLogic.dest_number t))
|
|
|
727 |
|
|
|
728 |
fun mk_frac phi cT x =
|
|
|
729 |
let val (a, b) = Rat.quotient_of_rat x
|
|
|
730 |
in if b = 1 then Normalizer.mk_cnumber cT a
|
|
|
731 |
else Thm.capply
|
|
|
732 |
(Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
|
|
|
733 |
(Normalizer.mk_cnumber cT a))
|
|
|
734 |
(Normalizer.mk_cnumber cT b)
|
|
|
735 |
end
|
|
|
736 |
|
|
|
737 |
fun whatis x ct = case term_of ct of
|
|
|
738 |
Const(@{const_name "HOL.plus"}, _)$(Const(@{const_name "HOL.times"},_)$_$y)$_ =>
|
|
|
739 |
if y aconv term_of x then ("c*x+t",[(funpow 2 Thm.dest_arg1) ct, Thm.dest_arg ct])
|
|
|
740 |
else ("Nox",[])
|
|
|
741 |
| Const(@{const_name "HOL.plus"}, _)$y$_ =>
|
|
|
742 |
if y aconv term_of x then ("x+t",[Thm.dest_arg ct])
|
|
|
743 |
else ("Nox",[])
|
|
|
744 |
| Const(@{const_name "HOL.times"}, _)$_$y =>
|
|
|
745 |
if y aconv term_of x then ("c*x",[Thm.dest_arg1 ct])
|
|
|
746 |
else ("Nox",[])
|
|
|
747 |
| t => if t aconv term_of x then ("x",[]) else ("Nox",[]);
|
|
|
748 |
|
|
|
749 |
fun xnormalize_conv ctxt [] ct = reflexive ct
|
|
|
750 |
| xnormalize_conv ctxt (vs as (x::_)) ct =
|
|
|
751 |
case term_of ct of
|
|
|
752 |
Const(@{const_name "Orderings.less"},_)$_$Const(@{const_name "HOL.zero"},_) =>
|
|
|
753 |
(case whatis x (Thm.dest_arg1 ct) of
|
|
|
754 |
("c*x+t",[c,t]) =>
|
|
|
755 |
let
|
|
|
756 |
val cr = dest_frac c
|
|
|
757 |
val clt = Thm.dest_fun2 ct
|
|
|
758 |
val cz = Thm.dest_arg ct
|
|
|
759 |
val neg = cr </ Rat.zero
|
|
|
760 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
761 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
762 |
(if neg then Thm.capply (Thm.capply clt c) cz
|
|
|
763 |
else Thm.capply (Thm.capply clt cz) c))
|
|
|
764 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
765 |
val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x,t])
|
|
|
766 |
(if neg then @{thm neg_prod_sum_lt} else @{thm pos_prod_sum_lt})) cth
|
|
|
767 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
768 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
769 |
in rth end
|
|
|
770 |
| ("x+t",[t]) =>
|
|
|
771 |
let
|
|
|
772 |
val T = ctyp_of_term x
|
|
|
773 |
val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_lt"}
|
|
|
774 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
775 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
776 |
in rth end
|
|
|
777 |
| ("c*x",[c]) =>
|
|
|
778 |
let
|
|
|
779 |
val cr = dest_frac c
|
|
|
780 |
val clt = Thm.dest_fun2 ct
|
|
|
781 |
val cz = Thm.dest_arg ct
|
|
|
782 |
val neg = cr </ Rat.zero
|
|
|
783 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
784 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
785 |
(if neg then Thm.capply (Thm.capply clt c) cz
|
|
|
786 |
else Thm.capply (Thm.capply clt cz) c))
|
|
|
787 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
788 |
val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
|
|
|
789 |
(if neg then @{thm neg_prod_lt} else @{thm pos_prod_lt})) cth
|
|
|
790 |
val rth = th
|
|
|
791 |
in rth end
|
|
|
792 |
| _ => reflexive ct)
|
|
|
793 |
|
|
|
794 |
|
|
|
795 |
| Const(@{const_name "Orderings.less_eq"},_)$_$Const(@{const_name "HOL.zero"},_) =>
|
|
|
796 |
(case whatis x (Thm.dest_arg1 ct) of
|
|
|
797 |
("c*x+t",[c,t]) =>
|
|
|
798 |
let
|
|
|
799 |
val T = ctyp_of_term x
|
|
|
800 |
val cr = dest_frac c
|
|
|
801 |
val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
|
|
|
802 |
val cz = Thm.dest_arg ct
|
|
|
803 |
val neg = cr </ Rat.zero
|
|
|
804 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
805 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
806 |
(if neg then Thm.capply (Thm.capply clt c) cz
|
|
|
807 |
else Thm.capply (Thm.capply clt cz) c))
|
|
|
808 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
809 |
val th = implies_elim (instantiate' [SOME T] (map SOME [c,x,t])
|
|
|
810 |
(if neg then @{thm neg_prod_sum_le} else @{thm pos_prod_sum_le})) cth
|
|
|
811 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
812 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
813 |
in rth end
|
|
|
814 |
| ("x+t",[t]) =>
|
|
|
815 |
let
|
|
|
816 |
val T = ctyp_of_term x
|
|
|
817 |
val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_le"}
|
|
|
818 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
819 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
820 |
in rth end
|
|
|
821 |
| ("c*x",[c]) =>
|
|
|
822 |
let
|
|
|
823 |
val T = ctyp_of_term x
|
|
|
824 |
val cr = dest_frac c
|
|
|
825 |
val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
|
|
|
826 |
val cz = Thm.dest_arg ct
|
|
|
827 |
val neg = cr </ Rat.zero
|
|
|
828 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
829 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
830 |
(if neg then Thm.capply (Thm.capply clt c) cz
|
|
|
831 |
else Thm.capply (Thm.capply clt cz) c))
|
|
|
832 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
833 |
val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
|
|
|
834 |
(if neg then @{thm neg_prod_le} else @{thm pos_prod_le})) cth
|
|
|
835 |
val rth = th
|
|
|
836 |
in rth end
|
|
|
837 |
| _ => reflexive ct)
|
|
|
838 |
|
|
|
839 |
| Const("op =",_)$_$Const(@{const_name "HOL.zero"},_) =>
|
|
|
840 |
(case whatis x (Thm.dest_arg1 ct) of
|
|
|
841 |
("c*x+t",[c,t]) =>
|
|
|
842 |
let
|
|
|
843 |
val T = ctyp_of_term x
|
|
|
844 |
val cr = dest_frac c
|
|
|
845 |
val ceq = Thm.dest_fun2 ct
|
|
|
846 |
val cz = Thm.dest_arg ct
|
|
|
847 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
848 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
849 |
(Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
|
|
|
850 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
851 |
val th = implies_elim
|
|
|
852 |
(instantiate' [SOME T] (map SOME [c,x,t]) @{thm nz_prod_sum_eq}) cth
|
|
|
853 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
854 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
855 |
in rth end
|
|
|
856 |
| ("x+t",[t]) =>
|
|
|
857 |
let
|
|
|
858 |
val T = ctyp_of_term x
|
|
|
859 |
val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_eq"}
|
|
|
860 |
val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
|
|
|
861 |
(Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
|
|
|
862 |
in rth end
|
|
|
863 |
| ("c*x",[c]) =>
|
|
|
864 |
let
|
|
|
865 |
val T = ctyp_of_term x
|
|
|
866 |
val cr = dest_frac c
|
|
|
867 |
val ceq = Thm.dest_fun2 ct
|
|
|
868 |
val cz = Thm.dest_arg ct
|
|
|
869 |
val cthp = Simplifier.rewrite (local_simpset_of ctxt)
|
|
|
870 |
(Thm.capply @{cterm "Trueprop"}
|
|
|
871 |
(Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
|
|
|
872 |
val cth = equal_elim (symmetric cthp) TrueI
|
|
|
873 |
val rth = implies_elim
|
|
|
874 |
(instantiate' [SOME T] (map SOME [c,x]) @{thm nz_prod_eq}) cth
|
|
|
875 |
in rth end
|
|
|
876 |
| _ => reflexive ct);
|
|
|
877 |
|
|
|
878 |
local
|
|
|
879 |
val less_iff_diff_less_0 = mk_meta_eq @{thm "less_iff_diff_less_0"}
|
|
|
880 |
val le_iff_diff_le_0 = mk_meta_eq @{thm "le_iff_diff_le_0"}
|
|
|
881 |
val eq_iff_diff_eq_0 = mk_meta_eq @{thm "eq_iff_diff_eq_0"}
|
|
|
882 |
in
|
|
|
883 |
fun field_isolate_conv phi ctxt vs ct = case term_of ct of
|
|
|
884 |
Const(@{const_name "Orderings.less"},_)$a$b =>
|
|
|
885 |
let val (ca,cb) = Thm.dest_binop ct
|
|
|
886 |
val T = ctyp_of_term ca
|
|
|
887 |
val th = instantiate' [SOME T] [SOME ca, SOME cb] less_iff_diff_less_0
|
|
|
888 |
val nth = Conv.fconv_rule
|
|
|
889 |
(Conv.arg_conv (Conv.arg1_conv
|
|
|
890 |
(Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
|
|
|
891 |
val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
|
|
|
892 |
in rth end
|
|
|
893 |
| Const(@{const_name "Orderings.less_eq"},_)$a$b =>
|
|
|
894 |
let val (ca,cb) = Thm.dest_binop ct
|
|
|
895 |
val T = ctyp_of_term ca
|
|
|
896 |
val th = instantiate' [SOME T] [SOME ca, SOME cb] le_iff_diff_le_0
|
|
|
897 |
val nth = Conv.fconv_rule
|
|
|
898 |
(Conv.arg_conv (Conv.arg1_conv
|
|
|
899 |
(Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
|
|
|
900 |
val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
|
|
|
901 |
in rth end
|
|
|
902 |
|
|
|
903 |
| Const("op =",_)$a$b =>
|
|
|
904 |
let val (ca,cb) = Thm.dest_binop ct
|
|
|
905 |
val T = ctyp_of_term ca
|
|
|
906 |
val th = instantiate' [SOME T] [SOME ca, SOME cb] eq_iff_diff_eq_0
|
|
|
907 |
val nth = Conv.fconv_rule
|
|
|
908 |
(Conv.arg_conv (Conv.arg1_conv
|
|
|
909 |
(Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
|
|
|
910 |
val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
|
|
|
911 |
in rth end
|
|
|
912 |
| @{term "Not"} $(Const("op =",_)$a$b) => Conv.arg_conv (field_isolate_conv phi ctxt vs) ct
|
|
|
913 |
| _ => reflexive ct
|
|
|
914 |
end;
|
|
|
915 |
|
|
|
916 |
fun classfield_whatis phi =
|
|
|
917 |
let
|
|
|
918 |
fun h x t =
|
|
|
919 |
case term_of t of
|
|
|
920 |
Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
|
|
|
921 |
else Ferrante_Rackoff_Data.Nox
|
|
|
922 |
| @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
|
|
|
923 |
else Ferrante_Rackoff_Data.Nox
|
|
|
924 |
| Const(@{const_name "Orderings.less"},_)$y$z =>
|
|
|
925 |
if term_of x aconv y then Ferrante_Rackoff_Data.Lt
|
|
|
926 |
else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
|
|
|
927 |
else Ferrante_Rackoff_Data.Nox
|
|
|
928 |
| Const (@{const_name "Orderings.less_eq"},_)$y$z =>
|
|
|
929 |
if term_of x aconv y then Ferrante_Rackoff_Data.Le
|
|
|
930 |
else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
|
|
|
931 |
else Ferrante_Rackoff_Data.Nox
|
|
|
932 |
| _ => Ferrante_Rackoff_Data.Nox
|
|
|
933 |
in h end;
|
|
|
934 |
fun class_field_ss phi =
|
|
|
935 |
HOL_basic_ss addsimps ([@{thm "linorder_not_less"}, @{thm "linorder_not_le"}])
|
|
|
936 |
addsplits [@{thm "abs_split"},@{thm "split_max"}, @{thm "split_min"}]
|
|
|
937 |
|
|
|
938 |
in
|
|
|
939 |
Ferrante_Rackoff_Data.funs @{thm "class_ordered_field_dense_linear_order.ferrack_axiom"}
|
|
|
940 |
{isolate_conv = field_isolate_conv, whatis = classfield_whatis, simpset = class_field_ss}
|
|
|
941 |
end
|
|
|
942 |
*}
|
|
|
943 |
|
|
|
944 |
|
|
|
945 |
subsection {* Decision Procedure for Presburger Arithmetic *}
|
|
|
946 |
|
|
|
947 |
setup CooperData.setup
|
|
|
948 |
|
|
|
949 |
subsection{* The @{text "-\<infinity>"} and @{text "+\<infinity>"} Properties *}
|
|
|
950 |
|
|
|
951 |
lemma minf:
|
|
|
952 |
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk>
|
|
|
953 |
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<and> Q x) = (P' x \<and> Q' x)"
|
|
|
954 |
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk>
|
|
|
955 |
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<or> Q x) = (P' x \<or> Q' x)"
|
|
|
956 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False"
|
|
|
957 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True"
|
|
|
958 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True"
|
|
|
959 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
|
|
|
960 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
|
|
|
961 |
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
|
|
|
962 |
"\<exists>z.\<forall>(x::'a::{linorder,plus,times})<z. (d dvd x + s) = (d dvd x + s)"
|
|
|
963 |
"\<exists>z.\<forall>(x::'a::{linorder,plus,times})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
|
|
|
964 |
"\<exists>z.\<forall>x<z. F = F"
|
|
|
965 |
by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastsimp)+) simp_all
|
|
|
966 |
|
|
|
967 |
lemma pinf:
|
|
|
968 |
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk>
|
|
|
969 |
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<and> Q x) = (P' x \<and> Q' x)"
|
|
|
970 |
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk>
|
|
|
971 |
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<or> Q x) = (P' x \<or> Q' x)"
|
|
|
972 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False"
|
|
|
973 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True"
|
|
|
974 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x < t) = False"
|
|
|
975 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False"
|
|
|
976 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
|
|
|
977 |
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
|
|
|
978 |
"\<exists>z.\<forall>(x::'a::{linorder,plus,times})>z. (d dvd x + s) = (d dvd x + s)"
|
|
|
979 |
"\<exists>z.\<forall>(x::'a::{linorder,plus,times})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
|
|
|
980 |
"\<exists>z.\<forall>x>z. F = F"
|
|
|
981 |
by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastsimp)+) simp_all
|
|
|
982 |
|
|
|
983 |
lemma inf_period:
|
|
|
984 |
"\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk>
|
|
|
985 |
\<Longrightarrow> \<forall>x k. (P x \<and> Q x) = (P (x - k*D) \<and> Q (x - k*D))"
|
|
|
986 |
"\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk>
|
|
|
987 |
\<Longrightarrow> \<forall>x k. (P x \<or> Q x) = (P (x - k*D) \<or> Q (x - k*D))"
|
|
|
988 |
"(d::'a::{comm_ring}) dvd D \<Longrightarrow> \<forall>x k. (d dvd x + t) = (d dvd (x - k*D) + t)"
|
|
|
989 |
"(d::'a::{comm_ring}) dvd D \<Longrightarrow> \<forall>x k. (\<not>d dvd x + t) = (\<not>d dvd (x - k*D) + t)"
|
|
|
990 |
"\<forall>x k. F = F"
|
|
|
991 |
by simp_all
|
|
|
992 |
(clarsimp simp add: dvd_def, rule iffI, clarsimp,rule_tac x = "kb - ka*k" in exI,
|
|
|
993 |
simp add: ring_eq_simps, clarsimp,rule_tac x = "kb + ka*k" in exI,simp add: ring_eq_simps)+
|
|
|
994 |
|
|
|
995 |
section{* The A and B sets *}
|
|
|
996 |
lemma bset:
|
|
|
997 |
"\<lbrakk>\<forall>x.(\<forall>j \<in> {1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
|
|
|
998 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow>
|
|
|
999 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> (P x \<and> Q x) \<longrightarrow> (P(x - D) \<and> Q (x - D))"
|
|
|
1000 |
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
|
|
|
1001 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow>
|
|
|
1002 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (P x \<or> Q x) \<longrightarrow> (P(x - D) \<or> Q (x - D))"
|
|
|
1003 |
"\<lbrakk>D>0; t - 1\<in> B\<rbrakk> \<Longrightarrow> (\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x - D = t))"
|
|
|
1004 |
"\<lbrakk>D>0 ; t \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x - D \<noteq> t))"
|
|
|
1005 |
"D>0 \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x < t) \<longrightarrow> (x - D < t))"
|
|
|
1006 |
"D>0 \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x - D \<le> t))"
|
|
|
1007 |
"\<lbrakk>D>0 ; t \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x > t) \<longrightarrow> (x - D > t))"
|
|
|
1008 |
"\<lbrakk>D>0 ; t - 1 \<in> B\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x - D \<ge> t))"
|
|
|
1009 |
"d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x - D) + t))"
|
|
|
1010 |
"d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not> d dvd (x - D) + t))"
|
|
|
1011 |
"\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> F \<longrightarrow> F"
|
|
|
1012 |
proof (blast, blast)
|
|
|
1013 |
assume dp: "D > 0" and tB: "t - 1\<in> B"
|
|
|
1014 |
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x - D = t))"
|
|
|
1015 |
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t - 1"])
|
|
|
1016 |
using dp tB by simp_all
|
|
|
1017 |
next
|
|
|
1018 |
assume dp: "D > 0" and tB: "t \<in> B"
|
|
|
1019 |
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x - D \<noteq> t))"
|
|
|
1020 |
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])
|
|
|
1021 |
using dp tB by simp_all
|
|
|
1022 |
next
|
|
|
1023 |
assume dp: "D > 0" thus "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x < t) \<longrightarrow> (x - D < t))" by arith
|
|
|
1024 |
next
|
|
|
1025 |
assume dp: "D > 0" thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x - D \<le> t)" by arith
|
|
|
1026 |
next
|
|
|
1027 |
assume dp: "D > 0" and tB:"t \<in> B"
|
|
|
1028 |
{fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j" and g: "x > t" and ng: "\<not> (x - D) > t"
|
|
|
1029 |
hence "x -t \<le> D" and "1 \<le> x - t" by simp+
|
|
|
1030 |
hence "\<exists>j \<in> {1 .. D}. x - t = j" by auto
|
|
|
1031 |
hence "\<exists>j \<in> {1 .. D}. x = t + j" by (simp add: ring_eq_simps)
|
|
|
1032 |
with nob tB have "False" by simp}
|
|
|
1033 |
thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x > t) \<longrightarrow> (x - D > t)" by blast
|
|
|
1034 |
next
|
|
|
1035 |
assume dp: "D > 0" and tB:"t - 1\<in> B"
|
|
|
1036 |
{fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j" and g: "x \<ge> t" and ng: "\<not> (x - D) \<ge> t"
|
|
|
1037 |
hence "x - (t - 1) \<le> D" and "1 \<le> x - (t - 1)" by simp+
|
|
|
1038 |
hence "\<exists>j \<in> {1 .. D}. x - (t - 1) = j" by auto
|
|
|
1039 |
hence "\<exists>j \<in> {1 .. D}. x = (t - 1) + j" by (simp add: ring_eq_simps)
|
|
|
1040 |
with nob tB have "False" by simp}
|
|
|
1041 |
thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x - D \<ge> t)" by blast
|
|
|
1042 |
next
|
|
|
1043 |
assume d: "d dvd D"
|
|
|
1044 |
{fix x assume H: "d dvd x + t" with d have "d dvd (x - D) + t"
|
|
|
1045 |
by (clarsimp simp add: dvd_def,rule_tac x= "ka - k" in exI,simp add: ring_eq_simps)}
|
|
|
1046 |
thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x - D) + t)" by simp
|
|
|
1047 |
next
|
|
|
1048 |
assume d: "d dvd D"
|
|
|
1049 |
{fix x assume H: "\<not>(d dvd x + t)" with d have "\<not>d dvd (x - D) + t"
|
|
|
1050 |
by (clarsimp simp add: dvd_def,erule_tac x= "ka + k" in allE,simp add: ring_eq_simps)}
|
|
|
1051 |
thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not>d dvd (x - D) + t)" by auto
|
|
|
1052 |
qed blast
|
|
|
1053 |
|
|
|
1054 |
lemma aset:
|
|
|
1055 |
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
|
|
|
1056 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow>
|
|
|
1057 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j) \<longrightarrow> (P x \<and> Q x) \<longrightarrow> (P(x + D) \<and> Q (x + D))"
|
|
|
1058 |
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
|
|
|
1059 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow>
|
|
|
1060 |
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (P x \<or> Q x) \<longrightarrow> (P(x + D) \<or> Q (x + D))"
|
|
|
1061 |
"\<lbrakk>D>0; t + 1\<in> A\<rbrakk> \<Longrightarrow> (\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))"
|
|
|
1062 |
"\<lbrakk>D>0 ; t \<in> A\<rbrakk> \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x + D \<noteq> t))"
|
|
|
1063 |
"\<lbrakk>D>0; t\<in> A\<rbrakk> \<Longrightarrow>(\<forall>(x::int). (\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x < t) \<longrightarrow> (x + D < t))"
|
|
|
1064 |
"\<lbrakk>D>0; t + 1 \<in> A\<rbrakk> \<Longrightarrow> (\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x + D \<le> t))"
|
|
|
1065 |
"D>0 \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x > t) \<longrightarrow> (x + D > t))"
|
|
|
1066 |
"D>0 \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x + D \<ge> t))"
|
|
|
1067 |
"d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x + D) + t))"
|
|
|
1068 |
"d dvd D \<Longrightarrow>(\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not> d dvd (x + D) + t))"
|
|
|
1069 |
"\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j) \<longrightarrow> F \<longrightarrow> F"
|
|
|
1070 |
proof (blast, blast)
|
|
|
1071 |
assume dp: "D > 0" and tA: "t + 1 \<in> A"
|
|
|
1072 |
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))"
|
|
|
1073 |
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t + 1"])
|
|
|
1074 |
using dp tA by simp_all
|
|
|
1075 |
next
|
|
|
1076 |
assume dp: "D > 0" and tA: "t \<in> A"
|
|
|
1077 |
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<noteq> t) \<longrightarrow> (x + D \<noteq> t))"
|
|
|
1078 |
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])
|
|
|
1079 |
using dp tA by simp_all
|
|
|
1080 |
next
|
|
|
1081 |
assume dp: "D > 0" thus "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x > t) \<longrightarrow> (x + D > t))" by arith
|
|
|
1082 |
next
|
|
|
1083 |
assume dp: "D > 0" thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<ge> t) \<longrightarrow> (x + D \<ge> t)" by arith
|
|
|
1084 |
next
|
|
|
1085 |
assume dp: "D > 0" and tA:"t \<in> A"
|
|
|
1086 |
{fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j" and g: "x < t" and ng: "\<not> (x + D) < t"
|
|
|
1087 |
hence "t - x \<le> D" and "1 \<le> t - x" by simp+
|
|
|
1088 |
hence "\<exists>j \<in> {1 .. D}. t - x = j" by auto
|
|
|
1089 |
hence "\<exists>j \<in> {1 .. D}. x = t - j" by (auto simp add: ring_eq_simps)
|
|
|
1090 |
with nob tA have "False" by simp}
|
|
|
1091 |
thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x < t) \<longrightarrow> (x + D < t)" by blast
|
|
|
1092 |
next
|
|
|
1093 |
assume dp: "D > 0" and tA:"t + 1\<in> A"
|
|
|
1094 |
{fix x assume nob: "\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j" and g: "x \<le> t" and ng: "\<not> (x + D) \<le> t"
|
|
|
1095 |
hence "(t + 1) - x \<le> D" and "1 \<le> (t + 1) - x" by (simp_all add: ring_eq_simps)
|
|
|
1096 |
hence "\<exists>j \<in> {1 .. D}. (t + 1) - x = j" by auto
|
|
|
1097 |
hence "\<exists>j \<in> {1 .. D}. x = (t + 1) - j" by (auto simp add: ring_eq_simps)
|
|
|
1098 |
with nob tA have "False" by simp}
|
|
|
1099 |
thus "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x \<le> t) \<longrightarrow> (x + D \<le> t)" by blast
|
|
|
1100 |
next
|
|
|
1101 |
assume d: "d dvd D"
|
|
|
1102 |
{fix x assume H: "d dvd x + t" with d have "d dvd (x + D) + t"
|
|
|
1103 |
by (clarsimp simp add: dvd_def,rule_tac x= "ka + k" in exI,simp add: ring_eq_simps)}
|
|
|
1104 |
thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (d dvd x+t) \<longrightarrow> (d dvd (x + D) + t)" by simp
|
|
|
1105 |
next
|
|
|
1106 |
assume d: "d dvd D"
|
|
|
1107 |
{fix x assume H: "\<not>(d dvd x + t)" with d have "\<not>d dvd (x + D) + t"
|
|
|
1108 |
by (clarsimp simp add: dvd_def,erule_tac x= "ka - k" in allE,simp add: ring_eq_simps)}
|
|
|
1109 |
thus "\<forall>(x::int).(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (\<not>d dvd x+t) \<longrightarrow> (\<not>d dvd (x + D) + t)" by auto
|
|
|
1110 |
qed blast
|
|
|
1111 |
|
|
|
1112 |
subsection{* Cooper's Theorem @{text "-\<infinity>"} and @{text "+\<infinity>"} Version *}
|
|
|
1113 |
|
|
|
1114 |
subsubsection{* First some trivial facts about periodic sets or predicates *}
|
|
|
1115 |
lemma periodic_finite_ex:
|
|
|
1116 |
assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
|
|
|
1117 |
shows "(EX x. P x) = (EX j : {1..d}. P j)"
|
|
|
1118 |
(is "?LHS = ?RHS")
|
|
|
1119 |
proof
|
|
|
1120 |
assume ?LHS
|
|
|
1121 |
then obtain x where P: "P x" ..
|
|
|
1122 |
have "x mod d = x - (x div d)*d" by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
|
|
|
1123 |
hence Pmod: "P x = P(x mod d)" using modd by simp
|
|
|
1124 |
show ?RHS
|
|
|
1125 |
proof (cases)
|
|
|
1126 |
assume "x mod d = 0"
|
|
|
1127 |
hence "P 0" using P Pmod by simp
|
|
|
1128 |
moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
|
|
|
1129 |
ultimately have "P d" by simp
|
|
|
1130 |
moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
|
|
|
1131 |
ultimately show ?RHS ..
|
|
|
1132 |
next
|
|
|
1133 |
assume not0: "x mod d \<noteq> 0"
|
|
|
1134 |
have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
|
|
|
1135 |
moreover have "x mod d : {1..d}"
|
|
|
1136 |
proof -
|
|
|
1137 |
from dpos have "0 \<le> x mod d" by(rule pos_mod_sign)
|
|
|
1138 |
moreover from dpos have "x mod d < d" by(rule pos_mod_bound)
|
|
|
1139 |
ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
|
|
|
1140 |
qed
|
|
|
1141 |
ultimately show ?RHS ..
|
|
|
1142 |
qed
|
|
|
1143 |
qed auto
|
|
|
1144 |
|
|
|
1145 |
subsubsection{* The @{text "-\<infinity>"} Version*}
|
|
|
1146 |
|
|
|
1147 |
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
|
|
|
1148 |
by(induct rule: int_gr_induct,simp_all add:int_distrib)
|
|
|
1149 |
|
|
|
1150 |
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
|
|
|
1151 |
by(induct rule: int_gr_induct, simp_all add:int_distrib)
|
|
|
1152 |
|
|
|
1153 |
theorem int_induct[case_names base step1 step2]:
|
|
|
1154 |
assumes
|
|
|
1155 |
base: "P(k::int)" and step1: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)" and
|
|
|
1156 |
step2: "\<And>i. \<lbrakk>k \<ge> i; P i\<rbrakk> \<Longrightarrow> P(i - 1)"
|
|
|
1157 |
shows "P i"
|
|
|
1158 |
proof -
|
|
|
1159 |
have "i \<le> k \<or> i\<ge> k" by arith
|
|
|
1160 |
thus ?thesis using prems int_ge_induct[where P="P" and k="k" and i="i"] int_le_induct[where P="P" and k="k" and i="i"] by blast
|
|
|
1161 |
qed
|
|
|
1162 |
|
|
|
1163 |
lemma decr_mult_lemma:
|
|
|
1164 |
assumes dpos: "(0::int) < d" and minus: "\<forall>x. P x \<longrightarrow> P(x - d)" and knneg: "0 <= k"
|
|
|
1165 |
shows "ALL x. P x \<longrightarrow> P(x - k*d)"
|
|
|
1166 |
using knneg
|
|
|
1167 |
proof (induct rule:int_ge_induct)
|
|
|
1168 |
case base thus ?case by simp
|
|
|
1169 |
next
|
|
|
1170 |
case (step i)
|
|
|
1171 |
{fix x
|
|
|
1172 |
have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
|
|
|
1173 |
also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)" using minus[THEN spec, of "x - i * d"]
|
|
|
1174 |
by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
|
|
|
1175 |
ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}
|
|
|
1176 |
thus ?case ..
|
|
|
1177 |
qed
|
|
|
1178 |
|
|
|
1179 |
lemma minusinfinity:
|
|
|
1180 |
assumes dpos: "0 < d" and
|
|
|
1181 |
P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
|
|
|
1182 |
shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
|
|
|
1183 |
proof
|
|
|
1184 |
assume eP1: "EX x. P1 x"
|
|
|
1185 |
then obtain x where P1: "P1 x" ..
|
|
|
1186 |
from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
|
|
|
1187 |
let ?w = "x - (abs(x-z)+1) * d"
|
|
|
1188 |
from dpos have w: "?w < z" by(rule decr_lemma)
|
|
|
1189 |
have "P1 x = P1 ?w" using P1eqP1 by blast
|
|
|
1190 |
also have "\<dots> = P(?w)" using w P1eqP by blast
|
|
|
1191 |
finally have "P ?w" using P1 by blast
|
|
|
1192 |
thus "EX x. P x" ..
|
|
|
1193 |
qed
|
|
|
1194 |
|
|
|
1195 |
lemma cpmi:
|
|
|
1196 |
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x< z. P x = P' x"
|
|
|
1197 |
and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> B. x \<noteq> b+j) --> P (x) --> P (x - D)"
|
|
|
1198 |
and pd: "\<forall> x k. P' x = P' (x-k*D)"
|
|
|
1199 |
shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j) | (\<exists> j \<in> {1..D}.\<exists> b\<in> B. P (b+j)))"
|
|
|
1200 |
(is "?L = (?R1 \<or> ?R2)")
|
|
|
1201 |
proof-
|
|
|
1202 |
{assume "?R2" hence "?L" by blast}
|
|
|
1203 |
moreover
|
|
|
1204 |
{assume H:"?R1" hence "?L" using minusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
|
|
|
1205 |
moreover
|
|
|
1206 |
{ fix x
|
|
|
1207 |
assume P: "P x" and H: "\<not> ?R2"
|
|
|
1208 |
{fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))" and P: "P y"
|
|
|
1209 |
hence "~(EX (j::int) : {1..D}. EX (b::int) : B. y = b+j)" by auto
|
|
|
1210 |
with nb P have "P (y - D)" by auto }
|
|
|
1211 |
hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D)" by blast
|
|
|
1212 |
with H P have th: " \<forall>x. P x \<longrightarrow> P (x - D)" by auto
|
|
|
1213 |
from p1 obtain z where z: "ALL x. x < z --> (P x = P' x)" by blast
|
|
|
1214 |
let ?y = "x - (\<bar>x - z\<bar> + 1)*D"
|
|
|
1215 |
have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
|
|
|
1216 |
from dp have yz: "?y < z" using decr_lemma[OF dp] by simp
|
|
|
1217 |
from z[rule_format, OF yz] decr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto
|
|
|
1218 |
with periodic_finite_ex[OF dp pd]
|
|
|
1219 |
have "?R1" by blast}
|
|
|
1220 |
ultimately show ?thesis by blast
|
|
|
1221 |
qed
|
|
|
1222 |
|
|
|
1223 |
subsubsection {* The @{text "+\<infinity>"} Version*}
|
|
|
1224 |
|
|
|
1225 |
lemma plusinfinity:
|
|
|
1226 |
assumes dpos: "(0::int) < d" and
|
|
|
1227 |
P1eqP1: "\<forall>x k. P' x = P'(x - k*d)" and ePeqP1: "\<exists> z. \<forall> x>z. P x = P' x"
|
|
|
1228 |
shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)"
|
|
|
1229 |
proof
|
|
|
1230 |
assume eP1: "EX x. P' x"
|
|
|
1231 |
then obtain x where P1: "P' x" ..
|
|
|
1232 |
from ePeqP1 obtain z where P1eqP: "\<forall>x>z. P x = P' x" ..
|
|
|
1233 |
let ?w' = "x + (abs(x-z)+1) * d"
|
|
|
1234 |
let ?w = "x - (-(abs(x-z) + 1))*d"
|
|
|
1235 |
have ww'[simp]: "?w = ?w'" by (simp add: ring_eq_simps)
|
|
|
1236 |
from dpos have w: "?w > z" by(simp only: ww' incr_lemma)
|
|
|
1237 |
hence "P' x = P' ?w" using P1eqP1 by blast
|
|
|
1238 |
also have "\<dots> = P(?w)" using w P1eqP by blast
|
|
|
1239 |
finally have "P ?w" using P1 by blast
|
|
|
1240 |
thus "EX x. P x" ..
|
|
|
1241 |
qed
|
|
|
1242 |
|
|
|
1243 |
lemma incr_mult_lemma:
|
|
|
1244 |
assumes dpos: "(0::int) < d" and plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and knneg: "0 <= k"
|
|
|
1245 |
shows "ALL x. P x \<longrightarrow> P(x + k*d)"
|
|
|
1246 |
using knneg
|
|
|
1247 |
proof (induct rule:int_ge_induct)
|
|
|
1248 |
case base thus ?case by simp
|
|
|
1249 |
next
|
|
|
1250 |
case (step i)
|
|
|
1251 |
{fix x
|
|
|
1252 |
have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
|
|
|
1253 |
also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)" using plus[THEN spec, of "x + i * d"]
|
|
|
1254 |
by (simp add:int_distrib zadd_ac)
|
|
|
1255 |
ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast}
|
|
|
1256 |
thus ?case ..
|
|
|
1257 |
qed
|
|
|
1258 |
|
|
|
1259 |
lemma cppi:
|
|
|
1260 |
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x> z. P x = P' x"
|
|
|
1261 |
and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> A. x \<noteq> b - j) --> P (x) --> P (x + D)"
|
|
|
1262 |
and pd: "\<forall> x k. P' x= P' (x-k*D)"
|
|
|
1263 |
shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j) | (\<exists> j \<in> {1..D}.\<exists> b\<in> A. P (b - j)))" (is "?L = (?R1 \<or> ?R2)")
|
|
|
1264 |
proof-
|
|
|
1265 |
{assume "?R2" hence "?L" by blast}
|
|
|
1266 |
moreover
|
|
|
1267 |
{assume H:"?R1" hence "?L" using plusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
|
|
|
1268 |
moreover
|
|
|
1269 |
{ fix x
|
|
|
1270 |
assume P: "P x" and H: "\<not> ?R2"
|
|
|
1271 |
{fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>A. P (b - j))" and P: "P y"
|
|
|
1272 |
hence "~(EX (j::int) : {1..D}. EX (b::int) : A. y = b - j)" by auto
|
|
|
1273 |
with nb P have "P (y + D)" by auto }
|
|
|
1274 |
hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : A. P(b-j)) --> P (x) --> P (x + D)" by blast
|
|
|
1275 |
with H P have th: " \<forall>x. P x \<longrightarrow> P (x + D)" by auto
|
|
|
1276 |
from p1 obtain z where z: "ALL x. x > z --> (P x = P' x)" by blast
|
|
|
1277 |
let ?y = "x + (\<bar>x - z\<bar> + 1)*D"
|
|
|
1278 |
have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith
|
|
|
1279 |
from dp have yz: "?y > z" using incr_lemma[OF dp] by simp
|
|
|
1280 |
from z[rule_format, OF yz] incr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto
|
|
|
1281 |
with periodic_finite_ex[OF dp pd]
|
|
|
1282 |
have "?R1" by blast}
|
|
|
1283 |
ultimately show ?thesis by blast
|
|
|
1284 |
qed
|
|
|
1285 |
|
|
|
1286 |
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
|
|
|
1287 |
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
|
|
|
1288 |
apply(fastsimp)
|
|
|
1289 |
done
|
|
|
1290 |
|
|
|
1291 |
theorem unity_coeff_ex: "(\<exists>(x::'a::{semiring_0}). P (l * x)) \<equiv> (\<exists>x. l dvd (x + 0) \<and> P x)"
|
|
|
1292 |
apply (rule eq_reflection[symmetric])
|
|
|
1293 |
apply (rule iffI)
|
|
|
1294 |
defer
|
|
|
1295 |
apply (erule exE)
|
|
|
1296 |
apply (rule_tac x = "l * x" in exI)
|
|
|
1297 |
apply (simp add: dvd_def)
|
|
|
1298 |
apply (rule_tac x="x" in exI, simp)
|
|
|
1299 |
apply (erule exE)
|
|
|
1300 |
apply (erule conjE)
|
|
|
1301 |
apply (erule dvdE)
|
|
|
1302 |
apply (rule_tac x = k in exI)
|
|
|
1303 |
apply simp
|
|
|
1304 |
done
|
|
|
1305 |
|
|
|
1306 |
lemma zdvd_mono: assumes not0: "(k::int) \<noteq> 0"
|
|
|
1307 |
shows "((m::int) dvd t) \<equiv> (k*m dvd k*t)"
|
|
|
1308 |
using not0 by (simp add: dvd_def)
|
|
|
1309 |
|
|
|
1310 |
lemma uminus_dvd_conv: "(d dvd (t::int)) \<equiv> (-d dvd t)" "(d dvd (t::int)) \<equiv> (d dvd -t)"
|
|
|
1311 |
by simp_all
|
|
|
1312 |
text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
|
|
|
1313 |
lemma all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
|
|
|
1314 |
by (simp split add: split_nat)
|
|
|
1315 |
|
|
|
1316 |
lemma ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
|
|
|
1317 |
apply (auto split add: split_nat)
|
|
|
1318 |
apply (rule_tac x="int x" in exI, simp)
|
|
|
1319 |
apply (rule_tac x = "nat x" in exI,erule_tac x = "nat x" in allE, simp)
|
|
|
1320 |
done
|
|
|
1321 |
|
|
|
1322 |
lemma zdiff_int_split: "P (int (x - y)) =
|
|
|
1323 |
((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
|
|
|
1324 |
by (case_tac "y \<le> x", simp_all add: zdiff_int)
|
|
|
1325 |
|
|
|
1326 |
lemma number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)" by simp
|
|
|
1327 |
lemma number_of2: "(0::int) <= Numeral0" by simp
|
|
|
1328 |
lemma Suc_plus1: "Suc n = n + 1" by simp
|
|
|
1329 |
|
|
|
1330 |
text {*
|
|
|
1331 |
\medskip Specific instances of congruence rules, to prevent
|
|
|
1332 |
simplifier from looping. *}
|
|
|
1333 |
|
|
|
1334 |
theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')" by simp
|
|
|
1335 |
|
|
|
1336 |
theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::int) \<and> P) = (0 <= x \<and> P')"
|
|
|
1337 |
by (simp cong: conj_cong)
|
|
|
1338 |
lemma int_eq_number_of_eq:
|
|
|
1339 |
"(((number_of v)::int) = (number_of w)) = iszero ((number_of (v + (uminus w)))::int)"
|
|
|
1340 |
by simp
|
|
|
1341 |
|
|
|
1342 |
lemma mod_eq0_dvd_iff[presburger]: "(m::nat) mod n = 0 \<longleftrightarrow> n dvd m"
|
|
|
1343 |
unfolding dvd_eq_mod_eq_0[symmetric] ..
|
|
|
1344 |
|
|
|
1345 |
lemma zmod_eq0_zdvd_iff[presburger]: "(m::int) mod n = 0 \<longleftrightarrow> n dvd m"
|
|
|
1346 |
unfolding zdvd_iff_zmod_eq_0[symmetric] ..
|
|
|
1347 |
declare mod_1[presburger]
|
|
|
1348 |
declare mod_0[presburger]
|
|
|
1349 |
declare zmod_1[presburger]
|
|
|
1350 |
declare zmod_zero[presburger]
|
|
|
1351 |
declare zmod_self[presburger]
|
|
|
1352 |
declare mod_self[presburger]
|
|
|
1353 |
declare DIVISION_BY_ZERO_MOD[presburger]
|
|
|
1354 |
declare nat_mod_div_trivial[presburger]
|
|
|
1355 |
declare div_mod_equality2[presburger]
|
|
|
1356 |
declare div_mod_equality[presburger]
|
|
|
1357 |
declare mod_div_equality2[presburger]
|
|
|
1358 |
declare mod_div_equality[presburger]
|
|
|
1359 |
declare mod_mult_self1[presburger]
|
|
|
1360 |
declare mod_mult_self2[presburger]
|
|
|
1361 |
declare zdiv_zmod_equality2[presburger]
|
|
|
1362 |
declare zdiv_zmod_equality[presburger]
|
|
|
1363 |
declare mod2_Suc_Suc[presburger]
|
|
|
1364 |
lemma [presburger]: "(a::int) div 0 = 0" and [presburger]: "a mod 0 = a"
|
|
|
1365 |
using IntDiv.DIVISION_BY_ZERO by blast+
|
|
|
1366 |
|
|
|
1367 |
use "Tools/Presburger/cooper.ML"
|
|
|
1368 |
oracle linzqe_oracle ("term") = Coopereif.cooper_oracle
|
|
|
1369 |
|
|
|
1370 |
use "Tools/Presburger/presburger.ML"
|
|
|
1371 |
|
|
|
1372 |
setup {*
|
|
|
1373 |
arith_tactic_add
|
|
|
1374 |
(mk_arith_tactic "presburger" (fn i => fn st =>
|
|
|
1375 |
(warning "Trying Presburger arithmetic ...";
|
|
|
1376 |
Presburger.cooper_tac true [] [] ((ProofContext.init o theory_of_thm) st) i st)))
|
|
|
1377 |
(* FIXME!!!!!!! get the right context!!*)
|
|
|
1378 |
*}
|
|
|
1379 |
|
|
|
1380 |
method_setup presburger = {*
|
|
|
1381 |
let
|
|
|
1382 |
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()
|
|
|
1383 |
fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()
|
|
|
1384 |
val addN = "add"
|
|
|
1385 |
val delN = "del"
|
|
|
1386 |
val elimN = "elim"
|
|
|
1387 |
val any_keyword = keyword addN || keyword delN || simple_keyword elimN
|
|
|
1388 |
val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat;
|
|
|
1389 |
in
|
|
|
1390 |
fn src => Method.syntax
|
|
|
1391 |
((Scan.optional (simple_keyword elimN >> K false) true) --
|
|
|
1392 |
(Scan.optional (keyword addN |-- thms) []) --
|
|
|
1393 |
(Scan.optional (keyword delN |-- thms) [])) src
|
|
|
1394 |
#> (fn (((elim, add_ths), del_ths),ctxt) =>
|
|
|
1395 |
Method.SIMPLE_METHOD' (Presburger.cooper_tac elim add_ths del_ths ctxt))
|
|
|
1396 |
end
|
|
|
1397 |
*} "Cooper's algorithm for Presburger arithmetic"
|
|
|
1398 |
|
|
|
1399 |
lemma [presburger]: "m mod 2 = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger
|
|
|
1400 |
lemma [presburger]: "m mod 2 = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger
|
|
|
1401 |
lemma [presburger]: "m mod (Suc (Suc 0)) = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger
|
|
|
1402 |
lemma [presburger]: "m mod (Suc (Suc 0)) = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger
|
|
|
1403 |
lemma [presburger]: "m mod 2 = (1::int) \<longleftrightarrow> \<not> 2 dvd m " by presburger
|
|
|
1404 |
|
|
|
1405 |
|
|
|
1406 |
subsection {* Code generator setup *}
|
|
|
1407 |
|
|
|
1408 |
text {*
|
|
|
1409 |
Presburger arithmetic is convenient to prove some
|
|
|
1410 |
of the following code lemmas on integer numerals:
|
|
|
1411 |
*}
|
|
|
1412 |
|
|
|
1413 |
lemma eq_Pls_Pls:
|
|
|
1414 |
"Numeral.Pls = Numeral.Pls \<longleftrightarrow> True" by presburger
|
|
|
1415 |
|
|
|
1416 |
lemma eq_Pls_Min:
|
|
|
1417 |
"Numeral.Pls = Numeral.Min \<longleftrightarrow> False"
|
|
|
1418 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1419 |
|
|
|
1420 |
lemma eq_Pls_Bit0:
|
|
|
1421 |
"Numeral.Pls = Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Pls = k"
|
|
|
1422 |
unfolding Pls_def Bit_def bit.cases by presburger
|
|
|
1423 |
|
|
|
1424 |
lemma eq_Pls_Bit1:
|
|
|
1425 |
"Numeral.Pls = Numeral.Bit k bit.B1 \<longleftrightarrow> False"
|
|
|
1426 |
unfolding Pls_def Bit_def bit.cases by presburger
|
|
|
1427 |
|
|
|
1428 |
lemma eq_Min_Pls:
|
|
|
1429 |
"Numeral.Min = Numeral.Pls \<longleftrightarrow> False"
|
|
|
1430 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1431 |
|
|
|
1432 |
lemma eq_Min_Min:
|
|
|
1433 |
"Numeral.Min = Numeral.Min \<longleftrightarrow> True" by presburger
|
|
|
1434 |
|
|
|
1435 |
lemma eq_Min_Bit0:
|
|
|
1436 |
"Numeral.Min = Numeral.Bit k bit.B0 \<longleftrightarrow> False"
|
|
|
1437 |
unfolding Numeral.Min_def Bit_def bit.cases by presburger
|
|
|
1438 |
|
|
|
1439 |
lemma eq_Min_Bit1:
|
|
|
1440 |
"Numeral.Min = Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Min = k"
|
|
|
1441 |
unfolding Numeral.Min_def Bit_def bit.cases by presburger
|
|
|
1442 |
|
|
|
1443 |
lemma eq_Bit0_Pls:
|
|
|
1444 |
"Numeral.Bit k bit.B0 = Numeral.Pls \<longleftrightarrow> Numeral.Pls = k"
|
|
|
1445 |
unfolding Pls_def Bit_def bit.cases by presburger
|
|
|
1446 |
|
|
|
1447 |
lemma eq_Bit1_Pls:
|
|
|
1448 |
"Numeral.Bit k bit.B1 = Numeral.Pls \<longleftrightarrow> False"
|
|
|
1449 |
unfolding Pls_def Bit_def bit.cases by presburger
|
|
|
1450 |
|
|
|
1451 |
lemma eq_Bit0_Min:
|
|
|
1452 |
"Numeral.Bit k bit.B0 = Numeral.Min \<longleftrightarrow> False"
|
|
|
1453 |
unfolding Numeral.Min_def Bit_def bit.cases by presburger
|
|
|
1454 |
|
|
|
1455 |
lemma eq_Bit1_Min:
|
|
|
1456 |
"(Numeral.Bit k bit.B1) = Numeral.Min \<longleftrightarrow> Numeral.Min = k"
|
|
|
1457 |
unfolding Numeral.Min_def Bit_def bit.cases by presburger
|
|
|
1458 |
|
|
|
1459 |
lemma eq_Bit_Bit:
|
|
|
1460 |
"Numeral.Bit k1 v1 = Numeral.Bit k2 v2 \<longleftrightarrow>
|
|
|
1461 |
v1 = v2 \<and> k1 = k2"
|
|
|
1462 |
unfolding Bit_def
|
|
|
1463 |
apply (cases v1)
|
|
|
1464 |
apply (cases v2)
|
|
|
1465 |
apply auto
|
|
|
1466 |
apply presburger
|
|
|
1467 |
apply (cases v2)
|
|
|
1468 |
apply auto
|
|
|
1469 |
apply presburger
|
|
|
1470 |
apply (cases v2)
|
|
|
1471 |
apply auto
|
|
|
1472 |
done
|
|
|
1473 |
|
|
|
1474 |
lemma eq_number_of:
|
|
|
1475 |
"(number_of k \<Colon> int) = number_of l \<longleftrightarrow> k = l"
|
|
|
1476 |
unfolding number_of_is_id ..
|
|
|
1477 |
|
|
|
1478 |
|
|
|
1479 |
lemma less_eq_Pls_Pls:
|
|
|
1480 |
"Numeral.Pls \<le> Numeral.Pls \<longleftrightarrow> True" by rule+
|
|
|
1481 |
|
|
|
1482 |
lemma less_eq_Pls_Min:
|
|
|
1483 |
"Numeral.Pls \<le> Numeral.Min \<longleftrightarrow> False"
|
|
|
1484 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1485 |
|
|
|
1486 |
lemma less_eq_Pls_Bit:
|
|
|
1487 |
"Numeral.Pls \<le> Numeral.Bit k v \<longleftrightarrow> Numeral.Pls \<le> k"
|
|
|
1488 |
unfolding Pls_def Bit_def by (cases v) auto
|
|
|
1489 |
|
|
|
1490 |
lemma less_eq_Min_Pls:
|
|
|
1491 |
"Numeral.Min \<le> Numeral.Pls \<longleftrightarrow> True"
|
|
|
1492 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1493 |
|
|
|
1494 |
lemma less_eq_Min_Min:
|
|
|
1495 |
"Numeral.Min \<le> Numeral.Min \<longleftrightarrow> True" by rule+
|
|
|
1496 |
|
|
|
1497 |
lemma less_eq_Min_Bit0:
|
|
|
1498 |
"Numeral.Min \<le> Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Min < k"
|
|
|
1499 |
unfolding Numeral.Min_def Bit_def by auto
|
|
|
1500 |
|
|
|
1501 |
lemma less_eq_Min_Bit1:
|
|
|
1502 |
"Numeral.Min \<le> Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Min \<le> k"
|
|
|
1503 |
unfolding Numeral.Min_def Bit_def by auto
|
|
|
1504 |
|
|
|
1505 |
lemma less_eq_Bit0_Pls:
|
|
|
1506 |
"Numeral.Bit k bit.B0 \<le> Numeral.Pls \<longleftrightarrow> k \<le> Numeral.Pls"
|
|
|
1507 |
unfolding Pls_def Bit_def by simp
|
|
|
1508 |
|
|
|
1509 |
lemma less_eq_Bit1_Pls:
|
|
|
1510 |
"Numeral.Bit k bit.B1 \<le> Numeral.Pls \<longleftrightarrow> k < Numeral.Pls"
|
|
|
1511 |
unfolding Pls_def Bit_def by auto
|
|
|
1512 |
|
|
|
1513 |
lemma less_eq_Bit_Min:
|
|
|
1514 |
"Numeral.Bit k v \<le> Numeral.Min \<longleftrightarrow> k \<le> Numeral.Min"
|
|
|
1515 |
unfolding Numeral.Min_def Bit_def by (cases v) auto
|
|
|
1516 |
|
|
|
1517 |
lemma less_eq_Bit0_Bit:
|
|
|
1518 |
"Numeral.Bit k1 bit.B0 \<le> Numeral.Bit k2 v \<longleftrightarrow> k1 \<le> k2"
|
|
|
1519 |
unfolding Bit_def bit.cases by (cases v) auto
|
|
|
1520 |
|
|
|
1521 |
lemma less_eq_Bit_Bit1:
|
|
|
1522 |
"Numeral.Bit k1 v \<le> Numeral.Bit k2 bit.B1 \<longleftrightarrow> k1 \<le> k2"
|
|
|
1523 |
unfolding Bit_def bit.cases by (cases v) auto
|
|
|
1524 |
|
|
|
1525 |
lemma less_eq_Bit1_Bit0:
|
|
|
1526 |
"Numeral.Bit k1 bit.B1 \<le> Numeral.Bit k2 bit.B0 \<longleftrightarrow> k1 < k2"
|
|
|
1527 |
unfolding Bit_def by (auto split: bit.split)
|
|
|
1528 |
|
|
|
1529 |
lemma less_eq_number_of:
|
|
|
1530 |
"(number_of k \<Colon> int) \<le> number_of l \<longleftrightarrow> k \<le> l"
|
|
|
1531 |
unfolding number_of_is_id ..
|
|
|
1532 |
|
|
|
1533 |
|
|
|
1534 |
lemma less_Pls_Pls:
|
|
|
1535 |
"Numeral.Pls < Numeral.Pls \<longleftrightarrow> False" by simp
|
|
|
1536 |
|
|
|
1537 |
lemma less_Pls_Min:
|
|
|
1538 |
"Numeral.Pls < Numeral.Min \<longleftrightarrow> False"
|
|
|
1539 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1540 |
|
|
|
1541 |
lemma less_Pls_Bit0:
|
|
|
1542 |
"Numeral.Pls < Numeral.Bit k bit.B0 \<longleftrightarrow> Numeral.Pls < k"
|
|
|
1543 |
unfolding Pls_def Bit_def by auto
|
|
|
1544 |
|
|
|
1545 |
lemma less_Pls_Bit1:
|
|
|
1546 |
"Numeral.Pls < Numeral.Bit k bit.B1 \<longleftrightarrow> Numeral.Pls \<le> k"
|
|
|
1547 |
unfolding Pls_def Bit_def by auto
|
|
|
1548 |
|
|
|
1549 |
lemma less_Min_Pls:
|
|
|
1550 |
"Numeral.Min < Numeral.Pls \<longleftrightarrow> True"
|
|
|
1551 |
unfolding Pls_def Numeral.Min_def by presburger
|
|
|
1552 |
|
|
|
1553 |
lemma less_Min_Min:
|
|
|
1554 |
"Numeral.Min < Numeral.Min \<longleftrightarrow> False" by simp
|
|
|
1555 |
|
|
|
1556 |
lemma less_Min_Bit:
|
|
|
1557 |
"Numeral.Min < Numeral.Bit k v \<longleftrightarrow> Numeral.Min < k"
|
|
|
1558 |
unfolding Numeral.Min_def Bit_def by (auto split: bit.split)
|
|
|
1559 |
|
|
|
1560 |
lemma less_Bit_Pls:
|
|
|
1561 |
"Numeral.Bit k v < Numeral.Pls \<longleftrightarrow> k < Numeral.Pls"
|
|
|
1562 |
unfolding Pls_def Bit_def by (auto split: bit.split)
|
|
|
1563 |
|
|
|
1564 |
lemma less_Bit0_Min:
|
|
|
1565 |
"Numeral.Bit k bit.B0 < Numeral.Min \<longleftrightarrow> k \<le> Numeral.Min"
|
|
|
1566 |
unfolding Numeral.Min_def Bit_def by auto
|
|
|
1567 |
|
|
|
1568 |
lemma less_Bit1_Min:
|
|
|
1569 |
"Numeral.Bit k bit.B1 < Numeral.Min \<longleftrightarrow> k < Numeral.Min"
|
|
|
1570 |
unfolding Numeral.Min_def Bit_def by auto
|
|
|
1571 |
|
|
|
1572 |
lemma less_Bit_Bit0:
|
|
|
1573 |
"Numeral.Bit k1 v < Numeral.Bit k2 bit.B0 \<longleftrightarrow> k1 < k2"
|
|
|
1574 |
unfolding Bit_def by (auto split: bit.split)
|
|
|
1575 |
|
|
|
1576 |
lemma less_Bit1_Bit:
|
|
|
1577 |
"Numeral.Bit k1 bit.B1 < Numeral.Bit k2 v \<longleftrightarrow> k1 < k2"
|
|
|
1578 |
unfolding Bit_def by (auto split: bit.split)
|
|
|
1579 |
|
|
|
1580 |
lemma less_Bit0_Bit1:
|
|
|
1581 |
"Numeral.Bit k1 bit.B0 < Numeral.Bit k2 bit.B1 \<longleftrightarrow> k1 \<le> k2"
|
|
|
1582 |
unfolding Bit_def bit.cases by arith
|
|
|
1583 |
|
|
|
1584 |
lemma less_number_of:
|
|
|
1585 |
"(number_of k \<Colon> int) < number_of l \<longleftrightarrow> k < l"
|
|
|
1586 |
unfolding number_of_is_id ..
|
|
|
1587 |
|
|
|
1588 |
lemmas pred_succ_numeral_code [code func] =
|
|
|
1589 |
arith_simps(5-12)
|
|
|
1590 |
|
|
|
1591 |
lemmas plus_numeral_code [code func] =
|
|
|
1592 |
arith_simps(13-17)
|
|
|
1593 |
arith_simps(26-27)
|
|
|
1594 |
arith_extra_simps(1) [where 'a = int]
|
|
|
1595 |
|
|
|
1596 |
lemmas minus_numeral_code [code func] =
|
|
|
1597 |
arith_simps(18-21)
|
|
|
1598 |
arith_extra_simps(2) [where 'a = int]
|
|
|
1599 |
arith_extra_simps(5) [where 'a = int]
|
|
|
1600 |
|
|
|
1601 |
lemmas times_numeral_code [code func] =
|
|
|
1602 |
arith_simps(22-25)
|
|
|
1603 |
arith_extra_simps(4) [where 'a = int]
|
|
|
1604 |
|
|
|
1605 |
lemmas eq_numeral_code [code func] =
|
|
|
1606 |
eq_Pls_Pls eq_Pls_Min eq_Pls_Bit0 eq_Pls_Bit1
|
|
|
1607 |
eq_Min_Pls eq_Min_Min eq_Min_Bit0 eq_Min_Bit1
|
|
|
1608 |
eq_Bit0_Pls eq_Bit1_Pls eq_Bit0_Min eq_Bit1_Min eq_Bit_Bit
|
|
|
1609 |
eq_number_of
|
|
|
1610 |
|
|
|
1611 |
lemmas less_eq_numeral_code [code func] = less_eq_Pls_Pls less_eq_Pls_Min less_eq_Pls_Bit
|
|
|
1612 |
less_eq_Min_Pls less_eq_Min_Min less_eq_Min_Bit0 less_eq_Min_Bit1
|
|
|
1613 |
less_eq_Bit0_Pls less_eq_Bit1_Pls less_eq_Bit_Min less_eq_Bit0_Bit less_eq_Bit_Bit1 less_eq_Bit1_Bit0
|
|
|
1614 |
less_eq_number_of
|
|
|
1615 |
|
|
|
1616 |
lemmas less_numeral_code [code func] = less_Pls_Pls less_Pls_Min less_Pls_Bit0
|
|
|
1617 |
less_Pls_Bit1 less_Min_Pls less_Min_Min less_Min_Bit less_Bit_Pls
|
|
|
1618 |
less_Bit0_Min less_Bit1_Min less_Bit_Bit0 less_Bit1_Bit less_Bit0_Bit1
|
|
|
1619 |
less_number_of
|
|
|
1620 |
|
|
|
1621 |
end
|