author | wenzelm |
Thu, 05 Nov 2015 10:39:59 +0100 | |
changeset 61586 | 5197a2ecb658 |
parent 61424 | c3658c18b7bc |
child 61610 | 4f54d2759a0b |
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 |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
7 |
"~~/src/HOL/Library/Code_Target_Numeral" "~~/src/HOL/Library/Old_Recdef" |
29789 | 8 |
begin |
9 |
||
61586 | 10 |
section \<open>Quantifier elimination for \<open>\<real> (0, 1, +, <)\<close>\<close> |
29789 | 11 |
|
12 |
(*********************************************************************************) |
|
13 |
(**** SHADOW SYNTAX AND SEMANTICS ****) |
|
14 |
(*********************************************************************************) |
|
15 |
||
60710 | 16 |
datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num |
17 |
| Mul int num |
|
29789 | 18 |
|
19 |
(* A size for num to make inductive proofs simpler*) |
|
60710 | 20 |
primrec num_size :: "num \<Rightarrow> nat" |
21 |
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) *) |
|
60710 | 31 |
primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" |
32 |
where |
|
29789 | 33 |
"Inum bs (C c) = (real c)" |
36853 | 34 |
| "Inum bs (Bound n) = bs!n" |
35 |
| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)" |
|
36 |
| "Inum bs (Neg a) = -(Inum bs a)" |
|
37 |
| "Inum bs (Add a b) = Inum bs a + Inum bs b" |
|
38 |
| "Inum bs (Sub a b) = Inum bs a - Inum bs b" |
|
39 |
| "Inum bs (Mul c a) = (real c) * Inum bs a" |
|
29789 | 40 |
(* FORMULAE *) |
60710 | 41 |
datatype fm = |
29789 | 42 |
T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| |
43 |
NOT fm| And fm fm| Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm |
|
44 |
||
45 |
||
46 |
(* A size for fm *) |
|
60710 | 47 |
fun fmsize :: "fm \<Rightarrow> nat" |
48 |
where |
|
29789 | 49 |
"fmsize (NOT p) = 1 + fmsize p" |
36853 | 50 |
| "fmsize (And p q) = 1 + fmsize p + fmsize q" |
51 |
| "fmsize (Or p q) = 1 + fmsize p + fmsize q" |
|
52 |
| "fmsize (Imp p q) = 3 + fmsize p + fmsize q" |
|
53 |
| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)" |
|
54 |
| "fmsize (E p) = 1 + fmsize p" |
|
55 |
| "fmsize (A p) = 4+ fmsize p" |
|
56 |
| "fmsize p = 1" |
|
29789 | 57 |
(* several lemmas about fmsize *) |
60710 | 58 |
|
29789 | 59 |
lemma fmsize_pos: "fmsize p > 0" |
60710 | 60 |
by (induct p rule: fmsize.induct) simp_all |
29789 | 61 |
|
62 |
(* Semantics of formulae (fm) *) |
|
60710 | 63 |
primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" |
64 |
where |
|
29789 | 65 |
"Ifm bs T = True" |
36853 | 66 |
| "Ifm bs F = False" |
67 |
| "Ifm bs (Lt a) = (Inum bs a < 0)" |
|
68 |
| "Ifm bs (Gt a) = (Inum bs a > 0)" |
|
69 |
| "Ifm bs (Le a) = (Inum bs a \<le> 0)" |
|
70 |
| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)" |
|
71 |
| "Ifm bs (Eq a) = (Inum bs a = 0)" |
|
72 |
| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)" |
|
73 |
| "Ifm bs (NOT p) = (\<not> (Ifm bs p))" |
|
74 |
| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)" |
|
75 |
| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)" |
|
76 |
| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))" |
|
77 |
| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)" |
|
60710 | 78 |
| "Ifm bs (E p) = (\<exists>x. Ifm (x#bs) p)" |
79 |
| "Ifm bs (A p) = (\<forall>x. Ifm (x#bs) p)" |
|
29789 | 80 |
|
81 |
lemma IfmLeSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Le (Sub s t)) = (s' \<le> t')" |
|
60710 | 82 |
by simp |
29789 | 83 |
|
84 |
lemma IfmLtSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Lt (Sub s t)) = (s' < t')" |
|
60710 | 85 |
by simp |
86 |
||
29789 | 87 |
lemma IfmEqSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Eq (Sub s t)) = (s' = t')" |
60710 | 88 |
by simp |
89 |
||
29789 | 90 |
lemma IfmNOT: " (Ifm bs p = P) \<Longrightarrow> (Ifm bs (NOT p) = (\<not>P))" |
60710 | 91 |
by simp |
92 |
||
29789 | 93 |
lemma IfmAnd: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (And p q) = (P \<and> Q))" |
60710 | 94 |
by simp |
95 |
||
29789 | 96 |
lemma IfmOr: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Or p q) = (P \<or> Q))" |
60710 | 97 |
by simp |
98 |
||
29789 | 99 |
lemma IfmImp: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Imp p q) = (P \<longrightarrow> Q))" |
60710 | 100 |
by simp |
101 |
||
29789 | 102 |
lemma IfmIff: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Iff p q) = (P = Q))" |
60710 | 103 |
by simp |
29789 | 104 |
|
105 |
lemma IfmE: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (E p) = (\<exists>x. P x))" |
|
60710 | 106 |
by simp |
107 |
||
29789 | 108 |
lemma IfmA: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (A p) = (\<forall>x. P x))" |
60710 | 109 |
by simp |
29789 | 110 |
|
60710 | 111 |
fun not:: "fm \<Rightarrow> fm" |
112 |
where |
|
29789 | 113 |
"not (NOT p) = p" |
36853 | 114 |
| "not T = F" |
115 |
| "not F = T" |
|
116 |
| "not p = NOT p" |
|
60710 | 117 |
|
29789 | 118 |
lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)" |
60710 | 119 |
by (cases p) auto |
29789 | 120 |
|
60710 | 121 |
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" |
122 |
where |
|
123 |
"conj p q = |
|
124 |
(if p = F \<or> q = F then F |
|
125 |
else if p = T then q |
|
126 |
else if q = T then p |
|
127 |
else if p = q then p else And p q)" |
|
128 |
||
29789 | 129 |
lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)" |
60710 | 130 |
by (cases "p = F \<or> q = F", simp_all add: conj_def) (cases p, simp_all) |
29789 | 131 |
|
60710 | 132 |
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" |
133 |
where |
|
134 |
"disj p q = |
|
135 |
(if p = T \<or> q = T then T |
|
136 |
else if p = F then q |
|
137 |
else if q = F then p |
|
138 |
else if p = q then p else Or p q)" |
|
29789 | 139 |
|
140 |
lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)" |
|
60710 | 141 |
by (cases "p = T \<or> q = T", simp_all add: disj_def) (cases p, simp_all) |
29789 | 142 |
|
60710 | 143 |
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" |
144 |
where |
|
145 |
"imp p q = |
|
146 |
(if p = F \<or> q = T \<or> p = q then T |
|
147 |
else if p = T then q |
|
148 |
else if q = F then not p |
|
29789 | 149 |
else Imp p q)" |
60710 | 150 |
|
29789 | 151 |
lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)" |
60710 | 152 |
by (cases "p = F \<or> q = T") (simp_all add: imp_def) |
29789 | 153 |
|
60710 | 154 |
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" |
155 |
where |
|
156 |
"iff p q = |
|
157 |
(if p = q then T |
|
158 |
else if p = NOT q \<or> NOT p = q then F |
|
159 |
else if p = F then not q |
|
160 |
else if q = F then not p |
|
161 |
else if p = T then q |
|
162 |
else if q = T then p |
|
163 |
else Iff p q)" |
|
164 |
||
29789 | 165 |
lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)" |
60710 | 166 |
by (unfold iff_def, cases "p = q", simp, cases "p = NOT q", simp) (cases "NOT p = q", auto) |
29789 | 167 |
|
168 |
lemma conj_simps: |
|
169 |
"conj F Q = F" |
|
170 |
"conj P F = F" |
|
171 |
"conj T Q = Q" |
|
172 |
"conj P T = P" |
|
173 |
"conj P P = P" |
|
174 |
"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" |
|
175 |
by (simp_all add: conj_def) |
|
176 |
||
177 |
lemma disj_simps: |
|
178 |
"disj T Q = T" |
|
179 |
"disj P T = T" |
|
180 |
"disj F Q = Q" |
|
181 |
"disj P F = P" |
|
182 |
"disj P P = P" |
|
183 |
"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" |
|
184 |
by (simp_all add: disj_def) |
|
60710 | 185 |
|
29789 | 186 |
lemma imp_simps: |
187 |
"imp F Q = T" |
|
188 |
"imp P T = T" |
|
189 |
"imp T Q = Q" |
|
190 |
"imp P F = not P" |
|
191 |
"imp P P = T" |
|
192 |
"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" |
|
193 |
by (simp_all add: imp_def) |
|
60710 | 194 |
|
29789 | 195 |
lemma trivNOT: "p \<noteq> NOT p" "NOT p \<noteq> p" |
60710 | 196 |
by (induct p) auto |
29789 | 197 |
|
198 |
lemma iff_simps: |
|
199 |
"iff p p = T" |
|
200 |
"iff p (NOT p) = F" |
|
201 |
"iff (NOT p) p = F" |
|
202 |
"iff p F = not p" |
|
203 |
"iff F p = not p" |
|
204 |
"p \<noteq> NOT T \<Longrightarrow> iff T p = p" |
|
205 |
"p\<noteq> NOT T \<Longrightarrow> iff p T = p" |
|
206 |
"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" |
|
207 |
using trivNOT |
|
208 |
by (simp_all add: iff_def, cases p, auto) |
|
60710 | 209 |
|
29789 | 210 |
(* Quantifier freeness *) |
60710 | 211 |
fun qfree:: "fm \<Rightarrow> bool" |
212 |
where |
|
29789 | 213 |
"qfree (E p) = False" |
36853 | 214 |
| "qfree (A p) = False" |
60710 | 215 |
| "qfree (NOT p) = qfree p" |
216 |
| "qfree (And p q) = (qfree p \<and> qfree q)" |
|
217 |
| "qfree (Or p q) = (qfree p \<and> qfree q)" |
|
218 |
| "qfree (Imp p q) = (qfree p \<and> qfree q)" |
|
36853 | 219 |
| "qfree (Iff p q) = (qfree p \<and> qfree q)" |
220 |
| "qfree p = True" |
|
29789 | 221 |
|
222 |
(* Boundedness and substitution *) |
|
60710 | 223 |
primrec numbound0:: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) |
224 |
where |
|
29789 | 225 |
"numbound0 (C c) = True" |
60710 | 226 |
| "numbound0 (Bound n) = (n > 0)" |
227 |
| "numbound0 (CN n c a) = (n \<noteq> 0 \<and> numbound0 a)" |
|
36853 | 228 |
| "numbound0 (Neg a) = numbound0 a" |
229 |
| "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)" |
|
60710 | 230 |
| "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" |
36853 | 231 |
| "numbound0 (Mul i a) = numbound0 a" |
232 |
||
29789 | 233 |
lemma numbound0_I: |
234 |
assumes nb: "numbound0 a" |
|
235 |
shows "Inum (b#bs) a = Inum (b'#bs) a" |
|
60710 | 236 |
using nb by (induct a) simp_all |
29789 | 237 |
|
60710 | 238 |
primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) |
239 |
where |
|
29789 | 240 |
"bound0 T = True" |
36853 | 241 |
| "bound0 F = True" |
242 |
| "bound0 (Lt a) = numbound0 a" |
|
243 |
| "bound0 (Le a) = numbound0 a" |
|
244 |
| "bound0 (Gt a) = numbound0 a" |
|
245 |
| "bound0 (Ge a) = numbound0 a" |
|
246 |
| "bound0 (Eq a) = numbound0 a" |
|
247 |
| "bound0 (NEq a) = numbound0 a" |
|
248 |
| "bound0 (NOT p) = bound0 p" |
|
249 |
| "bound0 (And p q) = (bound0 p \<and> bound0 q)" |
|
250 |
| "bound0 (Or p q) = (bound0 p \<and> bound0 q)" |
|
251 |
| "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))" |
|
252 |
| "bound0 (Iff p q) = (bound0 p \<and> bound0 q)" |
|
253 |
| "bound0 (E p) = False" |
|
254 |
| "bound0 (A p) = False" |
|
29789 | 255 |
|
256 |
lemma bound0_I: |
|
257 |
assumes bp: "bound0 p" |
|
258 |
shows "Ifm (b#bs) p = Ifm (b'#bs) p" |
|
60710 | 259 |
using bp numbound0_I[where b="b" and bs="bs" and b'="b'"] |
260 |
by (induct p) auto |
|
29789 | 261 |
|
262 |
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)" |
|
60710 | 263 |
by (cases p) auto |
264 |
||
29789 | 265 |
lemma not_bn[simp]: "bound0 p \<Longrightarrow> bound0 (not p)" |
60710 | 266 |
by (cases p) auto |
29789 | 267 |
|
268 |
||
269 |
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)" |
|
60710 | 270 |
using conj_def by auto |
29789 | 271 |
lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)" |
60710 | 272 |
using conj_def by auto |
29789 | 273 |
|
274 |
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)" |
|
60710 | 275 |
using disj_def by auto |
29789 | 276 |
lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)" |
60710 | 277 |
using disj_def by auto |
29789 | 278 |
|
279 |
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)" |
|
60710 | 280 |
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def) |
29789 | 281 |
lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)" |
60710 | 282 |
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def) |
29789 | 283 |
|
284 |
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)" |
|
60710 | 285 |
unfolding iff_def by (cases "p = q") auto |
29789 | 286 |
lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)" |
60710 | 287 |
using iff_def unfolding iff_def by (cases "p = q") auto |
29789 | 288 |
|
60710 | 289 |
fun decrnum:: "num \<Rightarrow> num" |
290 |
where |
|
29789 | 291 |
"decrnum (Bound n) = Bound (n - 1)" |
36853 | 292 |
| "decrnum (Neg a) = Neg (decrnum a)" |
293 |
| "decrnum (Add a b) = Add (decrnum a) (decrnum b)" |
|
294 |
| "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)" |
|
295 |
| "decrnum (Mul c a) = Mul c (decrnum a)" |
|
296 |
| "decrnum (CN n c a) = CN (n - 1) c (decrnum a)" |
|
297 |
| "decrnum a = a" |
|
29789 | 298 |
|
60710 | 299 |
fun decr :: "fm \<Rightarrow> fm" |
300 |
where |
|
29789 | 301 |
"decr (Lt a) = Lt (decrnum a)" |
36853 | 302 |
| "decr (Le a) = Le (decrnum a)" |
303 |
| "decr (Gt a) = Gt (decrnum a)" |
|
304 |
| "decr (Ge a) = Ge (decrnum a)" |
|
305 |
| "decr (Eq a) = Eq (decrnum a)" |
|
306 |
| "decr (NEq a) = NEq (decrnum a)" |
|
60710 | 307 |
| "decr (NOT p) = NOT (decr p)" |
36853 | 308 |
| "decr (And p q) = conj (decr p) (decr q)" |
309 |
| "decr (Or p q) = disj (decr p) (decr q)" |
|
310 |
| "decr (Imp p q) = imp (decr p) (decr q)" |
|
311 |
| "decr (Iff p q) = iff (decr p) (decr q)" |
|
312 |
| "decr p = p" |
|
29789 | 313 |
|
60710 | 314 |
lemma decrnum: |
315 |
assumes nb: "numbound0 t" |
|
316 |
shows "Inum (x # bs) t = Inum bs (decrnum t)" |
|
317 |
using nb by (induct t rule: decrnum.induct) simp_all |
|
29789 | 318 |
|
60710 | 319 |
lemma decr: |
320 |
assumes nb: "bound0 p" |
|
321 |
shows "Ifm (x # bs) p = Ifm bs (decr p)" |
|
322 |
using nb by (induct p rule: decr.induct) (simp_all add: decrnum) |
|
29789 | 323 |
|
324 |
lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)" |
|
60710 | 325 |
by (induct p) simp_all |
29789 | 326 |
|
60710 | 327 |
fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) |
328 |
where |
|
29789 | 329 |
"isatom T = True" |
36853 | 330 |
| "isatom F = True" |
331 |
| "isatom (Lt a) = True" |
|
332 |
| "isatom (Le a) = True" |
|
333 |
| "isatom (Gt a) = True" |
|
334 |
| "isatom (Ge a) = True" |
|
335 |
| "isatom (Eq a) = True" |
|
336 |
| "isatom (NEq a) = True" |
|
337 |
| "isatom p = False" |
|
29789 | 338 |
|
339 |
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p" |
|
60710 | 340 |
by (induct p) simp_all |
29789 | 341 |
|
60710 | 342 |
definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" |
343 |
where |
|
344 |
"djf f p q = |
|
345 |
(if q = T then T |
|
346 |
else if q = F then f p |
|
347 |
else (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))" |
|
348 |
||
349 |
definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" |
|
350 |
where "evaldjf f ps = foldr (djf f) ps F" |
|
29789 | 351 |
|
352 |
lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)" |
|
60710 | 353 |
by (cases "q = T", simp add: djf_def, cases "q = F", simp add: djf_def) |
354 |
(cases "f p", simp_all add: Let_def djf_def) |
|
29789 | 355 |
|
356 |
||
357 |
lemma djf_simps: |
|
358 |
"djf f p T = T" |
|
359 |
"djf f p F = f p" |
|
60710 | 360 |
"q \<noteq> T \<Longrightarrow> q \<noteq> F \<Longrightarrow> djf f p q = (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q)" |
29789 | 361 |
by (simp_all add: djf_def) |
362 |
||
60710 | 363 |
lemma evaldjf_ex: "Ifm bs (evaldjf f ps) \<longleftrightarrow> (\<exists>p \<in> set ps. Ifm bs (f p))" |
364 |
by (induct ps) (simp_all add: evaldjf_def djf_Or) |
|
29789 | 365 |
|
60710 | 366 |
lemma evaldjf_bound0: |
367 |
assumes nb: "\<forall>x\<in> set xs. bound0 (f x)" |
|
29789 | 368 |
shows "bound0 (evaldjf f xs)" |
60710 | 369 |
using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) |
29789 | 370 |
|
60710 | 371 |
lemma evaldjf_qf: |
372 |
assumes nb: "\<forall>x\<in> set xs. qfree (f x)" |
|
29789 | 373 |
shows "qfree (evaldjf f xs)" |
60710 | 374 |
using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) |
29789 | 375 |
|
60710 | 376 |
fun disjuncts :: "fm \<Rightarrow> fm list" |
377 |
where |
|
36853 | 378 |
"disjuncts (Or p q) = disjuncts p @ disjuncts q" |
379 |
| "disjuncts F = []" |
|
380 |
| "disjuncts p = [p]" |
|
29789 | 381 |
|
60710 | 382 |
lemma disjuncts: "(\<exists>q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p" |
383 |
by (induct p rule: disjuncts.induct) auto |
|
29789 | 384 |
|
60710 | 385 |
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall>q\<in> set (disjuncts p). bound0 q" |
386 |
proof - |
|
29789 | 387 |
assume nb: "bound0 p" |
60710 | 388 |
then have "list_all bound0 (disjuncts p)" |
389 |
by (induct p rule: disjuncts.induct) auto |
|
390 |
then show ?thesis |
|
391 |
by (simp only: list_all_iff) |
|
29789 | 392 |
qed |
393 |
||
60710 | 394 |
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall>q\<in> set (disjuncts p). qfree q" |
395 |
proof - |
|
29789 | 396 |
assume qf: "qfree p" |
60710 | 397 |
then have "list_all qfree (disjuncts p)" |
398 |
by (induct p rule: disjuncts.induct) auto |
|
399 |
then show ?thesis |
|
400 |
by (simp only: list_all_iff) |
|
29789 | 401 |
qed |
402 |
||
60710 | 403 |
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" |
404 |
where "DJ f p = evaldjf f (disjuncts p)" |
|
29789 | 405 |
|
60710 | 406 |
lemma DJ: |
407 |
assumes fdj: "\<forall>p q. Ifm bs (f (Or p q)) = Ifm bs (Or (f p) (f q))" |
|
408 |
and fF: "f F = F" |
|
29789 | 409 |
shows "Ifm bs (DJ f p) = Ifm bs (f p)" |
60710 | 410 |
proof - |
411 |
have "Ifm bs (DJ f p) = (\<exists>q \<in> set (disjuncts p). Ifm bs (f q))" |
|
412 |
by (simp add: DJ_def evaldjf_ex) |
|
413 |
also have "\<dots> = Ifm bs (f p)" |
|
414 |
using fdj fF by (induct p rule: disjuncts.induct) auto |
|
29789 | 415 |
finally show ?thesis . |
416 |
qed |
|
417 |
||
60710 | 418 |
lemma DJ_qf: |
419 |
assumes fqf: "\<forall>p. qfree p \<longrightarrow> qfree (f p)" |
|
29789 | 420 |
shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) " |
60710 | 421 |
proof clarify |
422 |
fix p |
|
423 |
assume qf: "qfree p" |
|
424 |
have th: "DJ f p = evaldjf f (disjuncts p)" |
|
425 |
by (simp add: DJ_def) |
|
426 |
from disjuncts_qf[OF qf] have "\<forall>q\<in> set (disjuncts p). qfree q" . |
|
427 |
with fqf have th':"\<forall>q\<in> set (disjuncts p). qfree (f q)" |
|
428 |
by blast |
|
429 |
from evaldjf_qf[OF th'] th show "qfree (DJ f p)" |
|
430 |
by simp |
|
29789 | 431 |
qed |
432 |
||
60710 | 433 |
lemma DJ_qe: |
434 |
assumes qe: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))" |
|
435 |
shows "\<forall>bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))" |
|
436 |
proof clarify |
|
437 |
fix p :: fm |
|
438 |
fix bs |
|
29789 | 439 |
assume qf: "qfree p" |
60710 | 440 |
from qe have qth: "\<forall>p. qfree p \<longrightarrow> qfree (qe p)" |
441 |
by blast |
|
442 |
from DJ_qf[OF qth] qf have qfth: "qfree (DJ qe p)" |
|
443 |
by auto |
|
444 |
have "Ifm bs (DJ qe p) \<longleftrightarrow> (\<exists>q\<in> set (disjuncts p). Ifm bs (qe q))" |
|
29789 | 445 |
by (simp add: DJ_def evaldjf_ex) |
60710 | 446 |
also have "\<dots> \<longleftrightarrow> (\<exists>q \<in> set(disjuncts p). Ifm bs (E q))" |
447 |
using qe disjuncts_qf[OF qf] by auto |
|
448 |
also have "\<dots> = Ifm bs (E p)" |
|
449 |
by (induct p rule: disjuncts.induct) auto |
|
450 |
finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" |
|
451 |
using qfth by blast |
|
29789 | 452 |
qed |
60710 | 453 |
|
29789 | 454 |
(* Simplification *) |
36853 | 455 |
|
60710 | 456 |
fun maxcoeff:: "num \<Rightarrow> int" |
457 |
where |
|
29789 | 458 |
"maxcoeff (C i) = abs i" |
36853 | 459 |
| "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)" |
460 |
| "maxcoeff t = 1" |
|
29789 | 461 |
|
462 |
lemma maxcoeff_pos: "maxcoeff t \<ge> 0" |
|
463 |
by (induct t rule: maxcoeff.induct, auto) |
|
464 |
||
60710 | 465 |
fun numgcdh:: "num \<Rightarrow> int \<Rightarrow> int" |
466 |
where |
|
31706 | 467 |
"numgcdh (C i) = (\<lambda>g. gcd i g)" |
36853 | 468 |
| "numgcdh (CN n c t) = (\<lambda>g. gcd c (numgcdh t g))" |
469 |
| "numgcdh t = (\<lambda>g. 1)" |
|
470 |
||
60710 | 471 |
definition numgcd :: "num \<Rightarrow> int" |
472 |
where "numgcd t = numgcdh t (maxcoeff t)" |
|
29789 | 473 |
|
60710 | 474 |
fun reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num" |
475 |
where |
|
476 |
"reducecoeffh (C i) = (\<lambda>g. C (i div g))" |
|
477 |
| "reducecoeffh (CN n c t) = (\<lambda>g. CN n (c div g) (reducecoeffh t g))" |
|
36853 | 478 |
| "reducecoeffh t = (\<lambda>g. t)" |
29789 | 479 |
|
60710 | 480 |
definition reducecoeff :: "num \<Rightarrow> num" |
481 |
where |
|
36853 | 482 |
"reducecoeff t = |
60710 | 483 |
(let g = numgcd t |
484 |
in if g = 0 then C 0 else if g = 1 then t else reducecoeffh t g)" |
|
29789 | 485 |
|
60710 | 486 |
fun dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" |
487 |
where |
|
488 |
"dvdnumcoeff (C i) = (\<lambda>g. g dvd i)" |
|
489 |
| "dvdnumcoeff (CN n c t) = (\<lambda>g. g dvd c \<and> dvdnumcoeff t g)" |
|
36853 | 490 |
| "dvdnumcoeff t = (\<lambda>g. False)" |
29789 | 491 |
|
60710 | 492 |
lemma dvdnumcoeff_trans: |
493 |
assumes gdg: "g dvd g'" |
|
494 |
and dgt':"dvdnumcoeff t g'" |
|
29789 | 495 |
shows "dvdnumcoeff t g" |
60710 | 496 |
using dgt' gdg |
497 |
by (induct t rule: dvdnumcoeff.induct) (simp_all add: gdg dvd_trans[OF gdg]) |
|
29789 | 498 |
|
30042 | 499 |
declare dvd_trans [trans add] |
29789 | 500 |
|
60710 | 501 |
lemma natabs0: "nat (abs x) = 0 \<longleftrightarrow> x = 0" |
502 |
by arith |
|
29789 | 503 |
|
504 |
lemma numgcd0: |
|
505 |
assumes g0: "numgcd t = 0" |
|
506 |
shows "Inum bs t = 0" |
|
60710 | 507 |
using g0[simplified numgcd_def] |
508 |
by (induct t rule: numgcdh.induct) (auto simp add: natabs0 maxcoeff_pos max.absorb2) |
|
29789 | 509 |
|
60710 | 510 |
lemma numgcdh_pos: |
511 |
assumes gp: "g \<ge> 0" |
|
512 |
shows "numgcdh t g \<ge> 0" |
|
513 |
using gp by (induct t rule: numgcdh.induct) auto |
|
29789 | 514 |
|
515 |
lemma numgcd_pos: "numgcd t \<ge>0" |
|
516 |
by (simp add: numgcd_def numgcdh_pos maxcoeff_pos) |
|
517 |
||
518 |
lemma reducecoeffh: |
|
60710 | 519 |
assumes gt: "dvdnumcoeff t g" |
520 |
and gp: "g > 0" |
|
29789 | 521 |
shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t" |
522 |
using gt |
|
60710 | 523 |
proof (induct t rule: reducecoeffh.induct) |
41807 | 524 |
case (1 i) |
60710 | 525 |
then have gd: "g dvd i" |
526 |
by simp |
|
527 |
with assms show ?case |
|
528 |
by (simp add: real_of_int_div[OF gd]) |
|
29789 | 529 |
next |
41807 | 530 |
case (2 n c t) |
60710 | 531 |
then have gd: "g dvd c" |
532 |
by simp |
|
533 |
from assms 2 show ?case |
|
534 |
by (simp add: real_of_int_div[OF gd] algebra_simps) |
|
29789 | 535 |
qed (auto simp add: numgcd_def gp) |
36853 | 536 |
|
60710 | 537 |
fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" |
538 |
where |
|
539 |
"ismaxcoeff (C i) = (\<lambda>x. abs i \<le> x)" |
|
540 |
| "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> ismaxcoeff t x)" |
|
36853 | 541 |
| "ismaxcoeff t = (\<lambda>x. True)" |
29789 | 542 |
|
543 |
lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'" |
|
41807 | 544 |
by (induct t rule: ismaxcoeff.induct) auto |
29789 | 545 |
|
546 |
lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)" |
|
547 |
proof (induct t rule: maxcoeff.induct) |
|
548 |
case (2 n c t) |
|
60710 | 549 |
then have H:"ismaxcoeff t (maxcoeff t)" . |
550 |
have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" |
|
551 |
by simp |
|
552 |
from ismaxcoeff_mono[OF H thh] show ?case |
|
553 |
by simp |
|
29789 | 554 |
qed simp_all |
555 |
||
60710 | 556 |
lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> |
557 |
abs i > 1 \<and> abs j > 1 \<or> abs i = 0 \<and> abs j > 1 \<or> abs i > 1 \<and> abs j = 0" |
|
31706 | 558 |
apply (cases "abs i = 0", simp_all add: gcd_int_def) |
29789 | 559 |
apply (cases "abs j = 0", simp_all) |
560 |
apply (cases "abs i = 1", simp_all) |
|
561 |
apply (cases "abs j = 1", simp_all) |
|
562 |
apply auto |
|
563 |
done |
|
60710 | 564 |
|
29789 | 565 |
lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow> m =0" |
60710 | 566 |
by (induct t rule: numgcdh.induct) auto |
29789 | 567 |
|
568 |
lemma dvdnumcoeff_aux: |
|
60710 | 569 |
assumes "ismaxcoeff t m" |
570 |
and mp: "m \<ge> 0" |
|
571 |
and "numgcdh t m > 1" |
|
29789 | 572 |
shows "dvdnumcoeff t (numgcdh t m)" |
60710 | 573 |
using assms |
574 |
proof (induct t rule: numgcdh.induct) |
|
575 |
case (2 n c t) |
|
29789 | 576 |
let ?g = "numgcdh t m" |
60710 | 577 |
from 2 have th: "gcd c ?g > 1" |
578 |
by simp |
|
29789 | 579 |
from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"] |
60710 | 580 |
consider "abs c > 1" "?g > 1" | "abs c = 0" "?g > 1" | "?g = 0" |
581 |
by auto |
|
582 |
then show ?case |
|
583 |
proof cases |
|
584 |
case 1 |
|
585 |
with 2 have th: "dvdnumcoeff t ?g" |
|
586 |
by simp |
|
587 |
have th': "gcd c ?g dvd ?g" |
|
588 |
by simp |
|
589 |
from dvdnumcoeff_trans[OF th' th] show ?thesis |
|
590 |
by simp |
|
591 |
next |
|
592 |
case "2'": 2 |
|
593 |
with 2 have th: "dvdnumcoeff t ?g" |
|
594 |
by simp |
|
595 |
have th': "gcd c ?g dvd ?g" |
|
596 |
by simp |
|
597 |
from dvdnumcoeff_trans[OF th' th] show ?thesis |
|
598 |
by simp |
|
599 |
next |
|
600 |
case 3 |
|
601 |
then have "m = 0" by (rule numgcdh0) |
|
602 |
with 2 3 show ?thesis by simp |
|
603 |
qed |
|
31706 | 604 |
qed auto |
29789 | 605 |
|
606 |
lemma dvdnumcoeff_aux2: |
|
41807 | 607 |
assumes "numgcd t > 1" |
608 |
shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0" |
|
609 |
using assms |
|
29789 | 610 |
proof (simp add: numgcd_def) |
611 |
let ?mc = "maxcoeff t" |
|
612 |
let ?g = "numgcdh t ?mc" |
|
60710 | 613 |
have th1: "ismaxcoeff t ?mc" |
614 |
by (rule maxcoeff_ismaxcoeff) |
|
615 |
have th2: "?mc \<ge> 0" |
|
616 |
by (rule maxcoeff_pos) |
|
29789 | 617 |
assume H: "numgcdh t ?mc > 1" |
60710 | 618 |
from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" . |
29789 | 619 |
qed |
620 |
||
621 |
lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t" |
|
60710 | 622 |
proof - |
29789 | 623 |
let ?g = "numgcd t" |
60710 | 624 |
have "?g \<ge> 0" |
625 |
by (simp add: numgcd_pos) |
|
626 |
then consider "?g = 0" | "?g = 1" | "?g > 1" by atomize_elim auto |
|
627 |
then show ?thesis |
|
628 |
proof cases |
|
629 |
case 1 |
|
630 |
then show ?thesis by (simp add: numgcd0) |
|
631 |
next |
|
632 |
case 2 |
|
633 |
then show ?thesis by (simp add: reducecoeff_def) |
|
634 |
next |
|
635 |
case g1: 3 |
|
636 |
from dvdnumcoeff_aux2[OF g1] have th1: "dvdnumcoeff t ?g" and g0: "?g > 0" |
|
637 |
by blast+ |
|
638 |
from reducecoeffh[OF th1 g0, where bs="bs"] g1 show ?thesis |
|
639 |
by (simp add: reducecoeff_def Let_def) |
|
640 |
qed |
|
29789 | 641 |
qed |
642 |
||
643 |
lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)" |
|
60710 | 644 |
by (induct t rule: reducecoeffh.induct) auto |
29789 | 645 |
|
646 |
lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)" |
|
60710 | 647 |
using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def) |
29789 | 648 |
|
60710 | 649 |
consts numadd:: "num \<times> num \<Rightarrow> num" |
650 |
recdef numadd "measure (\<lambda>(t,s). size t + size s)" |
|
29789 | 651 |
"numadd (CN n1 c1 r1,CN n2 c2 r2) = |
60710 | 652 |
(if n1 = n2 then |
653 |
(let c = c1 + c2 |
|
654 |
in (if c = 0 then numadd(r1,r2) else CN n1 c (numadd (r1, r2)))) |
|
655 |
else if n1 \<le> n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2))) |
|
656 |
else (CN n2 c2 (numadd (CN n1 c1 r1, r2))))" |
|
657 |
"numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))" |
|
658 |
"numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t, r2))" |
|
659 |
"numadd (C b1, C b2) = C (b1 + b2)" |
|
29789 | 660 |
"numadd (a,b) = Add a b" |
661 |
||
662 |
lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)" |
|
60710 | 663 |
apply (induct t s rule: numadd.induct) |
664 |
apply (simp_all add: Let_def) |
|
665 |
apply (case_tac "c1 + c2 = 0") |
|
666 |
apply (case_tac "n1 \<le> n2") |
|
667 |
apply simp_all |
|
668 |
apply (case_tac "n1 = n2") |
|
669 |
apply (simp_all add: algebra_simps) |
|
670 |
apply (simp only: distrib_right[symmetric]) |
|
671 |
apply simp |
|
672 |
done |
|
29789 | 673 |
|
674 |
lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))" |
|
60710 | 675 |
by (induct t s rule: numadd.induct) (auto simp add: Let_def) |
29789 | 676 |
|
60710 | 677 |
fun nummul:: "num \<Rightarrow> int \<Rightarrow> num" |
678 |
where |
|
679 |
"nummul (C j) = (\<lambda>i. C (i * j))" |
|
680 |
| "nummul (CN n c a) = (\<lambda>i. CN n (i * c) (nummul a i))" |
|
681 |
| "nummul t = (\<lambda>i. Mul i t)" |
|
29789 | 682 |
|
60710 | 683 |
lemma nummul[simp]: "\<And>i. Inum bs (nummul t i) = Inum bs (Mul i t)" |
684 |
by (induct t rule: nummul.induct) (auto simp add: algebra_simps) |
|
29789 | 685 |
|
60710 | 686 |
lemma nummul_nb[simp]: "\<And>i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)" |
687 |
by (induct t rule: nummul.induct) auto |
|
29789 | 688 |
|
60710 | 689 |
definition numneg :: "num \<Rightarrow> num" |
690 |
where "numneg t = nummul t (- 1)" |
|
29789 | 691 |
|
60710 | 692 |
definition numsub :: "num \<Rightarrow> num \<Rightarrow> num" |
693 |
where "numsub s t = (if s = t then C 0 else numadd (s, numneg t))" |
|
29789 | 694 |
|
695 |
lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)" |
|
60710 | 696 |
using numneg_def by simp |
29789 | 697 |
|
698 |
lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)" |
|
60710 | 699 |
using numneg_def by simp |
29789 | 700 |
|
701 |
lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)" |
|
60710 | 702 |
using numsub_def by simp |
29789 | 703 |
|
704 |
lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)" |
|
60710 | 705 |
using numsub_def by simp |
29789 | 706 |
|
60710 | 707 |
primrec simpnum:: "num \<Rightarrow> num" |
708 |
where |
|
29789 | 709 |
"simpnum (C j) = C j" |
36853 | 710 |
| "simpnum (Bound n) = CN n 1 (C 0)" |
711 |
| "simpnum (Neg t) = numneg (simpnum t)" |
|
712 |
| "simpnum (Add t s) = numadd (simpnum t,simpnum s)" |
|
713 |
| "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)" |
|
60710 | 714 |
| "simpnum (Mul i t) = (if i = 0 then C 0 else nummul (simpnum t) i)" |
715 |
| "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0), simpnum t))" |
|
29789 | 716 |
|
717 |
lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t" |
|
60710 | 718 |
by (induct t) simp_all |
719 |
||
720 |
lemma simpnum_numbound0[simp]: "numbound0 t \<Longrightarrow> numbound0 (simpnum t)" |
|
721 |
by (induct t) simp_all |
|
29789 | 722 |
|
60710 | 723 |
fun nozerocoeff:: "num \<Rightarrow> bool" |
724 |
where |
|
29789 | 725 |
"nozerocoeff (C c) = True" |
60710 | 726 |
| "nozerocoeff (CN n c t) = (c \<noteq> 0 \<and> nozerocoeff t)" |
36853 | 727 |
| "nozerocoeff t = True" |
29789 | 728 |
|
729 |
lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))" |
|
60710 | 730 |
by (induct a b rule: numadd.induct) (auto simp add: Let_def) |
29789 | 731 |
|
60710 | 732 |
lemma nummul_nz : "\<And>i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)" |
733 |
by (induct a rule: nummul.induct) (auto simp add: Let_def numadd_nz) |
|
29789 | 734 |
|
735 |
lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)" |
|
60710 | 736 |
by (simp add: numneg_def nummul_nz) |
29789 | 737 |
|
738 |
lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)" |
|
60710 | 739 |
by (simp add: numsub_def numneg_nz numadd_nz) |
29789 | 740 |
|
741 |
lemma simpnum_nz: "nozerocoeff (simpnum t)" |
|
60710 | 742 |
by (induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz) |
29789 | 743 |
|
744 |
lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0" |
|
745 |
proof (induct t rule: maxcoeff.induct) |
|
746 |
case (2 n c t) |
|
60710 | 747 |
then have cnz: "c \<noteq> 0" and mx: "max (abs c) (maxcoeff t) = 0" |
748 |
by simp_all |
|
749 |
have "max (abs c) (maxcoeff t) \<ge> abs c" |
|
750 |
by simp |
|
751 |
with cnz have "max (abs c) (maxcoeff t) > 0" |
|
752 |
by arith |
|
753 |
with 2 show ?case |
|
754 |
by simp |
|
29789 | 755 |
qed auto |
756 |
||
60710 | 757 |
lemma numgcd_nz: |
758 |
assumes nz: "nozerocoeff t" |
|
759 |
and g0: "numgcd t = 0" |
|
760 |
shows "t = C 0" |
|
761 |
proof - |
|
762 |
from g0 have th:"numgcdh t (maxcoeff t) = 0" |
|
763 |
by (simp add: numgcd_def) |
|
764 |
from numgcdh0[OF th] have th:"maxcoeff t = 0" . |
|
29789 | 765 |
from maxcoeff_nz[OF nz th] show ?thesis . |
766 |
qed |
|
767 |
||
60710 | 768 |
definition simp_num_pair :: "(num \<times> int) \<Rightarrow> num \<times> int" |
769 |
where |
|
770 |
"simp_num_pair = |
|
771 |
(\<lambda>(t,n). |
|
772 |
(if n = 0 then (C 0, 0) |
|
773 |
else |
|
774 |
(let t' = simpnum t ; g = numgcd t' in |
|
775 |
if g > 1 then |
|
776 |
(let g' = gcd n g |
|
777 |
in if g' = 1 then (t', n) else (reducecoeffh t' g', n div g')) |
|
778 |
else (t', n))))" |
|
29789 | 779 |
|
780 |
lemma simp_num_pair_ci: |
|
60710 | 781 |
shows "((\<lambda>(t,n). Inum bs t / real n) (simp_num_pair (t,n))) = |
782 |
((\<lambda>(t,n). Inum bs t / real n) (t, n))" |
|
29789 | 783 |
(is "?lhs = ?rhs") |
60710 | 784 |
proof - |
29789 | 785 |
let ?t' = "simpnum t" |
786 |
let ?g = "numgcd ?t'" |
|
31706 | 787 |
let ?g' = "gcd n ?g" |
60710 | 788 |
show ?thesis |
789 |
proof (cases "n = 0") |
|
790 |
case True |
|
791 |
then show ?thesis |
|
792 |
by (simp add: Let_def simp_num_pair_def) |
|
793 |
next |
|
794 |
case nnz: False |
|
795 |
show ?thesis |
|
796 |
proof (cases "?g > 1") |
|
797 |
case False |
|
798 |
then show ?thesis by (simp add: Let_def simp_num_pair_def) |
|
799 |
next |
|
800 |
case g1: True |
|
801 |
then have g0: "?g > 0" |
|
802 |
by simp |
|
803 |
from g1 nnz have gp0: "?g' \<noteq> 0" |
|
804 |
by simp |
|
805 |
then have g'p: "?g' > 0" |
|
806 |
using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith |
|
807 |
then consider "?g' = 1" | "?g' > 1" by arith |
|
808 |
then show ?thesis |
|
809 |
proof cases |
|
810 |
case 1 |
|
811 |
then show ?thesis |
|
812 |
by (simp add: Let_def simp_num_pair_def) |
|
813 |
next |
|
814 |
case g'1: 2 |
|
815 |
from dvdnumcoeff_aux2[OF g1] have th1: "dvdnumcoeff ?t' ?g" .. |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
816 |
let ?tt = "reducecoeffh ?t' ?g'" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
817 |
let ?t = "Inum bs ?tt" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
818 |
have gpdg: "?g' dvd ?g" by simp |
60710 | 819 |
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
|
820 |
have gpdgp: "?g' dvd ?g'" by simp |
60710 | 821 |
from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] |
822 |
have th2:"real ?g' * ?t = Inum bs ?t'" |
|
823 |
by simp |
|
824 |
from g1 g'1 have "?lhs = ?t / real (n div ?g')" |
|
825 |
by (simp add: simp_num_pair_def Let_def) |
|
826 |
also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" |
|
827 |
by simp |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
828 |
also have "\<dots> = (Inum bs ?t' / real n)" |
46670 | 829 |
using real_of_int_div[OF gpdd] th2 gp0 by simp |
60710 | 830 |
finally have "?lhs = Inum bs t / real n" |
831 |
by simp |
|
832 |
then show ?thesis |
|
833 |
by (simp add: simp_num_pair_def) |
|
834 |
qed |
|
835 |
qed |
|
836 |
qed |
|
29789 | 837 |
qed |
838 |
||
60710 | 839 |
lemma simp_num_pair_l: |
840 |
assumes tnb: "numbound0 t" |
|
841 |
and np: "n > 0" |
|
842 |
and tn: "simp_num_pair (t, n) = (t', n')" |
|
843 |
shows "numbound0 t' \<and> n' > 0" |
|
844 |
proof - |
|
41807 | 845 |
let ?t' = "simpnum t" |
29789 | 846 |
let ?g = "numgcd ?t'" |
31706 | 847 |
let ?g' = "gcd n ?g" |
60710 | 848 |
show ?thesis |
849 |
proof (cases "n = 0") |
|
850 |
case True |
|
851 |
then show ?thesis |
|
852 |
using assms by (simp add: Let_def simp_num_pair_def) |
|
853 |
next |
|
854 |
case nnz: False |
|
855 |
show ?thesis |
|
856 |
proof (cases "?g > 1") |
|
857 |
case False |
|
858 |
then show ?thesis |
|
859 |
using assms by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) |
|
860 |
next |
|
861 |
case g1: True |
|
862 |
then have g0: "?g > 0" by simp |
|
31706 | 863 |
from g1 nnz have gp0: "?g' \<noteq> 0" by simp |
60710 | 864 |
then have g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] |
865 |
by arith |
|
866 |
then consider "?g'= 1" | "?g' > 1" by arith |
|
867 |
then show ?thesis |
|
868 |
proof cases |
|
869 |
case 1 |
|
870 |
then show ?thesis |
|
871 |
using assms g1 by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) |
|
872 |
next |
|
873 |
case g'1: 2 |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
874 |
have gpdg: "?g' dvd ?g" by simp |
41807 | 875 |
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
|
876 |
have gpdgp: "?g' dvd ?g'" by simp |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
877 |
from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" . |
60710 | 878 |
from zdiv_mono1[OF g'n g'p, simplified div_self[OF gp0]] have "n div ?g' > 0" |
879 |
by simp |
|
880 |
then show ?thesis |
|
881 |
using assms g1 g'1 |
|
882 |
by (auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0) |
|
883 |
qed |
|
884 |
qed |
|
885 |
qed |
|
29789 | 886 |
qed |
887 |
||
60710 | 888 |
fun simpfm :: "fm \<Rightarrow> fm" |
889 |
where |
|
29789 | 890 |
"simpfm (And p q) = conj (simpfm p) (simpfm q)" |
36853 | 891 |
| "simpfm (Or p q) = disj (simpfm p) (simpfm q)" |
892 |
| "simpfm (Imp p q) = imp (simpfm p) (simpfm q)" |
|
893 |
| "simpfm (Iff p q) = iff (simpfm p) (simpfm q)" |
|
894 |
| "simpfm (NOT p) = not (simpfm p)" |
|
60710 | 895 |
| "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F | _ \<Rightarrow> Lt a')" |
36853 | 896 |
| "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')" |
897 |
| "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0) then T else F | _ \<Rightarrow> Gt a')" |
|
898 |
| "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')" |
|
899 |
| "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0) then T else F | _ \<Rightarrow> Eq a')" |
|
900 |
| "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')" |
|
901 |
| "simpfm p = p" |
|
60710 | 902 |
|
29789 | 903 |
lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p" |
60710 | 904 |
proof (induct p rule: simpfm.induct) |
905 |
case (6 a) |
|
906 |
let ?sa = "simpnum a" |
|
907 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
908 |
by simp |
|
909 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
910 |
then show ?case |
|
911 |
proof cases |
|
912 |
case 1 |
|
913 |
then show ?thesis using sa by simp |
|
914 |
next |
|
915 |
case 2 |
|
916 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
917 |
qed |
|
29789 | 918 |
next |
60710 | 919 |
case (7 a) |
920 |
let ?sa = "simpnum a" |
|
921 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
922 |
by simp |
|
923 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
924 |
then show ?case |
|
925 |
proof cases |
|
926 |
case 1 |
|
927 |
then show ?thesis using sa by simp |
|
928 |
next |
|
929 |
case 2 |
|
930 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
931 |
qed |
|
29789 | 932 |
next |
60710 | 933 |
case (8 a) |
934 |
let ?sa = "simpnum a" |
|
935 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
936 |
by simp |
|
937 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
938 |
then show ?case |
|
939 |
proof cases |
|
940 |
case 1 |
|
941 |
then show ?thesis using sa by simp |
|
942 |
next |
|
943 |
case 2 |
|
944 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
945 |
qed |
|
29789 | 946 |
next |
60710 | 947 |
case (9 a) |
948 |
let ?sa = "simpnum a" |
|
949 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
950 |
by simp |
|
951 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
952 |
then show ?case |
|
953 |
proof cases |
|
954 |
case 1 |
|
955 |
then show ?thesis using sa by simp |
|
956 |
next |
|
957 |
case 2 |
|
958 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
959 |
qed |
|
29789 | 960 |
next |
60710 | 961 |
case (10 a) |
962 |
let ?sa = "simpnum a" |
|
963 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
964 |
by simp |
|
965 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
966 |
then show ?case |
|
967 |
proof cases |
|
968 |
case 1 |
|
969 |
then show ?thesis using sa by simp |
|
970 |
next |
|
971 |
case 2 |
|
972 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
973 |
qed |
|
29789 | 974 |
next |
60710 | 975 |
case (11 a) |
976 |
let ?sa = "simpnum a" |
|
977 |
from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" |
|
978 |
by simp |
|
979 |
consider v where "?sa = C v" | "\<not> (\<exists>v. ?sa = C v)" by blast |
|
980 |
then show ?case |
|
981 |
proof cases |
|
982 |
case 1 |
|
983 |
then show ?thesis using sa by simp |
|
984 |
next |
|
985 |
case 2 |
|
986 |
then show ?thesis using sa by (cases ?sa) (simp_all add: Let_def) |
|
987 |
qed |
|
29789 | 988 |
qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not) |
989 |
||
990 |
||
991 |
lemma simpfm_bound0: "bound0 p \<Longrightarrow> bound0 (simpfm p)" |
|
60710 | 992 |
proof (induct p rule: simpfm.induct) |
993 |
case (6 a) |
|
994 |
then have nb: "numbound0 a" by simp |
|
995 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
996 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
29789 | 997 |
next |
60710 | 998 |
case (7 a) |
999 |
then have nb: "numbound0 a" by simp |
|
1000 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
1001 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
29789 | 1002 |
next |
60710 | 1003 |
case (8 a) |
1004 |
then have nb: "numbound0 a" by simp |
|
1005 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
1006 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
29789 | 1007 |
next |
60710 | 1008 |
case (9 a) |
1009 |
then have nb: "numbound0 a" by simp |
|
1010 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
1011 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
29789 | 1012 |
next |
60710 | 1013 |
case (10 a) |
1014 |
then have nb: "numbound0 a" by simp |
|
1015 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
1016 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
29789 | 1017 |
next |
60710 | 1018 |
case (11 a) |
1019 |
then have nb: "numbound0 a" by simp |
|
1020 |
then have "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb]) |
|
1021 |
then show ?case by (cases "simpnum a") (auto simp add: Let_def) |
|
1022 |
qed (auto simp add: disj_def imp_def iff_def conj_def not_bn) |
|
29789 | 1023 |
|
1024 |
lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)" |
|
44779 | 1025 |
apply (induct p rule: simpfm.induct) |
1026 |
apply (auto simp add: Let_def) |
|
1027 |
apply (case_tac "simpnum a", auto)+ |
|
1028 |
done |
|
29789 | 1029 |
|
1030 |
consts prep :: "fm \<Rightarrow> fm" |
|
1031 |
recdef prep "measure fmsize" |
|
1032 |
"prep (E T) = T" |
|
1033 |
"prep (E F) = F" |
|
1034 |
"prep (E (Or p q)) = disj (prep (E p)) (prep (E q))" |
|
1035 |
"prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))" |
|
60710 | 1036 |
"prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" |
29789 | 1037 |
"prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))" |
1038 |
"prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))" |
|
1039 |
"prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))" |
|
1040 |
"prep (E p) = E (prep p)" |
|
1041 |
"prep (A (And p q)) = conj (prep (A p)) (prep (A q))" |
|
1042 |
"prep (A p) = prep (NOT (E (NOT p)))" |
|
1043 |
"prep (NOT (NOT p)) = prep p" |
|
1044 |
"prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))" |
|
1045 |
"prep (NOT (A p)) = prep (E (NOT p))" |
|
1046 |
"prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))" |
|
1047 |
"prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))" |
|
1048 |
"prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))" |
|
1049 |
"prep (NOT p) = not (prep p)" |
|
1050 |
"prep (Or p q) = disj (prep p) (prep q)" |
|
1051 |
"prep (And p q) = conj (prep p) (prep q)" |
|
1052 |
"prep (Imp p q) = prep (Or (NOT p) q)" |
|
1053 |
"prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))" |
|
1054 |
"prep p = p" |
|
60710 | 1055 |
(hints simp add: fmsize_pos) |
1056 |
||
1057 |
lemma prep: "\<And>bs. Ifm bs (prep p) = Ifm bs p" |
|
44779 | 1058 |
by (induct p rule: prep.induct) auto |
29789 | 1059 |
|
1060 |
(* Generic quantifier elimination *) |
|
60710 | 1061 |
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" |
1062 |
where |
|
1063 |
"qelim (E p) = (\<lambda>qe. DJ qe (qelim p qe))" |
|
1064 |
| "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))" |
|
1065 |
| "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))" |
|
1066 |
| "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))" |
|
1067 |
| "qelim (Or p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))" |
|
1068 |
| "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))" |
|
1069 |
| "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))" |
|
1070 |
| "qelim p = (\<lambda>y. simpfm p)" |
|
1071 |
by pat_completeness auto |
|
36853 | 1072 |
termination qelim by (relation "measure fmsize") simp_all |
29789 | 1073 |
|
1074 |
lemma qelim_ci: |
|
60710 | 1075 |
assumes qe_inv: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))" |
1076 |
shows "\<And>bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)" |
|
1077 |
using qe_inv DJ_qe[OF qe_inv] |
|
1078 |
by (induct p rule: qelim.induct) |
|
1079 |
(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf |
|
1080 |
simpfm simpfm_qf simp del: simpfm.simps) |
|
29789 | 1081 |
|
60710 | 1082 |
fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*) |
1083 |
where |
|
1084 |
"minusinf (And p q) = conj (minusinf p) (minusinf q)" |
|
1085 |
| "minusinf (Or p q) = disj (minusinf p) (minusinf q)" |
|
36853 | 1086 |
| "minusinf (Eq (CN 0 c e)) = F" |
1087 |
| "minusinf (NEq (CN 0 c e)) = T" |
|
1088 |
| "minusinf (Lt (CN 0 c e)) = T" |
|
1089 |
| "minusinf (Le (CN 0 c e)) = T" |
|
1090 |
| "minusinf (Gt (CN 0 c e)) = F" |
|
1091 |
| "minusinf (Ge (CN 0 c e)) = F" |
|
1092 |
| "minusinf p = p" |
|
29789 | 1093 |
|
60710 | 1094 |
fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*) |
1095 |
where |
|
1096 |
"plusinf (And p q) = conj (plusinf p) (plusinf q)" |
|
1097 |
| "plusinf (Or p q) = disj (plusinf p) (plusinf q)" |
|
36853 | 1098 |
| "plusinf (Eq (CN 0 c e)) = F" |
1099 |
| "plusinf (NEq (CN 0 c e)) = T" |
|
1100 |
| "plusinf (Lt (CN 0 c e)) = F" |
|
1101 |
| "plusinf (Le (CN 0 c e)) = F" |
|
1102 |
| "plusinf (Gt (CN 0 c e)) = T" |
|
1103 |
| "plusinf (Ge (CN 0 c e)) = T" |
|
1104 |
| "plusinf p = p" |
|
29789 | 1105 |
|
60710 | 1106 |
fun isrlfm :: "fm \<Rightarrow> bool" (* Linearity test for fm *) |
1107 |
where |
|
1108 |
"isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" |
|
1109 |
| "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" |
|
36853 | 1110 |
| "isrlfm (Eq (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
1111 |
| "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
1112 |
| "isrlfm (Lt (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
1113 |
| "isrlfm (Le (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
1114 |
| "isrlfm (Gt (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
1115 |
| "isrlfm (Ge (CN 0 c e)) = (c>0 \<and> numbound0 e)" |
|
1116 |
| "isrlfm p = (isatom p \<and> (bound0 p))" |
|
29789 | 1117 |
|
1118 |
(* splits the bounded from the unbounded part*) |
|
60710 | 1119 |
function (sequential) rsplit0 :: "num \<Rightarrow> int \<times> num" |
1120 |
where |
|
29789 | 1121 |
"rsplit0 (Bound 0) = (1,C 0)" |
60710 | 1122 |
| "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a; (cb,tb) = rsplit0 b in (ca + cb, Add ta tb))" |
36853 | 1123 |
| "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))" |
60710 | 1124 |
| "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (- c, Neg t))" |
1125 |
| "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c * ca, Mul c ta))" |
|
1126 |
| "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c + ca, ta))" |
|
1127 |
| "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca, CN n c ta))" |
|
36853 | 1128 |
| "rsplit0 t = (0,t)" |
60710 | 1129 |
by pat_completeness auto |
36853 | 1130 |
termination rsplit0 by (relation "measure num_size") simp_all |
1131 |
||
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1132 |
lemma rsplit0: "Inum bs ((case_prod (CN 0)) (rsplit0 t)) = Inum bs t \<and> numbound0 (snd (rsplit0 t))" |
29789 | 1133 |
proof (induct t rule: rsplit0.induct) |
60710 | 1134 |
case (2 a b) |
1135 |
let ?sa = "rsplit0 a" |
|
1136 |
let ?sb = "rsplit0 b" |
|
1137 |
let ?ca = "fst ?sa" |
|
1138 |
let ?cb = "fst ?sb" |
|
1139 |
let ?ta = "snd ?sa" |
|
1140 |
let ?tb = "snd ?sb" |
|
1141 |
from 2 have nb: "numbound0 (snd(rsplit0 (Add a b)))" |
|
36853 | 1142 |
by (cases "rsplit0 a") (auto simp add: Let_def split_def) |
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1143 |
have "Inum bs ((case_prod (CN 0)) (rsplit0 (Add a b))) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1144 |
Inum bs ((case_prod (CN 0)) ?sa)+Inum bs ((case_prod (CN 0)) ?sb)" |
29789 | 1145 |
by (simp add: Let_def split_def algebra_simps) |
60710 | 1146 |
also have "\<dots> = Inum bs a + Inum bs b" |
1147 |
using 2 by (cases "rsplit0 a") auto |
|
1148 |
finally show ?case |
|
1149 |
using nb by simp |
|
49962
a8cc904a6820
Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents:
49070
diff
changeset
|
1150 |
qed (auto simp add: Let_def split_def algebra_simps, simp add: distrib_left[symmetric]) |
29789 | 1151 |
|
1152 |
(* Linearize a formula*) |
|
60710 | 1153 |
definition lt :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1154 |
where |
60710 | 1155 |
"lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) |
29789 | 1156 |
else (Gt (CN 0 (-c) (Neg t))))" |
1157 |
||
60710 | 1158 |
definition le :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1159 |
where |
60710 | 1160 |
"le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) |
29789 | 1161 |
else (Ge (CN 0 (-c) (Neg t))))" |
1162 |
||
60710 | 1163 |
definition gt :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1164 |
where |
60710 | 1165 |
"gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) |
29789 | 1166 |
else (Lt (CN 0 (-c) (Neg t))))" |
1167 |
||
60710 | 1168 |
definition ge :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1169 |
where |
60710 | 1170 |
"ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) |
29789 | 1171 |
else (Le (CN 0 (-c) (Neg t))))" |
1172 |
||
60710 | 1173 |
definition eq :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1174 |
where |
60710 | 1175 |
"eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) |
29789 | 1176 |
else (Eq (CN 0 (-c) (Neg t))))" |
1177 |
||
60710 | 1178 |
definition neq :: "int \<Rightarrow> num \<Rightarrow> fm" |
29789 | 1179 |
where |
60710 | 1180 |
"neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) |
29789 | 1181 |
else (NEq (CN 0 (-c) (Neg t))))" |
1182 |
||
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1183 |
lemma lt: "numnoabs t \<Longrightarrow> Ifm bs (case_prod lt (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1184 |
Ifm bs (Lt t) \<and> isrlfm (case_prod lt (rsplit0 t))" |
60710 | 1185 |
using rsplit0[where bs = "bs" and t="t"] |
1186 |
by (auto simp add: lt_def split_def, cases "snd(rsplit0 t)", auto, |
|
1187 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1188 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1189 |
lemma le: "numnoabs t \<Longrightarrow> Ifm bs (case_prod le (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1190 |
Ifm bs (Le t) \<and> isrlfm (case_prod le (rsplit0 t))" |
60710 | 1191 |
using rsplit0[where bs = "bs" and t="t"] |
1192 |
by (auto simp add: le_def split_def, cases "snd(rsplit0 t)", auto, |
|
1193 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1194 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1195 |
lemma gt: "numnoabs t \<Longrightarrow> Ifm bs (case_prod gt (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1196 |
Ifm bs (Gt t) \<and> isrlfm (case_prod gt (rsplit0 t))" |
60710 | 1197 |
using rsplit0[where bs = "bs" and t="t"] |
1198 |
by (auto simp add: gt_def split_def, cases "snd(rsplit0 t)", auto, |
|
1199 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1200 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1201 |
lemma ge: "numnoabs t \<Longrightarrow> Ifm bs (case_prod ge (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1202 |
Ifm bs (Ge t) \<and> isrlfm (case_prod ge (rsplit0 t))" |
60710 | 1203 |
using rsplit0[where bs = "bs" and t="t"] |
1204 |
by (auto simp add: ge_def split_def, cases "snd(rsplit0 t)", auto, |
|
1205 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1206 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1207 |
lemma eq: "numnoabs t \<Longrightarrow> Ifm bs (case_prod eq (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1208 |
Ifm bs (Eq t) \<and> isrlfm (case_prod eq (rsplit0 t))" |
60710 | 1209 |
using rsplit0[where bs = "bs" and t="t"] |
1210 |
by (auto simp add: eq_def split_def, cases "snd(rsplit0 t)", auto, |
|
1211 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1212 |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1213 |
lemma neq: "numnoabs t \<Longrightarrow> Ifm bs (case_prod neq (rsplit0 t)) = |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1214 |
Ifm bs (NEq t) \<and> isrlfm (case_prod neq (rsplit0 t))" |
60710 | 1215 |
using rsplit0[where bs = "bs" and t="t"] |
1216 |
by (auto simp add: neq_def split_def, cases "snd(rsplit0 t)", auto, |
|
1217 |
rename_tac nat a b, case_tac "nat", auto) |
|
29789 | 1218 |
|
1219 |
lemma conj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)" |
|
60710 | 1220 |
by (auto simp add: conj_def) |
1221 |
||
29789 | 1222 |
lemma disj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)" |
60710 | 1223 |
by (auto simp add: disj_def) |
29789 | 1224 |
|
1225 |
consts rlfm :: "fm \<Rightarrow> fm" |
|
1226 |
recdef rlfm "measure fmsize" |
|
1227 |
"rlfm (And p q) = conj (rlfm p) (rlfm q)" |
|
1228 |
"rlfm (Or p q) = disj (rlfm p) (rlfm q)" |
|
1229 |
"rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)" |
|
1230 |
"rlfm (Iff p q) = disj (conj (rlfm p) (rlfm q)) (conj (rlfm (NOT p)) (rlfm (NOT q)))" |
|
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1231 |
"rlfm (Lt a) = case_prod lt (rsplit0 a)" |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1232 |
"rlfm (Le a) = case_prod le (rsplit0 a)" |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1233 |
"rlfm (Gt a) = case_prod gt (rsplit0 a)" |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1234 |
"rlfm (Ge a) = case_prod ge (rsplit0 a)" |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1235 |
"rlfm (Eq a) = case_prod eq (rsplit0 a)" |
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
1236 |
"rlfm (NEq a) = case_prod neq (rsplit0 a)" |
29789 | 1237 |
"rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))" |
1238 |
"rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))" |
|
1239 |
"rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))" |
|
1240 |
"rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))" |
|
1241 |
"rlfm (NOT (NOT p)) = rlfm p" |
|
1242 |
"rlfm (NOT T) = F" |
|
1243 |
"rlfm (NOT F) = T" |
|
1244 |
"rlfm (NOT (Lt a)) = rlfm (Ge a)" |
|
1245 |
"rlfm (NOT (Le a)) = rlfm (Gt a)" |
|
1246 |
"rlfm (NOT (Gt a)) = rlfm (Le a)" |
|
1247 |
"rlfm (NOT (Ge a)) = rlfm (Lt a)" |
|
1248 |
"rlfm (NOT (Eq a)) = rlfm (NEq a)" |
|
1249 |
"rlfm (NOT (NEq a)) = rlfm (Eq a)" |
|
60710 | 1250 |
"rlfm p = p" |
1251 |
(hints simp add: fmsize_pos) |
|
29789 | 1252 |
|
1253 |
lemma rlfm_I: |
|
1254 |
assumes qfp: "qfree p" |
|
1255 |
shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)" |
|
60710 | 1256 |
using qfp |
1257 |
by (induct p rule: rlfm.induct) (auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin) |
|
29789 | 1258 |
|
1259 |
(* Operations needed for Ferrante and Rackoff *) |
|
1260 |
lemma rminusinf_inf: |
|
1261 |
assumes lp: "isrlfm p" |
|
60710 | 1262 |
shows "\<exists>z. \<forall>x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\<exists>z. \<forall>x. ?P z x p") |
1263 |
using lp |
|
29789 | 1264 |
proof (induct p rule: minusinf.induct) |
44779 | 1265 |
case (1 p q) |
60710 | 1266 |
then show ?case |
1267 |
apply auto |
|
1268 |
apply (rule_tac x= "min z za" in exI) |
|
1269 |
apply auto |
|
1270 |
done |
|
29789 | 1271 |
next |
44779 | 1272 |
case (2 p q) |
60710 | 1273 |
then show ?case |
1274 |
apply auto |
|
1275 |
apply (rule_tac x= "min z za" in exI) |
|
1276 |
apply auto |
|
1277 |
done |
|
29789 | 1278 |
next |
60710 | 1279 |
case (3 c e) |
41807 | 1280 |
from 3 have nb: "numbound0 e" by simp |
1281 |
from 3 have cp: "real c > 0" by simp |
|
29789 | 1282 |
fix a |
60710 | 1283 |
let ?e = "Inum (a#bs) e" |
29789 | 1284 |
let ?z = "(- ?e) / real c" |
60710 | 1285 |
{ |
1286 |
fix x |
|
29789 | 1287 |
assume xz: "x < ?z" |
60710 | 1288 |
then have "(real c * x < - ?e)" |
1289 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1290 |
then have "real c * x + ?e < 0" by arith |
|
1291 |
then have "real c * x + ?e \<noteq> 0" by simp |
|
29789 | 1292 |
with xz have "?P ?z x (Eq (CN 0 c e))" |
60710 | 1293 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1294 |
} |
|
1295 |
then have "\<forall>x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp |
|
1296 |
then show ?case by blast |
|
29789 | 1297 |
next |
60710 | 1298 |
case (4 c e) |
41807 | 1299 |
from 4 have nb: "numbound0 e" by simp |
1300 |
from 4 have cp: "real c > 0" by simp |
|
29789 | 1301 |
fix a |
60710 | 1302 |
let ?e = "Inum (a # bs) e" |
29789 | 1303 |
let ?z = "(- ?e) / real c" |
60710 | 1304 |
{ |
1305 |
fix x |
|
29789 | 1306 |
assume xz: "x < ?z" |
60710 | 1307 |
then have "(real c * x < - ?e)" |
1308 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1309 |
then have "real c * x + ?e < 0" by arith |
|
1310 |
then have "real c * x + ?e \<noteq> 0" by simp |
|
29789 | 1311 |
with xz have "?P ?z x (NEq (CN 0 c e))" |
60710 | 1312 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1313 |
} |
|
1314 |
then have "\<forall>x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp |
|
1315 |
then show ?case by blast |
|
29789 | 1316 |
next |
60710 | 1317 |
case (5 c e) |
41807 | 1318 |
from 5 have nb: "numbound0 e" by simp |
1319 |
from 5 have cp: "real c > 0" by simp |
|
29789 | 1320 |
fix a |
1321 |
let ?e="Inum (a#bs) e" |
|
1322 |
let ?z = "(- ?e) / real c" |
|
60710 | 1323 |
{ |
1324 |
fix x |
|
29789 | 1325 |
assume xz: "x < ?z" |
60710 | 1326 |
then have "(real c * x < - ?e)" |
1327 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1328 |
then have "real c * x + ?e < 0" by arith |
|
29789 | 1329 |
with xz have "?P ?z x (Lt (CN 0 c e))" |
60710 | 1330 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1331 |
} |
|
1332 |
then have "\<forall>x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp |
|
1333 |
then show ?case by blast |
|
29789 | 1334 |
next |
60710 | 1335 |
case (6 c e) |
41807 | 1336 |
from 6 have nb: "numbound0 e" by simp |
1337 |
from lp 6 have cp: "real c > 0" by simp |
|
29789 | 1338 |
fix a |
60710 | 1339 |
let ?e = "Inum (a # bs) e" |
29789 | 1340 |
let ?z = "(- ?e) / real c" |
60710 | 1341 |
{ |
1342 |
fix x |
|
29789 | 1343 |
assume xz: "x < ?z" |
60710 | 1344 |
then have "(real c * x < - ?e)" |
1345 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1346 |
then have "real c * x + ?e < 0" by arith |
|
29789 | 1347 |
with xz have "?P ?z x (Le (CN 0 c e))" |
60710 | 1348 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1349 |
} |
|
1350 |
then have "\<forall>x < ?z. ?P ?z x (Le (CN 0 c e))" by simp |
|
1351 |
then show ?case by blast |
|
29789 | 1352 |
next |
60710 | 1353 |
case (7 c e) |
41807 | 1354 |
from 7 have nb: "numbound0 e" by simp |
1355 |
from 7 have cp: "real c > 0" by simp |
|
29789 | 1356 |
fix a |
60710 | 1357 |
let ?e = "Inum (a # bs) e" |
29789 | 1358 |
let ?z = "(- ?e) / real c" |
60710 | 1359 |
{ |
1360 |
fix x |
|
29789 | 1361 |
assume xz: "x < ?z" |
60710 | 1362 |
then have "(real c * x < - ?e)" |
1363 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1364 |
then have "real c * x + ?e < 0" by arith |
|
29789 | 1365 |
with xz have "?P ?z x (Gt (CN 0 c e))" |
60710 | 1366 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1367 |
} |
|
1368 |
then have "\<forall>x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp |
|
1369 |
then show ?case by blast |
|
29789 | 1370 |
next |
60710 | 1371 |
case (8 c e) |
41807 | 1372 |
from 8 have nb: "numbound0 e" by simp |
1373 |
from 8 have cp: "real c > 0" by simp |
|
29789 | 1374 |
fix a |
1375 |
let ?e="Inum (a#bs) e" |
|
1376 |
let ?z = "(- ?e) / real c" |
|
60710 | 1377 |
{ |
1378 |
fix x |
|
29789 | 1379 |
assume xz: "x < ?z" |
60710 | 1380 |
then have "(real c * x < - ?e)" |
1381 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] ac_simps) |
|
1382 |
then have "real c * x + ?e < 0" by arith |
|
29789 | 1383 |
with xz have "?P ?z x (Ge (CN 0 c e))" |
60710 | 1384 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1385 |
} |
|
1386 |
then have "\<forall>x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp |
|
1387 |
then show ?case by blast |
|
29789 | 1388 |
qed simp_all |
1389 |
||
1390 |
lemma rplusinf_inf: |
|
1391 |
assumes lp: "isrlfm p" |
|
60710 | 1392 |
shows "\<exists>z. \<forall>x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\<exists>z. \<forall>x. ?P z x p") |
29789 | 1393 |
using lp |
1394 |
proof (induct p rule: isrlfm.induct) |
|
60710 | 1395 |
case (1 p q) |
1396 |
then show ?case |
|
1397 |
apply auto |
|
1398 |
apply (rule_tac x= "max z za" in exI) |
|
1399 |
apply auto |
|
1400 |
done |
|
29789 | 1401 |
next |
60710 | 1402 |
case (2 p q) |
1403 |
then show ?case |
|
1404 |
apply auto |
|
1405 |
apply (rule_tac x= "max z za" in exI) |
|
1406 |
apply auto |
|
1407 |
done |
|
29789 | 1408 |
next |
60710 | 1409 |
case (3 c e) |
41807 | 1410 |
from 3 have nb: "numbound0 e" by simp |
1411 |
from 3 have cp: "real c > 0" by simp |
|
29789 | 1412 |
fix a |
60710 | 1413 |
let ?e = "Inum (a # bs) e" |
29789 | 1414 |
let ?z = "(- ?e) / real c" |
60710 | 1415 |
{ |
1416 |
fix x |
|
29789 | 1417 |
assume xz: "x > ?z" |
1418 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1419 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1420 |
then have "real c * x + ?e > 0" by arith |
1421 |
then have "real c * x + ?e \<noteq> 0" by simp |
|
29789 | 1422 |
with xz have "?P ?z x (Eq (CN 0 c e))" |
60710 | 1423 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1424 |
} |
|
1425 |
then have "\<forall>x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp |
|
1426 |
then show ?case by blast |
|
29789 | 1427 |
next |
60710 | 1428 |
case (4 c e) |
41807 | 1429 |
from 4 have nb: "numbound0 e" by simp |
1430 |
from 4 have cp: "real c > 0" by simp |
|
29789 | 1431 |
fix a |
60710 | 1432 |
let ?e = "Inum (a # bs) e" |
29789 | 1433 |
let ?z = "(- ?e) / real c" |
60710 | 1434 |
{ |
1435 |
fix x |
|
29789 | 1436 |
assume xz: "x > ?z" |
1437 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1438 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1439 |
then have "real c * x + ?e > 0" by arith |
1440 |
then have "real c * x + ?e \<noteq> 0" by simp |
|
29789 | 1441 |
with xz have "?P ?z x (NEq (CN 0 c e))" |
60710 | 1442 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1443 |
} |
|
1444 |
then have "\<forall>x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp |
|
1445 |
then show ?case by blast |
|
29789 | 1446 |
next |
60710 | 1447 |
case (5 c e) |
41807 | 1448 |
from 5 have nb: "numbound0 e" by simp |
1449 |
from 5 have cp: "real c > 0" by simp |
|
29789 | 1450 |
fix a |
60710 | 1451 |
let ?e = "Inum (a # bs) e" |
29789 | 1452 |
let ?z = "(- ?e) / real c" |
60710 | 1453 |
{ |
1454 |
fix x |
|
29789 | 1455 |
assume xz: "x > ?z" |
1456 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1457 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1458 |
then have "real c * x + ?e > 0" by arith |
29789 | 1459 |
with xz have "?P ?z x (Lt (CN 0 c e))" |
60710 | 1460 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1461 |
} |
|
1462 |
then have "\<forall>x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp |
|
1463 |
then show ?case by blast |
|
29789 | 1464 |
next |
60710 | 1465 |
case (6 c e) |
41807 | 1466 |
from 6 have nb: "numbound0 e" by simp |
1467 |
from 6 have cp: "real c > 0" by simp |
|
29789 | 1468 |
fix a |
60710 | 1469 |
let ?e = "Inum (a # bs) e" |
29789 | 1470 |
let ?z = "(- ?e) / real c" |
60710 | 1471 |
{ |
1472 |
fix x |
|
29789 | 1473 |
assume xz: "x > ?z" |
1474 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1475 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1476 |
then have "real c * x + ?e > 0" by arith |
29789 | 1477 |
with xz have "?P ?z x (Le (CN 0 c e))" |
60710 | 1478 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1479 |
} |
|
1480 |
then have "\<forall>x > ?z. ?P ?z x (Le (CN 0 c e))" by simp |
|
1481 |
then show ?case by blast |
|
29789 | 1482 |
next |
60710 | 1483 |
case (7 c e) |
41807 | 1484 |
from 7 have nb: "numbound0 e" by simp |
1485 |
from 7 have cp: "real c > 0" by simp |
|
29789 | 1486 |
fix a |
60710 | 1487 |
let ?e = "Inum (a # bs) e" |
29789 | 1488 |
let ?z = "(- ?e) / real c" |
60710 | 1489 |
{ |
1490 |
fix x |
|
29789 | 1491 |
assume xz: "x > ?z" |
1492 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1493 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1494 |
then have "real c * x + ?e > 0" by arith |
29789 | 1495 |
with xz have "?P ?z x (Gt (CN 0 c e))" |
60710 | 1496 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1497 |
} |
|
1498 |
then have "\<forall>x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp |
|
1499 |
then show ?case by blast |
|
29789 | 1500 |
next |
60710 | 1501 |
case (8 c e) |
41807 | 1502 |
from 8 have nb: "numbound0 e" by simp |
1503 |
from 8 have cp: "real c > 0" by simp |
|
29789 | 1504 |
fix a |
1505 |
let ?e="Inum (a#bs) e" |
|
1506 |
let ?z = "(- ?e) / real c" |
|
60710 | 1507 |
{ |
1508 |
fix x |
|
29789 | 1509 |
assume xz: "x > ?z" |
1510 |
with mult_strict_right_mono [OF xz cp] cp |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1511 |
have "(real c * x > - ?e)" by (simp add: ac_simps) |
60710 | 1512 |
then have "real c * x + ?e > 0" by arith |
29789 | 1513 |
with xz have "?P ?z x (Ge (CN 0 c e))" |
60710 | 1514 |
using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp |
1515 |
} |
|
1516 |
then have "\<forall>x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp |
|
1517 |
then show ?case by blast |
|
29789 | 1518 |
qed simp_all |
1519 |
||
1520 |
lemma rminusinf_bound0: |
|
1521 |
assumes lp: "isrlfm p" |
|
1522 |
shows "bound0 (minusinf p)" |
|
60710 | 1523 |
using lp by (induct p rule: minusinf.induct) simp_all |
29789 | 1524 |
|
1525 |
lemma rplusinf_bound0: |
|
1526 |
assumes lp: "isrlfm p" |
|
1527 |
shows "bound0 (plusinf p)" |
|
60710 | 1528 |
using lp by (induct p rule: plusinf.induct) simp_all |
29789 | 1529 |
|
1530 |
lemma rminusinf_ex: |
|
1531 |
assumes lp: "isrlfm p" |
|
60710 | 1532 |
and ex: "Ifm (a#bs) (minusinf p)" |
1533 |
shows "\<exists>x. Ifm (x#bs) p" |
|
1534 |
proof - |
|
29789 | 1535 |
from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex |
60710 | 1536 |
have th: "\<forall>x. Ifm (x#bs) (minusinf p)" by auto |
1537 |
from rminusinf_inf[OF lp, where bs="bs"] |
|
29789 | 1538 |
obtain z where z_def: "\<forall>x<z. Ifm (x # bs) (minusinf p) = Ifm (x # bs) p" by blast |
60710 | 1539 |
from th have "Ifm ((z - 1) # bs) (minusinf p)" by simp |
29789 | 1540 |
moreover have "z - 1 < z" by simp |
1541 |
ultimately show ?thesis using z_def by auto |
|
1542 |
qed |
|
1543 |
||
1544 |
lemma rplusinf_ex: |
|
1545 |
assumes lp: "isrlfm p" |
|
60710 | 1546 |
and ex: "Ifm (a # bs) (plusinf p)" |
1547 |
shows "\<exists>x. Ifm (x # bs) p" |
|
1548 |
proof - |
|
29789 | 1549 |
from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex |
60710 | 1550 |
have th: "\<forall>x. Ifm (x # bs) (plusinf p)" by auto |
1551 |
from rplusinf_inf[OF lp, where bs="bs"] |
|
29789 | 1552 |
obtain z where z_def: "\<forall>x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast |
60710 | 1553 |
from th have "Ifm ((z + 1) # bs) (plusinf p)" by simp |
29789 | 1554 |
moreover have "z + 1 > z" by simp |
1555 |
ultimately show ?thesis using z_def by auto |
|
1556 |
qed |
|
1557 |
||
60710 | 1558 |
consts |
29789 | 1559 |
uset:: "fm \<Rightarrow> (num \<times> int) list" |
1560 |
usubst :: "fm \<Rightarrow> (num \<times> int) \<Rightarrow> fm " |
|
1561 |
recdef uset "measure size" |
|
60710 | 1562 |
"uset (And p q) = (uset p @ uset q)" |
1563 |
"uset (Or p q) = (uset p @ uset q)" |
|
29789 | 1564 |
"uset (Eq (CN 0 c e)) = [(Neg e,c)]" |
1565 |
"uset (NEq (CN 0 c e)) = [(Neg e,c)]" |
|
1566 |
"uset (Lt (CN 0 c e)) = [(Neg e,c)]" |
|
1567 |
"uset (Le (CN 0 c e)) = [(Neg e,c)]" |
|
1568 |
"uset (Gt (CN 0 c e)) = [(Neg e,c)]" |
|
1569 |
"uset (Ge (CN 0 c e)) = [(Neg e,c)]" |
|
1570 |
"uset p = []" |
|
1571 |
recdef usubst "measure size" |
|
60710 | 1572 |
"usubst (And p q) = (\<lambda>(t,n). And (usubst p (t,n)) (usubst q (t,n)))" |
1573 |
"usubst (Or p q) = (\<lambda>(t,n). Or (usubst p (t,n)) (usubst q (t,n)))" |
|
1574 |
"usubst (Eq (CN 0 c e)) = (\<lambda>(t,n). Eq (Add (Mul c t) (Mul n e)))" |
|
1575 |
"usubst (NEq (CN 0 c e)) = (\<lambda>(t,n). NEq (Add (Mul c t) (Mul n e)))" |
|
1576 |
"usubst (Lt (CN 0 c e)) = (\<lambda>(t,n). Lt (Add (Mul c t) (Mul n e)))" |
|
1577 |
"usubst (Le (CN 0 c e)) = (\<lambda>(t,n). Le (Add (Mul c t) (Mul n e)))" |
|
1578 |
"usubst (Gt (CN 0 c e)) = (\<lambda>(t,n). Gt (Add (Mul c t) (Mul n e)))" |
|
1579 |
"usubst (Ge (CN 0 c e)) = (\<lambda>(t,n). Ge (Add (Mul c t) (Mul n e)))" |
|
1580 |
"usubst p = (\<lambda>(t, n). p)" |
|
29789 | 1581 |
|
60710 | 1582 |
lemma usubst_I: |
1583 |
assumes lp: "isrlfm p" |
|
1584 |
and np: "real n > 0" |
|
1585 |
and nbt: "numbound0 t" |
|
1586 |
shows "(Ifm (x # bs) (usubst p (t,n)) = |
|
1587 |
Ifm (((Inum (x # bs) t) / (real n)) # bs) p) \<and> bound0 (usubst p (t, n))" |
|
1588 |
(is "(?I x (usubst p (t, n)) = ?I ?u p) \<and> ?B p" |
|
1589 |
is "(_ = ?I (?t/?n) p) \<and> _" |
|
1590 |
is "(_ = ?I (?N x t /_) p) \<and> _") |
|
29789 | 1591 |
using lp |
60710 | 1592 |
proof (induct p rule: usubst.induct) |
1593 |
case (5 c e) |
|
1594 |
with assms have cp: "c > 0" and nb: "numbound0 e" by simp_all |
|
1595 |
have "?I ?u (Lt (CN 0 c e)) \<longleftrightarrow> real c * (?t / ?n) + ?N x e < 0" |
|
29789 | 1596 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
60710 | 1597 |
also have "\<dots> \<longleftrightarrow> ?n * (real c * (?t / ?n)) + ?n*(?N x e) < 0" |
1598 |
by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
29789 | 1599 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1600 |
also have "\<dots> \<longleftrightarrow> real c * ?t + ?n * (?N x e) < 0" using np by simp |
29789 | 1601 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
1602 |
next |
|
60710 | 1603 |
case (6 c e) |
1604 |
with assms have cp: "c > 0" and nb: "numbound0 e" by simp_all |
|
1605 |
have "?I ?u (Le (CN 0 c e)) \<longleftrightarrow> real c * (?t / ?n) + ?N x e \<le> 0" |
|
29789 | 1606 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
1607 |
also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<le> 0)" |
|
60710 | 1608 |
by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
29789 | 1609 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1610 |
also have "\<dots> = (real c *?t + ?n* (?N x e) \<le> 0)" using np by simp |
29789 | 1611 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
1612 |
next |
|
60710 | 1613 |
case (7 c e) |
1614 |
with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
|
1615 |
have "?I ?u (Gt (CN 0 c e)) \<longleftrightarrow> real c *(?t / ?n) + ?N x e > 0" |
|
29789 | 1616 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
60710 | 1617 |
also have "\<dots> \<longleftrightarrow> ?n * (real c * (?t / ?n)) + ?n * ?N x e > 0" |
1618 |
by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
29789 | 1619 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1620 |
also have "\<dots> \<longleftrightarrow> real c * ?t + ?n * ?N x e > 0" using np by simp |
29789 | 1621 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
1622 |
next |
|
60710 | 1623 |
case (8 c e) |
1624 |
with assms have cp: "c > 0" and nb: "numbound0 e" by simp_all |
|
1625 |
have "?I ?u (Ge (CN 0 c e)) \<longleftrightarrow> real c * (?t / ?n) + ?N x e \<ge> 0" |
|
29789 | 1626 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
60710 | 1627 |
also have "\<dots> \<longleftrightarrow> ?n * (real c * (?t / ?n)) + ?n * ?N x e \<ge> 0" |
1628 |
by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
29789 | 1629 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1630 |
also have "\<dots> \<longleftrightarrow> real c * ?t + ?n * ?N x e \<ge> 0" using np by simp |
29789 | 1631 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
1632 |
next |
|
60710 | 1633 |
case (3 c e) |
1634 |
with assms have cp: "c > 0" and nb: "numbound0 e" by simp_all |
|
29789 | 1635 |
from np have np: "real n \<noteq> 0" by simp |
60710 | 1636 |
have "?I ?u (Eq (CN 0 c e)) \<longleftrightarrow> real c * (?t / ?n) + ?N x e = 0" |
29789 | 1637 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
60710 | 1638 |
also have "\<dots> \<longleftrightarrow> ?n * (real c * (?t / ?n)) + ?n * ?N x e = 0" |
1639 |
by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
29789 | 1640 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1641 |
also have "\<dots> \<longleftrightarrow> real c * ?t + ?n * ?N x e = 0" using np by simp |
29789 | 1642 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
1643 |
next |
|
41807 | 1644 |
case (4 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all |
29789 | 1645 |
from np have np: "real n \<noteq> 0" by simp |
60710 | 1646 |
have "?I ?u (NEq (CN 0 c e)) \<longleftrightarrow> real c * (?t / ?n) + ?N x e \<noteq> 0" |
29789 | 1647 |
using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp |
60710 | 1648 |
also have "\<dots> \<longleftrightarrow> ?n * (real c * (?t / ?n)) + ?n * ?N x e \<noteq> 0" |
1649 |
by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" |
|
29789 | 1650 |
and b="0", simplified divide_zero_left]) (simp only: algebra_simps) |
60710 | 1651 |
also have "\<dots> \<longleftrightarrow> real c * ?t + ?n * ?N x e \<noteq> 0" using np by simp |
29789 | 1652 |
finally show ?case using nbt nb by (simp add: algebra_simps) |
41842 | 1653 |
qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"]) |
29789 | 1654 |
|
1655 |
lemma uset_l: |
|
1656 |
assumes lp: "isrlfm p" |
|
60710 | 1657 |
shows "\<forall>(t,k) \<in> set (uset p). numbound0 t \<and> k > 0" |
1658 |
using lp by (induct p rule: uset.induct) auto |
|
29789 | 1659 |
|
1660 |
lemma rminusinf_uset: |
|
1661 |
assumes lp: "isrlfm p" |
|
60710 | 1662 |
and nmi: "\<not> (Ifm (a # bs) (minusinf p))" (is "\<not> (Ifm (a # bs) (?M p))") |
1663 |
and ex: "Ifm (x#bs) p" (is "?I x p") |
|
1664 |
shows "\<exists>(s,m) \<in> set (uset p). x \<ge> Inum (a#bs) s / real m" |
|
1665 |
(is "\<exists>(s,m) \<in> ?U p. x \<ge> ?N a s / real m") |
|
1666 |
proof - |
|
1667 |
have "\<exists>(s,m) \<in> set (uset p). real m * x \<ge> Inum (a#bs) s" |
|
1668 |
(is "\<exists>(s,m) \<in> ?U p. real m *x \<ge> ?N a s") |
|
29789 | 1669 |
using lp nmi ex |
60710 | 1670 |
by (induct p rule: minusinf.induct) (auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"]) |
1671 |
then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<ge> ?N a s" |
|
1672 |
by blast |
|
1673 |
from uset_l[OF lp] smU have mp: "real m > 0" |
|
1674 |
by auto |
|
1675 |
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" |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
56544
diff
changeset
|
1676 |
by (auto simp add: mult.commute) |
60710 | 1677 |
then show ?thesis |
1678 |
using smU by auto |
|
29789 | 1679 |
qed |
1680 |
||
1681 |
lemma rplusinf_uset: |
|
1682 |
assumes lp: "isrlfm p" |
|
60710 | 1683 |
and nmi: "\<not> (Ifm (a # bs) (plusinf p))" (is "\<not> (Ifm (a # bs) (?M p))") |
1684 |
and ex: "Ifm (x # bs) p" (is "?I x p") |
|
1685 |
shows "\<exists>(s,m) \<in> set (uset p). x \<le> Inum (a#bs) s / real m" |
|
1686 |
(is "\<exists>(s,m) \<in> ?U p. x \<le> ?N a s / real m") |
|
1687 |
proof - |
|
1688 |
have "\<exists>(s,m) \<in> set (uset p). real m * x \<le> Inum (a#bs) s" |
|
1689 |
(is "\<exists>(s,m) \<in> ?U p. real m *x \<le> ?N a s") |
|
29789 | 1690 |
using lp nmi ex |
60710 | 1691 |
by (induct p rule: minusinf.induct) |
1692 |
(auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"]) |
|
1693 |
then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<le> ?N a s" |
|
1694 |
by blast |
|
1695 |
from uset_l[OF lp] smU have mp: "real m > 0" |
|
1696 |
by auto |
|
1697 |
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" |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
56544
diff
changeset
|
1698 |
by (auto simp add: mult.commute) |
60710 | 1699 |
then show ?thesis |
1700 |
using smU by auto |
|
29789 | 1701 |
qed |
1702 |
||
60710 | 1703 |
lemma lin_dense: |
29789 | 1704 |
assumes lp: "isrlfm p" |
60711 | 1705 |
and noS: "\<forall>t. l < t \<and> t< u \<longrightarrow> t \<notin> (\<lambda>(t,n). Inum (x#bs) t / real n) ` set (uset p)" |
1706 |
(is "\<forall>t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda>(t,n). ?N x t / real n ) ` (?U p)") |
|
1707 |
and lx: "l < x" |
|
1708 |
and xu:"x < u" |
|
1709 |
and px:" Ifm (x#bs) p" |
|
1710 |
and ly: "l < y" and yu: "y < u" |
|
29789 | 1711 |
shows "Ifm (y#bs) p" |
60711 | 1712 |
using lp px noS |
29789 | 1713 |
proof (induct p rule: isrlfm.induct) |
60711 | 1714 |
case (5 c e) |
1715 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1716 |
by simp_all |
|
1717 |
from 5 have "x * real c + ?N x e < 0" |
|
1718 |
by (simp add: algebra_simps) |
|
60710 | 1719 |
then have pxc: "x < (- ?N x e) / real c" |
41807 | 1720 |
by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"]) |
60711 | 1721 |
from 5 have noSc:"\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
1722 |
by auto |
|
1723 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" |
|
1724 |
by auto |
|
1725 |
then consider "y < (-?N x e)/ real c" | "y > (- ?N x e) / real c" |
|
1726 |
by atomize_elim auto |
|
1727 |
then show ?case |
|
1728 |
proof cases |
|
60767 | 1729 |
case 1 |
60711 | 1730 |
then have "y * real c < - ?N x e" |
1731 |
by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1732 |
then have "real c * y + ?N x e < 0" |
|
1733 |
by (simp add: algebra_simps) |
|
1734 |
then show ?thesis |
|
1735 |
using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp |
|
1736 |
next |
|
60767 | 1737 |
case 2 |
60711 | 1738 |
with yu have eu: "u > (- ?N x e) / real c" |
1739 |
by auto |
|
1740 |
with noSc ly yu have "(- ?N x e) / real c \<le> l" |
|
1741 |
by (cases "(- ?N x e) / real c > l") auto |
|
1742 |
with lx pxc have False |
|
1743 |
by auto |
|
1744 |
then show ?thesis .. |
|
1745 |
qed |
|
1746 |
next |
|
1747 |
case (6 c e) |
|
1748 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1749 |
by simp_all |
|
1750 |
from 6 have "x * real c + ?N x e \<le> 0" |
|
1751 |
by (simp add: algebra_simps) |
|
1752 |
then have pxc: "x \<le> (- ?N x e) / real c" |
|
1753 |
by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1754 |
from 6 have noSc:"\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
|
1755 |
by auto |
|
1756 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" |
|
1757 |
by auto |
|
1758 |
then consider "y < (- ?N x e) / real c" | "y > (-?N x e) / real c" |
|
1759 |
by atomize_elim auto |
|
1760 |
then show ?case |
|
1761 |
proof cases |
|
60767 | 1762 |
case 1 |
60710 | 1763 |
then have "y * real c < - ?N x e" |
41807 | 1764 |
by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
60711 | 1765 |
then have "real c * y + ?N x e < 0" |
1766 |
by (simp add: algebra_simps) |
|
1767 |
then show ?thesis |
|
1768 |
using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp |
|
1769 |
next |
|
60767 | 1770 |
case 2 |
60711 | 1771 |
with yu have eu: "u > (- ?N x e) / real c" |
1772 |
by auto |
|
1773 |
with noSc ly yu have "(- ?N x e) / real c \<le> l" |
|
1774 |
by (cases "(- ?N x e) / real c > l") auto |
|
1775 |
with lx pxc have False |
|
1776 |
by auto |
|
1777 |
then show ?thesis .. |
|
1778 |
qed |
|
29789 | 1779 |
next |
60711 | 1780 |
case (7 c e) |
1781 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1782 |
by simp_all |
|
1783 |
from 7 have "x * real c + ?N x e > 0" |
|
1784 |
by (simp add: algebra_simps) |
|
60710 | 1785 |
then have pxc: "x > (- ?N x e) / real c" |
41807 | 1786 |
by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"]) |
60711 | 1787 |
from 7 have noSc: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
1788 |
by auto |
|
1789 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" |
|
1790 |
by auto |
|
1791 |
then consider "y > (- ?N x e) / real c" | "y < (-?N x e) / real c" |
|
1792 |
by atomize_elim auto |
|
1793 |
then show ?case |
|
1794 |
proof cases |
|
1795 |
case 1 |
|
1796 |
then have "y * real c > - ?N x e" |
|
1797 |
by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
|
1798 |
then have "real c * y + ?N x e > 0" |
|
1799 |
by (simp add: algebra_simps) |
|
1800 |
then show ?thesis |
|
1801 |
using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp |
|
1802 |
next |
|
1803 |
case 2 |
|
1804 |
with ly have eu: "l < (- ?N x e) / real c" |
|
1805 |
by auto |
|
1806 |
with noSc ly yu have "(- ?N x e) / real c \<ge> u" |
|
1807 |
by (cases "(- ?N x e) / real c > l") auto |
|
1808 |
with xu pxc have False by auto |
|
1809 |
then show ?thesis .. |
|
1810 |
qed |
|
1811 |
next |
|
1812 |
case (8 c e) |
|
1813 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1814 |
by simp_all |
|
1815 |
from 8 have "x * real c + ?N x e \<ge> 0" |
|
1816 |
by (simp add: algebra_simps) |
|
1817 |
then have pxc: "x \<ge> (- ?N x e) / real c" |
|
1818 |
by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"]) |
|
1819 |
from 8 have noSc:"\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
|
1820 |
by auto |
|
1821 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" |
|
1822 |
by auto |
|
1823 |
then consider "y > (- ?N x e) / real c" | "y < (-?N x e) / real c" |
|
1824 |
by atomize_elim auto |
|
1825 |
then show ?case |
|
1826 |
proof cases |
|
1827 |
case 1 |
|
60710 | 1828 |
then have "y * real c > - ?N x e" |
41807 | 1829 |
by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric]) |
60710 | 1830 |
then have "real c * y + ?N x e > 0" by (simp add: algebra_simps) |
60711 | 1831 |
then show ?thesis |
1832 |
using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp |
|
1833 |
next |
|
1834 |
case 2 |
|
1835 |
with ly have eu: "l < (- ?N x e) / real c" |
|
1836 |
by auto |
|
1837 |
with noSc ly yu have "(- ?N x e) / real c \<ge> u" |
|
1838 |
by (cases "(- ?N x e) / real c > l") auto |
|
1839 |
with xu pxc have False |
|
1840 |
by auto |
|
1841 |
then show ?thesis .. |
|
1842 |
qed |
|
29789 | 1843 |
next |
60711 | 1844 |
case (3 c e) |
1845 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1846 |
by simp_all |
|
1847 |
from cp have cnz: "real c \<noteq> 0" |
|
1848 |
by simp |
|
1849 |
from 3 have "x * real c + ?N x e = 0" |
|
1850 |
by (simp add: algebra_simps) |
|
60710 | 1851 |
then have pxc: "x = (- ?N x e) / real c" |
41807 | 1852 |
by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"]) |
60711 | 1853 |
from 3 have noSc:"\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
1854 |
by auto |
|
1855 |
with lx xu have yne: "x \<noteq> - ?N x e / real c" |
|
1856 |
by auto |
|
1857 |
with pxc show ?case |
|
1858 |
by simp |
|
29789 | 1859 |
next |
60711 | 1860 |
case (4 c e) |
1861 |
then have cp: "real c > 0" and nb: "numbound0 e" |
|
1862 |
by simp_all |
|
1863 |
from cp have cnz: "real c \<noteq> 0" |
|
1864 |
by simp |
|
1865 |
from 4 have noSc:"\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" |
|
1866 |
by auto |
|
1867 |
with ly yu have yne: "y \<noteq> - ?N x e / real c" |
|
1868 |
by auto |
|
60710 | 1869 |
then have "y* real c \<noteq> -?N x e" |
41807 | 1870 |
by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp |
60711 | 1871 |
then have "y* real c + ?N x e \<noteq> 0" |
1872 |
by (simp add: algebra_simps) |
|
60710 | 1873 |
then show ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] |
41807 | 1874 |
by (simp add: algebra_simps) |
41842 | 1875 |
qed (auto simp add: numbound0_I[where bs="bs" and b="y" and b'="x"]) |
29789 | 1876 |
|
1877 |
lemma finite_set_intervals: |
|
60711 | 1878 |
fixes x :: real |
1879 |
assumes px: "P x" |
|
1880 |
and lx: "l \<le> x" |
|
1881 |
and xu: "x \<le> u" |
|
1882 |
and linS: "l\<in> S" |
|
1883 |
and uinS: "u \<in> S" |
|
1884 |
and fS: "finite S" |
|
1885 |
and lS: "\<forall>x\<in> S. l \<le> x" |
|
1886 |
and Su: "\<forall>x\<in> S. x \<le> u" |
|
60710 | 1887 |
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" |
1888 |
proof - |
|
29789 | 1889 |
let ?Mx = "{y. y\<in> S \<and> y \<le> x}" |
1890 |
let ?xM = "{y. y\<in> S \<and> x \<le> y}" |
|
1891 |
let ?a = "Max ?Mx" |
|
1892 |
let ?b = "Min ?xM" |
|
60711 | 1893 |
have MxS: "?Mx \<subseteq> S" |
1894 |
by blast |
|
1895 |
then have fMx: "finite ?Mx" |
|
1896 |
using fS finite_subset by auto |
|
1897 |
from lx linS have linMx: "l \<in> ?Mx" |
|
1898 |
by blast |
|
1899 |
then have Mxne: "?Mx \<noteq> {}" |
|
1900 |
by blast |
|
1901 |
have xMS: "?xM \<subseteq> S" |
|
1902 |
by blast |
|
1903 |
then have fxM: "finite ?xM" |
|
1904 |
using fS finite_subset by auto |
|
1905 |
from xu uinS have linxM: "u \<in> ?xM" |
|
1906 |
by blast |
|
1907 |
then have xMne: "?xM \<noteq> {}" |
|
1908 |
by blast |
|
1909 |
have ax:"?a \<le> x" |
|
1910 |
using Mxne fMx by auto |
|
1911 |
have xb:"x \<le> ?b" |
|
1912 |
using xMne fxM by auto |
|
1913 |
have "?a \<in> ?Mx" |
|
1914 |
using Max_in[OF fMx Mxne] by simp |
|
1915 |
then have ainS: "?a \<in> S" |
|
1916 |
using MxS by blast |
|
1917 |
have "?b \<in> ?xM" |
|
1918 |
using Min_in[OF fxM xMne] by simp |
|
1919 |
then have binS: "?b \<in> S" |
|
1920 |
using xMS by blast |
|
1921 |
have noy: "\<forall>y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S" |
|
1922 |
proof clarsimp |
|
29789 | 1923 |
fix y |
1924 |
assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S" |
|
60711 | 1925 |
from yS consider "y \<in> ?Mx" | "y \<in> ?xM" |
1926 |
by atomize_elim auto |
|
1927 |
then show False |
|
1928 |
proof cases |
|
1929 |
case 1 |
|
1930 |
then have "y \<le> ?a" |
|
1931 |
using Mxne fMx by auto |
|
1932 |
with ay show ?thesis by simp |
|
1933 |
next |
|
1934 |
case 2 |
|
1935 |
then have "y \<ge> ?b" |
|
1936 |
using xMne fxM by auto |
|
1937 |
with yb show ?thesis by simp |
|
1938 |
qed |
|
29789 | 1939 |
qed |
60711 | 1940 |
from ainS binS noy ax xb px show ?thesis |
1941 |
by blast |
|
29789 | 1942 |
qed |
1943 |
||
1944 |
lemma rinf_uset: |
|
1945 |
assumes lp: "isrlfm p" |
|
60711 | 1946 |
and nmi: "\<not> (Ifm (x # bs) (minusinf p))" (is "\<not> (Ifm (x # bs) (?M p))") |
1947 |
and npi: "\<not> (Ifm (x # bs) (plusinf p))" (is "\<not> (Ifm (x # bs) (?P p))") |
|
1948 |
and ex: "\<exists>x. Ifm (x # bs) p" (is "\<exists>x. ?I x p") |
|
1949 |
shows "\<exists>(l,n) \<in> set (uset p). \<exists>(s,m) \<in> set (uset p). |
|
1950 |
?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p" |
|
60710 | 1951 |
proof - |
60711 | 1952 |
let ?N = "\<lambda>x t. Inum (x # bs) t" |
29789 | 1953 |
let ?U = "set (uset p)" |
60711 | 1954 |
from ex obtain a where pa: "?I a p" |
1955 |
by blast |
|
29789 | 1956 |
from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi |
60711 | 1957 |
have nmi': "\<not> (?I a (?M p))" |
1958 |
by simp |
|
29789 | 1959 |
from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi |
60711 | 1960 |
have npi': "\<not> (?I a (?P p))" |
1961 |
by simp |
|
60710 | 1962 |
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" |
1963 |
proof - |
|
1964 |
let ?M = "(\<lambda>(t,c). ?N a t / real c) ` ?U" |
|
60711 | 1965 |
have fM: "finite ?M" |
1966 |
by auto |
|
60710 | 1967 |
from rminusinf_uset[OF lp nmi pa] rplusinf_uset[OF lp npi pa] |
60711 | 1968 |
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" |
1969 |
by blast |
|
1970 |
then obtain "t" "n" "s" "m" |
|
1971 |
where tnU: "(t,n) \<in> ?U" |
|
1972 |
and smU: "(s,m) \<in> ?U" |
|
1973 |
and xs1: "a \<le> ?N x s / real m" |
|
1974 |
and tx1: "a \<ge> ?N x t / real n" |
|
1975 |
by blast |
|
1976 |
from uset_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 |
|
1977 |
have xs: "a \<le> ?N a s / real m" and tx: "a \<ge> ?N a t / real n" |
|
1978 |
by auto |
|
1979 |
from tnU have Mne: "?M \<noteq> {}" |
|
1980 |
by auto |
|
1981 |
then have Une: "?U \<noteq> {}" |
|
1982 |
by simp |
|
29789 | 1983 |
let ?l = "Min ?M" |
1984 |
let ?u = "Max ?M" |
|
60711 | 1985 |
have linM: "?l \<in> ?M" |
1986 |
using fM Mne by simp |
|
1987 |
have uinM: "?u \<in> ?M" |
|
1988 |
using fM Mne by simp |
|
1989 |
have tnM: "?N a t / real n \<in> ?M" |
|
1990 |
using tnU by auto |
|
1991 |
have smM: "?N a s / real m \<in> ?M" |
|
1992 |
using smU by auto |
|
1993 |
have lM: "\<forall>t\<in> ?M. ?l \<le> t" |
|
1994 |
using Mne fM by auto |
|
1995 |
have Mu: "\<forall>t\<in> ?M. t \<le> ?u" |
|
1996 |
using Mne fM by auto |
|
1997 |
have "?l \<le> ?N a t / real n" |
|
1998 |
using tnM Mne by simp |
|
1999 |
then have lx: "?l \<le> a" |
|
2000 |
using tx by simp |
|
2001 |
have "?N a s / real m \<le> ?u" |
|
2002 |
using smM Mne by simp |
|
2003 |
then have xu: "a \<le> ?u" |
|
2004 |
using xs by simp |
|
60710 | 2005 |
from finite_set_intervals2[where P="\<lambda>x. ?I x p",OF pa lx xu linM uinM fM lM Mu] |
60711 | 2006 |
consider u where "u \<in> ?M" "?I u p" |
2007 |
| t1 t2 where "t1 \<in> ?M" "t2 \<in> ?M" "\<forall>y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" "t1 < a" "a < t2" "?I a p" |
|
2008 |
by blast |
|
2009 |
then show ?thesis |
|
2010 |
proof cases |
|
2011 |
case 1 |
|
2012 |
note um = \<open>u \<in> ?M\<close> and pu = \<open>?I u p\<close> |
|
2013 |
then have "\<exists>(tu,nu) \<in> ?U. u = ?N a tu / real nu" |
|
2014 |
by auto |
|
2015 |
then obtain tu nu where tuU: "(tu, nu) \<in> ?U" and tuu: "u= ?N a tu / real nu" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32642
diff
changeset
|
2016 |
by blast |
60711 | 2017 |
have "(u + u) / 2 = u" |
2018 |
by auto |
|
2019 |
with pu tuu have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" |
|
2020 |
by simp |
|
2021 |
with tuU show ?thesis by blast |
|
2022 |
next |
|
2023 |
case 2 |
|
2024 |
note t1M = \<open>t1 \<in> ?M\<close> and t2M = \<open>t2\<in> ?M\<close> |
|
2025 |
and noM = \<open>\<forall>y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M\<close> |
|
2026 |
and t1x = \<open>t1 < a\<close> and xt2 = \<open>a < t2\<close> and px = \<open>?I a p\<close> |
|
2027 |
from t1M have "\<exists>(t1u,t1n) \<in> ?U. t1 = ?N a t1u / real t1n" |
|
2028 |
by auto |
|
2029 |
then obtain t1u t1n where t1uU: "(t1u, t1n) \<in> ?U" and t1u: "t1 = ?N a t1u / real t1n" |
|
2030 |
by blast |
|
2031 |
from t2M have "\<exists>(t2u,t2n) \<in> ?U. t2 = ?N a t2u / real t2n" |
|
2032 |
by auto |
|
2033 |
then obtain t2u t2n where t2uU: "(t2u, t2n) \<in> ?U" and t2u: "t2 = ?N a t2u / real t2n" |
|
2034 |
by blast |
|
2035 |
from t1x xt2 have t1t2: "t1 < t2" |
|
2036 |
by simp |
|
29789 | 2037 |
let ?u = "(t1 + t2) / 2" |
60711 | 2038 |
from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" |
2039 |
by auto |
|
29789 | 2040 |
from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" . |
60711 | 2041 |
with t1uU t2uU t1u t2u show ?thesis |
2042 |
by blast |
|
2043 |
qed |
|
29789 | 2044 |
qed |
60711 | 2045 |
then obtain l n s m where lnU: "(l, n) \<in> ?U" and smU:"(s, m) \<in> ?U" |
2046 |
and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" |
|
2047 |
by blast |
|
2048 |
from lnU smU uset_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" |
|
2049 |
by auto |
|
60710 | 2050 |
from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] |
29789 | 2051 |
numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu |
60711 | 2052 |
have "?I ((?N x l / real n + ?N x s / real m) / 2) p" |
2053 |
by simp |
|
2054 |
with lnU smU show ?thesis |
|
2055 |
by auto |
|
29789 | 2056 |
qed |
60711 | 2057 |
|
2058 |
||
29789 | 2059 |
(* The Ferrante - Rackoff Theorem *) |
2060 |
||
60710 | 2061 |
theorem fr_eq: |
29789 | 2062 |
assumes lp: "isrlfm p" |
60711 | 2063 |
shows "(\<exists>x. Ifm (x#bs) p) \<longleftrightarrow> |
2064 |
Ifm (x # bs) (minusinf p) \<or> Ifm (x # bs) (plusinf p) \<or> |
|
2065 |
(\<exists>(t,n) \<in> set (uset p). \<exists>(s,m) \<in> set (uset p). |
|
2066 |
Ifm ((((Inum (x # bs) t) / real n + (Inum (x # bs) s) / real m) / 2) # bs) p)" |
|
2067 |
(is "(\<exists>x. ?I x p) \<longleftrightarrow> (?M \<or> ?P \<or> ?F)" is "?E = ?D") |
|
29789 | 2068 |
proof |
60710 | 2069 |
assume px: "\<exists>x. ?I x p" |
60711 | 2070 |
consider "?M \<or> ?P" | "\<not> ?M" "\<not> ?P" by blast |
2071 |
then show ?D |
|
2072 |
proof cases |
|
2073 |
case 1 |
|
2074 |
then show ?thesis by blast |
|
2075 |
next |
|
2076 |
case 2 |
|
2077 |
from rinf_uset[OF lp this] have ?F |
|
2078 |
using px by blast |
|
2079 |
then show ?thesis by blast |
|
2080 |
qed |
|
29789 | 2081 |
next |
60711 | 2082 |
assume ?D |
2083 |
then consider ?M | ?P | ?F by blast |
|
2084 |
then show ?E |
|
2085 |
proof cases |
|
2086 |
case 1 |
|
2087 |
from rminusinf_ex[OF lp this] show ?thesis . |
|
2088 |
next |
|
2089 |
case 2 |
|
2090 |
from rplusinf_ex[OF lp this] show ?thesis . |
|
2091 |
next |
|
2092 |
case 3 |
|
2093 |
then show ?thesis by blast |
|
2094 |
qed |
|
29789 | 2095 |
qed |
2096 |
||
2097 |
||
60710 | 2098 |
lemma fr_equsubst: |
29789 | 2099 |
assumes lp: "isrlfm p" |
60711 | 2100 |
shows "(\<exists>x. Ifm (x # bs) p) \<longleftrightarrow> |
2101 |
(Ifm (x # bs) (minusinf p) \<or> Ifm (x # bs) (plusinf p) \<or> |
|
2102 |
(\<exists>(t,k) \<in> set (uset p). \<exists>(s,l) \<in> set (uset p). |
|
2103 |
Ifm (x#bs) (usubst p (Add (Mul l t) (Mul k s), 2 * k * l))))" |
|
2104 |
(is "(\<exists>x. ?I x p) \<longleftrightarrow> ?M \<or> ?P \<or> ?F" is "?E = ?D") |
|
29789 | 2105 |
proof |
60710 | 2106 |
assume px: "\<exists>x. ?I x p" |
60711 | 2107 |
consider "?M \<or> ?P" | "\<not> ?M" "\<not> ?P" by blast |
2108 |
then show ?D |
|
2109 |
proof cases |
|
2110 |
case 1 |
|
2111 |
then show ?thesis by blast |
|
2112 |
next |
|
2113 |
case 2 |
|
2114 |
let ?f = "\<lambda>(t,n). Inum (x # bs) t / real n" |
|
2115 |
let ?N = "\<lambda>t. Inum (x # bs) t" |
|
2116 |
{ |
|
2117 |
fix t n s m |
|
2118 |
assume "(t, n) \<in> set (uset p)" and "(s, m) \<in> set (uset p)" |
|
2119 |
with uset_l[OF lp] have tnb: "numbound0 t" |
|
2120 |
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
|
2121 |
by auto |
29789 | 2122 |
let ?st = "Add (Mul m t) (Mul n s)" |
60711 | 2123 |
from np mp have mnp: "real (2 * n * m) > 0" |
2124 |
by (simp add: mult.commute) |
|
2125 |
from tnb snb have st_nb: "numbound0 ?st" |
|
2126 |
by simp |
|
2127 |
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
|
2128 |
using mnp mp np by (simp add: algebra_simps add_divide_distrib) |
60710 | 2129 |
from usubst_I[OF lp mnp st_nb, where x="x" and bs="bs"] |
60711 | 2130 |
have "?I x (usubst p (?st, 2 * n * m)) = ?I ((?N t / real n + ?N s / real m) / 2) p" |
2131 |
by (simp only: st[symmetric]) |
|
2132 |
} |
|
2133 |
with rinf_uset[OF lp 2 px] have ?F |
|
2134 |
by blast |
|
2135 |
then show ?thesis |
|
2136 |
by blast |
|
2137 |
qed |
|
29789 | 2138 |
next |
60711 | 2139 |
assume ?D |
2140 |
then consider ?M | ?P | t k s l where "(t, k) \<in> set (uset p)" "(s, l) \<in> set (uset p)" |
|
2141 |
"?I x (usubst p (Add (Mul l t) (Mul k s), 2 * k * l))" |
|
2142 |
by blast |
|
2143 |
then show ?E |
|
2144 |
proof cases |
|
2145 |
case 1 |
|
2146 |
from rminusinf_ex[OF lp this] show ?thesis . |
|
2147 |
next |
|
2148 |
case 2 |
|
2149 |
from rplusinf_ex[OF lp this] show ?thesis . |
|
2150 |
next |
|
2151 |
case 3 |
|
2152 |
with uset_l[OF lp] have tnb: "numbound0 t" and np: "real k > 0" |
|
2153 |
and snb: "numbound0 s" and mp: "real l > 0" |
|
2154 |
by auto |
|
29789 | 2155 |
let ?st = "Add (Mul l t) (Mul k s)" |
60711 | 2156 |
from np mp have mnp: "real (2 * k * l) > 0" |
2157 |
by (simp add: mult.commute) |
|
2158 |
from tnb snb have st_nb: "numbound0 ?st" |
|
2159 |
by simp |
|
2160 |
from usubst_I[OF lp mnp st_nb, where bs="bs"] |
|
2161 |
\<open>?I x (usubst p (Add (Mul l t) (Mul k s), 2 * k * l))\<close> show ?thesis |
|
2162 |
by auto |
|
2163 |
qed |
|
29789 | 2164 |
qed |
2165 |
||
2166 |
||
2167 |
(* Implement the right hand side of Ferrante and Rackoff's Theorem. *) |
|
60711 | 2168 |
definition ferrack :: "fm \<Rightarrow> fm" |
2169 |
where |
|
2170 |
"ferrack p = |
|
2171 |
(let |
|
2172 |
p' = rlfm (simpfm p); |
|
2173 |
mp = minusinf p'; |
|
2174 |
pp = plusinf p' |
|
2175 |
in |
|
2176 |
if mp = T \<or> pp = T then T |
|
2177 |
else |
|
2178 |
(let U = remdups (map simp_num_pair |
|
2179 |
(map (\<lambda>((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2 * n * m)) |
|
2180 |
(alluopairs (uset p')))) |
|
2181 |
in decr (disj mp (disj pp (evaldjf (simpfm \<circ> usubst p') U)))))" |
|
29789 | 2182 |
|
2183 |
lemma uset_cong_aux: |
|
60711 | 2184 |
assumes Ul: "\<forall>(t,n) \<in> set U. numbound0 t \<and> n > 0" |
2185 |
shows "((\<lambda>(t,n). Inum (x # bs) t / real n) ` |
|
2186 |
(set (map (\<lambda>((t,n),(s,m)). (Add (Mul m t) (Mul n s), 2 * n * m)) (alluopairs U)))) = |
|
2187 |
((\<lambda>((t,n),(s,m)). (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` (set U \<times> set U))" |
|
29789 | 2188 |
(is "?lhs = ?rhs") |
60711 | 2189 |
proof auto |
29789 | 2190 |
fix t n s m |
60711 | 2191 |
assume "((t, n), (s, m)) \<in> set (alluopairs U)" |
2192 |
then have th: "((t, n), (s, m)) \<in> set U \<times> set U" |
|
29789 | 2193 |
using alluopairs_set1[where xs="U"] by blast |
60711 | 2194 |
let ?N = "\<lambda>t. Inum (x # bs) t" |
2195 |
let ?st = "Add (Mul m t) (Mul n s)" |
|
2196 |
from Ul th have mnz: "m \<noteq> 0" |
|
2197 |
by auto |
|
2198 |
from Ul th have nnz: "n \<noteq> 0" |
|
2199 |
by auto |
|
2200 |
have st: "(?N t / real n + ?N s / real m) / 2 = ?N ?st / real (2 * n * m)" |
|
2201 |
using mnz nnz by (simp add: algebra_simps add_divide_distrib) |
|
2202 |
then show "(real m * Inum (x # bs) t + real n * Inum (x # bs) s) / (2 * real n * real m) |
|
2203 |
\<in> (\<lambda>((t, n), s, m). (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` |
|
2204 |
(set U \<times> set U)" |
|
2205 |
using mnz nnz th |
|
29789 | 2206 |
apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def) |
60711 | 2207 |
apply (rule_tac x="(s,m)" in bexI) |
2208 |
apply simp_all |
|
2209 |
apply (rule_tac x="(t,n)" in bexI) |
|
2210 |
apply (simp_all add: mult.commute) |
|
2211 |
done |
|
29789 | 2212 |
next |
2213 |
fix t n s m |
|
60711 | 2214 |
assume tnU: "(t, n) \<in> set U" and smU: "(s, m) \<in> set U" |
2215 |
let ?N = "\<lambda>t. Inum (x # bs) t" |
|
2216 |
let ?st = "Add (Mul m t) (Mul n s)" |
|
2217 |
from Ul smU have mnz: "m \<noteq> 0" |
|
2218 |
by auto |
|
2219 |
from Ul tnU have nnz: "n \<noteq> 0" |
|
2220 |
by auto |
|
2221 |
have st: "(?N t / real n + ?N s / real m) / 2 = ?N ?st / real (2 * n * m)" |
|
2222 |
using mnz nnz by (simp add: algebra_simps add_divide_distrib) |
|
2223 |
let ?P = "\<lambda>(t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = |
|
2224 |
(Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m') / 2" |
|
2225 |
have Pc:"\<forall>a b. ?P a b = ?P b a" |
|
2226 |
by auto |
|
2227 |
from Ul alluopairs_set1 have Up:"\<forall>((t,n),(s,m)) \<in> set (alluopairs U). n \<noteq> 0 \<and> m \<noteq> 0" |
|
2228 |
by blast |
|
2229 |
from alluopairs_ex[OF Pc, where xs="U"] tnU smU |
|
2230 |
have th':"\<exists>((t',n'),(s',m')) \<in> set (alluopairs U). ?P (t',n') (s',m')" |
|
2231 |
by blast |
|
2232 |
then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \<in> set (alluopairs U)" |
|
2233 |
and Pts': "?P (t', n') (s', m')" |
|
2234 |
by blast |
|
2235 |
from ts'_U Up have mnz': "m' \<noteq> 0" and nnz': "n'\<noteq> 0" |
|
2236 |
by auto |
|
2237 |
let ?st' = "Add (Mul m' t') (Mul n' s')" |
|
2238 |
have st': "(?N t' / real n' + ?N s' / real m') / 2 = ?N ?st' / real (2 * n' * m')" |
|
2239 |
using mnz' nnz' by (simp add: algebra_simps add_divide_distrib) |
|
2240 |
from Pts' have "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 = |
|
2241 |
(Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m') / 2" |
|
2242 |
by simp |
|
2243 |
also have "\<dots> = (\<lambda>(t, n). Inum (x # bs) t / real n) |
|
2244 |
((\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t', n'), (s', m')))" |
|
2245 |
by (simp add: st') |
|
2246 |
finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2 |
|
2247 |
\<in> (\<lambda>(t, n). Inum (x # bs) t / real n) ` |
|
2248 |
(\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ` set (alluopairs U)" |
|
2249 |
using ts'_U by blast |
|
29789 | 2250 |
qed |
2251 |
||
2252 |
lemma uset_cong: |
|
2253 |
assumes lp: "isrlfm p" |
|
60711 | 2254 |
and UU': "((\<lambda>(t,n). Inum (x # bs) t / real n) ` U') = |
2255 |
((\<lambda>((t,n),(s,m)). (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) ` (U \<times> U))" |
|
2256 |
(is "?f ` U' = ?g ` (U \<times> U)") |
|
2257 |
and U: "\<forall>(t,n) \<in> U. numbound0 t \<and> n > 0" |
|
2258 |
and U': "\<forall>(t,n) \<in> U'. numbound0 t \<and> n > 0" |
|
2259 |
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))) = |
|
2260 |
(\<exists>(t,n) \<in> U'. Ifm (x # bs) (usubst p (t, n)))" |
|
2261 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
29789 | 2262 |
proof |
60711 | 2263 |
show ?rhs if ?lhs |
2264 |
proof - |
|
2265 |
from that obtain t n s m where tnU: "(t, n) \<in> U" and smU: "(s, m) \<in> U" |
|
2266 |
and Pst: "Ifm (x # bs) (usubst p (Add (Mul m t) (Mul n s), 2 * n * m))" |
|
2267 |
by blast |
|
2268 |
let ?N = "\<lambda>t. Inum (x#bs) t" |
|
2269 |
from tnU smU U have tnb: "numbound0 t" and np: "n > 0" |
|
2270 |
and snb: "numbound0 s" and mp: "m > 0" |
|
2271 |
by auto |
|
2272 |
let ?st = "Add (Mul m t) (Mul n s)" |
|
2273 |
from np mp have mnp: "real (2 * n * m) > 0" |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
56544
diff
changeset
|
2274 |
by (simp add: mult.commute real_of_int_mult[symmetric] del: real_of_int_mult) |
60711 | 2275 |
from tnb snb have stnb: "numbound0 ?st" |
2276 |
by simp |
|
2277 |
have st: "(?N t / real n + ?N s / real m) / 2 = ?N ?st / real (2 * n * m)" |
|
2278 |
using mp np by (simp add: algebra_simps add_divide_distrib) |
|
2279 |
from tnU smU UU' have "?g ((t, n), (s, m)) \<in> ?f ` U'" |
|
2280 |
by blast |
|
2281 |
then have "\<exists>(t',n') \<in> U'. ?g ((t, n), (s, m)) = ?f (t', n')" |
|
2282 |
apply auto |
|
2283 |
apply (rule_tac x="(a, b)" in bexI) |
|
2284 |
apply auto |
|
2285 |
done |
|
2286 |
then obtain t' n' where tnU': "(t',n') \<in> U'" and th: "?g ((t, n), (s, m)) = ?f (t', n')" |
|
2287 |
by blast |
|
2288 |
from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" |
|
2289 |
by auto |
|
2290 |
from usubst_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst |
|
2291 |
have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" |
|
2292 |
by simp |
|
2293 |
from conjunct1[OF usubst_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] |
|
2294 |
th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]] |
|
2295 |
have "Ifm (x # bs) (usubst p (t', n'))" |
|
2296 |
by (simp only: st) |
|
2297 |
then show ?thesis |
|
2298 |
using tnU' by auto |
|
2299 |
qed |
|
2300 |
show ?lhs if ?rhs |
|
2301 |
proof - |
|
2302 |
from that obtain t' n' where tnU': "(t', n') \<in> U'" and Pt': "Ifm (x # bs) (usubst p (t', n'))" |
|
2303 |
by blast |
|
2304 |
from tnU' UU' have "?f (t', n') \<in> ?g ` (U \<times> U)" |
|
2305 |
by blast |
|
2306 |
then have "\<exists>((t,n),(s,m)) \<in> U \<times> U. ?f (t', n') = ?g ((t, n), (s, m))" |
|
2307 |
apply auto |
|
2308 |
apply (rule_tac x="(a,b)" in bexI) |
|
2309 |
apply auto |
|
2310 |
done |
|
2311 |
then obtain t n s m where tnU: "(t, n) \<in> U" and smU: "(s, m) \<in> U" and |
|
2312 |
th: "?f (t', n') = ?g ((t, n), (s, m))" |
|
2313 |
by blast |
|
2314 |
let ?N = "\<lambda>t. Inum (x # bs) t" |
|
2315 |
from tnU smU U have tnb: "numbound0 t" and np: "n > 0" |
|
2316 |
and snb: "numbound0 s" and mp: "m > 0" |
|
2317 |
by auto |
|
2318 |
let ?st = "Add (Mul m t) (Mul n s)" |
|
2319 |
from np mp have mnp: "real (2 * n * m) > 0" |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
56544
diff
changeset
|
2320 |
by (simp add: mult.commute real_of_int_mult[symmetric] del: real_of_int_mult) |
60711 | 2321 |
from tnb snb have stnb: "numbound0 ?st" |
2322 |
by simp |
|
2323 |
have st: "(?N t / real n + ?N s / real m) / 2 = ?N ?st / real (2 * n * m)" |
|
2324 |
using mp np by (simp add: algebra_simps add_divide_distrib) |
|
2325 |
from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" |
|
2326 |
by auto |
|
2327 |
from usubst_I[OF lp np' tnb', where bs="bs" and x="x",simplified |
|
2328 |
th[simplified split_def fst_conv snd_conv] st] Pt' |
|
2329 |
have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" |
|
2330 |
by simp |
|
2331 |
with usubst_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU |
|
2332 |
show ?thesis by blast |
|
2333 |
qed |
|
29789 | 2334 |
qed |
2335 |
||
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2336 |
lemma ferrack: |
29789 | 2337 |
assumes qf: "qfree p" |
60711 | 2338 |
shows "qfree (ferrack p) \<and> (Ifm bs (ferrack p) \<longleftrightarrow> (\<exists>x. Ifm (x # bs) p))" |
2339 |
(is "_ \<and> (?rhs \<longleftrightarrow> ?lhs)") |
|
60710 | 2340 |
proof - |
60711 | 2341 |
let ?I = "\<lambda>x p. Ifm (x # bs) p" |
29789 | 2342 |
fix x |
60711 | 2343 |
let ?N = "\<lambda>t. Inum (x # bs) t" |
60710 | 2344 |
let ?q = "rlfm (simpfm p)" |
29789 | 2345 |
let ?U = "uset ?q" |
2346 |
let ?Up = "alluopairs ?U" |
|
60711 | 2347 |
let ?g = "\<lambda>((t,n),(s,m)). (Add (Mul m t) (Mul n s), 2 * n * m)" |
29789 | 2348 |
let ?S = "map ?g ?Up" |
2349 |
let ?SS = "map simp_num_pair ?S" |
|
36853 | 2350 |
let ?Y = "remdups ?SS" |
60711 | 2351 |
let ?f = "\<lambda>(t,n). ?N t / real n" |
2352 |
let ?h = "\<lambda>((t,n),(s,m)). (?N t / real n + ?N s / real m) / 2" |
|
2353 |
let ?F = "\<lambda>p. \<exists>a \<in> set (uset p). \<exists>b \<in> set (uset p). ?I x (usubst p (?g (a, b)))" |
|
60710 | 2354 |
let ?ep = "evaldjf (simpfm \<circ> (usubst ?q)) ?Y" |
60711 | 2355 |
from rlfm_I[OF simpfm_qf[OF qf]] have lq: "isrlfm ?q" |
2356 |
by blast |
|
2357 |
from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \<subseteq> set ?U \<times> set ?U" |
|
2358 |
by simp |
|
60710 | 2359 |
from uset_l[OF lq] have U_l: "\<forall>(t,n) \<in> set ?U. numbound0 t \<and> n > 0" . |
2360 |
from U_l UpU |
|
60711 | 2361 |
have "\<forall>((t,n),(s,m)) \<in> set ?Up. numbound0 t \<and> n> 0 \<and> numbound0 s \<and> m > 0" |
2362 |
by auto |
|
2363 |
then have Snb: "\<forall>(t,n) \<in> set ?S. numbound0 t \<and> n > 0 " |
|
2364 |
by auto |
|
60710 | 2365 |
have Y_l: "\<forall>(t,n) \<in> set ?Y. numbound0 t \<and> n > 0" |
2366 |
proof - |
|
60711 | 2367 |
have "numbound0 t \<and> n > 0" if tnY: "(t, n) \<in> set ?Y" for t n |
2368 |
proof - |
|
2369 |
from that have "(t,n) \<in> set ?SS" |
|
2370 |
by simp |
|
2371 |
then have "\<exists>(t',n') \<in> set ?S. simp_num_pair (t', n') = (t, n)" |
|
2372 |
apply (auto simp add: split_def simp del: map_map) |
|
2373 |
apply (rule_tac x="((aa,ba),(ab,bb))" in bexI) |
|
2374 |
apply simp_all |
|
2375 |
done |
|
2376 |
then obtain t' n' where tn'S: "(t', n') \<in> set ?S" and tns: "simp_num_pair (t', n') = (t, n)" |
|
2377 |
by blast |
|
2378 |
from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" |
|
2379 |
by auto |
|
2380 |
from simp_num_pair_l[OF tnb np tns] show ?thesis . |
|
2381 |
qed |
|
60710 | 2382 |
then show ?thesis by blast |
29789 | 2383 |
qed |
2384 |
||
2385 |
have YU: "(?f ` set ?Y) = (?h ` (set ?U \<times> set ?U))" |
|
60710 | 2386 |
proof - |
60711 | 2387 |
from simp_num_pair_ci[where bs="x#bs"] have "\<forall>x. (?f \<circ> simp_num_pair) x = ?f x" |
2388 |
by auto |
|
2389 |
then have th: "?f \<circ> simp_num_pair = ?f" |
|
2390 |
by auto |
|
2391 |
have "(?f ` set ?Y) = ((?f \<circ> simp_num_pair) ` set ?S)" |
|
2392 |
by (simp add: comp_assoc image_comp) |
|
2393 |
also have "\<dots> = ?f ` set ?S" |
|
2394 |
by (simp add: th) |
|
2395 |
also have "\<dots> = (?f \<circ> ?g) ` set ?Up" |
|
56154
f0a927235162
more complete set of lemmas wrt. image and composition
haftmann
parents:
55422
diff
changeset
|
2396 |
by (simp only: set_map o_def image_comp) |
60711 | 2397 |
also have "\<dots> = ?h ` (set ?U \<times> set ?U)" |
2398 |
using uset_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_comp] |
|
2399 |
by blast |
|
29789 | 2400 |
finally show ?thesis . |
2401 |
qed |
|
60711 | 2402 |
have "\<forall>(t,n) \<in> set ?Y. bound0 (simpfm (usubst ?q (t, n)))" |
60710 | 2403 |
proof - |
60711 | 2404 |
have "bound0 (simpfm (usubst ?q (t, n)))" if tnY: "(t,n) \<in> set ?Y" for t n |
2405 |
proof - |
|
2406 |
from Y_l that have tnb: "numbound0 t" and np: "real n > 0" |
|
2407 |
by auto |
|
2408 |
from usubst_I[OF lq np tnb] have "bound0 (usubst ?q (t, n))" |
|
2409 |
by simp |
|
2410 |
then show ?thesis |
|
2411 |
using simpfm_bound0 by simp |
|
2412 |
qed |
|
60710 | 2413 |
then show ?thesis by blast |
29789 | 2414 |
qed |
60711 | 2415 |
then have ep_nb: "bound0 ?ep" |
2416 |
using evaldjf_bound0[where xs="?Y" and f="simpfm \<circ> (usubst ?q)"] by auto |
|
29789 | 2417 |
let ?mp = "minusinf ?q" |
2418 |
let ?pp = "plusinf ?q" |
|
2419 |
let ?M = "?I x ?mp" |
|
2420 |
let ?P = "?I x ?pp" |
|
2421 |
let ?res = "disj ?mp (disj ?pp ?ep)" |
|
60711 | 2422 |
from rminusinf_bound0[OF lq] rplusinf_bound0[OF lq] ep_nb have nbth: "bound0 ?res" |
2423 |
by auto |
|
29789 | 2424 |
|
60711 | 2425 |
from conjunct1[OF rlfm_I[OF simpfm_qf[OF qf]]] simpfm have th: "?lhs = (\<exists>x. ?I x ?q)" |
2426 |
by auto |
|
29789 | 2427 |
from th fr_equsubst[OF lq, where bs="bs" and x="x"] have lhfr: "?lhs = (?M \<or> ?P \<or> ?F ?q)" |
2428 |
by (simp only: split_def fst_conv snd_conv) |
|
60710 | 2429 |
also have "\<dots> = (?M \<or> ?P \<or> (\<exists>(t,n) \<in> set ?Y. ?I x (simpfm (usubst ?q (t,n)))))" |
60711 | 2430 |
using uset_cong[OF lq YU U_l Y_l] by (simp only: split_def fst_conv snd_conv simpfm) |
29789 | 2431 |
also have "\<dots> = (Ifm (x#bs) ?res)" |
60710 | 2432 |
using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="simpfm \<circ> (usubst ?q)",symmetric] |
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60767
diff
changeset
|
2433 |
by (simp add: split_def prod.collapse) |
60711 | 2434 |
finally have lheq: "?lhs = Ifm bs (decr ?res)" |
2435 |
using decr[OF nbth] by blast |
|
2436 |
then have lr: "?lhs = ?rhs" |
|
2437 |
unfolding ferrack_def Let_def |
|
29789 | 2438 |
by (cases "?mp = T \<or> ?pp = T", auto) (simp add: disj_def)+ |
60711 | 2439 |
from decr_qf[OF nbth] have "qfree (ferrack p)" |
2440 |
by (auto simp add: Let_def ferrack_def) |
|
2441 |
with lr show ?thesis |
|
2442 |
by blast |
|
29789 | 2443 |
qed |
2444 |
||
60711 | 2445 |
definition linrqe:: "fm \<Rightarrow> fm" |
2446 |
where "linrqe p = qelim (prep p) ferrack" |
|
29789 | 2447 |
|
2448 |
theorem linrqe: "Ifm bs (linrqe p) = Ifm bs p \<and> qfree (linrqe p)" |
|
60711 | 2449 |
using ferrack qelim_ci prep |
2450 |
unfolding linrqe_def by auto |
|
29789 | 2451 |
|
60711 | 2452 |
definition ferrack_test :: "unit \<Rightarrow> fm" |
2453 |
where |
|
2454 |
"ferrack_test u = |
|
2455 |
linrqe (A (A (Imp (Lt (Sub (Bound 1) (Bound 0))) |
|
2456 |
(E (Eq (Sub (Add (Bound 0) (Bound 2)) (Bound 1)))))))" |
|
29789 | 2457 |
|
60533 | 2458 |
ML_val \<open>@{code ferrack_test} ()\<close> |
29789 | 2459 |
|
60533 | 2460 |
oracle linr_oracle = \<open> |
29789 | 2461 |
let |
2462 |
||
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2463 |
val mk_C = @{code C} o @{code int_of_integer}; |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2464 |
val mk_Bound = @{code Bound} o @{code nat_of_integer}; |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2465 |
|
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2466 |
fun num_of_term vs (Free vT) = mk_Bound (find_index (fn vT' => vT = vT') vs) |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2467 |
| num_of_term vs @{term "real (0::int)"} = mk_C 0 |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2468 |
| num_of_term vs @{term "real (1::int)"} = mk_C 1 |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2469 |
| num_of_term vs @{term "0::real"} = mk_C 0 |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2470 |
| num_of_term vs @{term "1::real"} = mk_C 1 |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2471 |
| num_of_term vs (Bound i) = mk_Bound i |
29789 | 2472 |
| num_of_term vs (@{term "uminus :: real \<Rightarrow> real"} $ t') = @{code Neg} (num_of_term vs t') |
36853 | 2473 |
| num_of_term vs (@{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = |
2474 |
@{code Add} (num_of_term vs t1, num_of_term vs t2) |
|
2475 |
| num_of_term vs (@{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = |
|
2476 |
@{code Sub} (num_of_term vs t1, num_of_term vs t2) |
|
2477 |
| num_of_term vs (@{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = (case num_of_term vs t1 |
|
29789 | 2478 |
of @{code C} i => @{code Mul} (i, num_of_term vs t2) |
36853 | 2479 |
| _ => error "num_of_term: unsupported multiplication") |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46670
diff
changeset
|
2480 |
| num_of_term vs (@{term "real :: int \<Rightarrow> real"} $ t') = |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2481 |
(mk_C (snd (HOLogic.dest_number t')) |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46670
diff
changeset
|
2482 |
handle TERM _ => error ("num_of_term: unknown term")) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46670
diff
changeset
|
2483 |
| num_of_term vs t' = |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2484 |
(mk_C (snd (HOLogic.dest_number t')) |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46670
diff
changeset
|
2485 |
handle TERM _ => error ("num_of_term: unknown term")); |
29789 | 2486 |
|
2487 |
fun fm_of_term vs @{term True} = @{code T} |
|
2488 |
| fm_of_term vs @{term False} = @{code F} |
|
36853 | 2489 |
| fm_of_term vs (@{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
2490 |
@{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
|
2491 |
| fm_of_term vs (@{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
|
2492 |
@{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
|
2493 |
| fm_of_term vs (@{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) = |
|
60710 | 2494 |
@{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) |
36853 | 2495 |
| fm_of_term vs (@{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ t1 $ t2) = |
2496 |
@{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
|
2497 |
| 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
|
2498 |
| 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
|
2499 |
| fm_of_term vs (@{term HOL.implies} $ t1 $ t2) = @{code Imp} (fm_of_term vs t1, fm_of_term vs t2) |
29789 | 2500 |
| fm_of_term vs (@{term "Not"} $ t') = @{code NOT} (fm_of_term vs t') |
38558 | 2501 |
| fm_of_term vs (Const (@{const_name Ex}, _) $ Abs (xn, xT, p)) = |
36853 | 2502 |
@{code E} (fm_of_term (("", dummyT) :: vs) p) |
38558 | 2503 |
| fm_of_term vs (Const (@{const_name All}, _) $ Abs (xn, xT, p)) = |
36853 | 2504 |
@{code A} (fm_of_term (("", dummyT) :: vs) p) |
29789 | 2505 |
| fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t); |
2506 |
||
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2507 |
fun term_of_num vs (@{code C} i) = @{term "real :: int \<Rightarrow> real"} $ |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2508 |
HOLogic.mk_number HOLogic.intT (@{code integer_of_int} i) |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
49962
diff
changeset
|
2509 |
| term_of_num vs (@{code Bound} n) = Free (nth vs (@{code integer_of_nat} n)) |
29789 | 2510 |
| term_of_num vs (@{code Neg} t') = @{term "uminus :: real \<Rightarrow> real"} $ term_of_num vs t' |
2511 |
| term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
2512 |
term_of_num vs t1 $ term_of_num vs t2 |
|
2513 |
| term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
2514 |
term_of_num vs t1 $ term_of_num vs t2 |
|
2515 |
| term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ |
|
2516 |
term_of_num vs (@{code C} i) $ term_of_num vs t2 |
|
2517 |
| term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t)); |
|
2518 |
||
60710 | 2519 |
fun term_of_fm vs @{code T} = @{term True} |
45740 | 2520 |
| term_of_fm vs @{code F} = @{term False} |
29789 | 2521 |
| term_of_fm vs (@{code Lt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
2522 |
term_of_num vs t $ @{term "0::real"} |
|
2523 |
| term_of_fm vs (@{code Le} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
2524 |
term_of_num vs t $ @{term "0::real"} |
|
2525 |
| term_of_fm vs (@{code Gt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
2526 |
@{term "0::real"} $ term_of_num vs t |
|
2527 |
| term_of_fm vs (@{code Ge} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
2528 |
@{term "0::real"} $ term_of_num vs t |
|
2529 |
| term_of_fm vs (@{code Eq} t) = @{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ |
|
2530 |
term_of_num vs t $ @{term "0::real"} |
|
2531 |
| term_of_fm vs (@{code NEq} t) = term_of_fm vs (@{code NOT} (@{code Eq} t)) |
|
2532 |
| term_of_fm vs (@{code NOT} t') = HOLogic.Not $ term_of_fm vs t' |
|
2533 |
| term_of_fm vs (@{code And} (t1, t2)) = HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
2534 |
| term_of_fm vs (@{code Or} (t1, t2)) = HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
2535 |
| term_of_fm vs (@{code Imp} (t1, t2)) = HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2 |
|
2536 |
| term_of_fm vs (@{code Iff} (t1, t2)) = @{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ |
|
36853 | 2537 |
term_of_fm vs t1 $ term_of_fm vs t2; |
29789 | 2538 |
|
36853 | 2539 |
in fn (ctxt, t) => |
60710 | 2540 |
let |
36853 | 2541 |
val vs = Term.add_frees t []; |
2542 |
val t' = (term_of_fm vs o @{code linrqe} o fm_of_term vs) t; |
|
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59580
diff
changeset
|
2543 |
in (Thm.cterm_of ctxt o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end |
29789 | 2544 |
end; |
60533 | 2545 |
\<close> |
29789 | 2546 |
|
48891 | 2547 |
ML_file "ferrack_tac.ML" |
47432 | 2548 |
|
60533 | 2549 |
method_setup rferrack = \<open> |
53168 | 2550 |
Scan.lift (Args.mode "no_quantify") >> |
47432 | 2551 |
(fn q => fn ctxt => SIMPLE_METHOD' (Ferrack_Tac.linr_tac ctxt (not q))) |
60533 | 2552 |
\<close> "decision procedure for linear real arithmetic" |
47432 | 2553 |
|
29789 | 2554 |
|
2555 |
lemma |
|
2556 |
fixes x :: real |
|
2557 |
shows "2 * x \<le> 2 * x \<and> 2 * x \<le> 2 * x + 1" |
|
49070 | 2558 |
by rferrack |
29789 | 2559 |
|
2560 |
lemma |
|
2561 |
fixes x :: real |
|
2562 |
shows "\<exists>y \<le> x. x = y + 1" |
|
49070 | 2563 |
by rferrack |
29789 | 2564 |
|
2565 |
lemma |
|
2566 |
fixes x :: real |
|
2567 |
shows "\<not> (\<exists>z. x + z = x + z + 1)" |
|
49070 | 2568 |
by rferrack |
29789 | 2569 |
|
2570 |
end |