Merged.
1 (* Author: Amine Chaieb, TU Muenchen *)
3 header {* Dense linear order without endpoints
4 and a quantifier elimination procedure in Ferrante and Rackoff style *}
6 theory Dense_Linear_Order
7 imports Plain Groebner_Basis
9 "~~/src/HOL/Tools/Qelim/langford_data.ML"
10 "~~/src/HOL/Tools/Qelim/ferrante_rackoff_data.ML"
11 ("~~/src/HOL/Tools/Qelim/langford.ML")
12 ("~~/src/HOL/Tools/Qelim/ferrante_rackoff.ML")
15 setup {* Langford_Data.setup #> Ferrante_Rackoff_Data.setup *}
20 lemma less_not_permute: "\<not> (x < y \<and> y < x)" by (simp add: not_less linear)
24 "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> x < u \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> (insert u U). x < y) \<and> P x)"
25 and "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> l < x \<and> P x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y < x) \<and> (\<forall>y \<in> U. x < y) \<and> P x)"
26 "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> x < u) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> (insert u U). x < y))"
27 and "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y) \<and> l < x) \<longleftrightarrow> (\<exists>x. (\<forall>y \<in> (insert l L). y < x) \<and> (\<forall>y \<in> U. x < y))" by auto
30 gather_start: "(\<exists>x. P x) \<equiv> (\<exists>x. (\<forall>y \<in> {}. y < x) \<and> (\<forall>y\<in> {}. x < y) \<and> P x)"
33 text{* Theorems for @{text "\<exists>z. \<forall>x. x < z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"}*}
34 lemma minf_lt: "\<exists>z . \<forall>x. x < z \<longrightarrow> (x < t \<longleftrightarrow> True)" by auto
35 lemma minf_gt: "\<exists>z . \<forall>x. x < z \<longrightarrow> (t < x \<longleftrightarrow> False)"
36 by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
38 lemma minf_le: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x \<le> t \<longleftrightarrow> True)" by (auto simp add: less_le)
39 lemma minf_ge: "\<exists>z. \<forall>x. x < z \<longrightarrow> (t \<le> x \<longleftrightarrow> False)"
40 by (auto simp add: less_le not_less not_le)
41 lemma minf_eq: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
42 lemma minf_neq: "\<exists>z. \<forall>x. x < z \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
43 lemma minf_P: "\<exists>z. \<forall>x. x < z \<longrightarrow> (P \<longleftrightarrow> P)" by blast
45 text{* Theorems for @{text "\<exists>z. \<forall>x. x < z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"}*}
46 lemma pinf_gt: "\<exists>z . \<forall>x. z < x \<longrightarrow> (t < x \<longleftrightarrow> True)" by auto
47 lemma pinf_lt: "\<exists>z . \<forall>x. z < x \<longrightarrow> (x < t \<longleftrightarrow> False)"
48 by (simp add: not_less) (rule exI[where x="t"], auto simp add: less_le)
50 lemma pinf_ge: "\<exists>z. \<forall>x. z < x \<longrightarrow> (t \<le> x \<longleftrightarrow> True)" by (auto simp add: less_le)
51 lemma pinf_le: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x \<le> t \<longleftrightarrow> False)"
52 by (auto simp add: less_le not_less not_le)
53 lemma pinf_eq: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x = t \<longleftrightarrow> False)" by auto
54 lemma pinf_neq: "\<exists>z. \<forall>x. z < x \<longrightarrow> (x \<noteq> t \<longleftrightarrow> True)" by auto
55 lemma pinf_P: "\<exists>z. \<forall>x. z < x \<longrightarrow> (P \<longleftrightarrow> P)" by blast
57 lemma nmi_lt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x < t \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
58 lemma nmi_gt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t < x \<longrightarrow> (\<exists> u\<in> U. u \<le> x)"
59 by (auto simp add: le_less)
60 lemma nmi_le: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x\<le> t \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
61 lemma nmi_ge: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> t\<le> x \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
62 lemma nmi_eq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> x = t \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
63 lemma nmi_neq: "t \<in> U \<Longrightarrow>\<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
64 lemma nmi_P: "\<forall> x. ~P \<and> P \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
65 lemma nmi_conj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow> (\<exists> u\<in> U. u \<le> x) ;
66 \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow> (\<exists> u\<in> U. u \<le> x)\<rbrakk> \<Longrightarrow>
67 \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
68 lemma nmi_disj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow> (\<exists> u\<in> U. u \<le> x) ;
69 \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow> (\<exists> u\<in> U. u \<le> x)\<rbrakk> \<Longrightarrow>
70 \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow> (\<exists> u\<in> U. u \<le> x)" by auto
72 lemma npi_lt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> x < t \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by (auto simp add: le_less)
73 lemma npi_gt: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t < x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
74 lemma npi_le: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> x \<le> t \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
75 lemma npi_ge: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> t \<le> x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
76 lemma npi_eq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> x = t \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
77 lemma npi_neq: "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> x \<noteq> t \<longrightarrow> (\<exists> u\<in> U. x \<le> u )" by auto
78 lemma npi_P: "\<forall> x. ~P \<and> P \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
79 lemma npi_conj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow> (\<exists> u\<in> U. x \<le> u) ; \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)\<rbrakk>
80 \<Longrightarrow> \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
81 lemma npi_disj: "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 x \<longrightarrow> (\<exists> u\<in> U. x \<le> u) ; \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)\<rbrakk>
82 \<Longrightarrow> \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow> (\<exists> u\<in> U. x \<le> u)" by auto
84 lemma lin_dense_lt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t < u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x < t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y < t)"
86 fix x l u y assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x"
87 and xu: "x<u" and px: "x < t" and ly: "l<y" and yu:"y < u"
88 from tU noU ly yu have tny: "t\<noteq>y" by auto
90 from less_trans[OF lx px] less_trans[OF H yu]
91 have "l < t \<and> t < u" by simp
92 with tU noU have "False" by auto}
93 hence "\<not> t < y" by auto hence "y \<le> t" by (simp add: not_less)
94 thus "y < t" using tny by (simp add: less_le)
97 lemma lin_dense_gt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l < x \<and> x < u \<and> t < x \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> t < y)"
100 assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
101 and px: "t < x" and ly: "l<y" and yu:"y < u"
102 from tU noU ly yu have tny: "t\<noteq>y" by auto
104 from less_trans[OF ly H] less_trans[OF px xu] have "l < t \<and> t < u" by simp
105 with tU noU have "False" by auto}
106 hence "\<not> y<t" by auto hence "t \<le> y" by (auto simp add: not_less)
107 thus "t < y" using tny by (simp add:less_le)
110 lemma lin_dense_le: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x \<le> t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<le> t)"
113 assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
114 and px: "x \<le> t" and ly: "l<y" and yu:"y < u"
115 from tU noU ly yu have tny: "t\<noteq>y" by auto
117 from less_le_trans[OF lx px] less_trans[OF H yu]
118 have "l < t \<and> t < u" by simp
119 with tU noU have "False" by auto}
120 hence "\<not> t < y" by auto thus "y \<le> t" by (simp add: not_less)
123 lemma lin_dense_ge: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> t \<le> x \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> t \<le> y)"
126 assume tU: "t \<in> U" and noU: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
127 and px: "t \<le> x" and ly: "l<y" and yu:"y < u"
128 from tU noU ly yu have tny: "t\<noteq>y" by auto
130 from less_trans[OF ly H] le_less_trans[OF px xu]
131 have "l < t \<and> t < u" by simp
132 with tU noU have "False" by auto}
133 hence "\<not> y<t" by auto thus "t \<le> y" by (simp add: not_less)
135 lemma lin_dense_eq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x = t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y= t)" by auto
136 lemma lin_dense_neq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> x \<noteq> t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<noteq> t)" by auto
137 lemma lin_dense_P: "\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P)" by auto
139 lemma lin_dense_conj:
140 "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 x
141 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;
142 \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 x
143 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
144 \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<and> P2 x)
145 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<and> P2 y))"
147 lemma lin_dense_disj:
148 "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 x
149 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;
150 \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 x
151 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow>
152 \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<or> P2 x)
153 \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<or> P2 y))"
156 lemma npmibnd: "\<lbrakk>\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<le> x); \<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<le> u)\<rbrakk>
157 \<Longrightarrow> \<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u')"
160 lemma finite_set_intervals:
161 assumes px: "P x" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S"
162 and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
163 shows "\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a \<le> x \<and> x \<le> b \<and> P x"
165 let ?Mx = "{y. y\<in> S \<and> y \<le> x}"
166 let ?xM = "{y. y\<in> S \<and> x \<le> y}"
169 have MxS: "?Mx \<subseteq> S" by blast
170 hence fMx: "finite ?Mx" using fS finite_subset by auto
171 from lx linS have linMx: "l \<in> ?Mx" by blast
172 hence Mxne: "?Mx \<noteq> {}" by blast
173 have xMS: "?xM \<subseteq> S" by blast
174 hence fxM: "finite ?xM" using fS finite_subset by auto
175 from xu uinS have linxM: "u \<in> ?xM" by blast
176 hence xMne: "?xM \<noteq> {}" by blast
177 have ax:"?a \<le> x" using Mxne fMx by auto
178 have xb:"x \<le> ?b" using xMne fxM by auto
179 have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast
180 have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast
181 have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S"
183 fix y assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S"
184 from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by (auto simp add: linear)
185 moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto with ay have "False" by (simp add: not_le[symmetric])}
186 moreover {assume "y \<in> ?xM" hence "?b \<le> y" using xMne fxM by auto with yb have "False" by (simp add: not_le[symmetric])}
187 ultimately show "False" by blast
189 from ainS binS noy ax xb px show ?thesis by blast
192 lemma finite_set_intervals2:
193 assumes px: "P x" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S"
194 and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
195 shows "(\<exists> s\<in> S. P s) \<or> (\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a < x \<and> x < b \<and> P x)"
197 from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su]
199 as: "a\<in> S" and bs: "b\<in> S" and noS:"\<forall>y. a < y \<and> y < b \<longrightarrow> y \<notin> S"
200 and axb: "a \<le> x \<and> x \<le> b \<and> P x" by auto
201 from axb have "x= a \<or> x= b \<or> (a < x \<and> x < b)" by (auto simp add: le_less)
202 thus ?thesis using px as bs noS by blast
207 section {* The classical QE after Langford for dense linear orders *}
209 context dense_linear_order
212 lemma interval_empty_iff:
213 "{y. x < y \<and> y < z} = {} \<longleftrightarrow> \<not> x < z"
214 by (auto dest: dense)
217 assumes ne: "L \<noteq> {}" and neU: "U \<noteq> {}" and fL: "finite L" and fU: "finite U"
218 shows "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> U. x < y)) \<equiv> (\<forall> l \<in> L. \<forall>u \<in> U. l < u)"
219 proof (simp only: atomize_eq, rule iffI)
220 assume H: "\<exists>x. (\<forall>y\<in>L. y < x) \<and> (\<forall>y\<in>U. x < y)"
221 then obtain x where xL: "\<forall>y\<in>L. y < x" and xU: "\<forall>y\<in>U. x < y" by blast
222 {fix l u assume l: "l \<in> L" and u: "u \<in> U"
223 have "l < x" using xL l by blast
224 also have "x < u" using xU u by blast
225 finally (less_trans) have "l < u" .}
226 thus "\<forall>l\<in>L. \<forall>u\<in>U. l < u" by blast
228 assume H: "\<forall>l\<in>L. \<forall>u\<in>U. l < u"
231 from fL ne have th1: "?ML \<in> L" and th1': "\<forall>l\<in>L. l \<le> ?ML" by auto
232 from fU neU have th2: "?MU \<in> U" and th2': "\<forall>u\<in>U. ?MU \<le> u" by auto
233 from th1 th2 H have "?ML < ?MU" by auto
234 with dense obtain w where th3: "?ML < w" and th4: "w < ?MU" by blast
235 from th3 th1' have "\<forall>l \<in> L. l < w" by auto
236 moreover from th4 th2' have "\<forall>u \<in> U. w < u" by auto
237 ultimately show "\<exists>x. (\<forall>y\<in>L. y < x) \<and> (\<forall>y\<in>U. x < y)" by auto
241 assumes ne: "L \<noteq> {}" and fL: "finite L"
242 shows "(\<exists>x. (\<forall>y \<in> L. y < x) \<and> (\<forall>y \<in> {}. x < y)) \<equiv> True"
243 proof(simp add: atomize_eq)
244 from gt_ex[of "Max L"] obtain M where M: "Max L < M" by blast
245 from ne fL have "\<forall>x \<in> L. x \<le> Max L" by simp
246 with M have "\<forall>x\<in>L. x < M" by (auto intro: le_less_trans)
247 thus "\<exists>x. \<forall>y\<in>L. y < x" by blast
251 assumes ne: "U \<noteq> {}" and fU: "finite U"
252 shows "(\<exists>x. (\<forall>y \<in> {}. y < x) \<and> (\<forall>y \<in> U. x < y)) \<equiv> True"
253 proof(simp add: atomize_eq)
254 from lt_ex[of "Min U"] obtain M where M: "M < Min U" by blast
255 from ne fU have "\<forall>x \<in> U. Min U \<le> x" by simp
256 with M have "\<forall>x\<in>U. M < x" by (auto intro: less_le_trans)
257 thus "\<exists>x. \<forall>y\<in>U. x < y" by blast
260 lemma exists_neq: "\<exists>(x::'a). x \<noteq> t" "\<exists>(x::'a). t \<noteq> x"
261 using gt_ex[of t] by auto
263 lemmas dlo_simps = order_refl less_irrefl not_less not_le exists_neq
264 le_less neq_iff linear less_not_permute
266 lemma axiom: "dense_linear_order (op \<le>) (op <)" by (rule dense_linear_order_axioms)
268 shows "TERM (less :: 'a \<Rightarrow> _)"
269 and "TERM (less_eq :: 'a \<Rightarrow> _)"
270 and "TERM (op = :: 'a \<Rightarrow> _)" .
272 declare axiom[langford qe: dlo_qe_bnds dlo_qe_nolb dlo_qe_noub gather: gather_start gather_simps atoms: atoms]
273 declare dlo_simps[langfordsimp]
277 (* FIXME: Move to HOL -- together with the conj_aci_rule in langford.ML *)
279 "(P & (Q | R)) = ((P&Q) | (P&R))"
280 "((Q | R) & P) = ((Q&P) | (R&P))"
283 lemmas weak_dnf_simps = simp_thms dnf
286 "(\<not>(P \<and> Q)) = (\<not>P \<or> \<not>Q)" "(\<not>(P \<or> Q)) = (\<not>P \<and> \<not>Q)" "(P \<longrightarrow> Q) = (\<not>P \<or> Q)"
287 "(P = Q) = ((P \<and> Q) \<or> (\<not>P \<and> \<not> Q))" "(\<not> \<not>(P)) = P"
290 lemma ex_distrib: "(\<exists>x. P x \<or> Q x) \<longleftrightarrow> ((\<exists>x. P x) \<or> (\<exists>x. Q x))" by blast
292 lemmas dnf_simps = weak_dnf_simps nnf_simps ex_distrib
294 use "~~/src/HOL/Tools/Qelim/langford.ML"
295 method_setup dlo = {*
296 Method.ctxt_args (Method.SIMPLE_METHOD' o LangfordQE.dlo_tac)
297 *} "Langford's algorithm for quantifier elimination in dense linear orders"
300 section {* Contructive dense linear orders yield QE for linear arithmetic over ordered Fields -- see @{text "Arith_Tools.thy"} *}
302 text {* Linear order without upper bounds *}
304 class_locale linorder_stupid_syntax = linorder
307 less_eq ("op \<sqsubseteq>") and
308 less_eq ("(_/ \<sqsubseteq> _)" [51, 51] 50) and
309 less ("op \<sqsubset>") and
310 less ("(_/ \<sqsubset> _)" [51, 51] 50)
314 class_locale linorder_no_ub = linorder_stupid_syntax +
315 assumes gt_ex: "\<exists>y. less x y"
317 lemma ge_ex: "\<exists>y. x \<sqsubseteq> y" using gt_ex by auto
319 text {* Theorems for @{text "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>+\<infinity>\<^esub>)"} *}
321 assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
322 and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
323 shows "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
325 from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
326 and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
327 from gt_ex obtain z where z:"ord.max less_eq z1 z2 \<sqsubset> z" by blast
328 from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
329 {fix x assume H: "z \<sqsubset> x"
330 from less_trans[OF zz1 H] less_trans[OF zz2 H]
331 have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')" using z1 zz1 z2 zz2 by auto
333 thus ?thesis by blast
337 assumes ex1: "\<exists>z1. \<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
338 and ex2: "\<exists>z2. \<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
339 shows "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
341 from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. z1 \<sqsubset> x \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
342 and z2: "\<forall>x. z2 \<sqsubset> x \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
343 from gt_ex obtain z where z:"ord.max less_eq z1 z2 \<sqsubset> z" by blast
344 from z have zz1: "z1 \<sqsubset> z" and zz2: "z2 \<sqsubset> z" by simp_all
345 {fix x assume H: "z \<sqsubset> x"
346 from less_trans[OF zz1 H] less_trans[OF zz2 H]
347 have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')" using z1 zz1 z2 zz2 by auto
349 thus ?thesis by blast
352 lemma pinf_ex: assumes ex:"\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
354 from ex obtain z where z: "\<forall>x. z \<sqsubset> x \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
355 from gt_ex obtain x where x: "z \<sqsubset> x" by blast
356 from z x p1 show ?thesis by blast
361 text {* Linear order without upper bounds *}
363 class_locale linorder_no_lb = linorder_stupid_syntax +
364 assumes lt_ex: "\<exists>y. less y x"
366 lemma le_ex: "\<exists>y. y \<sqsubseteq> x" using lt_ex by auto
369 text {* Theorems for @{text "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P\<^bsub>-\<infinity>\<^esub>)"} *}
371 assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
372 and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
373 shows "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> ((P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2'))"
375 from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"and z2: "\<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
376 from lt_ex obtain z where z:"z \<sqsubset> ord.min less_eq z1 z2" by blast
377 from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
378 {fix x assume H: "x \<sqsubset> z"
379 from less_trans[OF H zz1] less_trans[OF H zz2]
380 have "(P1 x \<and> P2 x) \<longleftrightarrow> (P1' \<and> P2')" using z1 zz1 z2 zz2 by auto
382 thus ?thesis by blast
386 assumes ex1: "\<exists>z1. \<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"
387 and ex2: "\<exists>z2. \<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')"
388 shows "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> ((P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2'))"
390 from ex1 ex2 obtain z1 and z2 where z1: "\<forall>x. x \<sqsubset> z1 \<longrightarrow> (P1 x \<longleftrightarrow> P1')"and z2: "\<forall>x. x \<sqsubset> z2 \<longrightarrow> (P2 x \<longleftrightarrow> P2')" by blast
391 from lt_ex obtain z where z:"z \<sqsubset> ord.min less_eq z1 z2" by blast
392 from z have zz1: "z \<sqsubset> z1" and zz2: "z \<sqsubset> z2" by simp_all
393 {fix x assume H: "x \<sqsubset> z"
394 from less_trans[OF H zz1] less_trans[OF H zz2]
395 have "(P1 x \<or> P2 x) \<longleftrightarrow> (P1' \<or> P2')" using z1 zz1 z2 zz2 by auto
397 thus ?thesis by blast
400 lemma minf_ex: assumes ex:"\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" and p1: P1 shows "\<exists> x. P x"
402 from ex obtain z where z: "\<forall>x. x \<sqsubset> z \<longrightarrow> (P x \<longleftrightarrow> P1)" by blast
403 from lt_ex obtain x where x: "x \<sqsubset> z" by blast
404 from z x p1 show ?thesis by blast
410 class_locale constr_dense_linear_order = linorder_no_lb + linorder_no_ub +
412 assumes between_less: "less x y \<Longrightarrow> less x (between x y) \<and> less (between x y) y"
413 and between_same: "between x x = x"
415 class_interpretation constr_dense_linear_order < dense_linear_order
417 using gt_ex lt_ex between_less
418 by (auto, rule_tac x="between x y" in exI, simp)
420 context constr_dense_linear_order
424 assumes fU: "finite U"
425 and lin_dense: "\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P x
426 \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
427 and nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u')"
428 and nmi: "\<not> MP" and npi: "\<not> PP" and ex: "\<exists> x. P x"
429 shows "\<exists> u\<in> U. \<exists> u' \<in> U. P (between u u')"
431 from ex obtain x where px: "P x" by blast
432 from px nmi npi nmpiU have "\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u'" by auto
433 then obtain u and u' where uU:"u\<in> U" and uU': "u' \<in> U" and ux:"u \<sqsubseteq> x" and xu':"x \<sqsubseteq> u'" by auto
434 from uU have Une: "U \<noteq> {}" by auto
435 term "linorder.Min less_eq"
436 let ?l = "linorder.Min less_eq U"
437 let ?u = "linorder.Max less_eq U"
438 have linM: "?l \<in> U" using fU Une by simp
439 have uinM: "?u \<in> U" using fU Une by simp
440 have lM: "\<forall> t\<in> U. ?l \<sqsubseteq> t" using Une fU by auto
441 have Mu: "\<forall> t\<in> U. t \<sqsubseteq> ?u" using Une fU by auto
442 have th:"?l \<sqsubseteq> u" using uU Une lM by auto
443 from order_trans[OF th ux] have lx: "?l \<sqsubseteq> x" .
444 have th: "u' \<sqsubseteq> ?u" using uU' Une Mu by simp
445 from order_trans[OF xu' th] have xu: "x \<sqsubseteq> ?u" .
446 from finite_set_intervals2[where P="P",OF px lx xu linM uinM fU lM Mu]
447 have "(\<exists> s\<in> U. P s) \<or>
448 (\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U) \<and> t1 \<sqsubset> x \<and> x \<sqsubset> t2 \<and> P x)" .
449 moreover { fix u assume um: "u\<in>U" and pu: "P u"
450 have "between u u = u" by (simp add: between_same)
451 with um pu have "P (between u u)" by simp
452 with um have ?thesis by blast}
454 assume "\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U) \<and> t1 \<sqsubset> x \<and> x \<sqsubset> t2 \<and> P x"
455 then obtain t1 and t2 where t1M: "t1 \<in> U" and t2M: "t2\<in> U"
456 and noM: "\<forall> y. t1 \<sqsubset> y \<and> y \<sqsubset> t2 \<longrightarrow> y \<notin> U" and t1x: "t1 \<sqsubset> x" and xt2: "x \<sqsubset> t2" and px: "P x"
458 from less_trans[OF t1x xt2] have t1t2: "t1 \<sqsubset> t2" .
459 let ?u = "between t1 t2"
460 from between_less t1t2 have t1lu: "t1 \<sqsubset> ?u" and ut2: "?u \<sqsubset> t2" by auto
461 from lin_dense noM t1x xt2 px t1lu ut2 have "P ?u" by blast
462 with t1M t2M have ?thesis by blast}
463 ultimately show ?thesis by blast
467 assumes fU: "finite U"
468 and lin_dense: "\<forall>x l u. (\<forall> t. l \<sqsubset> t \<and> t\<sqsubset> u \<longrightarrow> t \<notin> U) \<and> l\<sqsubset> x \<and> x \<sqsubset> u \<and> P x
469 \<longrightarrow> (\<forall> y. l \<sqsubset> y \<and> y \<sqsubset> u \<longrightarrow> P y )"
470 and nmibnd: "\<forall>x. \<not> MP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<sqsubseteq> x)"
471 and npibnd: "\<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. x \<sqsubseteq> u)"
472 and mi: "\<exists>z. \<forall>x. x \<sqsubset> z \<longrightarrow> (P x = MP)" and pi: "\<exists>z. \<forall>x. z \<sqsubset> x \<longrightarrow> (P x = PP)"
473 shows "(\<exists> x. P x) \<equiv> (MP \<or> PP \<or> (\<exists> u \<in> U. \<exists> u'\<in> U. P (between u u')))"
474 (is "_ \<equiv> (_ \<or> _ \<or> ?F)" is "?E \<equiv> ?D")
477 assume px: "\<exists> x. P x"
478 have "MP \<or> PP \<or> (\<not> MP \<and> \<not> PP)" by blast
479 moreover {assume "MP \<or> PP" hence "?D" by blast}
480 moreover {assume nmi: "\<not> MP" and npi: "\<not> PP"
481 from npmibnd[OF nmibnd npibnd]
482 have nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<sqsubseteq> x \<and> x \<sqsubseteq> u')" .
483 from rinf_U[OF fU lin_dense nmpiU nmi npi px] have "?D" by blast}
484 ultimately have "?D" by blast}
487 moreover {assume m:"MP" from minf_ex[OF mi m] have "?E" .}
488 moreover {assume p: "PP" from pinf_ex[OF pi p] have "?E" . }
489 moreover {assume f:"?F" hence "?E" by blast}
490 ultimately have "?E" by blast}
491 ultimately have "?E = ?D" by blast thus "?E \<equiv> ?D" by simp
494 lemmas minf_thms = minf_conj minf_disj minf_eq minf_neq minf_lt minf_le minf_gt minf_ge minf_P
495 lemmas pinf_thms = pinf_conj pinf_disj pinf_eq pinf_neq pinf_lt pinf_le pinf_gt pinf_ge pinf_P
497 lemmas nmi_thms = nmi_conj nmi_disj nmi_eq nmi_neq nmi_lt nmi_le nmi_gt nmi_ge nmi_P
498 lemmas npi_thms = npi_conj npi_disj npi_eq npi_neq npi_lt npi_le npi_gt npi_ge npi_P
499 lemmas lin_dense_thms = lin_dense_conj lin_dense_disj lin_dense_eq lin_dense_neq lin_dense_lt lin_dense_le lin_dense_gt lin_dense_ge lin_dense_P
501 lemma ferrack_axiom: "constr_dense_linear_order less_eq less between"
502 by (rule constr_dense_linear_order_axioms)
504 shows "TERM (less :: 'a \<Rightarrow> _)"
505 and "TERM (less_eq :: 'a \<Rightarrow> _)"
506 and "TERM (op = :: 'a \<Rightarrow> _)" .
508 declare ferrack_axiom [ferrack minf: minf_thms pinf: pinf_thms
509 nmi: nmi_thms npi: npi_thms lindense:
510 lin_dense_thms qe: fr_eq atoms: atoms]
514 fun simps phi = map (Morphism.thm phi) [@{thm "not_less"}, @{thm "not_le"}]
515 fun generic_whatis phi =
517 val [lt, le] = map (Morphism.term phi) [@{term "op \<sqsubset>"}, @{term "op \<sqsubseteq>"}]
520 Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
521 else Ferrante_Rackoff_Data.Nox
522 | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
523 else Ferrante_Rackoff_Data.Nox
524 | b$y$z => if Term.could_unify (b, lt) then
525 if term_of x aconv y then Ferrante_Rackoff_Data.Lt
526 else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
527 else Ferrante_Rackoff_Data.Nox
528 else if Term.could_unify (b, le) then
529 if term_of x aconv y then Ferrante_Rackoff_Data.Le
530 else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
531 else Ferrante_Rackoff_Data.Nox
532 else Ferrante_Rackoff_Data.Nox
533 | _ => Ferrante_Rackoff_Data.Nox
535 fun ss phi = HOL_ss addsimps (simps phi)
537 Ferrante_Rackoff_Data.funs @{thm "ferrack_axiom"}
538 {isolate_conv = K (K (K Thm.reflexive)), whatis = generic_whatis, simpset = ss}
544 use "~~/src/HOL/Tools/Qelim/ferrante_rackoff.ML"
546 method_setup ferrack = {*
547 Method.ctxt_args (Method.SIMPLE_METHOD' o FerranteRackoff.dlo_tac)
548 *} "Ferrante and Rackoff's algorithm for quantifier elimination in dense linear orders"
550 subsection {* Ferrante and Rackoff algorithm over ordered fields *}
552 lemma neg_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x < 0) == (x > 0))"
555 have "c*x < 0 = (0/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_simps)
556 also have "\<dots> = (0 < x)" by simp
557 finally show "(c*x < 0) == (x > 0)" by simp
560 lemma pos_prod_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x < 0) == (x < 0))"
563 hence "c*x < 0 = (0/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_simps)
564 also have "\<dots> = (0 > x)" by simp
565 finally show "(c*x < 0) == (x < 0)" by simp
568 lemma neg_prod_sum_lt: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t< 0) == (x > (- 1/c)*t))"
571 have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
572 also have "\<dots> = (-t/c < x)" by (simp only: neg_divide_less_eq[OF H] ring_simps)
573 also have "\<dots> = ((- 1/c)*t < x)" by simp
574 finally show "(c*x + t < 0) == (x > (- 1/c)*t)" by simp
577 lemma pos_prod_sum_lt:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t < 0) == (x < (- 1/c)*t))"
580 have "c*x + t< 0 = (c*x < -t)" by (subst less_iff_diff_less_0 [of "c*x" "-t"], simp)
581 also have "\<dots> = (-t/c > x)" by (simp only: pos_less_divide_eq[OF H] ring_simps)
582 also have "\<dots> = ((- 1/c)*t > x)" by simp
583 finally show "(c*x + t < 0) == (x < (- 1/c)*t)" by simp
586 lemma sum_lt:"((x::'a::pordered_ab_group_add) + t < 0) == (x < - t)"
587 using less_diff_eq[where a= x and b=t and c=0] by simp
589 lemma neg_prod_le:"(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x <= 0) == (x >= 0))"
592 have "c*x <= 0 = (0/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_simps)
593 also have "\<dots> = (0 <= x)" by simp
594 finally show "(c*x <= 0) == (x >= 0)" by simp
597 lemma pos_prod_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x <= 0) == (x <= 0))"
600 hence "c*x <= 0 = (0/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_simps)
601 also have "\<dots> = (0 >= x)" by simp
602 finally show "(c*x <= 0) == (x <= 0)" by simp
605 lemma neg_prod_sum_le: "(c\<Colon>'a\<Colon>ordered_field) < 0 \<Longrightarrow> ((c*x + t <= 0) == (x >= (- 1/c)*t))"
608 have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
609 also have "\<dots> = (-t/c <= x)" by (simp only: neg_divide_le_eq[OF H] ring_simps)
610 also have "\<dots> = ((- 1/c)*t <= x)" by simp
611 finally show "(c*x + t <= 0) == (x >= (- 1/c)*t)" by simp
614 lemma pos_prod_sum_le:"(c\<Colon>'a\<Colon>ordered_field) > 0 \<Longrightarrow> ((c*x + t <= 0) == (x <= (- 1/c)*t))"
617 have "c*x + t <= 0 = (c*x <= -t)" by (subst le_iff_diff_le_0 [of "c*x" "-t"], simp)
618 also have "\<dots> = (-t/c >= x)" by (simp only: pos_le_divide_eq[OF H] ring_simps)
619 also have "\<dots> = ((- 1/c)*t >= x)" by simp
620 finally show "(c*x + t <= 0) == (x <= (- 1/c)*t)" by simp
623 lemma sum_le:"((x::'a::pordered_ab_group_add) + t <= 0) == (x <= - t)"
624 using le_diff_eq[where a= x and b=t and c=0] by simp
626 lemma nz_prod_eq:"(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x = 0) == (x = 0))" by simp
627 lemma nz_prod_sum_eq: "(c\<Colon>'a\<Colon>ordered_field) \<noteq> 0 \<Longrightarrow> ((c*x + t = 0) == (x = (- 1/c)*t))"
629 assume H: "c \<noteq> 0"
630 have "c*x + t = 0 = (c*x = -t)" by (subst eq_iff_diff_eq_0 [of "c*x" "-t"], simp)
631 also have "\<dots> = (x = -t/c)" by (simp only: nonzero_eq_divide_eq[OF H] ring_simps)
632 finally show "(c*x + t = 0) == (x = (- 1/c)*t)" by simp
634 lemma sum_eq:"((x::'a::pordered_ab_group_add) + t = 0) == (x = - t)"
635 using eq_diff_eq[where a= x and b=t and c=0] by simp
638 class_interpretation class_ordered_field_dense_linear_order: constr_dense_linear_order
640 "\<lambda> x y. 1/2 * ((x::'a::{ordered_field,recpower,number_ring}) + y)"]
641 proof (unfold_locales, dlo, dlo, auto)
642 fix x y::'a assume lt: "x < y"
643 from less_half_sum[OF lt] show "x < (x + y) /2" by simp
645 fix x y::'a assume lt: "x < y"
646 from gt_half_sum[OF lt] show "(x + y) /2 < y" by simp
651 fun earlier [] x y = false
652 | earlier (h::t) x y =
653 if h aconvc y then false else if h aconvc x then true else earlier t x y;
655 fun dest_frac ct = case term_of ct of
656 Const (@{const_name "HOL.divide"},_) $ a $ b=>
657 Rat.rat_of_quotient (snd (HOLogic.dest_number a), snd (HOLogic.dest_number b))
658 | t => Rat.rat_of_int (snd (HOLogic.dest_number t))
660 fun mk_frac phi cT x =
661 let val (a, b) = Rat.quotient_of_rat x
662 in if b = 1 then Numeral.mk_cnumber cT a
664 (Thm.capply (Drule.cterm_rule (instantiate' [SOME cT] []) @{cpat "op /"})
665 (Numeral.mk_cnumber cT a))
666 (Numeral.mk_cnumber cT b)
669 fun whatis x ct = case term_of ct of
670 Const(@{const_name "HOL.plus"}, _)$(Const(@{const_name "HOL.times"},_)$_$y)$_ =>
671 if y aconv term_of x then ("c*x+t",[(funpow 2 Thm.dest_arg1) ct, Thm.dest_arg ct])
673 | Const(@{const_name "HOL.plus"}, _)$y$_ =>
674 if y aconv term_of x then ("x+t",[Thm.dest_arg ct])
676 | Const(@{const_name "HOL.times"}, _)$_$y =>
677 if y aconv term_of x then ("c*x",[Thm.dest_arg1 ct])
679 | t => if t aconv term_of x then ("x",[]) else ("Nox",[]);
681 fun xnormalize_conv ctxt [] ct = reflexive ct
682 | xnormalize_conv ctxt (vs as (x::_)) ct =
684 Const(@{const_name HOL.less},_)$_$Const(@{const_name "HOL.zero"},_) =>
685 (case whatis x (Thm.dest_arg1 ct) of
689 val clt = Thm.dest_fun2 ct
690 val cz = Thm.dest_arg ct
691 val neg = cr </ Rat.zero
692 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
693 (Thm.capply @{cterm "Trueprop"}
694 (if neg then Thm.capply (Thm.capply clt c) cz
695 else Thm.capply (Thm.capply clt cz) c))
696 val cth = equal_elim (symmetric cthp) TrueI
697 val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x,t])
698 (if neg then @{thm neg_prod_sum_lt} else @{thm pos_prod_sum_lt})) cth
699 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
700 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
704 val T = ctyp_of_term x
705 val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_lt"}
706 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
707 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
712 val clt = Thm.dest_fun2 ct
713 val cz = Thm.dest_arg ct
714 val neg = cr </ Rat.zero
715 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
716 (Thm.capply @{cterm "Trueprop"}
717 (if neg then Thm.capply (Thm.capply clt c) cz
718 else Thm.capply (Thm.capply clt cz) c))
719 val cth = equal_elim (symmetric cthp) TrueI
720 val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
721 (if neg then @{thm neg_prod_lt} else @{thm pos_prod_lt})) cth
727 | Const(@{const_name HOL.less_eq},_)$_$Const(@{const_name "HOL.zero"},_) =>
728 (case whatis x (Thm.dest_arg1 ct) of
731 val T = ctyp_of_term x
733 val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
734 val cz = Thm.dest_arg ct
735 val neg = cr </ Rat.zero
736 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
737 (Thm.capply @{cterm "Trueprop"}
738 (if neg then Thm.capply (Thm.capply clt c) cz
739 else Thm.capply (Thm.capply clt cz) c))
740 val cth = equal_elim (symmetric cthp) TrueI
741 val th = implies_elim (instantiate' [SOME T] (map SOME [c,x,t])
742 (if neg then @{thm neg_prod_sum_le} else @{thm pos_prod_sum_le})) cth
743 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
744 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
748 val T = ctyp_of_term x
749 val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_le"}
750 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
751 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
755 val T = ctyp_of_term x
757 val clt = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat "op <"}
758 val cz = Thm.dest_arg ct
759 val neg = cr </ Rat.zero
760 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
761 (Thm.capply @{cterm "Trueprop"}
762 (if neg then Thm.capply (Thm.capply clt c) cz
763 else Thm.capply (Thm.capply clt cz) c))
764 val cth = equal_elim (symmetric cthp) TrueI
765 val th = implies_elim (instantiate' [SOME (ctyp_of_term x)] (map SOME [c,x])
766 (if neg then @{thm neg_prod_le} else @{thm pos_prod_le})) cth
771 | Const("op =",_)$_$Const(@{const_name "HOL.zero"},_) =>
772 (case whatis x (Thm.dest_arg1 ct) of
775 val T = ctyp_of_term x
777 val ceq = Thm.dest_fun2 ct
778 val cz = Thm.dest_arg ct
779 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
780 (Thm.capply @{cterm "Trueprop"}
781 (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
782 val cth = equal_elim (symmetric cthp) TrueI
783 val th = implies_elim
784 (instantiate' [SOME T] (map SOME [c,x,t]) @{thm nz_prod_sum_eq}) cth
785 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
786 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
790 val T = ctyp_of_term x
791 val th = instantiate' [SOME T] [SOME x, SOME t] @{thm "sum_eq"}
792 val rth = Conv.fconv_rule (Conv.arg_conv (Conv.binop_conv
793 (Normalizer.semiring_normalize_ord_conv ctxt (earlier vs)))) th
797 val T = ctyp_of_term x
799 val ceq = Thm.dest_fun2 ct
800 val cz = Thm.dest_arg ct
801 val cthp = Simplifier.rewrite (local_simpset_of ctxt)
802 (Thm.capply @{cterm "Trueprop"}
803 (Thm.capply @{cterm "Not"} (Thm.capply (Thm.capply ceq c) cz)))
804 val cth = equal_elim (symmetric cthp) TrueI
805 val rth = implies_elim
806 (instantiate' [SOME T] (map SOME [c,x]) @{thm nz_prod_eq}) cth
808 | _ => reflexive ct);
811 val less_iff_diff_less_0 = mk_meta_eq @{thm "less_iff_diff_less_0"}
812 val le_iff_diff_le_0 = mk_meta_eq @{thm "le_iff_diff_le_0"}
813 val eq_iff_diff_eq_0 = mk_meta_eq @{thm "eq_iff_diff_eq_0"}
815 fun field_isolate_conv phi ctxt vs ct = case term_of ct of
816 Const(@{const_name HOL.less},_)$a$b =>
817 let val (ca,cb) = Thm.dest_binop ct
818 val T = ctyp_of_term ca
819 val th = instantiate' [SOME T] [SOME ca, SOME cb] less_iff_diff_less_0
820 val nth = Conv.fconv_rule
821 (Conv.arg_conv (Conv.arg1_conv
822 (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
823 val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
825 | Const(@{const_name HOL.less_eq},_)$a$b =>
826 let val (ca,cb) = Thm.dest_binop ct
827 val T = ctyp_of_term ca
828 val th = instantiate' [SOME T] [SOME ca, SOME cb] le_iff_diff_le_0
829 val nth = Conv.fconv_rule
830 (Conv.arg_conv (Conv.arg1_conv
831 (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
832 val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
835 | Const("op =",_)$a$b =>
836 let val (ca,cb) = Thm.dest_binop ct
837 val T = ctyp_of_term ca
838 val th = instantiate' [SOME T] [SOME ca, SOME cb] eq_iff_diff_eq_0
839 val nth = Conv.fconv_rule
840 (Conv.arg_conv (Conv.arg1_conv
841 (Normalizer.semiring_normalize_ord_conv @{context} (earlier vs)))) th
842 val rth = transitive nth (xnormalize_conv ctxt vs (Thm.rhs_of nth))
844 | @{term "Not"} $(Const("op =",_)$a$b) => Conv.arg_conv (field_isolate_conv phi ctxt vs) ct
848 fun classfield_whatis phi =
852 Const("op =", _)$y$z => if term_of x aconv y then Ferrante_Rackoff_Data.Eq
853 else Ferrante_Rackoff_Data.Nox
854 | @{term "Not"}$(Const("op =", _)$y$z) => if term_of x aconv y then Ferrante_Rackoff_Data.NEq
855 else Ferrante_Rackoff_Data.Nox
856 | Const(@{const_name HOL.less},_)$y$z =>
857 if term_of x aconv y then Ferrante_Rackoff_Data.Lt
858 else if term_of x aconv z then Ferrante_Rackoff_Data.Gt
859 else Ferrante_Rackoff_Data.Nox
860 | Const (@{const_name HOL.less_eq},_)$y$z =>
861 if term_of x aconv y then Ferrante_Rackoff_Data.Le
862 else if term_of x aconv z then Ferrante_Rackoff_Data.Ge
863 else Ferrante_Rackoff_Data.Nox
864 | _ => Ferrante_Rackoff_Data.Nox
866 fun class_field_ss phi =
867 HOL_basic_ss addsimps ([@{thm "linorder_not_less"}, @{thm "linorder_not_le"}])
868 addsplits [@{thm "abs_split"},@{thm "split_max"}, @{thm "split_min"}]
871 Ferrante_Rackoff_Data.funs @{thm "class_ordered_field_dense_linear_order.ferrack_axiom"}
872 {isolate_conv = field_isolate_conv, whatis = classfield_whatis, simpset = class_field_ss}