author | huffman |
Wed, 17 Aug 2011 14:32:48 -0700 | |
changeset 44256 | c478cd500dc4 |
parent 44013 | 5cfc1c36ae97 |
child 44779 | 98d597c4193d |
permissions | -rw-r--r-- |
30439 | 1 |
(* Title: HOL/Decision_Procs/Ferrack.thy |
29789 | 2 |
Author: Amine Chaieb |
3 |
*) |
|
4 |
||
5 |
theory Ferrack |
|
41849 | 6 |
imports Complex_Main Dense_Linear_Order DP_Library |
44013
5cfc1c36ae97
moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents:
42361
diff
changeset
|
7 |
"~~/src/HOL/Library/Efficient_Nat" "~~/src/HOL/Library/Old_Recdef" |
29789 | 8 |
uses ("ferrack_tac.ML") |
9 |
begin |
|
10 |
||
11 |
section {* Quantifier elimination for @{text "\<real> (0, 1, +, <)"} *} |
|
12 |
||
13 |
(*********************************************************************************) |
|
14 |
(**** SHADOW SYNTAX AND SEMANTICS ****) |
|
15 |
(*********************************************************************************) |
|
16 |
||
17 |
datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num |
|
18 |
| Mul int num |
|
19 |
||
20 |
(* A size for num to make inductive proofs simpler*) |
|
36853 | 21 |
primrec num_size :: "num \<Rightarrow> nat" where |
29789 | 22 |
"num_size (C c) = 1" |
36853 | 23 |
| "num_size (Bound n) = 1" |
24 |
| "num_size (Neg a) = 1 + num_size a" |
|
25 |
| "num_size (Add a b) = 1 + num_size a + num_size b" |
|
26 |
| "num_size (Sub a b) = 3 + num_size a + num_size b" |
|
27 |
| "num_size (Mul c a) = 1 + num_size a" |
|
28 |
| "num_size (CN n c a) = 3 + num_size a " |
|
29789 | 29 |
|
30 |
(* Semantics of numeral terms (num) *) |
|
36853 | 31 |
primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where |
29789 | 32 |
"Inum bs (C c) = (real c)" |
36853 | 33 |
| "Inum bs (Bound n) = bs!n" |
34 |
| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)" |
|
35 |
| "Inum bs (Neg a) = -(Inum bs a)" |
|
36 |
| "Inum bs (Add a b) = Inum bs a + Inum bs b" |
|
37 |
| "Inum bs (Sub a b) = Inum bs a - Inum bs b" |
|
38 |
| "Inum bs (Mul c a) = (real c) * Inum bs a" |
|
29789 | 39 |
(* FORMULAE *) |
40 |
datatype fm = |
|
41 |
T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| |
|
42 |
NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm |
|
43 |
||
44 |
||
45 |
(* A size for fm *) |
|
36853 | 46 |
fun fmsize :: "fm \<Rightarrow> nat" where |
29789 | 47 |
"fmsize (NOT p) = 1 + fmsize p" |
36853 | 48 |
| "fmsize (And p q) = 1 + fmsize p + fmsize q" |
49 |
| "fmsize (Or p q) = 1 + fmsize p + fmsize q" |
|
50 |
| "fmsize (Imp p q) = 3 + fmsize p + fmsize q" |
|
51 |
| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" |
|
52 |
| "fmsize (E p) = 1 + fmsize p" |
|
53 |
| "fmsize (A p) = 4+ fmsize p" |
|
54 |
| "fmsize p = 1" |
|
29789 | 55 |
(* several lemmas about fmsize *) |
56 |
lemma fmsize_pos: "fmsize p > 0" |
|
57 |
by (induct p rule: fmsize.induct) simp_all |
|
58 |
||
59 |
(* Semantics of formulae (fm) *) |
|
36853 | 60 |
primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where |
29789 | 61 |
"Ifm bs T = True" |
36853 | 62 |
| "Ifm bs F = False" |
63 |
| "Ifm bs (Lt a) = (Inum bs a < 0)" |
|
64 |
| "Ifm bs (Gt a) = (Inum bs a > 0)" |
|
65 |
| "Ifm bs (Le a) = (Inum bs a \<le> 0)" |
|
66 |
| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)" |
|
67 |
| "Ifm bs (Eq a) = (Inum bs a = 0)" |
|
68 |
| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)" |
|
69 |
| "Ifm bs (NOT p) = (\<not> (Ifm bs p))" |
|
70 |
| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)" |
|
71 |
| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)" |
|
72 |
| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))" |
|
73 |
| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)" |
|
74 |
| "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)" |
|
75 |
| "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)" |
|
29789 | 76 |
|
77 |
lemma IfmLeSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Le (Sub s t)) = (s' \<le> t')" |
|
78 |
apply simp |
|
79 |
done |
|
80 |
||
81 |
lemma IfmLtSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Lt (Sub s t)) = (s' < t')" |
|
82 |
apply simp |
|
83 |
done |
|
84 |
lemma IfmEqSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Eq (Sub s t)) = (s' = t')" |
|
85 |
apply simp |
|
86 |
done |
|
87 |
lemma IfmNOT: " (Ifm bs p = P) \<Longrightarrow> (Ifm bs (NOT p) = (\<not>P))" |
|
88 |
apply simp |
|
89 |
done |
|
90 |
lemma IfmAnd: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (And p q) = (P \<and> Q))" |
|
91 |
apply simp |
|
92 |
done |
|
93 |
lemma IfmOr: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Or p q) = (P \<or> Q))" |
|
94 |
apply simp |
|
95 |
done |
|
96 |
lemma IfmImp: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Imp p q) = (P \<longrightarrow> Q))" |
|
97 |
apply simp |
|
98 |
done |
|
99 |
lemma IfmIff: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Iff p q) = (P = Q))" |
|
100 |
apply simp |
|
101 |
done |
|
102 |
||
103 |
lemma IfmE: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (E p) = (\<exists>x. P x))" |
|
104 |
apply simp |
|
105 |
done |
|
106 |
lemma IfmA: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (A p) = (\<forall>x. P x))" |
|
107 |
apply simp |
|
108 |
done |
|
109 |
||
36853 | 110 |
fun not:: "fm \<Rightarrow> fm" where |
29789 | 111 |
"not (NOT p) = p" |
36853 | 112 |
| "not T = F" |
113 |
| "not F = T" |
|
114 |
| "not p = NOT p" |
|
29789 | 115 |
lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)" |
116 |
by (cases p) auto |
|
117 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
118 |
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 119 |
"conj p q = (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else |
29789 | 120 |
if p = q then p else And p q)" |
121 |
lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)" |
|
122 |
by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all) |
|
123 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
124 |
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 125 |
"disj p q = (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p |
29789 | 126 |
else if p=q then p else Or p q)" |
127 |
||
128 |
lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)" |
|
129 |
by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all) |
|
130 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
131 |
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 132 |
"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 |
29789 | 133 |
else Imp p q)" |
134 |
lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)" |
|
135 |
by (cases "p=F \<or> q=T",simp_all add: imp_def) |
|
136 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
137 |
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 138 |
"iff p q = (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else |
29789 | 139 |
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 |
140 |
Iff p q)" |
|
141 |
lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)" |
|
142 |
by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto) |
|
143 |
||
144 |
lemma conj_simps: |
|
145 |
"conj F Q = F" |
|
146 |
"conj P F = F" |
|
147 |
"conj T Q = Q" |
|
148 |
"conj P T = P" |
|
149 |
"conj P P = P" |
|
150 |
"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" |
|
151 |
by (simp_all add: conj_def) |
|
152 |
||
153 |
lemma disj_simps: |
|
154 |
"disj T Q = T" |
|
155 |
"disj P T = T" |
|
156 |
"disj F Q = Q" |
|
157 |
"disj P F = P" |
|
158 |
"disj P P = P" |
|
159 |
"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" |
|
160 |
by (simp_all add: disj_def) |
|
161 |
lemma imp_simps: |
|
162 |
"imp F Q = T" |
|
163 |
"imp P T = T" |
|
164 |
"imp T Q = Q" |
|
165 |
"imp P F = not P" |
|
166 |
"imp P P = T" |
|
167 |
"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" |
|
168 |
by (simp_all add: imp_def) |
|
169 |
lemma trivNOT: "p \<noteq> NOT p" "NOT p \<noteq> p" |
|
170 |
apply (induct p, auto) |
|
171 |
done |
|
172 |
||
173 |
lemma iff_simps: |
|
174 |
"iff p p = T" |
|
175 |
"iff p (NOT p) = F" |
|
176 |
"iff (NOT p) p = F" |
|
177 |
"iff p F = not p" |
|
178 |
"iff F p = not p" |
|
179 |
"p \<noteq> NOT T \<Longrightarrow> iff T p = p" |
|
180 |
"p\<noteq> NOT T \<Longrightarrow> iff p T = p" |
|
181 |
"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" |
|
182 |
using trivNOT |
|
183 |
by (simp_all add: iff_def, cases p, auto) |
|
184 |
(* Quantifier freeness *) |
|
36853 | 185 |
fun qfree:: "fm \<Rightarrow> bool" where |
29789 | 186 |
"qfree (E p) = False" |
36853 | 187 |
| "qfree (A p) = False" |
188 |
| "qfree (NOT p) = qfree p" |
|
189 |
| "qfree (And p q) = (qfree p \<and> qfree q)" |
|
190 |
| "qfree (Or p q) = (qfree p \<and> qfree q)" |
|
191 |
| "qfree (Imp p q) = (qfree p \<and> qfree q)" |
|
192 |
| "qfree (Iff p q) = (qfree p \<and> qfree q)" |
|
193 |
| "qfree p = True" |
|
29789 | 194 |
|
195 |
(* Boundedness and substitution *) |
|
36853 | 196 |
primrec numbound0:: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where |
29789 | 197 |
"numbound0 (C c) = True" |
36853 | 198 |
| "numbound0 (Bound n) = (n>0)" |
199 |
| "numbound0 (CN n c a) = (n\<noteq>0 \<and> numbound0 a)" |
|
200 |
| "numbound0 (Neg a) = numbound0 a" |
|
201 |
| "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)" |
|
202 |
| "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" |
|
203 |
| "numbound0 (Mul i a) = numbound0 a" |
|
204 |
||
29789 | 205 |
lemma numbound0_I: |
206 |
assumes nb: "numbound0 a" |
|
207 |
shows "Inum (b#bs) a = Inum (b'#bs) a" |
|
208 |
using nb |
|
41842 | 209 |
by (induct a) simp_all |
29789 | 210 |
|
36853 | 211 |
primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where |
29789 | 212 |
"bound0 T = True" |
36853 | 213 |
| "bound0 F = True" |
214 |
| "bound0 (Lt a) = numbound0 a" |
|
215 |
| "bound0 (Le a) = numbound0 a" |
|
216 |
| "bound0 (Gt a) = numbound0 a" |
|
217 |
| "bound0 (Ge a) = numbound0 a" |
|
218 |
| "bound0 (Eq a) = numbound0 a" |
|
219 |
| "bound0 (NEq a) = numbound0 a" |
|
220 |
| "bound0 (NOT p) = bound0 p" |
|
221 |
| "bound0 (And p q) = (bound0 p \<and> bound0 q)" |
|
222 |
| "bound0 (Or p q) = (bound0 p \<and> bound0 q)" |
|
223 |
| "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))" |
|
224 |
| "bound0 (Iff p q) = (bound0 p \<and> bound0 q)" |
|
225 |
| "bound0 (E p) = False" |
|
226 |
| "bound0 (A p) = False" |
|
29789 | 227 |
|
228 |
lemma bound0_I: |
|
229 |
assumes bp: "bound0 p" |
|
230 |
shows "Ifm (b#bs) p = Ifm (b'#bs) p" |
|
231 |
using bp numbound0_I[where b="b" and bs="bs" and b'="b'"] |
|
41842 | 232 |
by (induct p) auto |
29789 | 233 |
|
234 |
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)" |
|
235 |
by (cases p, auto) |
|
236 |
lemma not_bn[simp]: "bound0 p \<Longrightarrow> bound0 (not p)" |
|
237 |
by (cases p, auto) |
|
238 |
||
239 |
||
240 |
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)" |
|
241 |
using conj_def by auto |
|
242 |
lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)" |
|
243 |
using conj_def by auto |
|
244 |
||
245 |
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)" |
|
246 |
using disj_def by auto |
|
247 |
lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)" |
|
248 |
using disj_def by auto |
|
249 |
||
250 |
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)" |
|
251 |
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def) |
|
252 |
lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)" |
|
253 |
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def) |
|
254 |
||
255 |
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)" |
|
256 |
by (unfold iff_def,cases "p=q", auto) |
|
257 |
lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)" |
|
258 |
using iff_def by (unfold iff_def,cases "p=q", auto) |
|
259 |
||
36853 | 260 |
fun decrnum:: "num \<Rightarrow> num" where |
29789 | 261 |
"decrnum (Bound n) = Bound (n - 1)" |
36853 | 262 |
| "decrnum (Neg a) = Neg (decrnum a)" |
263 |
| "decrnum (Add a b) = Add (decrnum a) (decrnum b)" |
|
264 |
| "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" |
|
265 |
| "decrnum (Mul c a) = Mul c (decrnum a)" |
|
266 |
| "decrnum (CN n c a) = CN (n - 1) c (decrnum a)" |
|
267 |
| "decrnum a = a" |
|
29789 | 268 |
|
36853 | 269 |
fun decr :: "fm \<Rightarrow> fm" where |
29789 | 270 |
"decr (Lt a) = Lt (decrnum a)" |
36853 | 271 |
| "decr (Le a) = Le (decrnum a)" |
272 |
| "decr (Gt a) = Gt (decrnum a)" |
|
273 |
| "decr (Ge a) = Ge (decrnum a)" |
|
274 |
| "decr (Eq a) = Eq (decrnum a)" |
|
275 |
| "decr (NEq a) = NEq (decrnum a)" |
|
276 |
| "decr (NOT p) = NOT (decr p)" |
|
277 |
| "decr (And p q) = conj (decr p) (decr q)" |
|
278 |
| "decr (Or p q) = disj (decr p) (decr q)" |
|
279 |
| "decr (Imp p q) = imp (decr p) (decr q)" |
|
280 |
| "decr (Iff p q) = iff (decr p) (decr q)" |
|
281 |
| "decr p = p" |
|
29789 | 282 |
|
283 |
lemma decrnum: assumes nb: "numbound0 t" |
|
284 |
shows "Inum (x#bs) t = Inum bs (decrnum t)" |
|
41842 | 285 |
using nb by (induct t rule: decrnum.induct, simp_all) |
29789 | 286 |
|
287 |
lemma decr: assumes nb: "bound0 p" |
|
288 |
shows "Ifm (x#bs) p = Ifm bs (decr p)" |
|
289 |
using nb |
|
41842 | 290 |
by (induct p rule: decr.induct, simp_all add: decrnum) |
29789 | 291 |
|
292 |
lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)" |
|
293 |
by (induct p, simp_all) |
|
294 |
||
36853 | 295 |
fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) where |
29789 | 296 |
"isatom T = True" |
36853 | 297 |
| "isatom F = True" |
298 |
| "isatom (Lt a) = True" |
|
299 |
| "isatom (Le a) = True" |
|
300 |
| "isatom (Gt a) = True" |
|
301 |
| "isatom (Ge a) = True" |
|
302 |
| "isatom (Eq a) = True" |
|
303 |
| "isatom (NEq a) = True" |
|
304 |
| "isatom p = False" |
|
29789 | 305 |
|
306 |
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p" |
|
307 |
by (induct p, simp_all) |
|
308 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
309 |
definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 310 |
"djf f p q = (if q=T then T else if q=F then f p else |
29789 | 311 |
(let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))" |
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
312 |
definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where |
36853 | 313 |
"evaldjf f ps = foldr (djf f) ps F" |
29789 | 314 |
|
315 |
lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)" |
|
316 |
by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) |
|
317 |
(cases "f p", simp_all add: Let_def djf_def) |
|
318 |
||
319 |
||
320 |
lemma djf_simps: |
|
321 |
"djf f p T = T" |
|
322 |
"djf f p F = f p" |
|
323 |
"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)" |
|
324 |
by (simp_all add: djf_def) |
|
325 |
||
326 |
lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))" |
|
327 |
by(induct ps, simp_all add: evaldjf_def djf_Or) |
|
328 |
||
329 |
lemma evaldjf_bound0: |
|
330 |
assumes nb: "\<forall> x\<in> set xs. bound0 (f x)" |
|
331 |
shows "bound0 (evaldjf f xs)" |
|
332 |
using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) |
|
333 |
||
334 |
lemma evaldjf_qf: |
|
335 |
assumes nb: "\<forall> x\<in> set xs. qfree (f x)" |
|
336 |
shows "qfree (evaldjf f xs)" |
|
337 |
using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) |
|
338 |
||
36853 | 339 |
fun disjuncts :: "fm \<Rightarrow> fm list" where |
340 |
"disjuncts (Or p q) = disjuncts p @ disjuncts q" |
|
341 |
| "disjuncts F = []" |
|
342 |
| "disjuncts p = [p]" |
|
29789 | 343 |
|
344 |
lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p" |
|
345 |
by(induct p rule: disjuncts.induct, auto) |
|
346 |
||
347 |
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q" |
|
348 |
proof- |
|
349 |
assume nb: "bound0 p" |
|
350 |
hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto) |
|
351 |
thus ?thesis by (simp only: list_all_iff) |
|
352 |
qed |
|
353 |
||
354 |
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q" |
|
355 |
proof- |
|
356 |
assume qf: "qfree p" |
|
357 |
hence "list_all qfree (disjuncts p)" |
|
358 |
by (induct p rule: disjuncts.induct, auto) |
|
359 |
thus ?thesis by (simp only: list_all_iff) |
|
360 |
qed |
|
361 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
362 |
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where |
36853 | 363 |
"DJ f p = evaldjf f (disjuncts p)" |
29789 | 364 |
|
365 |
lemma DJ: assumes fdj: "\<forall> p q. Ifm bs (f (Or p q)) = Ifm bs (Or (f p) (f q))" |
|
366 |
and fF: "f F = F" |
|
367 |
shows "Ifm bs (DJ f p) = Ifm bs (f p)" |
|
368 |
proof- |
|
369 |
have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))" |
|
370 |
by (simp add: DJ_def evaldjf_ex) |
|
371 |
also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto) |
|
372 |
finally show ?thesis . |
|
373 |
qed |
|
374 |
||
375 |
lemma DJ_qf: assumes |
|
376 |
fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)" |
|
377 |
shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) " |
|
378 |
proof(clarify) |
|
379 |
fix p assume qf: "qfree p" |
|
380 |
have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def) |
|
381 |
from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" . |
|
382 |
with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast |
|
383 |
||
384 |
from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp |
|
385 |
qed |
|
386 |
||
387 |
lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))" |
|
388 |
shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))" |
|
389 |
proof(clarify) |
|
390 |
fix p::fm and bs |
|
391 |
assume qf: "qfree p" |
|
392 |
from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast |
|
393 |
from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto |
|
394 |
have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))" |
|
395 |
by (simp add: DJ_def evaldjf_ex) |
|
396 |
also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto |
|
397 |
also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto) |
|
398 |
finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast |
|
399 |
qed |
|
400 |
(* Simplification *) |
|
36853 | 401 |
|
402 |
fun maxcoeff:: "num \<Rightarrow> int" where |
|
29789 | 403 |
"maxcoeff (C i) = abs i" |
36853 | 404 |
| "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" |
405 |
| "maxcoeff t = 1" |
|
29789 | 406 |
|
407 |
lemma maxcoeff_pos: "maxcoeff t \<ge> 0" |
|
408 |
by (induct t rule: maxcoeff.induct, auto) |
|
409 |
||
36853 | 410 |
fun numgcdh:: "num \<Rightarrow> int \<Rightarrow> int" where |
31706 | 411 |
"numgcdh (C i) = (\<lambda>g. gcd i g)" |
36853 | 412 |
| "numgcdh (CN n c t) = (\<lambda>g. gcd c (numgcdh t g))" |
413 |
| "numgcdh t = (\<lambda>g. 1)" |
|
414 |
||
415 |
definition numgcd :: "num \<Rightarrow> int" where |
|
416 |
"numgcd t = numgcdh t (maxcoeff t)" |
|
29789 | 417 |
|
36853 | 418 |
fun reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num" where |
29789 | 419 |
"reducecoeffh (C i) = (\<lambda> g. C (i div g))" |
36853 | 420 |
| "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))" |
421 |
| "reducecoeffh t = (\<lambda>g. t)" |
|
29789 | 422 |
|
36853 | 423 |
definition reducecoeff :: "num \<Rightarrow> num" where |
424 |
"reducecoeff t = |
|
29789 | 425 |
(let g = numgcd t in |
426 |
if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)" |
|
427 |
||
36853 | 428 |
fun dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where |
29789 | 429 |
"dvdnumcoeff (C i) = (\<lambda> g. g dvd i)" |
36853 | 430 |
| "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))" |
431 |
| "dvdnumcoeff t = (\<lambda>g. False)" |
|
29789 | 432 |
|
433 |
lemma dvdnumcoeff_trans: |
|
434 |
assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'" |
|
435 |
shows "dvdnumcoeff t g" |
|
436 |
using dgt' gdg |
|
30042 | 437 |
by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg dvd_trans[OF gdg]) |
29789 | 438 |
|
30042 | 439 |
declare dvd_trans [trans add] |
29789 | 440 |
|
441 |
lemma natabs0: "(nat (abs x) = 0) = (x = 0)" |
|
442 |
by arith |
|
443 |
||
444 |
lemma numgcd0: |
|
445 |
assumes g0: "numgcd t = 0" |
|
446 |
shows "Inum bs t = 0" |
|
447 |
using g0[simplified numgcd_def] |
|
32642
026e7c6a6d08
be more cautious wrt. simp rules: inf_absorb1, inf_absorb2, sup_absorb1, sup_absorb2 are no simp rules by default any longer
haftmann
parents:
32441
diff
changeset
|
448 |
by (induct t rule: numgcdh.induct, auto simp add: natabs0 maxcoeff_pos min_max.sup_absorb2) |
29789 | 449 |
|
450 |
lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0" |
|
451 |
using gp |
|
31706 | 452 |
by (induct t rule: numgcdh.induct, auto) |
29789 | 453 |
|
454 |
lemma numgcd_pos: "numgcd t \<ge>0" |
|
455 |
by (simp add: numgcd_def numgcdh_pos maxcoeff_pos) |
|
456 |
||
457 |
lemma reducecoeffh: |
|
458 |
assumes gt: "dvdnumcoeff t g" and gp: "g > 0" |
|
459 |
shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t" |
|
460 |
using gt |
|
41807 | 461 |
proof (induct t rule: reducecoeffh.induct) |
462 |
case (1 i) |
|
463 |
hence gd: "g dvd i" by simp |
|
29789 | 464 |
from gp have gnz: "g \<noteq> 0" by simp |
41807 | 465 |
with assms show ?case by (simp add: real_of_int_div[OF gnz gd]) |
29789 | 466 |
next |
41807 | 467 |
case (2 n c t) |
468 |
hence gd: "g dvd c" by simp |
|
29789 | 469 |
from gp have gnz: "g \<noteq> 0" by simp |
41807 | 470 |
from assms 2 show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps) |
29789 | 471 |
qed (auto simp add: numgcd_def gp) |
36853 | 472 |
|
473 |
fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where |
|
29789 | 474 |
"ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)" |
36853 | 475 |
| "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))" |
476 |
| "ismaxcoeff t = (\<lambda>x. True)" |
|
29789 | 477 |
|
478 |
lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'" |
|
41807 | 479 |
by (induct t rule: ismaxcoeff.induct) auto |
29789 | 480 |
|
481 |
lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" |
|
482 |
proof (induct t rule: maxcoeff.induct) |
|
483 |
case (2 n c t) |
|
484 |
hence H:"ismaxcoeff t (maxcoeff t)" . |
|
41807 | 485 |
have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by simp |
486 |
from ismaxcoeff_mono[OF H thh] show ?case by simp |
|
29789 | 487 |
qed simp_all |
488 |
||
31706 | 489 |
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))" |
490 |
apply (cases "abs i = 0", simp_all add: gcd_int_def) |
|
29789 | 491 |
apply (cases "abs j = 0", simp_all) |
492 |
apply (cases "abs i = 1", simp_all) |
|
493 |
apply (cases "abs j = 1", simp_all) |
|
494 |
apply auto |
|
495 |
done |
|
496 |
lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow> m =0" |
|
31706 | 497 |
by (induct t rule: numgcdh.induct, auto) |
29789 | 498 |
|
499 |
lemma dvdnumcoeff_aux: |
|
500 |
assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1" |
|
501 |
shows "dvdnumcoeff t (numgcdh t m)" |
|
41807 | 502 |
using assms |
29789 | 503 |
proof(induct t rule: numgcdh.induct) |
504 |
case (2 n c t) |
|
505 |
let ?g = "numgcdh t m" |
|
41807 | 506 |
from 2 have th:"gcd c ?g > 1" by simp |
29789 | 507 |
from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] |
508 |
have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp |
|
41807 | 509 |
moreover {assume "abs c > 1" and gp: "?g > 1" with 2 |
29789 | 510 |
have th: "dvdnumcoeff t ?g" by simp |
31706 | 511 |
have th': "gcd c ?g dvd ?g" by simp |
512 |
from dvdnumcoeff_trans[OF th' th] have ?case by simp } |
|
29789 | 513 |
moreover {assume "abs c = 0 \<and> ?g > 1" |
41807 | 514 |
with 2 have th: "dvdnumcoeff t ?g" by simp |
31706 | 515 |
have th': "gcd c ?g dvd ?g" by simp |
516 |
from dvdnumcoeff_trans[OF th' th] have ?case by simp |
|
29789 | 517 |
hence ?case by simp } |
518 |
moreover {assume "abs c > 1" and g0:"?g = 0" |
|
41807 | 519 |
from numgcdh0[OF g0] have "m=0". with 2 g0 have ?case by simp } |
29789 | 520 |
ultimately show ?case by blast |
31706 | 521 |
qed auto |
29789 | 522 |
|
523 |
lemma dvdnumcoeff_aux2: |
|
41807 | 524 |
assumes "numgcd t > 1" |
525 |
shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0" |
|
526 |
using assms |
|
29789 | 527 |
proof (simp add: numgcd_def) |
528 |
let ?mc = "maxcoeff t" |
|
529 |
let ?g = "numgcdh t ?mc" |
|
530 |
have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff) |
|
531 |
have th2: "?mc \<ge> 0" by (rule maxcoeff_pos) |
|
532 |
assume H: "numgcdh t ?mc > 1" |
|
533 |
from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" . |
|
534 |
qed |
|
535 |
||
536 |
lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t" |
|
537 |
proof- |
|
538 |
let ?g = "numgcd t" |
|
539 |
have "?g \<ge> 0" by (simp add: numgcd_pos) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
540 |
hence "?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto |
29789 | 541 |
moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} |
542 |
moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} |
|
543 |
moreover { assume g1:"?g > 1" |
|
544 |
from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+ |
|
545 |
from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis |
|
546 |
by (simp add: reducecoeff_def Let_def)} |
|
547 |
ultimately show ?thesis by blast |
|
548 |
qed |
|
549 |
||
550 |
lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)" |
|
551 |
by (induct t rule: reducecoeffh.induct, auto) |
|
552 |
||
553 |
lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)" |
|
554 |
using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def) |
|
555 |
||
556 |
consts |
|
557 |
numadd:: "num \<times> num \<Rightarrow> num" |
|
36853 | 558 |
|
29789 | 559 |
recdef numadd "measure (\<lambda> (t,s). size t + size s)" |
560 |
"numadd (CN n1 c1 r1,CN n2 c2 r2) = |
|
561 |
(if n1=n2 then |
|
562 |
(let c = c1 + c2 |
|
563 |
in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2)))) |
|
564 |
else if n1 \<le> n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2))) |
|
565 |
else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))" |
|
566 |
"numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))" |
|
567 |
"numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" |
|
568 |
"numadd (C b1, C b2) = C (b1+b2)" |
|
569 |
"numadd (a,b) = Add a b" |
|
570 |
||
571 |
lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" |
|
572 |
apply (induct t s rule: numadd.induct, simp_all add: Let_def) |
|
573 |
apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all) |
|
574 |
apply (case_tac "n1 = n2", simp_all add: algebra_simps) |
|
575 |
by (simp only: left_distrib[symmetric],simp) |
|
576 |
||
577 |
lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))" |
|
578 |
by (induct t s rule: numadd.induct, auto simp add: Let_def) |
|
579 |
||
36853 | 580 |
fun nummul:: "num \<Rightarrow> int \<Rightarrow> num" where |
29789 | 581 |
"nummul (C j) = (\<lambda> i. C (i*j))" |
36853 | 582 |
| "nummul (CN n c a) = (\<lambda> i. CN n (i*c) (nummul a i))" |
583 |
| "nummul t = (\<lambda> i. Mul i t)" |
|
29789 | 584 |
|
585 |
lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)" |
|
586 |
by (induct t rule: nummul.induct, auto simp add: algebra_simps) |
|
587 |
||
588 |
lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)" |
|
589 |
by (induct t rule: nummul.induct, auto ) |
|
590 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
591 |
definition numneg :: "num \<Rightarrow> num" where |
36853 | 592 |
"numneg t = nummul t (- 1)" |
29789 | 593 |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
594 |
definition numsub :: "num \<Rightarrow> num \<Rightarrow> num" where |
36853 | 595 |
"numsub s t = (if s = t then C 0 else numadd (s,numneg t))" |
29789 | 596 |
|
597 |
lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)" |
|
598 |
using numneg_def by simp |
|
599 |
||
600 |
lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)" |
|
601 |
using numneg_def by simp |
|
602 |
||
603 |
lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)" |
|
604 |
using numsub_def by simp |
|
605 |
||
606 |
lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)" |
|
607 |
using numsub_def by simp |
|
608 |
||
36853 | 609 |
primrec simpnum:: "num \<Rightarrow> num" where |
29789 | 610 |
"simpnum (C j) = C j" |
36853 | 611 |
| "simpnum (Bound n) = CN n 1 (C 0)" |
612 |
| "simpnum (Neg t) = numneg (simpnum t)" |
|
613 |
| "simpnum (Add t s) = numadd (simpnum t,simpnum s)" |
|
614 |
| "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" |
|
615 |
| "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)" |
|
616 |
| "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0),simpnum t))" |
|
29789 | 617 |
|
618 |
lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t" |
|
36853 | 619 |
by (induct t) simp_all |
29789 | 620 |
|
621 |
lemma simpnum_numbound0[simp]: |
|
622 |
"numbound0 t \<Longrightarrow> numbound0 (simpnum t)" |
|
36853 | 623 |
by (induct t) simp_all |
29789 | 624 |
|
36853 | 625 |
fun nozerocoeff:: "num \<Rightarrow> bool" where |
29789 | 626 |
"nozerocoeff (C c) = True" |
36853 | 627 |
| "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)" |
628 |
| "nozerocoeff t = True" |
|
29789 | 629 |
|
630 |
lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))" |
|
631 |
by (induct a b rule: numadd.induct,auto simp add: Let_def) |
|
632 |
||
633 |
lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)" |
|
634 |
by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz) |
|
635 |
||
636 |
lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)" |
|
637 |
by (simp add: numneg_def nummul_nz) |
|
638 |
||
639 |
lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)" |
|
640 |
by (simp add: numsub_def numneg_nz numadd_nz) |
|
641 |
||
642 |
lemma simpnum_nz: "nozerocoeff (simpnum t)" |
|
36853 | 643 |
by(induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz) |
29789 | 644 |
|
645 |
lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0" |
|
646 |
proof (induct t rule: maxcoeff.induct) |
|
647 |
case (2 n c t) |
|
41807 | 648 |
hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp_all |
649 |
have "max (abs c) (maxcoeff t) \<ge> abs c" by simp |
|
29789 | 650 |
with cnz have "max (abs c) (maxcoeff t) > 0" by arith |
41807 | 651 |
with 2 show ?case by simp |
29789 | 652 |
qed auto |
653 |
||
654 |
lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0" |
|
655 |
proof- |
|
656 |
from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def) |
|
657 |
from numgcdh0[OF th] have th:"maxcoeff t = 0" . |
|
658 |
from maxcoeff_nz[OF nz th] show ?thesis . |
|
659 |
qed |
|
660 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
661 |
definition simp_num_pair :: "(num \<times> int) \<Rightarrow> num \<times> int" where |
36853 | 662 |
"simp_num_pair = (\<lambda> (t,n). (if n = 0 then (C 0, 0) else |
29789 | 663 |
(let t' = simpnum t ; g = numgcd t' in |
31706 | 664 |
if g > 1 then (let g' = gcd n g in |
29789 | 665 |
if g' = 1 then (t',n) |
666 |
else (reducecoeffh t' g', n div g')) |
|
667 |
else (t',n))))" |
|
668 |
||
669 |
lemma simp_num_pair_ci: |
|
670 |
shows "((\<lambda> (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\<lambda> (t,n). Inum bs t / real n) (t,n))" |
|
671 |
(is "?lhs = ?rhs") |
|
672 |
proof- |
|
673 |
let ?t' = "simpnum t" |
|
674 |
let ?g = "numgcd ?t'" |
|
31706 | 675 |
let ?g' = "gcd n ?g" |
29789 | 676 |
{assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)} |
677 |
moreover |
|
678 |
{ assume nnz: "n \<noteq> 0" |
|
41807 | 679 |
{assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci) } |
29789 | 680 |
moreover |
681 |
{assume g1:"?g>1" hence g0: "?g > 0" by simp |
|
31706 | 682 |
from g1 nnz have gp0: "?g' \<noteq> 0" by simp |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31706
diff
changeset
|
683 |
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith |
29789 | 684 |
hence "?g'= 1 \<or> ?g' > 1" by arith |
685 |
moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)} |
|
686 |
moreover {assume g'1:"?g'>1" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
687 |
from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
688 |
let ?tt = "reducecoeffh ?t' ?g'" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
689 |
let ?t = "Inum bs ?tt" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
690 |
have gpdg: "?g' dvd ?g" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
691 |
have gpdd: "?g' dvd n" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
692 |
have gpdgp: "?g' dvd ?g'" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
693 |
from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
694 |
have th2:"real ?g' * ?t = Inum bs ?t'" by simp |
41807 | 695 |
from g1 g'1 have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def) |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
696 |
also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
697 |
also have "\<dots> = (Inum bs ?t' / real n)" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
698 |
using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp |
41807 | 699 |
finally have "?lhs = Inum bs t / real n" by simp |
700 |
then have ?thesis by (simp add: simp_num_pair_def) } |
|
701 |
ultimately have ?thesis by blast } |
|
702 |
ultimately have ?thesis by blast } |
|
29789 | 703 |
ultimately show ?thesis by blast |
704 |
qed |
|
705 |
||
706 |
lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')" |
|
707 |
shows "numbound0 t' \<and> n' >0" |
|
708 |
proof- |
|
41807 | 709 |
let ?t' = "simpnum t" |
29789 | 710 |
let ?g = "numgcd ?t'" |
31706 | 711 |
let ?g' = "gcd n ?g" |
41807 | 712 |
{ assume nz: "n = 0" hence ?thesis using assms by (simp add: Let_def simp_num_pair_def) } |
29789 | 713 |
moreover |
714 |
{ assume nnz: "n \<noteq> 0" |
|
41807 | 715 |
{ assume "\<not> ?g > 1" hence ?thesis using assms |
716 |
by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) } |
|
29789 | 717 |
moreover |
41807 | 718 |
{ assume g1:"?g>1" hence g0: "?g > 0" by simp |
31706 | 719 |
from g1 nnz have gp0: "?g' \<noteq> 0" by simp |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31706
diff
changeset
|
720 |
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith |
29789 | 721 |
hence "?g'= 1 \<or> ?g' > 1" by arith |
41807 | 722 |
moreover { |
723 |
assume "?g' = 1" hence ?thesis using assms g1 |
|
724 |
by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) } |
|
725 |
moreover { |
|
726 |
assume g'1: "?g' > 1" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
727 |
have gpdg: "?g' dvd ?g" by simp |
41807 | 728 |
have gpdd: "?g' dvd n" by simp |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
729 |
have gpdgp: "?g' dvd ?g'" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
730 |
from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" . |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
731 |
from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]] |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
732 |
have "n div ?g' >0" by simp |
41807 | 733 |
hence ?thesis using assms g1 g'1 |
734 |
by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0) } |
|
735 |
ultimately have ?thesis by blast } |
|
736 |
ultimately have ?thesis by blast } |
|
29789 | 737 |
ultimately show ?thesis by blast |
738 |
qed |
|
739 |
||
36853 | 740 |
fun simpfm :: "fm \<Rightarrow> fm" where |
29789 | 741 |
"simpfm (And p q) = conj (simpfm p) (simpfm q)" |
36853 | 742 |
| "simpfm (Or p q) = disj (simpfm p) (simpfm q)" |
743 |
| "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" |
|
744 |
| "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" |
|
745 |
| "simpfm (NOT p) = not (simpfm p)" |
|
746 |
| "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F |
|
29789 | 747 |
| _ \<Rightarrow> Lt a')" |
36853 | 748 |
| "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')" |
749 |
| "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0) then T else F | _ \<Rightarrow> Gt a')" |
|
750 |
| "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')" |
|
751 |
| "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0) then T else F | _ \<Rightarrow> Eq a')" |
|
752 |
| "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')" |
|
753 |
| "simpfm p = p" |
|
29789 | 754 |
lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p" |
755 |
proof(induct p rule: simpfm.induct) |
|
756 |
case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
757 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
758 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
759 |
by (cases ?sa, simp_all add: Let_def)} |
|
760 |
ultimately show ?case by blast |
|
761 |
next |
|
762 |
case (7 a) let ?sa = "simpnum a" |
|
763 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
764 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
765 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
766 |
by (cases ?sa, simp_all add: Let_def)} |
|
767 |
ultimately show ?case by blast |
|
768 |
next |
|
769 |
case (8 a) let ?sa = "simpnum a" |
|
770 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
771 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
772 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
773 |
by (cases ?sa, simp_all add: Let_def)} |
|
774 |
ultimately show ?case by blast |
|
775 |
next |
|
776 |
case (9 a) let ?sa = "simpnum a" |
|
777 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
778 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
779 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
780 |
by (cases ?sa, simp_all add: Let_def)} |
|
781 |
ultimately show ?case by blast |
|
782 |
next |
|
783 |
case (10 a) let ?sa = "simpnum a" |
|
784 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
785 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
786 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
787 |
by (cases ?sa, simp_all add: Let_def)} |
|
788 |
ultimately show ?case by blast |
|
789 |
next |
|
790 |
case (11 a) let ?sa = "simpnum a" |
|
791 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp |
|
792 |
{fix v assume "?sa = C v" hence ?case using sa by simp } |
|
793 |
moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa |
|
794 |
by (cases ?sa, simp_all add: Let_def)} |
|
795 |
ultimately show ?case by blast |
|
796 |
qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not) |
|
797 |
||
798 |
||
799 |
lemma simpfm_bound0: "bound0 p \<Longrightarrow> bound0 (simpfm p)" |
|
800 |
proof(induct p rule: simpfm.induct) |
|
801 |
case (6 a) hence nb: "numbound0 a" by simp |
|
802 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
803 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
804 |
next |
|
805 |
case (7 a) hence nb: "numbound0 a" by simp |
|
806 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
807 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
808 |
next |
|
809 |
case (8 a) hence nb: "numbound0 a" by simp |
|
810 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
811 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
812 |
next |
|
813 |
case (9 a) hence nb: "numbound0 a" by simp |
|
814 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
815 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
816 |
next |
|
817 |
case (10 a) hence nb: "numbound0 a" by simp |
|
818 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
819 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
820 |
next |
|
821 |
case (11 a) hence nb: "numbound0 a" by simp |
|
822 |
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
823 |
thus ?case by (cases "simpnum a", auto simp add: Let_def) |
|
824 |
qed(auto simp add: disj_def imp_def iff_def conj_def not_bn) |
|
825 |
||
826 |
lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)" |
|
827 |
by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def) |
|
828 |
(case_tac "simpnum a",auto)+ |
|
829 |
||
830 |
consts prep :: "fm \<Rightarrow> fm" |
|
831 |
recdef prep "measure fmsize" |
|
832 |
"prep (E T) = T" |
|
833 |
"prep (E F) = F" |
|
834 |
"prep (E (Or p q)) = disj (prep (E p)) (prep (E q))" |
|
835 |
"prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))" |
|
836 |
"prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" |
|
837 |
"prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))" |
|
838 |
"prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" |
|
839 |
"prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" |
|
840 |
"prep (E p) = E (prep p)" |
|
841 |
"prep (A (And p q)) = conj (prep (A p)) (prep (A q))" |
|
842 |
"prep (A p) = prep (NOT (E (NOT p)))" |
|
843 |
"prep (NOT (NOT p)) = prep p" |
|
844 |
"prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))" |
|
845 |
"prep (NOT (A p)) = prep (E (NOT p))" |
|
846 |
"prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))" |
|
847 |
"prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))" |
|
848 |
"prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))" |
|
849 |
"prep (NOT p) = not (prep p)" |
|
850 |
"prep (Or p q) = disj (prep p) (prep q)" |
|
851 |
"prep (And p q) = conj (prep p) (prep q)" |
|
852 |
"prep (Imp p q) = prep (Or (NOT p) q)" |
|
853 |
"prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))" |
|
854 |
"prep p = p" |
|
855 |
(hints simp add: fmsize_pos) |
|
856 |
lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p" |
|
857 |
by (induct p rule: prep.induct, auto) |
|
858 |
||
859 |
(* Generic quantifier elimination *) |
|
36853 | 860 |
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where |
29789 | 861 |
"qelim (E p) = (\<lambda> qe. DJ qe (qelim p qe))" |
36853 | 862 |
| "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))" |
863 |
| "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))" |
|
864 |
| "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" |
|
865 |
| "qelim (Or p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" |
|
866 |
| "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))" |
|
867 |
| "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))" |
|
868 |
| "qelim p = (\<lambda> y. simpfm p)" |
|
869 |
by pat_completeness auto |
|
870 |
termination qelim by (relation "measure fmsize") simp_all |
|
29789 | 871 |
|
872 |
lemma qelim_ci: |
|
873 |
assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))" |
|
874 |
shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)" |
|
875 |
using qe_inv DJ_qe[OF qe_inv] |
|
876 |
by(induct p rule: qelim.induct) |
|
877 |
(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf |
|
878 |
simpfm simpfm_qf simp del: simpfm.simps) |
|
879 |
||
36853 | 880 |
fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*) where |
29789 | 881 |
"minusinf (And p q) = conj (minusinf p) (minusinf q)" |
36853 | 882 |
| "minusinf (Or p q) = disj (minusinf p) (minusinf q)" |
883 |
| "minusinf (Eq (CN 0 c e)) = F" |
|
884 |
| "minusinf (NEq (CN 0 c e)) = T" |
|
885 |
| "minusinf (Lt (CN 0 c e)) = T" |
|
886 |
| "minusinf (Le (CN 0 c e)) = T" |
|
887 |
| "minusinf (Gt (CN 0 c e)) = F" |
|
888 |
| "minusinf (Ge (CN 0 c e)) = F" |
|
889 |
| "minusinf p = p" |
|
29789 | 890 |
|
36853 | 891 |
fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*) where |
29789 | 892 |
"plusinf (And p q) = conj (plusinf p) (plusinf q)" |
36853 | 893 |
| "plusinf (Or p q) = disj (plusinf p) (plusinf q)" |
894 |
| "plusinf (Eq (CN 0 c e)) = F" |
|
895 |
| "plusinf (NEq (CN 0 c e)) = T" |
|
896 |
| "plusinf (Lt (CN 0 c e)) = F" |
|
897 |
| "plusinf (Le (CN 0 c e)) = F" |
|
898 |
| "plusinf (Gt (CN 0 c e)) = T" |
|
899 |
| "plusinf (Ge (CN 0 c e)) = T" |
|
900 |
| "plusinf p = p" |
|
29789 | 901 |
|
36853 | 902 |
fun isrlfm :: "fm \<Rightarrow> bool" (* Linearity test for fm *) where |
29789 | 903 |
"isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" |
36853 | 904 |
| "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" |
905 |
| "isrlfm (Eq (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
906 |
| "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
907 |
| "isrlfm (Lt (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
908 |
| "isrlfm (Le (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
909 |
| "isrlfm (Gt (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
910 |
| "isrlfm (Ge (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
911 |
| "isrlfm p = (isatom p \<and> (bound0 p))" |
|
29789 | 912 |
|
913 |
(* splits the bounded from the unbounded part*) |
|
36853 | 914 |
function (sequential) rsplit0 :: "num \<Rightarrow> int \<times> num" where |
29789 | 915 |
"rsplit0 (Bound 0) = (1,C 0)" |
36853 | 916 |
| "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a ; (cb,tb) = rsplit0 b |
29789 | 917 |
in (ca+cb, Add ta tb))" |
36853 | 918 |
| "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))" |
919 |
| "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (-c,Neg t))" |
|
920 |
| "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c*ca,Mul c ta))" |
|
921 |
| "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c+ca,ta))" |
|
922 |
| "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca,CN n c ta))" |
|
923 |
| "rsplit0 t = (0,t)" |
|
924 |
by pat_completeness auto |
|
925 |
termination rsplit0 by (relation "measure num_size") simp_all |
|
926 |
||
29789 | 927 |
lemma rsplit0: |
928 |
shows "Inum bs ((split (CN 0)) (rsplit0 t)) = Inum bs t \<and> numbound0 (snd (rsplit0 t))" |
|
929 |
proof (induct t rule: rsplit0.induct) |
|
930 |
case (2 a b) |
|
931 |
let ?sa = "rsplit0 a" let ?sb = "rsplit0 b" |
|
932 |
let ?ca = "fst ?sa" let ?cb = "fst ?sb" |
|
933 |
let ?ta = "snd ?sa" let ?tb = "snd ?sb" |
|
41807 | 934 |
from 2 have nb: "numbound0 (snd(rsplit0 (Add a b)))" |
36853 | 935 |
by (cases "rsplit0 a") (auto simp add: Let_def split_def) |
29789 | 936 |
have "Inum bs ((split (CN 0)) (rsplit0 (Add a b))) = |
937 |
Inum bs ((split (CN 0)) ?sa)+Inum bs ((split (CN 0)) ?sb)" |
|
938 |
by (simp add: Let_def split_def algebra_simps) |
|
41807 | 939 |
also have "\<dots> = Inum bs a + Inum bs b" using 2 by (cases "rsplit0 a") auto |
29789 | 940 |
finally show ?case using nb by simp |
41807 | 941 |
qed (auto simp add: Let_def split_def algebra_simps, simp add: right_distrib[symmetric]) |
29789 | 942 |
|
943 |
(* Linearize a formula*) |
|
944 |
definition |
|
945 |
lt :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
946 |
where |
|
947 |
"lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) |
|
948 |
else (Gt (CN 0 (-c) (Neg t))))" |
|
949 |
||
950 |
definition |
|
951 |
le :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
952 |
where |
|
953 |
"le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) |
|
954 |
else (Ge (CN 0 (-c) (Neg t))))" |
|
955 |
||
956 |
definition |
|
957 |
gt :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
958 |
where |
|
959 |
"gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) |
|
960 |
else (Lt (CN 0 (-c) (Neg t))))" |
|
961 |
||
962 |
definition |
|
963 |
ge :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
964 |
where |
|
965 |
"ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) |
|
966 |
else (Le (CN 0 (-c) (Neg t))))" |
|
967 |
||
968 |
definition |
|
969 |
eq :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
970 |
where |
|
971 |
"eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) |
|
972 |
else (Eq (CN 0 (-c) (Neg t))))" |
|
973 |
||
974 |
definition |
|
975 |
neq :: "int \<Rightarrow> num \<Rightarrow> fm" |
|
976 |
where |
|
977 |
"neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) |
|
978 |
else (NEq (CN 0 (-c) (Neg t))))" |
|
979 |
||
980 |
lemma lt: "numnoabs t \<Longrightarrow> Ifm bs (split lt (rsplit0 t)) = Ifm bs (Lt t) \<and> isrlfm (split lt (rsplit0 t))" |
|
981 |
using rsplit0[where bs = "bs" and t="t"] |
|
982 |
by (auto simp add: lt_def split_def,cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
983 |
||
984 |
lemma le: "numnoabs t \<Longrightarrow> Ifm bs (split le (rsplit0 t)) = Ifm bs (Le t) \<and> isrlfm (split le (rsplit0 t))" |
|
985 |
using rsplit0[where bs = "bs" and t="t"] |
|
986 |
by (auto simp add: le_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
987 |
||
988 |
lemma gt: "numnoabs t \<Longrightarrow> Ifm bs (split gt (rsplit0 t)) = Ifm bs (Gt t) \<and> isrlfm (split gt (rsplit0 t))" |
|
989 |
using rsplit0[where bs = "bs" and t="t"] |
|
990 |
by (auto simp add: gt_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
991 |
||
992 |
lemma ge: "numnoabs t \<Longrightarrow> Ifm bs (split ge (rsplit0 t)) = Ifm bs (Ge t) \<and> isrlfm (split ge (rsplit0 t))" |
|
993 |
using rsplit0[where bs = "bs" and t="t"] |
|
994 |
by (auto simp add: ge_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
995 |
||
996 |
lemma eq: "numnoabs t \<Longrightarrow> Ifm bs (split eq (rsplit0 t)) = Ifm bs (Eq t) \<and> isrlfm (split eq (rsplit0 t))" |
|
997 |
using rsplit0[where bs = "bs" and t="t"] |
|
998 |
by (auto simp add: eq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
999 |
||
1000 |
lemma neq: "numnoabs t \<Longrightarrow> Ifm bs (split neq (rsplit0 t)) = Ifm bs (NEq t) \<and> isrlfm (split neq (rsplit0 t))" |
|
1001 |
using rsplit0[where bs = "bs" and t="t"] |
|
1002 |
by (auto simp add: neq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto) |
|
1003 |
||
1004 |
lemma conj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)" |
|
1005 |
by (auto simp add: conj_def) |
|
1006 |
lemma disj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)" |
|
1007 |
by (auto simp add: disj_def) |
|
1008 |
||
1009 |
consts rlfm :: "fm \<Rightarrow> fm" |
|
1010 |
recdef rlfm "measure fmsize" |
|
1011 |
"rlfm (And p q) = conj (rlfm p) (rlfm q)" |
|
1012 |
"rlfm (Or p q) = disj (rlfm p) (rlfm q)" |
|
1013 |
"rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)" |
|
1014 |
"rlfm (Iff p q) = disj (conj (rlfm p) (rlfm q)) (conj (rlfm (NOT p)) (rlfm (NOT q)))" |
|
1015 |
"rlfm (Lt a) = split lt (rsplit0 a)" |
|
1016 |
"rlfm (Le a) = split le (rsplit0 a)" |
|
1017 |
"rlfm (Gt a) = split gt (rsplit0 a)" |
|
1018 |
"rlfm (Ge a) = split ge (rsplit0 a)" |
|
1019 |
"rlfm (Eq a) = split eq (rsplit0 a)" |
|
1020 |
"rlfm (NEq a) = split neq (rsplit0 a)" |
|
1021 |
"rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))" |
|
1022 |
"rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))" |
|
1023 |
"rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))" |
|
1024 |
"rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))" |
|
1025 |
"rlfm (NOT (NOT p)) = rlfm p" |
|
1026 |
"rlfm (NOT T) = F" |
|
1027 |
"rlfm (NOT F) = T" |
|
1028 |
"rlfm (NOT (Lt a)) = rlfm (Ge a)" |
|
1029 |
"rlfm (NOT (Le a)) = rlfm (Gt a)" |
|
1030 |
"rlfm (NOT (Gt a)) = rlfm (Le a)" |
|
1031 |
"rlfm (NOT (Ge a)) = rlfm (Lt a)" |
|
1032 |
"rlfm (NOT (Eq a)) = rlfm (NEq a)" |
|
1033 |
"rlfm (NOT (NEq a)) = rlfm (Eq a)" |
|
1034 |
"rlfm p = p" (hints simp add: fmsize_pos) |
|
1035 |
||
1036 |
lemma rlfm_I: |
|
1037 |
assumes qfp: "qfree p" |
|
1038 |
shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)" |
|
1039 |
using qfp |
|
1040 |
by (induct p rule: rlfm.induct, auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin) |
|
1041 |
||
1042 |
(* Operations needed for Ferrante and Rackoff *) |
|
1043 |
lemma rminusinf_inf: |
|
1044 |
assumes lp: "isrlfm p" |
|
1045 |
shows "\<exists> z. \<forall> x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p") |
|
1046 |
using lp |
|
1047 |
proof (induct p rule: minusinf.induct) |
|
1048 |
case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto |
|
1049 |
next |
|
1050 |
case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto |
|
1051 |
next |
|
1052 |
case (3 c e) |
|
41807 | 1053 |
from 3 have nb: "numbound0 e" by simp |
1054 |
from 3 have cp: "real c > 0" by simp |
|
29789 | 1055 |
fix a |
1056 |
let ?e="Inum (a#bs) e" |
|
1057 |
let ?z = "(- ?e) / real c" |
|
1058 |
{fix x |
|
1059 |
assume xz: "x < ?z" |
|
1060 |
hence "(real c * x < - ?e)" |
|
1061 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1062 |
hence "real c * x + ?e < 0" by arith |
|
1063 |
hence "real c * x + ?e \<noteq> 0" by simp |
|
1064 |
with xz have "?P ?z x (Eq (CN 0 c e))" |
|
1065 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1066 |
hence "\<forall> x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp |
|
1067 |
thus ?case by blast |
|
1068 |
next |
|
1069 |
case (4 c e) |
|
41807 | 1070 |
from 4 have nb: "numbound0 e" by simp |
1071 |
from 4 have cp: "real c > 0" by simp |
|
29789 | 1072 |
fix a |
1073 |
let ?e="Inum (a#bs) e" |
|
1074 |
let ?z = "(- ?e) / real c" |
|
1075 |
{fix x |
|
1076 |
assume xz: "x < ?z" |
|
1077 |
hence "(real c * x < - ?e)" |
|
1078 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1079 |
hence "real c * x + ?e < 0" by arith |
|
1080 |
hence "real c * x + ?e \<noteq> 0" by simp |
|
1081 |
with xz have "?P ?z x (NEq (CN 0 c e))" |
|
1082 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1083 |
hence "\<forall> x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp |
|
1084 |
thus ?case by blast |
|
1085 |
next |
|
1086 |
case (5 c e) |
|
41807 | 1087 |
from 5 have nb: "numbound0 e" by simp |
1088 |
from 5 have cp: "real c > 0" by simp |
|
29789 | 1089 |
fix a |
1090 |
let ?e="Inum (a#bs) e" |
|
1091 |
let ?z = "(- ?e) / real c" |
|
1092 |
{fix x |
|
1093 |
assume xz: "x < ?z" |
|
1094 |
hence "(real c * x < - ?e)" |
|
1095 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1096 |
hence "real c * x + ?e < 0" by arith |
|
1097 |
with xz have "?P ?z x (Lt (CN 0 c e))" |
|
1098 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1099 |
hence "\<forall> x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp |
|
1100 |
thus ?case by blast |
|
1101 |
next |
|
1102 |
case (6 c e) |
|
41807 | 1103 |
from 6 have nb: "numbound0 e" by simp |
1104 |
from lp 6 have cp: "real c > 0" by simp |
|
29789 | 1105 |
fix a |
1106 |
let ?e="Inum (a#bs) e" |
|
1107 |
let ?z = "(- ?e) / real c" |
|
1108 |
{fix x |
|
1109 |
assume xz: "x < ?z" |
|
1110 |
hence "(real c * x < - ?e)" |
|
1111 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1112 |
hence "real c * x + ?e < 0" by arith |
|
1113 |
with xz have "?P ?z x (Le (CN 0 c e))" |
|
1114 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1115 |
hence "\<forall> x < ?z. ?P ?z x (Le (CN 0 c e))" by simp |
|
1116 |
thus ?case by blast |
|
1117 |
next |
|
1118 |
case (7 c e) |
|
41807 | 1119 |
from 7 have nb: "numbound0 e" by simp |
1120 |
from 7 have cp: "real c > 0" by simp |
|
29789 | 1121 |
fix a |
1122 |
let ?e="Inum (a#bs) e" |
|
1123 |
let ?z = "(- ?e) / real c" |
|
1124 |
{fix x |
|
1125 |
assume xz: "x < ?z" |
|
1126 |
hence "(real c * x < - ?e)" |
|
1127 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1128 |
hence "real c * x + ?e < 0" by arith |
|
1129 |
with xz have "?P ?z x (Gt (CN 0 c e))" |
|
1130 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1131 |
hence "\<forall> x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp |
|
1132 |
thus ?case by blast |
|
1133 |
next |
|
1134 |
case (8 c e) |
|
41807 | 1135 |
from 8 have nb: "numbound0 e" by simp |
1136 |
from 8 have cp: "real c > 0" by simp |
|
29789 | 1137 |
fix a |
1138 |
let ?e="Inum (a#bs) e" |
|
1139 |
let ?z = "(- ?e) / real c" |
|
1140 |
{fix x |
|
1141 |
assume xz: "x < ?z" |
|
1142 |
hence "(real c * x < - ?e)" |
|
1143 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) |
|
1144 |
hence "real c * x + ?e < 0" by arith |
|
1145 |
with xz have "?P ?z x (Ge (CN 0 c e))" |
|
1146 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1147 |
hence "\<forall> x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp |
|
1148 |
thus ?case by blast |
|
1149 |
qed simp_all |
|
1150 |
||
1151 |
lemma rplusinf_inf: |
|
1152 |
assumes lp: "isrlfm p" |
|
1153 |
shows "\<exists> z. \<forall> x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p") |
|
1154 |
using lp |
|
1155 |
proof (induct p rule: isrlfm.induct) |
|
1156 |
case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto |
|
1157 |
next |
|
1158 |
case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto |
|
1159 |
next |
|
1160 |
case (3 c e) |
|
41807 | 1161 |
from 3 have nb: "numbound0 e" by simp |
1162 |
from 3 have cp: "real c > 0" by simp |
|
29789 | 1163 |
fix a |
1164 |
let ?e="Inum (a#bs) e" |
|
1165 |
let ?z = "(- ?e) / real c" |
|
1166 |
{fix x |
|
1167 |
assume xz: "x > ?z" |
|
1168 |
with mult_strict_right_mono [OF xz cp] cp |
|
1169 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1170 |
hence "real c * x + ?e > 0" by arith |
|
1171 |
hence "real c * x + ?e \<noteq> 0" by simp |
|
1172 |
with xz have "?P ?z x (Eq (CN 0 c e))" |
|
1173 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1174 |
hence "\<forall> x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp |
|
1175 |
thus ?case by blast |
|
1176 |
next |
|
1177 |
case (4 c e) |
|
41807 | 1178 |
from 4 have nb: "numbound0 e" by simp |
1179 |
from 4 have cp: "real c > 0" by simp |
|
29789 | 1180 |
fix a |
1181 |
let ?e="Inum (a#bs) e" |
|
1182 |
let ?z = "(- ?e) / real c" |
|
1183 |
{fix x |
|
1184 |
assume xz: "x > ?z" |
|
1185 |
with mult_strict_right_mono [OF xz cp] cp |
|
1186 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1187 |
hence "real c * x + ?e > 0" by arith |
|
1188 |
hence "real c * x + ?e \<noteq> 0" by simp |
|
1189 |
with xz have "?P ?z x (NEq (CN 0 c e))" |
|
1190 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1191 |
hence "\<forall> x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp |
|
1192 |
thus ?case by blast |
|
1193 |
next |
|
1194 |
case (5 c e) |
|
41807 | 1195 |
from 5 have nb: "numbound0 e" by simp |
1196 |
from 5 have cp: "real c > 0" by simp |
|
29789 | 1197 |
fix a |
1198 |
let ?e="Inum (a#bs) e" |
|
1199 |
let ?z = "(- ?e) / real c" |
|
1200 |
{fix x |
|
1201 |
assume xz: "x > ?z" |
|
1202 |
with mult_strict_right_mono [OF xz cp] cp |
|
1203 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1204 |
hence "real c * x + ?e > 0" by arith |
|
1205 |
with xz have "?P ?z x (Lt (CN 0 c e))" |
|
1206 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1207 |
hence "\<forall> x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp |
|
1208 |
thus ?case by blast |
|
1209 |
next |
|
1210 |
case (6 c e) |
|
41807 | 1211 |
from 6 have nb: "numbound0 e" by simp |
1212 |
from 6 have cp: "real c > 0" by simp |
|
29789 | 1213 |
fix a |
1214 |
let ?e="Inum (a#bs) e" |
|
1215 |
let ?z = "(- ?e) / real c" |
|
1216 |
{fix x |
|
1217 |
assume xz: "x > ?z" |
|
1218 |
with mult_strict_right_mono [OF xz cp] cp |
|
1219 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1220 |
hence "real c * x + ?e > 0" by arith |
|
1221 |
with xz have "?P ?z x (Le (CN 0 c e))" |
|
1222 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1223 |
hence "\<forall> x > ?z. ?P ?z x (Le (CN 0 c e))" by simp |
|
1224 |
thus ?case by blast |
|
1225 |
next |
|
1226 |
case (7 c e) |
|
41807 | 1227 |
from 7 have nb: "numbound0 e" by simp |
1228 |
from 7 have cp: "real c > 0" by simp |
|
29789 | 1229 |
fix a |
1230 |
let ?e="Inum (a#bs) e" |
|
1231 |
let ?z = "(- ?e) / real c" |
|
1232 |
{fix x |
|
1233 |
assume xz: "x > ?z" |
|
1234 |
with mult_strict_right_mono [OF xz cp] cp |
|
1235 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1236 |
hence "real c * x + ?e > 0" by arith |
|
1237 |
with xz have "?P ?z x (Gt (CN 0 c e))" |
|
1238 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1239 |
hence "\<forall> x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp |
|
1240 |
thus ?case by blast |
|
1241 |
next |
|
1242 |
case (8 c e) |
|
41807 | 1243 |
from 8 have nb: "numbound0 e" by simp |
1244 |
from 8 have cp: "real c > 0" by simp |
|
29789 | 1245 |
fix a |
1246 |
let ?e="Inum (a#bs) e" |
|
1247 |
let ?z = "(- ?e) / real c" |
|
1248 |
{fix x |
|
1249 |
assume xz: "x > ?z" |
|
1250 |
with mult_strict_right_mono [OF xz cp] cp |
|
1251 |
have "(real c * x > - ?e)" by (simp add: mult_ac) |
|
1252 |
hence "real c * x + ?e > 0" by arith |
|
1253 |
with xz have "?P ?z x (Ge (CN 0 c e))" |
|
1254 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp } |
|
1255 |
hence "\<forall> x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp |
|
1256 |
thus ?case by blast |
|
1257 |
qed simp_all |
|
1258 |
||
1259 |
lemma rminusinf_bound0: |
|
1260 |
assumes lp: "isrlfm p" |
|
1261 |
shows "bound0 (minusinf p)" |
|
1262 |
using lp |
|
1263 |
by (induct p rule: minusinf.induct) simp_all |
|
1264 |
||
1265 |
lemma rplusinf_bound0: |
|
1266 |
assumes lp: "isrlfm p" |
|
1267 |
shows "bound0 (plusinf p)" |
|
1268 |
using lp |
|
1269 |
by (induct p rule: plusinf.induct) simp_all |
|
1270 |
||
1271 |
lemma rminusinf_ex: |
|
1272 |
assumes lp: "isrlfm p" |
|
1273 |
and ex: "Ifm (a#bs) (minusinf p)" |
|
1274 |
shows "\<exists> x. Ifm (x#bs) p" |
|
1275 |
proof- |
|
1276 |
from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex |
|
1277 |
have th: "\<forall> x. Ifm (x#bs) (minusinf p)" by auto |
|
1278 |
from rminusinf_inf[OF lp, where bs="bs"] |
|
1279 |
obtain z where z_def: "\<forall>x<z. Ifm (x # bs) (minusinf p) = Ifm (x # bs) p" by blast |
|
1280 |
from th have "Ifm ((z - 1)#bs) (minusinf p)" by simp |
|
1281 |
moreover have "z - 1 < z" by simp |
|
1282 |
ultimately show ?thesis using z_def by auto |
|
1283 |
qed |
|
1284 |
||
1285 |
lemma rplusinf_ex: |
|
1286 |
assumes lp: "isrlfm p" |
|
1287 |
and ex: "Ifm (a#bs) (plusinf p)" |
|
1288 |
shows "\<exists> x. Ifm (x#bs) p" |
|
1289 |
proof- |
|
1290 |
from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex |
|
1291 |
have th: "\<forall> x. Ifm (x#bs) (plusinf p)" by auto |
|
1292 |
from rplusinf_inf[OF lp, where bs="bs"] |
|
1293 |
obtain z where z_def: "\<forall>x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast |
|
1294 |
from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp |
|
1295 |
moreover have "z + 1 > z" by simp |
|
1296 |
ultimately show ?thesis using z_def by auto |
|
1297 |
qed |
|
1298 |
||
1299 |
consts |
|
1300 |
uset:: "fm \<Rightarrow> (num \<times> int) list" |
|
1301 |
usubst :: "fm \<Rightarrow> (num \<times> int) \<Rightarrow> fm " |
|
1302 |
recdef uset "measure size" |
|
1303 |
"uset (And p q) = (uset p @ uset q)" |
|
1304 |
"uset (Or p q) = (uset p @ uset q)" |
|
1305 |
"uset (Eq (CN 0 c e)) = [(Neg e,c)]" |
|
1306 |
"uset (NEq (CN 0 c e)) = [(Neg e,c)]" |
|
1307 |
"uset (Lt (CN 0 c e)) = [(Neg e,c)]" |
|
1308 |
"uset (Le (CN 0 c e)) = [(Neg e,c)]" |
|
1309 |
"uset (Gt (CN 0 c e)) = [(Neg e,c)]" |
|
1310 |
"uset (Ge (CN 0 c e)) = [(Neg e,c)]" |
|
1311 |
"uset p = []" |
|
1312 |
recdef usubst "measure size" |
|
1313 |
"usubst (And p q) = (\<lambda> (t,n). And (usubst p (t,n)) (usubst q (t,n)))" |
|
1314 |
"usubst (Or p q) = (\<lambda> (t,n). Or (usubst p (t,n)) (usubst q (t,n)))" |
|
1315 |
"usubst (Eq (CN 0 c e)) = (\<lambda> (t,n). Eq (Add (Mul c t) (Mul n e)))" |
|
1316 |
"usubst (NEq (CN 0 c e)) = (\<lambda> (t,n). NEq (Add (Mul c t) (Mul n e)))" |
|
1317 |
"usubst (Lt (CN 0 c e)) = (\<lambda> (t,n). Lt (Add (Mul c t) (Mul n e)))" |
|
1318 |
"usubst (Le (CN 0 c e)) = (\<lambda> (t,n). Le (Add (Mul c t) (Mul n e)))" |
|
1319 |
"usubst (Gt (CN 0 c e)) = (\<lambda> (t,n). Gt (Add (Mul c t) (Mul n e)))" |
|
1320 |
"usubst (Ge (CN 0 c e)) = (\<lambda> (t,n). Ge (Add (Mul c t) (Mul n e)))" |
|
1321 |
"usubst p = (\<lambda> (t,n). p)" |
|
1322 |
||
1323 |
lemma usubst_I: assumes lp: "isrlfm p" |
|
1324 |
and np: "real n > 0" and nbt: "numbound0 t" |
|
1325 |
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> _") |
|
1326 |
using lp |
|
1327 |
proof(induct p rule: usubst.induct) |
|
41807 | 1328 |
case (5 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1329 |
have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)" |
1330 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
|
1331 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)" |
|
1332 |
by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
1333 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
|
1334 |
also have "\<dots> = (real c *?t + ?n* (?N x e) < 0)" |
|
1335 |
using np by simp |
|
1336 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
1337 |
next |
|
41807 | 1338 |
case (6 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1339 |
have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<le> 0)" |
1340 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
|
1341 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<le> 0)" |
|
1342 |
by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
1343 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
|
1344 |
also have "\<dots> = (real c *?t + ?n* (?N x e) \<le> 0)" |
|
1345 |
using np by simp |
|
1346 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
1347 |
next |
|
41807 | 1348 |
case (7 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1349 |
have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)" |
1350 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
|
1351 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)" |
|
1352 |
by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
1353 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
|
1354 |
also have "\<dots> = (real c *?t + ?n* (?N x e) > 0)" |
|
1355 |
using np by simp |
|
1356 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
1357 |
next |
|
41807 | 1358 |
case (8 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1359 |
have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<ge> 0)" |
1360 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
|
1361 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<ge> 0)" |
|
1362 |
by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
1363 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
|
1364 |
also have "\<dots> = (real c *?t + ?n* (?N x e) \<ge> 0)" |
|
1365 |
using np by simp |
|
1366 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
1367 |
next |
|
41807 | 1368 |
case (3 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1369 |
from np have np: "real n \<noteq> 0" by simp |
1370 |
have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 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) = 0)" |
|
1373 |
by (simp only: nonzero_eq_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) = 0)" |
|
1376 |
using np by simp |
|
1377 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
1378 |
next |
|
41807 | 1379 |
case (4 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1380 |
from np have np: "real n \<noteq> 0" by simp |
1381 |
have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<noteq> 0)" |
|
1382 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
|
1383 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<noteq> 0)" |
|
1384 |
by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
1385 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
|
1386 |
also have "\<dots> = (real c *?t + ?n* (?N x e) \<noteq> 0)" |
|
1387 |
using np by simp |
|
1388 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
|
41842 | 1389 |
qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"]) |
29789 | 1390 |
|
1391 |
lemma uset_l: |
|
1392 |
assumes lp: "isrlfm p" |
|
1393 |
shows "\<forall> (t,k) \<in> set (uset p). numbound0 t \<and> k >0" |
|
1394 |
using lp |
|
1395 |
by(induct p rule: uset.induct,auto) |
|
1396 |
||
1397 |
lemma rminusinf_uset: |
|
1398 |
assumes lp: "isrlfm p" |
|
1399 |
and nmi: "\<not> (Ifm (a#bs) (minusinf p))" (is "\<not> (Ifm (a#bs) (?M p))") |
|
1400 |
and ex: "Ifm (x#bs) p" (is "?I x p") |
|
1401 |
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") |
|
1402 |
proof- |
|
1403 |
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") |
|
1404 |
using lp nmi ex |
|
41842 | 1405 |
by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"]) |
29789 | 1406 |
then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<ge> ?N a s" by blast |
1407 |
from uset_l[OF lp] smU have mp: "real m > 0" by auto |
|
1408 |
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" |
|
1409 |
by (auto simp add: mult_commute) |
|
1410 |
thus ?thesis using smU by auto |
|
1411 |
qed |
|
1412 |
||
1413 |
lemma rplusinf_uset: |
|
1414 |
assumes lp: "isrlfm p" |
|
1415 |
and nmi: "\<not> (Ifm (a#bs) (plusinf p))" (is "\<not> (Ifm (a#bs) (?M p))") |
|
1416 |
and ex: "Ifm (x#bs) p" (is "?I x p") |
|
1417 |
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") |
|
1418 |
proof- |
|
1419 |
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") |
|
1420 |
using lp nmi ex |
|
41842 | 1421 |
by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"]) |
29789 | 1422 |
then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<le> ?N a s" by blast |
1423 |
from uset_l[OF lp] smU have mp: "real m > 0" by auto |
|
1424 |
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" |
|
1425 |
by (auto simp add: mult_commute) |
|
1426 |
thus ?thesis using smU by auto |
|
1427 |
qed |
|
1428 |
||
1429 |
lemma lin_dense: |
|
1430 |
assumes lp: "isrlfm p" |
|
1431 |
and noS: "\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> (\<lambda> (t,n). Inum (x#bs) t / real n) ` set (uset p)" |
|
1432 |
(is "\<forall> t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda> (t,n). ?N x t / real n ) ` (?U p)") |
|
1433 |
and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p" |
|
1434 |
and ly: "l < y" and yu: "y < u" |
|
1435 |
shows "Ifm (y#bs) p" |
|
1436 |
using lp px noS |
|
1437 |
proof (induct p rule: isrlfm.induct) |
|
1438 |
case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ |
|
41807 | 1439 |
from 5 have "x * real c + ?N x e < 0" by (simp add: algebra_simps) |
1440 |
hence pxc: "x < (- ?N x e) / real c" |
|
1441 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1442 |
from 5 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1443 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto |
|
1444 |
hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto |
|
1445 |
moreover {assume y: "y < (-?N x e)/ real c" |
|
1446 |
hence "y * real c < - ?N x e" |
|
1447 |
by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1448 |
hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) |
|
1449 |
hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} |
|
1450 |
moreover {assume y: "y > (- ?N x e) / real c" |
|
1451 |
with yu have eu: "u > (- ?N x e) / real c" by auto |
|
1452 |
with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto) |
|
1453 |
with lx pxc have "False" by auto |
|
1454 |
hence ?case by simp } |
|
1455 |
ultimately show ?case by blast |
|
29789 | 1456 |
next |
1457 |
case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp + |
|
41807 | 1458 |
from 6 have "x * real c + ?N x e \<le> 0" by (simp add: algebra_simps) |
1459 |
hence pxc: "x \<le> (- ?N x e) / real c" |
|
1460 |
by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1461 |
from 6 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1462 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto |
|
1463 |
hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto |
|
1464 |
moreover {assume y: "y < (-?N x e)/ real c" |
|
1465 |
hence "y * real c < - ?N x e" |
|
1466 |
by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1467 |
hence "real c * y + ?N x e < 0" by (simp add: algebra_simps) |
|
1468 |
hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} |
|
1469 |
moreover {assume y: "y > (- ?N x e) / real c" |
|
1470 |
with yu have eu: "u > (- ?N x e) / real c" by auto |
|
1471 |
with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto) |
|
1472 |
with lx pxc have "False" by auto |
|
1473 |
hence ?case by simp } |
|
1474 |
ultimately show ?case by blast |
|
29789 | 1475 |
next |
1476 |
case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ |
|
41807 | 1477 |
from 7 have "x * real c + ?N x e > 0" by (simp add: algebra_simps) |
1478 |
hence pxc: "x > (- ?N x e) / real c" |
|
1479 |
by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1480 |
from 7 have noSc: "\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1481 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto |
|
1482 |
hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto |
|
1483 |
moreover {assume y: "y > (-?N x e)/ real c" |
|
1484 |
hence "y * real c > - ?N x e" |
|
1485 |
by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1486 |
hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) |
|
1487 |
hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} |
|
1488 |
moreover {assume y: "y < (- ?N x e) / real c" |
|
1489 |
with ly have eu: "l < (- ?N x e) / real c" by auto |
|
1490 |
with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto) |
|
1491 |
with xu pxc have "False" by auto |
|
1492 |
hence ?case by simp } |
|
1493 |
ultimately show ?case by blast |
|
29789 | 1494 |
next |
1495 |
case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ |
|
41807 | 1496 |
from 8 have "x * real c + ?N x e \<ge> 0" by (simp add: algebra_simps) |
1497 |
hence pxc: "x \<ge> (- ?N x e) / real c" |
|
1498 |
by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1499 |
from 8 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1500 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto |
|
1501 |
hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto |
|
1502 |
moreover {assume y: "y > (-?N x e)/ real c" |
|
1503 |
hence "y * real c > - ?N x e" |
|
1504 |
by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1505 |
hence "real c * y + ?N x e > 0" by (simp add: algebra_simps) |
|
1506 |
hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp} |
|
1507 |
moreover {assume y: "y < (- ?N x e) / real c" |
|
1508 |
with ly have eu: "l < (- ?N x e) / real c" by auto |
|
1509 |
with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto) |
|
1510 |
with xu pxc have "False" by auto |
|
1511 |
hence ?case by simp } |
|
1512 |
ultimately show ?case by blast |
|
29789 | 1513 |
next |
1514 |
case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ |
|
41807 | 1515 |
from cp have cnz: "real c \<noteq> 0" by simp |
1516 |
from 3 have "x * real c + ?N x e = 0" by (simp add: algebra_simps) |
|
1517 |
hence pxc: "x = (- ?N x e) / real c" |
|
1518 |
by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"]) |
|
1519 |
from 3 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1520 |
with lx xu have yne: "x \<noteq> - ?N x e / real c" by auto |
|
1521 |
with pxc show ?case by simp |
|
29789 | 1522 |
next |
1523 |
case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+ |
|
41807 | 1524 |
from cp have cnz: "real c \<noteq> 0" by simp |
1525 |
from 4 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto |
|
1526 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto |
|
1527 |
hence "y* real c \<noteq> -?N x e" |
|
1528 |
by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp |
|
1529 |
hence "y* real c + ?N x e \<noteq> 0" by (simp add: algebra_simps) |
|
1530 |
thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] |
|
1531 |
by (simp add: algebra_simps) |
|
41842 | 1532 |
qed (auto simp add: numbound0_I[where bs="bs" and b="y" and b'="x"]) |
29789 | 1533 |
|
1534 |
lemma finite_set_intervals: |
|
1535 |
assumes px: "P (x::real)" |
|
1536 |
and lx: "l \<le> x" and xu: "x \<le> u" |
|
1537 |
and linS: "l\<in> S" and uinS: "u \<in> S" |
|
1538 |
and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u" |
|
1539 |
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" |
|
1540 |
proof- |
|
1541 |
let ?Mx = "{y. y\<in> S \<and> y \<le> x}" |
|
1542 |
let ?xM = "{y. y\<in> S \<and> x \<le> y}" |
|
1543 |
let ?a = "Max ?Mx" |
|
1544 |
let ?b = "Min ?xM" |
|
1545 |
have MxS: "?Mx \<subseteq> S" by blast |
|
1546 |
hence fMx: "finite ?Mx" using fS finite_subset by auto |
|
1547 |
from lx linS have linMx: "l \<in> ?Mx" by blast |
|
1548 |
hence Mxne: "?Mx \<noteq> {}" by blast |
|
1549 |
have xMS: "?xM \<subseteq> S" by blast |
|
1550 |
hence fxM: "finite ?xM" using fS finite_subset by auto |
|
1551 |
from xu uinS have linxM: "u \<in> ?xM" by blast |
|
1552 |
hence xMne: "?xM \<noteq> {}" by blast |
|
1553 |
have ax:"?a \<le> x" using Mxne fMx by auto |
|
1554 |
have xb:"x \<le> ?b" using xMne fxM by auto |
|
1555 |
have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast |
|
1556 |
have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast |
|
1557 |
have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S" |
|
1558 |
proof(clarsimp) |
|
1559 |
fix y |
|
1560 |
assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S" |
|
1561 |
from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by auto |
|
1562 |
moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto with ay have "False" by simp} |
|
1563 |
moreover {assume "y \<in> ?xM" hence "y \<ge> ?b" using xMne fxM by auto with yb have "False" by simp} |
|
1564 |
ultimately show "False" by blast |
|
1565 |
qed |
|
1566 |
from ainS binS noy ax xb px show ?thesis by blast |
|
1567 |
qed |
|
1568 |
||
1569 |
lemma rinf_uset: |
|
1570 |
assumes lp: "isrlfm p" |
|
1571 |
and nmi: "\<not> (Ifm (x#bs) (minusinf p))" (is "\<not> (Ifm (x#bs) (?M p))") |
|
1572 |
and npi: "\<not> (Ifm (x#bs) (plusinf p))" (is "\<not> (Ifm (x#bs) (?P p))") |
|
1573 |
and ex: "\<exists> x. Ifm (x#bs) p" (is "\<exists> x. ?I x p") |
|
1574 |
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" |
|
1575 |
proof- |
|
1576 |
let ?N = "\<lambda> x t. Inum (x#bs) t" |
|
1577 |
let ?U = "set (uset p)" |
|
1578 |
from ex obtain a where pa: "?I a p" by blast |
|
1579 |
from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi |
|
1580 |
have nmi': "\<not> (?I a (?M p))" by simp |
|
1581 |
from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi |
|
1582 |
have npi': "\<not> (?I a (?P p))" by simp |
|
1583 |
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" |
|
1584 |
proof- |
|
1585 |
let ?M = "(\<lambda> (t,c). ?N a t / real c) ` ?U" |
|
1586 |
have fM: "finite ?M" by auto |
|
1587 |
from rminusinf_uset[OF lp nmi pa] rplusinf_uset[OF lp npi pa] |
|
1588 |
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 |
|
1589 |
then obtain "t" "n" "s" "m" where |
|
1590 |
tnU: "(t,n) \<in> ?U" and smU: "(s,m) \<in> ?U" |
|
1591 |
and xs1: "a \<le> ?N x s / real m" and tx1: "a \<ge> ?N x t / real n" by blast |
|
1592 |
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 |
|
1593 |
from tnU have Mne: "?M \<noteq> {}" by auto |
|
1594 |
hence Une: "?U \<noteq> {}" by simp |
|
1595 |
let ?l = "Min ?M" |
|
1596 |
let ?u = "Max ?M" |
|
1597 |
have linM: "?l \<in> ?M" using fM Mne by simp |
|
1598 |
have uinM: "?u \<in> ?M" using fM Mne by simp |
|
1599 |
have tnM: "?N a t / real n \<in> ?M" using tnU by auto |
|
1600 |
have smM: "?N a s / real m \<in> ?M" using smU by auto |
|
1601 |
have lM: "\<forall> t\<in> ?M. ?l \<le> t" using Mne fM by auto |
|
1602 |
have Mu: "\<forall> t\<in> ?M. t \<le> ?u" using Mne fM by auto |
|
1603 |
have "?l \<le> ?N a t / real n" using tnM Mne by simp hence lx: "?l \<le> a" using tx by simp |
|
1604 |
have "?N a s / real m \<le> ?u" using smM Mne by simp hence xu: "a \<le> ?u" using xs by simp |
|
1605 |
from finite_set_intervals2[where P="\<lambda> x. ?I x p",OF pa lx xu linM uinM fM lM Mu] |
|
1606 |
have "(\<exists> s\<in> ?M. ?I s p) \<or> |
|
1607 |
(\<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)" . |
|
1608 |
moreover { fix u assume um: "u\<in> ?M" and pu: "?I u p" |
|
1609 |
hence "\<exists> (tu,nu) \<in> ?U. u = ?N a tu / real nu" by auto |
|
1610 |
then obtain "tu" "nu" where tuU: "(tu,nu) \<in> ?U" and tuu:"u= ?N a tu / real nu" by blast |
|
1611 |
have "(u + u) / 2 = u" by auto with pu tuu |
|
1612 |
have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp |
|
1613 |
with tuU have ?thesis by blast} |
|
1614 |
moreover{ |
|
1615 |
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" |
|
1616 |
then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
1617 |
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" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
1618 |
by blast |
29789 | 1619 |
from t1M have "\<exists> (t1u,t1n) \<in> ?U. t1 = ?N a t1u / real t1n" by auto |
1620 |
then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \<in> ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast |
|
1621 |
from t2M have "\<exists> (t2u,t2n) \<in> ?U. t2 = ?N a t2u / real t2n" by auto |
|
1622 |
then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \<in> ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast |
|
1623 |
from t1x xt2 have t1t2: "t1 < t2" by simp |
|
1624 |
let ?u = "(t1 + t2) / 2" |
|
1625 |
from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto |
|
1626 |
from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" . |
|
1627 |
with t1uU t2uU t1u t2u have ?thesis by blast} |
|
1628 |
ultimately show ?thesis by blast |
|
1629 |
qed |
|
1630 |
then obtain "l" "n" "s" "m" where lnU: "(l,n) \<in> ?U" and smU:"(s,m) \<in> ?U" |
|
1631 |
and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast |
|
1632 |
from lnU smU uset_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto |
|
1633 |
from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] |
|
1634 |
numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu |
|
1635 |
have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp |
|
1636 |
with lnU smU |
|
1637 |
show ?thesis by auto |
|
1638 |
qed |
|
1639 |
(* The Ferrante - Rackoff Theorem *) |
|
1640 |
||
1641 |
theorem fr_eq: |
|
1642 |
assumes lp: "isrlfm p" |
|
1643 |
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))" |
|
1644 |
(is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D") |
|
1645 |
proof |
|
1646 |
assume px: "\<exists> x. ?I x p" |
|
1647 |
have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast |
|
1648 |
moreover {assume "?M \<or> ?P" hence "?D" by blast} |
|
1649 |
moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P" |
|
1650 |
from rinf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast} |
|
1651 |
ultimately show "?D" by blast |
|
1652 |
next |
|
1653 |
assume "?D" |
|
1654 |
moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} |
|
1655 |
moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } |
|
1656 |
moreover {assume f:"?F" hence "?E" by blast} |
|
1657 |
ultimately show "?E" by blast |
|
1658 |
qed |
|
1659 |
||
1660 |
||
1661 |
lemma fr_equsubst: |
|
1662 |
assumes lp: "isrlfm p" |
|
1663 |
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))))" |
|
1664 |
(is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D") |
|
1665 |
proof |
|
1666 |
assume px: "\<exists> x. ?I x p" |
|
1667 |
have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast |
|
1668 |
moreover {assume "?M \<or> ?P" hence "?D" by blast} |
|
1669 |
moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P" |
|
1670 |
let ?f ="\<lambda> (t,n). Inum (x#bs) t / real n" |
|
1671 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1672 |
{fix t n s m assume "(t,n)\<in> set (uset p)" and "(s,m) \<in> set (uset p)" |
|
1673 |
with uset_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
1674 |
by auto |
29789 | 1675 |
let ?st = "Add (Mul m t) (Mul n s)" |
1676 |
from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
1677 |
by (simp add: mult_commute) |
29789 | 1678 |
from tnb snb have st_nb: "numbound0 ?st" by simp |
1679 |
have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
1680 |
using mnp mp np by (simp add: algebra_simps add_divide_distrib) |
29789 | 1681 |
from usubst_I[OF lp mnp st_nb, where x="x" and bs="bs"] |
1682 |
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])} |
|
1683 |
with rinf_uset[OF lp nmi npi px] have "?F" by blast hence "?D" by blast} |
|
1684 |
ultimately show "?D" by blast |
|
1685 |
next |
|
1686 |
assume "?D" |
|
1687 |
moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .} |
|
1688 |
moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . } |
|
1689 |
moreover {fix t k s l assume "(t,k) \<in> set (uset p)" and "(s,l) \<in> set (uset p)" |
|
1690 |
and px:"?I x (usubst p (Add (Mul l t) (Mul k s), 2*k*l))" |
|
1691 |
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 |
|
1692 |
let ?st = "Add (Mul l t) (Mul k s)" |
|
1693 |
from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0" |
|
1694 |
by (simp add: mult_commute) |
|
1695 |
from tnb snb have st_nb: "numbound0 ?st" by simp |
|
1696 |
from usubst_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto} |
|
1697 |
ultimately show "?E" by blast |
|
1698 |
qed |
|
1699 |
||
1700 |
||
1701 |
(* Implement the right hand side of Ferrante and Rackoff's Theorem. *) |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
33639
diff
changeset
|
1702 |
definition ferrack :: "fm \<Rightarrow> fm" where |
36853 | 1703 |
"ferrack p = (let p' = rlfm (simpfm p); mp = minusinf p'; pp = plusinf p' |
29789 | 1704 |
in if (mp = T \<or> pp = T) then T else |
36853 | 1705 |
(let U = remdups(map simp_num_pair |
29789 | 1706 |
(map (\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) |
1707 |
(alluopairs (uset p')))) |
|
1708 |
in decr (disj mp (disj pp (evaldjf (simpfm o (usubst p')) U)))))" |
|
1709 |
||
1710 |
lemma uset_cong_aux: |
|
1711 |
assumes Ul: "\<forall> (t,n) \<in> set U. numbound0 t \<and> n >0" |
|
1712 |
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))" |
|
1713 |
(is "?lhs = ?rhs") |
|
1714 |
proof(auto) |
|
1715 |
fix t n s m |
|
1716 |
assume "((t,n),(s,m)) \<in> set (alluopairs U)" |
|
1717 |
hence th: "((t,n),(s,m)) \<in> (set U \<times> set U)" |
|
1718 |
using alluopairs_set1[where xs="U"] by blast |
|
1719 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1720 |
let ?st= "Add (Mul m t) (Mul n s)" |
|
1721 |
from Ul th have mnz: "m \<noteq> 0" by auto |
|
1722 |
from Ul th have nnz: "n \<noteq> 0" by auto |
|
1723 |
have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" |
|
1724 |
using mnz nnz by (simp add: algebra_simps add_divide_distrib) |
|
1725 |
||
1726 |
thus "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) / |
|
1727 |
(2 * real n * real m) |
|
1728 |
\<in> (\<lambda>((t, n), s, m). |
|
1729 |
(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` |
|
1730 |
(set U \<times> set U)"using mnz nnz th |
|
1731 |
apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def) |
|
1732 |
by (rule_tac x="(s,m)" in bexI,simp_all) |
|
1733 |
(rule_tac x="(t,n)" in bexI,simp_all) |
|
1734 |
next |
|
1735 |
fix t n s m |
|
1736 |
assume tnU: "(t,n) \<in> set U" and smU:"(s,m) \<in> set U" |
|
1737 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1738 |
let ?st= "Add (Mul m t) (Mul n s)" |
|
1739 |
from Ul smU have mnz: "m \<noteq> 0" by auto |
|
1740 |
from Ul tnU have nnz: "n \<noteq> 0" by auto |
|
1741 |
have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" |
|
1742 |
using mnz nnz by (simp add: algebra_simps add_divide_distrib) |
|
1743 |
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" |
|
1744 |
have Pc:"\<forall> a b. ?P a b = ?P b a" |
|
1745 |
by auto |
|
1746 |
from Ul alluopairs_set1 have Up:"\<forall> ((t,n),(s,m)) \<in> set (alluopairs U). n \<noteq> 0 \<and> m \<noteq> 0" by blast |
|
1747 |
from alluopairs_ex[OF Pc, where xs="U"] tnU smU |
|
1748 |
have th':"\<exists> ((t',n'),(s',m')) \<in> set (alluopairs U). ?P (t',n') (s',m')" |
|
1749 |
by blast |
|
1750 |
then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \<in> set (alluopairs U)" |
|
1751 |
and Pts': "?P (t',n') (s',m')" by blast |
|
1752 |
from ts'_U Up have mnz': "m' \<noteq> 0" and nnz': "n'\<noteq> 0" by auto |
|
1753 |
let ?st' = "Add (Mul m' t') (Mul n' s')" |
|
1754 |
have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')" |
|
1755 |
using mnz' nnz' by (simp add: algebra_simps add_divide_distrib) |
|
1756 |
from Pts' have |
|
1757 |
"(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 |
|
1758 |
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') |
|
1759 |
finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 |
|
1760 |
\<in> (\<lambda>(t, n). Inum (x # bs) t / real n) ` |
|
1761 |
(\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ` |
|
1762 |
set (alluopairs U)" |
|
1763 |
using ts'_U by blast |
|
1764 |
qed |
|
1765 |
||
1766 |
lemma uset_cong: |
|
1767 |
assumes lp: "isrlfm p" |
|
1768 |
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)") |
|
1769 |
and U: "\<forall> (t,n) \<in> U. numbound0 t \<and> n > 0" |
|
1770 |
and U': "\<forall> (t,n) \<in> U'. numbound0 t \<and> n > 0" |
|
1771 |
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)))" |
|
1772 |
(is "?lhs = ?rhs") |
|
1773 |
proof |
|
1774 |
assume ?lhs |
|
1775 |
then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and |
|
1776 |
Pst: "Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))" by blast |
|
1777 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1778 |
from tnU smU U have tnb: "numbound0 t" and np: "n > 0" |
|
1779 |
and snb: "numbound0 s" and mp:"m > 0" by auto |
|
1780 |
let ?st= "Add (Mul m t) (Mul n s)" |
|
1781 |
from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" |
|
1782 |
by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) |
|
1783 |
from tnb snb have stnb: "numbound0 ?st" by simp |
|
1784 |
have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" |
|
1785 |
using mp np by (simp add: algebra_simps add_divide_distrib) |
|
1786 |
from tnU smU UU' have "?g ((t,n),(s,m)) \<in> ?f ` U'" by blast |
|
1787 |
hence "\<exists> (t',n') \<in> U'. ?g ((t,n),(s,m)) = ?f (t',n')" |
|
1788 |
by auto (rule_tac x="(a,b)" in bexI, auto) |
|
1789 |
then obtain t' n' where tnU': "(t',n') \<in> U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast |
|
1790 |
from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto |
|
1791 |
from usubst_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst |
|
1792 |
have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp |
|
1793 |
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]] |
|
1794 |
have "Ifm (x # bs) (usubst p (t', n')) " by (simp only: st) |
|
1795 |
then show ?rhs using tnU' by auto |
|
1796 |
next |
|
1797 |
assume ?rhs |
|
1798 |
then obtain t' n' where tnU': "(t',n') \<in> U'" and Pt': "Ifm (x # bs) (usubst p (t', n'))" |
|
1799 |
by blast |
|
1800 |
from tnU' UU' have "?f (t',n') \<in> ?g ` (U\<times>U)" by blast |
|
1801 |
hence "\<exists> ((t,n),(s,m)) \<in> (U\<times>U). ?f (t',n') = ?g ((t,n),(s,m))" |
|
1802 |
by auto (rule_tac x="(a,b)" in bexI, auto) |
|
1803 |
then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and |
|
1804 |
th: "?f (t',n') = ?g((t,n),(s,m)) "by blast |
|
1805 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1806 |
from tnU smU U have tnb: "numbound0 t" and np: "n > 0" |
|
1807 |
and snb: "numbound0 s" and mp:"m > 0" by auto |
|
1808 |
let ?st= "Add (Mul m t) (Mul n s)" |
|
1809 |
from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" |
|
1810 |
by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult) |
|
1811 |
from tnb snb have stnb: "numbound0 ?st" by simp |
|
1812 |
have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)" |
|
1813 |
using mp np by (simp add: algebra_simps add_divide_distrib) |
|
1814 |
from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto |
|
1815 |
from usubst_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt' |
|
1816 |
have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp |
|
1817 |
with usubst_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast |
|
1818 |
qed |
|
1819 |
||
1820 |
lemma ferrack: |
|
1821 |
assumes qf: "qfree p" |
|
1822 |
shows "qfree (ferrack p) \<and> ((Ifm bs (ferrack p)) = (\<exists> x. Ifm (x#bs) p))" |
|
1823 |
(is "_ \<and> (?rhs = ?lhs)") |
|
1824 |
proof- |
|
1825 |
let ?I = "\<lambda> x p. Ifm (x#bs) p" |
|
1826 |
fix x |
|
1827 |
let ?N = "\<lambda> t. Inum (x#bs) t" |
|
1828 |
let ?q = "rlfm (simpfm p)" |
|
1829 |
let ?U = "uset ?q" |
|
1830 |
let ?Up = "alluopairs ?U" |
|
1831 |
let ?g = "\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)" |
|
1832 |
let ?S = "map ?g ?Up" |
|
1833 |
let ?SS = "map simp_num_pair ?S" |
|
36853 | 1834 |
let ?Y = "remdups ?SS" |
29789 | 1835 |
let ?f= "(\<lambda> (t,n). ?N t / real n)" |
1836 |
let ?h = "\<lambda> ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2" |
|
1837 |
let ?F = "\<lambda> p. \<exists> a \<in> set (uset p). \<exists> b \<in> set (uset p). ?I x (usubst p (?g(a,b)))" |
|
1838 |
let ?ep = "evaldjf (simpfm o (usubst ?q)) ?Y" |
|
1839 |
from rlfm_I[OF simpfm_qf[OF qf]] have lq: "isrlfm ?q" by blast |
|
1840 |
from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \<le> (set ?U \<times> set ?U)" by simp |
|
1841 |
from uset_l[OF lq] have U_l: "\<forall> (t,n) \<in> set ?U. numbound0 t \<and> n > 0" . |
|
1842 |
from U_l UpU |
|
1843 |
have "\<forall> ((t,n),(s,m)) \<in> set ?Up. numbound0 t \<and> n> 0 \<and> numbound0 s \<and> m > 0" by auto |
|
1844 |
hence Snb: "\<forall> (t,n) \<in> set ?S. numbound0 t \<and> n > 0 " |
|
1845 |
by (auto simp add: mult_pos_pos) |
|
1846 |
have Y_l: "\<forall> (t,n) \<in> set ?Y. numbound0 t \<and> n > 0" |
|
1847 |
proof- |
|
1848 |
{ fix t n assume tnY: "(t,n) \<in> set ?Y" |
|
1849 |
hence "(t,n) \<in> set ?SS" by simp |
|
1850 |
hence "\<exists> (t',n') \<in> set ?S. simp_num_pair (t',n') = (t,n)" |
|
33639
603320b93668
New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents:
33063
diff
changeset
|
1851 |
by (auto simp add: split_def simp del: map_map) |
603320b93668
New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents:
33063
diff
changeset
|
1852 |
(rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all) |
29789 | 1853 |
then obtain t' n' where tn'S: "(t',n') \<in> set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast |
1854 |
from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto |
|
1855 |
from simp_num_pair_l[OF tnb np tns] |
|
1856 |
have "numbound0 t \<and> n > 0" . } |
|
1857 |
thus ?thesis by blast |
|
1858 |
qed |
|
1859 |
||
1860 |
have YU: "(?f ` set ?Y) = (?h ` (set ?U \<times> set ?U))" |
|
1861 |
proof- |
|
1862 |
from simp_num_pair_ci[where bs="x#bs"] have |
|
1863 |
"\<forall>x. (?f o simp_num_pair) x = ?f x" by auto |
|
1864 |
hence th: "?f o simp_num_pair = ?f" using ext by blast |
|
1865 |
have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose) |
|
1866 |
also have "\<dots> = (?f ` set ?S)" by (simp add: th) |
|
1867 |
also have "\<dots> = ((?f o ?g) ` set ?Up)" |
|
1868 |
by (simp only: set_map o_def image_compose[symmetric]) |
|
1869 |
also have "\<dots> = (?h ` (set ?U \<times> set ?U))" |
|
1870 |
using uset_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast |
|
1871 |
finally show ?thesis . |
|
1872 |
qed |
|
1873 |
have "\<forall> (t,n) \<in> set ?Y. bound0 (simpfm (usubst ?q (t,n)))" |
|
1874 |
proof- |
|
1875 |
{ fix t n assume tnY: "(t,n) \<in> set ?Y" |
|
1876 |
with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto |
|
1877 |
from usubst_I[OF lq np tnb] |
|
1878 |
have "bound0 (usubst ?q (t,n))" by simp hence "bound0 (simpfm (usubst ?q (t,n)))" |
|
1879 |
using simpfm_bound0 by simp} |
|
1880 |
thus ?thesis by blast |
|
1881 |
qed |
|
1882 |
hence ep_nb: "bound0 ?ep" using evaldjf_bound0[where xs="?Y" and f="simpfm o (usubst ?q)"] by auto |
|
1883 |
let ?mp = "minusinf ?q" |
|
1884 |
let ?pp = "plusinf ?q" |
|
1885 |
let ?M = "?I x ?mp" |
|
1886 |
let ?P = "?I x ?pp" |
|
1887 |
let ?res = "disj ?mp (disj ?pp ?ep)" |
|
1888 |
from rminusinf_bound0[OF lq] rplusinf_bound0[OF lq] ep_nb |
|
1889 |
have nbth: "bound0 ?res" by auto |
|
1890 |
||
1891 |
from conjunct1[OF rlfm_I[OF simpfm_qf[OF qf]]] simpfm |
|
1892 |
||
1893 |
have th: "?lhs = (\<exists> x. ?I x ?q)" by auto |
|
1894 |
from th fr_equsubst[OF lq, where bs="bs" and x="x"] have lhfr: "?lhs = (?M \<or> ?P \<or> ?F ?q)" |
|
1895 |
by (simp only: split_def fst_conv snd_conv) |
|
1896 |
also have "\<dots> = (?M \<or> ?P \<or> (\<exists> (t,n) \<in> set ?Y. ?I x (simpfm (usubst ?q (t,n)))))" |
|
1897 |
using uset_cong[OF lq YU U_l Y_l] by (simp only: split_def fst_conv snd_conv simpfm) |
|
1898 |
also have "\<dots> = (Ifm (x#bs) ?res)" |
|
1899 |
using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="simpfm o (usubst ?q)",symmetric] |
|
1900 |
by (simp add: split_def pair_collapse) |
|
1901 |
finally have lheq: "?lhs = (Ifm bs (decr ?res))" using decr[OF nbth] by blast |
|
1902 |
hence lr: "?lhs = ?rhs" apply (unfold ferrack_def Let_def) |
|
1903 |
by (cases "?mp = T \<or> ?pp = T", auto) (simp add: disj_def)+ |
|
1904 |
from decr_qf[OF nbth] have "qfree (ferrack p)" by (auto simp add: Let_def ferrack_def) |
|
1905 |
with lr show ?thesis by blast |
|
1906 |
qed |
|
1907 |
||
1908 |
definition linrqe:: "fm \<Rightarrow> fm" where |
|
1909 |
"linrqe p = qelim (prep p) ferrack" |
|
1910 |
||
1911 |
theorem linrqe: "Ifm bs (linrqe p) = Ifm bs p \<and> qfree (linrqe p)" |
|
1912 |
using ferrack qelim_ci prep |
|
1913 |
unfolding linrqe_def by auto |
|
1914 |
||
1915 |
definition ferrack_test :: "unit \<Rightarrow> fm" where |
|
1916 |
"ferrack_test u = linrqe (A (A (Imp (Lt (Sub (Bound 1) (Bound 0))) |
|
1917 |
(E (Eq (Sub (Add (Bound 0) (Bound 2)) (Bound 1)))))))" |
|
1918 |
||
1919 |
ML {* @{code ferrack_test} () *} |
|
1920 |
||
1921 |
oracle linr_oracle = {* |
|
1922 |
let |
|
1923 |
||
36853 | 1924 |
fun num_of_term vs (Free vT) = @{code Bound} (find_index (fn vT' => vT = vT') vs) |
29789 | 1925 |
| num_of_term vs @{term "real (0::int)"} = @{code C} 0 |
1926 |
| num_of_term vs @{term "real (1::int)"} = @{code C} 1 |
|
1927 |
| num_of_term vs @{term "0::real"} = @{code C} 0 |
|
1928 |
| num_of_term vs @{term "1::real"} = @{code C} 1 |
|
1929 |
| num_of_term vs (Bound i) = @{code Bound} i |
|
1930 |
| num_of_term vs (@{term "uminus :: real \<Rightarrow> real"} $ t') = @{code Neg} (num_of_term vs t') |
|
36853 | 1931 |
| num_of_term vs (@{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = |
1932 |
@{code Add} (num_of_term vs t1, num_of_term vs t2) |
|
1933 |
| num_of_term vs (@{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = |
|
1934 |
@{code Sub} (num_of_term vs t1, num_of_term vs t2) |
|
1935 |
| num_of_term vs (@{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = (case num_of_term vs t1 |
|
29789 | 1936 |
of @{code C} i => @{code Mul} (i, num_of_term vs t2) |
36853 | 1937 |
| _ => error "num_of_term: unsupported multiplication") |
1938 |
| num_of_term vs (@{term "real :: int \<Rightarrow> real"} $ (@{term "number_of :: int \<Rightarrow> int"} $ t')) = |
|
1939 |
@{code C} (HOLogic.dest_numeral t') |
|
1940 |
| num_of_term vs (@{term "number_of :: int \<Rightarrow> real"} $ t') = |
|
1941 |
@{code C} (HOLogic.dest_numeral t') |
|
1942 |
| num_of_term vs t = error ("num_of_term: unknown term"); |
|
29789 | 1943 |
|
1944 |
fun fm_of_term vs @{term True} = @{code T} |
|
1945 |
| fm_of_term vs @{term False} = @{code F} |
|
36853 | 1946 |
| fm_of_term vs (@{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
1947 |
@{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
|
1948 |
| fm_of_term vs (@{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
|
1949 |
@{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
|
1950 |
| fm_of_term vs (@{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
|
1951 |
@{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
|
1952 |
| fm_of_term vs (@{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ t1 $ t2) = |
|
1953 |
@{code Iff} (fm_of_term vs t1, fm_of_term vs t2) |
|
38795
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
1954 |
| fm_of_term vs (@{term HOL.conj} $ t1 $ t2) = @{code And} (fm_of_term vs t1, fm_of_term vs t2) |
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
1955 |
| fm_of_term vs (@{term HOL.disj} $ t1 $ t2) = @{code Or} (fm_of_term vs t1, fm_of_term vs t2) |
38786
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
haftmann
parents:
38558
diff
changeset
|
1956 |
| fm_of_term vs (@{term HOL.implies} $ t1 $ t2) = @{code Imp} (fm_of_term vs t1, fm_of_term vs t2) |
29789 | 1957 |
| fm_of_term vs (@{term "Not"} $ t') = @{code NOT} (fm_of_term vs t') |
38558 | 1958 |
| fm_of_term vs (Const (@{const_name Ex}, _) $ Abs (xn, xT, p)) = |
36853 | 1959 |
@{code E} (fm_of_term (("", dummyT) :: vs) p) |
38558 | 1960 |
| fm_of_term vs (Const (@{const_name All}, _) $ Abs (xn, xT, p)) = |
36853 | 1961 |
@{code A} (fm_of_term (("", dummyT) :: vs) p) |
29789 | 1962 |
| fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); |
1963 |
||
1964 |
fun term_of_num vs (@{code C} i) = @{term "real :: int \<Rightarrow> real"} $ HOLogic.mk_number HOLogic.intT i |
|
36853 | 1965 |
| term_of_num vs (@{code Bound} n) = Free (nth vs n) |
29789 | 1966 |
| term_of_num vs (@{code Neg} t') = @{term "uminus :: real \<Rightarrow> real"} $ term_of_num vs t' |
1967 |
| term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
1968 |
term_of_num vs t1 $ term_of_num vs t2 |
|
1969 |
| term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
1970 |
term_of_num vs t1 $ term_of_num vs t2 |
|
1971 |
| term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
1972 |
term_of_num vs (@{code C} i) $ term_of_num vs t2 |
|
1973 |
| term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)); |
|
1974 |
||
1975 |
fun term_of_fm vs @{code T} = HOLogic.true_const |
|
1976 |
| term_of_fm vs @{code F} = HOLogic.false_const |
|
1977 |
| term_of_fm vs (@{code Lt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
1978 |
term_of_num vs t $ @{term "0::real"} |
|
1979 |
| term_of_fm vs (@{code Le} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
1980 |
term_of_num vs t $ @{term "0::real"} |
|
1981 |
| term_of_fm vs (@{code Gt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
1982 |
@{term "0::real"} $ term_of_num vs t |
|
1983 |
| term_of_fm vs (@{code Ge} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
1984 |
@{term "0::real"} $ term_of_num vs t |
|
1985 |
| term_of_fm vs (@{code Eq} t) = @{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
1986 |
term_of_num vs t $ @{term "0::real"} |
|
1987 |
| term_of_fm vs (@{code NEq} t) = term_of_fm vs (@{code NOT} (@{code Eq} t)) |
|
1988 |
| term_of_fm vs (@{code NOT} t') = HOLogic.Not $ term_of_fm vs t' |
|
1989 |
| term_of_fm vs (@{code And} (t1, t2)) = HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
1990 |
| term_of_fm vs (@{code Or} (t1, t2)) = HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
1991 |
| term_of_fm vs (@{code Imp} (t1, t2)) = HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
1992 |
| term_of_fm vs (@{code Iff} (t1, t2)) = @{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ |
|
36853 | 1993 |
term_of_fm vs t1 $ term_of_fm vs t2; |
29789 | 1994 |
|
36853 | 1995 |
in fn (ctxt, t) => |
29789 | 1996 |
let |
36853 | 1997 |
val vs = Term.add_frees t []; |
1998 |
val t' = (term_of_fm vs o @{code linrqe} o fm_of_term vs) t; |
|
42361 | 1999 |
in (Thm.cterm_of (Proof_Context.theory_of ctxt) o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end |
29789 | 2000 |
end; |
2001 |
*} |
|
2002 |
||
2003 |
use "ferrack_tac.ML" |
|
2004 |
setup Ferrack_Tac.setup |
|
2005 |
||
2006 |
lemma |
|
2007 |
fixes x :: real |
|
2008 |
shows "2 * x \<le> 2 * x \<and> 2 * x \<le> 2 * x + 1" |
|
2009 |
apply rferrack |
|
2010 |
done |
|
2011 |
||
2012 |
lemma |
|
2013 |
fixes x :: real |
|
2014 |
shows "\<exists>y \<le> x. x = y + 1" |
|
2015 |
apply rferrack |
|
2016 |
done |
|
2017 |
||
2018 |
lemma |
|
2019 |
fixes x :: real |
|
2020 |
shows "\<not> (\<exists>z. x + z = x + z + 1)" |
|
2021 |
apply rferrack |
|
2022 |
done |
|
2023 |
||
2024 |
end |