1 (* Title: HOL/Decision_Procs/Ferrack.thy
6 imports Complex_Main Dense_Linear_Order Efficient_Nat
7 uses ("ferrack_tac.ML")
10 section {* Quantifier elimination for @{text "\<real> (0, 1, +, <)"} *}
12 (*********************************************************************************)
13 (* SOME GENERAL STUFF< HAS TO BE MOVED IN SOME LIB *)
14 (*********************************************************************************)
16 primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list" where
18 | "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)"
20 lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}"
24 "\<lbrakk>x\<in> set xs ; y \<in> set xs\<rbrakk> \<Longrightarrow> (x,y) \<in> set (alluopairs xs) \<or> (y,x) \<in> set (alluopairs xs) "
28 assumes Pc: "\<forall> x y. P x y = P y x"
29 shows "(\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)"
31 assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y"
32 then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y" by blast
33 from alluopairs_set[OF x y] P Pc show"\<exists>(x, y)\<in>set (alluopairs xs). P x y"
36 assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y"
37 then obtain "x" and "y" where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+
38 from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast
39 with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
42 lemma nth_pos2: "0 < n \<Longrightarrow> (x#xs) ! n = xs ! (n - 1)"
43 using Nat.gr0_conv_Suc
46 lemma filter_length: "length (List.filter P xs) < Suc (length xs)"
47 apply (induct xs, auto) done
50 (*********************************************************************************)
51 (**** SHADOW SYNTAX AND SEMANTICS ****)
52 (*********************************************************************************)
54 datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num
57 (* A size for num to make inductive proofs simpler*)
58 primrec num_size :: "num \<Rightarrow> nat" where
60 | "num_size (Bound n) = 1"
61 | "num_size (Neg a) = 1 + num_size a"
62 | "num_size (Add a b) = 1 + num_size a + num_size b"
63 | "num_size (Sub a b) = 3 + num_size a + num_size b"
64 | "num_size (Mul c a) = 1 + num_size a"
65 | "num_size (CN n c a) = 3 + num_size a "
67 (* Semantics of numeral terms (num) *)
68 primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where
69 "Inum bs (C c) = (real c)"
70 | "Inum bs (Bound n) = bs!n"
71 | "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)"
72 | "Inum bs (Neg a) = -(Inum bs a)"
73 | "Inum bs (Add a b) = Inum bs a + Inum bs b"
74 | "Inum bs (Sub a b) = Inum bs a - Inum bs b"
75 | "Inum bs (Mul c a) = (real c) * Inum bs a"
78 T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num|
79 NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
83 fun fmsize :: "fm \<Rightarrow> nat" where
84 "fmsize (NOT p) = 1 + fmsize p"
85 | "fmsize (And p q) = 1 + fmsize p + fmsize q"
86 | "fmsize (Or p q) = 1 + fmsize p + fmsize q"
87 | "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
88 | "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
89 | "fmsize (E p) = 1 + fmsize p"
90 | "fmsize (A p) = 4+ fmsize p"
92 (* several lemmas about fmsize *)
93 lemma fmsize_pos: "fmsize p > 0"
94 by (induct p rule: fmsize.induct) simp_all
96 (* Semantics of formulae (fm) *)
97 primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where
100 | "Ifm bs (Lt a) = (Inum bs a < 0)"
101 | "Ifm bs (Gt a) = (Inum bs a > 0)"
102 | "Ifm bs (Le a) = (Inum bs a \<le> 0)"
103 | "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
104 | "Ifm bs (Eq a) = (Inum bs a = 0)"
105 | "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
106 | "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
107 | "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
108 | "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
109 | "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
110 | "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
111 | "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
112 | "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
114 lemma IfmLeSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Le (Sub s t)) = (s' \<le> t')"
118 lemma IfmLtSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Lt (Sub s t)) = (s' < t')"
121 lemma IfmEqSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Eq (Sub s t)) = (s' = t')"
124 lemma IfmNOT: " (Ifm bs p = P) \<Longrightarrow> (Ifm bs (NOT p) = (\<not>P))"
127 lemma IfmAnd: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (And p q) = (P \<and> Q))"
130 lemma IfmOr: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Or p q) = (P \<or> Q))"
133 lemma IfmImp: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Imp p q) = (P \<longrightarrow> Q))"
136 lemma IfmIff: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Iff p q) = (P = Q))"
140 lemma IfmE: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (E p) = (\<exists>x. P x))"
143 lemma IfmA: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (A p) = (\<forall>x. P x))"
147 fun not:: "fm \<Rightarrow> fm" where
152 lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
155 definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
156 "conj p q = (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else
157 if p = q then p else And p q)"
158 lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
159 by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
161 definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
162 "disj p q = (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p
163 else if p=q then p else Or p q)"
165 lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
166 by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
168 definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
169 "imp p q = (if (p = F \<or> q=T \<or> p=q) then T else if p=T then q else if q=F then not p
171 lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
172 by (cases "p=F \<or> q=T",simp_all add: imp_def)
174 definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
175 "iff p q = (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else
176 if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else
178 lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
179 by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto)
187 "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> conj P Q = And P Q"
188 by (simp_all add: conj_def)
196 "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> disj P Q = Or P Q"
197 by (simp_all add: disj_def)
204 "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> imp P Q = Imp P Q"
205 by (simp_all add: imp_def)
206 lemma trivNOT: "p \<noteq> NOT p" "NOT p \<noteq> p"
207 apply (induct p, auto)
216 "p \<noteq> NOT T \<Longrightarrow> iff T p = p"
217 "p\<noteq> NOT T \<Longrightarrow> iff p T = p"
218 "p\<noteq>q \<Longrightarrow> p\<noteq> NOT q \<Longrightarrow> q\<noteq> NOT p \<Longrightarrow> p\<noteq> F \<Longrightarrow> q\<noteq> F \<Longrightarrow> p \<noteq> T \<Longrightarrow> q \<noteq> T \<Longrightarrow> iff p q = Iff p q"
220 by (simp_all add: iff_def, cases p, auto)
221 (* Quantifier freeness *)
222 fun qfree:: "fm \<Rightarrow> bool" where
223 "qfree (E p) = False"
224 | "qfree (A p) = False"
225 | "qfree (NOT p) = qfree p"
226 | "qfree (And p q) = (qfree p \<and> qfree q)"
227 | "qfree (Or p q) = (qfree p \<and> qfree q)"
228 | "qfree (Imp p q) = (qfree p \<and> qfree q)"
229 | "qfree (Iff p q) = (qfree p \<and> qfree q)"
232 (* Boundedness and substitution *)
233 primrec numbound0:: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where
234 "numbound0 (C c) = True"
235 | "numbound0 (Bound n) = (n>0)"
236 | "numbound0 (CN n c a) = (n\<noteq>0 \<and> numbound0 a)"
237 | "numbound0 (Neg a) = numbound0 a"
238 | "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
239 | "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)"
240 | "numbound0 (Mul i a) = numbound0 a"
243 assumes nb: "numbound0 a"
244 shows "Inum (b#bs) a = Inum (b'#bs) a"
246 by (induct a) (simp_all add: nth_pos2)
248 primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
251 | "bound0 (Lt a) = numbound0 a"
252 | "bound0 (Le a) = numbound0 a"
253 | "bound0 (Gt a) = numbound0 a"
254 | "bound0 (Ge a) = numbound0 a"
255 | "bound0 (Eq a) = numbound0 a"
256 | "bound0 (NEq a) = numbound0 a"
257 | "bound0 (NOT p) = bound0 p"
258 | "bound0 (And p q) = (bound0 p \<and> bound0 q)"
259 | "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
260 | "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
261 | "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
262 | "bound0 (E p) = False"
263 | "bound0 (A p) = False"
266 assumes bp: "bound0 p"
267 shows "Ifm (b#bs) p = Ifm (b'#bs) p"
268 using bp numbound0_I[where b="b" and bs="bs" and b'="b'"]
269 by (induct p) (auto simp add: nth_pos2)
271 lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
273 lemma not_bn[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
277 lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
278 using conj_def by auto
279 lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
280 using conj_def by auto
282 lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
283 using disj_def by auto
284 lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
285 using disj_def by auto
287 lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
288 using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
289 lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
290 using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
292 lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
293 by (unfold iff_def,cases "p=q", auto)
294 lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
295 using iff_def by (unfold iff_def,cases "p=q", auto)
297 fun decrnum:: "num \<Rightarrow> num" where
298 "decrnum (Bound n) = Bound (n - 1)"
299 | "decrnum (Neg a) = Neg (decrnum a)"
300 | "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
301 | "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
302 | "decrnum (Mul c a) = Mul c (decrnum a)"
303 | "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
306 fun decr :: "fm \<Rightarrow> fm" where
307 "decr (Lt a) = Lt (decrnum a)"
308 | "decr (Le a) = Le (decrnum a)"
309 | "decr (Gt a) = Gt (decrnum a)"
310 | "decr (Ge a) = Ge (decrnum a)"
311 | "decr (Eq a) = Eq (decrnum a)"
312 | "decr (NEq a) = NEq (decrnum a)"
313 | "decr (NOT p) = NOT (decr p)"
314 | "decr (And p q) = conj (decr p) (decr q)"
315 | "decr (Or p q) = disj (decr p) (decr q)"
316 | "decr (Imp p q) = imp (decr p) (decr q)"
317 | "decr (Iff p q) = iff (decr p) (decr q)"
320 lemma decrnum: assumes nb: "numbound0 t"
321 shows "Inum (x#bs) t = Inum bs (decrnum t)"
322 using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2)
324 lemma decr: assumes nb: "bound0 p"
325 shows "Ifm (x#bs) p = Ifm bs (decr p)"
327 by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum)
329 lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
330 by (induct p, simp_all)
332 fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) where
335 | "isatom (Lt a) = True"
336 | "isatom (Le a) = True"
337 | "isatom (Gt a) = True"
338 | "isatom (Ge a) = True"
339 | "isatom (Eq a) = True"
340 | "isatom (NEq a) = True"
343 lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
344 by (induct p, simp_all)
346 definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
347 "djf f p q = (if q=T then T else if q=F then f p else
348 (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
349 definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
350 "evaldjf f ps = foldr (djf f) ps F"
352 lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
353 by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def)
354 (cases "f p", simp_all add: Let_def djf_def)
360 "q\<noteq>T \<Longrightarrow> q\<noteq>F \<Longrightarrow> djf f p q = (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q)"
361 by (simp_all add: djf_def)
363 lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))"
364 by(induct ps, simp_all add: evaldjf_def djf_Or)
366 lemma evaldjf_bound0:
367 assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
368 shows "bound0 (evaldjf f xs)"
369 using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto)
372 assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
373 shows "qfree (evaldjf f xs)"
374 using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto)
376 fun disjuncts :: "fm \<Rightarrow> fm list" where
377 "disjuncts (Or p q) = disjuncts p @ disjuncts q"
379 | "disjuncts p = [p]"
381 lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p"
382 by(induct p rule: disjuncts.induct, auto)
384 lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
386 assume nb: "bound0 p"
387 hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
388 thus ?thesis by (simp only: list_all_iff)
391 lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
394 hence "list_all qfree (disjuncts p)"
395 by (induct p rule: disjuncts.induct, auto)
396 thus ?thesis by (simp only: list_all_iff)
399 definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
400 "DJ f p = evaldjf f (disjuncts p)"
402 lemma DJ: assumes fdj: "\<forall> p q. Ifm bs (f (Or p q)) = Ifm bs (Or (f p) (f q))"
404 shows "Ifm bs (DJ f p) = Ifm bs (f p)"
406 have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))"
407 by (simp add: DJ_def evaldjf_ex)
408 also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
409 finally show ?thesis .
413 fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
414 shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
416 fix p assume qf: "qfree p"
417 have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
418 from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
419 with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
421 from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
424 lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
425 shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))"
429 from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
430 from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
431 have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))"
432 by (simp add: DJ_def evaldjf_ex)
433 also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto
434 also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
435 finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast
439 fun maxcoeff:: "num \<Rightarrow> int" where
440 "maxcoeff (C i) = abs i"
441 | "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)"
444 lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
445 by (induct t rule: maxcoeff.induct, auto)
447 fun numgcdh:: "num \<Rightarrow> int \<Rightarrow> int" where
448 "numgcdh (C i) = (\<lambda>g. gcd i g)"
449 | "numgcdh (CN n c t) = (\<lambda>g. gcd c (numgcdh t g))"
450 | "numgcdh t = (\<lambda>g. 1)"
452 definition numgcd :: "num \<Rightarrow> int" where
453 "numgcd t = numgcdh t (maxcoeff t)"
455 fun reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num" where
456 "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
457 | "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
458 | "reducecoeffh t = (\<lambda>g. t)"
460 definition reducecoeff :: "num \<Rightarrow> num" where
463 if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
465 fun dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
466 "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
467 | "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
468 | "dvdnumcoeff t = (\<lambda>g. False)"
470 lemma dvdnumcoeff_trans:
471 assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
472 shows "dvdnumcoeff t g"
474 by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg dvd_trans[OF gdg])
476 declare dvd_trans [trans add]
478 lemma natabs0: "(nat (abs x) = 0) = (x = 0)"
482 assumes g0: "numgcd t = 0"
483 shows "Inum bs t = 0"
484 using g0[simplified numgcd_def]
485 by (induct t rule: numgcdh.induct, auto simp add: natabs0 maxcoeff_pos min_max.sup_absorb2)
487 lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
489 by (induct t rule: numgcdh.induct, auto)
491 lemma numgcd_pos: "numgcd t \<ge>0"
492 by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
495 assumes gt: "dvdnumcoeff t g" and gp: "g > 0"
496 shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t"
498 proof(induct t rule: reducecoeffh.induct)
499 case (1 i) hence gd: "g dvd i" by simp
500 from gp have gnz: "g \<noteq> 0" by simp
501 from prems show ?case by (simp add: real_of_int_div[OF gnz gd])
503 case (2 n c t) hence gd: "g dvd c" by simp
504 from gp have gnz: "g \<noteq> 0" by simp
505 from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps)
506 qed (auto simp add: numgcd_def gp)
508 fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
509 "ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)"
510 | "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
511 | "ismaxcoeff t = (\<lambda>x. True)"
513 lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
514 by (induct t rule: ismaxcoeff.induct, auto)
516 lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
517 proof (induct t rule: maxcoeff.induct)
519 hence H:"ismaxcoeff t (maxcoeff t)" .
520 have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by (simp add: le_maxI2)
521 from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1)
524 lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> ((abs i > 1 \<and> abs j > 1) \<or> (abs i = 0 \<and> abs j > 1) \<or> (abs i > 1 \<and> abs j = 0))"
525 apply (cases "abs i = 0", simp_all add: gcd_int_def)
526 apply (cases "abs j = 0", simp_all)
527 apply (cases "abs i = 1", simp_all)
528 apply (cases "abs j = 1", simp_all)
531 lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow> m =0"
532 by (induct t rule: numgcdh.induct, auto)
534 lemma dvdnumcoeff_aux:
535 assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
536 shows "dvdnumcoeff t (numgcdh t m)"
538 proof(induct t rule: numgcdh.induct)
540 let ?g = "numgcdh t m"
541 from prems have th:"gcd c ?g > 1" by simp
542 from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
543 have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
544 moreover {assume "abs c > 1" and gp: "?g > 1" with prems
545 have th: "dvdnumcoeff t ?g" by simp
546 have th': "gcd c ?g dvd ?g" by simp
547 from dvdnumcoeff_trans[OF th' th] have ?case by simp }
548 moreover {assume "abs c = 0 \<and> ?g > 1"
549 with prems have th: "dvdnumcoeff t ?g" by simp
550 have th': "gcd c ?g dvd ?g" by simp
551 from dvdnumcoeff_trans[OF th' th] have ?case by simp
552 hence ?case by simp }
553 moreover {assume "abs c > 1" and g0:"?g = 0"
554 from numgcdh0[OF g0] have "m=0". with prems have ?case by simp }
555 ultimately show ?case by blast
558 lemma dvdnumcoeff_aux2:
559 assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
561 proof (simp add: numgcd_def)
562 let ?mc = "maxcoeff t"
563 let ?g = "numgcdh t ?mc"
564 have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
565 have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
566 assume H: "numgcdh t ?mc > 1"
567 from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" .
570 lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
573 have "?g \<ge> 0" by (simp add: numgcd_pos)
574 hence "?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
575 moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)}
576 moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)}
577 moreover { assume g1:"?g > 1"
578 from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+
579 from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis
580 by (simp add: reducecoeff_def Let_def)}
581 ultimately show ?thesis by blast
584 lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
585 by (induct t rule: reducecoeffh.induct, auto)
587 lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
588 using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
591 numadd:: "num \<times> num \<Rightarrow> num"
593 recdef numadd "measure (\<lambda> (t,s). size t + size s)"
594 "numadd (CN n1 c1 r1,CN n2 c2 r2) =
597 in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
598 else if n1 \<le> n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2)))
599 else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
600 "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"
601 "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))"
602 "numadd (C b1, C b2) = C (b1+b2)"
603 "numadd (a,b) = Add a b"
605 lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
606 apply (induct t s rule: numadd.induct, simp_all add: Let_def)
607 apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
608 apply (case_tac "n1 = n2", simp_all add: algebra_simps)
609 by (simp only: left_distrib[symmetric],simp)
611 lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
612 by (induct t s rule: numadd.induct, auto simp add: Let_def)
614 fun nummul:: "num \<Rightarrow> int \<Rightarrow> num" where
615 "nummul (C j) = (\<lambda> i. C (i*j))"
616 | "nummul (CN n c a) = (\<lambda> i. CN n (i*c) (nummul a i))"
617 | "nummul t = (\<lambda> i. Mul i t)"
619 lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
620 by (induct t rule: nummul.induct, auto simp add: algebra_simps)
622 lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
623 by (induct t rule: nummul.induct, auto )
625 definition numneg :: "num \<Rightarrow> num" where
626 "numneg t = nummul t (- 1)"
628 definition numsub :: "num \<Rightarrow> num \<Rightarrow> num" where
629 "numsub s t = (if s = t then C 0 else numadd (s,numneg t))"
631 lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
632 using numneg_def by simp
634 lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
635 using numneg_def by simp
637 lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
638 using numsub_def by simp
640 lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
641 using numsub_def by simp
643 primrec simpnum:: "num \<Rightarrow> num" where
644 "simpnum (C j) = C j"
645 | "simpnum (Bound n) = CN n 1 (C 0)"
646 | "simpnum (Neg t) = numneg (simpnum t)"
647 | "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
648 | "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
649 | "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
650 | "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0),simpnum t))"
652 lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
653 by (induct t) simp_all
655 lemma simpnum_numbound0[simp]:
656 "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
657 by (induct t) simp_all
659 fun nozerocoeff:: "num \<Rightarrow> bool" where
660 "nozerocoeff (C c) = True"
661 | "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
662 | "nozerocoeff t = True"
664 lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
665 by (induct a b rule: numadd.induct,auto simp add: Let_def)
667 lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)"
668 by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz)
670 lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
671 by (simp add: numneg_def nummul_nz)
673 lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
674 by (simp add: numsub_def numneg_nz numadd_nz)
676 lemma simpnum_nz: "nozerocoeff (simpnum t)"
677 by(induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz)
679 lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
680 proof (induct t rule: maxcoeff.induct)
682 hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
683 have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
684 with cnz have "max (abs c) (maxcoeff t) > 0" by arith
685 with prems show ?case by simp
688 lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0"
690 from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
691 from numgcdh0[OF th] have th:"maxcoeff t = 0" .
692 from maxcoeff_nz[OF nz th] show ?thesis .
695 definition simp_num_pair :: "(num \<times> int) \<Rightarrow> num \<times> int" where
696 "simp_num_pair = (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
697 (let t' = simpnum t ; g = numgcd t' in
698 if g > 1 then (let g' = gcd n g in
699 if g' = 1 then (t',n)
700 else (reducecoeffh t' g', n div g'))
703 lemma simp_num_pair_ci:
704 shows "((\<lambda> (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\<lambda> (t,n). Inum bs t / real n) (t,n))"
707 let ?t' = "simpnum t"
708 let ?g = "numgcd ?t'"
710 {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
712 { assume nnz: "n \<noteq> 0"
713 {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)}
715 {assume g1:"?g>1" hence g0: "?g > 0" by simp
716 from g1 nnz have gp0: "?g' \<noteq> 0" by simp
717 hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
718 hence "?g'= 1 \<or> ?g' > 1" by arith
719 moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)}
720 moreover {assume g'1:"?g'>1"
721 from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
722 let ?tt = "reducecoeffh ?t' ?g'"
723 let ?t = "Inum bs ?tt"
724 have gpdg: "?g' dvd ?g" by simp
725 have gpdd: "?g' dvd n" by simp
726 have gpdgp: "?g' dvd ?g'" by simp
727 from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p]
728 have th2:"real ?g' * ?t = Inum bs ?t'" by simp
729 from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def)
730 also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp
731 also have "\<dots> = (Inum bs ?t' / real n)"
732 using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp
733 finally have "?lhs = Inum bs t / real n" by (simp add: simpnum_ci)
734 then have ?thesis using prems by (simp add: simp_num_pair_def)}
735 ultimately have ?thesis by blast}
736 ultimately have ?thesis by blast}
737 ultimately show ?thesis by blast
740 lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')"
741 shows "numbound0 t' \<and> n' >0"
743 let ?t' = "simpnum t"
744 let ?g = "numgcd ?t'"
746 {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)}
748 { assume nnz: "n \<noteq> 0"
749 {assume "\<not> ?g > 1" hence ?thesis using prems by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)}
751 {assume g1:"?g>1" hence g0: "?g > 0" by simp
752 from g1 nnz have gp0: "?g' \<noteq> 0" by simp
753 hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
754 hence "?g'= 1 \<or> ?g' > 1" by arith
755 moreover {assume "?g'=1" hence ?thesis using prems
756 by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)}
757 moreover {assume g'1:"?g'>1"
758 have gpdg: "?g' dvd ?g" by simp
759 have gpdd: "?g' dvd n" by simp
760 have gpdgp: "?g' dvd ?g'" by simp
761 from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
762 from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]]
763 have "n div ?g' >0" by simp
764 hence ?thesis using prems
765 by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0)}
766 ultimately have ?thesis by blast}
767 ultimately have ?thesis by blast}
768 ultimately show ?thesis by blast
771 fun simpfm :: "fm \<Rightarrow> fm" where
772 "simpfm (And p q) = conj (simpfm p) (simpfm q)"
773 | "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
774 | "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
775 | "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
776 | "simpfm (NOT p) = not (simpfm p)"
777 | "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F
778 | _ \<Rightarrow> Lt a')"
779 | "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<le> 0) then T else F | _ \<Rightarrow> Le a')"
780 | "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0) then T else F | _ \<Rightarrow> Gt a')"
781 | "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<ge> 0) then T else F | _ \<Rightarrow> Ge a')"
782 | "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0) then T else F | _ \<Rightarrow> Eq a')"
783 | "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<noteq> 0) then T else F | _ \<Rightarrow> NEq a')"
785 lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p"
786 proof(induct p rule: simpfm.induct)
787 case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
788 {fix v assume "?sa = C v" hence ?case using sa by simp }
789 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
790 by (cases ?sa, simp_all add: Let_def)}
791 ultimately show ?case by blast
793 case (7 a) let ?sa = "simpnum a"
794 from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
795 {fix v assume "?sa = C v" hence ?case using sa by simp }
796 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
797 by (cases ?sa, simp_all add: Let_def)}
798 ultimately show ?case by blast
800 case (8 a) let ?sa = "simpnum a"
801 from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
802 {fix v assume "?sa = C v" hence ?case using sa by simp }
803 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
804 by (cases ?sa, simp_all add: Let_def)}
805 ultimately show ?case by blast
807 case (9 a) let ?sa = "simpnum a"
808 from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
809 {fix v assume "?sa = C v" hence ?case using sa by simp }
810 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
811 by (cases ?sa, simp_all add: Let_def)}
812 ultimately show ?case by blast
814 case (10 a) let ?sa = "simpnum a"
815 from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
816 {fix v assume "?sa = C v" hence ?case using sa by simp }
817 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
818 by (cases ?sa, simp_all add: Let_def)}
819 ultimately show ?case by blast
821 case (11 a) let ?sa = "simpnum a"
822 from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
823 {fix v assume "?sa = C v" hence ?case using sa by simp }
824 moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa
825 by (cases ?sa, simp_all add: Let_def)}
826 ultimately show ?case by blast
827 qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not)
830 lemma simpfm_bound0: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
831 proof(induct p rule: simpfm.induct)
832 case (6 a) hence nb: "numbound0 a" by simp
833 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
834 thus ?case by (cases "simpnum a", auto simp add: Let_def)
836 case (7 a) hence nb: "numbound0 a" by simp
837 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
838 thus ?case by (cases "simpnum a", auto simp add: Let_def)
840 case (8 a) hence nb: "numbound0 a" by simp
841 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
842 thus ?case by (cases "simpnum a", auto simp add: Let_def)
844 case (9 a) hence nb: "numbound0 a" by simp
845 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
846 thus ?case by (cases "simpnum a", auto simp add: Let_def)
848 case (10 a) hence nb: "numbound0 a" by simp
849 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
850 thus ?case by (cases "simpnum a", auto simp add: Let_def)
852 case (11 a) hence nb: "numbound0 a" by simp
853 hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
854 thus ?case by (cases "simpnum a", auto simp add: Let_def)
855 qed(auto simp add: disj_def imp_def iff_def conj_def not_bn)
857 lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)"
858 by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def)
859 (case_tac "simpnum a",auto)+
861 consts prep :: "fm \<Rightarrow> fm"
862 recdef prep "measure fmsize"
865 "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
866 "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
867 "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
868 "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
869 "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
870 "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
871 "prep (E p) = E (prep p)"
872 "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
873 "prep (A p) = prep (NOT (E (NOT p)))"
874 "prep (NOT (NOT p)) = prep p"
875 "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
876 "prep (NOT (A p)) = prep (E (NOT p))"
877 "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
878 "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
879 "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
880 "prep (NOT p) = not (prep p)"
881 "prep (Or p q) = disj (prep p) (prep q)"
882 "prep (And p q) = conj (prep p) (prep q)"
883 "prep (Imp p q) = prep (Or (NOT p) q)"
884 "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
886 (hints simp add: fmsize_pos)
887 lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
888 by (induct p rule: prep.induct, auto)
890 (* Generic quantifier elimination *)
891 function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where
892 "qelim (E p) = (\<lambda> qe. DJ qe (qelim p qe))"
893 | "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
894 | "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
895 | "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))"
896 | "qelim (Or p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))"
897 | "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))"
898 | "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
899 | "qelim p = (\<lambda> y. simpfm p)"
900 by pat_completeness auto
901 termination qelim by (relation "measure fmsize") simp_all
904 assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
905 shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)"
906 using qe_inv DJ_qe[OF qe_inv]
907 by(induct p rule: qelim.induct)
908 (auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf
909 simpfm simpfm_qf simp del: simpfm.simps)
911 fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*) where
912 "minusinf (And p q) = conj (minusinf p) (minusinf q)"
913 | "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
914 | "minusinf (Eq (CN 0 c e)) = F"
915 | "minusinf (NEq (CN 0 c e)) = T"
916 | "minusinf (Lt (CN 0 c e)) = T"
917 | "minusinf (Le (CN 0 c e)) = T"
918 | "minusinf (Gt (CN 0 c e)) = F"
919 | "minusinf (Ge (CN 0 c e)) = F"
922 fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*) where
923 "plusinf (And p q) = conj (plusinf p) (plusinf q)"
924 | "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
925 | "plusinf (Eq (CN 0 c e)) = F"
926 | "plusinf (NEq (CN 0 c e)) = T"
927 | "plusinf (Lt (CN 0 c e)) = F"
928 | "plusinf (Le (CN 0 c e)) = F"
929 | "plusinf (Gt (CN 0 c e)) = T"
930 | "plusinf (Ge (CN 0 c e)) = T"
933 fun isrlfm :: "fm \<Rightarrow> bool" (* Linearity test for fm *) where
934 "isrlfm (And p q) = (isrlfm p \<and> isrlfm q)"
935 | "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)"
936 | "isrlfm (Eq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
937 | "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
938 | "isrlfm (Lt (CN 0 c e)) = (c>0 \<and> numbound0 e)"
939 | "isrlfm (Le (CN 0 c e)) = (c>0 \<and> numbound0 e)"
940 | "isrlfm (Gt (CN 0 c e)) = (c>0 \<and> numbound0 e)"
941 | "isrlfm (Ge (CN 0 c e)) = (c>0 \<and> numbound0 e)"
942 | "isrlfm p = (isatom p \<and> (bound0 p))"
944 (* splits the bounded from the unbounded part*)
945 function (sequential) rsplit0 :: "num \<Rightarrow> int \<times> num" where
946 "rsplit0 (Bound 0) = (1,C 0)"
947 | "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a ; (cb,tb) = rsplit0 b
948 in (ca+cb, Add ta tb))"
949 | "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))"
950 | "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (-c,Neg t))"
951 | "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c*ca,Mul c ta))"
952 | "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c+ca,ta))"
953 | "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca,CN n c ta))"
954 | "rsplit0 t = (0,t)"
955 by pat_completeness auto
956 termination rsplit0 by (relation "measure num_size") simp_all
959 shows "Inum bs ((split (CN 0)) (rsplit0 t)) = Inum bs t \<and> numbound0 (snd (rsplit0 t))"
960 proof (induct t rule: rsplit0.induct)
962 let ?sa = "rsplit0 a" let ?sb = "rsplit0 b"
963 let ?ca = "fst ?sa" let ?cb = "fst ?sb"
964 let ?ta = "snd ?sa" let ?tb = "snd ?sb"
965 from prems have nb: "numbound0 (snd(rsplit0 (Add a b)))"
966 by (cases "rsplit0 a") (auto simp add: Let_def split_def)
967 have "Inum bs ((split (CN 0)) (rsplit0 (Add a b))) =
968 Inum bs ((split (CN 0)) ?sa)+Inum bs ((split (CN 0)) ?sb)"
969 by (simp add: Let_def split_def algebra_simps)
970 also have "\<dots> = Inum bs a + Inum bs b" using prems by (cases "rsplit0 a") auto
971 finally show ?case using nb by simp
972 qed (auto simp add: Let_def split_def algebra_simps , simp add: right_distrib[symmetric])
974 (* Linearize a formula*)
976 lt :: "int \<Rightarrow> num \<Rightarrow> fm"
978 "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t))
979 else (Gt (CN 0 (-c) (Neg t))))"
982 le :: "int \<Rightarrow> num \<Rightarrow> fm"
984 "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t))
985 else (Ge (CN 0 (-c) (Neg t))))"
988 gt :: "int \<Rightarrow> num \<Rightarrow> fm"
990 "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t))
991 else (Lt (CN 0 (-c) (Neg t))))"
994 ge :: "int \<Rightarrow> num \<Rightarrow> fm"
996 "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t))
997 else (Le (CN 0 (-c) (Neg t))))"
1000 eq :: "int \<Rightarrow> num \<Rightarrow> fm"
1002 "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t))
1003 else (Eq (CN 0 (-c) (Neg t))))"
1006 neq :: "int \<Rightarrow> num \<Rightarrow> fm"
1008 "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t))
1009 else (NEq (CN 0 (-c) (Neg t))))"
1011 lemma lt: "numnoabs t \<Longrightarrow> Ifm bs (split lt (rsplit0 t)) = Ifm bs (Lt t) \<and> isrlfm (split lt (rsplit0 t))"
1012 using rsplit0[where bs = "bs" and t="t"]
1013 by (auto simp add: lt_def split_def,cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1015 lemma le: "numnoabs t \<Longrightarrow> Ifm bs (split le (rsplit0 t)) = Ifm bs (Le t) \<and> isrlfm (split le (rsplit0 t))"
1016 using rsplit0[where bs = "bs" and t="t"]
1017 by (auto simp add: le_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1019 lemma gt: "numnoabs t \<Longrightarrow> Ifm bs (split gt (rsplit0 t)) = Ifm bs (Gt t) \<and> isrlfm (split gt (rsplit0 t))"
1020 using rsplit0[where bs = "bs" and t="t"]
1021 by (auto simp add: gt_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1023 lemma ge: "numnoabs t \<Longrightarrow> Ifm bs (split ge (rsplit0 t)) = Ifm bs (Ge t) \<and> isrlfm (split ge (rsplit0 t))"
1024 using rsplit0[where bs = "bs" and t="t"]
1025 by (auto simp add: ge_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1027 lemma eq: "numnoabs t \<Longrightarrow> Ifm bs (split eq (rsplit0 t)) = Ifm bs (Eq t) \<and> isrlfm (split eq (rsplit0 t))"
1028 using rsplit0[where bs = "bs" and t="t"]
1029 by (auto simp add: eq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1031 lemma neq: "numnoabs t \<Longrightarrow> Ifm bs (split neq (rsplit0 t)) = Ifm bs (NEq t) \<and> isrlfm (split neq (rsplit0 t))"
1032 using rsplit0[where bs = "bs" and t="t"]
1033 by (auto simp add: neq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
1035 lemma conj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)"
1036 by (auto simp add: conj_def)
1037 lemma disj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)"
1038 by (auto simp add: disj_def)
1040 consts rlfm :: "fm \<Rightarrow> fm"
1041 recdef rlfm "measure fmsize"
1042 "rlfm (And p q) = conj (rlfm p) (rlfm q)"
1043 "rlfm (Or p q) = disj (rlfm p) (rlfm q)"
1044 "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)"
1045 "rlfm (Iff p q) = disj (conj (rlfm p) (rlfm q)) (conj (rlfm (NOT p)) (rlfm (NOT q)))"
1046 "rlfm (Lt a) = split lt (rsplit0 a)"
1047 "rlfm (Le a) = split le (rsplit0 a)"
1048 "rlfm (Gt a) = split gt (rsplit0 a)"
1049 "rlfm (Ge a) = split ge (rsplit0 a)"
1050 "rlfm (Eq a) = split eq (rsplit0 a)"
1051 "rlfm (NEq a) = split neq (rsplit0 a)"
1052 "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))"
1053 "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))"
1054 "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))"
1055 "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))"
1056 "rlfm (NOT (NOT p)) = rlfm p"
1059 "rlfm (NOT (Lt a)) = rlfm (Ge a)"
1060 "rlfm (NOT (Le a)) = rlfm (Gt a)"
1061 "rlfm (NOT (Gt a)) = rlfm (Le a)"
1062 "rlfm (NOT (Ge a)) = rlfm (Lt a)"
1063 "rlfm (NOT (Eq a)) = rlfm (NEq a)"
1064 "rlfm (NOT (NEq a)) = rlfm (Eq a)"
1065 "rlfm p = p" (hints simp add: fmsize_pos)
1068 assumes qfp: "qfree p"
1069 shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)"
1071 by (induct p rule: rlfm.induct, auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin)
1073 (* Operations needed for Ferrante and Rackoff *)
1074 lemma rminusinf_inf:
1075 assumes lp: "isrlfm p"
1076 shows "\<exists> z. \<forall> x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p")
1078 proof (induct p rule: minusinf.induct)
1079 case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto
1081 case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto
1084 from prems have nb: "numbound0 e" by simp
1085 from prems have cp: "real c > 0" by simp
1087 let ?e="Inum (a#bs) e"
1088 let ?z = "(- ?e) / real c"
1091 hence "(real c * x < - ?e)"
1092 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1093 hence "real c * x + ?e < 0" by arith
1094 hence "real c * x + ?e \<noteq> 0" by simp
1095 with xz have "?P ?z x (Eq (CN 0 c e))"
1096 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1097 hence "\<forall> x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp
1101 from prems have nb: "numbound0 e" by simp
1102 from prems have cp: "real c > 0" by simp
1104 let ?e="Inum (a#bs) e"
1105 let ?z = "(- ?e) / real c"
1108 hence "(real c * x < - ?e)"
1109 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1110 hence "real c * x + ?e < 0" by arith
1111 hence "real c * x + ?e \<noteq> 0" by simp
1112 with xz have "?P ?z x (NEq (CN 0 c e))"
1113 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1114 hence "\<forall> x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp
1118 from prems have nb: "numbound0 e" by simp
1119 from prems have cp: "real c > 0" by simp
1121 let ?e="Inum (a#bs) e"
1122 let ?z = "(- ?e) / real c"
1125 hence "(real c * x < - ?e)"
1126 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1127 hence "real c * x + ?e < 0" by arith
1128 with xz have "?P ?z x (Lt (CN 0 c e))"
1129 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1130 hence "\<forall> x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp
1134 from prems have nb: "numbound0 e" by simp
1135 from prems have cp: "real c > 0" by simp
1137 let ?e="Inum (a#bs) e"
1138 let ?z = "(- ?e) / real c"
1141 hence "(real c * x < - ?e)"
1142 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1143 hence "real c * x + ?e < 0" by arith
1144 with xz have "?P ?z x (Le (CN 0 c e))"
1145 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1146 hence "\<forall> x < ?z. ?P ?z x (Le (CN 0 c e))" by simp
1150 from prems have nb: "numbound0 e" by simp
1151 from prems have cp: "real c > 0" by simp
1153 let ?e="Inum (a#bs) e"
1154 let ?z = "(- ?e) / real c"
1157 hence "(real c * x < - ?e)"
1158 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1159 hence "real c * x + ?e < 0" by arith
1160 with xz have "?P ?z x (Gt (CN 0 c e))"
1161 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1162 hence "\<forall> x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp
1166 from prems have nb: "numbound0 e" by simp
1167 from prems have cp: "real c > 0" by simp
1169 let ?e="Inum (a#bs) e"
1170 let ?z = "(- ?e) / real c"
1173 hence "(real c * x < - ?e)"
1174 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac)
1175 hence "real c * x + ?e < 0" by arith
1176 with xz have "?P ?z x (Ge (CN 0 c e))"
1177 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1178 hence "\<forall> x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp
1183 assumes lp: "isrlfm p"
1184 shows "\<exists> z. \<forall> x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p")
1186 proof (induct p rule: isrlfm.induct)
1187 case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto
1189 case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto
1192 from prems have nb: "numbound0 e" by simp
1193 from prems have cp: "real c > 0" by simp
1195 let ?e="Inum (a#bs) e"
1196 let ?z = "(- ?e) / real c"
1199 with mult_strict_right_mono [OF xz cp] cp
1200 have "(real c * x > - ?e)" by (simp add: mult_ac)
1201 hence "real c * x + ?e > 0" by arith
1202 hence "real c * x + ?e \<noteq> 0" by simp
1203 with xz have "?P ?z x (Eq (CN 0 c e))"
1204 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1205 hence "\<forall> x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp
1209 from prems have nb: "numbound0 e" by simp
1210 from prems have cp: "real c > 0" by simp
1212 let ?e="Inum (a#bs) e"
1213 let ?z = "(- ?e) / real c"
1216 with mult_strict_right_mono [OF xz cp] cp
1217 have "(real c * x > - ?e)" by (simp add: mult_ac)
1218 hence "real c * x + ?e > 0" by arith
1219 hence "real c * x + ?e \<noteq> 0" by simp
1220 with xz have "?P ?z x (NEq (CN 0 c e))"
1221 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1222 hence "\<forall> x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp
1226 from prems have nb: "numbound0 e" by simp
1227 from prems have cp: "real c > 0" by simp
1229 let ?e="Inum (a#bs) e"
1230 let ?z = "(- ?e) / real c"
1233 with mult_strict_right_mono [OF xz cp] cp
1234 have "(real c * x > - ?e)" by (simp add: mult_ac)
1235 hence "real c * x + ?e > 0" by arith
1236 with xz have "?P ?z x (Lt (CN 0 c e))"
1237 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1238 hence "\<forall> x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp
1242 from prems have nb: "numbound0 e" by simp
1243 from prems have cp: "real c > 0" by simp
1245 let ?e="Inum (a#bs) e"
1246 let ?z = "(- ?e) / real c"
1249 with mult_strict_right_mono [OF xz cp] cp
1250 have "(real c * x > - ?e)" by (simp add: mult_ac)
1251 hence "real c * x + ?e > 0" by arith
1252 with xz have "?P ?z x (Le (CN 0 c e))"
1253 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1254 hence "\<forall> x > ?z. ?P ?z x (Le (CN 0 c e))" by simp
1258 from prems have nb: "numbound0 e" by simp
1259 from prems have cp: "real c > 0" by simp
1261 let ?e="Inum (a#bs) e"
1262 let ?z = "(- ?e) / real c"
1265 with mult_strict_right_mono [OF xz cp] cp
1266 have "(real c * x > - ?e)" by (simp add: mult_ac)
1267 hence "real c * x + ?e > 0" by arith
1268 with xz have "?P ?z x (Gt (CN 0 c e))"
1269 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1270 hence "\<forall> x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp
1274 from prems have nb: "numbound0 e" by simp
1275 from prems have cp: "real c > 0" by simp
1277 let ?e="Inum (a#bs) e"
1278 let ?z = "(- ?e) / real c"
1281 with mult_strict_right_mono [OF xz cp] cp
1282 have "(real c * x > - ?e)" by (simp add: mult_ac)
1283 hence "real c * x + ?e > 0" by arith
1284 with xz have "?P ?z x (Ge (CN 0 c e))"
1285 using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
1286 hence "\<forall> x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp
1290 lemma rminusinf_bound0:
1291 assumes lp: "isrlfm p"
1292 shows "bound0 (minusinf p)"
1294 by (induct p rule: minusinf.induct) simp_all
1296 lemma rplusinf_bound0:
1297 assumes lp: "isrlfm p"
1298 shows "bound0 (plusinf p)"
1300 by (induct p rule: plusinf.induct) simp_all
1303 assumes lp: "isrlfm p"
1304 and ex: "Ifm (a#bs) (minusinf p)"
1305 shows "\<exists> x. Ifm (x#bs) p"
1307 from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
1308 have th: "\<forall> x. Ifm (x#bs) (minusinf p)" by auto
1309 from rminusinf_inf[OF lp, where bs="bs"]
1310 obtain z where z_def: "\<forall>x<z. Ifm (x # bs) (minusinf p) = Ifm (x # bs) p" by blast
1311 from th have "Ifm ((z - 1)#bs) (minusinf p)" by simp
1312 moreover have "z - 1 < z" by simp
1313 ultimately show ?thesis using z_def by auto
1317 assumes lp: "isrlfm p"
1318 and ex: "Ifm (a#bs) (plusinf p)"
1319 shows "\<exists> x. Ifm (x#bs) p"
1321 from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
1322 have th: "\<forall> x. Ifm (x#bs) (plusinf p)" by auto
1323 from rplusinf_inf[OF lp, where bs="bs"]
1324 obtain z where z_def: "\<forall>x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast
1325 from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp
1326 moreover have "z + 1 > z" by simp
1327 ultimately show ?thesis using z_def by auto
1331 uset:: "fm \<Rightarrow> (num \<times> int) list"
1332 usubst :: "fm \<Rightarrow> (num \<times> int) \<Rightarrow> fm "
1333 recdef uset "measure size"
1334 "uset (And p q) = (uset p @ uset q)"
1335 "uset (Or p q) = (uset p @ uset q)"
1336 "uset (Eq (CN 0 c e)) = [(Neg e,c)]"
1337 "uset (NEq (CN 0 c e)) = [(Neg e,c)]"
1338 "uset (Lt (CN 0 c e)) = [(Neg e,c)]"
1339 "uset (Le (CN 0 c e)) = [(Neg e,c)]"
1340 "uset (Gt (CN 0 c e)) = [(Neg e,c)]"
1341 "uset (Ge (CN 0 c e)) = [(Neg e,c)]"
1343 recdef usubst "measure size"
1344 "usubst (And p q) = (\<lambda> (t,n). And (usubst p (t,n)) (usubst q (t,n)))"
1345 "usubst (Or p q) = (\<lambda> (t,n). Or (usubst p (t,n)) (usubst q (t,n)))"
1346 "usubst (Eq (CN 0 c e)) = (\<lambda> (t,n). Eq (Add (Mul c t) (Mul n e)))"
1347 "usubst (NEq (CN 0 c e)) = (\<lambda> (t,n). NEq (Add (Mul c t) (Mul n e)))"
1348 "usubst (Lt (CN 0 c e)) = (\<lambda> (t,n). Lt (Add (Mul c t) (Mul n e)))"
1349 "usubst (Le (CN 0 c e)) = (\<lambda> (t,n). Le (Add (Mul c t) (Mul n e)))"
1350 "usubst (Gt (CN 0 c e)) = (\<lambda> (t,n). Gt (Add (Mul c t) (Mul n e)))"
1351 "usubst (Ge (CN 0 c e)) = (\<lambda> (t,n). Ge (Add (Mul c t) (Mul n e)))"
1352 "usubst p = (\<lambda> (t,n). p)"
1354 lemma usubst_I: assumes lp: "isrlfm p"
1355 and np: "real n > 0" and nbt: "numbound0 t"
1356 shows "(Ifm (x#bs) (usubst p (t,n)) = Ifm (((Inum (x#bs) t)/(real n))#bs) p) \<and> bound0 (usubst p (t,n))" (is "(?I x (usubst p (t,n)) = ?I ?u p) \<and> ?B p" is "(_ = ?I (?t/?n) p) \<and> _" is "(_ = ?I (?N x t /_) p) \<and> _")
1358 proof(induct p rule: usubst.induct)
1359 case (5 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1360 have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)"
1361 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1362 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)"
1363 by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1364 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1365 also have "\<dots> = (real c *?t + ?n* (?N x e) < 0)"
1367 finally show ?case using nbt nb by (simp add: algebra_simps)
1369 case (6 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1370 have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<le> 0)"
1371 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1372 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<le> 0)"
1373 by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1374 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1375 also have "\<dots> = (real c *?t + ?n* (?N x e) \<le> 0)"
1377 finally show ?case using nbt nb by (simp add: algebra_simps)
1379 case (7 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1380 have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)"
1381 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1382 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)"
1383 by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1384 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1385 also have "\<dots> = (real c *?t + ?n* (?N x e) > 0)"
1387 finally show ?case using nbt nb by (simp add: algebra_simps)
1389 case (8 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1390 have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<ge> 0)"
1391 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1392 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<ge> 0)"
1393 by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1394 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1395 also have "\<dots> = (real c *?t + ?n* (?N x e) \<ge> 0)"
1397 finally show ?case using nbt nb by (simp add: algebra_simps)
1399 case (3 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1400 from np have np: "real n \<noteq> 0" by simp
1401 have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 0)"
1402 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1403 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)"
1404 by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1405 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1406 also have "\<dots> = (real c *?t + ?n* (?N x e) = 0)"
1408 finally show ?case using nbt nb by (simp add: algebra_simps)
1410 case (4 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
1411 from np have np: "real n \<noteq> 0" by simp
1412 have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<noteq> 0)"
1413 using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
1414 also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<noteq> 0)"
1415 by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)"
1416 and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
1417 also have "\<dots> = (real c *?t + ?n* (?N x e) \<noteq> 0)"
1419 finally show ?case using nbt nb by (simp add: algebra_simps)
1420 qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"] nth_pos2)
1423 assumes lp: "isrlfm p"
1424 shows "\<forall> (t,k) \<in> set (uset p). numbound0 t \<and> k >0"
1426 by(induct p rule: uset.induct,auto)
1428 lemma rminusinf_uset:
1429 assumes lp: "isrlfm p"
1430 and nmi: "\<not> (Ifm (a#bs) (minusinf p))" (is "\<not> (Ifm (a#bs) (?M p))")
1431 and ex: "Ifm (x#bs) p" (is "?I x p")
1432 shows "\<exists> (s,m) \<in> set (uset p). x \<ge> Inum (a#bs) s / real m" (is "\<exists> (s,m) \<in> ?U p. x \<ge> ?N a s / real m")
1434 have "\<exists> (s,m) \<in> set (uset p). real m * x \<ge> Inum (a#bs) s " (is "\<exists> (s,m) \<in> ?U p. real m *x \<ge> ?N a s")
1436 by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2)
1437 then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<ge> ?N a s" by blast
1438 from uset_l[OF lp] smU have mp: "real m > 0" by auto
1439 from pos_divide_le_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \<ge> ?N a s / real m"
1440 by (auto simp add: mult_commute)
1441 thus ?thesis using smU by auto
1444 lemma rplusinf_uset:
1445 assumes lp: "isrlfm p"
1446 and nmi: "\<not> (Ifm (a#bs) (plusinf p))" (is "\<not> (Ifm (a#bs) (?M p))")
1447 and ex: "Ifm (x#bs) p" (is "?I x p")
1448 shows "\<exists> (s,m) \<in> set (uset p). x \<le> Inum (a#bs) s / real m" (is "\<exists> (s,m) \<in> ?U p. x \<le> ?N a s / real m")
1450 have "\<exists> (s,m) \<in> set (uset p). real m * x \<le> Inum (a#bs) s " (is "\<exists> (s,m) \<in> ?U p. real m *x \<le> ?N a s")
1452 by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"] nth_pos2)
1453 then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<le> ?N a s" by blast
1454 from uset_l[OF lp] smU have mp: "real m > 0" by auto
1455 from pos_le_divide_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \<le> ?N a s / real m"
1456 by (auto simp add: mult_commute)
1457 thus ?thesis using smU by auto
1461 assumes lp: "isrlfm p"
1462 and noS: "\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> (\<lambda> (t,n). Inum (x#bs) t / real n) ` set (uset p)"
1463 (is "\<forall> t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda> (t,n). ?N x t / real n ) ` (?U p)")
1464 and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p"
1465 and ly: "l < y" and yu: "y < u"
1466 shows "Ifm (y#bs) p"
1468 proof (induct p rule: isrlfm.induct)
1469 case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
1470 from prems have "x * real c + ?N x e < 0" by (simp add: algebra_simps)
1471 hence pxc: "x < (- ?N x e) / real c"
1472 by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"])
1473 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1474 with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
1475 hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
1476 moreover {assume y: "y < (-?N x e)/ real c"
1477 hence "y * real c < - ?N x e"
1478 by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric])
1479 hence "real c * y + ?N x e < 0" by (simp add: algebra_simps)
1480 hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
1481 moreover {assume y: "y > (- ?N x e) / real c"
1482 with yu have eu: "u > (- ?N x e) / real c" by auto
1483 with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto)
1484 with lx pxc have "False" by auto
1485 hence ?case by simp }
1486 ultimately show ?case by blast
1488 case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp +
1489 from prems have "x * real c + ?N x e \<le> 0" by (simp add: algebra_simps)
1490 hence pxc: "x \<le> (- ?N x e) / real c"
1491 by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"])
1492 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1493 with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
1494 hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
1495 moreover {assume y: "y < (-?N x e)/ real c"
1496 hence "y * real c < - ?N x e"
1497 by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric])
1498 hence "real c * y + ?N x e < 0" by (simp add: algebra_simps)
1499 hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
1500 moreover {assume y: "y > (- ?N x e) / real c"
1501 with yu have eu: "u > (- ?N x e) / real c" by auto
1502 with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto)
1503 with lx pxc have "False" by auto
1504 hence ?case by simp }
1505 ultimately show ?case by blast
1507 case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
1508 from prems have "x * real c + ?N x e > 0" by (simp add: algebra_simps)
1509 hence pxc: "x > (- ?N x e) / real c"
1510 by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"])
1511 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1512 with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
1513 hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
1514 moreover {assume y: "y > (-?N x e)/ real c"
1515 hence "y * real c > - ?N x e"
1516 by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric])
1517 hence "real c * y + ?N x e > 0" by (simp add: algebra_simps)
1518 hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
1519 moreover {assume y: "y < (- ?N x e) / real c"
1520 with ly have eu: "l < (- ?N x e) / real c" by auto
1521 with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto)
1522 with xu pxc have "False" by auto
1523 hence ?case by simp }
1524 ultimately show ?case by blast
1526 case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
1527 from prems have "x * real c + ?N x e \<ge> 0" by (simp add: algebra_simps)
1528 hence pxc: "x \<ge> (- ?N x e) / real c"
1529 by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"])
1530 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1531 with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
1532 hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
1533 moreover {assume y: "y > (-?N x e)/ real c"
1534 hence "y * real c > - ?N x e"
1535 by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric])
1536 hence "real c * y + ?N x e > 0" by (simp add: algebra_simps)
1537 hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
1538 moreover {assume y: "y < (- ?N x e) / real c"
1539 with ly have eu: "l < (- ?N x e) / real c" by auto
1540 with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto)
1541 with xu pxc have "False" by auto
1542 hence ?case by simp }
1543 ultimately show ?case by blast
1545 case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
1546 from cp have cnz: "real c \<noteq> 0" by simp
1547 from prems have "x * real c + ?N x e = 0" by (simp add: algebra_simps)
1548 hence pxc: "x = (- ?N x e) / real c"
1549 by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"])
1550 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1551 with lx xu have yne: "x \<noteq> - ?N x e / real c" by auto
1552 with pxc show ?case by simp
1554 case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
1555 from cp have cnz: "real c \<noteq> 0" by simp
1556 from prems have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
1557 with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
1558 hence "y* real c \<noteq> -?N x e"
1559 by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp
1560 hence "y* real c + ?N x e \<noteq> 0" by (simp add: algebra_simps)
1561 thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"]
1562 by (simp add: algebra_simps)
1563 qed (auto simp add: nth_pos2 numbound0_I[where bs="bs" and b="y" and b'="x"])
1565 lemma finite_set_intervals:
1566 assumes px: "P (x::real)"
1567 and lx: "l \<le> x" and xu: "x \<le> u"
1568 and linS: "l\<in> S" and uinS: "u \<in> S"
1569 and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
1570 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"
1572 let ?Mx = "{y. y\<in> S \<and> y \<le> x}"
1573 let ?xM = "{y. y\<in> S \<and> x \<le> y}"
1576 have MxS: "?Mx \<subseteq> S" by blast
1577 hence fMx: "finite ?Mx" using fS finite_subset by auto
1578 from lx linS have linMx: "l \<in> ?Mx" by blast
1579 hence Mxne: "?Mx \<noteq> {}" by blast
1580 have xMS: "?xM \<subseteq> S" by blast
1581 hence fxM: "finite ?xM" using fS finite_subset by auto
1582 from xu uinS have linxM: "u \<in> ?xM" by blast
1583 hence xMne: "?xM \<noteq> {}" by blast
1584 have ax:"?a \<le> x" using Mxne fMx by auto
1585 have xb:"x \<le> ?b" using xMne fxM by auto
1586 have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast
1587 have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast
1588 have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S"
1591 assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S"
1592 from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by auto
1593 moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto with ay have "False" by simp}
1594 moreover {assume "y \<in> ?xM" hence "y \<ge> ?b" using xMne fxM by auto with yb have "False" by simp}
1595 ultimately show "False" by blast
1597 from ainS binS noy ax xb px show ?thesis by blast
1600 lemma finite_set_intervals2:
1601 assumes px: "P (x::real)"
1602 and lx: "l \<le> x" and xu: "x \<le> u"
1603 and linS: "l\<in> S" and uinS: "u \<in> S"
1604 and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
1605 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)"
1607 from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su]
1608 obtain a and b where
1609 as: "a\<in> S" and bs: "b\<in> S" and noS:"\<forall>y. a < y \<and> y < b \<longrightarrow> y \<notin> S" and axb: "a \<le> x \<and> x \<le> b \<and> P x" by auto
1610 from axb have "x= a \<or> x= b \<or> (a < x \<and> x < b)" by auto
1611 thus ?thesis using px as bs noS by blast
1615 assumes lp: "isrlfm p"
1616 and nmi: "\<not> (Ifm (x#bs) (minusinf p))" (is "\<not> (Ifm (x#bs) (?M p))")
1617 and npi: "\<not> (Ifm (x#bs) (plusinf p))" (is "\<not> (Ifm (x#bs) (?P p))")
1618 and ex: "\<exists> x. Ifm (x#bs) p" (is "\<exists> x. ?I x p")
1619 shows "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). ?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p"
1621 let ?N = "\<lambda> x t. Inum (x#bs) t"
1622 let ?U = "set (uset p)"
1623 from ex obtain a where pa: "?I a p" by blast
1624 from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi
1625 have nmi': "\<not> (?I a (?M p))" by simp
1626 from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi
1627 have npi': "\<not> (?I a (?P p))" by simp
1628 have "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). ?I ((?N a l/real n + ?N a s /real m) / 2) p"
1630 let ?M = "(\<lambda> (t,c). ?N a t / real c) ` ?U"
1631 have fM: "finite ?M" by auto
1632 from rminusinf_uset[OF lp nmi pa] rplusinf_uset[OF lp npi pa]
1633 have "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). a \<le> ?N x l / real n \<and> a \<ge> ?N x s / real m" by blast
1634 then obtain "t" "n" "s" "m" where
1635 tnU: "(t,n) \<in> ?U" and smU: "(s,m) \<in> ?U"
1636 and xs1: "a \<le> ?N x s / real m" and tx1: "a \<ge> ?N x t / real n" by blast
1637 from uset_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 have xs: "a \<le> ?N a s / real m" and tx: "a \<ge> ?N a t / real n" by auto
1638 from tnU have Mne: "?M \<noteq> {}" by auto
1639 hence Une: "?U \<noteq> {}" by simp
1642 have linM: "?l \<in> ?M" using fM Mne by simp
1643 have uinM: "?u \<in> ?M" using fM Mne by simp
1644 have tnM: "?N a t / real n \<in> ?M" using tnU by auto
1645 have smM: "?N a s / real m \<in> ?M" using smU by auto
1646 have lM: "\<forall> t\<in> ?M. ?l \<le> t" using Mne fM by auto
1647 have Mu: "\<forall> t\<in> ?M. t \<le> ?u" using Mne fM by auto
1648 have "?l \<le> ?N a t / real n" using tnM Mne by simp hence lx: "?l \<le> a" using tx by simp
1649 have "?N a s / real m \<le> ?u" using smM Mne by simp hence xu: "a \<le> ?u" using xs by simp
1650 from finite_set_intervals2[where P="\<lambda> x. ?I x p",OF pa lx xu linM uinM fM lM Mu]
1651 have "(\<exists> s\<in> ?M. ?I s p) \<or>
1652 (\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p)" .
1653 moreover { fix u assume um: "u\<in> ?M" and pu: "?I u p"
1654 hence "\<exists> (tu,nu) \<in> ?U. u = ?N a tu / real nu" by auto
1655 then obtain "tu" "nu" where tuU: "(tu,nu) \<in> ?U" and tuu:"u= ?N a tu / real nu" by blast
1656 have "(u + u) / 2 = u" by auto with pu tuu
1657 have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp
1658 with tuU have ?thesis by blast}
1660 assume "\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p"
1661 then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M"
1662 and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p"
1664 from t1M have "\<exists> (t1u,t1n) \<in> ?U. t1 = ?N a t1u / real t1n" by auto
1665 then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \<in> ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast
1666 from t2M have "\<exists> (t2u,t2n) \<in> ?U. t2 = ?N a t2u / real t2n" by auto
1667 then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \<in> ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast
1668 from t1x xt2 have t1t2: "t1 < t2" by simp
1669 let ?u = "(t1 + t2) / 2"
1670 from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
1671 from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
1672 with t1uU t2uU t1u t2u have ?thesis by blast}
1673 ultimately show ?thesis by blast
1675 then obtain "l" "n" "s" "m" where lnU: "(l,n) \<in> ?U" and smU:"(s,m) \<in> ?U"
1676 and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast
1677 from lnU smU uset_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto
1678 from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"]
1679 numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
1680 have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp
1682 show ?thesis by auto
1684 (* The Ferrante - Rackoff Theorem *)
1687 assumes lp: "isrlfm p"
1688 shows "(\<exists> x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \<or> (Ifm (x#bs) (plusinf p)) \<or> (\<exists> (t,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). Ifm ((((Inum (x#bs) t)/ real n + (Inum (x#bs) s) / real m) /2)#bs) p))"
1689 (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
1691 assume px: "\<exists> x. ?I x p"
1692 have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
1693 moreover {assume "?M \<or> ?P" hence "?D" by blast}
1694 moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
1695 from rinf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast}
1696 ultimately show "?D" by blast
1699 moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .}
1700 moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . }
1701 moreover {assume f:"?F" hence "?E" by blast}
1702 ultimately show "?E" by blast
1707 assumes lp: "isrlfm p"
1708 shows "(\<exists> x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \<or> (Ifm (x#bs) (plusinf p)) \<or> (\<exists> (t,k) \<in> set (uset p). \<exists> (s,l) \<in> set (uset p). Ifm (x#bs) (usubst p (Add(Mul l t) (Mul k s) , 2*k*l))))"
1709 (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
1711 assume px: "\<exists> x. ?I x p"
1712 have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
1713 moreover {assume "?M \<or> ?P" hence "?D" by blast}
1714 moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
1715 let ?f ="\<lambda> (t,n). Inum (x#bs) t / real n"
1716 let ?N = "\<lambda> t. Inum (x#bs) t"
1717 {fix t n s m assume "(t,n)\<in> set (uset p)" and "(s,m) \<in> set (uset p)"
1718 with uset_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0"
1720 let ?st = "Add (Mul m t) (Mul n s)"
1721 from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0"
1722 by (simp add: mult_commute)
1723 from tnb snb have st_nb: "numbound0 ?st" by simp
1724 have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
1725 using mnp mp np by (simp add: algebra_simps add_divide_distrib)
1726 from usubst_I[OF lp mnp st_nb, where x="x" and bs="bs"]
1727 have "?I x (usubst p (?st,2*n*m)) = ?I ((?N t / real n + ?N s / real m) /2) p" by (simp only: st[symmetric])}
1728 with rinf_uset[OF lp nmi npi px] have "?F" by blast hence "?D" by blast}
1729 ultimately show "?D" by blast
1732 moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .}
1733 moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . }
1734 moreover {fix t k s l assume "(t,k) \<in> set (uset p)" and "(s,l) \<in> set (uset p)"
1735 and px:"?I x (usubst p (Add (Mul l t) (Mul k s), 2*k*l))"
1736 with uset_l[OF lp] have tnb: "numbound0 t" and np:"real k > 0" and snb: "numbound0 s" and mp:"real l > 0" by auto
1737 let ?st = "Add (Mul l t) (Mul k s)"
1738 from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0"
1739 by (simp add: mult_commute)
1740 from tnb snb have st_nb: "numbound0 ?st" by simp
1741 from usubst_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto}
1742 ultimately show "?E" by blast
1746 (* Implement the right hand side of Ferrante and Rackoff's Theorem. *)
1747 definition ferrack :: "fm \<Rightarrow> fm" where
1748 "ferrack p = (let p' = rlfm (simpfm p); mp = minusinf p'; pp = plusinf p'
1749 in if (mp = T \<or> pp = T) then T else
1750 (let U = remdups(map simp_num_pair
1751 (map (\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m))
1752 (alluopairs (uset p'))))
1753 in decr (disj mp (disj pp (evaldjf (simpfm o (usubst p')) U)))))"
1755 lemma uset_cong_aux:
1756 assumes Ul: "\<forall> (t,n) \<in> set U. numbound0 t \<and> n >0"
1757 shows "((\<lambda> (t,n). Inum (x#bs) t /real n) ` (set (map (\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) (alluopairs U)))) = ((\<lambda> ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (set U \<times> set U))"
1761 assume "((t,n),(s,m)) \<in> set (alluopairs U)"
1762 hence th: "((t,n),(s,m)) \<in> (set U \<times> set U)"
1763 using alluopairs_set1[where xs="U"] by blast
1764 let ?N = "\<lambda> t. Inum (x#bs) t"
1765 let ?st= "Add (Mul m t) (Mul n s)"
1766 from Ul th have mnz: "m \<noteq> 0" by auto
1767 from Ul th have nnz: "n \<noteq> 0" by auto
1768 have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
1769 using mnz nnz by (simp add: algebra_simps add_divide_distrib)
1771 thus "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) /
1772 (2 * real n * real m)
1773 \<in> (\<lambda>((t, n), s, m).
1774 (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) `
1775 (set U \<times> set U)"using mnz nnz th
1776 apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def)
1777 by (rule_tac x="(s,m)" in bexI,simp_all)
1778 (rule_tac x="(t,n)" in bexI,simp_all)
1781 assume tnU: "(t,n) \<in> set U" and smU:"(s,m) \<in> set U"
1782 let ?N = "\<lambda> t. Inum (x#bs) t"
1783 let ?st= "Add (Mul m t) (Mul n s)"
1784 from Ul smU have mnz: "m \<noteq> 0" by auto
1785 from Ul tnU have nnz: "n \<noteq> 0" by auto
1786 have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
1787 using mnz nnz by (simp add: algebra_simps add_divide_distrib)
1788 let ?P = "\<lambda> (t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2"
1789 have Pc:"\<forall> a b. ?P a b = ?P b a"
1791 from Ul alluopairs_set1 have Up:"\<forall> ((t,n),(s,m)) \<in> set (alluopairs U). n \<noteq> 0 \<and> m \<noteq> 0" by blast
1792 from alluopairs_ex[OF Pc, where xs="U"] tnU smU
1793 have th':"\<exists> ((t',n'),(s',m')) \<in> set (alluopairs U). ?P (t',n') (s',m')"
1795 then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \<in> set (alluopairs U)"
1796 and Pts': "?P (t',n') (s',m')" by blast
1797 from ts'_U Up have mnz': "m' \<noteq> 0" and nnz': "n'\<noteq> 0" by auto
1798 let ?st' = "Add (Mul m' t') (Mul n' s')"
1799 have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')"
1800 using mnz' nnz' by (simp add: algebra_simps add_divide_distrib)
1802 "(Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" by simp
1803 also have "\<dots> = ((\<lambda>(t, n). Inum (x # bs) t / real n) ((\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t',n'),(s',m'))))" by (simp add: st')
1804 finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2
1805 \<in> (\<lambda>(t, n). Inum (x # bs) t / real n) `
1806 (\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) `
1808 using ts'_U by blast
1812 assumes lp: "isrlfm p"
1813 and UU': "((\<lambda> (t,n). Inum (x#bs) t /real n) ` U') = ((\<lambda> ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (U \<times> U))" (is "?f ` U' = ?g ` (U\<times>U)")
1814 and U: "\<forall> (t,n) \<in> U. numbound0 t \<and> n > 0"
1815 and U': "\<forall> (t,n) \<in> U'. numbound0 t \<and> n > 0"
1816 shows "(\<exists> (t,n) \<in> U. \<exists> (s,m) \<in> U. Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))) = (\<exists> (t,n) \<in> U'. Ifm (x#bs) (usubst p (t,n)))"
1820 then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and
1821 Pst: "Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))" by blast
1822 let ?N = "\<lambda> t. Inum (x#bs) t"
1823 from tnU smU U have tnb: "numbound0 t" and np: "n > 0"
1824 and snb: "numbound0 s" and mp:"m > 0" by auto
1825 let ?st= "Add (Mul m t) (Mul n s)"
1826 from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0"
1827 by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult)
1828 from tnb snb have stnb: "numbound0 ?st" by simp
1829 have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
1830 using mp np by (simp add: algebra_simps add_divide_distrib)
1831 from tnU smU UU' have "?g ((t,n),(s,m)) \<in> ?f ` U'" by blast
1832 hence "\<exists> (t',n') \<in> U'. ?g ((t,n),(s,m)) = ?f (t',n')"
1833 by auto (rule_tac x="(a,b)" in bexI, auto)
1834 then obtain t' n' where tnU': "(t',n') \<in> U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast
1835 from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto
1836 from usubst_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst
1837 have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp
1838 from conjunct1[OF usubst_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]]
1839 have "Ifm (x # bs) (usubst p (t', n')) " by (simp only: st)
1840 then show ?rhs using tnU' by auto
1843 then obtain t' n' where tnU': "(t',n') \<in> U'" and Pt': "Ifm (x # bs) (usubst p (t', n'))"
1845 from tnU' UU' have "?f (t',n') \<in> ?g ` (U\<times>U)" by blast
1846 hence "\<exists> ((t,n),(s,m)) \<in> (U\<times>U). ?f (t',n') = ?g ((t,n),(s,m))"
1847 by auto (rule_tac x="(a,b)" in bexI, auto)
1848 then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and
1849 th: "?f (t',n') = ?g((t,n),(s,m)) "by blast
1850 let ?N = "\<lambda> t. Inum (x#bs) t"
1851 from tnU smU U have tnb: "numbound0 t" and np: "n > 0"
1852 and snb: "numbound0 s" and mp:"m > 0" by auto
1853 let ?st= "Add (Mul m t) (Mul n s)"
1854 from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0"
1855 by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult)
1856 from tnb snb have stnb: "numbound0 ?st" by simp
1857 have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
1858 using mp np by (simp add: algebra_simps add_divide_distrib)
1859 from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto
1860 from usubst_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt'
1861 have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp
1862 with usubst_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast
1866 assumes qf: "qfree p"
1867 shows "qfree (ferrack p) \<and> ((Ifm bs (ferrack p)) = (\<exists> x. Ifm (x#bs) p))"
1868 (is "_ \<and> (?rhs = ?lhs)")
1870 let ?I = "\<lambda> x p. Ifm (x#bs) p"
1872 let ?N = "\<lambda> t. Inum (x#bs) t"
1873 let ?q = "rlfm (simpfm p)"
1875 let ?Up = "alluopairs ?U"
1876 let ?g = "\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)"
1877 let ?S = "map ?g ?Up"
1878 let ?SS = "map simp_num_pair ?S"
1879 let ?Y = "remdups ?SS"
1880 let ?f= "(\<lambda> (t,n). ?N t / real n)"
1881 let ?h = "\<lambda> ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2"
1882 let ?F = "\<lambda> p. \<exists> a \<in> set (uset p). \<exists> b \<in> set (uset p). ?I x (usubst p (?g(a,b)))"
1883 let ?ep = "evaldjf (simpfm o (usubst ?q)) ?Y"
1884 from rlfm_I[OF simpfm_qf[OF qf]] have lq: "isrlfm ?q" by blast
1885 from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \<le> (set ?U \<times> set ?U)" by simp
1886 from uset_l[OF lq] have U_l: "\<forall> (t,n) \<in> set ?U. numbound0 t \<and> n > 0" .
1888 have "\<forall> ((t,n),(s,m)) \<in> set ?Up. numbound0 t \<and> n> 0 \<and> numbound0 s \<and> m > 0" by auto
1889 hence Snb: "\<forall> (t,n) \<in> set ?S. numbound0 t \<and> n > 0 "
1890 by (auto simp add: mult_pos_pos)
1891 have Y_l: "\<forall> (t,n) \<in> set ?Y. numbound0 t \<and> n > 0"
1893 { fix t n assume tnY: "(t,n) \<in> set ?Y"
1894 hence "(t,n) \<in> set ?SS" by simp
1895 hence "\<exists> (t',n') \<in> set ?S. simp_num_pair (t',n') = (t,n)"
1896 by (auto simp add: split_def simp del: map_map)
1897 (rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all)
1898 then obtain t' n' where tn'S: "(t',n') \<in> set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast
1899 from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto
1900 from simp_num_pair_l[OF tnb np tns]
1901 have "numbound0 t \<and> n > 0" . }
1902 thus ?thesis by blast
1905 have YU: "(?f ` set ?Y) = (?h ` (set ?U \<times> set ?U))"
1907 from simp_num_pair_ci[where bs="x#bs"] have
1908 "\<forall>x. (?f o simp_num_pair) x = ?f x" by auto
1909 hence th: "?f o simp_num_pair = ?f" using ext by blast
1910 have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose)
1911 also have "\<dots> = (?f ` set ?S)" by (simp add: th)
1912 also have "\<dots> = ((?f o ?g) ` set ?Up)"
1913 by (simp only: set_map o_def image_compose[symmetric])
1914 also have "\<dots> = (?h ` (set ?U \<times> set ?U))"
1915 using uset_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast
1916 finally show ?thesis .
1918 have "\<forall> (t,n) \<in> set ?Y. bound0 (simpfm (usubst ?q (t,n)))"
1920 { fix t n assume tnY: "(t,n) \<in> set ?Y"
1921 with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto
1922 from usubst_I[OF lq np tnb]
1923 have "bound0 (usubst ?q (t,n))" by simp hence "bound0 (simpfm (usubst ?q (t,n)))"
1924 using simpfm_bound0 by simp}
1925 thus ?thesis by blast
1927 hence ep_nb: "bound0 ?ep" using evaldjf_bound0[where xs="?Y" and f="simpfm o (usubst ?q)"] by auto
1928 let ?mp = "minusinf ?q"
1929 let ?pp = "plusinf ?q"
1932 let ?res = "disj ?mp (disj ?pp ?ep)"
1933 from rminusinf_bound0[OF lq] rplusinf_bound0[OF lq] ep_nb
1934 have nbth: "bound0 ?res" by auto
1936 from conjunct1[OF rlfm_I[OF simpfm_qf[OF qf]]] simpfm
1938 have th: "?lhs = (\<exists> x. ?I x ?q)" by auto
1939 from th fr_equsubst[OF lq, where bs="bs" and x="x"] have lhfr: "?lhs = (?M \<or> ?P \<or> ?F ?q)"
1940 by (simp only: split_def fst_conv snd_conv)
1941 also have "\<dots> = (?M \<or> ?P \<or> (\<exists> (t,n) \<in> set ?Y. ?I x (simpfm (usubst ?q (t,n)))))"
1942 using uset_cong[OF lq YU U_l Y_l] by (simp only: split_def fst_conv snd_conv simpfm)
1943 also have "\<dots> = (Ifm (x#bs) ?res)"
1944 using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="simpfm o (usubst ?q)",symmetric]
1945 by (simp add: split_def pair_collapse)
1946 finally have lheq: "?lhs = (Ifm bs (decr ?res))" using decr[OF nbth] by blast
1947 hence lr: "?lhs = ?rhs" apply (unfold ferrack_def Let_def)
1948 by (cases "?mp = T \<or> ?pp = T", auto) (simp add: disj_def)+
1949 from decr_qf[OF nbth] have "qfree (ferrack p)" by (auto simp add: Let_def ferrack_def)
1950 with lr show ?thesis by blast
1953 definition linrqe:: "fm \<Rightarrow> fm" where
1954 "linrqe p = qelim (prep p) ferrack"
1956 theorem linrqe: "Ifm bs (linrqe p) = Ifm bs p \<and> qfree (linrqe p)"
1957 using ferrack qelim_ci prep
1958 unfolding linrqe_def by auto
1960 definition ferrack_test :: "unit \<Rightarrow> fm" where
1961 "ferrack_test u = linrqe (A (A (Imp (Lt (Sub (Bound 1) (Bound 0)))
1962 (E (Eq (Sub (Add (Bound 0) (Bound 2)) (Bound 1)))))))"
1964 ML {* @{code ferrack_test} () *}
1966 oracle linr_oracle = {*
1969 fun num_of_term vs (Free vT) = @{code Bound} (find_index (fn vT' => vT = vT') vs)
1970 | num_of_term vs @{term "real (0::int)"} = @{code C} 0
1971 | num_of_term vs @{term "real (1::int)"} = @{code C} 1
1972 | num_of_term vs @{term "0::real"} = @{code C} 0
1973 | num_of_term vs @{term "1::real"} = @{code C} 1
1974 | num_of_term vs (Bound i) = @{code Bound} i
1975 | num_of_term vs (@{term "uminus :: real \<Rightarrow> real"} $ t') = @{code Neg} (num_of_term vs t')
1976 | num_of_term vs (@{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) =
1977 @{code Add} (num_of_term vs t1, num_of_term vs t2)
1978 | num_of_term vs (@{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) =
1979 @{code Sub} (num_of_term vs t1, num_of_term vs t2)
1980 | num_of_term vs (@{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = (case num_of_term vs t1
1981 of @{code C} i => @{code Mul} (i, num_of_term vs t2)
1982 | _ => error "num_of_term: unsupported multiplication")
1983 | num_of_term vs (@{term "real :: int \<Rightarrow> real"} $ (@{term "number_of :: int \<Rightarrow> int"} $ t')) =
1984 @{code C} (HOLogic.dest_numeral t')
1985 | num_of_term vs (@{term "number_of :: int \<Rightarrow> real"} $ t') =
1986 @{code C} (HOLogic.dest_numeral t')
1987 | num_of_term vs t = error ("num_of_term: unknown term");
1989 fun fm_of_term vs @{term True} = @{code T}
1990 | fm_of_term vs @{term False} = @{code F}
1991 | fm_of_term vs (@{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
1992 @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2))
1993 | fm_of_term vs (@{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
1994 @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2))
1995 | fm_of_term vs (@{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
1996 @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2))
1997 | fm_of_term vs (@{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ t1 $ t2) =
1998 @{code Iff} (fm_of_term vs t1, fm_of_term vs t2)
1999 | fm_of_term vs (@{term "op &"} $ t1 $ t2) = @{code And} (fm_of_term vs t1, fm_of_term vs t2)
2000 | fm_of_term vs (@{term "op |"} $ t1 $ t2) = @{code Or} (fm_of_term vs t1, fm_of_term vs t2)
2001 | fm_of_term vs (@{term HOL.implies} $ t1 $ t2) = @{code Imp} (fm_of_term vs t1, fm_of_term vs t2)
2002 | fm_of_term vs (@{term "Not"} $ t') = @{code NOT} (fm_of_term vs t')
2003 | fm_of_term vs (Const (@{const_name Ex}, _) $ Abs (xn, xT, p)) =
2004 @{code E} (fm_of_term (("", dummyT) :: vs) p)
2005 | fm_of_term vs (Const (@{const_name All}, _) $ Abs (xn, xT, p)) =
2006 @{code A} (fm_of_term (("", dummyT) :: vs) p)
2007 | fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t);
2009 fun term_of_num vs (@{code C} i) = @{term "real :: int \<Rightarrow> real"} $ HOLogic.mk_number HOLogic.intT i
2010 | term_of_num vs (@{code Bound} n) = Free (nth vs n)
2011 | term_of_num vs (@{code Neg} t') = @{term "uminus :: real \<Rightarrow> real"} $ term_of_num vs t'
2012 | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $
2013 term_of_num vs t1 $ term_of_num vs t2
2014 | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $
2015 term_of_num vs t1 $ term_of_num vs t2
2016 | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $
2017 term_of_num vs (@{code C} i) $ term_of_num vs t2
2018 | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t));
2020 fun term_of_fm vs @{code T} = HOLogic.true_const
2021 | term_of_fm vs @{code F} = HOLogic.false_const
2022 | term_of_fm vs (@{code Lt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $
2023 term_of_num vs t $ @{term "0::real"}
2024 | term_of_fm vs (@{code Le} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $
2025 term_of_num vs t $ @{term "0::real"}
2026 | term_of_fm vs (@{code Gt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $
2027 @{term "0::real"} $ term_of_num vs t
2028 | term_of_fm vs (@{code Ge} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $
2029 @{term "0::real"} $ term_of_num vs t
2030 | term_of_fm vs (@{code Eq} t) = @{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $
2031 term_of_num vs t $ @{term "0::real"}
2032 | term_of_fm vs (@{code NEq} t) = term_of_fm vs (@{code NOT} (@{code Eq} t))
2033 | term_of_fm vs (@{code NOT} t') = HOLogic.Not $ term_of_fm vs t'
2034 | term_of_fm vs (@{code And} (t1, t2)) = HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2
2035 | term_of_fm vs (@{code Or} (t1, t2)) = HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2
2036 | term_of_fm vs (@{code Imp} (t1, t2)) = HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2
2037 | term_of_fm vs (@{code Iff} (t1, t2)) = @{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $
2038 term_of_fm vs t1 $ term_of_fm vs t2;
2042 val vs = Term.add_frees t [];
2043 val t' = (term_of_fm vs o @{code linrqe} o fm_of_term vs) t;
2044 in (Thm.cterm_of (ProofContext.theory_of ctxt) o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
2048 use "ferrack_tac.ML"
2049 setup Ferrack_Tac.setup
2053 shows "2 * x \<le> 2 * x \<and> 2 * x \<le> 2 * x + 1"
2059 shows "\<exists>y \<le> x. x = y + 1"
2065 shows "\<not> (\<exists>z. x + z = x + z + 1)"