src/HOL/Decision_Procs/MIR.thy
author nipkow
Tue Feb 23 16:25:08 2016 +0100 (2016-02-23)
changeset 62390 842917225d56
parent 62342 1cf129590be8
child 63600 d0fa16751d14
permissions -rw-r--r--
more canonical names
hoelzl@30439
     1
(*  Title:      HOL/Decision_Procs/MIR.thy
chaieb@23264
     2
    Author:     Amine Chaieb
chaieb@23264
     3
*)
chaieb@23264
     4
chaieb@23264
     5
theory MIR
nipkow@41849
     6
imports Complex_Main Dense_Linear_Order DP_Library
haftmann@51143
     7
  "~~/src/HOL/Library/Code_Target_Numeral" "~~/src/HOL/Library/Old_Recdef"
haftmann@27368
     8
begin
chaieb@23264
     9
wenzelm@61586
    10
section \<open>Quantifier elimination for \<open>\<real> (0, 1, +, floor, <)\<close>\<close>
haftmann@27456
    11
lp15@61609
    12
declare of_int_floor_cancel [simp del]
chaieb@23264
    13
wenzelm@51369
    14
lemma myle:
wenzelm@51369
    15
  fixes a b :: "'a::{ordered_ab_group_add}"
nipkow@41849
    16
  shows "(a \<le> b) = (0 \<le> b - a)"
wenzelm@51369
    17
  by (metis add_0_left add_le_cancel_right diff_add_cancel)
wenzelm@51369
    18
wenzelm@51369
    19
lemma myless:
wenzelm@51369
    20
  fixes a b :: "'a::{ordered_ab_group_add}"
nipkow@41849
    21
  shows "(a < b) = (0 < b - a)"
wenzelm@51369
    22
  by (metis le_iff_diff_le_0 less_le_not_le myle)
chaieb@23264
    23
chaieb@23264
    24
(* Periodicity of dvd *)
lp15@61609
    25
lemmas dvd_period = zdvd_period
chaieb@23264
    26
wenzelm@32960
    27
(* The Divisibility relation between reals *)
wenzelm@51369
    28
definition rdvd:: "real \<Rightarrow> real \<Rightarrow> bool" (infixl "rdvd" 50)
lp15@61609
    29
  where "x rdvd y \<longleftrightarrow> (\<exists>k::int. y = x * real_of_int k)"
chaieb@23264
    30
lp15@61694
    31
lemma int_rdvd_real:
wenzelm@61942
    32
  "real_of_int (i::int) rdvd x = (i dvd \<lfloor>x\<rfloor> \<and> real_of_int \<lfloor>x\<rfloor> = x)" (is "?l = ?r")
chaieb@23264
    33
proof
lp15@61694
    34
  assume "?l"
lp15@61609
    35
  hence th: "\<exists> k. x=real_of_int (i*k)" by (simp add: rdvd_def)
wenzelm@61942
    36
  hence th': "real_of_int \<lfloor>x\<rfloor> = x" by (auto simp del: of_int_mult)
wenzelm@61942
    37
  with th have "\<exists> k. real_of_int \<lfloor>x\<rfloor> = real_of_int (i*k)" by simp
wenzelm@61942
    38
  hence "\<exists>k. \<lfloor>x\<rfloor> = i*k" by presburger
wenzelm@61942
    39
  thus ?r using th' by (simp add: dvd_def)
chaieb@23264
    40
next
wenzelm@61076
    41
  assume "?r" hence "(i::int) dvd \<lfloor>x::real\<rfloor>" ..
wenzelm@61942
    42
  hence "\<exists>k. real_of_int \<lfloor>x\<rfloor> = real_of_int (i*k)"
lp15@61649
    43
    by (metis (no_types) dvd_def)
wenzelm@60533
    44
  thus ?l using \<open>?r\<close> by (simp add: rdvd_def)
chaieb@23264
    45
qed
chaieb@23264
    46
lp15@61609
    47
lemma int_rdvd_iff: "(real_of_int (i::int) rdvd real_of_int t) = (i dvd t)"
lp15@61609
    48
  by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only: of_int_mult[symmetric])
lp15@61609
    49
lp15@61609
    50
wenzelm@61945
    51
lemma rdvd_abs1: "(\<bar>real_of_int d\<bar> rdvd t) = (real_of_int (d ::int) rdvd t)"
chaieb@23264
    52
proof
lp15@61609
    53
  assume d: "real_of_int d rdvd t"
wenzelm@61942
    54
  from d int_rdvd_real have d2: "d dvd \<lfloor>t\<rfloor>" and ti: "real_of_int \<lfloor>t\<rfloor> = t"
wenzelm@51369
    55
    by auto
chaieb@23264
    56
wenzelm@61945
    57
  from iffD2[OF abs_dvd_iff] d2 have "\<bar>d\<bar> dvd \<lfloor>t\<rfloor>" by blast
wenzelm@61945
    58
  with ti int_rdvd_real[symmetric] have "real_of_int \<bar>d\<bar> rdvd t" by blast
wenzelm@61945
    59
  thus "\<bar>real_of_int d\<bar> rdvd t" by simp
chaieb@23264
    60
next
wenzelm@61945
    61
  assume "\<bar>real_of_int d\<bar> rdvd t" hence "real_of_int \<bar>d\<bar> rdvd t" by simp
wenzelm@61945
    62
  with int_rdvd_real[where i="\<bar>d\<bar>" and x="t"]
wenzelm@61945
    63
  have d2: "\<bar>d\<bar> dvd \<lfloor>t\<rfloor>" and ti: "real_of_int \<lfloor>t\<rfloor> = t"
wenzelm@51369
    64
    by auto
wenzelm@61942
    65
  from iffD1[OF abs_dvd_iff] d2 have "d dvd \<lfloor>t\<rfloor>" by blast
lp15@61609
    66
  with ti int_rdvd_real[symmetric] show "real_of_int d rdvd t" by blast
chaieb@23264
    67
qed
chaieb@23264
    68
lp15@61609
    69
lemma rdvd_minus: "(real_of_int (d::int) rdvd t) = (real_of_int d rdvd -t)"
chaieb@23264
    70
  apply (auto simp add: rdvd_def)
lp15@61694
    71
  apply (rule_tac x="-k" in exI, simp)
chaieb@23264
    72
  apply (rule_tac x="-k" in exI, simp)
wenzelm@51369
    73
  done
chaieb@23264
    74
chaieb@23264
    75
lemma rdvd_left_0_eq: "(0 rdvd t) = (t=0)"
wenzelm@51369
    76
  by (auto simp add: rdvd_def)
chaieb@23264
    77
lp15@61694
    78
lemma rdvd_mult:
chaieb@23264
    79
  assumes knz: "k\<noteq>0"
lp15@61609
    80
  shows "(real_of_int (n::int) * real_of_int (k::int) rdvd x * real_of_int k) = (real_of_int n rdvd x)"
wenzelm@51369
    81
  using knz by (simp add: rdvd_def)
chaieb@23264
    82
chaieb@23264
    83
  (*********************************************************************************)
chaieb@23264
    84
  (****                            SHADOW SYNTAX AND SEMANTICS                  ****)
chaieb@23264
    85
  (*********************************************************************************)
chaieb@23264
    86
lp15@61694
    87
datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num
chaieb@23264
    88
  | Mul int num | Floor num| CF int num num
chaieb@23264
    89
chaieb@23264
    90
  (* A size for num to make inductive proofs simpler*)
haftmann@25765
    91
primrec num_size :: "num \<Rightarrow> nat" where
chaieb@23264
    92
 "num_size (C c) = 1"
chaieb@23264
    93
| "num_size (Bound n) = 1"
chaieb@23264
    94
| "num_size (Neg a) = 1 + num_size a"
chaieb@23264
    95
| "num_size (Add a b) = 1 + num_size a + num_size b"
chaieb@23264
    96
| "num_size (Sub a b) = 3 + num_size a + num_size b"
chaieb@23264
    97
| "num_size (CN n c a) = 4 + num_size a "
chaieb@23264
    98
| "num_size (CF c a b) = 4 + num_size a + num_size b"
chaieb@23264
    99
| "num_size (Mul c a) = 1 + num_size a"
chaieb@23264
   100
| "num_size (Floor a) = 1 + num_size a"
chaieb@23264
   101
chaieb@23264
   102
  (* Semantics of numeral terms (num) *)
haftmann@25765
   103
primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where
lp15@61609
   104
  "Inum bs (C c) = (real_of_int c)"
chaieb@23264
   105
| "Inum bs (Bound n) = bs!n"
lp15@61609
   106
| "Inum bs (CN n c a) = (real_of_int c) * (bs!n) + (Inum bs a)"
chaieb@23264
   107
| "Inum bs (Neg a) = -(Inum bs a)"
chaieb@23264
   108
| "Inum bs (Add a b) = Inum bs a + Inum bs b"
chaieb@23264
   109
| "Inum bs (Sub a b) = Inum bs a - Inum bs b"
lp15@61609
   110
| "Inum bs (Mul c a) = (real_of_int c) * Inum bs a"
wenzelm@61942
   111
| "Inum bs (Floor a) = real_of_int \<lfloor>Inum bs a\<rfloor>"
wenzelm@61942
   112
| "Inum bs (CF c a b) = real_of_int c * real_of_int \<lfloor>Inum bs a\<rfloor> + Inum bs b"
wenzelm@61942
   113
definition "isint t bs \<equiv> real_of_int \<lfloor>Inum bs t\<rfloor> = Inum bs t"
wenzelm@61942
   114
wenzelm@61942
   115
lemma isint_iff: "isint n bs = (real_of_int \<lfloor>Inum bs n\<rfloor> = Inum bs n)"
wenzelm@51369
   116
  by (simp add: isint_def)
chaieb@23264
   117
chaieb@23264
   118
lemma isint_Floor: "isint (Floor n) bs"
chaieb@23264
   119
  by (simp add: isint_iff)
chaieb@23264
   120
chaieb@23264
   121
lemma isint_Mul: "isint e bs \<Longrightarrow> isint (Mul c e) bs"
chaieb@23264
   122
proof-
chaieb@23264
   123
  let ?e = "Inum bs e"
wenzelm@61942
   124
  assume be: "isint e bs" hence efe:"real_of_int \<lfloor>?e\<rfloor> = ?e" by (simp add: isint_iff)
wenzelm@61942
   125
  have "real_of_int \<lfloor>Inum bs (Mul c e)\<rfloor> = real_of_int \<lfloor>real_of_int (c * \<lfloor>?e\<rfloor>)\<rfloor>"
wenzelm@61942
   126
    using efe by simp
wenzelm@61942
   127
  also have "\<dots> = real_of_int (c* \<lfloor>?e\<rfloor>)" by (metis floor_of_int)
lp15@61609
   128
  also have "\<dots> = real_of_int c * ?e" using efe by simp
chaieb@23264
   129
  finally show ?thesis using isint_iff by simp
chaieb@23264
   130
qed
chaieb@23264
   131
chaieb@23264
   132
lemma isint_neg: "isint e bs \<Longrightarrow> isint (Neg e) bs"
chaieb@23264
   133
proof-
chaieb@23264
   134
  let ?I = "\<lambda> t. Inum bs t"
chaieb@23264
   135
  assume ie: "isint e bs"
wenzelm@61942
   136
  hence th: "real_of_int \<lfloor>?I e\<rfloor> = ?I e" by (simp add: isint_def)
wenzelm@61942
   137
  have "real_of_int \<lfloor>?I (Neg e)\<rfloor> = real_of_int \<lfloor>- (real_of_int \<lfloor>?I e\<rfloor>)\<rfloor>"
wenzelm@61942
   138
    by (simp add: th)
wenzelm@61942
   139
  also have "\<dots> = - real_of_int \<lfloor>?I e\<rfloor>" by simp
chaieb@23264
   140
  finally show "isint (Neg e) bs" by (simp add: isint_def th)
chaieb@23264
   141
qed
chaieb@23264
   142
lp15@61694
   143
lemma isint_sub:
chaieb@23264
   144
  assumes ie: "isint e bs" shows "isint (Sub (C c) e) bs"
chaieb@23264
   145
proof-
chaieb@23264
   146
  let ?I = "\<lambda> t. Inum bs t"
wenzelm@61942
   147
  from ie have th: "real_of_int \<lfloor>?I e\<rfloor> = ?I e" by (simp add: isint_def)
wenzelm@61942
   148
  have "real_of_int \<lfloor>?I (Sub (C c) e)\<rfloor> = real_of_int \<lfloor>real_of_int (c - \<lfloor>?I e\<rfloor>)\<rfloor>"
wenzelm@61942
   149
    by (simp add: th)
wenzelm@61942
   150
  also have "\<dots> = real_of_int (c - \<lfloor>?I e\<rfloor>)" by simp
chaieb@23264
   151
  finally show "isint (Sub (C c) e) bs" by (simp add: isint_def th)
chaieb@23264
   152
qed
chaieb@23264
   153
wenzelm@51369
   154
lemma isint_add:
wenzelm@51369
   155
  assumes ai: "isint a bs" and bi: "isint b bs"
wenzelm@51369
   156
  shows "isint (Add a b) bs"
chaieb@23264
   157
proof-
chaieb@23264
   158
  let ?a = "Inum bs a"
chaieb@23264
   159
  let ?b = "Inum bs b"
wenzelm@61942
   160
  from ai bi isint_iff have "real_of_int \<lfloor>?a + ?b\<rfloor> = real_of_int \<lfloor>real_of_int \<lfloor>?a\<rfloor> + real_of_int \<lfloor>?b\<rfloor>\<rfloor>"
wenzelm@51369
   161
    by simp
wenzelm@61942
   162
  also have "\<dots> = real_of_int \<lfloor>?a\<rfloor> + real_of_int \<lfloor>?b\<rfloor>" by simp
chaieb@23264
   163
  also have "\<dots> = ?a + ?b" using ai bi isint_iff by simp
chaieb@23264
   164
  finally show "isint (Add a b) bs" by (simp add: isint_iff)
chaieb@23264
   165
qed
chaieb@23264
   166
chaieb@23264
   167
lemma isint_c: "isint (C j) bs"
chaieb@23264
   168
  by (simp add: isint_iff)
chaieb@23264
   169
chaieb@23264
   170
chaieb@23264
   171
    (* FORMULAE *)
lp15@61694
   172
datatype fm  =
chaieb@23264
   173
  T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num|
chaieb@23264
   174
  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
chaieb@23264
   175
chaieb@23264
   176
chaieb@23264
   177
  (* A size for fm *)
chaieb@23264
   178
fun fmsize :: "fm \<Rightarrow> nat" where
chaieb@23264
   179
 "fmsize (NOT p) = 1 + fmsize p"
chaieb@23264
   180
| "fmsize (And p q) = 1 + fmsize p + fmsize q"
chaieb@23264
   181
| "fmsize (Or p q) = 1 + fmsize p + fmsize q"
chaieb@23264
   182
| "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
chaieb@23264
   183
| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
chaieb@23264
   184
| "fmsize (E p) = 1 + fmsize p"
chaieb@23264
   185
| "fmsize (A p) = 4+ fmsize p"
chaieb@23264
   186
| "fmsize (Dvd i t) = 2"
chaieb@23264
   187
| "fmsize (NDvd i t) = 2"
chaieb@23264
   188
| "fmsize p = 1"
chaieb@23264
   189
  (* several lemmas about fmsize *)
wenzelm@32960
   190
lemma fmsize_pos: "fmsize p > 0"
wenzelm@51369
   191
  by (induct p rule: fmsize.induct) simp_all
chaieb@23264
   192
chaieb@23264
   193
  (* Semantics of formulae (fm) *)
haftmann@25765
   194
primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where
chaieb@23264
   195
  "Ifm bs T = True"
chaieb@23264
   196
| "Ifm bs F = False"
chaieb@23264
   197
| "Ifm bs (Lt a) = (Inum bs a < 0)"
chaieb@23264
   198
| "Ifm bs (Gt a) = (Inum bs a > 0)"
chaieb@23264
   199
| "Ifm bs (Le a) = (Inum bs a \<le> 0)"
chaieb@23264
   200
| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
chaieb@23264
   201
| "Ifm bs (Eq a) = (Inum bs a = 0)"
chaieb@23264
   202
| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
lp15@61609
   203
| "Ifm bs (Dvd i b) = (real_of_int i rdvd Inum bs b)"
lp15@61609
   204
| "Ifm bs (NDvd i b) = (\<not>(real_of_int i rdvd Inum bs b))"
chaieb@23264
   205
| "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
chaieb@23264
   206
| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
chaieb@23264
   207
| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
chaieb@23264
   208
| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
chaieb@23264
   209
| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
chaieb@23264
   210
| "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
chaieb@23264
   211
| "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
chaieb@23264
   212
chaieb@23264
   213
consts prep :: "fm \<Rightarrow> fm"
chaieb@23264
   214
recdef prep "measure fmsize"
chaieb@23264
   215
  "prep (E T) = T"
chaieb@23264
   216
  "prep (E F) = F"
chaieb@23264
   217
  "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))"
chaieb@23264
   218
  "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))"
lp15@61694
   219
  "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
chaieb@23264
   220
  "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))"
chaieb@23264
   221
  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
chaieb@23264
   222
  "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
chaieb@23264
   223
  "prep (E p) = E (prep p)"
chaieb@23264
   224
  "prep (A (And p q)) = And (prep (A p)) (prep (A q))"
chaieb@23264
   225
  "prep (A p) = prep (NOT (E (NOT p)))"
chaieb@23264
   226
  "prep (NOT (NOT p)) = prep p"
chaieb@23264
   227
  "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))"
chaieb@23264
   228
  "prep (NOT (A p)) = prep (E (NOT p))"
chaieb@23264
   229
  "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))"
chaieb@23264
   230
  "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))"
chaieb@23264
   231
  "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))"
chaieb@23264
   232
  "prep (NOT p) = NOT (prep p)"
chaieb@23264
   233
  "prep (Or p q) = Or (prep p) (prep q)"
chaieb@23264
   234
  "prep (And p q) = And (prep p) (prep q)"
chaieb@23264
   235
  "prep (Imp p q) = prep (Or (NOT p) q)"
chaieb@23264
   236
  "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))"
chaieb@23264
   237
  "prep p = p"
nipkow@25162
   238
(hints simp add: fmsize_pos)
chaieb@23264
   239
lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
wenzelm@51369
   240
  by (induct p rule: prep.induct) auto
chaieb@23264
   241
chaieb@23264
   242
chaieb@23264
   243
  (* Quantifier freeness *)
haftmann@25765
   244
fun qfree:: "fm \<Rightarrow> bool" where
chaieb@23264
   245
  "qfree (E p) = False"
haftmann@25765
   246
  | "qfree (A p) = False"
lp15@61694
   247
  | "qfree (NOT p) = qfree p"
lp15@61694
   248
  | "qfree (And p q) = (qfree p \<and> qfree q)"
lp15@61694
   249
  | "qfree (Or  p q) = (qfree p \<and> qfree q)"
lp15@61694
   250
  | "qfree (Imp p q) = (qfree p \<and> qfree q)"
haftmann@25765
   251
  | "qfree (Iff p q) = (qfree p \<and> qfree q)"
haftmann@25765
   252
  | "qfree p = True"
chaieb@23264
   253
chaieb@23264
   254
  (* Boundedness and substitution *)
haftmann@25765
   255
primrec numbound0 :: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where
chaieb@23264
   256
  "numbound0 (C c) = True"
haftmann@25765
   257
  | "numbound0 (Bound n) = (n>0)"
haftmann@25765
   258
  | "numbound0 (CN n i a) = (n > 0 \<and> numbound0 a)"
haftmann@25765
   259
  | "numbound0 (Neg a) = numbound0 a"
haftmann@25765
   260
  | "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
lp15@61694
   261
  | "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)"
haftmann@25765
   262
  | "numbound0 (Mul i a) = numbound0 a"
haftmann@25765
   263
  | "numbound0 (Floor a) = numbound0 a"
lp15@61694
   264
  | "numbound0 (CF c a b) = (numbound0 a \<and> numbound0 b)"
haftmann@25765
   265
chaieb@23264
   266
lemma numbound0_I:
chaieb@23264
   267
  assumes nb: "numbound0 a"
chaieb@23264
   268
  shows "Inum (b#bs) a = Inum (b'#bs) a"
nipkow@41849
   269
  using nb by (induct a) auto
chaieb@23264
   270
lp15@61694
   271
lemma numbound0_gen:
chaieb@23264
   272
  assumes nb: "numbound0 t" and ti: "isint t (x#bs)"
chaieb@23264
   273
  shows "\<forall> y. isint t (y#bs)"
lp15@61694
   274
  using nb ti
chaieb@23264
   275
proof(clarify)
chaieb@23264
   276
  fix y
chaieb@23264
   277
  from numbound0_I[OF nb, where bs="bs" and b="y" and b'="x"] ti[simplified isint_def]
chaieb@23264
   278
  show "isint t (y#bs)"
chaieb@23264
   279
    by (simp add: isint_def)
chaieb@23264
   280
qed
chaieb@23264
   281
haftmann@25765
   282
primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
chaieb@23264
   283
  "bound0 T = True"
haftmann@25765
   284
  | "bound0 F = True"
haftmann@25765
   285
  | "bound0 (Lt a) = numbound0 a"
haftmann@25765
   286
  | "bound0 (Le a) = numbound0 a"
haftmann@25765
   287
  | "bound0 (Gt a) = numbound0 a"
haftmann@25765
   288
  | "bound0 (Ge a) = numbound0 a"
haftmann@25765
   289
  | "bound0 (Eq a) = numbound0 a"
haftmann@25765
   290
  | "bound0 (NEq a) = numbound0 a"
haftmann@25765
   291
  | "bound0 (Dvd i a) = numbound0 a"
haftmann@25765
   292
  | "bound0 (NDvd i a) = numbound0 a"
haftmann@25765
   293
  | "bound0 (NOT p) = bound0 p"
haftmann@25765
   294
  | "bound0 (And p q) = (bound0 p \<and> bound0 q)"
haftmann@25765
   295
  | "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
haftmann@25765
   296
  | "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
haftmann@25765
   297
  | "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
haftmann@25765
   298
  | "bound0 (E p) = False"
haftmann@25765
   299
  | "bound0 (A p) = False"
chaieb@23264
   300
chaieb@23264
   301
lemma bound0_I:
chaieb@23264
   302
  assumes bp: "bound0 p"
chaieb@23264
   303
  shows "Ifm (b#bs) p = Ifm (b'#bs) p"
wenzelm@51369
   304
  using bp numbound0_I [where b="b" and bs="bs" and b'="b'"]
nipkow@41849
   305
  by (induct p) auto
haftmann@25765
   306
haftmann@25765
   307
primrec numsubst0:: "num \<Rightarrow> num \<Rightarrow> num" (* substitute a num into a num for Bound 0 *) where
chaieb@23264
   308
  "numsubst0 t (C c) = (C c)"
haftmann@25765
   309
  | "numsubst0 t (Bound n) = (if n=0 then t else Bound n)"
haftmann@25765
   310
  | "numsubst0 t (CN n i a) = (if n=0 then Add (Mul i t) (numsubst0 t a) else CN n i (numsubst0 t a))"
haftmann@25765
   311
  | "numsubst0 t (CF i a b) = CF i (numsubst0 t a) (numsubst0 t b)"
haftmann@25765
   312
  | "numsubst0 t (Neg a) = Neg (numsubst0 t a)"
haftmann@25765
   313
  | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)"
lp15@61694
   314
  | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)"
haftmann@25765
   315
  | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)"
haftmann@25765
   316
  | "numsubst0 t (Floor a) = Floor (numsubst0 t a)"
chaieb@23264
   317
chaieb@23264
   318
lemma numsubst0_I:
chaieb@23264
   319
  shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t"
nipkow@41849
   320
  by (induct t) simp_all
chaieb@23264
   321
haftmann@25765
   322
primrec subst0:: "num \<Rightarrow> fm \<Rightarrow> fm" (* substitue a num into a formula for Bound 0 *) where
chaieb@23264
   323
  "subst0 t T = T"
haftmann@25765
   324
  | "subst0 t F = F"
haftmann@25765
   325
  | "subst0 t (Lt a) = Lt (numsubst0 t a)"
haftmann@25765
   326
  | "subst0 t (Le a) = Le (numsubst0 t a)"
haftmann@25765
   327
  | "subst0 t (Gt a) = Gt (numsubst0 t a)"
haftmann@25765
   328
  | "subst0 t (Ge a) = Ge (numsubst0 t a)"
haftmann@25765
   329
  | "subst0 t (Eq a) = Eq (numsubst0 t a)"
haftmann@25765
   330
  | "subst0 t (NEq a) = NEq (numsubst0 t a)"
haftmann@25765
   331
  | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)"
haftmann@25765
   332
  | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)"
haftmann@25765
   333
  | "subst0 t (NOT p) = NOT (subst0 t p)"
haftmann@25765
   334
  | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
haftmann@25765
   335
  | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
haftmann@25765
   336
  | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)"
haftmann@25765
   337
  | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
chaieb@23264
   338
chaieb@23264
   339
lemma subst0_I: assumes qfp: "qfree p"
chaieb@23264
   340
  shows "Ifm (b#bs) (subst0 a p) = Ifm ((Inum (b#bs) a)#bs) p"
chaieb@23264
   341
  using qfp numsubst0_I[where b="b" and bs="bs" and a="a"]
nipkow@41849
   342
  by (induct p) simp_all
chaieb@23264
   343
krauss@41839
   344
fun decrnum:: "num \<Rightarrow> num" where
chaieb@23264
   345
  "decrnum (Bound n) = Bound (n - 1)"
krauss@41839
   346
| "decrnum (Neg a) = Neg (decrnum a)"
krauss@41839
   347
| "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
krauss@41839
   348
| "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
krauss@41839
   349
| "decrnum (Mul c a) = Mul c (decrnum a)"
krauss@41839
   350
| "decrnum (Floor a) = Floor (decrnum a)"
krauss@41839
   351
| "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
krauss@41839
   352
| "decrnum (CF c a b) = CF c (decrnum a) (decrnum b)"
krauss@41839
   353
| "decrnum a = a"
krauss@41839
   354
krauss@41839
   355
fun decr :: "fm \<Rightarrow> fm" where
chaieb@23264
   356
  "decr (Lt a) = Lt (decrnum a)"
krauss@41839
   357
| "decr (Le a) = Le (decrnum a)"
krauss@41839
   358
| "decr (Gt a) = Gt (decrnum a)"
krauss@41839
   359
| "decr (Ge a) = Ge (decrnum a)"
krauss@41839
   360
| "decr (Eq a) = Eq (decrnum a)"
krauss@41839
   361
| "decr (NEq a) = NEq (decrnum a)"
krauss@41839
   362
| "decr (Dvd i a) = Dvd i (decrnum a)"
krauss@41839
   363
| "decr (NDvd i a) = NDvd i (decrnum a)"
lp15@61694
   364
| "decr (NOT p) = NOT (decr p)"
krauss@41839
   365
| "decr (And p q) = And (decr p) (decr q)"
krauss@41839
   366
| "decr (Or p q) = Or (decr p) (decr q)"
krauss@41839
   367
| "decr (Imp p q) = Imp (decr p) (decr q)"
krauss@41839
   368
| "decr (Iff p q) = Iff (decr p) (decr q)"
krauss@41839
   369
| "decr p = p"
chaieb@23264
   370
chaieb@23264
   371
lemma decrnum: assumes nb: "numbound0 t"
chaieb@23264
   372
  shows "Inum (x#bs) t = Inum bs (decrnum t)"
wenzelm@51369
   373
  using nb by (induct t rule: decrnum.induct) simp_all
chaieb@23264
   374
chaieb@23264
   375
lemma decr: assumes nb: "bound0 p"
chaieb@23264
   376
  shows "Ifm (x#bs) p = Ifm bs (decr p)"
wenzelm@51369
   377
  using nb by (induct p rule: decr.induct) (simp_all add: decrnum)
chaieb@23264
   378
chaieb@23264
   379
lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
wenzelm@51369
   380
  by (induct p) simp_all
chaieb@23264
   381
krauss@41839
   382
fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) where
chaieb@23264
   383
  "isatom T = True"
krauss@41839
   384
| "isatom F = True"
krauss@41839
   385
| "isatom (Lt a) = True"
krauss@41839
   386
| "isatom (Le a) = True"
krauss@41839
   387
| "isatom (Gt a) = True"
krauss@41839
   388
| "isatom (Ge a) = True"
krauss@41839
   389
| "isatom (Eq a) = True"
krauss@41839
   390
| "isatom (NEq a) = True"
krauss@41839
   391
| "isatom (Dvd i b) = True"
krauss@41839
   392
| "isatom (NDvd i b) = True"
krauss@41839
   393
| "isatom p = False"
chaieb@23264
   394
wenzelm@51369
   395
lemma numsubst0_numbound0:
wenzelm@51369
   396
  assumes nb: "numbound0 t"
chaieb@23264
   397
  shows "numbound0 (numsubst0 t a)"
wenzelm@51369
   398
  using nb by (induct a) auto
wenzelm@51369
   399
wenzelm@51369
   400
lemma subst0_bound0:
wenzelm@51369
   401
  assumes qf: "qfree p" and nb: "numbound0 t"
chaieb@23264
   402
  shows "bound0 (subst0 t p)"
wenzelm@51369
   403
  using qf numsubst0_numbound0[OF nb] by (induct p) auto
chaieb@23264
   404
chaieb@23264
   405
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
wenzelm@51369
   406
  by (induct p) simp_all
chaieb@23264
   407
chaieb@23264
   408
haftmann@25765
   409
definition djf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
lp15@61694
   410
  "djf f p q = (if q=T then T else if q=F then f p else
chaieb@23264
   411
  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or fp q))"
haftmann@25765
   412
haftmann@25765
   413
definition evaldjf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
haftmann@25765
   414
  "evaldjf f ps = foldr (djf f) ps F"
chaieb@23264
   415
chaieb@23264
   416
lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
lp15@61694
   417
  by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def)
lp15@61694
   418
  (cases "f p", simp_all add: Let_def djf_def)
chaieb@23264
   419
chaieb@23264
   420
lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))"
wenzelm@51369
   421
  by (induct ps) (simp_all add: evaldjf_def djf_Or)
chaieb@23264
   422
lp15@61694
   423
lemma evaldjf_bound0:
chaieb@23264
   424
  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
chaieb@23264
   425
  shows "bound0 (evaldjf f xs)"
wenzelm@51369
   426
  using nb
wenzelm@51369
   427
  apply (induct xs)
wenzelm@51369
   428
  apply (auto simp add: evaldjf_def djf_def Let_def)
wenzelm@51369
   429
  apply (case_tac "f a")
wenzelm@51369
   430
  apply auto
wenzelm@51369
   431
  done
chaieb@23264
   432
lp15@61694
   433
lemma evaldjf_qf:
chaieb@23264
   434
  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
chaieb@23264
   435
  shows "qfree (evaldjf f xs)"
wenzelm@51369
   436
  using nb
wenzelm@51369
   437
  apply (induct xs)
wenzelm@51369
   438
  apply (auto simp add: evaldjf_def djf_def Let_def)
wenzelm@51369
   439
  apply (case_tac "f a")
wenzelm@51369
   440
  apply auto
wenzelm@51369
   441
  done
chaieb@23264
   442
krauss@41839
   443
fun disjuncts :: "fm \<Rightarrow> fm list" where
chaieb@23264
   444
  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
krauss@41839
   445
| "disjuncts F = []"
krauss@41839
   446
| "disjuncts p = [p]"
krauss@41839
   447
krauss@41839
   448
fun conjuncts :: "fm \<Rightarrow> fm list" where
chaieb@23264
   449
  "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
krauss@41839
   450
| "conjuncts T = []"
krauss@41839
   451
| "conjuncts p = [p]"
krauss@41839
   452
chaieb@23264
   453
lemma conjuncts: "(\<forall> q\<in> set (conjuncts p). Ifm bs q) = Ifm bs p"
wenzelm@51369
   454
  by (induct p rule: conjuncts.induct) auto
chaieb@23264
   455
chaieb@23264
   456
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
wenzelm@51369
   457
proof -
chaieb@23264
   458
  assume qf: "qfree p"
chaieb@23264
   459
  hence "list_all qfree (disjuncts p)"
chaieb@23264
   460
    by (induct p rule: disjuncts.induct, auto)
chaieb@23264
   461
  thus ?thesis by (simp only: list_all_iff)
chaieb@23264
   462
qed
wenzelm@51369
   463
chaieb@23264
   464
lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). qfree q"
chaieb@23264
   465
proof-
chaieb@23264
   466
  assume qf: "qfree p"
chaieb@23264
   467
  hence "list_all qfree (conjuncts p)"
chaieb@23264
   468
    by (induct p rule: conjuncts.induct, auto)
chaieb@23264
   469
  thus ?thesis by (simp only: list_all_iff)
chaieb@23264
   470
qed
chaieb@23264
   471
haftmann@35416
   472
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@23264
   473
  "DJ f p \<equiv> evaldjf f (disjuncts p)"
chaieb@23264
   474
chaieb@23264
   475
lemma DJ: assumes fdj: "\<forall> p q. f (Or p q) = Or (f p) (f q)"
chaieb@23264
   476
  and fF: "f F = F"
chaieb@23264
   477
  shows "Ifm bs (DJ f p) = Ifm bs (f p)"
wenzelm@51369
   478
proof -
chaieb@23264
   479
  have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))"
lp15@61694
   480
    by (simp add: DJ_def evaldjf_ex)
chaieb@23264
   481
  also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
chaieb@23264
   482
  finally show ?thesis .
chaieb@23264
   483
qed
chaieb@23264
   484
lp15@61694
   485
lemma DJ_qf: assumes
chaieb@23264
   486
  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
chaieb@23264
   487
  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
chaieb@23264
   488
proof(clarify)
chaieb@23264
   489
  fix  p assume qf: "qfree p"
chaieb@23264
   490
  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
chaieb@23264
   491
  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
chaieb@23264
   492
  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
lp15@61694
   493
chaieb@23264
   494
  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
chaieb@23264
   495
qed
chaieb@23264
   496
chaieb@23264
   497
lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
chaieb@23264
   498
  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))"
chaieb@23264
   499
proof(clarify)
chaieb@23264
   500
  fix p::fm and bs
chaieb@23264
   501
  assume qf: "qfree p"
chaieb@23264
   502
  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
chaieb@23264
   503
  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
chaieb@23264
   504
  have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))"
chaieb@23264
   505
    by (simp add: DJ_def evaldjf_ex)
chaieb@23264
   506
  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto
chaieb@23264
   507
  also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
chaieb@23264
   508
  finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast
chaieb@23264
   509
qed
chaieb@23264
   510
  (* Simplification *)
chaieb@23264
   511
chaieb@23264
   512
  (* Algebraic simplifications for nums *)
krauss@41839
   513
fun bnds:: "num \<Rightarrow> nat list" where
chaieb@23264
   514
  "bnds (Bound n) = [n]"
krauss@41839
   515
| "bnds (CN n c a) = n#(bnds a)"
krauss@41839
   516
| "bnds (Neg a) = bnds a"
krauss@41839
   517
| "bnds (Add a b) = (bnds a)@(bnds b)"
krauss@41839
   518
| "bnds (Sub a b) = (bnds a)@(bnds b)"
krauss@41839
   519
| "bnds (Mul i a) = bnds a"
krauss@41839
   520
| "bnds (Floor a) = bnds a"
krauss@41839
   521
| "bnds (CF c a b) = (bnds a)@(bnds b)"
krauss@41839
   522
| "bnds a = []"
krauss@41839
   523
fun lex_ns:: "nat list \<Rightarrow> nat list \<Rightarrow> bool" where
krauss@41839
   524
  "lex_ns [] ms = True"
krauss@41839
   525
| "lex_ns ns [] = False"
krauss@41839
   526
| "lex_ns (n#ns) (m#ms) = (n<m \<or> ((n = m) \<and> lex_ns ns ms)) "
haftmann@35416
   527
definition lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool" where
krauss@41839
   528
  "lex_bnd t s \<equiv> lex_ns (bnds t) (bnds s)"
krauss@41839
   529
krauss@41839
   530
fun maxcoeff:: "num \<Rightarrow> int" where
wenzelm@61945
   531
  "maxcoeff (C i) = \<bar>i\<bar>"
wenzelm@61945
   532
| "maxcoeff (CN n c t) = max \<bar>c\<bar> (maxcoeff t)"
wenzelm@61945
   533
| "maxcoeff (CF c t s) = max \<bar>c\<bar> (maxcoeff s)"
krauss@41839
   534
| "maxcoeff t = 1"
chaieb@23264
   535
chaieb@23264
   536
lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
wenzelm@51369
   537
  by (induct t rule: maxcoeff.induct) auto
chaieb@23264
   538
krauss@41839
   539
fun numgcdh:: "num \<Rightarrow> int \<Rightarrow> int" where
huffman@31706
   540
  "numgcdh (C i) = (\<lambda>g. gcd i g)"
krauss@41839
   541
| "numgcdh (CN n c t) = (\<lambda>g. gcd c (numgcdh t g))"
krauss@41839
   542
| "numgcdh (CF c s t) = (\<lambda>g. gcd c (numgcdh t g))"
krauss@41839
   543
| "numgcdh t = (\<lambda>g. 1)"
haftmann@23858
   544
wenzelm@51369
   545
definition numgcd :: "num \<Rightarrow> int"
wenzelm@51369
   546
  where "numgcd t = numgcdh t (maxcoeff t)"
chaieb@23264
   547
krauss@41839
   548
fun reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num" where
chaieb@23264
   549
  "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
krauss@41839
   550
| "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
krauss@41839
   551
| "reducecoeffh (CF c s t) = (\<lambda> g. CF (c div g)  s (reducecoeffh t g))"
krauss@41839
   552
| "reducecoeffh t = (\<lambda>g. t)"
chaieb@23264
   553
wenzelm@51369
   554
definition reducecoeff :: "num \<Rightarrow> num"
haftmann@23858
   555
where
wenzelm@51369
   556
  "reducecoeff t =
lp15@61694
   557
    (let g = numgcd t in
wenzelm@51369
   558
     if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
chaieb@23264
   559
krauss@41839
   560
fun dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
chaieb@23264
   561
  "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
krauss@41839
   562
| "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
krauss@41839
   563
| "dvdnumcoeff (CF c s t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
krauss@41839
   564
| "dvdnumcoeff t = (\<lambda>g. False)"
chaieb@23264
   565
lp15@61694
   566
lemma dvdnumcoeff_trans:
chaieb@23264
   567
  assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
chaieb@23264
   568
  shows "dvdnumcoeff t g"
lp15@61694
   569
  using dgt' gdg
wenzelm@51369
   570
  by (induct t rule: dvdnumcoeff.induct) (simp_all add: gdg dvd_trans[OF gdg])
nipkow@30042
   571
nipkow@30042
   572
declare dvd_trans [trans add]
chaieb@23264
   573
chaieb@23264
   574
lemma numgcd0:
chaieb@23264
   575
  assumes g0: "numgcd t = 0"
chaieb@23264
   576
  shows "Inum bs t = 0"
chaieb@23264
   577
proof-
chaieb@23264
   578
  have "\<And>x. numgcdh t x= 0 \<Longrightarrow> Inum bs t = 0"
huffman@31706
   579
    by (induct t rule: numgcdh.induct, auto)
chaieb@23264
   580
  thus ?thesis using g0[simplified numgcd_def] by blast
chaieb@23264
   581
qed
chaieb@23264
   582
chaieb@23264
   583
lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
wenzelm@51369
   584
  using gp by (induct t rule: numgcdh.induct) auto
chaieb@23264
   585
chaieb@23264
   586
lemma numgcd_pos: "numgcd t \<ge>0"
chaieb@23264
   587
  by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
chaieb@23264
   588
chaieb@23264
   589
lemma reducecoeffh:
lp15@61694
   590
  assumes gt: "dvdnumcoeff t g" and gp: "g > 0"
lp15@61609
   591
  shows "real_of_int g *(Inum bs (reducecoeffh t g)) = Inum bs t"
chaieb@23264
   592
  using gt
lp15@61694
   593
proof(induct t rule: reducecoeffh.induct)
chaieb@23264
   594
  case (1 i) hence gd: "g dvd i" by simp
bulwahn@46670
   595
  from assms 1 show ?case by (simp add: real_of_int_div[OF gd])
chaieb@23264
   596
next
chaieb@23264
   597
  case (2 n c t)  hence gd: "g dvd c" by simp
bulwahn@46670
   598
  from assms 2 show ?case by (simp add: real_of_int_div[OF gd] algebra_simps)
chaieb@23264
   599
next
chaieb@23264
   600
  case (3 c s t)  hence gd: "g dvd c" by simp
lp15@61694
   601
  from assms 3 show ?case by (simp add: real_of_int_div[OF gd] algebra_simps)
chaieb@23264
   602
qed (auto simp add: numgcd_def gp)
wenzelm@41807
   603
krauss@41839
   604
fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
wenzelm@61945
   605
  "ismaxcoeff (C i) = (\<lambda> x. \<bar>i\<bar> \<le> x)"
wenzelm@61945
   606
| "ismaxcoeff (CN n c t) = (\<lambda>x. \<bar>c\<bar> \<le> x \<and> (ismaxcoeff t x))"
wenzelm@61945
   607
| "ismaxcoeff (CF c s t) = (\<lambda>x. \<bar>c\<bar> \<le> x \<and> (ismaxcoeff t x))"
krauss@41839
   608
| "ismaxcoeff t = (\<lambda>x. True)"
chaieb@23264
   609
chaieb@23264
   610
lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
wenzelm@51369
   611
  by (induct t rule: ismaxcoeff.induct) auto
chaieb@23264
   612
chaieb@23264
   613
lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
chaieb@23264
   614
proof (induct t rule: maxcoeff.induct)
chaieb@23264
   615
  case (2 n c t)
chaieb@23264
   616
  hence H:"ismaxcoeff t (maxcoeff t)" .
wenzelm@61945
   617
  have thh: "maxcoeff t \<le> max \<bar>c\<bar> (maxcoeff t)" by simp
wenzelm@51369
   618
  from ismaxcoeff_mono[OF H thh] show ?case by simp
chaieb@23264
   619
next
lp15@61694
   620
  case (3 c t s)
chaieb@23264
   621
  hence H1:"ismaxcoeff s (maxcoeff s)" by auto
chaieb@23264
   622
  have thh1: "maxcoeff s \<le> max \<bar>c\<bar> (maxcoeff s)" by (simp add: max_def)
wenzelm@51369
   623
  from ismaxcoeff_mono[OF H1 thh1] show ?case by simp
chaieb@23264
   624
qed simp_all
chaieb@23264
   625
wenzelm@61945
   626
lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> ((\<bar>i\<bar> > 1 \<and> \<bar>j\<bar> > 1) \<or> (\<bar>i\<bar> = 0 \<and> \<bar>j\<bar> > 1) \<or> (\<bar>i\<bar> > 1 \<and> \<bar>j\<bar> = 0))"
huffman@31706
   627
  apply (unfold gcd_int_def)
chaieb@23264
   628
  apply (cases "i = 0", simp_all)
chaieb@23264
   629
  apply (cases "j = 0", simp_all)
wenzelm@61945
   630
  apply (cases "\<bar>i\<bar> = 1", simp_all)
wenzelm@61945
   631
  apply (cases "\<bar>j\<bar> = 1", simp_all)
chaieb@23264
   632
  apply auto
chaieb@23264
   633
  done
wenzelm@51369
   634
chaieb@23264
   635
lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow>  m =0"
wenzelm@41807
   636
  by (induct t rule: numgcdh.induct) auto
chaieb@23264
   637
chaieb@23264
   638
lemma dvdnumcoeff_aux:
chaieb@23264
   639
  assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
chaieb@23264
   640
  shows "dvdnumcoeff t (numgcdh t m)"
wenzelm@41807
   641
using assms
chaieb@23264
   642
proof(induct t rule: numgcdh.induct)
lp15@61694
   643
  case (2 n c t)
chaieb@23264
   644
  let ?g = "numgcdh t m"
wenzelm@41807
   645
  from 2 have th:"gcd c ?g > 1" by simp
haftmann@27556
   646
  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
wenzelm@61945
   647
  have "(\<bar>c\<bar> > 1 \<and> ?g > 1) \<or> (\<bar>c\<bar> = 0 \<and> ?g > 1) \<or> (\<bar>c\<bar> > 1 \<and> ?g = 0)" by simp
wenzelm@61945
   648
  moreover {assume "\<bar>c\<bar> > 1" and gp: "?g > 1" with 2
chaieb@23264
   649
    have th: "dvdnumcoeff t ?g" by simp
huffman@31706
   650
    have th': "gcd c ?g dvd ?g" by simp
huffman@31706
   651
    from dvdnumcoeff_trans[OF th' th] have ?case by simp }
wenzelm@61945
   652
  moreover {assume "\<bar>c\<bar> = 0 \<and> ?g > 1"
wenzelm@41807
   653
    with 2 have th: "dvdnumcoeff t ?g" by simp
huffman@31706
   654
    have th': "gcd c ?g dvd ?g" by simp
huffman@31706
   655
    from dvdnumcoeff_trans[OF th' th] have ?case by simp
chaieb@23264
   656
    hence ?case by simp }
wenzelm@61945
   657
  moreover {assume "\<bar>c\<bar> > 1" and g0:"?g = 0"
wenzelm@41807
   658
    from numgcdh0[OF g0] have "m=0". with 2 g0 have ?case by simp }
chaieb@23264
   659
  ultimately show ?case by blast
chaieb@23264
   660
next
lp15@61694
   661
  case (3 c s t)
chaieb@23264
   662
  let ?g = "numgcdh t m"
wenzelm@41807
   663
  from 3 have th:"gcd c ?g > 1" by simp
haftmann@27556
   664
  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
wenzelm@61945
   665
  have "(\<bar>c\<bar> > 1 \<and> ?g > 1) \<or> (\<bar>c\<bar> = 0 \<and> ?g > 1) \<or> (\<bar>c\<bar> > 1 \<and> ?g = 0)" by simp
wenzelm@61945
   666
  moreover {assume "\<bar>c\<bar> > 1" and gp: "?g > 1" with 3
chaieb@23264
   667
    have th: "dvdnumcoeff t ?g" by simp
huffman@31706
   668
    have th': "gcd c ?g dvd ?g" by simp
huffman@31706
   669
    from dvdnumcoeff_trans[OF th' th] have ?case by simp }
wenzelm@61945
   670
  moreover {assume "\<bar>c\<bar> = 0 \<and> ?g > 1"
wenzelm@41807
   671
    with 3 have th: "dvdnumcoeff t ?g" by simp
huffman@31706
   672
    have th': "gcd c ?g dvd ?g" by simp
huffman@31706
   673
    from dvdnumcoeff_trans[OF th' th] have ?case by simp
chaieb@23264
   674
    hence ?case by simp }
wenzelm@61945
   675
  moreover {assume "\<bar>c\<bar> > 1" and g0:"?g = 0"
wenzelm@41807
   676
    from numgcdh0[OF g0] have "m=0". with 3 g0 have ?case by simp }
chaieb@23264
   677
  ultimately show ?case by blast
huffman@31706
   678
qed auto
chaieb@23264
   679
chaieb@23264
   680
lemma dvdnumcoeff_aux2:
chaieb@23264
   681
  assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
lp15@61694
   682
  using assms
chaieb@23264
   683
proof (simp add: numgcd_def)
chaieb@23264
   684
  let ?mc = "maxcoeff t"
chaieb@23264
   685
  let ?g = "numgcdh t ?mc"
chaieb@23264
   686
  have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
chaieb@23264
   687
  have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
chaieb@23264
   688
  assume H: "numgcdh t ?mc > 1"
wenzelm@41807
   689
  from dvdnumcoeff_aux[OF th1 th2 H] show "dvdnumcoeff t ?g" .
chaieb@23264
   690
qed
chaieb@23264
   691
lp15@61609
   692
lemma reducecoeff: "real_of_int (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
chaieb@23264
   693
proof-
chaieb@23264
   694
  let ?g = "numgcd t"
chaieb@23264
   695
  have "?g \<ge> 0"  by (simp add: numgcd_pos)
wenzelm@32960
   696
  hence "?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
lp15@61694
   697
  moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)}
lp15@61694
   698
  moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)}
chaieb@23264
   699
  moreover { assume g1:"?g > 1"
chaieb@23264
   700
    from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+
lp15@61694
   701
    from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis
lp15@61694
   702
      by (simp add: reducecoeff_def Let_def)}
chaieb@23264
   703
  ultimately show ?thesis by blast
chaieb@23264
   704
qed
chaieb@23264
   705
chaieb@23264
   706
lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
wenzelm@51369
   707
  by (induct t rule: reducecoeffh.induct) auto
chaieb@23264
   708
chaieb@23264
   709
lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
wenzelm@51369
   710
  using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
wenzelm@51369
   711
wenzelm@51369
   712
consts numadd:: "num \<times> num \<Rightarrow> num"
chaieb@23264
   713
recdef numadd "measure (\<lambda> (t,s). size t + size s)"
chaieb@23264
   714
  "numadd (CN n1 c1 r1,CN n2 c2 r2) =
lp15@61694
   715
  (if n1=n2 then
chaieb@23264
   716
  (let c = c1 + c2
chaieb@23264
   717
  in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
chaieb@23264
   718
  else if n1 \<le> n2 then CN n1 c1 (numadd (r1,CN n2 c2 r2))
chaieb@23264
   719
  else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
lp15@61694
   720
  "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"
lp15@61694
   721
  "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))"
lp15@61694
   722
  "numadd (CF c1 t1 r1,CF c2 t2 r2) =
lp15@61694
   723
   (if t1 = t2 then
chaieb@23264
   724
    (let c=c1+c2; s= numadd(r1,r2) in (if c=0 then s else CF c t1 s))
chaieb@23264
   725
   else if lex_bnd t1 t2 then CF c1 t1 (numadd(r1,CF c2 t2 r2))
chaieb@23264
   726
   else CF c2 t2 (numadd(CF c1 t1 r1,r2)))"
chaieb@23264
   727
  "numadd (CF c1 t1 r1,C c) = CF c1 t1 (numadd (r1, C c))"
chaieb@23264
   728
  "numadd (C c,CF c1 t1 r1) = CF c1 t1 (numadd (r1, C c))"
chaieb@23264
   729
  "numadd (C b1, C b2) = C (b1+b2)"
chaieb@23264
   730
  "numadd (a,b) = Add a b"
chaieb@23264
   731
chaieb@23264
   732
lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
chaieb@23264
   733
apply (induct t s rule: numadd.induct, simp_all add: Let_def)
nipkow@23477
   734
 apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
nipkow@29667
   735
  apply (case_tac "n1 = n2", simp_all add: algebra_simps)
webertj@49962
   736
  apply (simp only: distrib_right[symmetric])
nipkow@23477
   737
 apply simp
chaieb@23264
   738
apply (case_tac "lex_bnd t1 t2", simp_all)
nipkow@23477
   739
 apply (case_tac "c1+c2 = 0")
wenzelm@51369
   740
  apply (case_tac "t1 = t2")
lp15@61609
   741
   apply (simp_all add: algebra_simps distrib_right[symmetric] of_int_mult[symmetric] of_int_add[symmetric]del: of_int_mult of_int_add distrib_right)
wenzelm@51369
   742
  done
chaieb@23264
   743
chaieb@23264
   744
lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
wenzelm@51369
   745
  by (induct t s rule: numadd.induct) (auto simp add: Let_def)
chaieb@23264
   746
krauss@41839
   747
fun nummul:: "num \<Rightarrow> int \<Rightarrow> num" where
chaieb@23264
   748
  "nummul (C j) = (\<lambda> i. C (i*j))"
krauss@41839
   749
| "nummul (CN n c t) = (\<lambda> i. CN n (c*i) (nummul t i))"
krauss@41839
   750
| "nummul (CF c t s) = (\<lambda> i. CF (c*i) t (nummul s i))"
krauss@41839
   751
| "nummul (Mul c t) = (\<lambda> i. nummul t (i*c))"
krauss@41839
   752
| "nummul t = (\<lambda> i. Mul i t)"
chaieb@23264
   753
chaieb@23264
   754
lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
wenzelm@51369
   755
  by (induct t rule: nummul.induct) (auto simp add: algebra_simps)
chaieb@23264
   756
chaieb@23264
   757
lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
wenzelm@51369
   758
  by (induct t rule: nummul.induct) auto
wenzelm@51369
   759
wenzelm@51369
   760
definition numneg :: "num \<Rightarrow> num"
wenzelm@51369
   761
  where "numneg t \<equiv> nummul t (- 1)"
wenzelm@51369
   762
wenzelm@51369
   763
definition numsub :: "num \<Rightarrow> num \<Rightarrow> num"
wenzelm@51369
   764
  where "numsub s t \<equiv> (if s = t then C 0 else numadd (s,numneg t))"
chaieb@23264
   765
chaieb@23264
   766
lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
wenzelm@51369
   767
  using numneg_def nummul by simp
chaieb@23264
   768
chaieb@23264
   769
lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
wenzelm@51369
   770
  using numneg_def by simp
chaieb@23264
   771
chaieb@23264
   772
lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
wenzelm@51369
   773
  using numsub_def by simp
chaieb@23264
   774
chaieb@23264
   775
lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
wenzelm@51369
   776
  using numsub_def by simp
chaieb@23264
   777
chaieb@23264
   778
lemma isint_CF: assumes si: "isint s bs" shows "isint (CF c t s) bs"
chaieb@23264
   779
proof-
chaieb@23264
   780
  have cti: "isint (Mul c (Floor t)) bs" by (simp add: isint_Mul isint_Floor)
lp15@61694
   781
chaieb@23264
   782
  have "?thesis = isint (Add (Mul c (Floor t)) s) bs" by (simp add: isint_def)
chaieb@23264
   783
  also have "\<dots>" by (simp add: isint_add cti si)
chaieb@23264
   784
  finally show ?thesis .
chaieb@23264
   785
qed
chaieb@23264
   786
krauss@41839
   787
fun split_int:: "num \<Rightarrow> num \<times> num" where
chaieb@23264
   788
  "split_int (C c) = (C 0, C c)"
lp15@61694
   789
| "split_int (CN n c b) =
lp15@61694
   790
     (let (bv,bi) = split_int b
chaieb@23264
   791
       in (CN n c bv, bi))"
lp15@61694
   792
| "split_int (CF c a b) =
lp15@61694
   793
     (let (bv,bi) = split_int b
chaieb@23264
   794
       in (bv, CF c a bi))"
krauss@41839
   795
| "split_int a = (a,C 0)"
chaieb@23264
   796
wenzelm@41807
   797
lemma split_int: "\<And>tv ti. split_int t = (tv,ti) \<Longrightarrow> (Inum bs (Add tv ti) = Inum bs t) \<and> isint ti bs"
chaieb@23264
   798
proof (induct t rule: split_int.induct)
chaieb@23264
   799
  case (2 c n b tv ti)
chaieb@23264
   800
  let ?bv = "fst (split_int b)"
chaieb@23264
   801
  let ?bi = "snd (split_int b)"
chaieb@23264
   802
  have "split_int b = (?bv,?bi)" by simp
wenzelm@41807
   803
  with 2(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
wenzelm@41807
   804
  from 2(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def)
wenzelm@41807
   805
  from 2(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def)
chaieb@23264
   806
next
lp15@61694
   807
  case (3 c a b tv ti)
chaieb@23264
   808
  let ?bv = "fst (split_int b)"
chaieb@23264
   809
  let ?bi = "snd (split_int b)"
chaieb@23264
   810
  have "split_int b = (?bv,?bi)" by simp
wenzelm@41807
   811
  with 3(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
wenzelm@41807
   812
  from 3(2) have tibi: "ti = CF c a ?bi"
wenzelm@41807
   813
    by (simp add: Let_def split_def)
wenzelm@41807
   814
  from 3(2) b[symmetric] bii show ?case
wenzelm@41807
   815
    by (auto simp add: Let_def split_def isint_Floor isint_add isint_Mul isint_CF)
nipkow@29667
   816
qed (auto simp add: Let_def isint_iff isint_Floor isint_add isint_Mul split_def algebra_simps)
chaieb@23264
   817
chaieb@23264
   818
lemma split_int_nb: "numbound0 t \<Longrightarrow> numbound0 (fst (split_int t)) \<and> numbound0 (snd (split_int t)) "
wenzelm@41807
   819
  by (induct t rule: split_int.induct) (auto simp add: Let_def split_def)
wenzelm@41807
   820
wenzelm@41807
   821
definition numfloor:: "num \<Rightarrow> num"
haftmann@23858
   822
where
lp15@61694
   823
  "numfloor t = (let (tv,ti) = split_int t in
lp15@61694
   824
  (case tv of C i \<Rightarrow> numadd (tv,ti)
chaieb@23264
   825
  | _ \<Rightarrow> numadd(CF 1 tv (C 0),ti)))"
chaieb@23264
   826
chaieb@23264
   827
lemma numfloor[simp]: "Inum bs (numfloor t) = Inum bs (Floor t)" (is "?n t = ?N (Floor t)")
chaieb@23264
   828
proof-
chaieb@23264
   829
  let ?tv = "fst (split_int t)"
chaieb@23264
   830
  let ?ti = "snd (split_int t)"
chaieb@23264
   831
  have tvti:"split_int t = (?tv,?ti)" by simp
chaieb@23264
   832
  {assume H: "\<forall> v. ?tv \<noteq> C v"
lp15@61694
   833
    hence th1: "?n t = ?N (Add (Floor ?tv) ?ti)"
wenzelm@51369
   834
      by (cases ?tv) (auto simp add: numfloor_def Let_def split_def)
chaieb@23264
   835
    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
wenzelm@61942
   836
    hence "?N (Floor t) = real_of_int \<lfloor>?N (Add ?tv ?ti)\<rfloor>" by simp
wenzelm@61942
   837
    also have "\<dots> = real_of_int (\<lfloor>?N ?tv\<rfloor> + \<lfloor>?N ?ti\<rfloor>)"
chaieb@23264
   838
      by (simp,subst tii[simplified isint_iff, symmetric]) simp
chaieb@23264
   839
    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
chaieb@23264
   840
    finally have ?thesis using th1 by simp}
lp15@61694
   841
  moreover {fix v assume H:"?tv = C v"
chaieb@23264
   842
    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
wenzelm@61942
   843
    hence "?N (Floor t) = real_of_int \<lfloor>?N (Add ?tv ?ti)\<rfloor>" by simp
wenzelm@61942
   844
    also have "\<dots> = real_of_int (\<lfloor>?N ?tv\<rfloor> + \<lfloor>?N ?ti\<rfloor>)"
chaieb@23264
   845
      by (simp,subst tii[simplified isint_iff, symmetric]) simp
chaieb@23264
   846
    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
wenzelm@51369
   847
    finally have ?thesis by (simp add: H numfloor_def Let_def split_def) }
chaieb@23264
   848
  ultimately show ?thesis by auto
chaieb@23264
   849
qed
chaieb@23264
   850
chaieb@23264
   851
lemma numfloor_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numfloor t)"
chaieb@23264
   852
  using split_int_nb[where t="t"]
wenzelm@51369
   853
  by (cases "fst (split_int t)") (auto simp add: numfloor_def Let_def split_def)
chaieb@23264
   854
krauss@41839
   855
function simpnum:: "num \<Rightarrow> num" where
chaieb@23264
   856
  "simpnum (C j) = C j"
krauss@41839
   857
| "simpnum (Bound n) = CN n 1 (C 0)"
krauss@41839
   858
| "simpnum (Neg t) = numneg (simpnum t)"
krauss@41839
   859
| "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
krauss@41839
   860
| "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
krauss@41839
   861
| "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
krauss@41839
   862
| "simpnum (Floor t) = numfloor (simpnum t)"
krauss@41839
   863
| "simpnum (CN n c t) = (if c=0 then simpnum t else CN n c (simpnum t))"
krauss@41839
   864
| "simpnum (CF c t s) = simpnum(Add (Mul c (Floor t)) s)"
krauss@41839
   865
by pat_completeness auto
krauss@41839
   866
termination by (relation "measure num_size") auto
chaieb@23264
   867
chaieb@23264
   868
lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
wenzelm@51369
   869
  by (induct t rule: simpnum.induct) auto
wenzelm@51369
   870
wenzelm@51369
   871
lemma simpnum_numbound0[simp]: "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
wenzelm@51369
   872
  by (induct t rule: simpnum.induct) auto
chaieb@23264
   873
krauss@41839
   874
fun nozerocoeff:: "num \<Rightarrow> bool" where
chaieb@23264
   875
  "nozerocoeff (C c) = True"
krauss@41839
   876
| "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
krauss@41839
   877
| "nozerocoeff (CF c s t) = (c \<noteq> 0 \<and> nozerocoeff t)"
krauss@41839
   878
| "nozerocoeff (Mul c t) = (c\<noteq>0 \<and> nozerocoeff t)"
krauss@41839
   879
| "nozerocoeff t = True"
chaieb@23264
   880
chaieb@23264
   881
lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
wenzelm@51369
   882
  by (induct a b rule: numadd.induct) (auto simp add: Let_def)
chaieb@23264
   883
chaieb@23264
   884
lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)"
wenzelm@51369
   885
  by (induct a rule: nummul.induct) (auto simp add: Let_def numadd_nz)
chaieb@23264
   886
chaieb@23264
   887
lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
wenzelm@51369
   888
  by (simp add: numneg_def nummul_nz)
chaieb@23264
   889
chaieb@23264
   890
lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
wenzelm@51369
   891
  by (simp add: numsub_def numneg_nz numadd_nz)
chaieb@23264
   892
chaieb@23264
   893
lemma split_int_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (fst (split_int t)) \<and> nozerocoeff (snd (split_int t))"
wenzelm@51369
   894
  by (induct t rule: split_int.induct) (auto simp add: Let_def split_def)
chaieb@23264
   895
chaieb@23264
   896
lemma numfloor_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (numfloor t)"
wenzelm@51369
   897
  by (simp add: numfloor_def Let_def split_def)
wenzelm@51369
   898
    (cases "fst (split_int t)", simp_all add: split_int_nz numadd_nz)
chaieb@23264
   899
chaieb@23264
   900
lemma simpnum_nz: "nozerocoeff (simpnum t)"
wenzelm@51369
   901
  by (induct t rule: simpnum.induct)
wenzelm@51369
   902
    (auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz numfloor_nz)
chaieb@23264
   903
chaieb@23264
   904
lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
chaieb@23264
   905
proof (induct t rule: maxcoeff.induct)
chaieb@23264
   906
  case (2 n c t)
wenzelm@61945
   907
  hence cnz: "c \<noteq>0" and mx: "max \<bar>c\<bar> (maxcoeff t) = 0" by simp+
wenzelm@61945
   908
  have "max \<bar>c\<bar> (maxcoeff t) \<ge> \<bar>c\<bar>" by simp
wenzelm@61945
   909
  with cnz have "max \<bar>c\<bar> (maxcoeff t) > 0" by arith
wenzelm@41807
   910
  with 2 show ?case by simp
chaieb@23264
   911
next
lp15@61694
   912
  case (3 c s t)
wenzelm@61945
   913
  hence cnz: "c \<noteq>0" and mx: "max \<bar>c\<bar> (maxcoeff t) = 0" by simp+
wenzelm@61945
   914
  have "max \<bar>c\<bar> (maxcoeff t) \<ge> \<bar>c\<bar>" by simp
wenzelm@61945
   915
  with cnz have "max \<bar>c\<bar> (maxcoeff t) > 0" by arith
wenzelm@41807
   916
  with 3 show ?case by simp
chaieb@23264
   917
qed auto
chaieb@23264
   918
chaieb@23264
   919
lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0"
chaieb@23264
   920
proof-
chaieb@23264
   921
  from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
chaieb@23264
   922
  from numgcdh0[OF th]  have th:"maxcoeff t = 0" .
chaieb@23264
   923
  from maxcoeff_nz[OF nz th] show ?thesis .
chaieb@23264
   924
qed
chaieb@23264
   925
haftmann@35416
   926
definition simp_num_pair :: "(num \<times> int) \<Rightarrow> num \<times> int" where
chaieb@23264
   927
  "simp_num_pair \<equiv> (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
lp15@61694
   928
   (let t' = simpnum t ; g = numgcd t' in
lp15@61694
   929
      if g > 1 then (let g' = gcd n g in
lp15@61694
   930
        if g' = 1 then (t',n)
lp15@61694
   931
        else (reducecoeffh t' g', n div g'))
chaieb@23264
   932
      else (t',n))))"
chaieb@23264
   933
chaieb@23264
   934
lemma simp_num_pair_ci:
lp15@61609
   935
  shows "((\<lambda> (t,n). Inum bs t / real_of_int n) (simp_num_pair (t,n))) = ((\<lambda> (t,n). Inum bs t / real_of_int n) (t,n))"
chaieb@23264
   936
  (is "?lhs = ?rhs")
chaieb@23264
   937
proof-
chaieb@23264
   938
  let ?t' = "simpnum t"
chaieb@23264
   939
  let ?g = "numgcd ?t'"
huffman@31706
   940
  let ?g' = "gcd n ?g"
chaieb@23264
   941
  {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
chaieb@23264
   942
  moreover
chaieb@23264
   943
  { assume nnz: "n \<noteq> 0"
chaieb@23264
   944
    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
chaieb@23264
   945
    moreover
chaieb@23264
   946
    {assume g1:"?g>1" hence g0: "?g > 0" by simp
huffman@31706
   947
      from g1 nnz have gp0: "?g' \<noteq> 0" by simp
nipkow@31952
   948
      hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
chaieb@23264
   949
      hence "?g'= 1 \<or> ?g' > 1" by arith
chaieb@23264
   950
      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
chaieb@23264
   951
      moreover {assume g'1:"?g'>1"
wenzelm@32960
   952
        from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
wenzelm@32960
   953
        let ?tt = "reducecoeffh ?t' ?g'"
wenzelm@32960
   954
        let ?t = "Inum bs ?tt"
wenzelm@32960
   955
        have gpdg: "?g' dvd ?g" by simp
wenzelm@32960
   956
        have gpdd: "?g' dvd n" by simp
wenzelm@32960
   957
        have gpdgp: "?g' dvd ?g'" by simp
lp15@61694
   958
        from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p]
lp15@61609
   959
        have th2:"real_of_int ?g' * ?t = Inum bs ?t'" by simp
lp15@61609
   960
        from nnz g1 g'1 have "?lhs = ?t / real_of_int (n div ?g')" by (simp add: simp_num_pair_def Let_def)
lp15@61609
   961
        also have "\<dots> = (real_of_int ?g' * ?t) / (real_of_int ?g' * (real_of_int (n div ?g')))" by simp
lp15@61609
   962
        also have "\<dots> = (Inum bs ?t' / real_of_int n)"
bulwahn@46670
   963
          using real_of_int_div[OF gpdd] th2 gp0 by simp
lp15@61609
   964
        finally have "?lhs = Inum bs t / real_of_int n" by simp
wenzelm@41807
   965
        then have ?thesis using nnz g1 g'1 by (simp add: simp_num_pair_def) }
wenzelm@41807
   966
      ultimately have ?thesis by blast }
wenzelm@41807
   967
    ultimately have ?thesis by blast }
chaieb@23264
   968
  ultimately show ?thesis by blast
chaieb@23264
   969
qed
chaieb@23264
   970
wenzelm@41807
   971
lemma simp_num_pair_l:
wenzelm@41807
   972
  assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')"
chaieb@23264
   973
  shows "numbound0 t' \<and> n' >0"
chaieb@23264
   974
proof-
wenzelm@41807
   975
  let ?t' = "simpnum t"
chaieb@23264
   976
  let ?g = "numgcd ?t'"
huffman@31706
   977
  let ?g' = "gcd n ?g"
wenzelm@41807
   978
  { assume nz: "n = 0" hence ?thesis using assms by (simp add: Let_def simp_num_pair_def) }
chaieb@23264
   979
  moreover
chaieb@23264
   980
  { assume nnz: "n \<noteq> 0"
wenzelm@41807
   981
    {assume "\<not> ?g > 1" hence ?thesis using assms by (auto simp add: Let_def simp_num_pair_def) }
chaieb@23264
   982
    moreover
chaieb@23264
   983
    {assume g1:"?g>1" hence g0: "?g > 0" by simp
huffman@31706
   984
      from g1 nnz have gp0: "?g' \<noteq> 0" by simp
nipkow@31952
   985
      hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
chaieb@23264
   986
      hence "?g'= 1 \<or> ?g' > 1" by arith
wenzelm@41807
   987
      moreover {assume "?g'=1" hence ?thesis using assms g1 g0
wenzelm@41807
   988
          by (auto simp add: Let_def simp_num_pair_def) }
chaieb@23264
   989
      moreover {assume g'1:"?g'>1"
wenzelm@32960
   990
        have gpdg: "?g' dvd ?g" by simp
wenzelm@32960
   991
        have gpdd: "?g' dvd n" by simp
wenzelm@32960
   992
        have gpdgp: "?g' dvd ?g'" by simp
wenzelm@32960
   993
        from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
huffman@47142
   994
        from zdiv_mono1[OF g'n g'p, simplified div_self[OF gp0]]
wenzelm@32960
   995
        have "n div ?g' >0" by simp
wenzelm@41807
   996
        hence ?thesis using assms g1 g'1
wenzelm@32960
   997
          by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)}
wenzelm@41807
   998
      ultimately have ?thesis by blast }
lp15@61694
   999
    ultimately have ?thesis by blast }
chaieb@23264
  1000
  ultimately show ?thesis by blast
chaieb@23264
  1001
qed
chaieb@23264
  1002
krauss@41839
  1003
fun not:: "fm \<Rightarrow> fm" where
chaieb@23264
  1004
  "not (NOT p) = p"
krauss@41839
  1005
| "not T = F"
krauss@41839
  1006
| "not F = T"
krauss@41839
  1007
| "not (Lt t) = Ge t"
krauss@41839
  1008
| "not (Le t) = Gt t"
krauss@41839
  1009
| "not (Gt t) = Le t"
krauss@41839
  1010
| "not (Ge t) = Lt t"
krauss@41839
  1011
| "not (Eq t) = NEq t"
krauss@41839
  1012
| "not (NEq t) = Eq t"
krauss@41839
  1013
| "not (Dvd i t) = NDvd i t"
krauss@41839
  1014
| "not (NDvd i t) = Dvd i t"
krauss@41839
  1015
| "not (And p q) = Or (not p) (not q)"
krauss@41839
  1016
| "not (Or p q) = And (not p) (not q)"
krauss@41839
  1017
| "not p = NOT p"
chaieb@23264
  1018
lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
wenzelm@41807
  1019
  by (induct p) auto
chaieb@23264
  1020
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
wenzelm@41807
  1021
  by (induct p) auto
chaieb@23264
  1022
lemma not_nb[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
wenzelm@41807
  1023
  by (induct p) auto
chaieb@23264
  1024
haftmann@35416
  1025
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
lp15@61694
  1026
  "conj p q \<equiv> (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else
chaieb@23264
  1027
   if p = q then p else And p q)"
chaieb@23264
  1028
lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
wenzelm@41807
  1029
  by (cases "p=F \<or> q=F", simp_all add: conj_def) (cases p, simp_all)
chaieb@23264
  1030
chaieb@23264
  1031
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
lp15@61694
  1032
  using conj_def by auto
chaieb@23264
  1033
lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
lp15@61694
  1034
  using conj_def by auto
chaieb@23264
  1035
haftmann@35416
  1036
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
lp15@61694
  1037
  "disj p q \<equiv> (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p
chaieb@23264
  1038
       else if p=q then p else Or p q)"
chaieb@23264
  1039
chaieb@23264
  1040
lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
wenzelm@41807
  1041
  by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
chaieb@23264
  1042
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
lp15@61694
  1043
  using disj_def by auto
chaieb@23264
  1044
lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
lp15@61694
  1045
  using disj_def by auto
chaieb@23264
  1046
haftmann@35416
  1047
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
lp15@61694
  1048
  "imp p q \<equiv> (if (p = F \<or> q=T \<or> p=q) then T else if p=T then q else if q=F then not p
chaieb@23264
  1049
    else Imp p q)"
chaieb@23264
  1050
lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
wenzelm@41807
  1051
  by (cases "p=F \<or> q=T",simp_all add: imp_def)
chaieb@23264
  1052
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
wenzelm@41807
  1053
  using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
chaieb@23264
  1054
haftmann@35416
  1055
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
lp15@61694
  1056
  "iff p q \<equiv> (if (p = q) then T else if (p = not q \<or> not p = q) then F else
lp15@61694
  1057
       if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else
chaieb@23264
  1058
  Iff p q)"
lp15@61649
  1059
chaieb@23264
  1060
lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
lp15@61649
  1061
  by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp)  (cases "not p= q", auto simp add:not)
lp15@61649
  1062
chaieb@23264
  1063
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
chaieb@23264
  1064
  by (unfold iff_def,cases "p=q", auto)
chaieb@23264
  1065
krauss@41839
  1066
fun check_int:: "num \<Rightarrow> bool" where
chaieb@23264
  1067
  "check_int (C i) = True"
krauss@41839
  1068
| "check_int (Floor t) = True"
krauss@41839
  1069
| "check_int (Mul i t) = check_int t"
krauss@41839
  1070
| "check_int (Add t s) = (check_int t \<and> check_int s)"
krauss@41839
  1071
| "check_int (Neg t) = check_int t"
krauss@41839
  1072
| "check_int (CF c t s) = check_int s"
krauss@41839
  1073
| "check_int t = False"
chaieb@23264
  1074
lemma check_int: "check_int t \<Longrightarrow> isint t bs"
wenzelm@51369
  1075
  by (induct t) (auto simp add: isint_add isint_Floor isint_Mul isint_neg isint_c isint_CF)
chaieb@23264
  1076
lp15@61609
  1077
lemma rdvd_left1_int: "real_of_int \<lfloor>t\<rfloor> = t \<Longrightarrow> 1 rdvd t"
chaieb@23264
  1078
  by (simp add: rdvd_def,rule_tac x="\<lfloor>t\<rfloor>" in exI) simp
chaieb@23264
  1079
lp15@61694
  1080
lemma rdvd_reduce:
chaieb@23264
  1081
  assumes gd:"g dvd d" and gc:"g dvd c" and gp: "g > 0"
lp15@61609
  1082
  shows "real_of_int (d::int) rdvd real_of_int (c::int)*t = (real_of_int (d div g) rdvd real_of_int (c div g)*t)"
chaieb@23264
  1083
proof
lp15@61609
  1084
  assume d: "real_of_int d rdvd real_of_int c * t"
lp15@61609
  1085
  from d rdvd_def obtain k where k_def: "real_of_int c * t = real_of_int d* real_of_int (k::int)" by auto
chaieb@23264
  1086
  from gd dvd_def obtain kd where kd_def: "d = g * kd" by auto
chaieb@23264
  1087
  from gc dvd_def obtain kc where kc_def: "c = g * kc" by auto
lp15@61609
  1088
  from k_def kd_def kc_def have "real_of_int g * real_of_int kc * t = real_of_int g * real_of_int kd * real_of_int k" by simp
lp15@61609
  1089
  hence "real_of_int kc * t = real_of_int kd * real_of_int k" using gp by simp
lp15@61609
  1090
  hence th:"real_of_int kd rdvd real_of_int kc * t" using rdvd_def by blast
chaieb@23264
  1091
  from kd_def gp have th':"kd = d div g" by simp
chaieb@23264
  1092
  from kc_def gp have "kc = c div g" by simp
lp15@61609
  1093
  with th th' show "real_of_int (d div g) rdvd real_of_int (c div g) * t" by simp
chaieb@23264
  1094
next
lp15@61609
  1095
  assume d: "real_of_int (d div g) rdvd real_of_int (c div g) * t"
chaieb@23264
  1096
  from gp have gnz: "g \<noteq> 0" by simp
lp15@61609
  1097
  thus "real_of_int d rdvd real_of_int c * t" using d rdvd_mult[OF gnz, where n="d div g" and x="real_of_int (c div g) * t"] real_of_int_div[OF gd] real_of_int_div[OF gc] by simp
chaieb@23264
  1098
qed
chaieb@23264
  1099
haftmann@35416
  1100
definition simpdvd :: "int \<Rightarrow> num \<Rightarrow> (int \<times> num)" where
lp15@61694
  1101
  "simpdvd d t \<equiv>
lp15@61694
  1102
   (let g = numgcd t in
lp15@61694
  1103
      if g > 1 then (let g' = gcd d g in
lp15@61694
  1104
        if g' = 1 then (d, t)
lp15@61694
  1105
        else (d div g',reducecoeffh t g'))
chaieb@23264
  1106
      else (d, t))"
lp15@61694
  1107
lemma simpdvd:
chaieb@23264
  1108
  assumes tnz: "nozerocoeff t" and dnz: "d \<noteq> 0"
chaieb@23264
  1109
  shows "Ifm bs (Dvd (fst (simpdvd d t)) (snd (simpdvd d t))) = Ifm bs (Dvd d t)"
chaieb@23264
  1110
proof-
chaieb@23264
  1111
  let ?g = "numgcd t"
huffman@31706
  1112
  let ?g' = "gcd d ?g"
chaieb@23264
  1113
  {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simpdvd_def)}
chaieb@23264
  1114
  moreover
chaieb@23264
  1115
  {assume g1:"?g>1" hence g0: "?g > 0" by simp
huffman@31706
  1116
    from g1 dnz have gp0: "?g' \<noteq> 0" by simp
nipkow@31952
  1117
    hence g'p: "?g' > 0" using gcd_ge_0_int[where x="d" and y="numgcd t"] by arith
chaieb@23264
  1118
    hence "?g'= 1 \<or> ?g' > 1" by arith
chaieb@23264
  1119
    moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simpdvd_def)}
chaieb@23264
  1120
    moreover {assume g'1:"?g'>1"
chaieb@23264
  1121
      from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" ..
chaieb@23264
  1122
      let ?tt = "reducecoeffh t ?g'"
chaieb@23264
  1123
      let ?t = "Inum bs ?tt"
huffman@31706
  1124
      have gpdg: "?g' dvd ?g" by simp
huffman@31706
  1125
      have gpdd: "?g' dvd d" by simp
chaieb@23264
  1126
      have gpdgp: "?g' dvd ?g'" by simp
lp15@61694
  1127
      from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p]
lp15@61609
  1128
      have th2:"real_of_int ?g' * ?t = Inum bs t" by simp
wenzelm@41807
  1129
      from assms g1 g0 g'1
wenzelm@41807
  1130
      have "Ifm bs (Dvd (fst (simpdvd d t)) (snd(simpdvd d t))) = Ifm bs (Dvd (d div ?g') ?tt)"
wenzelm@32960
  1131
        by (simp add: simpdvd_def Let_def)
lp15@61609
  1132
      also have "\<dots> = (real_of_int d rdvd (Inum bs t))"
lp15@61694
  1133
        using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified div_self[OF gp0]]
wenzelm@32960
  1134
          th2[symmetric] by simp
chaieb@23264
  1135
      finally have ?thesis by simp  }
chaieb@23264
  1136
    ultimately have ?thesis by blast
chaieb@23264
  1137
  }
chaieb@23264
  1138
  ultimately show ?thesis by blast
chaieb@23264
  1139
qed
chaieb@23264
  1140
krauss@41839
  1141
function (sequential) simpfm :: "fm \<Rightarrow> fm" where
chaieb@23264
  1142
  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
krauss@41839
  1143
| "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
krauss@41839
  1144
| "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
krauss@41839
  1145
| "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
krauss@41839
  1146
| "simpfm (NOT p) = not (simpfm p)"
lp15@61694
  1147
| "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F
chaieb@23264
  1148
  | _ \<Rightarrow> Lt (reducecoeff a'))"
krauss@41839
  1149
| "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<le> 0)  then T else F | _ \<Rightarrow> Le (reducecoeff a'))"
krauss@41839
  1150
| "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0)  then T else F | _ \<Rightarrow> Gt (reducecoeff a'))"
krauss@41839
  1151
| "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<ge> 0)  then T else F | _ \<Rightarrow> Ge (reducecoeff a'))"
krauss@41839
  1152
| "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0)  then T else F | _ \<Rightarrow> Eq (reducecoeff a'))"
krauss@41839
  1153
| "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<noteq> 0)  then T else F | _ \<Rightarrow> NEq (reducecoeff a'))"
krauss@41839
  1154
| "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a)
wenzelm@61945
  1155
             else if (\<bar>i\<bar> = 1) \<and> check_int a then T
chaieb@23264
  1156
             else let a' = simpnum a in case a' of C v \<Rightarrow> if (i dvd v)  then T else F | _ \<Rightarrow> (let (d,t) = simpdvd i a' in Dvd d t))"
lp15@61694
  1157
| "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a)
wenzelm@61945
  1158
             else if (\<bar>i\<bar> = 1) \<and> check_int a then F
chaieb@23264
  1159
             else let a' = simpnum a in case a' of C v \<Rightarrow> if (\<not>(i dvd v)) then T else F | _ \<Rightarrow> (let (d,t) = simpdvd i a' in NDvd d t))"
krauss@41839
  1160
| "simpfm p = p"
krauss@41839
  1161
by pat_completeness auto
krauss@41839
  1162
termination by (relation "measure fmsize") auto
chaieb@23264
  1163
chaieb@23264
  1164
lemma simpfm[simp]: "Ifm bs (simpfm p) = Ifm bs p"
chaieb@23264
  1165
proof(induct p rule: simpfm.induct)
chaieb@23264
  1166
  case (6 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1167
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1168
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1169
    let ?g = "numgcd ?sa"
chaieb@23264
  1170
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1171
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1172
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1173
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1174
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1175
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1176
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1177
    with sa have "Inum bs a < 0 = (real_of_int ?g * ?r < real_of_int ?g * 0)" by simp
chaieb@23264
  1178
    also have "\<dots> = (?r < 0)" using gp
chaieb@23264
  1179
      by (simp only: mult_less_cancel_left) simp
chaieb@23264
  1180
    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
chaieb@23264
  1181
  ultimately show ?case by blast
chaieb@23264
  1182
next
chaieb@23264
  1183
  case (7 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1184
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1185
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1186
    let ?g = "numgcd ?sa"
chaieb@23264
  1187
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1188
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1189
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1190
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1191
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1192
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1193
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1194
    with sa have "Inum bs a \<le> 0 = (real_of_int ?g * ?r \<le> real_of_int ?g * 0)" by simp
chaieb@23264
  1195
    also have "\<dots> = (?r \<le> 0)" using gp
chaieb@23264
  1196
      by (simp only: mult_le_cancel_left) simp
chaieb@23264
  1197
    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
chaieb@23264
  1198
  ultimately show ?case by blast
chaieb@23264
  1199
next
chaieb@23264
  1200
  case (8 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1201
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1202
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1203
    let ?g = "numgcd ?sa"
chaieb@23264
  1204
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1205
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1206
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1207
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1208
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1209
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1210
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1211
    with sa have "Inum bs a > 0 = (real_of_int ?g * ?r > real_of_int ?g * 0)" by simp
chaieb@23264
  1212
    also have "\<dots> = (?r > 0)" using gp
chaieb@23264
  1213
      by (simp only: mult_less_cancel_left) simp
chaieb@23264
  1214
    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
chaieb@23264
  1215
  ultimately show ?case by blast
chaieb@23264
  1216
next
chaieb@23264
  1217
  case (9 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1218
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1219
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1220
    let ?g = "numgcd ?sa"
chaieb@23264
  1221
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1222
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1223
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1224
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1225
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1226
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1227
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1228
    with sa have "Inum bs a \<ge> 0 = (real_of_int ?g * ?r \<ge> real_of_int ?g * 0)" by simp
chaieb@23264
  1229
    also have "\<dots> = (?r \<ge> 0)" using gp
chaieb@23264
  1230
      by (simp only: mult_le_cancel_left) simp
chaieb@23264
  1231
    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
chaieb@23264
  1232
  ultimately show ?case by blast
chaieb@23264
  1233
next
chaieb@23264
  1234
  case (10 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1235
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1236
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1237
    let ?g = "numgcd ?sa"
chaieb@23264
  1238
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1239
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1240
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1241
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1242
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1243
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1244
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1245
    with sa have "Inum bs a = 0 = (real_of_int ?g * ?r = 0)" by simp
chaieb@23264
  1246
    also have "\<dots> = (?r = 0)" using gp
wenzelm@51369
  1247
      by simp
chaieb@23264
  1248
    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
chaieb@23264
  1249
  ultimately show ?case by blast
chaieb@23264
  1250
next
chaieb@23264
  1251
  case (11 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
chaieb@23264
  1252
  {fix v assume "?sa = C v" hence ?case using sa by simp }
chaieb@23264
  1253
  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1254
    let ?g = "numgcd ?sa"
chaieb@23264
  1255
    let ?rsa = "reducecoeff ?sa"
chaieb@23264
  1256
    let ?r = "Inum bs ?rsa"
chaieb@23264
  1257
    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
chaieb@23264
  1258
    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
chaieb@23264
  1259
    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
lp15@61609
  1260
    hence gp: "real_of_int ?g > 0" by simp
lp15@61609
  1261
    have "Inum bs ?sa = real_of_int ?g* ?r" by (simp add: reducecoeff)
lp15@61609
  1262
    with sa have "Inum bs a \<noteq> 0 = (real_of_int ?g * ?r \<noteq> 0)" by simp
chaieb@23264
  1263
    also have "\<dots> = (?r \<noteq> 0)" using gp
wenzelm@51369
  1264
      by simp
wenzelm@51369
  1265
    finally have ?case using H by (cases "?sa") (simp_all add: Let_def) }
chaieb@23264
  1266
  ultimately show ?case by blast
chaieb@23264
  1267
next
chaieb@23264
  1268
  case (12 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
wenzelm@61945
  1269
  have "i=0 \<or> (\<bar>i\<bar> = 1 \<and> check_int a) \<or> (i\<noteq>0 \<and> ((\<bar>i\<bar> \<noteq> 1) \<or> (\<not> check_int a)))" by auto
chaieb@23264
  1270
  {assume "i=0" hence ?case using "12.hyps" by (simp add: rdvd_left_0_eq Let_def)}
lp15@61694
  1271
  moreover
wenzelm@61945
  1272
  {assume ai1: "\<bar>i\<bar> = 1" and ai: "check_int a"
chaieb@23264
  1273
    hence "i=1 \<or> i= - 1" by arith
lp15@61694
  1274
    moreover {assume i1: "i = 1"
lp15@61694
  1275
      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]]
chaieb@23264
  1276
      have ?case using i1 ai by simp }
lp15@61694
  1277
    moreover {assume i1: "i = - 1"
lp15@61694
  1278
      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]]
wenzelm@32960
  1279
        rdvd_abs1[where d="- 1" and t="Inum bs a"]
chaieb@23264
  1280
      have ?case using i1 ai by simp }
chaieb@23264
  1281
    ultimately have ?case by blast}
lp15@61694
  1282
  moreover
wenzelm@61945
  1283
  {assume inz: "i\<noteq>0" and cond: "(\<bar>i\<bar> \<noteq> 1) \<or> (\<not> check_int a)"
chaieb@23264
  1284
    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
wenzelm@61945
  1285
        by (cases "\<bar>i\<bar> = 1", auto simp add: int_rdvd_iff) }
lp15@61694
  1286
    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
chaieb@23264
  1287
      hence th: "simpfm (Dvd i a) = Dvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond by (cases ?sa, auto simp add: Let_def split_def)
chaieb@23264
  1288
      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
chaieb@23264
  1289
      from simpdvd [OF nz inz] th have ?case using sa by simp}
chaieb@23264
  1290
    ultimately have ?case by blast}
chaieb@23264
  1291
  ultimately show ?case by blast
chaieb@23264
  1292
next
chaieb@23264
  1293
  case (13 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
wenzelm@61945
  1294
  have "i=0 \<or> (\<bar>i\<bar> = 1 \<and> check_int a) \<or> (i\<noteq>0 \<and> ((\<bar>i\<bar> \<noteq> 1) \<or> (\<not> check_int a)))" by auto
chaieb@23264
  1295
  {assume "i=0" hence ?case using "13.hyps" by (simp add: rdvd_left_0_eq Let_def)}
lp15@61694
  1296
  moreover
wenzelm@61945
  1297
  {assume ai1: "\<bar>i\<bar> = 1" and ai: "check_int a"
chaieb@23264
  1298
    hence "i=1 \<or> i= - 1" by arith
lp15@61694
  1299
    moreover {assume i1: "i = 1"
lp15@61694
  1300
      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]]
chaieb@23264
  1301
      have ?case using i1 ai by simp }
lp15@61694
  1302
    moreover {assume i1: "i = - 1"
lp15@61694
  1303
      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]]
wenzelm@32960
  1304
        rdvd_abs1[where d="- 1" and t="Inum bs a"]
chaieb@23264
  1305
      have ?case using i1 ai by simp }
chaieb@23264
  1306
    ultimately have ?case by blast}
lp15@61694
  1307
  moreover
wenzelm@61945
  1308
  {assume inz: "i\<noteq>0" and cond: "(\<bar>i\<bar> \<noteq> 1) \<or> (\<not> check_int a)"
chaieb@23264
  1309
    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
wenzelm@61945
  1310
        by (cases "\<bar>i\<bar> = 1", auto simp add: int_rdvd_iff) }
lp15@61694
  1311
    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
lp15@61694
  1312
      hence th: "simpfm (NDvd i a) = NDvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond
wenzelm@32960
  1313
        by (cases ?sa, auto simp add: Let_def split_def)
chaieb@23264
  1314
      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
chaieb@23264
  1315
      from simpdvd [OF nz inz] th have ?case using sa by simp}
chaieb@23264
  1316
    ultimately have ?case by blast}
chaieb@23264
  1317
  ultimately show ?case by blast
chaieb@23264
  1318
qed (induct p rule: simpfm.induct, simp_all)
chaieb@23264
  1319
chaieb@23264
  1320
lemma simpdvd_numbound0: "numbound0 t \<Longrightarrow> numbound0 (snd (simpdvd d t))"
chaieb@23264
  1321
  by (simp add: simpdvd_def Let_def split_def reducecoeffh_numbound0)
chaieb@23264
  1322
chaieb@23264
  1323
lemma simpfm_bound0[simp]: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
chaieb@23264
  1324
proof(induct p rule: simpfm.induct)
chaieb@23264
  1325
  case (6 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1326
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1327
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1328
next
chaieb@23264
  1329
  case (7 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1330
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1331
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1332
next
chaieb@23264
  1333
  case (8 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1334
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1335
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1336
next
chaieb@23264
  1337
  case (9 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1338
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1339
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1340
next
chaieb@23264
  1341
  case (10 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1342
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1343
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1344
next
chaieb@23264
  1345
  case (11 a) hence nb: "numbound0 a" by simp
chaieb@23264
  1346
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1347
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
chaieb@23264
  1348
next
chaieb@23264
  1349
  case (12 i a) hence nb: "numbound0 a" by simp
chaieb@23264
  1350
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1351
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
chaieb@23264
  1352
next
chaieb@23264
  1353
  case (13 i a) hence nb: "numbound0 a" by simp
chaieb@23264
  1354
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
chaieb@23264
  1355
  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
chaieb@23264
  1356
qed(auto simp add: disj_def imp_def iff_def conj_def)
chaieb@23264
  1357
chaieb@23264
  1358
lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
chaieb@23264
  1359
by (induct p rule: simpfm.induct, auto simp add: Let_def)
chaieb@23264
  1360
(case_tac "simpnum a",auto simp add: split_def Let_def)+
chaieb@23264
  1361
chaieb@23264
  1362
chaieb@23264
  1363
  (* Generic quantifier elimination *)
chaieb@23264
  1364
haftmann@35416
  1365
definition list_conj :: "fm list \<Rightarrow> fm" where
chaieb@23264
  1366
  "list_conj ps \<equiv> foldr conj ps T"
chaieb@23264
  1367
lemma list_conj: "Ifm bs (list_conj ps) = (\<forall>p\<in> set ps. Ifm bs p)"
chaieb@23264
  1368
  by (induct ps, auto simp add: list_conj_def)
chaieb@23264
  1369
lemma list_conj_qf: " \<forall>p\<in> set ps. qfree p \<Longrightarrow> qfree (list_conj ps)"
chaieb@23264
  1370
  by (induct ps, auto simp add: list_conj_def)
chaieb@23264
  1371
lemma list_conj_nb: " \<forall>p\<in> set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
chaieb@23264
  1372
  by (induct ps, auto simp add: list_conj_def)
haftmann@35416
  1373
definition CJNB :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
haftmann@29788
  1374
  "CJNB f p \<equiv> (let cjs = conjuncts p ; (yes,no) = List.partition bound0 cjs
chaieb@23264
  1375
                   in conj (decr (list_conj yes)) (f (list_conj no)))"
chaieb@23264
  1376
lp15@61694
  1377
lemma CJNB_qe:
chaieb@23264
  1378
  assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
chaieb@23264
  1379
  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (CJNB qe p) \<and> (Ifm bs ((CJNB qe p)) = Ifm bs (E p))"
chaieb@23264
  1380
proof(clarify)
chaieb@23264
  1381
  fix bs p
chaieb@23264
  1382
  assume qfp: "qfree p"
chaieb@23264
  1383
  let ?cjs = "conjuncts p"
haftmann@29788
  1384
  let ?yes = "fst (List.partition bound0 ?cjs)"
haftmann@29788
  1385
  let ?no = "snd (List.partition bound0 ?cjs)"
chaieb@23264
  1386
  let ?cno = "list_conj ?no"
chaieb@23264
  1387
  let ?cyes = "list_conj ?yes"
haftmann@29788
  1388
  have part: "List.partition bound0 ?cjs = (?yes,?no)" by simp
lp15@61694
  1389
  from partition_P[OF part] have "\<forall> q\<in> set ?yes. bound0 q" by blast
lp15@61694
  1390
  hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb)
chaieb@23264
  1391
  hence yes_qf: "qfree (decr ?cyes )" by (simp add: decr_qf)
lp15@61694
  1392
  from conjuncts_qf[OF qfp] partition_set[OF part]
chaieb@23264
  1393
  have " \<forall>q\<in> set ?no. qfree q" by auto
chaieb@23264
  1394
  hence no_qf: "qfree ?cno"by (simp add: list_conj_qf)
lp15@61694
  1395
  with qe have cno_qf:"qfree (qe ?cno )"
chaieb@23264
  1396
    and noE: "Ifm bs (qe ?cno) = Ifm bs (E ?cno)" by blast+
lp15@61694
  1397
  from cno_qf yes_qf have qf: "qfree (CJNB qe p)"
wenzelm@51369
  1398
    by (simp add: CJNB_def Let_def split_def)
chaieb@23264
  1399
  {fix bs
chaieb@23264
  1400
    from conjuncts have "Ifm bs p = (\<forall>q\<in> set ?cjs. Ifm bs q)" by blast
chaieb@23264
  1401
    also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm bs q) \<and> (\<forall>q\<in> set ?no. Ifm bs q))"
chaieb@23264
  1402
      using partition_set[OF part] by auto
chaieb@23264
  1403
    finally have "Ifm bs p = ((Ifm bs ?cyes) \<and> (Ifm bs ?cno))" using list_conj by simp}
chaieb@23264
  1404
  hence "Ifm bs (E p) = (\<exists>x. (Ifm (x#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))" by simp
wenzelm@26932
  1405
  also fix y have "\<dots> = (\<exists>x. (Ifm (y#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))"
chaieb@23264
  1406
    using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
chaieb@23264
  1407
  also have "\<dots> = (Ifm bs (decr ?cyes) \<and> Ifm bs (E ?cno))"
hoelzl@33639
  1408
    by (auto simp add: decr[OF yes_nb] simp del: partition_filter_conv)
chaieb@23264
  1409
  also have "\<dots> = (Ifm bs (conj (decr ?cyes) (qe ?cno)))"
chaieb@23264
  1410
    using qe[rule_format, OF no_qf] by auto
lp15@61694
  1411
  finally have "Ifm bs (E p) = Ifm bs (CJNB qe p)"
chaieb@23264
  1412
    by (simp add: Let_def CJNB_def split_def)
chaieb@23264
  1413
  with qf show "qfree (CJNB qe p) \<and> Ifm bs (CJNB qe p) = Ifm bs (E p)" by blast
chaieb@23264
  1414
qed
chaieb@23264
  1415
krauss@41839
  1416
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where
chaieb@23264
  1417
  "qelim (E p) = (\<lambda> qe. DJ (CJNB qe) (qelim p qe))"
krauss@41839
  1418
| "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
krauss@41839
  1419
| "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
lp15@61694
  1420
| "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))"
lp15@61694
  1421
| "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))"
krauss@41839
  1422
| "qelim (Imp p q) = (\<lambda> qe. disj (qelim (NOT p) qe) (qelim q qe))"
krauss@41839
  1423
| "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
krauss@41839
  1424
| "qelim p = (\<lambda> y. simpfm p)"
krauss@41839
  1425
by pat_completeness auto
krauss@41839
  1426
termination by (relation "measure fmsize") auto
chaieb@23264
  1427
chaieb@23264
  1428
lemma qelim_ci:
chaieb@23264
  1429
  assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
chaieb@23264
  1430
  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)"
lp15@61694
  1431
  using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]]
wenzelm@41807
  1432
  by (induct p rule: qelim.induct) (auto simp del: simpfm.simps)
chaieb@23264
  1433
chaieb@23264
  1434
wenzelm@61586
  1435
text \<open>The \<open>\<int>\<close> Part\<close>
wenzelm@61586
  1436
text\<open>Linearity for fm where Bound 0 ranges over \<open>\<int>\<close>\<close>
krauss@41839
  1437
krauss@41839
  1438
function zsplit0 :: "num \<Rightarrow> int \<times> num" (* splits the bounded from the unbounded part*) where
chaieb@23264
  1439
  "zsplit0 (C c) = (0,C c)"
krauss@41839
  1440
| "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))"
krauss@41839
  1441
| "zsplit0 (CN n c a) = zsplit0 (Add (Mul c (Bound n)) a)"
krauss@41839
  1442
| "zsplit0 (CF c a b) = zsplit0 (Add (Mul c (Floor a)) b)"
krauss@41839
  1443
| "zsplit0 (Neg a) = (let (i',a') =  zsplit0 a in (-i', Neg a'))"
lp15@61694
  1444
| "zsplit0 (Add a b) = (let (ia,a') =  zsplit0 a ;
lp15@61694
  1445
                            (ib,b') =  zsplit0 b
chaieb@23264
  1446
                            in (ia+ib, Add a' b'))"
lp15@61694
  1447
| "zsplit0 (Sub a b) = (let (ia,a') =  zsplit0 a ;
lp15@61694
  1448
                            (ib,b') =  zsplit0 b
chaieb@23264
  1449
                            in (ia-ib, Sub a' b'))"
krauss@41839
  1450
| "zsplit0 (Mul i a) = (let (i',a') =  zsplit0 a in (i*i', Mul i a'))"
krauss@41839
  1451
| "zsplit0 (Floor a) = (let (i',a') =  zsplit0 a in (i',Floor a'))"
krauss@41839
  1452
by pat_completeness auto
krauss@41839
  1453
termination by (relation "measure num_size") auto
chaieb@23264
  1454
chaieb@23264
  1455
lemma zsplit0_I:
lp15@61609
  1456
  shows "\<And> n a. zsplit0 t = (n,a) \<Longrightarrow> (Inum ((real_of_int (x::int)) #bs) (CN 0 n a) = Inum (real_of_int x #bs) t) \<and> numbound0 a"
chaieb@23264
  1457
  (is "\<And> n a. ?S t = (n,a) \<Longrightarrow> (?I x (CN 0 n a) = ?I x t) \<and> ?N a")
chaieb@23264
  1458
proof(induct t rule: zsplit0.induct)
lp15@61694
  1459
  case (1 c n a) thus ?case by auto
chaieb@23264
  1460
next
chaieb@23264
  1461
  case (2 m n a) thus ?case by (cases "m=0") auto
chaieb@23264
  1462
next
chaieb@23264
  1463
  case (3 n i a n a') thus ?case by auto
lp15@61694
  1464
next
chaieb@23264
  1465
  case (4 c a b n a') thus ?case by auto
chaieb@23264
  1466
next
chaieb@23264
  1467
  case (5 t n a)
chaieb@23264
  1468
  let ?nt = "fst (zsplit0 t)"
chaieb@23264
  1469
  let ?at = "snd (zsplit0 t)"
lp15@61694
  1470
  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \<and> n=-?nt" using 5
chaieb@23264
  1471
    by (simp add: Let_def split_def)
wenzelm@41891
  1472
  from abj 5 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
chaieb@23264
  1473
  from th2[simplified] th[simplified] show ?case by simp
chaieb@23264
  1474
next
chaieb@23264
  1475
  case (6 s t n a)
chaieb@23264
  1476
  let ?ns = "fst (zsplit0 s)"
chaieb@23264
  1477
  let ?as = "snd (zsplit0 s)"
chaieb@23264
  1478
  let ?nt = "fst (zsplit0 t)"
chaieb@23264
  1479
  let ?at = "snd (zsplit0 t)"
lp15@61694
  1480
  have abjs: "zsplit0 s = (?ns,?as)" by simp
lp15@61694
  1481
  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp
wenzelm@41891
  1482
  ultimately have th: "a=Add ?as ?at \<and> n=?ns + ?nt" using 6
chaieb@23264
  1483
    by (simp add: Let_def split_def)
chaieb@23264
  1484
  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
lp15@61609
  1485
  from 6 have "(\<exists> x y. (x,y) = zsplit0 s) \<longrightarrow> (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (real_of_int x # bs) (CN 0 xa xb) = Inum (real_of_int x # bs) t \<and> numbound0 xb)" by blast (*FIXME*)
chaieb@23264
  1486
  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
wenzelm@41891
  1487
  from abjs 6  have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
lp15@61694
  1488
  from th3[simplified] th2[simplified] th[simplified] show ?case
webertj@49962
  1489
    by (simp add: distrib_right)
chaieb@23264
  1490
next
chaieb@23264
  1491
  case (7 s t n a)
chaieb@23264
  1492
  let ?ns = "fst (zsplit0 s)"
chaieb@23264
  1493
  let ?as = "snd (zsplit0 s)"
chaieb@23264
  1494
  let ?nt = "fst (zsplit0 t)"
chaieb@23264
  1495
  let ?at = "snd (zsplit0 t)"
lp15@61694
  1496
  have abjs: "zsplit0 s = (?ns,?as)" by simp
lp15@61694
  1497
  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp
wenzelm@41891
  1498
  ultimately have th: "a=Sub ?as ?at \<and> n=?ns - ?nt" using 7
chaieb@23264
  1499
    by (simp add: Let_def split_def)
chaieb@23264
  1500
  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
lp15@61609
  1501
  from 7 have "(\<exists> x y. (x,y) = zsplit0 s) \<longrightarrow> (\<forall>xa xb. zsplit0 t = (xa, xb) \<longrightarrow> Inum (real_of_int x # bs) (CN 0 xa xb) = Inum (real_of_int x # bs) t \<and> numbound0 xb)" by blast (*FIXME*)
chaieb@23264
  1502
  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
wenzelm@41891
  1503
  from abjs 7 have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
lp15@61694
  1504
  from th3[simplified] th2[simplified] th[simplified] show ?case
chaieb@23264
  1505
    by (simp add: left_diff_distrib)
chaieb@23264
  1506
next
chaieb@23264
  1507
  case (8 i t n a)
chaieb@23264
  1508
  let ?nt = "fst (zsplit0 t)"
chaieb@23264
  1509
  let ?at = "snd (zsplit0 t)"
wenzelm@41891
  1510
  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \<and> n=i*?nt" using 8
chaieb@23264
  1511
    by (simp add: Let_def split_def)
wenzelm@41891
  1512
  from abj 8 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
lp15@61609
  1513
  hence "?I x (Mul i t) = (real_of_int i) * ?I x (CN 0 ?nt ?at)" by simp
webertj@49962
  1514
  also have "\<dots> = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: distrib_left)
chaieb@23264
  1515
  finally show ?case using th th2 by simp
chaieb@23264
  1516
next
chaieb@23264
  1517
  case (9 t n a)
chaieb@23264
  1518
  let ?nt = "fst (zsplit0 t)"
chaieb@23264
  1519
  let ?at = "snd (zsplit0 t)"
wenzelm@41891
  1520
  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a= Floor ?at \<and> n=?nt" using 9
chaieb@23264
  1521
    by (simp add: Let_def split_def)
wenzelm@41891
  1522
  from abj 9 have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
chaieb@23264
  1523
  hence na: "?N a" using th by simp
lp15@61609
  1524
  have th': "(real_of_int ?nt)*(real_of_int x) = real_of_int (?nt * x)" by simp
chaieb@23264
  1525
  have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp
wenzelm@61942
  1526
  also have "\<dots> = real_of_int \<lfloor>real_of_int ?nt * real_of_int x + ?I x ?at\<rfloor>" by simp
wenzelm@61942
  1527
  also have "\<dots> = real_of_int \<lfloor>?I x ?at + real_of_int (?nt * x)\<rfloor>" by (simp add: ac_simps)
wenzelm@61942
  1528
  also have "\<dots> = real_of_int (\<lfloor>?I x ?at\<rfloor> + (?nt * x))"
wenzelm@61942
  1529
    using floor_add_of_int[of "?I x ?at" "?nt * x"] by simp
wenzelm@61942
  1530
  also have "\<dots> = real_of_int (?nt)*(real_of_int x) + real_of_int \<lfloor>?I x ?at\<rfloor>" by (simp add: ac_simps)
chaieb@23264
  1531
  finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp
chaieb@23264
  1532
  with na show ?case by simp
chaieb@23264
  1533
qed
chaieb@23264
  1534
chaieb@23264
  1535
consts
chaieb@23264
  1536
  iszlfm :: "fm \<Rightarrow> real list \<Rightarrow> bool"   (* Linearity test for fm *)
chaieb@23264
  1537
  zlfm :: "fm \<Rightarrow> fm"       (* Linearity transformation for fm *)
chaieb@23264
  1538
recdef iszlfm "measure size"
lp15@61694
  1539
  "iszlfm (And p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)"
lp15@61694
  1540
  "iszlfm (Or p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)"
chaieb@23264
  1541
  "iszlfm (Eq  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1542
  "iszlfm (NEq (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1543
  "iszlfm (Lt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1544
  "iszlfm (Le  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1545
  "iszlfm (Gt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1546
  "iszlfm (Ge  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
lp15@61694
  1547
  "iszlfm (Dvd i (CN 0 c e)) =
chaieb@23264
  1548
                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
lp15@61694
  1549
  "iszlfm (NDvd i (CN 0 c e))=
chaieb@23264
  1550
                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
chaieb@23264
  1551
  "iszlfm p = (\<lambda> bs. isatom p \<and> (bound0 p))"
chaieb@23264
  1552
chaieb@23264
  1553
lemma zlin_qfree: "iszlfm p bs \<Longrightarrow> qfree p"
chaieb@23264
  1554
  by (induct p rule: iszlfm.induct) auto
chaieb@23264
  1555
chaieb@23264
  1556
lemma iszlfm_gen:
chaieb@23264
  1557
  assumes lp: "iszlfm p (x#bs)"
chaieb@23264
  1558
  shows "\<forall> y. iszlfm p (y#bs)"
chaieb@23264
  1559
proof
chaieb@23264
  1560
  fix y
chaieb@23264
  1561
  show "iszlfm p (y#bs)"
chaieb@23264
  1562
    using lp
chaieb@23264
  1563
  by(induct p rule: iszlfm.induct, simp_all add: numbound0_gen[rule_format, where x="x" and y="y"])
chaieb@23264
  1564
qed
chaieb@23264
  1565
chaieb@23264
  1566
lemma conj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (conj p q) bs"
chaieb@23264
  1567
  using conj_def by (cases p,auto)
chaieb@23264
  1568
lemma disj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (disj p q) bs"
chaieb@23264
  1569
  using disj_def by (cases p,auto)
chaieb@23264
  1570
chaieb@23264
  1571
recdef zlfm "measure fmsize"
chaieb@23264
  1572
  "zlfm (And p q) = conj (zlfm p) (zlfm q)"
chaieb@23264
  1573
  "zlfm (Or p q) = disj (zlfm p) (zlfm q)"
chaieb@23264
  1574
  "zlfm (Imp p q) = disj (zlfm (NOT p)) (zlfm q)"
chaieb@23264
  1575
  "zlfm (Iff p q) = disj (conj (zlfm p) (zlfm q)) (conj (zlfm (NOT p)) (zlfm (NOT q)))"
lp15@61694
  1576
  "zlfm (Lt a) = (let (c,r) = zsplit0 a in
lp15@61694
  1577
     if c=0 then Lt r else
lp15@61694
  1578
     if c>0 then Or (Lt (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r)))
chaieb@23264
  1579
     else Or (Gt (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
lp15@61694
  1580
  "zlfm (Le a) = (let (c,r) = zsplit0 a in
lp15@61694
  1581
     if c=0 then Le r else
lp15@61694
  1582
     if c>0 then Or (Le (CN 0 c (Neg (Floor (Neg r))))) (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Lt (Add (Floor (Neg r)) r)))
chaieb@23264
  1583
     else Or (Ge (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
lp15@61694
  1584
  "zlfm (Gt a) = (let (c,r) = zsplit0 a in
lp15@61694
  1585
     if c=0 then Gt r else
lp15@61694
  1586
     if c>0 then Or (Gt (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r)))
chaieb@23264
  1587
     else Or (Lt (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
lp15@61694
  1588
  "zlfm (Ge a) = (let (c,r) = zsplit0 a in
lp15@61694
  1589
     if c=0 then Ge r else
lp15@61694
  1590
     if c>0 then Or (Ge (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r)))
chaieb@23264
  1591
     else Or (Le (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
lp15@61694
  1592
  "zlfm (Eq a) = (let (c,r) = zsplit0 a in
lp15@61694
  1593
              if c=0 then Eq r else
chaieb@23264
  1594
      if c>0 then (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Eq (Add (Floor (Neg r)) r)))
chaieb@23264
  1595
      else (And (Eq (CN 0 (-c) (Floor (Neg r)))) (Eq (Add (Floor (Neg r)) r))))"
lp15@61694
  1596
  "zlfm (NEq a) = (let (c,r) = zsplit0 a in
lp15@61694
  1597
              if c=0 then NEq r else
chaieb@23264
  1598
      if c>0 then (Or (NEq (CN 0 c (Neg (Floor (Neg r))))) (NEq (Add (Floor (Neg r)) r)))
chaieb@23264
  1599
      else (Or (NEq (CN 0 (-c) (Floor (Neg r)))) (NEq (Add (Floor (Neg r)) r))))"
lp15@61694
  1600
  "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a)
lp15@61694
  1601
  else (let (c,r) = zsplit0 a in
wenzelm@61945
  1602
              if c=0 then Dvd \<bar>i\<bar> r else
wenzelm@61945
  1603
      if c>0 then And (Eq (Sub (Floor r) r)) (Dvd \<bar>i\<bar> (CN 0 c (Floor r)))
wenzelm@61945
  1604
      else And (Eq (Sub (Floor r) r)) (Dvd \<bar>i\<bar> (CN 0 (-c) (Neg (Floor r))))))"
lp15@61694
  1605
  "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a)
lp15@61694
  1606
  else (let (c,r) = zsplit0 a in
wenzelm@61945
  1607
              if c=0 then NDvd \<bar>i\<bar> r else
wenzelm@61945
  1608
      if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd \<bar>i\<bar> (CN 0 c (Floor r)))
wenzelm@61945
  1609
      else Or (NEq (Sub (Floor r) r)) (NDvd \<bar>i\<bar> (CN 0 (-c) (Neg (Floor r))))))"
chaieb@23264
  1610
  "zlfm (NOT (And p q)) = disj (zlfm (NOT p)) (zlfm (NOT q))"
chaieb@23264
  1611
  "zlfm (NOT (Or p q)) = conj (zlfm (NOT p)) (zlfm (NOT q))"
chaieb@23264
  1612
  "zlfm (NOT (Imp p q)) = conj (zlfm p) (zlfm (NOT q))"
chaieb@23264
  1613
  "zlfm (NOT (Iff p q)) = disj (conj(zlfm p) (zlfm(NOT q))) (conj (zlfm(NOT p)) (zlfm q))"
chaieb@23264
  1614
  "zlfm (NOT (NOT p)) = zlfm p"
chaieb@23264
  1615
  "zlfm (NOT T) = F"
chaieb@23264
  1616
  "zlfm (NOT F) = T"
chaieb@23264
  1617
  "zlfm (NOT (Lt a)) = zlfm (Ge a)"
chaieb@23264
  1618
  "zlfm (NOT (Le a)) = zlfm (Gt a)"
chaieb@23264
  1619
  "zlfm (NOT (Gt a)) = zlfm (Le a)"
chaieb@23264
  1620
  "zlfm (NOT (Ge a)) = zlfm (Lt a)"
chaieb@23264
  1621
  "zlfm (NOT (Eq a)) = zlfm (NEq a)"
chaieb@23264
  1622
  "zlfm (NOT (NEq a)) = zlfm (Eq a)"
chaieb@23264
  1623
  "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)"
chaieb@23264
  1624
  "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)"
chaieb@23264
  1625
  "zlfm p = p" (hints simp add: fmsize_pos)
chaieb@23264
  1626
lp15@61694
  1627
lemma split_int_less_real:
wenzelm@61942
  1628
  "(real_of_int (a::int) < b) = (a < \<lfloor>b\<rfloor> \<or> (a = \<lfloor>b\<rfloor> \<and> real_of_int \<lfloor>b\<rfloor> < b))"
chaieb@23264
  1629
proof( auto)
wenzelm@61942
  1630
  assume alb: "real_of_int a < b" and agb: "\<not> a < \<lfloor>b\<rfloor>"
wenzelm@61942
  1631
  from agb have "\<lfloor>b\<rfloor> \<le> a" by simp
wenzelm@61942
  1632
  hence th: "b < real_of_int a + 1" by (simp only: floor_le_iff)
wenzelm@61942
  1633
  from floor_eq[OF alb th] show "a = \<lfloor>b\<rfloor>" by simp
chaieb@23264
  1634
next
wenzelm@61942
  1635
  assume alb: "a < \<lfloor>b\<rfloor>"
wenzelm@61942
  1636
  hence "real_of_int a < real_of_int \<lfloor>b\<rfloor>" by simp
wenzelm@61942
  1637
  moreover have "real_of_int \<lfloor>b\<rfloor> \<le> b" by simp
wenzelm@61942
  1638
  ultimately show  "real_of_int a < b" by arith
chaieb@23264
  1639
qed
chaieb@23264
  1640
lp15@61694
  1641
lemma split_int_less_real':
wenzelm@61942
  1642
  "(real_of_int (a::int) + b < 0) = (real_of_int a - real_of_int \<lfloor>- b\<rfloor> < 0 \<or> (real_of_int a - real_of_int \<lfloor>- b\<rfloor> = 0 \<and> real_of_int \<lfloor>- b\<rfloor> + b < 0))"
lp15@61694
  1643
proof-
lp15@61609
  1644
  have "(real_of_int a + b <0) = (real_of_int a < -b)" by arith
lp15@61694
  1645
  with split_int_less_real[where a="a" and b="-b"] show ?thesis by arith
chaieb@23264
  1646
qed
chaieb@23264
  1647
lp15@61694
  1648
lemma split_int_gt_real':
wenzelm@61942
  1649
  "(real_of_int (a::int) + b > 0) = (real_of_int a + real_of_int \<lfloor>b\<rfloor> > 0 \<or> (real_of_int a + real_of_int \<lfloor>b\<rfloor> = 0 \<and> real_of_int \<lfloor>b\<rfloor> - b < 0))"
lp15@61694
  1650
proof-
lp15@61609
  1651
  have th: "(real_of_int a + b >0) = (real_of_int (-a) + (-b)< 0)" by arith
lp15@61762
  1652
  show ?thesis 
lp15@61762
  1653
    by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) (auto simp add: algebra_simps)
chaieb@23264
  1654
qed
chaieb@23264
  1655
lp15@61694
  1656
lemma split_int_le_real:
wenzelm@61942
  1657
  "(real_of_int (a::int) \<le> b) = (a \<le> \<lfloor>b\<rfloor> \<or> (a = \<lfloor>b\<rfloor> \<and> real_of_int \<lfloor>b\<rfloor> < b))"
chaieb@23264
  1658
proof( auto)
wenzelm@61942
  1659
  assume alb: "real_of_int a \<le> b" and agb: "\<not> a \<le> \<lfloor>b\<rfloor>"
wenzelm@61942
  1660
  from alb have "\<lfloor>real_of_int a\<rfloor> \<le> \<lfloor>b\<rfloor>" by (simp only: floor_mono)
wenzelm@61942
  1661
  hence "a \<le> \<lfloor>b\<rfloor>" by simp with agb show "False" by simp
chaieb@23264
  1662
next
wenzelm@61942
  1663
  assume alb: "a \<le> \<lfloor>b\<rfloor>"
wenzelm@61942
  1664
  hence "real_of_int a \<le> real_of_int \<lfloor>b\<rfloor>" by (simp only: floor_mono)
lp15@61694
  1665
  also have "\<dots>\<le> b" by simp  finally show  "real_of_int a \<le> b" .
chaieb@23264
  1666
qed
chaieb@23264
  1667
lp15@61694
  1668
lemma split_int_le_real':
wenzelm@61942
  1669
  "(real_of_int (a::int) + b \<le> 0) = (real_of_int a - real_of_int \<lfloor>- b\<rfloor> \<le> 0 \<or> (real_of_int a - real_of_int \<lfloor>- b\<rfloor> = 0 \<and> real_of_int \<lfloor>- b\<rfloor> + b < 0))"
lp15@61694
  1670
proof-
lp15@61609
  1671
  have "(real_of_int a + b \<le>0) = (real_of_int a \<le> -b)" by arith
lp15@61694
  1672
  with split_int_le_real[where a="a" and b="-b"] show ?thesis by arith
chaieb@23264
  1673
qed
chaieb@23264
  1674
lp15@61694
  1675
lemma split_int_ge_real':
wenzelm@61942
  1676
  "(real_of_int (a::int) + b \<ge> 0) = (real_of_int a + real_of_int \<lfloor>b\<rfloor> \<ge> 0 \<or> (real_of_int a + real_of_int \<lfloor>b\<rfloor> = 0 \<and> real_of_int \<lfloor>b\<rfloor> - b < 0))"
lp15@61694
  1677
proof-
lp15@61609
  1678
  have th: "(real_of_int a + b \<ge>0) = (real_of_int (-a) + (-b) \<le> 0)" by arith
chaieb@23264
  1679
  show ?thesis by (simp only: th split_int_le_real'[where a="-a" and b="-b"])
wenzelm@51369
  1680
    (simp add: algebra_simps ,arith)
chaieb@23264
  1681
qed
chaieb@23264
  1682
wenzelm@61942
  1683
lemma split_int_eq_real: "(real_of_int (a::int) = b) = ( a = \<lfloor>b\<rfloor> \<and> b = real_of_int \<lfloor>b\<rfloor>)" (is "?l = ?r")
chaieb@23264
  1684
by auto
chaieb@23264
  1685
wenzelm@61942
  1686
lemma split_int_eq_real': "(real_of_int (a::int) + b = 0) = ( a - \<lfloor>- b\<rfloor> = 0 \<and> real_of_int \<lfloor>- b\<rfloor> + b = 0)" (is "?l = ?r")
chaieb@23264
  1687
proof-
lp15@61609
  1688
  have "?l = (real_of_int a = -b)" by arith
chaieb@23264
  1689
  with split_int_eq_real[where a="a" and b="-b"] show ?thesis by simp arith
chaieb@23264
  1690
qed
chaieb@23264
  1691
chaieb@23264
  1692
lemma zlfm_I:
chaieb@23264
  1693
  assumes qfp: "qfree p"
lp15@61609
  1694
  shows "(Ifm (real_of_int i #bs) (zlfm p) = Ifm (real_of_int i# bs) p) \<and> iszlfm (zlfm p) (real_of_int (i::int) #bs)"
chaieb@23264
  1695
  (is "(?I (?l p) = ?I p) \<and> ?L (?l p)")
chaieb@23264
  1696
using qfp
chaieb@23264
  1697
proof(induct p rule: zlfm.induct)
lp15@61694
  1698
  case (5 a)
chaieb@23264
  1699
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1700
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1701
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1702
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1703
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1704
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1705
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1706
  moreover
lp15@61694
  1707
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1708
      by (cases "?r", simp_all add: Let_def split_def,rename_tac nat a b,case_tac "nat", simp_all)}
chaieb@23264
  1709
  moreover
lp15@61694
  1710
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))"
chaieb@23264
  1711
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1712
    have "?I (Lt a) = (real_of_int (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
haftmann@54230
  1713
    also have "\<dots> = (?I (?l (Lt a)))" apply (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) by (simp add: Ia cp cnz Let_def split_def)
chaieb@23264
  1714
    finally have ?case using l by simp}
chaieb@23264
  1715
  moreover
lp15@61694
  1716
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))"
chaieb@23264
  1717
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1718
    have "?I (Lt a) = (real_of_int (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
haftmann@57514
  1719
    also from cn cnz have "\<dots> = (?I (?l (Lt a)))" by (simp only: split_int_less_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def ac_simps, arith)
chaieb@23264
  1720
    finally have ?case using l by simp}
chaieb@23264
  1721
  ultimately show ?case by blast
chaieb@23264
  1722
next
chaieb@23264
  1723
  case (6 a)
chaieb@23264
  1724
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1725
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1726
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1727
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1728
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1729
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1730
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1731
  moreover
lp15@61694
  1732
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1733
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat",simp_all)}
chaieb@23264
  1734
  moreover
lp15@61694
  1735
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))"
chaieb@23264
  1736
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1737
    have "?I (Le a) = (real_of_int (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
haftmann@54230
  1738
    also have "\<dots> = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def)
chaieb@23264
  1739
    finally have ?case using l by simp}
chaieb@23264
  1740
  moreover
lp15@61694
  1741
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))"
chaieb@23264
  1742
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1743
    have "?I (Le a) = (real_of_int (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
haftmann@57514
  1744
    also from cn cnz have "\<dots> = (?I (?l (Le a)))" by (simp only: split_int_le_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def ac_simps, arith)
chaieb@23264
  1745
    finally have ?case using l by simp}
chaieb@23264
  1746
  ultimately show ?case by blast
chaieb@23264
  1747
next
lp15@61694
  1748
  case (7 a)
chaieb@23264
  1749
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1750
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1751
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1752
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1753
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1754
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1755
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1756
  moreover
lp15@61694
  1757
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1758
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1759
  moreover
lp15@61694
  1760
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))"
chaieb@23264
  1761
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1762
    have "?I (Gt a) = (real_of_int (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
haftmann@54230
  1763
    also have "\<dots> = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def)
chaieb@23264
  1764
    finally have ?case using l by simp}
chaieb@23264
  1765
  moreover
lp15@61694
  1766
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))"
chaieb@23264
  1767
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1768
    have "?I (Gt a) = (real_of_int (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
haftmann@57514
  1769
    also from cn cnz have "\<dots> = (?I (?l (Gt a)))" by (simp only: split_int_gt_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def ac_simps, arith)
chaieb@23264
  1770
    finally have ?case using l by simp}
chaieb@23264
  1771
  ultimately show ?case by blast
chaieb@23264
  1772
next
chaieb@23264
  1773
  case (8 a)
chaieb@23264
  1774
   let ?c = "fst (zsplit0 a)"
chaieb@23264
  1775
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1776
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1777
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1778
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1779
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1780
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1781
  moreover
lp15@61694
  1782
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1783
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1784
  moreover
lp15@61694
  1785
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))"
chaieb@23264
  1786
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1787
    have "?I (Ge a) = (real_of_int (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
haftmann@54230
  1788
    also have "\<dots> = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia cp cnz Let_def split_def)
chaieb@23264
  1789
    finally have ?case using l by simp}
chaieb@23264
  1790
  moreover
lp15@61694
  1791
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))"
chaieb@23264
  1792
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1793
    have "?I (Ge a) = (real_of_int (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
haftmann@57514
  1794
    also from cn cnz have "\<dots> = (?I (?l (Ge a)))" by (simp only: split_int_ge_real'[where a="?c*i" and b="?N ?r"]) (simp add: Ia Let_def split_def ac_simps, arith)
chaieb@23264
  1795
    finally have ?case using l by simp}
chaieb@23264
  1796
  ultimately show ?case by blast
chaieb@23264
  1797
next
chaieb@23264
  1798
  case (9 a)
chaieb@23264
  1799
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1800
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1801
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1802
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1803
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1804
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1805
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1806
  moreover
lp15@61694
  1807
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1808
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1809
  moreover
lp15@61694
  1810
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))"
chaieb@23264
  1811
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1812
    have "?I (Eq a) = (real_of_int (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
lp15@61609
  1813
    also have "\<dots> = (?I (?l (Eq a)))" using cp cnz  by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia of_int_mult[symmetric] del: of_int_mult)
chaieb@23264
  1814
    finally have ?case using l by simp}
chaieb@23264
  1815
  moreover
lp15@61694
  1816
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))"
chaieb@23264
  1817
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1818
    have "?I (Eq a) = (real_of_int (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
lp15@61609
  1819
    also from cn cnz have "\<dots> = (?I (?l (Eq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia of_int_mult[symmetric] del: of_int_mult,arith)
chaieb@23264
  1820
    finally have ?case using l by simp}
chaieb@23264
  1821
  ultimately show ?case by blast
chaieb@23264
  1822
next
chaieb@23264
  1823
  case (10 a)
chaieb@23264
  1824
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1825
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1826
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1827
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1828
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1829
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1830
  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1831
  moreover
lp15@61694
  1832
  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"]
blanchet@58259
  1833
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1834
  moreover
lp15@61694
  1835
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))"
chaieb@23264
  1836
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1837
    have "?I (NEq a) = (real_of_int (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
lp15@61609
  1838
    also have "\<dots> = (?I (?l (NEq a)))" using cp cnz  by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia of_int_mult[symmetric] del: of_int_mult)
chaieb@23264
  1839
    finally have ?case using l by simp}
chaieb@23264
  1840
  moreover
lp15@61694
  1841
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))"
chaieb@23264
  1842
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61609
  1843
    have "?I (NEq a) = (real_of_int (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
lp15@61609
  1844
    also from cn cnz have "\<dots> = (?I (?l (NEq a)))" by (simp only: split_int_eq_real'[where a="?c*i" and b="?N ?r"]) (simp add: Let_def split_def Ia of_int_mult[symmetric] del: of_int_mult,arith)
chaieb@23264
  1845
    finally have ?case using l by simp}
chaieb@23264
  1846
  ultimately show ?case by blast
chaieb@23264
  1847
next
chaieb@23264
  1848
  case (11 j a)
chaieb@23264
  1849
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1850
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1851
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1852
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1853
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1854
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1855
  have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0 \<and> ?c\<noteq>0) \<or> (j\<noteq> 0 \<and> ?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1856
  moreover
lp15@61694
  1857
  { assume j: "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def)
wenzelm@41891
  1858
    hence ?case using 11 j by (simp del: zlfm.simps add: rdvd_left_0_eq)}
chaieb@23264
  1859
  moreover
lp15@61694
  1860
  {assume "?c=0" and "j\<noteq>0" hence ?case
chaieb@23264
  1861
      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
blanchet@58259
  1862
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1863
  moreover
lp15@61694
  1864
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
chaieb@23264
  1865
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61694
  1866
    have "?I (Dvd j a) = (real_of_int j rdvd (real_of_int (?c * i) + (?N ?r)))"
chaieb@23264
  1867
      using Ia by (simp add: Let_def split_def)
wenzelm@61945
  1868
    also have "\<dots> = (real_of_int \<bar>j\<bar> rdvd real_of_int (?c*i) + (?N ?r))"
lp15@61609
  1869
      by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
wenzelm@61945
  1870
    also have "\<dots> = (\<bar>j\<bar> dvd \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> \<and>
wenzelm@61942
  1871
       (real_of_int \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> = (real_of_int (?c*i) + (?N ?r))))"
wenzelm@61945
  1872
      by(simp only: int_rdvd_real[where i="\<bar>j\<bar>" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
lp15@61694
  1873
    also have "\<dots> = (?I (?l (Dvd j a)))" using cp cnz jnz
lp15@61694
  1874
      by (simp add: Let_def split_def int_rdvd_iff[symmetric]
lp15@61609
  1875
        del: of_int_mult) (auto simp add: ac_simps)
chaieb@23264
  1876
    finally have ?case using l jnz  by simp }
chaieb@23264
  1877
  moreover
lp15@61694
  1878
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))"
chaieb@23264
  1879
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61694
  1880
    have "?I (Dvd j a) = (real_of_int j rdvd (real_of_int (?c * i) + (?N ?r)))"
chaieb@23264
  1881
      using Ia by (simp add: Let_def split_def)
wenzelm@61945
  1882
    also have "\<dots> = (real_of_int \<bar>j\<bar> rdvd real_of_int (?c*i) + (?N ?r))"
lp15@61609
  1883
      by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
wenzelm@61945
  1884
    also have "\<dots> = (\<bar>j\<bar> dvd \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> \<and>
wenzelm@61942
  1885
       (real_of_int \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> = (real_of_int (?c*i) + (?N ?r))))"
wenzelm@61945
  1886
      by(simp only: int_rdvd_real[where i="\<bar>j\<bar>" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
chaieb@23264
  1887
    also have "\<dots> = (?I (?l (Dvd j a)))" using cn cnz jnz
wenzelm@61945
  1888
      using rdvd_minus [where d="\<bar>j\<bar>" and t="real_of_int (?c*i + \<lfloor>?N ?r\<rfloor>)", simplified, symmetric]
lp15@61694
  1889
      by (simp add: Let_def split_def int_rdvd_iff[symmetric]
lp15@61609
  1890
        del: of_int_mult) (auto simp add: ac_simps)
chaieb@23264
  1891
    finally have ?case using l jnz by blast }
chaieb@23264
  1892
  ultimately show ?case by blast
chaieb@23264
  1893
next
chaieb@23264
  1894
  case (12 j a)
chaieb@23264
  1895
  let ?c = "fst (zsplit0 a)"
chaieb@23264
  1896
  let ?r = "snd (zsplit0 a)"
chaieb@23264
  1897
  have spl: "zsplit0 a = (?c,?r)" by simp
lp15@61694
  1898
  from zsplit0_I[OF spl, where x="i" and bs="bs"]
lp15@61694
  1899
  have Ia:"Inum (real_of_int i # bs) a = Inum (real_of_int i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto
lp15@61609
  1900
  let ?N = "\<lambda> t. Inum (real_of_int i#bs) t"
chaieb@23264
  1901
  have "j=0 \<or> (j\<noteq>0 \<and> ?c = 0) \<or> (j\<noteq>0 \<and> ?c >0 \<and> ?c\<noteq>0) \<or> (j\<noteq> 0 \<and> ?c<0 \<and> ?c\<noteq>0)" by arith
chaieb@23264
  1902
  moreover
lp15@61694
  1903
  {assume j: "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def)
wenzelm@41891
  1904
    hence ?case using 12 j by (simp del: zlfm.simps add: rdvd_left_0_eq)}
chaieb@23264
  1905
  moreover
lp15@61694
  1906
  {assume "?c=0" and "j\<noteq>0" hence ?case
chaieb@23264
  1907
      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
blanchet@58259
  1908
      by (cases "?r", simp_all add: Let_def split_def, rename_tac nat a b, case_tac "nat", simp_all)}
chaieb@23264
  1909
  moreover
lp15@61694
  1910
  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))"
chaieb@23264
  1911
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61694
  1912
    have "?I (NDvd j a) = (\<not> (real_of_int j rdvd (real_of_int (?c * i) + (?N ?r))))"
chaieb@23264
  1913
      using Ia by (simp add: Let_def split_def)
wenzelm@61945
  1914
    also have "\<dots> = (\<not> (real_of_int \<bar>j\<bar> rdvd real_of_int (?c*i) + (?N ?r)))"
lp15@61609
  1915
      by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
wenzelm@61945
  1916
    also have "\<dots> = (\<not> (\<bar>j\<bar> dvd \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> \<and>
wenzelm@61942
  1917
       (real_of_int \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> = (real_of_int (?c*i) + (?N ?r)))))"
wenzelm@61945
  1918
      by(simp only: int_rdvd_real[where i="\<bar>j\<bar>" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
lp15@61694
  1919
    also have "\<dots> = (?I (?l (NDvd j a)))" using cp cnz jnz
lp15@61694
  1920
      by (simp add: Let_def split_def int_rdvd_iff[symmetric]
lp15@61609
  1921
        del: of_int_mult) (auto simp add: ac_simps)
chaieb@23264
  1922
    finally have ?case using l jnz  by simp }
chaieb@23264
  1923
  moreover
lp15@61694
  1924
  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))"
chaieb@23264
  1925
      by (simp add: nb Let_def split_def isint_Floor isint_neg)
lp15@61694
  1926
    have "?I (NDvd j a) = (\<not> (real_of_int j rdvd (real_of_int (?c * i) + (?N ?r))))"
chaieb@23264
  1927
      using Ia by (simp add: Let_def split_def)
wenzelm@61945
  1928
    also have "\<dots> = (\<not> (real_of_int \<bar>j\<bar> rdvd real_of_int (?c*i) + (?N ?r)))"
lp15@61609
  1929
      by (simp only: rdvd_abs1[where d="j" and t="real_of_int (?c*i) + ?N ?r", symmetric]) simp
wenzelm@61945
  1930
    also have "\<dots> = (\<not> (\<bar>j\<bar> dvd \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> \<and>
wenzelm@61942
  1931
       (real_of_int \<lfloor>(?N ?r) + real_of_int (?c*i)\<rfloor> = (real_of_int (?c*i) + (?N ?r)))))"
wenzelm@61945
  1932
      by(simp only: int_rdvd_real[where i="\<bar>j\<bar>" and x="real_of_int (?c*i) + (?N ?r)"]) (simp only: ac_simps)
chaieb@23264
  1933
    also have "\<dots> = (?I (?l (NDvd j a)))" using cn cnz jnz
wenzelm@61945
  1934
      using rdvd_minus [where d="\<bar>j\<bar>" and t="real_of_int (?c*i + \<lfloor>?N ?r\<rfloor>)", simplified, symmetric]
lp15@61694
  1935
      by (simp add: Let_def split_def int_rdvd_iff[symmetric]
lp15@61609
  1936
        del: of_int_mult) (auto simp add: ac_simps)
chaieb@23264
  1937
    finally have ?case using l jnz by blast }
chaieb@23264
  1938
  ultimately show ?case by blast
chaieb@23264
  1939
qed auto
chaieb@23264
  1940
wenzelm@61586
  1941
text\<open>plusinf : Virtual substitution of \<open>+\<infinity>\<close>
wenzelm@61586
  1942
       minusinf: Virtual substitution of \<open>-\<infinity>\<close>
wenzelm@61586
  1943
       \<open>\<delta>\<close> Compute lcm \<open>d| Dvd d  c*x+t \<in> p\<close>
wenzelm@61586
  1944
       \<open>d_\<delta>\<close> checks if a given l divides all the ds above\<close>
chaieb@23316
  1945
krauss@41839
  1946
fun minusinf:: "fm \<Rightarrow> fm" where
lp15@61694
  1947
  "minusinf (And p q) = conj (minusinf p) (minusinf q)"
lp15@61694
  1948
| "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
krauss@41839
  1949
| "minusinf (Eq  (CN 0 c e)) = F"
krauss@41839
  1950
| "minusinf (NEq (CN 0 c e)) = T"
krauss@41839
  1951
| "minusinf (Lt  (CN 0 c e)) = T"
krauss@41839
  1952
| "minusinf (Le  (CN 0 c e)) = T"
krauss@41839
  1953
| "minusinf (Gt  (CN 0 c e)) = F"
krauss@41839
  1954
| "minusinf (Ge  (CN 0 c e)) = F"
krauss@41839
  1955
| "minusinf p = p"
chaieb@23264
  1956
chaieb@23264
  1957
lemma minusinf_qfree: "qfree p \<Longrightarrow> qfree (minusinf p)"
chaieb@23264
  1958
  by (induct p rule: minusinf.induct, auto)
chaieb@23264
  1959
krauss@41839
  1960
fun plusinf:: "fm \<Rightarrow> fm" where
lp15@61694
  1961
  "plusinf (And p q) = conj (plusinf p) (plusinf q)"
lp15@61694
  1962
| "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
krauss@41839
  1963
| "plusinf (Eq  (CN 0 c e)) = F"
krauss@41839
  1964
| "plusinf (NEq (CN 0 c e)) = T"
krauss@41839
  1965
| "plusinf (Lt  (CN 0 c e)) = F"
krauss@41839
  1966
| "plusinf (Le  (CN 0 c e)) = F"
krauss@41839
  1967
| "plusinf (Gt  (CN 0 c e)) = T"
krauss@41839
  1968
| "plusinf (Ge  (CN 0 c e)) = T"
krauss@41839
  1969
| "plusinf p = p"
krauss@41839
  1970
krauss@41839
  1971
fun \<delta> :: "fm \<Rightarrow> int" where
lp15@61694
  1972
  "\<delta> (And p q) = lcm (\<delta> p) (\<delta> q)"
lp15@61694
  1973
| "\<delta> (Or p q) = lcm (\<delta> p) (\<delta> q)"
krauss@41839
  1974
| "\<delta> (Dvd i (CN 0 c e)) = i"
krauss@41839
  1975
| "\<delta> (NDvd i (CN 0 c e)) = i"
krauss@41839
  1976
| "\<delta> p = 1"
krauss@41839
  1977
wenzelm@50252
  1978
fun d_\<delta> :: "fm \<Rightarrow> int \<Rightarrow> bool" where
lp15@61694
  1979
  "d_\<delta> (And p q) = (\<lambda> d. d_\<delta> p d \<and> d_\<delta> q d)"
lp15@61694
  1980
| "d_\<delta> (Or p q) = (\<lambda> d. d_\<delta> p d \<and> d_\<delta> q d)"
wenzelm@50252
  1981
| "d_\<delta> (Dvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
wenzelm@50252
  1982
| "d_\<delta> (NDvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
wenzelm@50252
  1983
| "d_\<delta> p = (\<lambda> d. True)"
chaieb@23264
  1984
lp15@61694
  1985
lemma delta_mono:
chaieb@23264
  1986
  assumes lin: "iszlfm p bs"
chaieb@23264
  1987
  and d: "d dvd d'"
wenzelm@50252
  1988
  and ad: "d_\<delta> p d"
wenzelm@50252
  1989
  shows "d_\<delta> p d'"
chaieb@23264
  1990
  using lin ad d
chaieb@23264
  1991
proof(induct p rule: iszlfm.induct)
chaieb@23264
  1992
  case (9 i c e)  thus ?case using d
nipkow@30042
  1993
    by (simp add: dvd_trans[of "i" "d" "d'"])
chaieb@23264
  1994
next
chaieb@23264
  1995
  case (10 i c e) thus ?case using d
nipkow@30042
  1996
    by (simp add: dvd_trans[of "i" "d" "d'"])
chaieb@23264
  1997
qed simp_all
chaieb@23264
  1998
chaieb@23264
  1999
lemma \<delta> : assumes lin:"iszlfm p bs"
wenzelm@50252
  2000
  shows "d_\<delta> p (\<delta> p) \<and> \<delta> p >0"
chaieb@23264
  2001
using lin
chaieb@23264
  2002
proof (induct p rule: iszlfm.induct)
lp15@61694
  2003
  case (1 p q)
chaieb@23264
  2004
  let ?d = "\<delta> (And p q)"
wenzelm@41891
  2005
  from 1 lcm_pos_int have dp: "?d >0" by simp
lp15@61694
  2006
  have d1: "\<delta> p dvd \<delta> (And p q)" using 1 by simp
lp15@61694
  2007
  hence th: "d_\<delta> p ?d"
wenzelm@41891
  2008
    using delta_mono 1 by (simp only: iszlfm.simps) blast
lp15@61694
  2009
  have "\<delta> q dvd \<delta> (And p q)" using 1 by simp
wenzelm@50252
  2010
  hence th': "d_\<delta> q ?d" using delta_mono 1 by (simp only: iszlfm.simps) blast
lp15@61694
  2011
  from th th' dp show ?case by simp
chaieb@23264
  2012
next
lp15@61694
  2013
  case (2 p q)
chaieb@23264
  2014
  let ?d = "\<delta> (And p q)"
wenzelm@41891
  2015
  from 2 lcm_pos_int have dp: "?d >0" by simp
wenzelm@41891
  2016
  have "\<delta> p dvd \<delta> (And p q)" using 2 by simp
wenzelm@50252
  2017
  hence th: "d_\<delta> p ?d" using delta_mono 2 by (simp only: iszlfm.simps) blast
wenzelm@41891
  2018
  have "\<delta> q dvd \<delta> (And p q)" using 2 by simp
wenzelm@50252
  2019
  hence th': "d_\<delta> q ?d" using delta_mono 2 by (simp only: iszlfm.simps) blast
nipkow@31730
  2020
  from th th' dp show ?case by simp
chaieb@23264
  2021
qed simp_all
chaieb@23264
  2022
chaieb@23264
  2023
chaieb@23264
  2024
lemma minusinf_inf:
chaieb@23264
  2025
  assumes linp: "iszlfm p (a # bs)"
lp15@61609
  2026
  shows "\<exists> (z::int). \<forall> x < z. Ifm ((real_of_int x)#bs) (minusinf p) = Ifm ((real_of_int x)#bs) p"
chaieb@23264
  2027
  (is "?P p" is "\<exists> (z::int). \<forall> x < z. ?I x (?M p) = ?I x p")
chaieb@23264
  2028
using linp
chaieb@23264
  2029
proof (induct p rule: minusinf.induct)
chaieb@23264
  2030
  case (1 f g)
wenzelm@41891
  2031
  then have "?P f" by simp
chaieb@23264
  2032
  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
wenzelm@41891
  2033
  with 1 have "?P g" by simp
chaieb@23264
  2034
  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
chaieb@23264
  2035
  let ?z = "min z1 z2"
chaieb@23264
  2036
  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (And f g)) = ?I x (And f g)" by simp
chaieb@23264
  2037
  thus ?case by blast
chaieb@23264
  2038
next
wenzelm@41891
  2039
  case (2 f g)
wenzelm@41891
  2040
  then have "?P f" by simp
chaieb@23264
  2041
  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
wenzelm@41891
  2042
  with 2 have "?P g" by simp
chaieb@23264
  2043
  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
chaieb@23264
  2044
  let ?z = "min z1 z2"
chaieb@23264
  2045
  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (Or f g)) = ?I x (Or f g)" by simp
chaieb@23264
  2046
  thus ?case by blast
chaieb@23264
  2047
next
lp15@61694
  2048
  case (3 c e)
wenzelm@41891
  2049
  then have "c > 0" by simp
lp15@61609
  2050
  hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2051
  from 3 have nbe: "numbound0 e" by simp
wenzelm@26932
  2052
  fix y
wenzelm@61942
  2053
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Eq (CN 0 c e))) = ?I x (Eq (CN 0 c e))"
lp15@61694
  2054
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2055
    fix x :: int
lp15@61609
  2056
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2057
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2058
    with rcpos  have "(real_of_int c)*(real_of_int  x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2059
      by (simp only: mult_strict_left_mono [OF th1 rcpos])
lp15@61609
  2060
    hence "real_of_int c * real_of_int x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
lp15@61694
  2061
    thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<noteq> 0"
lp15@61609
  2062
      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"]  by simp
chaieb@23264
  2063
  qed
chaieb@23264
  2064
  thus ?case by blast
chaieb@23264
  2065
next
lp15@61694
  2066
  case (4 c e)
lp15@61609
  2067
  then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2068
  from 4 have nbe: "numbound0 e" by simp
wenzelm@26932
  2069
  fix y
wenzelm@61942
  2070
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (NEq (CN 0 c e))) = ?I x (NEq (CN 0 c e))"
lp15@61694
  2071
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2072
    fix x :: int
lp15@61609
  2073
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2074
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2075
    with rcpos  have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2076
      by (simp only: mult_strict_left_mono [OF th1 rcpos])
lp15@61609
  2077
    hence "real_of_int c * real_of_int x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
lp15@61694
  2078
    thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<noteq> 0"
lp15@61609
  2079
      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"]  by simp
chaieb@23264
  2080
  qed
chaieb@23264
  2081
  thus ?case by blast
chaieb@23264
  2082
next
lp15@61694
  2083
  case (5 c e)
lp15@61609
  2084
  then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2085
  from 5 have nbe: "numbound0 e" by simp
wenzelm@26932
  2086
  fix y
wenzelm@61942
  2087
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Lt (CN 0 c e))) = ?I x (Lt (CN 0 c e))"
lp15@61694
  2088
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2089
    fix x :: int
lp15@61609
  2090
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2091
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2092
    with rcpos  have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2093
      by (simp only: mult_strict_left_mono [OF th1 rcpos])
lp15@61694
  2094
    thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e < 0"
lp15@61609
  2095
      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
chaieb@23264
  2096
  qed
chaieb@23264
  2097
  thus ?case by blast
chaieb@23264
  2098
next
lp15@61694
  2099
  case (6 c e)
lp15@61609
  2100
  then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2101
  from 6 have nbe: "numbound0 e" by simp
wenzelm@26932
  2102
  fix y
wenzelm@61942
  2103
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Le (CN 0 c e))) = ?I x (Le (CN 0 c e))"
lp15@61694
  2104
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2105
    fix x :: int
lp15@61609
  2106
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2107
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2108
    with rcpos  have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2109
      by (simp only: mult_strict_left_mono [OF th1 rcpos])
lp15@61694
  2110
    thus "real_of_int c * real_of_int x + Inum (real_of_int x # bs) e \<le> 0"
lp15@61609
  2111
      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
chaieb@23264
  2112
  qed
chaieb@23264
  2113
  thus ?case by blast
chaieb@23264
  2114
next
lp15@61694
  2115
  case (7 c e)
lp15@61609
  2116
  then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2117
  from 7 have nbe: "numbound0 e" by simp
wenzelm@26932
  2118
  fix y
wenzelm@61942
  2119
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Gt (CN 0 c e))) = ?I x (Gt (CN 0 c e))"
lp15@61694
  2120
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2121
    fix x :: int
lp15@61609
  2122
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2123
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2124
    with rcpos  have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2125
      by (simp only: mult_strict_left_mono [OF th1 rcpos])
lp15@61694
  2126
    thus "\<not> (real_of_int c * real_of_int x + Inum (real_of_int x # bs) e>0)"
lp15@61609
  2127
      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real_of_int x"] rcpos by simp
chaieb@23264
  2128
  qed
chaieb@23264
  2129
  thus ?case by blast
chaieb@23264
  2130
next
lp15@61694
  2131
  case (8 c e)
lp15@61609
  2132
  then have "c > 0" by simp hence rcpos: "real_of_int c > 0" by simp
wenzelm@41891
  2133
  from 8 have nbe: "numbound0 e" by simp
wenzelm@26932
  2134
  fix y
wenzelm@61942
  2135
  have "\<forall> x < \<lfloor>- (Inum (y#bs) e) / (real_of_int c)\<rfloor>. ?I x (?M (Ge (CN 0 c e))) = ?I x (Ge (CN 0 c e))"
lp15@61694
  2136
  proof (simp add: less_floor_iff , rule allI, rule impI)
wenzelm@51369
  2137
    fix x :: int
lp15@61609
  2138
    assume A: "real_of_int x + 1 \<le> - (Inum (y # bs) e / real_of_int c)"
lp15@61609
  2139
    hence th1:"real_of_int x < - (Inum (y # bs) e / real_of_int c)" by simp
lp15@61609
  2140
    with rcpos  have "(real_of_int c)*(real_of_int x) < (real_of_int c)*(- (Inum (y # bs) e / real_of_int c))"
huffman@36778
  2141
      by