author  haftmann 
Thu, 23 Oct 2014 19:40:39 +0200  
changeset 58777  6ba2f1fa243b 
parent 57514  bdc2c6b40bf2 
child 58787  af9eb5e566dd 
permissions  rwrr 
23465  1 
(* Title: HOL/Presburger.thy 
2 
Author: Amine Chaieb, TU Muenchen 

3 
*) 

4 

23472  5 
header {* Decision Procedure for Presburger Arithmetic *} 
6 

23465  7 
theory Presburger 
47317
432b29a96f61
modernized obsolete oldstyle theory name with proper newstyle underscore
huffman
parents:
47165
diff
changeset

8 
imports Groebner_Basis Set_Interval 
23465  9 
begin 
10 

48891  11 
ML_file "Tools/Qelim/qelim.ML" 
12 
ML_file "Tools/Qelim/cooper_procedure.ML" 

13 

23465  14 
subsection{* The @{text "\<infinity>"} and @{text "+\<infinity>"} Properties *} 
15 

16 
lemma minf: 

17 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk> 

18 
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<and> Q x) = (P' x \<and> Q' x)" 

19 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x<z. P x = P' x; \<exists>z.\<forall>x<z. Q x = Q' x\<rbrakk> 

20 
\<Longrightarrow> \<exists>z.\<forall>x<z. (P x \<or> Q x) = (P' x \<or> Q' x)" 

21 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x = t) = False" 

22 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<noteq> t) = True" 

23 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x < t) = True" 

24 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True" 

25 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False" 

26 
"\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False" 

45425  27 
"\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})<z. (d dvd x + s) = (d dvd x + s)" 
28 
"\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)" 

23465  29 
"\<exists>z.\<forall>x<z. F = F" 
44890
22f665a2e91c
new fastforce replacing fastsimp  less confusing name
nipkow
parents:
44766
diff
changeset

30 
by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastforce)+) simp_all 
23465  31 

32 
lemma pinf: 

33 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk> 

34 
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<and> Q x) = (P' x \<and> Q' x)" 

35 
"\<lbrakk>\<exists>(z ::'a::linorder).\<forall>x>z. P x = P' x; \<exists>z.\<forall>x>z. Q x = Q' x\<rbrakk> 

36 
\<Longrightarrow> \<exists>z.\<forall>x>z. (P x \<or> Q x) = (P' x \<or> Q' x)" 

37 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x = t) = False" 

38 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<noteq> t) = True" 

39 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x < t) = False" 

40 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False" 

41 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True" 

42 
"\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True" 

45425  43 
"\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})>z. (d dvd x + s) = (d dvd x + s)" 
44 
"\<exists>z.\<forall>(x::'b::{linorder,plus,Rings.dvd})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)" 

23465  45 
"\<exists>z.\<forall>x>z. F = F" 
44890
22f665a2e91c
new fastforce replacing fastsimp  less confusing name
nipkow
parents:
44766
diff
changeset

46 
by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastforce)+) simp_all 
23465  47 

48 
lemma inf_period: 

49 
"\<lbrakk>\<forall>x k. P x = P (x  k*D); \<forall>x k. Q x = Q (x  k*D)\<rbrakk> 

50 
\<Longrightarrow> \<forall>x k. (P x \<and> Q x) = (P (x  k*D) \<and> Q (x  k*D))" 

51 
"\<lbrakk>\<forall>x k. P x = P (x  k*D); \<forall>x k. Q x = Q (x  k*D)\<rbrakk> 

52 
\<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

53 
"(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

54 
"(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  55 
"\<forall>x k. F = F" 
29667  56 
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

57 
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

58 
unfolding dvd_def mult.commute [of d] 
27668  59 
by auto 
23465  60 

23472  61 
subsection{* The A and B sets *} 
23465  62 
lemma bset: 
63 
"\<lbrakk>\<forall>x.(\<forall>j \<in> {1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x  D) ; 

64 
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x  D)\<rbrakk> \<Longrightarrow> 

65 
\<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))" 

66 
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> P x \<longrightarrow> P(x  D) ; 

67 
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> Q x \<longrightarrow> Q(x  D)\<rbrakk> \<Longrightarrow> 

68 
\<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))" 

69 
"\<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))" 

70 
"\<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))" 

71 
"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))" 

72 
"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))" 

73 
"\<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))" 

74 
"\<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))" 

75 
"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))" 

76 
"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))" 

77 
"\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j) \<longrightarrow> F \<longrightarrow> F" 

78 
proof (blast, blast) 

79 
assume dp: "D > 0" and tB: "t  1\<in> B" 

80 
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>B. x \<noteq> b + j)\<longrightarrow> (x = t) \<longrightarrow> (x  D = t))" 

27668  81 
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t  1"]) 
82 
apply algebra using dp tB by simp_all 

23465  83 
next 
84 
assume dp: "D > 0" and tB: "t \<in> B" 

85 
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))" 

86 
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"]) 

27668  87 
apply algebra 
23465  88 
using dp tB by simp_all 
89 
next 

90 
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 

91 
next 

92 
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 

93 
next 

94 
assume dp: "D > 0" and tB:"t \<in> B" 

95 
{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" 

96 
hence "x t \<le> D" and "1 \<le> x  t" by simp+ 

97 
hence "\<exists>j \<in> {1 .. D}. x  t = j" by auto 

29667  98 
hence "\<exists>j \<in> {1 .. D}. x = t + j" by (simp add: algebra_simps) 
23465  99 
with nob tB have "False" by simp} 
100 
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 

101 
next 

102 
assume dp: "D > 0" and tB:"t  1\<in> B" 

103 
{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" 

104 
hence "x  (t  1) \<le> D" and "1 \<le> x  (t  1)" by simp+ 

105 
hence "\<exists>j \<in> {1 .. D}. x  (t  1) = j" by auto 

29667  106 
hence "\<exists>j \<in> {1 .. D}. x = (t  1) + j" by (simp add: algebra_simps) 
23465  107 
with nob tB have "False" by simp} 
108 
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 

109 
next 

110 
assume d: "d dvd D" 

27668  111 
{fix x assume H: "d dvd x + t" with d have "d dvd (x  D) + t" by algebra} 
23465  112 
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 
113 
next 

114 
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

115 
{fix x assume H: "\<not>(d dvd x + t)" with d have "\<not> d dvd (x  D) + t" 
29667  116 
by (clarsimp simp add: dvd_def,erule_tac x= "ka + k" in allE,simp add: algebra_simps)} 
23465  117 
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 
118 
qed blast 

119 

120 
lemma aset: 

121 
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j)\<longrightarrow> P x \<longrightarrow> P(x + D) ; 

122 
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 

123 
\<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))" 

124 
"\<lbrakk>\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j)\<longrightarrow> P x \<longrightarrow> P(x + D) ; 

125 
\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j)\<longrightarrow> Q x \<longrightarrow> Q(x + D)\<rbrakk> \<Longrightarrow> 

126 
\<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))" 

127 
"\<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))" 

128 
"\<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))" 

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 < t) \<longrightarrow> (x + D < t))" 

130 
"\<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))" 

131 
"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))" 

132 
"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))" 

133 
"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))" 

134 
"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))" 

135 
"\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j) \<longrightarrow> F \<longrightarrow> F" 

136 
proof (blast, blast) 

137 
assume dp: "D > 0" and tA: "t + 1 \<in> A" 

138 
show "(\<forall>x.(\<forall>j\<in>{1 .. D}. \<forall>b\<in>A. x \<noteq> b  j)\<longrightarrow> (x = t) \<longrightarrow> (x + D = t))" 

139 
apply (rule allI, rule impI,erule ballE[where x="1"],erule ballE[where x="t + 1"]) 

140 
using dp tA by simp_all 

141 
next 

142 
assume dp: "D > 0" and tA: "t \<in> A" 

143 
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))" 

144 
apply (rule allI, rule impI,erule ballE[where x="D"],erule ballE[where x="t"]) 

145 
using dp tA by simp_all 

146 
next 

147 
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 

148 
next 

149 
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 

150 
next 

151 
assume dp: "D > 0" and tA:"t \<in> A" 

152 
{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" 

153 
hence "t  x \<le> D" and "1 \<le> t  x" by simp+ 

154 
hence "\<exists>j \<in> {1 .. D}. t  x = j" by auto 

29667  155 
hence "\<exists>j \<in> {1 .. D}. x = t  j" by (auto simp add: algebra_simps) 
23465  156 
with nob tA have "False" by simp} 
157 
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 

158 
next 

159 
assume dp: "D > 0" and tA:"t + 1\<in> A" 

160 
{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  161 
hence "(t + 1)  x \<le> D" and "1 \<le> (t + 1)  x" by (simp_all add: algebra_simps) 
23465  162 
hence "\<exists>j \<in> {1 .. D}. (t + 1)  x = j" by auto 
29667  163 
hence "\<exists>j \<in> {1 .. D}. x = (t + 1)  j" by (auto simp add: algebra_simps) 
23465  164 
with nob tA have "False" by simp} 
165 
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 

166 
next 

167 
assume d: "d dvd D" 

168 
{fix x assume H: "d dvd x + t" with d have "d dvd (x + D) + t" 

29667  169 
by (clarsimp simp add: dvd_def,rule_tac x= "ka + k" in exI,simp add: algebra_simps)} 
23465  170 
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 
171 
next 

172 
assume d: "d dvd D" 

173 
{fix x assume H: "\<not>(d dvd x + t)" with d have "\<not>d dvd (x + D) + t" 

29667  174 
by (clarsimp simp add: dvd_def,erule_tac x= "ka  k" in allE,simp add: algebra_simps)} 
23465  175 
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 
176 
qed blast 

177 

178 
subsection{* Cooper's Theorem @{text "\<infinity>"} and @{text "+\<infinity>"} Version *} 

179 

180 
subsubsection{* First some trivial facts about periodic sets or predicates *} 

181 
lemma periodic_finite_ex: 

182 
assumes dpos: "(0::int) < d" and modd: "ALL x k. P x = P(x  k*d)" 

183 
shows "(EX x. P x) = (EX j : {1..d}. P j)" 

184 
(is "?LHS = ?RHS") 

185 
proof 

186 
assume ?LHS 

187 
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

188 
have "x mod d = x  (x div d)*d" by(simp add:zmod_zdiv_equality ac_simps eq_diff_eq) 
23465  189 
hence Pmod: "P x = P(x mod d)" using modd by simp 
190 
show ?RHS 

191 
proof (cases) 

192 
assume "x mod d = 0" 

193 
hence "P 0" using P Pmod by simp 

194 
moreover have "P 0 = P(0  (1)*d)" using modd by blast 

195 
ultimately have "P d" by simp 

35216  196 
moreover have "d : {1..d}" using dpos by simp 
23465  197 
ultimately show ?RHS .. 
198 
next 

199 
assume not0: "x mod d \<noteq> 0" 

35216  200 
have "P(x mod d)" using dpos P Pmod by simp 
23465  201 
moreover have "x mod d : {1..d}" 
202 
proof  

203 
from dpos have "0 \<le> x mod d" by(rule pos_mod_sign) 

204 
moreover from dpos have "x mod d < d" by(rule pos_mod_bound) 

35216  205 
ultimately show ?thesis using not0 by simp 
23465  206 
qed 
207 
ultimately show ?RHS .. 

208 
qed 

209 
qed auto 

210 

211 
subsubsection{* The @{text "\<infinity>"} Version*} 

212 

213 
lemma decr_lemma: "0 < (d::int) \<Longrightarrow> x  (abs(xz)+1) * d < z" 

214 
by(induct rule: int_gr_induct,simp_all add:int_distrib) 

215 

216 
lemma incr_lemma: "0 < (d::int) \<Longrightarrow> z < x + (abs(xz)+1) * d" 

217 
by(induct rule: int_gr_induct, simp_all add:int_distrib) 

218 

219 
lemma decr_mult_lemma: 

220 
assumes dpos: "(0::int) < d" and minus: "\<forall>x. P x \<longrightarrow> P(x  d)" and knneg: "0 <= k" 

221 
shows "ALL x. P x \<longrightarrow> P(x  k*d)" 

222 
using knneg 

223 
proof (induct rule:int_ge_induct) 

224 
case base thus ?case by simp 

225 
next 

226 
case (step i) 

227 
{fix x 

228 
have "P x \<longrightarrow> P (x  i * d)" using step.hyps by blast 

229 
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

230 
by (simp add: algebra_simps) 
23465  231 
ultimately have "P x \<longrightarrow> P(x  (i + 1) * d)" by blast} 
232 
thus ?case .. 

233 
qed 

234 

235 
lemma minusinfinity: 

236 
assumes dpos: "0 < d" and 

237 
P1eqP1: "ALL x k. P1 x = P1(x  k*d)" and ePeqP1: "EX z::int. ALL x. x < z \<longrightarrow> (P x = P1 x)" 

238 
shows "(EX x. P1 x) \<longrightarrow> (EX x. P x)" 

239 
proof 

240 
assume eP1: "EX x. P1 x" 

241 
then obtain x where P1: "P1 x" .. 

242 
from ePeqP1 obtain z where P1eqP: "ALL x. x < z \<longrightarrow> (P x = P1 x)" .. 

243 
let ?w = "x  (abs(xz)+1) * d" 

244 
from dpos have w: "?w < z" by(rule decr_lemma) 

245 
have "P1 x = P1 ?w" using P1eqP1 by blast 

246 
also have "\<dots> = P(?w)" using w P1eqP by blast 

247 
finally have "P ?w" using P1 by blast 

248 
thus "EX x. P x" .. 

249 
qed 

250 

251 
lemma cpmi: 

252 
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x< z. P x = P' x" 

253 
and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> B. x \<noteq> b+j) > P (x) > P (x  D)" 

254 
and pd: "\<forall> x k. P' x = P' (xk*D)" 

255 
shows "(\<exists>x. P x) = ((\<exists> j\<in> {1..D} . P' j)  (\<exists> j \<in> {1..D}.\<exists> b\<in> B. P (b+j)))" 

256 
(is "?L = (?R1 \<or> ?R2)") 

257 
proof 

258 
{assume "?R2" hence "?L" by blast} 

259 
moreover 

260 
{assume H:"?R1" hence "?L" using minusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp} 

261 
moreover 

262 
{ fix x 

263 
assume P: "P x" and H: "\<not> ?R2" 

264 
{fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>B. P (b + j))" and P: "P y" 

265 
hence "~(EX (j::int) : {1..D}. EX (b::int) : B. y = b+j)" by auto 

266 
with nb P have "P (y  D)" by auto } 

267 
hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) > P (x) > P (x  D)" by blast 

268 
with H P have th: " \<forall>x. P x \<longrightarrow> P (x  D)" by auto 

269 
from p1 obtain z where z: "ALL x. x < z > (P x = P' x)" by blast 

270 
let ?y = "x  (\<bar>x  z\<bar> + 1)*D" 

271 
have zp: "0 <= (\<bar>x  z\<bar> + 1)" by arith 

272 
from dp have yz: "?y < z" using decr_lemma[OF dp] by simp 

273 
from z[rule_format, OF yz] decr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto 

274 
with periodic_finite_ex[OF dp pd] 

275 
have "?R1" by blast} 

276 
ultimately show ?thesis by blast 

277 
qed 

278 

279 
subsubsection {* The @{text "+\<infinity>"} Version*} 

280 

281 
lemma plusinfinity: 

282 
assumes dpos: "(0::int) < d" and 

283 
P1eqP1: "\<forall>x k. P' x = P'(x  k*d)" and ePeqP1: "\<exists> z. \<forall> x>z. P x = P' x" 

284 
shows "(\<exists> x. P' x) \<longrightarrow> (\<exists> x. P x)" 

285 
proof 

286 
assume eP1: "EX x. P' x" 

287 
then obtain x where P1: "P' x" .. 

288 
from ePeqP1 obtain z where P1eqP: "\<forall>x>z. P x = P' x" .. 

289 
let ?w' = "x + (abs(xz)+1) * d" 

290 
let ?w = "x  ((abs(xz) + 1))*d" 

29667  291 
have ww'[simp]: "?w = ?w'" by (simp add: algebra_simps) 
23465  292 
from dpos have w: "?w > z" by(simp only: ww' incr_lemma) 
293 
hence "P' x = P' ?w" using P1eqP1 by blast 

294 
also have "\<dots> = P(?w)" using w P1eqP by blast 

295 
finally have "P ?w" using P1 by blast 

296 
thus "EX x. P x" .. 

297 
qed 

298 

299 
lemma incr_mult_lemma: 

300 
assumes dpos: "(0::int) < d" and plus: "ALL x::int. P x \<longrightarrow> P(x + d)" and knneg: "0 <= k" 

301 
shows "ALL x. P x \<longrightarrow> P(x + k*d)" 

302 
using knneg 

303 
proof (induct rule:int_ge_induct) 

304 
case base thus ?case by simp 

305 
next 

306 
case (step i) 

307 
{fix x 

308 
have "P x \<longrightarrow> P (x + i * d)" using step.hyps by blast 

309 
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

310 
by (simp add:int_distrib ac_simps) 
23465  311 
ultimately have "P x \<longrightarrow> P(x + (i + 1) * d)" by blast} 
312 
thus ?case .. 

313 
qed 

314 

315 
lemma cppi: 

316 
assumes dp: "0 < D" and p1:"\<exists>z. \<forall> x> z. P x = P' x" 

317 
and nb:"\<forall>x.(\<forall> j\<in> {1..D}. \<forall>(b::int) \<in> A. x \<noteq> b  j) > P (x) > P (x + D)" 

318 
and pd: "\<forall> x k. P' x= P' (xk*D)" 

319 
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)") 

320 
proof 

321 
{assume "?R2" hence "?L" by blast} 

322 
moreover 

323 
{assume H:"?R1" hence "?L" using plusinfinity[OF dp pd p1] periodic_finite_ex[OF dp pd] by simp} 

324 
moreover 

325 
{ fix x 

326 
assume P: "P x" and H: "\<not> ?R2" 

327 
{fix y assume "\<not> (\<exists>j\<in>{1..D}. \<exists>b\<in>A. P (b  j))" and P: "P y" 

328 
hence "~(EX (j::int) : {1..D}. EX (b::int) : A. y = b  j)" by auto 

329 
with nb P have "P (y + D)" by auto } 

330 
hence "ALL x.~(EX (j::int) : {1..D}. EX (b::int) : A. P(bj)) > P (x) > P (x + D)" by blast 

331 
with H P have th: " \<forall>x. P x \<longrightarrow> P (x + D)" by auto 

332 
from p1 obtain z where z: "ALL x. x > z > (P x = P' x)" by blast 

333 
let ?y = "x + (\<bar>x  z\<bar> + 1)*D" 

334 
have zp: "0 <= (\<bar>x  z\<bar> + 1)" by arith 

335 
from dp have yz: "?y > z" using incr_lemma[OF dp] by simp 

336 
from z[rule_format, OF yz] incr_mult_lemma[OF dp th zp, rule_format, OF P] have th2: " P' ?y" by auto 

337 
with periodic_finite_ex[OF dp pd] 

338 
have "?R1" by blast} 

339 
ultimately show ?thesis by blast 

340 
qed 

341 

342 
lemma simp_from_to: "{i..j::int} = (if j < i then {} else insert i {i+1..j})" 

343 
apply(simp add:atLeastAtMost_def atLeast_def atMost_def) 

44890
22f665a2e91c
new fastforce replacing fastsimp  less confusing name
nipkow
parents:
44766
diff
changeset

344 
apply(fastforce) 
23465  345 
done 
346 

35050
9f841f20dca6
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
haftmann
parents:
33318
diff
changeset

347 
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

348 
apply (rule eq_reflection [symmetric]) 
23465  349 
apply (rule iffI) 
350 
defer 

351 
apply (erule exE) 

352 
apply (rule_tac x = "l * x" in exI) 

353 
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

354 
apply (rule_tac x = x in exI, simp) 
23465  355 
apply (erule exE) 
356 
apply (erule conjE) 

27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
27540
diff
changeset

357 
apply simp 
23465  358 
apply (erule dvdE) 
359 
apply (rule_tac x = k in exI) 

360 
apply simp 

361 
done 

362 

54227
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

363 
lemma zdvd_mono: 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

364 
fixes k m t :: int 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

365 
assumes "k \<noteq> 0" 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

366 
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

367 
using assms by simp 
23465  368 

54227
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

369 
lemma uminus_dvd_conv: 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

370 
fixes d t :: int 
63b441f49645
moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents:
49962
diff
changeset

371 
shows "d dvd t \<equiv>  d dvd t" and "d dvd t \<equiv> d dvd  t" 
23465  372 
by simp_all 
32553  373 

23465  374 
text {* \bigskip Theorems for transforming predicates on nat to predicates on @{text int}*} 
32553  375 

23465  376 
lemma zdiff_int_split: "P (int (x  y)) = 
377 
((y \<le> x \<longrightarrow> P (int x  int y)) \<and> (x < y \<longrightarrow> P 0))" 

36800  378 
by (cases "y \<le> x") (simp_all add: zdiff_int) 
23465  379 

380 
text {* 

381 
\medskip Specific instances of congruence rules, to prevent 

382 
simplifier from looping. *} 

383 

47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45425
diff
changeset

384 
theorem imp_le_cong: 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45425
diff
changeset

385 
"\<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

386 
by simp 
23465  387 

47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45425
diff
changeset

388 
theorem conj_le_cong: 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45425
diff
changeset

389 
"\<lbrakk>x = x'; 0 \<le> x' \<Longrightarrow> P = P'\<rbrakk> \<Longrightarrow> (0 \<le> (x::int) \<and> P) = (0 \<le> x' \<and> P')" 
23465  390 
by (simp cong: conj_cong) 
36799  391 

48891  392 
ML_file "Tools/Qelim/cooper.ML" 
36799  393 
setup Cooper.setup 
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_iff [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_le_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 zero_less_power_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_less_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 
declare power_le_zero_eq [presburger] 
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 
end 
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 
declare even_Suc [presburger] 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

473 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

474 
lemma [presburger]: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

475 
"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

476 
by 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 
declare even_diff_nat [presburger] 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

479 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

480 
lemma [presburger]: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

481 
fixes k :: int 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

482 
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

483 
by presburger 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

484 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

485 
lemma [presburger]: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

486 
fixes k :: int 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

487 
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

488 
by presburger 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

489 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

490 
lemma [presburger]: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

491 
"even n \<longleftrightarrow> even (int n)" 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

492 
using even_int_iff [of n] by simp 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

493 

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 
subsection {* Nice facts about division by @{term 4} *} 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

496 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

497 
lemma even_even_mod_4_iff: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

498 
"even (n::nat) \<longleftrightarrow> even (n mod 4)" 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

499 
by presburger 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

500 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

501 
lemma odd_mod_4_div_2: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

502 
"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

503 
by presburger 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

504 

6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

505 
lemma even_mod_4_div_2: 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

506 
"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

507 
by presburger 
6ba2f1fa243b
further downshift of theory Parity in the hierarchy
haftmann
parents:
57514
diff
changeset

508 

56850  509 

510 
subsection {* Try0 *} 

511 

512 
ML_file "Tools/try0.ML" 

513 

23465  514 
end 