src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
author haftmann
Wed Sep 08 19:21:46 2010 +0200 (2010-09-08)
changeset 39246 9e58f0499f57
parent 38864 4abe644fcea5
child 41413 64cd30d6b0b8
permissions -rw-r--r--
modernized primrec
chaieb@33152
     1
(*  Title:      HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
chaieb@33152
     2
    Author:     Amine Chaieb
chaieb@33152
     3
*)
chaieb@33152
     4
chaieb@33152
     5
header{* A formalization of Ferrante and Rackoff's procedure with polynomial parameters, see Paper in CALCULEMUS 2008 *}
chaieb@33152
     6
chaieb@33152
     7
theory Parametric_Ferrante_Rackoff
wenzelm@38136
     8
imports Reflected_Multivariate_Polynomial
wenzelm@38136
     9
  Dense_Linear_Order
haftmann@35045
    10
  Efficient_Nat
chaieb@33152
    11
begin
chaieb@33152
    12
chaieb@33152
    13
subsection {* Terms *}
chaieb@33152
    14
chaieb@33152
    15
datatype tm = CP poly | Bound nat | Add tm tm | Mul poly tm 
chaieb@33152
    16
  | Neg tm | Sub tm tm | CNP nat poly tm
chaieb@33152
    17
  (* A size for poly to make inductive proofs simpler*)
chaieb@33152
    18
haftmann@39246
    19
primrec tmsize :: "tm \<Rightarrow> nat" where
chaieb@33152
    20
  "tmsize (CP c) = polysize c"
haftmann@39246
    21
| "tmsize (Bound n) = 1"
haftmann@39246
    22
| "tmsize (Neg a) = 1 + tmsize a"
haftmann@39246
    23
| "tmsize (Add a b) = 1 + tmsize a + tmsize b"
haftmann@39246
    24
| "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
haftmann@39246
    25
| "tmsize (Mul c a) = 1 + polysize c + tmsize a"
haftmann@39246
    26
| "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
chaieb@33152
    27
chaieb@33152
    28
  (* Semantics of terms tm *)
haftmann@39246
    29
primrec Itm :: "'a::{field_char_0, field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a" where
chaieb@33152
    30
  "Itm vs bs (CP c) = (Ipoly vs c)"
haftmann@39246
    31
| "Itm vs bs (Bound n) = bs!n"
haftmann@39246
    32
| "Itm vs bs (Neg a) = -(Itm vs bs a)"
haftmann@39246
    33
| "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
haftmann@39246
    34
| "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
haftmann@39246
    35
| "Itm vs bs (Mul c a) = (Ipoly vs c) * Itm vs bs a"
haftmann@39246
    36
| "Itm vs bs (CNP n c t) = (Ipoly vs c)*(bs!n) + Itm vs bs t"   
chaieb@33152
    37
chaieb@33152
    38
chaieb@33152
    39
fun allpolys:: "(poly \<Rightarrow> bool) \<Rightarrow> tm \<Rightarrow> bool"  where
chaieb@33152
    40
  "allpolys P (CP c) = P c"
chaieb@33152
    41
| "allpolys P (CNP n c p) = (P c \<and> allpolys P p)"
chaieb@33152
    42
| "allpolys P (Mul c p) = (P c \<and> allpolys P p)"
chaieb@33152
    43
| "allpolys P (Neg p) = allpolys P p"
chaieb@33152
    44
| "allpolys P (Add p q) = (allpolys P p \<and> allpolys P q)"
chaieb@33152
    45
| "allpolys P (Sub p q) = (allpolys P p \<and> allpolys P q)"
chaieb@33152
    46
| "allpolys P p = True"
chaieb@33152
    47
haftmann@39246
    48
primrec tmboundslt:: "nat \<Rightarrow> tm \<Rightarrow> bool" where
chaieb@33152
    49
  "tmboundslt n (CP c) = True"
haftmann@39246
    50
| "tmboundslt n (Bound m) = (m < n)"
haftmann@39246
    51
| "tmboundslt n (CNP m c a) = (m < n \<and> tmboundslt n a)"
haftmann@39246
    52
| "tmboundslt n (Neg a) = tmboundslt n a"
haftmann@39246
    53
| "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
haftmann@39246
    54
| "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)" 
haftmann@39246
    55
| "tmboundslt n (Mul i a) = tmboundslt n a"
haftmann@39246
    56
haftmann@39246
    57
primrec tmbound0:: "tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound 0 *) where
chaieb@33152
    58
  "tmbound0 (CP c) = True"
haftmann@39246
    59
| "tmbound0 (Bound n) = (n>0)"
haftmann@39246
    60
| "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
haftmann@39246
    61
| "tmbound0 (Neg a) = tmbound0 a"
haftmann@39246
    62
| "tmbound0 (Add a b) = (tmbound0 a \<and> tmbound0 b)"
haftmann@39246
    63
| "tmbound0 (Sub a b) = (tmbound0 a \<and> tmbound0 b)" 
haftmann@39246
    64
| "tmbound0 (Mul i a) = tmbound0 a"
chaieb@33152
    65
lemma tmbound0_I:
chaieb@33152
    66
  assumes nb: "tmbound0 a"
chaieb@33152
    67
  shows "Itm vs (b#bs) a = Itm vs (b'#bs) a"
chaieb@33152
    68
using nb
haftmann@39246
    69
by (induct a rule: tm.induct,auto simp add: nth_pos2)
chaieb@33152
    70
haftmann@39246
    71
primrec tmbound:: "nat \<Rightarrow> tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound n *) where
chaieb@33152
    72
  "tmbound n (CP c) = True"
haftmann@39246
    73
| "tmbound n (Bound m) = (n \<noteq> m)"
haftmann@39246
    74
| "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
haftmann@39246
    75
| "tmbound n (Neg a) = tmbound n a"
haftmann@39246
    76
| "tmbound n (Add a b) = (tmbound n a \<and> tmbound n b)"
haftmann@39246
    77
| "tmbound n (Sub a b) = (tmbound n a \<and> tmbound n b)" 
haftmann@39246
    78
| "tmbound n (Mul i a) = tmbound n a"
chaieb@33152
    79
lemma tmbound0_tmbound_iff: "tmbound 0 t = tmbound0 t" by (induct t, auto)
chaieb@33152
    80
chaieb@33152
    81
lemma tmbound_I: 
chaieb@33152
    82
  assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound n t" and le: "n \<le> length bs"
chaieb@33152
    83
  shows "Itm vs (bs[n:=x]) t = Itm vs bs t"
chaieb@33152
    84
  using nb le bnd
haftmann@39246
    85
  by (induct t rule: tm.induct , auto)
haftmann@39246
    86
haftmann@39246
    87
consts 
haftmann@39246
    88
  incrtm0:: "tm \<Rightarrow> tm"
haftmann@39246
    89
  decrtm0:: "tm \<Rightarrow> tm" 
chaieb@33152
    90
chaieb@33152
    91
recdef decrtm0 "measure size"
chaieb@33152
    92
  "decrtm0 (Bound n) = Bound (n - 1)"
chaieb@33152
    93
  "decrtm0 (Neg a) = Neg (decrtm0 a)"
chaieb@33152
    94
  "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)"
chaieb@33152
    95
  "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)"
chaieb@33152
    96
  "decrtm0 (Mul c a) = Mul c (decrtm0 a)"
chaieb@33152
    97
  "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)"
chaieb@33152
    98
  "decrtm0 a = a"
haftmann@39246
    99
chaieb@33152
   100
recdef incrtm0 "measure size"
chaieb@33152
   101
  "incrtm0 (Bound n) = Bound (n + 1)"
chaieb@33152
   102
  "incrtm0 (Neg a) = Neg (incrtm0 a)"
chaieb@33152
   103
  "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)"
chaieb@33152
   104
  "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)"
chaieb@33152
   105
  "incrtm0 (Mul c a) = Mul c (incrtm0 a)"
chaieb@33152
   106
  "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)"
chaieb@33152
   107
  "incrtm0 a = a"
haftmann@39246
   108
chaieb@33152
   109
lemma decrtm0: assumes nb: "tmbound0 t"
chaieb@33152
   110
  shows "Itm vs (x#bs) t = Itm vs bs (decrtm0 t)"
chaieb@33152
   111
  using nb by (induct t rule: decrtm0.induct, simp_all add: nth_pos2)
haftmann@39246
   112
chaieb@33152
   113
lemma incrtm0: "Itm vs (x#bs) (incrtm0 t) = Itm vs bs t"
chaieb@33152
   114
  by (induct t rule: decrtm0.induct, simp_all add: nth_pos2)
chaieb@33152
   115
haftmann@39246
   116
primrec decrtm:: "nat \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   117
  "decrtm m (CP c) = (CP c)"
haftmann@39246
   118
| "decrtm m (Bound n) = (if n < m then Bound n else Bound (n - 1))"
haftmann@39246
   119
| "decrtm m (Neg a) = Neg (decrtm m a)"
haftmann@39246
   120
| "decrtm m (Add a b) = Add (decrtm m a) (decrtm m b)"
haftmann@39246
   121
| "decrtm m (Sub a b) = Sub (decrtm m a) (decrtm m b)"
haftmann@39246
   122
| "decrtm m (Mul c a) = Mul c (decrtm m a)"
haftmann@39246
   123
| "decrtm m (CNP n c a) = (if n < m then CNP n c (decrtm m a) else CNP (n - 1) c (decrtm m a))"
chaieb@33152
   124
haftmann@39246
   125
primrec removen:: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list" where
chaieb@33152
   126
  "removen n [] = []"
haftmann@39246
   127
| "removen n (x#xs) = (if n=0 then xs else (x#(removen (n - 1) xs)))"
chaieb@33152
   128
chaieb@33152
   129
lemma removen_same: "n \<ge> length xs \<Longrightarrow> removen n xs = xs"
chaieb@33152
   130
  by (induct xs arbitrary: n, auto)
chaieb@33152
   131
chaieb@33152
   132
lemma nth_length_exceeds: "n \<ge> length xs \<Longrightarrow> xs!n = []!(n - length xs)"
chaieb@33152
   133
  by (induct xs arbitrary: n, auto)
chaieb@33152
   134
chaieb@33152
   135
lemma removen_length: "length (removen n xs) = (if n \<ge> length xs then length xs else length xs - 1)"
chaieb@33152
   136
  by (induct xs arbitrary: n, auto)
chaieb@33152
   137
lemma removen_nth: "(removen n xs)!m = (if n \<ge> length xs then xs!m 
chaieb@33152
   138
  else if m < n then xs!m else if m \<le> length xs then xs!(Suc m) else []!(m - (length xs - 1)))"
chaieb@33152
   139
proof(induct xs arbitrary: n m)
chaieb@33152
   140
  case Nil thus ?case by simp
chaieb@33152
   141
next
chaieb@33152
   142
  case (Cons x xs n m)
chaieb@33152
   143
  {assume nxs: "n \<ge> length (x#xs)" hence ?case using removen_same[OF nxs] by simp}
chaieb@33152
   144
  moreover
chaieb@33152
   145
  {assume nxs: "\<not> (n \<ge> length (x#xs))" 
chaieb@33152
   146
    {assume mln: "m < n" hence ?case using prems by (cases m, auto)}
chaieb@33152
   147
    moreover
chaieb@33152
   148
    {assume mln: "\<not> (m < n)" 
chaieb@33152
   149
      
chaieb@33152
   150
      {assume mxs: "m \<le> length (x#xs)" hence ?case using prems by (cases m, auto)}
chaieb@33152
   151
      moreover
chaieb@33152
   152
      {assume mxs: "\<not> (m \<le> length (x#xs))" 
wenzelm@33268
   153
        have th: "length (removen n (x#xs)) = length xs" 
wenzelm@33268
   154
          using removen_length[where n="n" and xs="x#xs"] nxs by simp
wenzelm@33268
   155
        with mxs have mxs':"m \<ge> length (removen n (x#xs))" by auto
wenzelm@33268
   156
        hence "(removen n (x#xs))!m = [] ! (m - length xs)" 
wenzelm@33268
   157
          using th nth_length_exceeds[OF mxs'] by auto
wenzelm@33268
   158
        hence th: "(removen n (x#xs))!m = [] ! (m - (length (x#xs) - 1))" 
wenzelm@33268
   159
          by auto
wenzelm@33268
   160
        hence ?case using nxs mln mxs by auto }
chaieb@33152
   161
      ultimately have ?case by blast
chaieb@33152
   162
    }
chaieb@33152
   163
    ultimately have ?case by blast
chaieb@33152
   164
    
chaieb@33152
   165
  }      ultimately show ?case by blast
chaieb@33152
   166
qed
chaieb@33152
   167
chaieb@33152
   168
lemma decrtm: assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound m t" 
chaieb@33152
   169
  and nle: "m \<le> length bs" 
chaieb@33152
   170
  shows "Itm vs (removen m bs) (decrtm m t) = Itm vs bs t"
chaieb@33152
   171
  using bnd nb nle
haftmann@39246
   172
  by (induct t rule: tm.induct, auto simp add: removen_nth)
chaieb@33152
   173
haftmann@39246
   174
primrec tmsubst0:: "tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   175
  "tmsubst0 t (CP c) = CP c"
haftmann@39246
   176
| "tmsubst0 t (Bound n) = (if n=0 then t else Bound n)"
haftmann@39246
   177
| "tmsubst0 t (CNP n c a) = (if n=0 then Add (Mul c t) (tmsubst0 t a) else CNP n c (tmsubst0 t a))"
haftmann@39246
   178
| "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
haftmann@39246
   179
| "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
haftmann@39246
   180
| "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)" 
haftmann@39246
   181
| "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
chaieb@33152
   182
lemma tmsubst0:
chaieb@33152
   183
  shows "Itm vs (x#bs) (tmsubst0 t a) = Itm vs ((Itm vs (x#bs) t)#bs) a"
haftmann@39246
   184
by (induct a rule: tm.induct,auto simp add: nth_pos2)
chaieb@33152
   185
chaieb@33152
   186
lemma tmsubst0_nb: "tmbound0 t \<Longrightarrow> tmbound0 (tmsubst0 t a)"
haftmann@39246
   187
by (induct a rule: tm.induct,auto simp add: nth_pos2)
chaieb@33152
   188
haftmann@39246
   189
primrec tmsubst:: "nat \<Rightarrow> tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   190
  "tmsubst n t (CP c) = CP c"
haftmann@39246
   191
| "tmsubst n t (Bound m) = (if n=m then t else Bound m)"
haftmann@39246
   192
| "tmsubst n t (CNP m c a) = (if n=m then Add (Mul c t) (tmsubst n t a) 
chaieb@33152
   193
             else CNP m c (tmsubst n t a))"
haftmann@39246
   194
| "tmsubst n t (Neg a) = Neg (tmsubst n t a)"
haftmann@39246
   195
| "tmsubst n t (Add a b) = Add (tmsubst n t a) (tmsubst n t b)"
haftmann@39246
   196
| "tmsubst n t (Sub a b) = Sub (tmsubst n t a) (tmsubst n t b)" 
haftmann@39246
   197
| "tmsubst n t (Mul i a) = Mul i (tmsubst n t a)"
chaieb@33152
   198
chaieb@33152
   199
lemma tmsubst: assumes nb: "tmboundslt (length bs) a" and nlt: "n \<le> length bs"
chaieb@33152
   200
  shows "Itm vs bs (tmsubst n t a) = Itm vs (bs[n:= Itm vs bs t]) a"
chaieb@33152
   201
using nb nlt
haftmann@39246
   202
by (induct a rule: tm.induct,auto simp add: nth_pos2)
chaieb@33152
   203
chaieb@33152
   204
lemma tmsubst_nb0: assumes tnb: "tmbound0 t"
chaieb@33152
   205
shows "tmbound0 (tmsubst 0 t a)"
chaieb@33152
   206
using tnb
haftmann@39246
   207
by (induct a rule: tm.induct, auto)
chaieb@33152
   208
chaieb@33152
   209
lemma tmsubst_nb: assumes tnb: "tmbound m t"
chaieb@33152
   210
shows "tmbound m (tmsubst m t a)"
chaieb@33152
   211
using tnb
haftmann@39246
   212
by (induct a rule: tm.induct, auto)
chaieb@33152
   213
lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)"
chaieb@33152
   214
  by (induct t, auto)
chaieb@33152
   215
  (* Simplification *)
chaieb@33152
   216
chaieb@33152
   217
consts
chaieb@33152
   218
  simptm:: "tm \<Rightarrow> tm"
chaieb@33152
   219
  tmadd:: "tm \<times> tm \<Rightarrow> tm"
chaieb@33152
   220
  tmmul:: "tm \<Rightarrow> poly \<Rightarrow> tm"
chaieb@33152
   221
recdef tmadd "measure (\<lambda> (t,s). size t + size s)"
chaieb@33152
   222
  "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) =
chaieb@33152
   223
  (if n1=n2 then 
chaieb@33152
   224
  (let c = c1 +\<^sub>p c2
chaieb@33152
   225
  in if c = 0\<^sub>p then tmadd(r1,r2) else CNP n1 c (tmadd (r1,r2)))
chaieb@33152
   226
  else if n1 \<le> n2 then (CNP n1 c1 (tmadd (r1,CNP n2 c2 r2))) 
chaieb@33152
   227
  else (CNP n2 c2 (tmadd (CNP n1 c1 r1,r2))))"
chaieb@33152
   228
  "tmadd (CNP n1 c1 r1,t) = CNP n1 c1 (tmadd (r1, t))"  
chaieb@33152
   229
  "tmadd (t,CNP n2 c2 r2) = CNP n2 c2 (tmadd (t,r2))" 
chaieb@33152
   230
  "tmadd (CP b1, CP b2) = CP (b1 +\<^sub>p b2)"
chaieb@33152
   231
  "tmadd (a,b) = Add a b"
chaieb@33152
   232
chaieb@33152
   233
lemma tmadd[simp]: "Itm vs bs (tmadd (t,s)) = Itm vs bs (Add t s)"
chaieb@33152
   234
apply (induct t s rule: tmadd.induct, simp_all add: Let_def)
chaieb@33152
   235
apply (case_tac "c1 +\<^sub>p c2 = 0\<^sub>p",case_tac "n1 \<le> n2", simp_all)
haftmann@36348
   236
apply (case_tac "n1 = n2", simp_all add: field_simps)
chaieb@33152
   237
apply (simp only: right_distrib[symmetric]) 
chaieb@33152
   238
by (auto simp del: polyadd simp add: polyadd[symmetric])
chaieb@33152
   239
chaieb@33152
   240
lemma tmadd_nb0[simp]: "\<lbrakk> tmbound0 t ; tmbound0 s\<rbrakk> \<Longrightarrow> tmbound0 (tmadd (t,s))"
chaieb@33152
   241
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   242
chaieb@33152
   243
lemma tmadd_nb[simp]: "\<lbrakk> tmbound n t ; tmbound n s\<rbrakk> \<Longrightarrow> tmbound n (tmadd (t,s))"
chaieb@33152
   244
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   245
lemma tmadd_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmadd (t,s))"
chaieb@33152
   246
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   247
chaieb@33152
   248
lemma tmadd_allpolys_npoly[simp]: "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmadd(t,s))" by (induct t s rule: tmadd.induct, simp_all add: Let_def polyadd_norm)
chaieb@33152
   249
chaieb@33152
   250
recdef tmmul "measure size"
chaieb@33152
   251
  "tmmul (CP j) = (\<lambda> i. CP (i *\<^sub>p j))"
chaieb@33152
   252
  "tmmul (CNP n c a) = (\<lambda> i. CNP n (i *\<^sub>p c) (tmmul a i))"
chaieb@33152
   253
  "tmmul t = (\<lambda> i. Mul i t)"
chaieb@33152
   254
chaieb@33152
   255
lemma tmmul[simp]: "Itm vs bs (tmmul t i) = Itm vs bs (Mul i t)"
haftmann@36348
   256
by (induct t arbitrary: i rule: tmmul.induct, simp_all add: field_simps)
chaieb@33152
   257
chaieb@33152
   258
lemma tmmul_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmmul t i)"
chaieb@33152
   259
by (induct t arbitrary: i rule: tmmul.induct, auto )
chaieb@33152
   260
chaieb@33152
   261
lemma tmmul_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (tmmul t i)"
chaieb@33152
   262
by (induct t arbitrary: n rule: tmmul.induct, auto )
chaieb@33152
   263
lemma tmmul_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmmul t i)"
chaieb@33152
   264
by (induct t arbitrary: i rule: tmmul.induct, auto simp add: Let_def)
chaieb@33152
   265
chaieb@33152
   266
lemma tmmul_allpolys_npoly[simp]: 
haftmann@36409
   267
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   268
  shows "allpolys isnpoly t \<Longrightarrow> isnpoly c \<Longrightarrow> allpolys isnpoly (tmmul t c)" by (induct t rule: tmmul.induct, simp_all add: Let_def polymul_norm)
chaieb@33152
   269
haftmann@35416
   270
definition tmneg :: "tm \<Rightarrow> tm" where
chaieb@33152
   271
  "tmneg t \<equiv> tmmul t (C (- 1,1))"
chaieb@33152
   272
haftmann@35416
   273
definition tmsub :: "tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   274
  "tmsub s t \<equiv> (if s = t then CP 0\<^sub>p else tmadd (s,tmneg t))"
chaieb@33152
   275
chaieb@33152
   276
lemma tmneg[simp]: "Itm vs bs (tmneg t) = Itm vs bs (Neg t)"
chaieb@33152
   277
using tmneg_def[of t] 
chaieb@33152
   278
apply simp
chaieb@33152
   279
apply (subst number_of_Min)
chaieb@33152
   280
apply (simp only: of_int_minus)
chaieb@33152
   281
apply simp
chaieb@33152
   282
done
chaieb@33152
   283
chaieb@33152
   284
lemma tmneg_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmneg t)"
chaieb@33152
   285
using tmneg_def by simp
chaieb@33152
   286
chaieb@33152
   287
lemma tmneg_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (tmneg t)"
chaieb@33152
   288
using tmneg_def by simp
chaieb@33152
   289
lemma tmneg_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmneg t)"
chaieb@33152
   290
using tmneg_def by simp
chaieb@33152
   291
lemma [simp]: "isnpoly (C (-1,1))" unfolding isnpoly_def by simp
chaieb@33152
   292
lemma tmneg_allpolys_npoly[simp]: 
haftmann@36409
   293
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   294
  shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly (tmneg t)" 
chaieb@33152
   295
  unfolding tmneg_def by auto
chaieb@33152
   296
chaieb@33152
   297
lemma tmsub[simp]: "Itm vs bs (tmsub a b) = Itm vs bs (Sub a b)"
chaieb@33152
   298
using tmsub_def by simp
chaieb@33152
   299
chaieb@33152
   300
lemma tmsub_nb0[simp]: "\<lbrakk> tmbound0 t ; tmbound0 s\<rbrakk> \<Longrightarrow> tmbound0 (tmsub t s)"
chaieb@33152
   301
using tmsub_def by simp
chaieb@33152
   302
lemma tmsub_nb[simp]: "\<lbrakk> tmbound n t ; tmbound n s\<rbrakk> \<Longrightarrow> tmbound n (tmsub t s)"
chaieb@33152
   303
using tmsub_def by simp
chaieb@33152
   304
lemma tmsub_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmsub t s )"
chaieb@33152
   305
using tmsub_def by simp
chaieb@33152
   306
lemma tmsub_allpolys_npoly[simp]: 
haftmann@36409
   307
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   308
  shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)" 
chaieb@33152
   309
  unfolding tmsub_def by (simp add: isnpoly_def)
chaieb@33152
   310
chaieb@33152
   311
recdef simptm "measure size"
chaieb@33152
   312
  "simptm (CP j) = CP (polynate j)"
chaieb@33152
   313
  "simptm (Bound n) = CNP n 1\<^sub>p (CP 0\<^sub>p)"
chaieb@33152
   314
  "simptm (Neg t) = tmneg (simptm t)"
chaieb@33152
   315
  "simptm (Add t s) = tmadd (simptm t,simptm s)"
chaieb@33152
   316
  "simptm (Sub t s) = tmsub (simptm t) (simptm s)"
chaieb@33152
   317
  "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
chaieb@33152
   318
  "simptm (CNP n c t) = (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))"
chaieb@33152
   319
chaieb@33152
   320
lemma polynate_stupid: 
haftmann@36409
   321
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
haftmann@36409
   322
  shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a::{field_char_0, field_inverse_zero})" 
chaieb@33152
   323
apply (subst polynate[symmetric])
chaieb@33152
   324
apply simp
chaieb@33152
   325
done
chaieb@33152
   326
chaieb@33152
   327
lemma simptm_ci[simp]: "Itm vs bs (simptm t) = Itm vs bs t"
chaieb@33152
   328
by (induct t rule: simptm.induct, auto simp add: tmneg tmadd tmsub tmmul Let_def polynate_stupid) 
chaieb@33152
   329
chaieb@33152
   330
lemma simptm_tmbound0[simp]: 
chaieb@33152
   331
  "tmbound0 t \<Longrightarrow> tmbound0 (simptm t)"
chaieb@33152
   332
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   333
chaieb@33152
   334
lemma simptm_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (simptm t)"
chaieb@33152
   335
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   336
lemma simptm_nlt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (simptm t)"
chaieb@33152
   337
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   338
chaieb@33152
   339
lemma [simp]: "isnpoly 0\<^sub>p" and [simp]: "isnpoly (C(1,1))" 
chaieb@33152
   340
  by (simp_all add: isnpoly_def)
chaieb@33152
   341
lemma simptm_allpolys_npoly[simp]: 
haftmann@36409
   342
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   343
  shows "allpolys isnpoly (simptm p)"
chaieb@33152
   344
  by (induct p rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   345
chaieb@33152
   346
consts split0 :: "tm \<Rightarrow> (poly \<times> tm)"
chaieb@33152
   347
recdef split0 "measure tmsize"
chaieb@33152
   348
  "split0 (Bound 0) = (1\<^sub>p, CP 0\<^sub>p)"
chaieb@33152
   349
  "split0 (CNP 0 c t) = (let (c',t') = split0 t in (c +\<^sub>p c',t'))"
chaieb@33152
   350
  "split0 (Neg t) = (let (c,t') = split0 t in (~\<^sub>p c,Neg t'))"
chaieb@33152
   351
  "split0 (CNP n c t) = (let (c',t') = split0 t in (c',CNP n c t'))"
chaieb@33152
   352
  "split0 (Add s t) = (let (c1,s') = split0 s ; (c2,t') = split0 t in (c1 +\<^sub>p c2, Add s' t'))"
chaieb@33152
   353
  "split0 (Sub s t) = (let (c1,s') = split0 s ; (c2,t') = split0 t in (c1 -\<^sub>p c2, Sub s' t'))"
chaieb@33152
   354
  "split0 (Mul c t) = (let (c',t') = split0 t in (c *\<^sub>p c', Mul c t'))"
chaieb@33152
   355
  "split0 t = (0\<^sub>p, t)"
chaieb@33152
   356
chaieb@33152
   357
lemma split0_stupid[simp]: "\<exists>x y. (x,y) = split0 p"
chaieb@33152
   358
  apply (rule exI[where x="fst (split0 p)"])
chaieb@33152
   359
  apply (rule exI[where x="snd (split0 p)"])
chaieb@33152
   360
  by simp
chaieb@33152
   361
chaieb@33152
   362
lemma split0:
chaieb@33152
   363
  "tmbound 0 (snd (split0 t)) \<and> (Itm vs bs (CNP 0 (fst (split0 t)) (snd (split0 t))) = Itm vs bs t)"
chaieb@33152
   364
  apply (induct t rule: split0.induct)
chaieb@33152
   365
  apply simp
haftmann@36348
   366
  apply (simp add: Let_def split_def field_simps)
haftmann@36348
   367
  apply (simp add: Let_def split_def field_simps)
haftmann@36348
   368
  apply (simp add: Let_def split_def field_simps)
haftmann@36348
   369
  apply (simp add: Let_def split_def field_simps)
haftmann@36348
   370
  apply (simp add: Let_def split_def field_simps)
chaieb@33152
   371
  apply (simp add: Let_def split_def mult_assoc right_distrib[symmetric])
haftmann@36348
   372
  apply (simp add: Let_def split_def field_simps)
haftmann@36348
   373
  apply (simp add: Let_def split_def field_simps)
chaieb@33152
   374
  done
chaieb@33152
   375
chaieb@33152
   376
lemma split0_ci: "split0 t = (c',t') \<Longrightarrow> Itm vs bs t = Itm vs bs (CNP 0 c' t')"
chaieb@33152
   377
proof-
chaieb@33152
   378
  fix c' t'
chaieb@33152
   379
  assume "split0 t = (c', t')" hence "c' = fst (split0 t)" and "t' = snd (split0 t)" by auto
chaieb@33152
   380
  with split0[where t="t" and bs="bs"] show "Itm vs bs t = Itm vs bs (CNP 0 c' t')" by simp
chaieb@33152
   381
qed
chaieb@33152
   382
chaieb@33152
   383
lemma split0_nb0: 
haftmann@36409
   384
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   385
  shows "split0 t = (c',t') \<Longrightarrow>  tmbound 0 t'"
chaieb@33152
   386
proof-
chaieb@33152
   387
  fix c' t'
chaieb@33152
   388
  assume "split0 t = (c', t')" hence "c' = fst (split0 t)" and "t' = snd (split0 t)" by auto
chaieb@33152
   389
  with conjunct1[OF split0[where t="t"]] show "tmbound 0 t'" by simp
chaieb@33152
   390
qed
chaieb@33152
   391
haftmann@36409
   392
lemma split0_nb0'[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   393
  shows "tmbound0 (snd (split0 t))"
chaieb@33152
   394
  using split0_nb0[of t "fst (split0 t)" "snd (split0 t)"] by (simp add: tmbound0_tmbound_iff)
chaieb@33152
   395
chaieb@33152
   396
chaieb@33152
   397
lemma split0_nb: assumes nb:"tmbound n t" shows "tmbound n (snd (split0 t))"
chaieb@33152
   398
  using nb by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   399
chaieb@33152
   400
lemma split0_blt: assumes nb:"tmboundslt n t" shows "tmboundslt n (snd (split0 t))"
chaieb@33152
   401
  using nb by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   402
chaieb@33152
   403
lemma tmbound_split0: "tmbound 0 t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0"
chaieb@33152
   404
 by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   405
chaieb@33152
   406
lemma tmboundslt_split0: "tmboundslt n t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0 \<or> n > 0"
chaieb@33152
   407
by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   408
chaieb@33152
   409
lemma tmboundslt0_split0: "tmboundslt 0 t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0"
chaieb@33152
   410
 by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   411
chaieb@33152
   412
lemma allpolys_split0: "allpolys isnpoly p \<Longrightarrow> allpolys isnpoly (snd (split0 p))"
chaieb@33152
   413
by (induct p rule: split0.induct, auto simp  add: isnpoly_def Let_def split_def split0_stupid)
chaieb@33152
   414
haftmann@36409
   415
lemma isnpoly_fst_split0:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   416
  shows 
chaieb@33152
   417
  "allpolys isnpoly p \<Longrightarrow> isnpoly (fst (split0 p))"
chaieb@33152
   418
  by (induct p rule: split0.induct, 
chaieb@33152
   419
    auto simp  add: polyadd_norm polysub_norm polyneg_norm polymul_norm 
chaieb@33152
   420
    Let_def split_def split0_stupid)
chaieb@33152
   421
chaieb@33152
   422
subsection{* Formulae *}
chaieb@33152
   423
chaieb@33152
   424
datatype fm  =  T| F| Le tm | Lt tm | Eq tm | NEq tm|
chaieb@33152
   425
  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
chaieb@33152
   426
chaieb@33152
   427
chaieb@33152
   428
  (* A size for fm *)
chaieb@33152
   429
consts fmsize :: "fm \<Rightarrow> nat"
chaieb@33152
   430
recdef fmsize "measure size"
chaieb@33152
   431
  "fmsize (NOT p) = 1 + fmsize p"
chaieb@33152
   432
  "fmsize (And p q) = 1 + fmsize p + fmsize q"
chaieb@33152
   433
  "fmsize (Or p q) = 1 + fmsize p + fmsize q"
chaieb@33152
   434
  "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
chaieb@33152
   435
  "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
chaieb@33152
   436
  "fmsize (E p) = 1 + fmsize p"
chaieb@33152
   437
  "fmsize (A p) = 4+ fmsize p"
chaieb@33152
   438
  "fmsize p = 1"
chaieb@33152
   439
  (* several lemmas about fmsize *)
wenzelm@33268
   440
lemma fmsize_pos: "fmsize p > 0"        
chaieb@33152
   441
by (induct p rule: fmsize.induct) simp_all
chaieb@33152
   442
chaieb@33152
   443
  (* Semantics of formulae (fm) *)
haftmann@39246
   444
primrec Ifm ::"'a::{linordered_field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool" where
chaieb@33152
   445
  "Ifm vs bs T = True"
haftmann@39246
   446
| "Ifm vs bs F = False"
haftmann@39246
   447
| "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
haftmann@39246
   448
| "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
haftmann@39246
   449
| "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
haftmann@39246
   450
| "Ifm vs bs (NEq a) = (Itm vs bs a \<noteq> 0)"
haftmann@39246
   451
| "Ifm vs bs (NOT p) = (\<not> (Ifm vs bs p))"
haftmann@39246
   452
| "Ifm vs bs (And p q) = (Ifm vs bs p \<and> Ifm vs bs q)"
haftmann@39246
   453
| "Ifm vs bs (Or p q) = (Ifm vs bs p \<or> Ifm vs bs q)"
haftmann@39246
   454
| "Ifm vs bs (Imp p q) = ((Ifm vs bs p) \<longrightarrow> (Ifm vs bs q))"
haftmann@39246
   455
| "Ifm vs bs (Iff p q) = (Ifm vs bs p = Ifm vs bs q)"
haftmann@39246
   456
| "Ifm vs bs (E p) = (\<exists> x. Ifm vs (x#bs) p)"
haftmann@39246
   457
| "Ifm vs bs (A p) = (\<forall> x. Ifm vs (x#bs) p)"
chaieb@33152
   458
chaieb@33152
   459
consts not:: "fm \<Rightarrow> fm"
chaieb@33152
   460
recdef not "measure size"
chaieb@33152
   461
  "not (NOT (NOT p)) = not p"
chaieb@33152
   462
  "not (NOT p) = p"
chaieb@33152
   463
  "not T = F"
chaieb@33152
   464
  "not F = T"
chaieb@33152
   465
  "not (Lt t) = Le (tmneg t)"
chaieb@33152
   466
  "not (Le t) = Lt (tmneg t)"
chaieb@33152
   467
  "not (Eq t) = NEq t"
chaieb@33152
   468
  "not (NEq t) = Eq t"
chaieb@33152
   469
  "not p = NOT p"
chaieb@33152
   470
lemma not[simp]: "Ifm vs bs (not p) = Ifm vs bs (NOT p)"
chaieb@33152
   471
by (induct p rule: not.induct) auto
chaieb@33152
   472
haftmann@35416
   473
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   474
  "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@33152
   475
   if p = q then p else And p q)"
chaieb@33152
   476
lemma conj[simp]: "Ifm vs bs (conj p q) = Ifm vs bs (And p q)"
chaieb@33152
   477
by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
chaieb@33152
   478
haftmann@35416
   479
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   480
  "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@33152
   481
       else if p=q then p else Or p q)"
chaieb@33152
   482
chaieb@33152
   483
lemma disj[simp]: "Ifm vs bs (disj p q) = Ifm vs bs (Or p q)"
chaieb@33152
   484
by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
chaieb@33152
   485
haftmann@35416
   486
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   487
  "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@33152
   488
    else Imp p q)"
chaieb@33152
   489
lemma imp[simp]: "Ifm vs bs (imp p q) = Ifm vs bs (Imp p q)"
chaieb@33152
   490
by (cases "p=F \<or> q=T",simp_all add: imp_def) 
chaieb@33152
   491
haftmann@35416
   492
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   493
  "iff p q \<equiv> (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else 
chaieb@33152
   494
       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@33152
   495
  Iff p q)"
chaieb@33152
   496
lemma iff[simp]: "Ifm vs bs (iff p q) = Ifm vs bs (Iff p q)"
chaieb@33152
   497
  by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto)
chaieb@33152
   498
  (* Quantifier freeness *)
chaieb@33152
   499
consts qfree:: "fm \<Rightarrow> bool"
chaieb@33152
   500
recdef qfree "measure size"
chaieb@33152
   501
  "qfree (E p) = False"
chaieb@33152
   502
  "qfree (A p) = False"
chaieb@33152
   503
  "qfree (NOT p) = qfree p" 
chaieb@33152
   504
  "qfree (And p q) = (qfree p \<and> qfree q)" 
chaieb@33152
   505
  "qfree (Or  p q) = (qfree p \<and> qfree q)" 
chaieb@33152
   506
  "qfree (Imp p q) = (qfree p \<and> qfree q)" 
chaieb@33152
   507
  "qfree (Iff p q) = (qfree p \<and> qfree q)"
chaieb@33152
   508
  "qfree p = True"
chaieb@33152
   509
chaieb@33152
   510
  (* Boundedness and substitution *)
chaieb@33152
   511
haftmann@39246
   512
primrec boundslt :: "nat \<Rightarrow> fm \<Rightarrow> bool" where
chaieb@33152
   513
  "boundslt n T = True"
haftmann@39246
   514
| "boundslt n F = True"
haftmann@39246
   515
| "boundslt n (Lt t) = (tmboundslt n t)"
haftmann@39246
   516
| "boundslt n (Le t) = (tmboundslt n t)"
haftmann@39246
   517
| "boundslt n (Eq t) = (tmboundslt n t)"
haftmann@39246
   518
| "boundslt n (NEq t) = (tmboundslt n t)"
haftmann@39246
   519
| "boundslt n (NOT p) = boundslt n p"
haftmann@39246
   520
| "boundslt n (And p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39246
   521
| "boundslt n (Or p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39246
   522
| "boundslt n (Imp p q) = ((boundslt n p) \<and> (boundslt n q))"
haftmann@39246
   523
| "boundslt n (Iff p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39246
   524
| "boundslt n (E p) = boundslt (Suc n) p"
haftmann@39246
   525
| "boundslt n (A p) = boundslt (Suc n) p"
chaieb@33152
   526
chaieb@33152
   527
consts 
chaieb@33152
   528
  bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *)
chaieb@33152
   529
  decr0 :: "fm \<Rightarrow> fm"
chaieb@33152
   530
recdef bound0 "measure size"
chaieb@33152
   531
  "bound0 T = True"
chaieb@33152
   532
  "bound0 F = True"
chaieb@33152
   533
  "bound0 (Lt a) = tmbound0 a"
chaieb@33152
   534
  "bound0 (Le a) = tmbound0 a"
chaieb@33152
   535
  "bound0 (Eq a) = tmbound0 a"
chaieb@33152
   536
  "bound0 (NEq a) = tmbound0 a"
chaieb@33152
   537
  "bound0 (NOT p) = bound0 p"
chaieb@33152
   538
  "bound0 (And p q) = (bound0 p \<and> bound0 q)"
chaieb@33152
   539
  "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
chaieb@33152
   540
  "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
chaieb@33152
   541
  "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
chaieb@33152
   542
  "bound0 p = False"
chaieb@33152
   543
lemma bound0_I:
chaieb@33152
   544
  assumes bp: "bound0 p"
chaieb@33152
   545
  shows "Ifm vs (b#bs) p = Ifm vs (b'#bs) p"
chaieb@33152
   546
using bp tmbound0_I[where b="b" and bs="bs" and b'="b'"]
chaieb@33152
   547
by (induct p rule: bound0.induct,auto simp add: nth_pos2)
chaieb@33152
   548
haftmann@39246
   549
primrec bound:: "nat \<Rightarrow> fm \<Rightarrow> bool" (* A Formula is independent of Bound n *) where
chaieb@33152
   550
  "bound m T = True"
haftmann@39246
   551
| "bound m F = True"
haftmann@39246
   552
| "bound m (Lt t) = tmbound m t"
haftmann@39246
   553
| "bound m (Le t) = tmbound m t"
haftmann@39246
   554
| "bound m (Eq t) = tmbound m t"
haftmann@39246
   555
| "bound m (NEq t) = tmbound m t"
haftmann@39246
   556
| "bound m (NOT p) = bound m p"
haftmann@39246
   557
| "bound m (And p q) = (bound m p \<and> bound m q)"
haftmann@39246
   558
| "bound m (Or p q) = (bound m p \<and> bound m q)"
haftmann@39246
   559
| "bound m (Imp p q) = ((bound m p) \<and> (bound m q))"
haftmann@39246
   560
| "bound m (Iff p q) = (bound m p \<and> bound m q)"
haftmann@39246
   561
| "bound m (E p) = bound (Suc m) p"
haftmann@39246
   562
| "bound m (A p) = bound (Suc m) p"
chaieb@33152
   563
chaieb@33152
   564
lemma bound_I:
chaieb@33152
   565
  assumes bnd: "boundslt (length bs) p" and nb: "bound n p" and le: "n \<le> length bs"
chaieb@33152
   566
  shows "Ifm vs (bs[n:=x]) p = Ifm vs bs p"
chaieb@33152
   567
  using bnd nb le tmbound_I[where bs=bs and vs = vs]
haftmann@39246
   568
proof(induct p arbitrary: bs n rule: fm.induct)
chaieb@33152
   569
  case (E p bs n) 
chaieb@33152
   570
  {fix y
chaieb@33152
   571
    from prems have bnd: "boundslt (length (y#bs)) p" 
chaieb@33152
   572
      and nb: "bound (Suc n) p" and le: "Suc n \<le> length (y#bs)" by simp+
chaieb@33152
   573
    from E.hyps[OF bnd nb le tmbound_I] have "Ifm vs ((y#bs)[Suc n:=x]) p = Ifm vs (y#bs) p" .   }
chaieb@33152
   574
  thus ?case by simp 
chaieb@33152
   575
next
chaieb@33152
   576
  case (A p bs n) {fix y
chaieb@33152
   577
    from prems have bnd: "boundslt (length (y#bs)) p" 
chaieb@33152
   578
      and nb: "bound (Suc n) p" and le: "Suc n \<le> length (y#bs)" by simp+
chaieb@33152
   579
    from A.hyps[OF bnd nb le tmbound_I] have "Ifm vs ((y#bs)[Suc n:=x]) p = Ifm vs (y#bs) p" .   }
chaieb@33152
   580
  thus ?case by simp 
chaieb@33152
   581
qed auto
chaieb@33152
   582
chaieb@33152
   583
recdef decr0 "measure size"
chaieb@33152
   584
  "decr0 (Lt a) = Lt (decrtm0 a)"
chaieb@33152
   585
  "decr0 (Le a) = Le (decrtm0 a)"
chaieb@33152
   586
  "decr0 (Eq a) = Eq (decrtm0 a)"
chaieb@33152
   587
  "decr0 (NEq a) = NEq (decrtm0 a)"
chaieb@33152
   588
  "decr0 (NOT p) = NOT (decr0 p)" 
chaieb@33152
   589
  "decr0 (And p q) = conj (decr0 p) (decr0 q)"
chaieb@33152
   590
  "decr0 (Or p q) = disj (decr0 p) (decr0 q)"
chaieb@33152
   591
  "decr0 (Imp p q) = imp (decr0 p) (decr0 q)"
chaieb@33152
   592
  "decr0 (Iff p q) = iff (decr0 p) (decr0 q)"
chaieb@33152
   593
  "decr0 p = p"
chaieb@33152
   594
chaieb@33152
   595
lemma decr0: assumes nb: "bound0 p"
chaieb@33152
   596
  shows "Ifm vs (x#bs) p = Ifm vs bs (decr0 p)"
chaieb@33152
   597
  using nb 
chaieb@33152
   598
  by (induct p rule: decr0.induct, simp_all add: decrtm0)
chaieb@33152
   599
haftmann@39246
   600
primrec decr :: "nat \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   601
  "decr m T = T"
haftmann@39246
   602
| "decr m F = F"
haftmann@39246
   603
| "decr m (Lt t) = (Lt (decrtm m t))"
haftmann@39246
   604
| "decr m (Le t) = (Le (decrtm m t))"
haftmann@39246
   605
| "decr m (Eq t) = (Eq (decrtm m t))"
haftmann@39246
   606
| "decr m (NEq t) = (NEq (decrtm m t))"
haftmann@39246
   607
| "decr m (NOT p) = NOT (decr m p)" 
haftmann@39246
   608
| "decr m (And p q) = conj (decr m p) (decr m q)"
haftmann@39246
   609
| "decr m (Or p q) = disj (decr m p) (decr m q)"
haftmann@39246
   610
| "decr m (Imp p q) = imp (decr m p) (decr m q)"
haftmann@39246
   611
| "decr m (Iff p q) = iff (decr m p) (decr m q)"
haftmann@39246
   612
| "decr m (E p) = E (decr (Suc m) p)"
haftmann@39246
   613
| "decr m (A p) = A (decr (Suc m) p)"
chaieb@33152
   614
chaieb@33152
   615
lemma decr: assumes  bnd: "boundslt (length bs) p" and nb: "bound m p" 
chaieb@33152
   616
  and nle: "m < length bs" 
chaieb@33152
   617
  shows "Ifm vs (removen m bs) (decr m p) = Ifm vs bs p"
chaieb@33152
   618
  using bnd nb nle
haftmann@39246
   619
proof(induct p arbitrary: bs m rule: fm.induct)
chaieb@33152
   620
  case (E p bs m) 
chaieb@33152
   621
  {fix x
chaieb@33152
   622
    from prems have bnd: "boundslt (length (x#bs)) p" and nb: "bound (Suc m) p" 
chaieb@33152
   623
  and nle: "Suc m < length (x#bs)" by auto
chaieb@33152
   624
    from prems(4)[OF bnd nb nle] have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p".
chaieb@33152
   625
  } thus ?case by auto 
chaieb@33152
   626
next
chaieb@33152
   627
  case (A p bs m)  
chaieb@33152
   628
  {fix x
chaieb@33152
   629
    from prems have bnd: "boundslt (length (x#bs)) p" and nb: "bound (Suc m) p" 
chaieb@33152
   630
  and nle: "Suc m < length (x#bs)" by auto
chaieb@33152
   631
    from prems(4)[OF bnd nb nle] have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p".
chaieb@33152
   632
  } thus ?case by auto
chaieb@33152
   633
qed (auto simp add: decrtm removen_nth)
chaieb@33152
   634
haftmann@39246
   635
primrec subst0:: "tm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   636
  "subst0 t T = T"
haftmann@39246
   637
| "subst0 t F = F"
haftmann@39246
   638
| "subst0 t (Lt a) = Lt (tmsubst0 t a)"
haftmann@39246
   639
| "subst0 t (Le a) = Le (tmsubst0 t a)"
haftmann@39246
   640
| "subst0 t (Eq a) = Eq (tmsubst0 t a)"
haftmann@39246
   641
| "subst0 t (NEq a) = NEq (tmsubst0 t a)"
haftmann@39246
   642
| "subst0 t (NOT p) = NOT (subst0 t p)"
haftmann@39246
   643
| "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
haftmann@39246
   644
| "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
haftmann@39246
   645
| "subst0 t (Imp p q) = Imp (subst0 t p)  (subst0 t q)"
haftmann@39246
   646
| "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
haftmann@39246
   647
| "subst0 t (E p) = E p"
haftmann@39246
   648
| "subst0 t (A p) = A p"
chaieb@33152
   649
chaieb@33152
   650
lemma subst0: assumes qf: "qfree p"
chaieb@33152
   651
  shows "Ifm vs (x#bs) (subst0 t p) = Ifm vs ((Itm vs (x#bs) t)#bs) p"
chaieb@33152
   652
using qf tmsubst0[where x="x" and bs="bs" and t="t"]
haftmann@39246
   653
by (induct p rule: fm.induct, auto)
chaieb@33152
   654
chaieb@33152
   655
lemma subst0_nb:
chaieb@33152
   656
  assumes bp: "tmbound0 t" and qf: "qfree p"
chaieb@33152
   657
  shows "bound0 (subst0 t p)"
chaieb@33152
   658
using qf tmsubst0_nb[OF bp] bp
haftmann@39246
   659
by (induct p rule: fm.induct, auto)
chaieb@33152
   660
haftmann@39246
   661
primrec subst:: "nat \<Rightarrow> tm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   662
  "subst n t T = T"
haftmann@39246
   663
| "subst n t F = F"
haftmann@39246
   664
| "subst n t (Lt a) = Lt (tmsubst n t a)"
haftmann@39246
   665
| "subst n t (Le a) = Le (tmsubst n t a)"
haftmann@39246
   666
| "subst n t (Eq a) = Eq (tmsubst n t a)"
haftmann@39246
   667
| "subst n t (NEq a) = NEq (tmsubst n t a)"
haftmann@39246
   668
| "subst n t (NOT p) = NOT (subst n t p)"
haftmann@39246
   669
| "subst n t (And p q) = And (subst n t p) (subst n t q)"
haftmann@39246
   670
| "subst n t (Or p q) = Or (subst n t p) (subst n t q)"
haftmann@39246
   671
| "subst n t (Imp p q) = Imp (subst n t p)  (subst n t q)"
haftmann@39246
   672
| "subst n t (Iff p q) = Iff (subst n t p) (subst n t q)"
haftmann@39246
   673
| "subst n t (E p) = E (subst (Suc n) (incrtm0 t) p)"
haftmann@39246
   674
| "subst n t (A p) = A (subst (Suc n) (incrtm0 t) p)"
chaieb@33152
   675
chaieb@33152
   676
lemma subst: assumes nb: "boundslt (length bs) p" and nlm: "n \<le> length bs"
chaieb@33152
   677
  shows "Ifm vs bs (subst n t p) = Ifm vs (bs[n:= Itm vs bs t]) p"
chaieb@33152
   678
  using nb nlm
haftmann@39246
   679
proof (induct p arbitrary: bs n t rule: fm.induct)
chaieb@33152
   680
  case (E p bs n) 
chaieb@33152
   681
  {fix x 
chaieb@33152
   682
    from prems have bn: "boundslt (length (x#bs)) p" by simp 
chaieb@33152
   683
      from prems have nlm: "Suc n \<le> length (x#bs)" by simp
chaieb@33152
   684
    from prems(3)[OF bn nlm] have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p" by simp 
chaieb@33152
   685
    hence "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs (x#bs[n:= Itm vs bs t]) p"
chaieb@33152
   686
    by (simp add: incrtm0[where x="x" and bs="bs" and t="t"]) }  
chaieb@33152
   687
thus ?case by simp 
chaieb@33152
   688
next
chaieb@33152
   689
  case (A p bs n)   
chaieb@33152
   690
  {fix x 
chaieb@33152
   691
    from prems have bn: "boundslt (length (x#bs)) p" by simp 
chaieb@33152
   692
      from prems have nlm: "Suc n \<le> length (x#bs)" by simp
chaieb@33152
   693
    from prems(3)[OF bn nlm] have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p" by simp 
chaieb@33152
   694
    hence "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs (x#bs[n:= Itm vs bs t]) p"
chaieb@33152
   695
    by (simp add: incrtm0[where x="x" and bs="bs" and t="t"]) }  
chaieb@33152
   696
thus ?case by simp 
chaieb@33152
   697
qed(auto simp add: tmsubst)
chaieb@33152
   698
chaieb@33152
   699
lemma subst_nb: assumes tnb: "tmbound m t"
chaieb@33152
   700
shows "bound m (subst m t p)"
chaieb@33152
   701
using tnb tmsubst_nb incrtm0_tmbound
haftmann@39246
   702
by (induct p arbitrary: m t rule: fm.induct, auto)
chaieb@33152
   703
chaieb@33152
   704
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
chaieb@33152
   705
by (induct p rule: not.induct, auto)
chaieb@33152
   706
lemma not_bn0[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
chaieb@33152
   707
by (induct p rule: not.induct, auto)
chaieb@33152
   708
lemma not_nb[simp]: "bound n p \<Longrightarrow> bound n (not p)"
chaieb@33152
   709
by (induct p rule: not.induct, auto)
chaieb@33152
   710
lemma not_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n (not p)"
chaieb@33152
   711
 by (induct p rule: not.induct, auto)
chaieb@33152
   712
chaieb@33152
   713
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
chaieb@33152
   714
using conj_def by auto 
chaieb@33152
   715
lemma conj_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
chaieb@33152
   716
using conj_def by auto 
chaieb@33152
   717
lemma conj_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (conj p q)"
chaieb@33152
   718
using conj_def by auto 
chaieb@33152
   719
lemma conj_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (conj p q)"
chaieb@33152
   720
using conj_def by auto 
chaieb@33152
   721
chaieb@33152
   722
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
chaieb@33152
   723
using disj_def by auto 
chaieb@33152
   724
lemma disj_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
chaieb@33152
   725
using disj_def by auto 
chaieb@33152
   726
lemma disj_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (disj p q)"
chaieb@33152
   727
using disj_def by auto 
chaieb@33152
   728
lemma disj_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (disj p q)"
chaieb@33152
   729
using disj_def by auto 
chaieb@33152
   730
chaieb@33152
   731
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
chaieb@33152
   732
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
chaieb@33152
   733
lemma imp_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
chaieb@33152
   734
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
chaieb@33152
   735
lemma imp_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (imp p q)"
chaieb@33152
   736
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
chaieb@33152
   737
lemma imp_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (imp p q)"
chaieb@33152
   738
using imp_def by auto 
chaieb@33152
   739
chaieb@33152
   740
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
chaieb@33152
   741
  by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   742
lemma iff_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
chaieb@33152
   743
using iff_def by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   744
lemma iff_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (iff p q)"
chaieb@33152
   745
using iff_def by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   746
lemma iff_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (iff p q)"
chaieb@33152
   747
using iff_def by auto 
chaieb@33152
   748
lemma decr0_qf: "bound0 p \<Longrightarrow> qfree (decr0 p)"
chaieb@33152
   749
by (induct p, simp_all)
chaieb@33152
   750
chaieb@33152
   751
consts 
chaieb@33152
   752
  isatom :: "fm \<Rightarrow> bool" (* test for atomicity *)
chaieb@33152
   753
recdef isatom "measure size"
chaieb@33152
   754
  "isatom T = True"
chaieb@33152
   755
  "isatom F = True"
chaieb@33152
   756
  "isatom (Lt a) = True"
chaieb@33152
   757
  "isatom (Le a) = True"
chaieb@33152
   758
  "isatom (Eq a) = True"
chaieb@33152
   759
  "isatom (NEq a) = True"
chaieb@33152
   760
  "isatom p = False"
chaieb@33152
   761
chaieb@33152
   762
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
chaieb@33152
   763
by (induct p, simp_all)
chaieb@33152
   764
haftmann@35416
   765
definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   766
  "djf f p q \<equiv> (if q=T then T else if q=F then f p else 
chaieb@33152
   767
  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
haftmann@35416
   768
definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
chaieb@33152
   769
  "evaldjf f ps \<equiv> foldr (djf f) ps F"
chaieb@33152
   770
chaieb@33152
   771
lemma djf_Or: "Ifm vs bs (djf f p q) = Ifm vs bs (Or (f p) q)"
chaieb@33152
   772
by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
chaieb@33152
   773
(cases "f p", simp_all add: Let_def djf_def) 
chaieb@33152
   774
chaieb@33152
   775
lemma evaldjf_ex: "Ifm vs bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm vs bs (f p))"
chaieb@33152
   776
  by(induct ps, simp_all add: evaldjf_def djf_Or)
chaieb@33152
   777
chaieb@33152
   778
lemma evaldjf_bound0: 
chaieb@33152
   779
  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
chaieb@33152
   780
  shows "bound0 (evaldjf f xs)"
chaieb@33152
   781
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
chaieb@33152
   782
chaieb@33152
   783
lemma evaldjf_qf: 
chaieb@33152
   784
  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
chaieb@33152
   785
  shows "qfree (evaldjf f xs)"
chaieb@33152
   786
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
chaieb@33152
   787
chaieb@33152
   788
consts disjuncts :: "fm \<Rightarrow> fm list"
chaieb@33152
   789
recdef disjuncts "measure size"
chaieb@33152
   790
  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
chaieb@33152
   791
  "disjuncts F = []"
chaieb@33152
   792
  "disjuncts p = [p]"
chaieb@33152
   793
chaieb@33152
   794
lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
   795
by(induct p rule: disjuncts.induct, auto)
chaieb@33152
   796
chaieb@33152
   797
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
chaieb@33152
   798
proof-
chaieb@33152
   799
  assume nb: "bound0 p"
chaieb@33152
   800
  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
chaieb@33152
   801
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   802
qed
chaieb@33152
   803
chaieb@33152
   804
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
chaieb@33152
   805
proof-
chaieb@33152
   806
  assume qf: "qfree p"
chaieb@33152
   807
  hence "list_all qfree (disjuncts p)"
chaieb@33152
   808
    by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   809
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   810
qed
chaieb@33152
   811
haftmann@35416
   812
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   813
  "DJ f p \<equiv> evaldjf f (disjuncts p)"
chaieb@33152
   814
chaieb@33152
   815
lemma DJ: assumes fdj: "\<forall> p q. Ifm vs bs (f (Or p q)) = Ifm vs bs (Or (f p) (f q))"
chaieb@33152
   816
  and fF: "f F = F"
chaieb@33152
   817
  shows "Ifm vs bs (DJ f p) = Ifm vs bs (f p)"
chaieb@33152
   818
proof-
chaieb@33152
   819
  have "Ifm vs bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm vs bs (f q))"
chaieb@33152
   820
    by (simp add: DJ_def evaldjf_ex) 
chaieb@33152
   821
  also have "\<dots> = Ifm vs bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   822
  finally show ?thesis .
chaieb@33152
   823
qed
chaieb@33152
   824
chaieb@33152
   825
lemma DJ_qf: assumes 
chaieb@33152
   826
  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
chaieb@33152
   827
  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
chaieb@33152
   828
proof(clarify)
chaieb@33152
   829
  fix  p assume qf: "qfree p"
chaieb@33152
   830
  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
chaieb@33152
   831
  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
chaieb@33152
   832
  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
chaieb@33152
   833
  
chaieb@33152
   834
  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
chaieb@33152
   835
qed
chaieb@33152
   836
chaieb@33152
   837
lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
chaieb@33152
   838
  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm vs bs ((DJ qe p)) = Ifm vs bs (E p))"
chaieb@33152
   839
proof(clarify)
chaieb@33152
   840
  fix p::fm and bs
chaieb@33152
   841
  assume qf: "qfree p"
chaieb@33152
   842
  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
chaieb@33152
   843
  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
chaieb@33152
   844
  have "Ifm vs bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm vs bs (qe q))"
chaieb@33152
   845
    by (simp add: DJ_def evaldjf_ex)
chaieb@33152
   846
  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm vs bs (E q))" using qe disjuncts_qf[OF qf] by auto
chaieb@33152
   847
  also have "\<dots> = Ifm vs bs (E p)" by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   848
  finally show "qfree (DJ qe p) \<and> Ifm vs bs (DJ qe p) = Ifm vs bs (E p)" using qfth by blast
chaieb@33152
   849
qed
chaieb@33152
   850
chaieb@33152
   851
consts conjuncts :: "fm \<Rightarrow> fm list"
chaieb@33152
   852
chaieb@33152
   853
recdef conjuncts "measure size"
chaieb@33152
   854
  "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
chaieb@33152
   855
  "conjuncts T = []"
chaieb@33152
   856
  "conjuncts p = [p]"
chaieb@33152
   857
haftmann@35416
   858
definition list_conj :: "fm list \<Rightarrow> fm" where
chaieb@33152
   859
  "list_conj ps \<equiv> foldr conj ps T"
chaieb@33152
   860
haftmann@35416
   861
definition CJNB :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   862
  "CJNB f p \<equiv> (let cjs = conjuncts p ; (yes,no) = partition bound0 cjs
chaieb@33152
   863
                   in conj (decr0 (list_conj yes)) (f (list_conj no)))"
chaieb@33152
   864
chaieb@33152
   865
lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). qfree q"
chaieb@33152
   866
proof-
chaieb@33152
   867
  assume qf: "qfree p"
chaieb@33152
   868
  hence "list_all qfree (conjuncts p)"
chaieb@33152
   869
    by (induct p rule: conjuncts.induct, auto)
chaieb@33152
   870
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   871
qed
chaieb@33152
   872
chaieb@33152
   873
lemma conjuncts: "(\<forall> q\<in> set (conjuncts p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
   874
by(induct p rule: conjuncts.induct, auto)
chaieb@33152
   875
chaieb@33152
   876
lemma conjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). bound0 q"
chaieb@33152
   877
proof-
chaieb@33152
   878
  assume nb: "bound0 p"
chaieb@33152
   879
  hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto)
chaieb@33152
   880
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   881
qed
chaieb@33152
   882
chaieb@33152
   883
fun islin :: "fm \<Rightarrow> bool" where
chaieb@33152
   884
  "islin (And p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
chaieb@33152
   885
| "islin (Or p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
chaieb@33152
   886
| "islin (Eq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   887
| "islin (NEq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   888
| "islin (Lt (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   889
| "islin (Le (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   890
| "islin (NOT p) = False"
chaieb@33152
   891
| "islin (Imp p q) = False"
chaieb@33152
   892
| "islin (Iff p q) = False"
chaieb@33152
   893
| "islin p = bound0 p"
chaieb@33152
   894
chaieb@33152
   895
lemma islin_stupid: assumes nb: "tmbound0 p"
chaieb@33152
   896
  shows "islin (Lt p)" and "islin (Le p)" and "islin (Eq p)" and "islin (NEq p)"
chaieb@33152
   897
  using nb by (cases p, auto, case_tac nat, auto)+
chaieb@33152
   898
chaieb@33152
   899
definition "lt p = (case p of CP (C c) \<Rightarrow> if 0>\<^sub>N c then T else F| _ \<Rightarrow> Lt p)"
chaieb@33152
   900
definition "le p = (case p of CP (C c) \<Rightarrow> if 0\<ge>\<^sub>N c then T else F | _ \<Rightarrow> Le p)"
haftmann@38864
   901
definition eq where "eq p = (case p of CP (C c) \<Rightarrow> if c = 0\<^sub>N then T else F | _ \<Rightarrow> Eq p)"
chaieb@33152
   902
definition "neq p = not (eq p)"
chaieb@33152
   903
chaieb@33152
   904
lemma lt: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (lt p) = Ifm vs bs (Lt p)"
chaieb@33152
   905
  apply(simp add: lt_def)
chaieb@33152
   906
  apply(cases p, simp_all)
chaieb@33152
   907
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   908
  done
chaieb@33152
   909
chaieb@33152
   910
lemma le: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (le p) = Ifm vs bs (Le p)"
chaieb@33152
   911
  apply(simp add: le_def)
chaieb@33152
   912
  apply(cases p, simp_all)
chaieb@33152
   913
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   914
  done
chaieb@33152
   915
chaieb@33152
   916
lemma eq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (eq p) = Ifm vs bs (Eq p)"
chaieb@33152
   917
  apply(simp add: eq_def)
chaieb@33152
   918
  apply(cases p, simp_all)
chaieb@33152
   919
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   920
  done
chaieb@33152
   921
chaieb@33152
   922
lemma neq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (neq p) = Ifm vs bs (NEq p)"
chaieb@33152
   923
  by(simp add: neq_def eq)
chaieb@33152
   924
chaieb@33152
   925
lemma lt_lin: "tmbound0 p \<Longrightarrow> islin (lt p)"
chaieb@33152
   926
  apply (simp add: lt_def)
chaieb@33152
   927
  apply (cases p, simp_all)
chaieb@33152
   928
  apply (case_tac poly, simp_all)
chaieb@33152
   929
  apply (case_tac nat, simp_all)
chaieb@33152
   930
  done
chaieb@33152
   931
chaieb@33152
   932
lemma le_lin: "tmbound0 p \<Longrightarrow> islin (le p)"
chaieb@33152
   933
  apply (simp add: le_def)
chaieb@33152
   934
  apply (cases p, simp_all)
chaieb@33152
   935
  apply (case_tac poly, simp_all)
chaieb@33152
   936
  apply (case_tac nat, simp_all)
chaieb@33152
   937
  done
chaieb@33152
   938
chaieb@33152
   939
lemma eq_lin: "tmbound0 p \<Longrightarrow> islin (eq p)"
chaieb@33152
   940
  apply (simp add: eq_def)
chaieb@33152
   941
  apply (cases p, simp_all)
chaieb@33152
   942
  apply (case_tac poly, simp_all)
chaieb@33152
   943
  apply (case_tac nat, simp_all)
chaieb@33152
   944
  done
chaieb@33152
   945
chaieb@33152
   946
lemma neq_lin: "tmbound0 p \<Longrightarrow> islin (neq p)"
chaieb@33152
   947
  apply (simp add: neq_def eq_def)
chaieb@33152
   948
  apply (cases p, simp_all)
chaieb@33152
   949
  apply (case_tac poly, simp_all)
chaieb@33152
   950
  apply (case_tac nat, simp_all)
chaieb@33152
   951
  done
chaieb@33152
   952
chaieb@33152
   953
definition "simplt t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then lt s else Lt (CNP 0 c s))"
chaieb@33152
   954
definition "simple t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then le s else Le (CNP 0 c s))"
chaieb@33152
   955
definition "simpeq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then eq s else Eq (CNP 0 c s))"
chaieb@33152
   956
definition "simpneq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then neq s else NEq (CNP 0 c s))"
chaieb@33152
   957
haftmann@36409
   958
lemma simplt_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   959
  shows "islin (simplt t)"
chaieb@33152
   960
  unfolding simplt_def 
chaieb@33152
   961
  using split0_nb0'
chaieb@33152
   962
by (auto simp add: lt_lin Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly] islin_stupid allpolys_split0[OF simptm_allpolys_npoly])
chaieb@33152
   963
  
haftmann@36409
   964
lemma simple_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   965
  shows "islin (simple t)"
chaieb@33152
   966
  unfolding simple_def 
chaieb@33152
   967
  using split0_nb0'
chaieb@33152
   968
by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly] islin_stupid allpolys_split0[OF simptm_allpolys_npoly] le_lin)
haftmann@36409
   969
lemma simpeq_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   970
  shows "islin (simpeq t)"
chaieb@33152
   971
  unfolding simpeq_def 
chaieb@33152
   972
  using split0_nb0'
chaieb@33152
   973
by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly] islin_stupid allpolys_split0[OF simptm_allpolys_npoly] eq_lin)
chaieb@33152
   974
haftmann@36409
   975
lemma simpneq_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   976
  shows "islin (simpneq t)"
chaieb@33152
   977
  unfolding simpneq_def 
chaieb@33152
   978
  using split0_nb0'
chaieb@33152
   979
by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly] islin_stupid allpolys_split0[OF simptm_allpolys_npoly] neq_lin)
chaieb@33152
   980
chaieb@33152
   981
lemma really_stupid: "\<not> (\<forall>c1 s'. (c1, s') \<noteq> split0 s)"
chaieb@33152
   982
  by (cases "split0 s", auto)
haftmann@36409
   983
lemma split0_npoly:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   984
  and n: "allpolys isnpoly t"
chaieb@33152
   985
  shows "isnpoly (fst (split0 t))" and "allpolys isnpoly (snd (split0 t))"
chaieb@33152
   986
  using n
chaieb@33152
   987
  by (induct t rule: split0.induct, auto simp add: Let_def split_def polyadd_norm polymul_norm polyneg_norm polysub_norm really_stupid)
chaieb@33152
   988
lemma simplt[simp]:
chaieb@33152
   989
  shows "Ifm vs bs (simplt t) = Ifm vs bs (Lt t)"
chaieb@33152
   990
proof-
chaieb@33152
   991
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
   992
  let ?t = "simptm t"
chaieb@33152
   993
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
   994
      using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
   995
      by (simp add: simplt_def Let_def split_def lt)}
chaieb@33152
   996
  moreover
chaieb@33152
   997
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
   998
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simplt_def Let_def split_def)
chaieb@33152
   999
  }
chaieb@33152
  1000
  ultimately show ?thesis by blast
chaieb@33152
  1001
qed
chaieb@33152
  1002
chaieb@33152
  1003
lemma simple[simp]:
chaieb@33152
  1004
  shows "Ifm vs bs (simple t) = Ifm vs bs (Le t)"
chaieb@33152
  1005
proof-
chaieb@33152
  1006
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
  1007
  let ?t = "simptm t"
chaieb@33152
  1008
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
  1009
      using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
  1010
      by (simp add: simple_def Let_def split_def le)}
chaieb@33152
  1011
  moreover
chaieb@33152
  1012
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
  1013
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simple_def Let_def split_def)
chaieb@33152
  1014
  }
chaieb@33152
  1015
  ultimately show ?thesis by blast
chaieb@33152
  1016
qed
chaieb@33152
  1017
chaieb@33152
  1018
lemma simpeq[simp]:
chaieb@33152
  1019
  shows "Ifm vs bs (simpeq t) = Ifm vs bs (Eq t)"
chaieb@33152
  1020
proof-
chaieb@33152
  1021
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
  1022
  let ?t = "simptm t"
chaieb@33152
  1023
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
  1024
      using split0[of "simptm t" vs bs] eq[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
  1025
      by (simp add: simpeq_def Let_def split_def)}
chaieb@33152
  1026
  moreover
chaieb@33152
  1027
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
  1028
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simpeq_def Let_def split_def)
chaieb@33152
  1029
  }
chaieb@33152
  1030
  ultimately show ?thesis by blast
chaieb@33152
  1031
qed
chaieb@33152
  1032
chaieb@33152
  1033
lemma simpneq[simp]:
chaieb@33152
  1034
  shows "Ifm vs bs (simpneq t) = Ifm vs bs (NEq t)"
chaieb@33152
  1035
proof-
chaieb@33152
  1036
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
  1037
  let ?t = "simptm t"
chaieb@33152
  1038
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
  1039
      using split0[of "simptm t" vs bs] neq[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
  1040
      by (simp add: simpneq_def Let_def split_def )}
chaieb@33152
  1041
  moreover
chaieb@33152
  1042
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
  1043
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simpneq_def Let_def split_def)
chaieb@33152
  1044
  }
chaieb@33152
  1045
  ultimately show ?thesis by blast
chaieb@33152
  1046
qed
chaieb@33152
  1047
chaieb@33152
  1048
lemma lt_nb: "tmbound0 t \<Longrightarrow> bound0 (lt t)"
chaieb@33152
  1049
  apply (simp add: lt_def)
chaieb@33152
  1050
  apply (cases t, auto)
chaieb@33152
  1051
  apply (case_tac poly, auto)
chaieb@33152
  1052
  done
chaieb@33152
  1053
chaieb@33152
  1054
lemma le_nb: "tmbound0 t \<Longrightarrow> bound0 (le t)"
chaieb@33152
  1055
  apply (simp add: le_def)
chaieb@33152
  1056
  apply (cases t, auto)
chaieb@33152
  1057
  apply (case_tac poly, auto)
chaieb@33152
  1058
  done
chaieb@33152
  1059
chaieb@33152
  1060
lemma eq_nb: "tmbound0 t \<Longrightarrow> bound0 (eq t)"
chaieb@33152
  1061
  apply (simp add: eq_def)
chaieb@33152
  1062
  apply (cases t, auto)
chaieb@33152
  1063
  apply (case_tac poly, auto)
chaieb@33152
  1064
  done
chaieb@33152
  1065
chaieb@33152
  1066
lemma neq_nb: "tmbound0 t \<Longrightarrow> bound0 (neq t)"
chaieb@33152
  1067
  apply (simp add: neq_def eq_def)
chaieb@33152
  1068
  apply (cases t, auto)
chaieb@33152
  1069
  apply (case_tac poly, auto)
chaieb@33152
  1070
  done
chaieb@33152
  1071
haftmann@36409
  1072
lemma simplt_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1073
  shows "tmbound0 t \<Longrightarrow> bound0 (simplt t)"
chaieb@33152
  1074
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1075
proof(simp add: simplt_def Let_def split_def)
chaieb@33152
  1076
  assume nb: "tmbound0 t"
chaieb@33152
  1077
  hence nb': "tmbound0 (simptm t)" by simp
chaieb@33152
  1078
  let ?c = "fst (split0 (simptm t))"
chaieb@33152
  1079
  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
chaieb@33152
  1080
  have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p" by auto
chaieb@33152
  1081
  from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
chaieb@33152
  1082
  have ths: "isnpolyh ?c 0" "isnpolyh 0\<^sub>p 0" by (simp_all add: isnpoly_def)
chaieb@33152
  1083
  from iffD1[OF isnpolyh_unique[OF ths] th]
chaieb@33152
  1084
  have "fst (split0 (simptm t)) = 0\<^sub>p" . 
chaieb@33152
  1085
  thus "(fst (split0 (simptm t)) = 0\<^sub>p \<longrightarrow> bound0 (lt (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1086
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simplt_def Let_def split_def lt_nb)
chaieb@33152
  1087
qed
chaieb@33152
  1088
haftmann@36409
  1089
lemma simple_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1090
  shows "tmbound0 t \<Longrightarrow> bound0 (simple t)"
chaieb@33152
  1091
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1092
proof(simp add: simple_def Let_def split_def)
chaieb@33152
  1093
  assume nb: "tmbound0 t"
chaieb@33152
  1094
  hence nb': "tmbound0 (simptm t)" by simp
chaieb@33152
  1095
  let ?c = "fst (split0 (simptm t))"
chaieb@33152
  1096
  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
chaieb@33152
  1097
  have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p" by auto
chaieb@33152
  1098
  from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
chaieb@33152
  1099
  have ths: "isnpolyh ?c 0" "isnpolyh 0\<^sub>p 0" by (simp_all add: isnpoly_def)
chaieb@33152
  1100
  from iffD1[OF isnpolyh_unique[OF ths] th]
chaieb@33152
  1101
  have "fst (split0 (simptm t)) = 0\<^sub>p" . 
chaieb@33152
  1102
  thus "(fst (split0 (simptm t)) = 0\<^sub>p \<longrightarrow> bound0 (le (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1103
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simplt_def Let_def split_def le_nb)
chaieb@33152
  1104
qed
chaieb@33152
  1105
haftmann@36409
  1106
lemma simpeq_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1107
  shows "tmbound0 t \<Longrightarrow> bound0 (simpeq t)"
chaieb@33152
  1108
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1109
proof(simp add: simpeq_def Let_def split_def)
chaieb@33152
  1110
  assume nb: "tmbound0 t"
chaieb@33152
  1111
  hence nb': "tmbound0 (simptm t)" by simp
chaieb@33152
  1112
  let ?c = "fst (split0 (simptm t))"
chaieb@33152
  1113
  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
chaieb@33152
  1114
  have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p" by auto
chaieb@33152
  1115
  from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
chaieb@33152
  1116
  have ths: "isnpolyh ?c 0" "isnpolyh 0\<^sub>p 0" by (simp_all add: isnpoly_def)
chaieb@33152
  1117
  from iffD1[OF isnpolyh_unique[OF ths] th]
chaieb@33152
  1118
  have "fst (split0 (simptm t)) = 0\<^sub>p" . 
chaieb@33152
  1119
  thus "(fst (split0 (simptm t)) = 0\<^sub>p \<longrightarrow> bound0 (eq (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1120
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simpeq_def Let_def split_def eq_nb)
chaieb@33152
  1121
qed
chaieb@33152
  1122
haftmann@36409
  1123
lemma simpneq_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1124
  shows "tmbound0 t \<Longrightarrow> bound0 (simpneq t)"
chaieb@33152
  1125
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1126
proof(simp add: simpneq_def Let_def split_def)
chaieb@33152
  1127
  assume nb: "tmbound0 t"
chaieb@33152
  1128
  hence nb': "tmbound0 (simptm t)" by simp
chaieb@33152
  1129
  let ?c = "fst (split0 (simptm t))"
chaieb@33152
  1130
  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
chaieb@33152
  1131
  have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p" by auto
chaieb@33152
  1132
  from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
chaieb@33152
  1133
  have ths: "isnpolyh ?c 0" "isnpolyh 0\<^sub>p 0" by (simp_all add: isnpoly_def)
chaieb@33152
  1134
  from iffD1[OF isnpolyh_unique[OF ths] th]
chaieb@33152
  1135
  have "fst (split0 (simptm t)) = 0\<^sub>p" . 
chaieb@33152
  1136
  thus "(fst (split0 (simptm t)) = 0\<^sub>p \<longrightarrow> bound0 (neq (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1137
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simpneq_def Let_def split_def neq_nb)
chaieb@33152
  1138
qed
chaieb@33152
  1139
chaieb@33152
  1140
consts conjs   :: "fm \<Rightarrow> fm list"
chaieb@33152
  1141
recdef conjs "measure size"
chaieb@33152
  1142
  "conjs (And p q) = (conjs p)@(conjs q)"
chaieb@33152
  1143
  "conjs T = []"
chaieb@33152
  1144
  "conjs p = [p]"
chaieb@33152
  1145
lemma conjs_ci: "(\<forall> q \<in> set (conjs p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
  1146
by (induct p rule: conjs.induct, auto)
haftmann@35416
  1147
definition list_disj :: "fm list \<Rightarrow> fm" where
chaieb@33152
  1148
  "list_disj ps \<equiv> foldr disj ps F"
chaieb@33152
  1149
chaieb@33152
  1150
lemma list_conj: "Ifm vs bs (list_conj ps) = (\<forall>p\<in> set ps. Ifm vs bs p)"
chaieb@33152
  1151
  by (induct ps, auto simp add: list_conj_def)
chaieb@33152
  1152
lemma list_conj_qf: " \<forall>p\<in> set ps. qfree p \<Longrightarrow> qfree (list_conj ps)"
chaieb@33152
  1153
  by (induct ps, auto simp add: list_conj_def conj_qf)
chaieb@33152
  1154
lemma list_disj: "Ifm vs bs (list_disj ps) = (\<exists>p\<in> set ps. Ifm vs bs p)"
chaieb@33152
  1155
  by (induct ps, auto simp add: list_disj_def)
chaieb@33152
  1156
chaieb@33152
  1157
lemma conj_boundslt: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (conj p q)"
chaieb@33152
  1158
  unfolding conj_def by auto
chaieb@33152
  1159
chaieb@33152
  1160
lemma conjs_nb: "bound n p \<Longrightarrow> \<forall>q\<in> set (conjs p). bound n q"
chaieb@33152
  1161
  apply (induct p rule: conjs.induct) 
chaieb@33152
  1162
  apply (unfold conjs.simps)
chaieb@33152
  1163
  apply (unfold set_append)
chaieb@33152
  1164
  apply (unfold ball_Un)
chaieb@33152
  1165
  apply (unfold bound.simps)
chaieb@33152
  1166
  apply auto
chaieb@33152
  1167
  done
chaieb@33152
  1168
chaieb@33152
  1169
lemma conjs_boundslt: "boundslt n p \<Longrightarrow> \<forall>q\<in> set (conjs p). boundslt n q"
chaieb@33152
  1170
  apply (induct p rule: conjs.induct) 
chaieb@33152
  1171
  apply (unfold conjs.simps)
chaieb@33152
  1172
  apply (unfold set_append)
chaieb@33152
  1173
  apply (unfold ball_Un)
chaieb@33152
  1174
  apply (unfold boundslt.simps)
chaieb@33152
  1175
  apply blast
chaieb@33152
  1176
by simp_all
chaieb@33152
  1177
chaieb@33152
  1178
lemma list_conj_boundslt: " \<forall>p\<in> set ps. boundslt n p \<Longrightarrow> boundslt n (list_conj ps)"
chaieb@33152
  1179
  unfolding list_conj_def
chaieb@33152
  1180
  by (induct ps, auto simp add: conj_boundslt)
chaieb@33152
  1181
chaieb@33152
  1182
lemma list_conj_nb: assumes bnd: "\<forall>p\<in> set ps. bound n p"
chaieb@33152
  1183
  shows "bound n (list_conj ps)"
chaieb@33152
  1184
  using bnd
chaieb@33152
  1185
  unfolding list_conj_def
chaieb@33152
  1186
  by (induct ps, auto simp add: conj_nb)
chaieb@33152
  1187
chaieb@33152
  1188
lemma list_conj_nb': "\<forall>p\<in>set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
chaieb@33152
  1189
unfolding list_conj_def by (induct ps , auto)
chaieb@33152
  1190
chaieb@33152
  1191
lemma CJNB_qe: 
chaieb@33152
  1192
  assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
chaieb@33152
  1193
  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (CJNB qe p) \<and> (Ifm vs bs ((CJNB qe p)) = Ifm vs bs (E p))"
chaieb@33152
  1194
proof(clarify)
chaieb@33152
  1195
  fix bs p
chaieb@33152
  1196
  assume qfp: "qfree p"
chaieb@33152
  1197
  let ?cjs = "conjuncts p"
chaieb@33152
  1198
  let ?yes = "fst (partition bound0 ?cjs)"
chaieb@33152
  1199
  let ?no = "snd (partition bound0 ?cjs)"
chaieb@33152
  1200
  let ?cno = "list_conj ?no"
chaieb@33152
  1201
  let ?cyes = "list_conj ?yes"
chaieb@33152
  1202
  have part: "partition bound0 ?cjs = (?yes,?no)" by simp
chaieb@33152
  1203
  from partition_P[OF part] have "\<forall> q\<in> set ?yes. bound0 q" by blast 
chaieb@33152
  1204
  hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb') 
chaieb@33152
  1205
  hence yes_qf: "qfree (decr0 ?cyes )" by (simp add: decr0_qf)
chaieb@33152
  1206
  from conjuncts_qf[OF qfp] partition_set[OF part] 
chaieb@33152
  1207
  have " \<forall>q\<in> set ?no. qfree q" by auto
chaieb@33152
  1208
  hence no_qf: "qfree ?cno"by (simp add: list_conj_qf)
chaieb@33152
  1209
  with qe have cno_qf:"qfree (qe ?cno )" 
chaieb@33152
  1210
    and noE: "Ifm vs bs (qe ?cno) = Ifm vs bs (E ?cno)" by blast+
chaieb@33152
  1211
  from cno_qf yes_qf have qf: "qfree (CJNB qe p)" 
chaieb@33152
  1212
    by (simp add: CJNB_def Let_def conj_qf split_def)
chaieb@33152
  1213
  {fix bs
chaieb@33152
  1214
    from conjuncts have "Ifm vs bs p = (\<forall>q\<in> set ?cjs. Ifm vs bs q)" by blast
chaieb@33152
  1215
    also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm vs bs q) \<and> (\<forall>q\<in> set ?no. Ifm vs bs q))"
chaieb@33152
  1216
      using partition_set[OF part] by auto
chaieb@33152
  1217
    finally have "Ifm vs bs p = ((Ifm vs bs ?cyes) \<and> (Ifm vs bs ?cno))" using list_conj[of vs bs] by simp}
chaieb@33152
  1218
  hence "Ifm vs bs (E p) = (\<exists>x. (Ifm vs (x#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))" by simp
chaieb@33152
  1219
  also have "\<dots> = (\<exists>x. (Ifm vs (y#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
chaieb@33152
  1220
    using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
chaieb@33152
  1221
  also have "\<dots> = (Ifm vs bs (decr0 ?cyes) \<and> Ifm vs bs (E ?cno))"
hoelzl@33639
  1222
    by (auto simp add: decr0[OF yes_nb] simp del: partition_filter_conv)
chaieb@33152
  1223
  also have "\<dots> = (Ifm vs bs (conj (decr0 ?cyes) (qe ?cno)))"
chaieb@33152
  1224
    using qe[rule_format, OF no_qf] by auto
chaieb@33152
  1225
  finally have "Ifm vs bs (E p) = Ifm vs bs (CJNB qe p)" 
chaieb@33152
  1226
    by (simp add: Let_def CJNB_def split_def)
chaieb@33152
  1227
  with qf show "qfree (CJNB qe p) \<and> Ifm vs bs (CJNB qe p) = Ifm vs bs (E p)" by blast
chaieb@33152
  1228
qed
chaieb@33152
  1229
chaieb@33152
  1230
consts simpfm :: "fm \<Rightarrow> fm"
chaieb@33152
  1231
recdef simpfm "measure fmsize"
chaieb@33152
  1232
  "simpfm (Lt t) = simplt (simptm t)"
chaieb@33152
  1233
  "simpfm (Le t) = simple (simptm t)"
chaieb@33152
  1234
  "simpfm (Eq t) = simpeq(simptm t)"
chaieb@33152
  1235
  "simpfm (NEq t) = simpneq(simptm t)"
chaieb@33152
  1236
  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
chaieb@33152
  1237
  "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
chaieb@33152
  1238
  "simpfm (Imp p q) = disj (simpfm (NOT p)) (simpfm q)"
chaieb@33152
  1239
  "simpfm (Iff p q) = disj (conj (simpfm p) (simpfm q)) (conj (simpfm (NOT p)) (simpfm (NOT q)))"
chaieb@33152
  1240
  "simpfm (NOT (And p q)) = disj (simpfm (NOT p)) (simpfm (NOT q))"
chaieb@33152
  1241
  "simpfm (NOT (Or p q)) = conj (simpfm (NOT p)) (simpfm (NOT q))"
chaieb@33152
  1242
  "simpfm (NOT (Imp p q)) = conj (simpfm p) (simpfm (NOT q))"
chaieb@33152
  1243
  "simpfm (NOT (Iff p q)) = disj (conj (simpfm p) (simpfm (NOT q))) (conj (simpfm (NOT p)) (simpfm q))"
chaieb@33152
  1244
  "simpfm (NOT (Eq t)) = simpneq t"
chaieb@33152
  1245
  "simpfm (NOT (NEq t)) = simpeq t"
chaieb@33152
  1246
  "simpfm (NOT (Le t)) = simplt (Neg t)"
chaieb@33152
  1247
  "simpfm (NOT (Lt t)) = simple (Neg t)"
chaieb@33152
  1248
  "simpfm (NOT (NOT p)) = simpfm p"
chaieb@33152
  1249
  "simpfm (NOT T) = F"
chaieb@33152
  1250
  "simpfm (NOT F) = T"
chaieb@33152
  1251
  "simpfm p = p"
chaieb@33152
  1252
chaieb@33152
  1253
lemma simpfm[simp]: "Ifm vs bs (simpfm p) = Ifm vs bs p"
chaieb@33152
  1254
by(induct p arbitrary: bs rule: simpfm.induct, auto)
chaieb@33152
  1255
haftmann@36409
  1256
lemma simpfm_bound0:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1257
  shows "bound0 p \<Longrightarrow> bound0 (simpfm p)"
chaieb@33152
  1258
by (induct p rule: simpfm.induct, auto)
chaieb@33152
  1259
chaieb@33152
  1260
lemma lt_qf[simp]: "qfree (lt t)"
chaieb@33152
  1261
  apply (cases t, auto simp add: lt_def)
chaieb@33152
  1262
  by (case_tac poly, auto)
chaieb@33152
  1263
chaieb@33152
  1264
lemma le_qf[simp]: "qfree (le t)"
chaieb@33152
  1265
  apply (cases t, auto simp add: le_def)
chaieb@33152
  1266
  by (case_tac poly, auto)
chaieb@33152
  1267
chaieb@33152
  1268
lemma eq_qf[simp]: "qfree (eq t)"
chaieb@33152
  1269
  apply (cases t, auto simp add: eq_def)
chaieb@33152
  1270
  by (case_tac poly, auto)
chaieb@33152
  1271
chaieb@33152
  1272
lemma neq_qf[simp]: "qfree (neq t)" by (simp add: neq_def)
chaieb@33152
  1273
chaieb@33152
  1274
lemma simplt_qf[simp]: "qfree (simplt t)" by (simp add: simplt_def Let_def split_def)
chaieb@33152
  1275
lemma simple_qf[simp]: "qfree (simple t)" by (simp add: simple_def Let_def split_def)
chaieb@33152
  1276
lemma simpeq_qf[simp]: "qfree (simpeq t)" by (simp add: simpeq_def Let_def split_def)
chaieb@33152
  1277
lemma simpneq_qf[simp]: "qfree (simpneq t)" by (simp add: simpneq_def Let_def split_def)
chaieb@33152
  1278
chaieb@33152
  1279
lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
chaieb@33152
  1280
by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def)
chaieb@33152
  1281
chaieb@33152
  1282
lemma disj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (disj p q)" by (simp add: disj_def)
chaieb@33152
  1283
lemma conj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (conj p q)" by (simp add: conj_def)
chaieb@33152
  1284
haftmann@36409
  1285
lemma   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1286
  shows "qfree p \<Longrightarrow> islin (simpfm p)" 
chaieb@33152
  1287
  apply (induct p rule: simpfm.induct)
chaieb@33152
  1288
  apply (simp_all add: conj_lin disj_lin)
chaieb@33152
  1289
  done
chaieb@33152
  1290
chaieb@33152
  1291
consts prep :: "fm \<Rightarrow> fm"
chaieb@33152
  1292
recdef prep "measure fmsize"
chaieb@33152
  1293
  "prep (E T) = T"
chaieb@33152
  1294
  "prep (E F) = F"
chaieb@33152
  1295
  "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
chaieb@33152
  1296
  "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
chaieb@33152
  1297
  "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" 
chaieb@33152
  1298
  "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
chaieb@33152
  1299
  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
chaieb@33152
  1300
  "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
chaieb@33152
  1301
  "prep (E p) = E (prep p)"
chaieb@33152
  1302
  "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
chaieb@33152
  1303
  "prep (A p) = prep (NOT (E (NOT p)))"
chaieb@33152
  1304
  "prep (NOT (NOT p)) = prep p"
chaieb@33152
  1305
  "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
chaieb@33152
  1306
  "prep (NOT (A p)) = prep (E (NOT p))"
chaieb@33152
  1307
  "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
chaieb@33152
  1308
  "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
chaieb@33152
  1309
  "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
chaieb@33152
  1310
  "prep (NOT p) = not (prep p)"
chaieb@33152
  1311
  "prep (Or p q) = disj (prep p) (prep q)"
chaieb@33152
  1312
  "prep (And p q) = conj (prep p) (prep q)"
chaieb@33152
  1313
  "prep (Imp p q) = prep (Or (NOT p) q)"
chaieb@33152
  1314
  "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
chaieb@33152
  1315
  "prep p = p"
chaieb@33152
  1316
(hints simp add: fmsize_pos)
chaieb@33152
  1317
lemma prep: "Ifm vs bs (prep p) = Ifm vs bs p"
chaieb@33152
  1318
by (induct p arbitrary: bs rule: prep.induct, auto)
chaieb@33152
  1319
chaieb@33152
  1320
chaieb@33152
  1321
chaieb@33152
  1322
  (* Generic quantifier elimination *)
chaieb@33152
  1323
consts qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
chaieb@33152
  1324
recdef qelim "measure fmsize"
chaieb@33152
  1325
  "qelim (E p) = (\<lambda> qe. DJ (CJNB qe) (qelim p qe))"
chaieb@33152
  1326
  "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
chaieb@33152
  1327
  "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
chaieb@33152
  1328
  "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
chaieb@33152
  1329
  "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
chaieb@33152
  1330
  "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))"
chaieb@33152
  1331
  "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
chaieb@33152
  1332
  "qelim p = (\<lambda> y. simpfm p)"
chaieb@33152
  1333
chaieb@33152
  1334
chaieb@33152
  1335
lemma qelim:
chaieb@33152
  1336
  assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
chaieb@33152
  1337
  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm vs bs (qelim p qe) = Ifm vs bs p)"
chaieb@33152
  1338
using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]]
chaieb@33152
  1339
by (induct p rule: qelim.induct) auto
chaieb@33152
  1340
chaieb@33152
  1341
subsection{* Core Procedure *}
chaieb@33152
  1342
chaieb@33152
  1343
consts 
chaieb@33152
  1344
  plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*)
chaieb@33152
  1345
  minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*)
chaieb@33152
  1346
recdef minusinf "measure size"
chaieb@33152
  1347
  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
chaieb@33152
  1348
  "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
chaieb@33152
  1349
  "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
chaieb@33152
  1350
  "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
chaieb@33152
  1351
  "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
chaieb@33152
  1352
  "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
chaieb@33152
  1353
  "minusinf p = p"
chaieb@33152
  1354
chaieb@33152
  1355
recdef plusinf "measure size"
chaieb@33152
  1356
  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
chaieb@33152
  1357
  "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
chaieb@33152
  1358
  "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
chaieb@33152
  1359
  "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
chaieb@33152
  1360
  "plusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP c))"
chaieb@33152
  1361
  "plusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP c))"
chaieb@33152
  1362
  "plusinf p = p"
chaieb@33152
  1363
chaieb@33152
  1364
lemma minusinf_inf: assumes lp:"islin p"
chaieb@33152
  1365
  shows "\<exists>z. \<forall>x < z. Ifm vs (x#bs) (minusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
chaieb@33152
  1366
  using lp
chaieb@33152
  1367
proof (induct p rule: minusinf.induct)
chaieb@33152
  1368
  case 1 thus ?case by (auto,rule_tac x="min z za" in exI, auto)
chaieb@33152
  1369
next
chaieb@33152
  1370
  case 2 thus ?case by (auto,rule_tac x="min z za" in exI, auto)
chaieb@33152
  1371
next
chaieb@33152
  1372
  case (3 c e) hence nbe: "tmbound0 e" by simp
chaieb@33152
  1373
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1374
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1375
  let ?c = "Ipoly vs c"
chaieb@33152
  1376
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1377
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1378
  moreover {assume "?c = 0" hence ?case 
chaieb@33152
  1379
      using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto}
chaieb@33152
  1380
  moreover {assume cp: "?c > 0"
chaieb@33152
  1381
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1382
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1383
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1384
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1385
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x" and vs=vs and bs=bs] by auto} hence ?case by auto}
chaieb@33152
  1386
  moreover {assume cp: "?c < 0"
chaieb@33152
  1387
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1388
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1389
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1390
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1391
        using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto} hence ?case by auto}
chaieb@33152
  1392
  ultimately show ?case by blast
chaieb@33152
  1393
next
chaieb@33152
  1394
  case (4 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1395
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1396
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1397
  let ?c = "Ipoly vs c"
chaieb@33152
  1398
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1399
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1400
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1401
  moreover {assume cp: "?c > 0"
chaieb@33152
  1402
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1403
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1404
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1405
      hence "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1406
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1407
  moreover {assume cp: "?c < 0"
chaieb@33152
  1408
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1409
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1410
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1411
      hence "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1412
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1413
  ultimately show ?case by blast
chaieb@33152
  1414
next
chaieb@33152
  1415
  case (5 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1416
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1417
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1418
  note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] lt[OF nc(2), where ?'a = 'a]
chaieb@33152
  1419
  let ?c = "Ipoly vs c"
chaieb@33152
  1420
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1421
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1422
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1423
  moreover {assume cp: "?c > 0"
chaieb@33152
  1424
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1425
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1426
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1427
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1428
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1429
  moreover {assume cp: "?c < 0"
chaieb@33152
  1430
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1431
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1432
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1433
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1434
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] cp by auto} hence ?case by auto}
chaieb@33152
  1435
  ultimately show ?case by blast
chaieb@33152
  1436
next
chaieb@33152
  1437
  case (6 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1438
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1439
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1440
  note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] le[OF nc(2), where ?'a = 'a]
chaieb@33152
  1441
  let ?c = "Ipoly vs c"
chaieb@33152
  1442
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1443
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1444
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1445
  moreover {assume cp: "?c > 0"
chaieb@33152
  1446
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1447
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1448
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1449
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1450
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1451
  moreover {assume cp: "?c < 0"
chaieb@33152
  1452
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1453
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1454
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1455
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1456
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1457
  ultimately show ?case by blast
chaieb@33152
  1458
qed (auto)
chaieb@33152
  1459
chaieb@33152
  1460
lemma plusinf_inf: assumes lp:"islin p"
chaieb@33152
  1461
  shows "\<exists>z. \<forall>x > z. Ifm vs (x#bs) (plusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
chaieb@33152
  1462
  using lp
chaieb@33152
  1463
proof (induct p rule: plusinf.induct)
chaieb@33152
  1464
  case 1 thus ?case by (auto,rule_tac x="max z za" in exI, auto)
chaieb@33152
  1465
next
chaieb@33152
  1466
  case 2 thus ?case by (auto,rule_tac x="max z za" in exI, auto)
chaieb@33152
  1467
next
chaieb@33152
  1468
  case (3 c e) hence nbe: "tmbound0 e" by simp
chaieb@33152
  1469
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1470
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1471
  let ?c = "Ipoly vs c"
chaieb@33152
  1472
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1473
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1474
  moreover {assume "?c = 0" hence ?case 
chaieb@33152
  1475
      using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto}
chaieb@33152
  1476
  moreover {assume cp: "?c > 0"
chaieb@33152
  1477
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e" 
wenzelm@33268
  1478
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1479
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1480
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1481
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x" and vs=vs and bs=bs] by auto} hence ?case by auto}
chaieb@33152
  1482
  moreover {assume cp: "?c < 0"
chaieb@33152
  1483
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1484
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1485
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1486
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1487
        using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto} hence ?case by auto}
chaieb@33152
  1488
  ultimately show ?case by blast
chaieb@33152
  1489
next
chaieb@33152
  1490
  case (4 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1491
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1492
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1493
  let ?c = "Ipoly vs c"
chaieb@33152
  1494
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1495
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1496
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1497
  moreover {assume cp: "?c > 0"
chaieb@33152
  1498
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1499
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1500
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1501
      hence "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1502
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1503
  moreover {assume cp: "?c < 0"
chaieb@33152
  1504
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1505
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1506
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1507
      hence "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1508
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1509
  ultimately show ?case by blast
chaieb@33152
  1510
next
chaieb@33152
  1511
  case (5 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1512
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1513
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1514
  note eqs = lt[OF nc(1), where ?'a = 'a] lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] lt[OF nc(2), where ?'a = 'a]
chaieb@33152
  1515
  let ?c = "Ipoly vs c"
chaieb@33152
  1516
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1517
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1518
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1519
  moreover {assume cp: "?c > 0"
chaieb@33152
  1520
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1521
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1522
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1523
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1524
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1525
  moreover {assume cp: "?c < 0"
chaieb@33152
  1526
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1527
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1528
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1529
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1530
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] cp by auto} hence ?case by auto}
chaieb@33152
  1531
  ultimately show ?case by blast
chaieb@33152
  1532
next
chaieb@33152
  1533
  case (6 c e)  hence nbe: "tmbound0 e" by simp
chaieb@33152
  1534
  from prems have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1535
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1536
  note eqs = lt[OF nc(1), where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] le[OF nc(2), where ?'a = 'a]
chaieb@33152
  1537
  let ?c = "Ipoly vs c"
chaieb@33152
  1538
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1539
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1540
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1541
  moreover {assume cp: "?c > 0"
chaieb@33152
  1542
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1543
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1544
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1545
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1546
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1547
  moreover {assume cp: "?c < 0"
chaieb@33152
  1548
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1549
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1550
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1551
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1552
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1553
  ultimately show ?case by blast
chaieb@33152
  1554
qed (auto)
chaieb@33152
  1555
chaieb@33152
  1556
lemma minusinf_nb: "islin p \<Longrightarrow> bound0 (minusinf p)" 
chaieb@33152
  1557
  by (induct p rule: minusinf.induct, auto simp add: eq_nb lt_nb le_nb)
chaieb@33152
  1558
lemma plusinf_nb: "islin p \<Longrightarrow> bound0 (plusinf p)" 
chaieb@33152
  1559
  by (induct p rule: minusinf.induct, auto simp add: eq_nb lt_nb le_nb)
chaieb@33152
  1560
chaieb@33152
  1561
lemma minusinf_ex: assumes lp: "islin p" and ex: "Ifm vs (x#bs) (minusinf p)"
chaieb@33152
  1562
  shows "\<exists>x. Ifm vs (x#bs) p"
chaieb@33152
  1563
proof-
chaieb@33152
  1564
  from bound0_I [OF minusinf_nb[OF lp], where b="a" and bs ="bs"] ex
chaieb@33152
  1565
  have th: "\<forall> x. Ifm vs (x#bs) (minusinf p)" by auto
chaieb@33152
  1566
  from minusinf_inf[OF lp, where bs="bs"] 
chaieb@33152
  1567
  obtain z where z_def: "\<forall>x<z. Ifm vs (x # bs) (minusinf p) = Ifm vs (x # bs) p" by blast
chaieb@33152
  1568
  from th have "Ifm vs ((z - 1)#bs) (minusinf p)" by simp
chaieb@33152
  1569
  moreover have "z - 1 < z" by simp
chaieb@33152
  1570
  ultimately show ?thesis using z_def by auto
chaieb@33152
  1571
qed
chaieb@33152
  1572
chaieb@33152
  1573
lemma plusinf_ex: assumes lp: "islin p" and ex: "Ifm vs (x#bs) (plusinf p)"
chaieb@33152
  1574
  shows "\<exists>x. Ifm vs (x#bs) p"
chaieb@33152
  1575
proof-
chaieb@33152
  1576
  from bound0_I [OF plusinf_nb[OF lp], where b="a" and bs ="bs"] ex
chaieb@33152
  1577
  have th: "\<forall> x. Ifm vs (x#bs) (plusinf p)" by auto
chaieb@33152
  1578
  from plusinf_inf[OF lp, where bs="bs"] 
chaieb@33152
  1579
  obtain z where z_def: "\<forall>x>z. Ifm vs (x # bs) (plusinf p) = Ifm vs (x # bs) p" by blast
chaieb@33152
  1580
  from th have "Ifm vs ((z + 1)#bs) (plusinf p)" by simp
chaieb@33152
  1581
  moreover have "z + 1 > z" by simp
chaieb@33152
  1582
  ultimately show ?thesis using z_def by auto
chaieb@33152
  1583
qed
chaieb@33152
  1584
chaieb@33152
  1585
fun uset :: "fm \<Rightarrow> (poly \<times> tm) list" where
chaieb@33152
  1586
  "uset (And p q) = uset p @ uset q"
chaieb@33152
  1587
| "uset (Or p q) = uset p @ uset q"
chaieb@33152
  1588
| "uset (Eq (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1589
| "uset (Le (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1590
| "uset (Lt (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1591
| "uset (NEq (CNP 0 a e)) = [(a,e)]"
chaieb@33152
  1592
| "uset p = []"
chaieb@33152
  1593
chaieb@33152
  1594
lemma uset_l:
chaieb@33152
  1595
  assumes lp: "islin p"
chaieb@33152
  1596
  shows "\<forall> (c,s) \<in> set (uset p). isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s"
chaieb@33152
  1597
using lp by(induct p rule: uset.induct,auto)
chaieb@33152
  1598
chaieb@33152
  1599
lemma minusinf_uset0:
chaieb@33152
  1600
  assumes lp: "islin p"
chaieb@33152
  1601
  and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))"
chaieb@33152
  1602
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1603
  shows "\<exists> (c,s) \<in> set (uset p). x \<ge> - Itm vs (x#bs) s / Ipoly vs c" 
chaieb@33152
  1604
proof-
chaieb@33152
  1605
  have "\<exists> (c,s) \<in> set (uset p). (Ipoly vs c < 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s) \<or>  (Ipoly vs c > 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s)" 
chaieb@33152
  1606
    using lp nmi ex
chaieb@33152
  1607
    apply (induct p rule: minusinf.induct, auto simp add: eq le lt nth_pos2 polyneg_norm)
chaieb@33152
  1608
    apply (auto simp add: linorder_not_less order_le_less)
chaieb@33152
  1609
    done 
chaieb@33152
  1610
  then obtain c s where csU: "(c,s) \<in> set (uset p)" and x: "(Ipoly vs c < 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s) \<or>  (Ipoly vs c > 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s)" by blast
chaieb@33152
  1611
  hence "x \<ge> (- Itm vs (x#bs) s) / Ipoly vs c"
chaieb@33152
  1612
    using divide_le_eq[of "- Itm vs (x#bs) s" "Ipoly vs c" x]
chaieb@33152
  1613
    by (auto simp add: mult_commute del: divide_minus_left)
chaieb@33152
  1614
  thus ?thesis using csU by auto
chaieb@33152
  1615
qed
chaieb@33152
  1616
chaieb@33152
  1617
lemma minusinf_uset:
chaieb@33152
  1618
  assumes lp: "islin p"
chaieb@33152
  1619
  and nmi: "\<not> (Ifm vs (a#bs) (minusinf p))"
chaieb@33152
  1620
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1621
  shows "\<exists> (c,s) \<in> set (uset p). x \<ge> - Itm vs (a#bs) s / Ipoly vs c" 
chaieb@33152
  1622
proof-
chaieb@33152
  1623
  from nmi have nmi': "\<not> (Ifm vs (x#bs) (minusinf p))" 
chaieb@33152
  1624
    by (simp add: bound0_I[OF minusinf_nb[OF lp], where b=x and b'=a])
chaieb@33152
  1625
  from minusinf_uset0[OF lp nmi' ex] 
chaieb@33152
  1626
  obtain c s where csU: "(c,s) \<in> set (uset p)" and th: "x \<ge> - Itm vs (x#bs) s / Ipoly vs c" by blast
chaieb@33152
  1627
  from uset_l[OF lp, rule_format, OF csU] have nb: "tmbound0 s" by simp
chaieb@33152
  1628
  from th tmbound0_I[OF nb, of vs x bs a] csU show ?thesis by auto
chaieb@33152
  1629
qed
chaieb@33152
  1630
chaieb@33152
  1631
chaieb@33152
  1632
lemma plusinf_uset0:
chaieb@33152
  1633
  assumes lp: "islin p"
chaieb@33152
  1634
  and nmi: "\<not> (Ifm vs (x#bs) (plusinf p))"
chaieb@33152
  1635
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1636
  shows "\<exists> (c,s) \<in> set (uset p). x \<le> - Itm vs (x#bs) s / Ipoly vs c" 
chaieb@33152
  1637
proof-
chaieb@33152
  1638
  have "\<exists> (c,s) \<in> set (uset p). (Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s) \<or>  (Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s)" 
chaieb@33152
  1639
    using lp nmi ex
chaieb@33152
  1640
    apply (induct p rule: minusinf.induct, auto simp add: eq le lt nth_pos2 polyneg_norm)
chaieb@33152
  1641
    apply (auto simp add: linorder_not_less order_le_less)
chaieb@33152
  1642
    done 
chaieb@33152
  1643
  then obtain c s where csU: "(c,s) \<in> set (uset p)" and x: "(Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s) \<or>  (Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s)" by blast
chaieb@33152
  1644
  hence "x \<le> (- Itm vs (x#bs) s) / Ipoly vs c"
chaieb@33152
  1645
    using le_divide_eq[of x "- Itm vs (x#bs) s" "Ipoly vs c"]
chaieb@33152
  1646
    by (auto simp add: mult_commute del: divide_minus_left)
chaieb@33152
  1647
  thus ?thesis using csU by auto
chaieb@33152
  1648
qed
chaieb@33152
  1649
chaieb@33152
  1650
lemma plusinf_uset:
chaieb@33152
  1651
  assumes lp: "islin p"
chaieb@33152
  1652
  and nmi: "\<not> (Ifm vs (a#bs) (plusinf p))"
chaieb@33152
  1653
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1654
  shows "\<exists> (c,s) \<in> set (uset p). x \<le> - Itm vs (a#bs) s / Ipoly vs c" 
chaieb@33152
  1655
proof-
chaieb@33152
  1656
  from nmi have nmi': "\<not> (Ifm vs (x#bs) (plusinf p))" 
chaieb@33152
  1657
    by (simp add: bound0_I[OF plusinf_nb[OF lp], where b=x and b'=a])
chaieb@33152
  1658
  from plusinf_uset0[OF lp nmi' ex] 
chaieb@33152
  1659
  obtain c s where csU: "(c,s) \<in> set (uset p)" and th: "x \<le> - Itm vs (x#bs) s / Ipoly vs c" by blast
chaieb@33152
  1660
  from uset_l[OF lp, rule_format, OF csU] have nb: "tmbound0 s" by simp
chaieb@33152
  1661
  from th tmbound0_I[OF nb, of vs x bs a] csU show ?thesis by auto
chaieb@33152
  1662
qed
chaieb@33152
  1663
chaieb@33152
  1664
lemma lin_dense: 
chaieb@33152
  1665
  assumes lp: "islin p"
chaieb@33152
  1666
  and noS: "\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> (\<lambda> (c,t). - Itm vs (x#bs) t / Ipoly vs c) ` set (uset p)" 
chaieb@33152
  1667
  (is "\<forall> t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda> (c,t). - ?Nt x t / ?N c) ` ?U p")
chaieb@33152
  1668
  and lx: "l < x" and xu:"x < u" and px:" Ifm vs (x#bs) p"
chaieb@33152
  1669
  and ly: "l < y" and yu: "y < u"
chaieb@33152
  1670
  shows "Ifm vs (y#bs) p"
chaieb@33152
  1671
using lp px noS
chaieb@33152
  1672
proof (induct p rule: islin.induct) 
chaieb@33152
  1673
  case (5 c s)
chaieb@33152
  1674
  from "5.prems" 
chaieb@33152
  1675
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1676
    and px: "Ifm vs (x # bs) (Lt (CNP 0 c s))"
chaieb@33152
  1677
    and noS: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> - Itm vs (x # bs) s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp_all
chaieb@33152
  1678
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1679
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1680
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1681
  moreover
chaieb@33152
  1682
  {assume "?N c = 0" hence ?case using px by (simp add: tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"])}
chaieb@33152
  1683
  moreover
chaieb@33152
  1684
  {assume c: "?N c > 0"
chaieb@33152
  1685
      from px pos_less_divide_eq[OF c, where a="x" and b="-?Nt x s"]  
chaieb@33152
  1686
      have px': "x < - ?Nt x s / ?N c" 
haftmann@36348
  1687
        by (auto simp add: not_less field_simps) 
chaieb@33152
  1688
    {assume y: "y < - ?Nt x s / ?N c" 
chaieb@33152
  1689
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1690
        by (simp add: pos_less_divide_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36348
  1691
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1692
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1693
    moreover
chaieb@33152
  1694
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1695
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1696
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1697
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1698
    ultimately have ?case using ycs by blast
chaieb@33152
  1699
  }
chaieb@33152
  1700
  moreover
chaieb@33152
  1701
  {assume c: "?N c < 0"
chaieb@33152
  1702
      from px neg_divide_less_eq[OF c, where a="x" and b="-?Nt x s"]  
chaieb@33152
  1703
      have px': "x > - ?Nt x s / ?N c" 
haftmann@36348
  1704
        by (auto simp add: not_less field_simps) 
chaieb@33152
  1705
    {assume y: "y > - ?Nt x s / ?N c" 
chaieb@33152
  1706
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1707
        by (simp add: neg_divide_less_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36348
  1708
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1709
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1710
    moreover
chaieb@33152
  1711
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1712
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1713
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1714
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1715
    ultimately have ?case using ycs by blast
chaieb@33152
  1716
  }
chaieb@33152
  1717
  ultimately show ?case by blast
chaieb@33152
  1718
next
chaieb@33152
  1719
  case (6 c s)
chaieb@33152
  1720
  from "6.prems" 
chaieb@33152
  1721
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1722
    and px: "Ifm vs (x # bs) (Le (CNP 0 c s))"
chaieb@33152
  1723
    and noS: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> - Itm vs (x # bs) s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp_all
chaieb@33152
  1724
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1725
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1726
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1727
  moreover
chaieb@33152
  1728
  {assume "?N c = 0" hence ?case using px by (simp add: tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"])}
chaieb@33152
  1729
  moreover
chaieb@33152
  1730
  {assume c: "?N c > 0"
chaieb@33152
  1731
      from px pos_le_divide_eq[OF c, where a="x" and b="-?Nt x s"]  
haftmann@36348
  1732
      have px': "x <= - ?Nt x s / ?N c" by (simp add: not_less field_simps) 
chaieb@33152
  1733
    {assume y: "y < - ?Nt x s / ?N c" 
chaieb@33152
  1734
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1735
        by (simp add: pos_less_divide_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36348
  1736
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1737
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1738
    moreover
chaieb@33152
  1739
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1740
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1741
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1742
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1743
    ultimately have ?case using ycs by blast
chaieb@33152
  1744
  }
chaieb@33152
  1745
  moreover
chaieb@33152
  1746
  {assume c: "?N c < 0"
chaieb@33152
  1747
      from px neg_divide_le_eq[OF c, where a="x" and b="-?Nt x s"]  
haftmann@36348
  1748
      have px': "x >= - ?Nt x s / ?N c" by (simp add: field_simps) 
chaieb@33152
  1749
    {assume y: "y > - ?Nt x s / ?N c" 
chaieb@33152
  1750
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1751
        by (simp add: neg_divide_less_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36348
  1752
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1753
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1754
    moreover
chaieb@33152
  1755
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1756
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1757
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1758
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1759
    ultimately have ?case using ycs by blast
chaieb@33152
  1760
  }
chaieb@33152
  1761
  ultimately show ?case by blast
chaieb@33152
  1762
next
chaieb@33152
  1763
    case (3 c s)
chaieb@33152
  1764
  from "3.prems" 
chaieb@33152
  1765
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1766
    and px: "Ifm vs (x # bs) (Eq (CNP 0 c s))"
chaieb@33152
  1767
    and noS: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> - Itm vs (x # bs) s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp_all
chaieb@33152
  1768
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1769
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1770
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1771
  moreover
chaieb@33152
  1772
  {assume "?N c = 0" hence ?case using px by (simp add: tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"])}
chaieb@33152
  1773
  moreover
chaieb@33152
  1774
  {assume c: "?N c > 0" hence cnz: "?N c \<noteq> 0" by simp
chaieb@33152
  1775
    from px eq_divide_eq[of "x" "-?Nt x s" "?N c"]  cnz
haftmann@36348
  1776
    have px': "x = - ?Nt x s / ?N c" by (simp add: field_simps)
chaieb@33152
  1777
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1778
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1779
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1780
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1781
    moreover
chaieb@33152
  1782
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1783
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1784
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1785
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1786
    ultimately have ?case using ycs by blast
chaieb@33152
  1787
  }
chaieb@33152
  1788
  moreover
chaieb@33152
  1789
  {assume c: "?N c < 0" hence cnz: "?N c \<noteq> 0" by simp
chaieb@33152
  1790
    from px eq_divide_eq[of "x" "-?Nt x s" "?N c"]  cnz
haftmann@36348
  1791
    have px': "x = - ?Nt x s / ?N c" by (simp add: field_simps)
chaieb@33152
  1792
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1793
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1794
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1795
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1796
    moreover
chaieb@33152
  1797
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1798
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1799
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1800
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1801
    ultimately have ?case using ycs by blast
chaieb@33152
  1802
  }
chaieb@33152
  1803
  ultimately show ?case by blast
chaieb@33152
  1804
next
chaieb@33152
  1805
    case (4 c s)
chaieb@33152
  1806
  from "4.prems" 
chaieb@33152
  1807
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1808
    and px: "Ifm vs (x # bs) (NEq (CNP 0 c s))"
chaieb@33152
  1809
    and noS: "\<forall>t. l < t \<and> t < u \<longrightarrow> t \<noteq> - Itm vs (x # bs) s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp_all
chaieb@33152
  1810
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1811
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1812
  have ccs: "?N c = 0 \<or> ?N c \<noteq> 0" by dlo
chaieb@33152
  1813
  moreover
chaieb@33152
  1814
  {assume "?N c = 0" hence ?case using px by (simp add: tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"])}
chaieb@33152
  1815
  moreover
chaieb@33152
  1816
  {assume c: "?N c \<noteq> 0"
chaieb@33152
  1817
    from yne c eq_divide_eq[of "y" "- ?Nt x s" "?N c"] have ?case
haftmann@36348
  1818
      by (simp add: field_simps tmbound0_I[OF lin(3), of vs x bs y] sum_eq[symmetric]) }
chaieb@33152
  1819
  ultimately show ?case by blast
chaieb@33152
  1820
qed (auto simp add: nth_pos2 tmbound0_I[where vs=vs and bs="bs" and b="y" and b'="x"] bound0_I[where vs=vs and bs="bs" and b="y" and b'="x"])
chaieb@33152
  1821
haftmann@35028
  1822
lemma one_plus_one_pos[simp]: "(1::'a::{linordered_field}) + 1 > 0"
chaieb@33152
  1823
proof-
chaieb@33152
  1824
  have op: "(1::'a) > 0" by simp
chaieb@33152
  1825
  from add_pos_pos[OF op op] show ?thesis . 
chaieb@33152
  1826
qed
chaieb@33152
  1827
haftmann@35028
  1828
lemma one_plus_one_nonzero[simp]: "(1::'a::{linordered_field}) + 1 \<noteq> 0" 
chaieb@33152
  1829
  using one_plus_one_pos[where ?'a = 'a] by (simp add: less_le) 
chaieb@33152
  1830
haftmann@35028
  1831
lemma half_sum_eq: "(u + u) / (1+1) = (u::'a::{linordered_field})" 
chaieb@33152
  1832
proof-
haftmann@36348
  1833
  have "(u + u) = (1 + 1) * u" by (simp add: field_simps)
chaieb@33152
  1834
  hence "(u + u) / (1+1) = (1 + 1)*u / (1 + 1)" by simp
chaieb@33152
  1835
  with nonzero_mult_divide_cancel_left[OF one_plus_one_nonzero, of u] show ?thesis by simp
chaieb@33152
  1836
qed
chaieb@33152
  1837
chaieb@33152
  1838
lemma inf_uset:
chaieb@33152
  1839
  assumes lp: "islin p"
chaieb@33152
  1840
  and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))" (is "\<not> (Ifm vs (x#bs) (?M p))")
chaieb@33152
  1841
  and npi: "\<not> (Ifm vs (x#bs) (plusinf p))" (is "\<not> (Ifm vs (x#bs) (?P p))")
chaieb@33152
  1842
  and ex: "\<exists> x.  Ifm vs (x#bs) p" (is "\<exists> x. ?I x p")
chaieb@33152
  1843
  shows "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- Itm vs (x#bs) t / Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) / (1 + 1)) p" 
chaieb@33152
  1844
proof-
chaieb@33152
  1845
  let ?Nt = "\<lambda> x t. Itm vs (x#bs) t"
chaieb@33152
  1846
  let ?N = "Ipoly vs"
chaieb@33152
  1847
  let ?U = "set (uset p)"
chaieb@33152
  1848
  from ex obtain a where pa: "?I a p" by blast
chaieb@33152
  1849
  from bound0_I[OF minusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] nmi
chaieb@33152
  1850
  have nmi': "\<not> (?I a (?M p))" by simp
chaieb@33152
  1851
  from bound0_I[OF plusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] npi
chaieb@33152
  1852
  have npi': "\<not> (?I a (?P p))" by simp
chaieb@33152
  1853
  have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- ?Nt a t/?N c + - ?Nt a s /?N d) / (1 + 1)) p"
chaieb@33152
  1854
  proof-
chaieb@33152
  1855
    let ?M = "(\<lambda> (c,t). - ?Nt a t / ?N c) ` ?U"
chaieb@33152
  1856
    have fM: "finite ?M" by auto
chaieb@33152
  1857
    from minusinf_uset[OF lp nmi pa] plusinf_uset[OF lp npi pa] 
chaieb@33152
  1858
    have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). a \<le> - ?Nt x t / ?N c \<and> a \<ge> - ?Nt x s / ?N d" by blast
chaieb@33152
  1859
    then obtain "c" "t" "d" "s" where 
chaieb@33152
  1860
      ctU: "(c,t) \<in> ?U" and dsU: "(d,s) \<in> ?U" 
chaieb@33152
  1861
      and xs1: "a \<le> - ?Nt x s / ?N d" and tx1: "a \<ge> - ?Nt x t / ?N c" by blast
chaieb@33152
  1862
    from uset_l[OF lp] ctU dsU tmbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 
chaieb@33152
  1863
    have xs: "a \<le> - ?Nt a s / ?N d" and tx: "a \<ge> - ?Nt a t / ?N c" by auto
chaieb@33152
  1864
    from ctU have Mne: "?M \<noteq> {}" by auto
chaieb@33152
  1865
    hence Une: "?U \<noteq> {}" by simp
chaieb@33152
  1866
    let ?l = "Min ?M"
chaieb@33152
  1867
    let ?u = "Max ?M"
chaieb@33152
  1868
    have linM: "?l \<in> ?M" using fM Mne by simp
chaieb@33152
  1869
    have uinM: "?u \<in> ?M" using fM Mne by simp
chaieb@33152
  1870
    have ctM: "- ?Nt a t / ?N c \<in> ?M" using ctU by auto
chaieb@33152
  1871
    have dsM: "- ?Nt a s / ?N d \<in> ?M" using dsU by auto 
chaieb@33152
  1872
    have lM: "\<forall> t\<in> ?M. ?l \<le> t" using Mne fM by auto
chaieb@33152
  1873
    have Mu: "\<forall> t\<in> ?M. t \<le> ?u" using Mne fM by auto
chaieb@33152
  1874
    have "?l \<le> - ?Nt a t / ?N c" using ctM Mne by simp hence lx: "?l \<le> a" using tx by simp
chaieb@33152
  1875
    have "- ?Nt a s / ?N d \<le> ?u" using dsM Mne by simp hence xu: "a \<le> ?u" using xs by simp
chaieb@33152
  1876
    from finite_set_intervals2[where P="\<lambda> x. ?I x p",OF pa lx xu linM uinM fM lM Mu]
chaieb@33152
  1877
    have "(\<exists> s\<in> ?M. ?I s p) \<or> 
chaieb@33152
  1878
      (\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p)" .
chaieb@33152
  1879
    moreover {fix u assume um: "u\<in> ?M" and pu: "?I u p"
chaieb@33152
  1880
      hence "\<exists> (nu,tu) \<in> ?U. u = - ?Nt a tu / ?N nu" by auto
chaieb@33152
  1881
      then obtain "tu" "nu" where tuU: "(nu,tu) \<in> ?U" and tuu:"u= - ?Nt a tu / ?N nu" by blast
chaieb@33152
  1882
      from half_sum_eq[of u] pu tuu 
chaieb@33152
  1883
      have "?I (((- ?Nt a tu / ?N nu) + (- ?Nt a tu / ?N nu)) / (1 + 1)) p" by simp
chaieb@33152
  1884
      with tuU have ?thesis by blast}
chaieb@33152
  1885
    moreover{
chaieb@33152
  1886
      assume "\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p"
chaieb@33152
  1887
      then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" 
wenzelm@33268
  1888
        and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p"
wenzelm@33268
  1889
        by blast
chaieb@33152
  1890
      from t1M have "\<exists> (t1n,t1u) \<in> ?U. t1 = - ?Nt a t1u / ?N t1n" by auto
chaieb@33152
  1891
      then obtain "t1u" "t1n" where t1uU: "(t1n,t1u) \<in> ?U" and t1u: "t1 = - ?Nt a t1u / ?N t1n" by blast
chaieb@33152
  1892
      from t2M have "\<exists> (t2n,t2u) \<in> ?U. t2 = - ?Nt a t2u / ?N t2n" by auto
chaieb@33152
  1893
      then obtain "t2u" "t2n" where t2uU: "(t2n,t2u) \<in> ?U" and t2u: "t2 = - ?Nt a t2u / ?N t2n" by blast
chaieb@33152
  1894
      from t1x xt2 have t1t2: "t1 < t2" by simp
chaieb@33152
  1895
      let ?u = "(t1 + t2) / (1 + 1)"
chaieb@33152
  1896
      from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
chaieb@33152
  1897
      from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
chaieb@33152
  1898
      with t1uU t2uU t1u t2u have ?thesis by blast}
chaieb@33152
  1899
    ultimately show ?thesis by blast
chaieb@33152
  1900
  qed
chaieb@33152
  1901
  then obtain "l" "n" "s"  "m" where lnU: "(n,l) \<in> ?U" and smU:"(m,s) \<in> ?U" 
chaieb@33152
  1902
    and pu: "?I ((- ?Nt a l / ?N n + - ?Nt a s / ?N m) / (1 + 1)) p" by blast
chaieb@33152
  1903
  from lnU smU uset_l[OF lp] have nbl: "tmbound0 l" and nbs: "tmbound0 s" by auto
chaieb@33152
  1904
  from tmbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] 
chaieb@33152
  1905
    tmbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
chaieb@33152
  1906
  have "?I ((- ?Nt x l / ?N n + - ?Nt x s / ?N m) / (1 + 1)) p" by simp
chaieb@33152
  1907
  with lnU smU
chaieb@33152
  1908
  show ?thesis by auto
chaieb@33152
  1909
qed
chaieb@33152
  1910
chaieb@33152
  1911
    (* The Ferrante - Rackoff Theorem *)
chaieb@33152
  1912
chaieb@33152
  1913
theorem fr_eq: 
chaieb@33152
  1914
  assumes lp: "islin p"
chaieb@33152
  1915
  shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) /(1 + 1))#bs) p))"
chaieb@33152
  1916
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
chaieb@33152
  1917
proof
chaieb@33152
  1918
  assume px: "\<exists> x. ?I x p"
chaieb@33152
  1919
  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
chaieb@33152
  1920
  moreover {assume "?M \<or> ?P" hence "?D" by blast}
chaieb@33152
  1921
  moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
chaieb@33152
  1922
    from inf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast}
chaieb@33152
  1923
  ultimately show "?D" by blast
chaieb@33152
  1924
next
chaieb@33152
  1925
  assume "?D" 
chaieb@33152
  1926
  moreover {assume m:"?M" from minusinf_ex[OF lp m] have "?E" .}
chaieb@33152
  1927
  moreover {assume p: "?P" from plusinf_ex[OF lp p] have "?E" . }
chaieb@33152
  1928
  moreover {assume f:"?F" hence "?E" by blast}
chaieb@33152
  1929
  ultimately show "?E" by blast
chaieb@33152
  1930
qed
chaieb@33152
  1931
chaieb@33152
  1932
section{* First implementation : Naive by encoding all case splits locally *}
chaieb@33152
  1933
definition "msubsteq c t d s a r = 
chaieb@33152
  1934
  evaldjf (split conj) 
chaieb@33152
  1935
  [(let cd = c *\<^sub>p d in (NEq (CP cd), Eq (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  1936
   (conj (Eq (CP c)) (NEq (CP d)) , Eq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  1937
   (conj (NEq (CP c)) (Eq (CP d)) , Eq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  1938
   (conj (Eq (CP c)) (Eq (CP d)) , Eq r)]"
chaieb@33152
  1939
chaieb@33152
  1940
lemma msubsteq_nb: assumes lp: "islin (Eq (CNP 0 a r))" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  1941
  shows "bound0 (msubsteq c t d s a r)"
chaieb@33152
  1942
proof-
chaieb@33152
  1943
  have th: "\<forall>x\<in> set [(let cd = c *\<^sub>p d in (NEq (CP cd), Eq (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  1944
   (conj (Eq (CP c)) (NEq (CP d)) , Eq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  1945
   (conj (NEq (CP c)) (Eq (CP d)) , Eq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  1946
   (conj (Eq (CP c)) (Eq (CP d)) , Eq r)]. bound0 (split conj x)"
chaieb@33152
  1947
    using lp by (simp add: Let_def t s )
chaieb@33152
  1948
  from evaldjf_bound0[OF th] show ?thesis by (simp add: msubsteq_def)
chaieb@33152
  1949
qed
chaieb@33152
  1950
chaieb@33152
  1951
lemma msubsteq: assumes lp: "islin (Eq (CNP 0 a r))"
chaieb@33152
  1952
  shows "Ifm vs (x#bs) (msubsteq c t d s a r) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Eq (CNP 0 a r))" (is "?lhs = ?rhs")
chaieb@33152
  1953
proof-
chaieb@33152
  1954
  let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
chaieb@33152
  1955
  let ?N = "\<lambda>p. Ipoly vs p"
chaieb@33152
  1956
  let ?c = "?N c"
chaieb@33152
  1957
  let ?d = "?N d"
chaieb@33152
  1958
  let ?t = "?Nt x t"
chaieb@33152
  1959
  let ?s = "?Nt x s"
chaieb@33152
  1960
  let ?a = "?N a"
chaieb@33152
  1961
  let ?r = "?Nt x r"
chaieb@33152
  1962
  from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r" by simp_all
chaieb@33152
  1963
  note r= tmbound0_I[OF lin(3), of vs _ bs x]
chaieb@33152
  1964
  have cd_cs: "?c * ?d \<noteq> 0 \<or> (?c = 0 \<and> ?d = 0) \<or> (?c = 0 \<and> ?d \<noteq> 0) \<or> (?c \<noteq> 0 \<and> ?d = 0)" by auto
chaieb@33152
  1965
  moreover
chaieb@33152
  1966
  {assume c: "?c = 0" and d: "?d=0"
chaieb@33152
  1967
    hence ?thesis  by (simp add: r[of 0] msubsteq_def Let_def evaldjf_ex)}
chaieb@33152
  1968
  moreover 
chaieb@33152
  1969
  {assume c: "?c = 0" and d: "?d\<noteq>0"
chaieb@33152
  1970
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?s / ((1 + 1)*?d)" by simp
chaieb@33152
  1971
    have "?rhs = Ifm vs (-?s / ((1 + 1)*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  1972
    also have "\<dots> \<longleftrightarrow> ?a * (-?s / ((1 + 1)*?d)) + ?r = 0" by (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
chaieb@33152
  1973
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a * (-?s / ((1 + 1)*?d)) + ?r) = 0" 
chaieb@33152
  1974
      using d mult_cancel_left[of "(1 + 1)*?d" "(?a * (-?s / ((1 + 1)*?d)) + ?r)" 0] by simp
chaieb@33152
  1975
    also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * ((1 + 1)*?d / ((1 + 1)*?d)) + (1 + 1)*?d*?r= 0"
haftmann@36348
  1976
      by (simp add: field_simps right_distrib[of "(1 + 1)*?d"] del: right_distrib)
chaieb@33152
  1977
    
chaieb@33152
  1978
    also have "\<dots> \<longleftrightarrow> - (?a * ?s) + (1 + 1)*?d*?r = 0" using d by simp 
chaieb@33152
  1979
    finally have ?thesis using c d 
chaieb@33152
  1980
      apply (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
chaieb@33152
  1981
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  1982
      apply simp
chaieb@33152
  1983
      done}
chaieb@33152
  1984
  moreover
chaieb@33152
  1985
  {assume c: "?c \<noteq> 0" and d: "?d=0"
chaieb@33152
  1986
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?t / ((1 + 1)*?c)" by simp
chaieb@33152
  1987
    have "?rhs = Ifm vs (-?t / ((1 + 1)*?c) # bs) (Eq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  1988
    also have "\<dots> \<longleftrightarrow> ?a * (-?t / ((1 + 1)*?c)) + ?r = 0" by (simp add: r[of "- (?t/ ((1 + 1)* ?c))"])
chaieb@33152
  1989
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a * (-?t / ((1 + 1)*?c)) + ?r) = 0" 
chaieb@33152
  1990
      using c mult_cancel_left[of "(1 + 1)*?c" "(?a * (-?t / ((1 + 1)*?c)) + ?r)" 0] by simp
chaieb@33152
  1991
    also have "\<dots> \<longleftrightarrow> (?a * -?t)* ((1 + 1)*?c) / ((1 + 1)*?c) + (1 + 1)*?c*?r= 0"
haftmann@36348
  1992
      by (simp add: field_simps right_distrib[of "(1 + 1)*?c"] del: right_distrib)
chaieb@33152
  1993
    also have "\<dots> \<longleftrightarrow> - (?a * ?t) + (1 + 1)*?c*?r = 0" using c by simp 
chaieb@33152
  1994
    finally have ?thesis using c d 
chaieb@33152
  1995
      apply (simp add: r[of "- (?t/ ((1 + 1)*?c))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
chaieb@33152
  1996
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  1997
      apply simp
chaieb@33152
  1998
      done }
chaieb@33152
  1999
  moreover
chaieb@33152
  2000
  {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *(1 + 1) \<noteq> 0" by simp