| author | wenzelm | 
| Sun, 14 Jun 2015 23:22:31 +0200 | |
| changeset 60478 | d1a9d098f870 | 
| parent 58925 | 1b655309617c | 
| child 60758 | d8d85a8172b5 | 
| permissions | -rw-r--r-- | 
| 23465 | 1  | 
(* Title: HOL/Presburger.thy  | 
2  | 
Author: Amine Chaieb, TU Muenchen  | 
|
3  | 
*)  | 
|
4  | 
||
| 58889 | 5  | 
section {* Decision Procedure for Presburger Arithmetic *}
 | 
| 23472 | 6  | 
|
| 23465 | 7  | 
theory Presburger  | 
| 
47317
 
432b29a96f61
modernized obsolete old-style theory name with proper new-style underscore
 
huffman 
parents: 
47165 
diff
changeset
 | 
8  | 
imports Groebner_Basis Set_Interval  | 
| 58925 | 9  | 
keywords "try0" :: diag  | 
| 23465 | 10  | 
begin  | 
11  | 
||
| 48891 | 12  | 
ML_file "Tools/Qelim/qelim.ML"  | 
13  | 
ML_file "Tools/Qelim/cooper_procedure.ML"  | 
|
14  | 
||
| 23465 | 15  | 
subsection{* The @{text "-\<infinity>"} and @{text "+\<infinity>"} Properties *}
 | 
16  | 
||
17  | 
lemma minf:  | 
|
18  | 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk>  | 
|
19  | 
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<and> Q x) = (P' x \<and> Q' x)"  | 
|
20  | 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk>  | 
|
21  | 
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<or> Q x) = (P' x \<or> Q' x)"  | 
|
22  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False"
 | 
|
23  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True"
 | 
|
24  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True"
 | 
|
25  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
 | 
|
26  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
 | 
|
27  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
 | 
|
| 45425 | 28  | 
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})<z. (d dvd x + s) = (d dvd x + s)"
 | 
29  | 
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
 | 
|
| 23465 | 30  | 
"\<exists>z.\<forall>x<z. F = F"  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
44766 
diff
changeset
 | 
31  | 
by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastforce)+) simp_all  | 
| 23465 | 32  | 
|
33  | 
lemma pinf:  | 
|
34  | 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk>  | 
|
35  | 
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<and> Q x) = (P' x \<and> Q' x)"  | 
|
36  | 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk>  | 
|
37  | 
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<or> Q x) = (P' x \<or> Q' x)"  | 
|
38  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False"
 | 
|
39  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True"
 | 
|
40  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x < t) = False"
 | 
|
41  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False"
 | 
|
42  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
 | 
|
43  | 
  "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
 | 
|
| 45425 | 44  | 
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})>z. (d dvd x + s) = (d dvd x + s)"
 | 
45  | 
  "\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
 | 
|
| 23465 | 46  | 
"\<exists>z.\<forall>x>z. F = F"  | 
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
44766 
diff
changeset
 | 
47  | 
by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastforce)+) simp_all  | 
| 23465 | 48  | 
|
49  | 
lemma inf_period:  | 
|
50  | 
"\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk>  | 
|
51  | 
\<Longrightarrow> \<forall>x k. (P x \<and> Q x) = (P (x - k*D) \<and> Q (x - k*D))"  | 
|
52  | 
"\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk>  | 
|
53  | 
\<Longrightarrow> \<forall>x k. (P x \<or> Q x) = (P (x - k*D) \<or> Q (x - k*D))"  | 
|
| 
35050
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
33318 
diff
changeset
 | 
54  | 
  "(d::'a::{comm_ring,Rings.dvd}) dvd D \<Longrightarrow> \<forall>x k. (d dvd x + t) = (d dvd (x - k*D) + t)"
 | 
| 
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
33318 
diff
changeset
 | 
55  | 
  "(d::'a::{comm_ring,Rings.dvd}) dvd D \<Longrightarrow> \<forall>x k. (\<not>d dvd x + t) = (\<not>d dvd (x - k*D) + t)"
 | 
| 23465 | 56  | 
"\<forall>x k. F = F"  | 
| 29667 | 57  | 
apply (auto elim!: dvdE simp add: algebra_simps)  | 
| 
57512
 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 
haftmann 
parents: 
56850 
diff
changeset
 | 
58  | 
unfolding mult.assoc [symmetric] distrib_right [symmetric] left_diff_distrib [symmetric]  | 
| 
 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 
haftmann 
parents: 
56850 
diff
changeset
 | 
59  | 
unfolding dvd_def mult.commute [of d]  | 
| 27668 | 60  | 
by auto  | 
| 23465 | 61  | 
|
| 23472 | 62  | 
subsection{* The A and B sets *}
 | 
| 23465 | 63  | 
lemma bset:  | 
64  | 
  "\<lbrakk>\<forall>x.(\<forall>j \<in> {1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
 | 
|
65  | 
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow> 
 | 
|
66  | 
  \<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))"
 | 
|
67  | 
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x - D) ;
 | 
|
68  | 
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x - D)\<rbrakk> \<Longrightarrow> 
 | 
|
69  | 
  \<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))"
 | 
|
70  | 
  "\<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))"
 | 
|
71  | 
  "\<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))"
 | 
|
72  | 
  "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))"
 | 
|
73  | 
  "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))"
 | 
|
74  | 
  "\<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))"
 | 
|
75  | 
  "\<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))"
 | 
|
76  | 
  "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))"
 | 
|
77  | 
  "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))"
 | 
|
78  | 
  "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> F \<longrightarrow> F"
 | 
|
79  | 
proof (blast, blast)  | 
|
80  | 
assume dp: "D > 0" and tB: "t - 1\<in> B"  | 
|
81  | 
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x - D = t))" 
 | 
|
| 27668 | 82  | 
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t - 1"])  | 
83  | 
apply algebra using dp tB by simp_all  | 
|
| 23465 | 84  | 
next  | 
85  | 
assume dp: "D > 0" and tB: "t \<in> B"  | 
|
86  | 
  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))" 
 | 
|
87  | 
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])  | 
|
| 27668 | 88  | 
apply algebra  | 
| 23465 | 89  | 
using dp tB by simp_all  | 
90  | 
next  | 
|
91  | 
  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
 | 
|
92  | 
next  | 
|
93  | 
  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
 | 
|
94  | 
next  | 
|
95  | 
assume dp: "D > 0" and tB:"t \<in> B"  | 
|
96  | 
  {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"
 | 
|
97  | 
hence "x -t \<le> D" and "1 \<le> x - t" by simp+  | 
|
98  | 
      hence "\<exists>j \<in> {1 .. D}. x - t = j" by auto
 | 
|
| 29667 | 99  | 
      hence "\<exists>j \<in> {1 .. D}. x = t + j" by (simp add: algebra_simps)
 | 
| 23465 | 100  | 
with nob tB have "False" by simp}  | 
101  | 
  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
 | 
|
102  | 
next  | 
|
103  | 
assume dp: "D > 0" and tB:"t - 1\<in> B"  | 
|
104  | 
  {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"
 | 
|
105  | 
hence "x - (t - 1) \<le> D" and "1 \<le> x - (t - 1)" by simp+  | 
|
106  | 
      hence "\<exists>j \<in> {1 .. D}. x - (t - 1) = j" by auto
 | 
|
| 29667 | 107  | 
      hence "\<exists>j \<in> {1 .. D}. x = (t - 1) + j" by (simp add: algebra_simps)
 | 
| 23465 | 108  | 
with nob tB have "False" by simp}  | 
109  | 
  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
 | 
|
110  | 
next  | 
|
111  | 
assume d: "d dvd D"  | 
|
| 27668 | 112  | 
  {fix x assume H: "d dvd x + t" with d have "d dvd (x - D) + t" by algebra}
 | 
| 23465 | 113  | 
  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
 | 
114  | 
next  | 
|
115  | 
assume d: "d dvd D"  | 
|
| 
27651
 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 
haftmann 
parents: 
27540 
diff
changeset
 | 
116  | 
  {fix x assume H: "\<not>(d dvd x + t)" with d have "\<not> d dvd (x - D) + t"
 | 
| 29667 | 117  | 
by (clarsimp simp add: dvd_def,erule_tac x= "ka + k" in allE,simp add: algebra_simps)}  | 
| 23465 | 118  | 
  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
 | 
119  | 
qed blast  | 
|
120  | 
||
121  | 
lemma aset:  | 
|
122  | 
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
 | 
|
123  | 
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 
 | 
|
124  | 
  \<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))"
 | 
|
125  | 
  "\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> P x \<longrightarrow> P(x + D) ;
 | 
|
126  | 
     \<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 
 | 
|
127  | 
  \<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))"
 | 
|
128  | 
  "\<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))"
 | 
|
129  | 
  "\<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))"
 | 
|
130  | 
  "\<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))"
 | 
|
131  | 
  "\<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))"
 | 
|
132  | 
  "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))"
 | 
|
133  | 
  "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))"
 | 
|
134  | 
  "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))"
 | 
|
135  | 
  "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))"
 | 
|
136  | 
  "\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j) \<longrightarrow> F \<longrightarrow> F"
 | 
|
137  | 
proof (blast, blast)  | 
|
138  | 
assume dp: "D > 0" and tA: "t + 1 \<in> A"  | 
|
139  | 
  show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b - j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))" 
 | 
|
140  | 
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t + 1"])  | 
|
141  | 
using dp tA by simp_all  | 
|
142  | 
next  | 
|
143  | 
assume dp: "D > 0" and tA: "t \<in> A"  | 
|
144  | 
  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))" 
 | 
|
145  | 
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"])  | 
|
146  | 
using dp tA by simp_all  | 
|
147  | 
next  | 
|
148  | 
  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
 | 
|
149  | 
next  | 
|
150  | 
  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
 | 
|
151  | 
next  | 
|
152  | 
assume dp: "D > 0" and tA:"t \<in> A"  | 
|
153  | 
  {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"
 | 
|
154  | 
hence "t - x \<le> D" and "1 \<le> t - x" by simp+  | 
|
155  | 
      hence "\<exists>j \<in> {1 .. D}. t - x = j" by auto
 | 
|
| 29667 | 156  | 
      hence "\<exists>j \<in> {1 .. D}. x = t - j" by (auto simp add: algebra_simps) 
 | 
| 23465 | 157  | 
with nob tA have "False" by simp}  | 
158  | 
  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
 | 
|
159  | 
next  | 
|
160  | 
assume dp: "D > 0" and tA:"t + 1\<in> A"  | 
|
161  | 
  {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"
 | 
|
| 29667 | 162  | 
hence "(t + 1) - x \<le> D" and "1 \<le> (t + 1) - x" by (simp_all add: algebra_simps)  | 
| 23465 | 163  | 
      hence "\<exists>j \<in> {1 .. D}. (t + 1) - x = j" by auto
 | 
| 29667 | 164  | 
      hence "\<exists>j \<in> {1 .. D}. x = (t + 1) - j" by (auto simp add: algebra_simps)
 | 
| 23465 | 165  | 
with nob tA have "False" by simp}  | 
166  | 
  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
 | 
|
167  | 
next  | 
|
168  | 
assume d: "d dvd D"  | 
|
169  | 
  {fix x assume H: "d dvd x + t" with d have "d dvd (x + D) + t"
 | 
|
| 29667 | 170  | 
by (clarsimp simp add: dvd_def,rule_tac x= "ka + k" in exI,simp add: algebra_simps)}  | 
| 23465 | 171  | 
  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
 | 
172  | 
next  | 
|
173  | 
assume d: "d dvd D"  | 
|
174  | 
  {fix x assume H: "\<not>(d dvd x + t)" with d have "\<not>d dvd (x + D) + t"
 | 
|
| 29667 | 175  | 
by (clarsimp simp add: dvd_def,erule_tac x= "ka - k" in allE,simp add: algebra_simps)}  | 
| 23465 | 176  | 
  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
 | 
177  | 
qed blast  | 
|
178  | 
||
179  | 
subsection{* Cooper's Theorem @{text "-\<infinity>"} and @{text "+\<infinity>"} Version *}
 | 
|
180  | 
||
181  | 
subsubsection{* First some trivial facts about periodic sets or predicates *}
 | 
|
182  | 
lemma periodic_finite_ex:  | 
|
183  | 
assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x - k*d)"  | 
|
184  | 
  shows "(EX x. P x) = (EX j : {1..d}. P j)"
 | 
|
185  | 
(is "?LHS = ?RHS")  | 
|
186  | 
proof  | 
|
187  | 
assume ?LHS  | 
|
188  | 
then obtain x where P: "P x" ..  | 
|
| 
57514
 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 
haftmann 
parents: 
57512 
diff
changeset
 | 
189  | 
have "x mod d = x - (x div d)*d" by(simp add:zmod_zdiv_equality ac_simps eq_diff_eq)  | 
| 23465 | 190  | 
hence Pmod: "P x = P(x mod d)" using modd by simp  | 
191  | 
show ?RHS  | 
|
192  | 
proof (cases)  | 
|
193  | 
assume "x mod d = 0"  | 
|
194  | 
hence "P 0" using P Pmod by simp  | 
|
195  | 
moreover have "P 0 = P(0 - (-1)*d)" using modd by blast  | 
|
196  | 
ultimately have "P d" by simp  | 
|
| 35216 | 197  | 
    moreover have "d : {1..d}" using dpos by simp
 | 
| 23465 | 198  | 
ultimately show ?RHS ..  | 
199  | 
next  | 
|
200  | 
assume not0: "x mod d \<noteq> 0"  | 
|
| 35216 | 201  | 
have "P(x mod d)" using dpos P Pmod by simp  | 
| 23465 | 202  | 
    moreover have "x mod d : {1..d}"
 | 
203  | 
proof -  | 
|
204  | 
from dpos have "0 \<le> x mod d" by(rule pos_mod_sign)  | 
|
205  | 
moreover from dpos have "x mod d < d" by(rule pos_mod_bound)  | 
|
| 35216 | 206  | 
ultimately show ?thesis using not0 by simp  | 
| 23465 | 207  | 
qed  | 
208  | 
ultimately show ?RHS ..  | 
|
209  | 
qed  | 
|
210  | 
qed auto  | 
|
211  | 
||
212  | 
subsubsection{* The @{text "-\<infinity>"} Version*}
 | 
|
213  | 
||
214  | 
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x - (abs(x-z)+1) * d < z"  | 
|
215  | 
by(induct rule: int_gr_induct,simp_all add:int_distrib)  | 
|
216  | 
||
217  | 
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(x-z)+1) * d"  | 
|
218  | 
by(induct rule: int_gr_induct, simp_all add:int_distrib)  | 
|
219  | 
||
220  | 
lemma decr_mult_lemma:  | 
|
221  | 
assumes dpos: "(0::int) < d" and minus: "\<forall>x. P x \<longrightarrow> P(x - d)" and knneg: "0 <= k"  | 
|
222  | 
shows "ALL x. P x \<longrightarrow> P(x - k*d)"  | 
|
223  | 
using knneg  | 
|
224  | 
proof (induct rule:int_ge_induct)  | 
|
225  | 
case base thus ?case by simp  | 
|
226  | 
next  | 
|
227  | 
case (step i)  | 
|
228  | 
  {fix x
 | 
|
229  | 
have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast  | 
|
230  | 
also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)" using minus[THEN spec, of "x - i * d"]  | 
|
| 
35050
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
33318 
diff
changeset
 | 
231  | 
by (simp add: algebra_simps)  | 
| 23465 | 232  | 
ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}  | 
233  | 
thus ?case ..  | 
|
234  | 
qed  | 
|
235  | 
||
236  | 
lemma minusinfinity:  | 
|
237  | 
assumes dpos: "0 < d" and  | 
|
238  | 
P1eqP1: "ALL x k. P1 x = P1(x - k*d)" and ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)"  | 
|
239  | 
shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)"  | 
|
240  | 
proof  | 
|
241  | 
assume eP1: "EX x. P1 x"  | 
|
242  | 
then obtain x where P1: "P1 x" ..  | 
|
243  | 
from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" ..  | 
|
244  | 
let ?w = "x - (abs(x-z)+1) * d"  | 
|
245  | 
from dpos have w: "?w < z" by(rule decr_lemma)  | 
|
246  | 
have "P1 x = P1 ?w" using P1eqP1 by blast  | 
|
247  | 
also have "\<dots> = P(?w)" using w P1eqP by blast  | 
|
248  | 
finally have "P ?w" using P1 by blast  | 
|
249  | 
thus "EX x. P x" ..  | 
|
250  | 
qed  | 
|
251  | 
||
252  | 
lemma cpmi:  | 
|
253  | 
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x< z. P x = P' x"  | 
|
254  | 
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> B. x \<noteq> b+j) --> P (x) --> P (x - D)"
 | 
|
255  | 
and pd: "\<forall> x k. P' x = P' (x-k*D)"  | 
|
256  | 
  shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j) | (\<exists> j \<in> {1..D}.\<exists> b\<in> B. P (b+j)))" 
 | 
|
257  | 
(is "?L = (?R1 \<or> ?R2)")  | 
|
258  | 
proof-  | 
|
259  | 
 {assume "?R2" hence "?L"  by blast}
 | 
|
260  | 
moreover  | 
|
261  | 
 {assume H:"?R1" hence "?L" using minusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
 | 
|
262  | 
moreover  | 
|
263  | 
 { fix x
 | 
|
264  | 
assume P: "P x" and H: "\<not> ?R2"  | 
|
265  | 
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))" and P: "P y"
 | 
|
266  | 
     hence "~(EX (j::int) : {1..D}. EX (b::int) : B. y = b+j)" by auto
 | 
|
267  | 
with nb P have "P (y - D)" by auto }  | 
|
268  | 
   hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D)" by blast
 | 
|
269  | 
with H P have th: " \<forall>x. P x \<longrightarrow> P (x - D)" by auto  | 
|
270  | 
from p1 obtain z where z: "ALL x. x < z --> (P x = P' x)" by blast  | 
|
271  | 
let ?y = "x - (\<bar>x - z\<bar> + 1)*D"  | 
|
272  | 
have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith  | 
|
273  | 
from dp have yz: "?y < z" using decr_lemma[OF dp] by simp  | 
|
274  | 
from z[rule_format, OF yz] decr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto  | 
|
275  | 
with periodic_finite_ex[OF dp pd]  | 
|
276  | 
have "?R1" by blast}  | 
|
277  | 
ultimately show ?thesis by blast  | 
|
278  | 
qed  | 
|
279  | 
||
280  | 
subsubsection {* The @{text "+\<infinity>"} Version*}
 | 
|
281  | 
||
282  | 
lemma plusinfinity:  | 
|
283  | 
assumes dpos: "(0::int) < d" and  | 
|
284  | 
P1eqP1: "\<forall>x k. P' x = P'(x - k*d)" and ePeqP1: "\<exists> z. \<forall> x>z. P x = P' x"  | 
|
285  | 
shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)"  | 
|
286  | 
proof  | 
|
287  | 
assume eP1: "EX x. P' x"  | 
|
288  | 
then obtain x where P1: "P' x" ..  | 
|
289  | 
from ePeqP1 obtain z where P1eqP: "\<forall>x>z. P x = P' x" ..  | 
|
290  | 
let ?w' = "x + (abs(x-z)+1) * d"  | 
|
291  | 
let ?w = "x - (-(abs(x-z) + 1))*d"  | 
|
| 29667 | 292  | 
have ww'[simp]: "?w = ?w'" by (simp add: algebra_simps)  | 
| 23465 | 293  | 
from dpos have w: "?w > z" by(simp only: ww' incr_lemma)  | 
294  | 
hence "P' x = P' ?w" using P1eqP1 by blast  | 
|
295  | 
also have "\<dots> = P(?w)" using w P1eqP by blast  | 
|
296  | 
finally have "P ?w" using P1 by blast  | 
|
297  | 
thus "EX x. P x" ..  | 
|
298  | 
qed  | 
|
299  | 
||
300  | 
lemma incr_mult_lemma:  | 
|
301  | 
assumes dpos: "(0::int) < d" and plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and knneg: "0 <= k"  | 
|
302  | 
shows "ALL x. P x \<longrightarrow> P(x + k*d)"  | 
|
303  | 
using knneg  | 
|
304  | 
proof (induct rule:int_ge_induct)  | 
|
305  | 
case base thus ?case by simp  | 
|
306  | 
next  | 
|
307  | 
case (step i)  | 
|
308  | 
  {fix x
 | 
|
309  | 
have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast  | 
|
310  | 
also have "\<dots> \<longrightarrow> P(x + (i + 1) * d)" using plus[THEN spec, of "x + i * d"]  | 
|
| 
57514
 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 
haftmann 
parents: 
57512 
diff
changeset
 | 
311  | 
by (simp add:int_distrib ac_simps)  | 
| 23465 | 312  | 
ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast}  | 
313  | 
thus ?case ..  | 
|
314  | 
qed  | 
|
315  | 
||
316  | 
lemma cppi:  | 
|
317  | 
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x> z. P x = P' x"  | 
|
318  | 
  and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> A. x \<noteq> b - j) --> P (x) --> P (x + D)"
 | 
|
319  | 
and pd: "\<forall> x k. P' x= P' (x-k*D)"  | 
|
320  | 
  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)")
 | 
|
321  | 
proof-  | 
|
322  | 
 {assume "?R2" hence "?L"  by blast}
 | 
|
323  | 
moreover  | 
|
324  | 
 {assume H:"?R1" hence "?L" using plusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp}
 | 
|
325  | 
moreover  | 
|
326  | 
 { fix x
 | 
|
327  | 
assume P: "P x" and H: "\<not> ?R2"  | 
|
328  | 
   {fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>A. P (b - j))" and P: "P y"
 | 
|
329  | 
     hence "~(EX (j::int) : {1..D}. EX (b::int) : A. y = b - j)" by auto
 | 
|
330  | 
with nb P have "P (y + D)" by auto }  | 
|
331  | 
   hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : A. P(b-j)) --> P (x) --> P (x + D)" by blast
 | 
|
332  | 
with H P have th: " \<forall>x. P x \<longrightarrow> P (x + D)" by auto  | 
|
333  | 
from p1 obtain z where z: "ALL x. x > z --> (P x = P' x)" by blast  | 
|
334  | 
let ?y = "x + (\<bar>x - z\<bar> + 1)*D"  | 
|
335  | 
have zp: "0 <= (\<bar>x - z\<bar> + 1)" by arith  | 
|
336  | 
from dp have yz: "?y > z" using incr_lemma[OF dp] by simp  | 
|
337  | 
from z[rule_format, OF yz] incr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto  | 
|
338  | 
with periodic_finite_ex[OF dp pd]  | 
|
339  | 
have "?R1" by blast}  | 
|
340  | 
ultimately show ?thesis by blast  | 
|
341  | 
qed  | 
|
342  | 
||
343  | 
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})"
 | 
|
344  | 
apply(simp add:atLeastAtMost_def atLeast_def atMost_def)  | 
|
| 
44890
 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 
nipkow 
parents: 
44766 
diff
changeset
 | 
345  | 
apply(fastforce)  | 
| 23465 | 346  | 
done  | 
347  | 
||
| 
35050
 
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
 
haftmann 
parents: 
33318 
diff
changeset
 | 
348  | 
theorem unity_coeff_ex: "(\<exists>(x::'a::{semiring_0,Rings.dvd}). P (l * x)) \<equiv> (\<exists>x. l dvd (x + 0) \<and> P x)"
 | 
| 
27651
 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 
haftmann 
parents: 
27540 
diff
changeset
 | 
349  | 
apply (rule eq_reflection [symmetric])  | 
| 23465 | 350  | 
apply (rule iffI)  | 
351  | 
defer  | 
|
352  | 
apply (erule exE)  | 
|
353  | 
apply (rule_tac x = "l * x" in exI)  | 
|
354  | 
apply (simp add: dvd_def)  | 
|
| 
27651
 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 
haftmann 
parents: 
27540 
diff
changeset
 | 
355  | 
apply (rule_tac x = x in exI, simp)  | 
| 23465 | 356  | 
apply (erule exE)  | 
357  | 
apply (erule conjE)  | 
|
| 
27651
 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 
haftmann 
parents: 
27540 
diff
changeset
 | 
358  | 
apply simp  | 
| 23465 | 359  | 
apply (erule dvdE)  | 
360  | 
apply (rule_tac x = k in exI)  | 
|
361  | 
apply simp  | 
|
362  | 
done  | 
|
363  | 
||
| 
54227
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
364  | 
lemma zdvd_mono:  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
365  | 
fixes k m t :: int  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
366  | 
assumes "k \<noteq> 0"  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
367  | 
shows "m dvd t \<equiv> k * m dvd k * t"  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
368  | 
using assms by simp  | 
| 23465 | 369  | 
|
| 
54227
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
370  | 
lemma uminus_dvd_conv:  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
371  | 
fixes d t :: int  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
372  | 
shows "d dvd t \<equiv> - d dvd t" and "d dvd t \<equiv> d dvd - t"  | 
| 23465 | 373  | 
by simp_all  | 
| 32553 | 374  | 
|
| 23465 | 375  | 
text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*}
 | 
| 32553 | 376  | 
|
| 23465 | 377  | 
lemma zdiff_int_split: "P (int (x - y)) =  | 
378  | 
((y \<le> x \<longrightarrow> P (int x - int y)) \<and> (x < y \<longrightarrow> P 0))"  | 
|
| 36800 | 379  | 
by (cases "y \<le> x") (simp_all add: zdiff_int)  | 
| 23465 | 380  | 
|
381  | 
text {*
 | 
|
382  | 
\medskip Specific instances of congruence rules, to prevent  | 
|
383  | 
simplifier from looping. *}  | 
|
384  | 
||
| 
47108
 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 
huffman 
parents: 
45425 
diff
changeset
 | 
385  | 
theorem imp_le_cong:  | 
| 
 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 
huffman 
parents: 
45425 
diff
changeset
 | 
386  | 
"\<lbrakk>x = x'; 0 \<le> x' \<Longrightarrow> P = P'\<rbrakk> \<Longrightarrow> (0 \<le> (x::int) \<longrightarrow> P) = (0 \<le> x' \<longrightarrow> P')"  | 
| 
 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 
huffman 
parents: 
45425 
diff
changeset
 | 
387  | 
by simp  | 
| 23465 | 388  | 
|
| 
47108
 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 
huffman 
parents: 
45425 
diff
changeset
 | 
389  | 
theorem conj_le_cong:  | 
| 
 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 
huffman 
parents: 
45425 
diff
changeset
 | 
390  | 
"\<lbrakk>x = x'; 0 \<le> x' \<Longrightarrow> P = P'\<rbrakk> \<Longrightarrow> (0 \<le> (x::int) \<and> P) = (0 \<le> x' \<and> P')"  | 
| 23465 | 391  | 
by (simp cong: conj_cong)  | 
| 36799 | 392  | 
|
| 48891 | 393  | 
ML_file "Tools/Qelim/cooper.ML"  | 
| 23465 | 394  | 
|
| 47432 | 395  | 
method_setup presburger = {*
 | 
396  | 
let  | 
|
397  | 
fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()  | 
|
398  | 
fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()  | 
|
399  | 
val addN = "add"  | 
|
400  | 
val delN = "del"  | 
|
401  | 
val elimN = "elim"  | 
|
402  | 
val any_keyword = keyword addN || keyword delN || simple_keyword elimN  | 
|
403  | 
val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat;  | 
|
404  | 
in  | 
|
405  | 
Scan.optional (simple_keyword elimN >> K false) true --  | 
|
406  | 
Scan.optional (keyword addN |-- thms) [] --  | 
|
407  | 
Scan.optional (keyword delN |-- thms) [] >>  | 
|
408  | 
(fn ((elim, add_ths), del_ths) => fn ctxt =>  | 
|
409  | 
SIMPLE_METHOD' (Cooper.tac elim add_ths del_ths ctxt))  | 
|
410  | 
end  | 
|
411  | 
*} "Cooper's algorithm for Presburger arithmetic"  | 
|
| 23465 | 412  | 
|
| 
54227
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
413  | 
declare dvd_eq_mod_eq_0 [symmetric, presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
414  | 
declare mod_1 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
415  | 
declare mod_0 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
416  | 
declare mod_by_1 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
417  | 
declare mod_self [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
418  | 
declare div_by_0 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
419  | 
declare mod_by_0 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
420  | 
declare mod_div_trivial [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
421  | 
declare div_mod_equality2 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
422  | 
declare div_mod_equality [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
423  | 
declare mod_div_equality2 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
424  | 
declare mod_div_equality [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
425  | 
declare mod_mult_self1 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
426  | 
declare mod_mult_self2 [presburger]  | 
| 36798 | 427  | 
declare mod2_Suc_Suc[presburger]  | 
| 
54227
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
428  | 
declare not_mod_2_eq_0_eq_1 [presburger]  | 
| 
 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
 
haftmann 
parents: 
49962 
diff
changeset
 | 
429  | 
declare nat_zero_less_power_iff [presburger]  | 
| 36798 | 430  | 
|
| 27668 | 431  | 
lemma [presburger, algebra]: "m mod 2 = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger  | 
432  | 
lemma [presburger, algebra]: "m mod 2 = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger  | 
|
433  | 
lemma [presburger, algebra]: "m mod (Suc (Suc 0)) = (1::nat) \<longleftrightarrow> \<not> 2 dvd m " by presburger  | 
|
434  | 
lemma [presburger, algebra]: "m mod (Suc (Suc 0)) = Suc 0 \<longleftrightarrow> \<not> 2 dvd m " by presburger  | 
|
435  | 
lemma [presburger, algebra]: "m mod 2 = (1::int) \<longleftrightarrow> \<not> 2 dvd m " by presburger  | 
|
| 23465 | 436  | 
|
| 
58777
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
437  | 
context semiring_parity  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
438  | 
begin  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
439  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
440  | 
declare even_times_iff [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
441  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
442  | 
declare even_power [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
443  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
444  | 
lemma [presburger]:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
445  | 
"even (a + b) \<longleftrightarrow> even a \<and> even b \<or> odd a \<and> odd b"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
446  | 
by auto  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
447  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
448  | 
end  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
449  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
450  | 
context ring_parity  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
451  | 
begin  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
452  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
453  | 
declare even_minus [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
454  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
455  | 
end  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
456  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
457  | 
context linordered_idom  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
458  | 
begin  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
459  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
460  | 
declare zero_le_power_eq [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
461  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
462  | 
declare zero_less_power_eq [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
463  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
464  | 
declare power_less_zero_eq [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
465  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
466  | 
declare power_le_zero_eq [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
467  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
468  | 
end  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
469  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
470  | 
declare even_Suc [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
471  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
472  | 
lemma [presburger]:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
473  | 
"Suc n div Suc (Suc 0) = n div Suc (Suc 0) \<longleftrightarrow> even n"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
474  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
475  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
476  | 
declare even_diff_nat [presburger]  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
477  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
478  | 
lemma [presburger]:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
479  | 
fixes k :: int  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
480  | 
shows "(k + 1) div 2 = k div 2 \<longleftrightarrow> even k"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
481  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
482  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
483  | 
lemma [presburger]:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
484  | 
fixes k :: int  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
485  | 
shows "(k + 1) div 2 = k div 2 + 1 \<longleftrightarrow> odd k"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
486  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
487  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
488  | 
lemma [presburger]:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
489  | 
"even n \<longleftrightarrow> even (int n)"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
490  | 
using even_int_iff [of n] by simp  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
491  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
492  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
493  | 
subsection {* Nice facts about division by @{term 4} *}  
 | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
494  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
495  | 
lemma even_even_mod_4_iff:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
496  | 
"even (n::nat) \<longleftrightarrow> even (n mod 4)"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
497  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
498  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
499  | 
lemma odd_mod_4_div_2:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
500  | 
"n mod 4 = (3::nat) \<Longrightarrow> odd ((n - 1) div 2)"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
501  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
502  | 
|
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
503  | 
lemma even_mod_4_div_2:  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
504  | 
"n mod 4 = (1::nat) \<Longrightarrow> even ((n - 1) div 2)"  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
505  | 
by presburger  | 
| 
 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
 
haftmann 
parents: 
57514 
diff
changeset
 | 
506  | 
|
| 56850 | 507  | 
|
508  | 
subsection {* Try0 *}
 | 
|
509  | 
||
510  | 
ML_file "Tools/try0.ML"  | 
|
511  | 
||
| 23465 | 512  | 
end  |