1 (* Title: HOL/Integ/Presburger.thy
3 Author: Amine Chaieb, Tobias Nipkow and Stefan Berghofer, TU Muenchen
4 License: GPL (GNU GENERAL PUBLIC LICENSE)
6 File containing necessary theorems for the proof
7 generation for Cooper Algorithm
10 header {* Presburger Arithmetic: Cooper Algorithm *}
12 theory Presburger = NatSimprocs + SetInterval
19 text {* Theorem for unitifying the coeffitients of @{text x} in an existential formula*}
21 theorem unity_coeff_ex: "(\<exists>x::int. P (l * x)) = (\<exists>x. l dvd (1*x+0) \<and> P x)"
24 apply (rule_tac x = "l * x" in exI)
29 apply (rule_tac x = k in exI)
33 lemma uminus_dvd_conv: "(d dvd (t::int)) = (-d dvd t)"
38 apply(rule_tac x = "-k" in exI)
42 apply(rule_tac x = "-k" in exI)
46 lemma uminus_dvd_conv': "(d dvd (t::int)) = (d dvd -t)"
50 apply(rule_tac x = "-k" in exI)
53 apply(rule_tac x = "-k" in exI)
59 text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} less than some integer @{text z}.*}
61 theorem eq_minf_conjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
62 \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
63 \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
65 apply (rule_tac x = "min z1 z2" in exI)
70 theorem eq_minf_disjI: "\<exists>z1::int. \<forall>x. x < z1 \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
71 \<exists>z2::int. \<forall>x. x < z2 \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
72 \<exists>z::int. \<forall>x. x < z \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
75 apply (rule_tac x = "min z1 z2" in exI)
80 text {*Theorems for the combination of proofs of the equality of @{text P} and @{text P_m} for integers @{text x} greather than some integer @{text z}.*}
82 theorem eq_pinf_conjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
83 \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
84 \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<and> B1 x) = (A2 x \<and> B2 x))"
86 apply (rule_tac x = "max z1 z2" in exI)
91 theorem eq_pinf_disjI: "\<exists>z1::int. \<forall>x. z1 < x \<longrightarrow> (A1 x = A2 x) \<Longrightarrow>
92 \<exists>z2::int. \<forall>x. z2 < x \<longrightarrow> (B1 x = B2 x) \<Longrightarrow>
93 \<exists>z::int. \<forall>x. z < x \<longrightarrow> ((A1 x \<or> B1 x) = (A2 x \<or> B2 x))"
95 apply (rule_tac x = "max z1 z2" in exI)
100 \medskip Theorems for the combination of proofs of the modulo @{text
101 D} property for @{text "P plusinfinity"}
103 FIXME: This is THE SAME theorem as for the @{text minusinf} version,
104 but with @{text "+k.."} instead of @{text "-k.."} In the future
105 replace these both with only one. *}
107 theorem modd_pinf_conjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
108 \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
109 \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x+k*d) \<and> B (x+k*d))"
112 theorem modd_pinf_disjI: "\<forall>(x::int) k. A x = A (x+k*d) \<Longrightarrow>
113 \<forall>(x::int) k. B x = B (x+k*d) \<Longrightarrow>
114 \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x+k*d) \<or> B (x+k*d))"
118 This is one of the cases where the simplifed formula is prooved to
119 habe some property (in relation to @{text P_m}) but we need to prove
120 the property for the original formula (@{text P_m})
122 FIXME: This is exaclty the same thm as for @{text minusinf}. *}
124 lemma pinf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x)) ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
129 \medskip Theorems for the combination of proofs of the modulo @{text D}
130 property for @{text "P minusinfinity"} *}
132 theorem modd_minf_conjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
133 \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
134 \<forall>(x::int) (k::int). (A x \<and> B x) = (A (x-k*d) \<and> B (x-k*d))"
137 theorem modd_minf_disjI: "\<forall>(x::int) k. A x = A (x-k*d) \<Longrightarrow>
138 \<forall>(x::int) k. B x = B (x-k*d) \<Longrightarrow>
139 \<forall>(x::int) (k::int). (A x \<or> B x) = (A (x-k*d) \<or> B (x-k*d))"
143 This is one of the cases where the simplifed formula is prooved to
144 have some property (in relation to @{text P_m}) but we need to
145 prove the property for the original formula (@{text P_m}). *}
147 lemma minf_simp_eq: "ALL x. P(x) = Q(x) ==> (EX (x::int). P(x)) --> (EX (x::int). F(x)) ==> (EX (x::int). Q(x)) --> (EX (x::int). F(x)) "
151 Theorem needed for proving at runtime divide properties using the
152 arithmetic tactic (which knows only about modulo = 0). *}
154 lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))"
155 by(simp add:dvd_def zmod_eq_0_iff)
158 \medskip Theorems used for the combination of proof for the
159 backwards direction of Cooper's Theorem. They rely exclusively on
160 Predicate calculus.*}
162 lemma not_ast_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P1(x) --> P1(x + d))
164 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
166 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<or> P2(x)) --> (P1(x + d) \<or> P2(x + d))) "
170 lemma not_ast_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a- j)) --> P1(x) --> P1(x + d))
172 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> P2(x) --> P2(x + d))
174 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->(P1(x) \<and> P2(x)) --> (P1(x + d)
178 lemma not_ast_p_Q_elim: "
179 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) -->P(x) --> P(x + d))
181 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (a::int) : A. P(a - j)) -->P(x) --> P(x + d))"
185 \medskip Theorems used for the combination of proof for the
186 backwards direction of Cooper's Theorem. They rely exclusively on
187 Predicate calculus.*}
189 lemma not_bst_p_disjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
191 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
193 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<or> P2(x)) --> (P1(x - d)
197 lemma not_bst_p_conjI: "(ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P1(x) --> P1(x - d))
199 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> P2(x) --> P2(x - d))
201 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->(P1(x) \<and> P2(x)) --> (P1(x - d)
205 lemma not_bst_p_Q_elim: "
206 (ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) -->P(x) --> P(x - d))
208 ==> (ALL x. ~(EX (j::int) : {1..d}. EX (b::int) : B. P(b+j)) -->P(x) --> P(x - d))"
211 text {* \medskip This is the first direction of Cooper's Theorem. *}
212 lemma cooper_thm: "(R --> (EX x::int. P x)) ==> (Q -->(EX x::int. P x )) ==> ((R|Q) --> (EX x::int. P x )) "
216 \medskip The full Cooper's Theorem in its equivalence Form. Given
217 the premises it is trivial too, it relies exclusively on prediacte calculus.*}
218 lemma cooper_eq_thm: "(R --> (EX x::int. P x)) ==> (Q -->(EX x::int. P x )) ==> ((~Q)
219 --> (EX x::int. P x ) --> R) ==> (EX x::int. P x) = R|Q "
223 \medskip Some of the atomic theorems generated each time the atom
224 does not depend on @{text x}, they are trivial.*}
226 lemma fm_eq_minf: "EX z::int. ALL x. x < z --> (P = P) "
229 lemma fm_modd_minf: "ALL (x::int). ALL (k::int). (P = P)"
232 lemma not_bst_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> fm --> fm"
235 lemma fm_eq_pinf: "EX z::int. ALL x. z < x --> (P = P) "
238 text {* The next two thms are the same as the @{text minusinf} version. *}
240 lemma fm_modd_pinf: "ALL (x::int). ALL (k::int). (P = P)"
243 lemma not_ast_p_fm: "ALL (x::int). Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> fm --> fm"
246 text {* Theorems to be deleted from simpset when proving simplified formulaes. *}
248 lemma P_eqtrue: "(P=True) = P"
251 lemma P_eqfalse: "(P=False) = (~P)"
255 \medskip Theorems for the generation of the bachwards direction of
258 These are the 6 interesting atomic cases which have to be proved relying on the
259 properties of B-set and the arithmetic and contradiction proofs. *}
261 lemma not_bst_p_lt: "0 < (d::int) ==>
262 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ( 0 < -x + a) --> (0 < -(x - d) + a )"
265 lemma not_bst_p_gt: "\<lbrakk> (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
266 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 < (x) + a) --> ( 0 < (x - d) + a)"
269 apply(drule_tac x = "x+a" in bspec)
270 apply(simp add:atLeastAtMost_iff)
271 apply(drule_tac x = "-a" in bspec)
276 lemma not_bst_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a - 1 \<rbrakk> \<Longrightarrow>
277 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> (0 = x + a) --> (0 = (x - d) + a )"
279 apply(subgoal_tac "x = -a")
281 apply(drule_tac x = "1" in bspec)
282 apply(simp add:atLeastAtMost_iff)
283 apply(drule_tac x = "-a- 1" in bspec)
289 lemma not_bst_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> B; g = -a \<rbrakk> \<Longrightarrow>
290 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(0 = x + a) --> ~(0 = (x - d) + a)"
292 apply(subgoal_tac "x = -a+d")
294 apply(drule_tac x = "d" in bspec)
295 apply(simp add:atLeastAtMost_iff)
296 apply(drule_tac x = "-a" in bspec)
302 lemma not_bst_p_dvd: "(d1::int) dvd d ==>
303 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> d1 dvd (x + a) --> d1 dvd ((x - d) + a )"
304 apply(clarsimp simp add:dvd_def)
306 apply(rule_tac x = "m - k" in exI)
307 apply(simp add:int_distrib)
310 lemma not_bst_p_ndvd: "(d1::int) dvd d ==>
311 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (b::int) : B. Q(b+j)) --> ~(d1 dvd (x + a)) --> ~(d1 dvd ((x - d) + a ))"
312 apply(clarsimp simp add:dvd_def)
314 apply(erule_tac x = "m + k" in allE)
315 apply(simp add:int_distrib)
319 \medskip Theorems for the generation of the bachwards direction of
322 These are the 6 interesting atomic cases which have to be proved
323 relying on the properties of A-set ant the arithmetic and
324 contradiction proofs. *}
326 lemma not_ast_p_gt: "0 < (d::int) ==>
327 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ( 0 < x + t) --> (0 < (x + d) + t )"
330 lemma not_ast_p_lt: "\<lbrakk>0 < d ;(t::int) \<in> A \<rbrakk> \<Longrightarrow>
331 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 < -x + t) --> ( 0 < -(x + d) + t)"
334 apply (drule_tac x = "t-x" in bspec)
336 apply (drule_tac x = "t" in bspec)
341 lemma not_ast_p_eq: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t + 1 \<rbrakk> \<Longrightarrow>
342 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> (0 = x + t) --> (0 = (x + d) + t )"
344 apply (drule_tac x="1" in bspec)
346 apply (drule_tac x="- t + 1" in bspec)
348 apply(subgoal_tac "x = -t")
353 lemma not_ast_p_ne: "\<lbrakk> 0 < d; (g::int) \<in> A; g = -t \<rbrakk> \<Longrightarrow>
354 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(0 = x + t) --> ~(0 = (x + d) + t)"
356 apply (subgoal_tac "x = -t-d")
358 apply (drule_tac x = "d" in bspec)
360 apply (drule_tac x = "-t" in bspec)
365 lemma not_ast_p_dvd: "(d1::int) dvd d ==>
366 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> d1 dvd (x + t) --> d1 dvd ((x + d) + t )"
367 apply(clarsimp simp add:dvd_def)
369 apply(rule_tac x = "m + k" in exI)
370 apply(simp add:int_distrib)
373 lemma not_ast_p_ndvd: "(d1::int) dvd d ==>
374 ALL x. Q(x::int) \<and> ~(EX (j::int) : {1..d}. EX (a::int) : A. Q(a - j)) --> ~(d1 dvd (x + t)) --> ~(d1 dvd ((x + d) + t ))"
375 apply(clarsimp simp add:dvd_def)
377 apply(erule_tac x = "m - k" in allE)
378 apply(simp add:int_distrib)
382 \medskip These are the atomic cases for the proof generation for the
383 modulo @{text D} property for @{text "P plusinfinity"}
385 They are fully based on arithmetics. *}
387 lemma dvd_modd_pinf: "((d::int) dvd d1) ==>
388 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x+k*d1 + t))))"
389 apply(clarsimp simp add:dvd_def)
392 apply(rename_tac n m)
393 apply(rule_tac x = "m + n*k" in exI)
394 apply(simp add:int_distrib)
396 apply(rename_tac n m)
397 apply(rule_tac x = "m - n*k" in exI)
398 apply(simp add:int_distrib mult_ac)
401 lemma not_dvd_modd_pinf: "((d::int) dvd d1) ==>
402 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x+k*d1 + t))))"
403 apply(clarsimp simp add:dvd_def)
406 apply(rename_tac n m)
407 apply(erule_tac x = "m - n*k" in allE)
408 apply(simp add:int_distrib mult_ac)
410 apply(rename_tac n m)
411 apply(erule_tac x = "m + n*k" in allE)
412 apply(simp add:int_distrib mult_ac)
416 \medskip These are the atomic cases for the proof generation for the
417 equivalence of @{text P} and @{text "P plusinfinity"} for integers
418 @{text x} greater than some integer @{text z}.
420 They are fully based on arithmetics. *}
422 lemma eq_eq_pinf: "EX z::int. ALL x. z < x --> (( 0 = x +t ) = False )"
423 apply(rule_tac x = "-t" in exI)
427 lemma neq_eq_pinf: "EX z::int. ALL x. z < x --> ((~( 0 = x +t )) = True )"
428 apply(rule_tac x = "-t" in exI)
432 lemma le_eq_pinf: "EX z::int. ALL x. z < x --> ( 0 < x +t = True )"
433 apply(rule_tac x = "-t" in exI)
437 lemma len_eq_pinf: "EX z::int. ALL x. z < x --> (0 < -x +t = False )"
438 apply(rule_tac x = "t" in exI)
442 lemma dvd_eq_pinf: "EX z::int. ALL x. z < x --> ((d dvd (x + t)) = (d dvd (x + t))) "
445 lemma not_dvd_eq_pinf: "EX z::int. ALL x. z < x --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
449 \medskip These are the atomic cases for the proof generation for the
450 modulo @{text D} property for @{text "P minusinfinity"}.
452 They are fully based on arithmetics. *}
454 lemma dvd_modd_minf: "((d::int) dvd d1) ==>
455 (ALL (x::int). ALL (k::int). (((d::int) dvd (x + t)) = (d dvd (x-k*d1 + t))))"
456 apply(clarsimp simp add:dvd_def)
459 apply(rename_tac n m)
460 apply(rule_tac x = "m - n*k" in exI)
461 apply(simp add:int_distrib)
463 apply(rename_tac n m)
464 apply(rule_tac x = "m + n*k" in exI)
465 apply(simp add:int_distrib mult_ac)
469 lemma not_dvd_modd_minf: "((d::int) dvd d1) ==>
470 (ALL (x::int). ALL k. (~((d::int) dvd (x + t))) = (~(d dvd (x-k*d1 + t))))"
471 apply(clarsimp simp add:dvd_def)
474 apply(rename_tac n m)
475 apply(erule_tac x = "m + n*k" in allE)
476 apply(simp add:int_distrib mult_ac)
478 apply(rename_tac n m)
479 apply(erule_tac x = "m - n*k" in allE)
480 apply(simp add:int_distrib mult_ac)
484 \medskip These are the atomic cases for the proof generation for the
485 equivalence of @{text P} and @{text "P minusinfinity"} for integers
486 @{text x} less than some integer @{text z}.
488 They are fully based on arithmetics. *}
490 lemma eq_eq_minf: "EX z::int. ALL x. x < z --> (( 0 = x +t ) = False )"
491 apply(rule_tac x = "-t" in exI)
495 lemma neq_eq_minf: "EX z::int. ALL x. x < z --> ((~( 0 = x +t )) = True )"
496 apply(rule_tac x = "-t" in exI)
500 lemma le_eq_minf: "EX z::int. ALL x. x < z --> ( 0 < x +t = False )"
501 apply(rule_tac x = "-t" in exI)
506 lemma len_eq_minf: "EX z::int. ALL x. x < z --> (0 < -x +t = True )"
507 apply(rule_tac x = "t" in exI)
511 lemma dvd_eq_minf: "EX z::int. ALL x. x < z --> ((d dvd (x + t)) = (d dvd (x + t))) "
514 lemma not_dvd_eq_minf: "EX z::int. ALL x. x < z --> ((~(d dvd (x + t))) = (~(d dvd (x + t)))) "
518 \medskip This Theorem combines whithnesses about @{text "P
519 minusinfinity"} to show one component of the equivalence proof for
522 FIXME: remove once they are part of the distribution. *}
524 theorem int_ge_induct[consumes 1,case_names base step]:
525 assumes ge: "k \<le> (i::int)" and
527 step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
530 { fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k <= i \<Longrightarrow> P i"
533 hence "i = k" by arith
534 thus "P i" using base by simp
537 hence "n = nat((i - 1) - k)" by arith
539 have ki1: "k \<le> i - 1" using Suc.prems by arith
541 have "P(i - 1)" by(rule Suc.hyps)
542 from step[OF ki1 this] show ?case by simp
545 from this ge show ?thesis by fast
548 theorem int_gr_induct[consumes 1,case_names base step]:
549 assumes gr: "k < (i::int)" and
551 step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)"
553 apply(rule int_ge_induct[of "k + 1"])
560 lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"
561 apply(induct rule: int_gr_induct)
564 apply (simp add:int_distrib)
568 lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"
569 apply(induct rule: int_gr_induct)
572 apply (simp add:int_distrib)
578 P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and
579 ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"
580 shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"
582 assume eP1: "EX x. P1 x"
583 then obtain x where P1: "P1 x" ..
584 from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..
585 let ?w = "x - (abs(x-z)+1) * d"
588 have w: "?w < z" by(rule decr_lemma)
589 have "P1 x = P1 ?w" using P1eqP1 by blast
590 also have "\<dots> = P(?w)" using w P1eqP by blast
591 finally show "P ?w" using P1 by blast
596 \medskip This Theorem combines whithnesses about @{text "P
597 minusinfinity"} to show one component of the equivalence proof for
602 P1eqP1: "ALL (x::int) (k::int). P1 x = P1 (x + k * d)" and
603 ePeqP1: "EX z::int. ALL x. z < x --> (P x = P1 x)"
604 shows "(EX x::int. P1 x) --> (EX x::int. P x)"
606 assume eP1: "EX x. P1 x"
607 then obtain x where P1: "P1 x" ..
608 from ePeqP1 obtain z where P1eqP: "ALL x. z < x \<longrightarrow> (P x = P1 x)" ..
609 let ?w = "x + (abs(x-z)+1) * d"
612 have w: "z < ?w" by(rule incr_lemma)
613 have "P1 x = P1 ?w" using P1eqP1 by blast
614 also have "\<dots> = P(?w)" using w P1eqP by blast
615 finally show "P ?w" using P1 by blast
620 \medskip Theorem for periodic function on discrete sets. *}
623 assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"
624 shows "(EX x. P x) = (EX j : {1..d}. P j)"
628 then obtain x where P: "P x" ..
629 have "x mod d = x - (x div d)*d"
630 by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
631 hence Pmod: "P x = P(x mod d)" using modd by simp
635 hence "P 0" using P Pmod by simp
636 moreover have "P 0 = P(0 - (-1)*d)" using modd by blast
637 ultimately have "P d" by simp
638 moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
639 ultimately show ?RHS ..
641 assume not0: "x mod d \<noteq> 0"
642 have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
643 moreover have "x mod d : {1..d}"
645 have "0 \<le> x mod d" by(rule pos_mod_sign)
646 moreover have "x mod d < d" by(rule pos_mod_bound)
647 ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
649 ultimately show ?RHS ..
652 assume ?RHS thus ?LHS by blast
656 \medskip Theorem for periodic function on discrete sets. *}
659 assumes dpos: "0 < (d::int)" and modd: "ALL (x::int) (k::int). P x = P (x+k*d)"
660 shows "(EX x::int. P x) = (EX (j::int) : {1..d} . P j)"
664 then obtain x where P: "P x" ..
665 have "x mod d = x + (-(x div d))*d"
666 by(simp add:zmod_zdiv_equality mult_ac eq_diff_eq)
667 hence Pmod: "P x = P(x mod d)" using modd by (simp only:)
671 hence "P 0" using P Pmod by simp
672 moreover have "P 0 = P(0 + 1*d)" using modd by blast
673 ultimately have "P d" by simp
674 moreover have "d : {1..d}" using dpos by(simp add:atLeastAtMost_iff)
675 ultimately show ?RHS ..
677 assume not0: "x mod d \<noteq> 0"
678 have "P(x mod d)" using dpos P Pmod by(simp add:pos_mod_sign pos_mod_bound)
679 moreover have "x mod d : {1..d}"
681 have "0 \<le> x mod d" by(rule pos_mod_sign)
682 moreover have "x mod d < d" by(rule pos_mod_bound)
683 ultimately show ?thesis using not0 by(simp add:atLeastAtMost_iff)
685 ultimately show ?RHS ..
688 assume ?RHS thus ?LHS by blast
691 lemma decr_mult_lemma:
692 assumes dpos: "(0::int) < d" and
693 minus: "ALL x::int. P x \<longrightarrow> P(x - d)" and
695 shows "ALL x. P x \<longrightarrow> P(x - k*d)"
697 proof (induct rule:int_ge_induct)
698 case base thus ?case by simp
704 have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
705 also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)"
706 using minus[THEN spec, of "x - i * d"]
707 by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
708 ultimately show "P x \<longrightarrow> P(x - (i + 1) * d)" by blast
712 lemma incr_mult_lemma:
713 assumes dpos: "(0::int) < d" and
714 plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and
716 shows "ALL x. P x \<longrightarrow> P(x + k*d)"
718 proof (induct rule:int_ge_induct)
719 case base thus ?case by simp
725 have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast
726 also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)"
727 using plus[THEN spec, of "x + i * d"]
728 by (simp add:int_distrib zadd_ac)
729 ultimately show "P x \<longrightarrow> P(x + (i + 1) * d)" by blast
733 lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
734 ==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D)
735 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
736 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (b::int) : B. P (b+j)))"
739 apply(drule minusinfinity)
743 apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
744 apply(frule_tac x = x and z=z in decr_lemma)
745 apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
747 apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
750 apply(drule (1) minf_vee)
752 apply(blast dest:decr_mult_lemma)
755 text {* Cooper Theorem, plus infinity version. *}
756 lemma cppi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. z < x --> (P x = P1 x))
757 ==> ALL x.~(EX (j::int) : {1..D}. EX (a::int) : A. P(a - j)) --> P (x) --> P (x + D)
758 ==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x+k*D))))
759 ==> (EX (x::int). P(x)) = ((EX (j::int) : {1..D} . (P1(j))) | (EX (j::int) : {1..D}. EX (a::int) : A. P (a - j)))"
762 apply(drule plusinfinity)
766 apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x + k*D)")
767 apply(frule_tac x = x and z=z in incr_lemma)
768 apply(subgoal_tac "P1(x + (\<bar>x - z\<bar> + 1) * D)")
770 apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
773 apply(drule (1) pinf_vee)
775 apply(blast dest:incr_mult_lemma)
780 \bigskip Theorems for the quantifier elminination Functions. *}
782 lemma qe_ex_conj: "(EX (x::int). A x) = R
783 ==> (EX (x::int). P x) = (Q & (EX x::int. A x))
784 ==> (EX (x::int). P x) = (Q & R)"
787 lemma qe_ex_nconj: "(EX (x::int). P x) = (True & Q)
788 ==> (EX (x::int). P x) = Q"
791 lemma qe_conjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 & Q1) = (P2 & Q2)"
794 lemma qe_disjI: "P1 = P2 ==> Q1 = Q2 ==> (P1 | Q1) = (P2 | Q2)"
797 lemma qe_impI: "P1 = P2 ==> Q1 = Q2 ==> (P1 --> Q1) = (P2 --> Q2)"
800 lemma qe_eqI: "P1 = P2 ==> Q1 = Q2 ==> (P1 = Q1) = (P2 = Q2)"
803 lemma qe_Not: "P = Q ==> (~P) = (~Q)"
806 lemma qe_ALL: "(EX x. ~P x) = R ==> (ALL x. P x) = (~R)"
809 text {* \bigskip Theorems for proving NNF *}
811 lemma nnf_im: "((~P) = P1) ==> (Q=Q1) ==> ((P --> Q) = (P1 | Q1))"
814 lemma nnf_eq: "((P & Q) = (P1 & Q1)) ==> (((~P) & (~Q)) = (P2 & Q2)) ==> ((P = Q) = ((P1 & Q1)|(P2 & Q2)))"
817 lemma nnf_nn: "(P = Q) ==> ((~~P) = Q)"
819 lemma nnf_ncj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P & Q)) = (P1 | Q1))"
822 lemma nnf_ndj: "((~P) = P1) ==> ((~Q) = Q1) ==> ((~(P | Q)) = (P1 & Q1))"
824 lemma nnf_nim: "(P = P1) ==> ((~Q) = Q1) ==> ((~(P --> Q)) = (P1 & Q1))"
826 lemma nnf_neq: "((P & (~Q)) = (P1 & Q1)) ==> (((~P) & Q) = (P2 & Q2)) ==> ((~(P = Q)) = ((P1 & Q1)|(P2 & Q2)))"
828 lemma nnf_sdj: "((A & (~B)) = (A1 & B1)) ==> ((C & (~D)) = (C1 & D1)) ==> (A = (~C)) ==> ((~((A & B) | (C & D))) = ((A1 & B1) | (C1 & D1)))"
832 lemma qe_exI2: "A = B ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
835 lemma qe_exI: "(!!x::int. A x = B x) ==> (EX (x::int). A(x)) = (EX (x::int). B(x))"
838 lemma qe_ALLI: "(!!x::int. A x = B x) ==> (ALL (x::int). A(x)) = (ALL (x::int). B(x))"
841 lemma cp_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j)))
842 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (b::int) : B. (P1 (j) | P(b+j))) "
845 lemma cppi_expand: "(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j)))
846 ==>(EX (x::int). P (x)) = (EX (j::int) : {1..d}. EX (a::int) : A. (P1 (j) | P(a - j))) "
850 lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
851 apply(simp add:atLeastAtMost_def atLeast_def atMost_def)
855 text {* \bigskip Theorems required for the @{text adjustcoeffitienteq} *}
857 lemma ac_dvd_eq: assumes not0: "0 ~= (k::int)"
858 shows "((m::int) dvd (c*n+t)) = (k*m dvd ((k*c)*n+(k*t)))" (is "?P = ?Q")
862 apply(simp add:dvd_def)
865 apply(drule_tac f = "op * k" in arg_cong)
866 apply(simp only:int_distrib)
867 apply(rule_tac x = "d" in exI)
868 apply(simp only:mult_ac)
872 then obtain d where "k * c * n + k * t = (k*m)*d" by(fastsimp simp:dvd_def)
873 hence "(c * n + t) * k = (m*d) * k" by(simp add:int_distrib mult_ac)
874 hence "((c * n + t) * k) div k = ((m*d) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
875 hence "c*n+t = m*d" by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
876 thus ?P by(simp add:dvd_def)
879 lemma ac_lt_eq: assumes gr0: "0 < (k::int)"
880 shows "((m::int) < (c*n+t)) = (k*m <((k*c)*n+(k*t)))" (is "?P = ?Q")
883 show ?Q using zmult_zless_mono2[OF P gr0] by(simp add: int_distrib mult_ac)
886 hence "0 < k*(c*n + t - m)" by(simp add: int_distrib mult_ac)
887 with gr0 have "0 < (c*n + t - m)" by(simp add: zero_less_mult_iff)
891 lemma ac_eq_eq : assumes not0: "0 ~= (k::int)" shows "((m::int) = (c*n+t)) = (k*m =((k*c)*n+(k*t)) )" (is "?P = ?Q")
895 apply(drule_tac f = "op * k" in arg_cong)
896 apply(simp only:int_distrib)
900 hence "m * k = (c*n + t) * k" by(simp add:int_distrib mult_ac)
901 hence "((m) * k) div k = ((c*n + t) * k) div k" by(rule arg_cong[of _ _ "%t. t div k"])
902 thus ?P by(simp add: zdiv_zmult_self1[OF not0[symmetric]])
905 lemma ac_pi_eq: assumes gr0: "0 < (k::int)" shows "(~((0::int) < (c*n + t))) = (0 < ((-k)*c)*n + ((-k)*t + k))"
907 have "(~ (0::int) < (c*n + t)) = (0<1-(c*n + t))" by arith
908 also have "(1-(c*n + t)) = (-1*c)*n + (-t+1)" by(simp add: int_distrib mult_ac)
909 also have "0<(-1*c)*n + (-t+1) = (0 < (k*(-1*c)*n) + (k*(-t+1)))" by(rule ac_lt_eq[of _ 0,OF gr0,simplified])
910 also have "(k*(-1*c)*n) + (k*(-t+1)) = ((-k)*c)*n + ((-k)*t + k)" by(simp add: int_distrib mult_ac)
911 finally show ?thesis .
914 lemma binminus_uminus_conv: "(a::int) - b = a + (-b)"
917 lemma linearize_dvd: "(t::int) = t1 ==> (d dvd t) = (d dvd t1)"
920 lemma lf_lt: "(l::int) = ll ==> (r::int) = lr ==> (l < r) =(ll < lr)"
923 lemma lf_eq: "(l::int) = ll ==> (r::int) = lr ==> (l = r) =(ll = lr)"
926 lemma lf_dvd: "(l::int) = ll ==> (r::int) = lr ==> (l dvd r) =(ll dvd lr)"
929 text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
931 theorem all_nat: "(\<forall>x::nat. P x) = (\<forall>x::int. 0 <= x \<longrightarrow> P (nat x))"
932 by (simp split add: split_nat)
934 theorem ex_nat: "(\<exists>x::nat. P x) = (\<exists>x::int. 0 <= x \<and> P (nat x))"
935 apply (simp split add: split_nat)
938 apply (rule_tac x = "int x" in exI)
941 apply (rule_tac x = "nat x" in exI)
943 apply (erule_tac x = "nat x" in allE)
947 theorem zdiff_int_split: "P (int (x - y)) =
948 ((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"
949 apply (case_tac "y \<le> x")
950 apply (simp_all add: zdiff_int)
953 theorem zdvd_int: "(x dvd y) = (int x dvd int y)"
954 apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric]
955 nat_0_le cong add: conj_cong)
959 apply (case_tac "x=0")
960 apply (rule_tac x=0 in exI)
962 apply (case_tac "0 \<le> k")
964 apply (simp add: linorder_not_le)
965 apply (drule mult_strict_left_mono_neg [OF iffD2 [OF zero_less_int_conv]])
967 apply (simp add: mult_ac)
970 theorem number_of1: "(0::int) <= number_of n \<Longrightarrow> (0::int) <= number_of (n BIT b)"
973 theorem number_of2: "(0::int) <= number_of bin.Pls" by simp
975 theorem Suc_plus1: "Suc n = n + 1" by simp
978 \medskip Specific instances of congruence rules, to prevent
979 simplifier from looping. *}
981 theorem imp_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<longrightarrow> P) = (0 <= x \<longrightarrow> P')"
984 theorem conj_le_cong: "(0 <= x \<Longrightarrow> P = P') \<Longrightarrow> (0 <= (x::nat) \<and> P) = (0 <= x \<and> P')"
988 use "cooper_proof.ML"
992 setup "Presburger.setup"