src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
author wenzelm
Sun, 15 May 2011 17:45:53 +0200
changeset 43685 5af15f1e2ef6
parent 43239 3b8498ac2314
child 44884 5cfc1c36ae97
permissions -rw-r--r--
simplified/unified method_setup/attribute_setup;
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
nipkow@42720
     8
imports Reflected_Multivariate_Polynomial Dense_Linear_Order DP_Library
wenzelm@41661
     9
  "~~/src/HOL/Library/Efficient_Nat"
chaieb@33152
    10
begin
chaieb@33152
    11
chaieb@33152
    12
subsection {* Terms *}
chaieb@33152
    13
chaieb@33152
    14
datatype tm = CP poly | Bound nat | Add tm tm | Mul poly tm 
chaieb@33152
    15
  | Neg tm | Sub tm tm | CNP nat poly tm
chaieb@33152
    16
  (* A size for poly to make inductive proofs simpler*)
chaieb@33152
    17
haftmann@39473
    18
primrec tmsize :: "tm \<Rightarrow> nat" where
chaieb@33152
    19
  "tmsize (CP c) = polysize c"
haftmann@39473
    20
| "tmsize (Bound n) = 1"
haftmann@39473
    21
| "tmsize (Neg a) = 1 + tmsize a"
haftmann@39473
    22
| "tmsize (Add a b) = 1 + tmsize a + tmsize b"
haftmann@39473
    23
| "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
haftmann@39473
    24
| "tmsize (Mul c a) = 1 + polysize c + tmsize a"
haftmann@39473
    25
| "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
chaieb@33152
    26
chaieb@33152
    27
  (* Semantics of terms tm *)
haftmann@39473
    28
primrec Itm :: "'a::{field_char_0, field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a" where
chaieb@33152
    29
  "Itm vs bs (CP c) = (Ipoly vs c)"
haftmann@39473
    30
| "Itm vs bs (Bound n) = bs!n"
haftmann@39473
    31
| "Itm vs bs (Neg a) = -(Itm vs bs a)"
haftmann@39473
    32
| "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
haftmann@39473
    33
| "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
haftmann@39473
    34
| "Itm vs bs (Mul c a) = (Ipoly vs c) * Itm vs bs a"
haftmann@39473
    35
| "Itm vs bs (CNP n c t) = (Ipoly vs c)*(bs!n) + Itm vs bs t"   
chaieb@33152
    36
chaieb@33152
    37
chaieb@33152
    38
fun allpolys:: "(poly \<Rightarrow> bool) \<Rightarrow> tm \<Rightarrow> bool"  where
chaieb@33152
    39
  "allpolys P (CP c) = P c"
chaieb@33152
    40
| "allpolys P (CNP n c p) = (P c \<and> allpolys P p)"
chaieb@33152
    41
| "allpolys P (Mul c p) = (P c \<and> allpolys P p)"
chaieb@33152
    42
| "allpolys P (Neg p) = allpolys P p"
chaieb@33152
    43
| "allpolys P (Add p q) = (allpolys P p \<and> allpolys P q)"
chaieb@33152
    44
| "allpolys P (Sub p q) = (allpolys P p \<and> allpolys P q)"
chaieb@33152
    45
| "allpolys P p = True"
chaieb@33152
    46
haftmann@39473
    47
primrec tmboundslt:: "nat \<Rightarrow> tm \<Rightarrow> bool" where
chaieb@33152
    48
  "tmboundslt n (CP c) = True"
haftmann@39473
    49
| "tmboundslt n (Bound m) = (m < n)"
haftmann@39473
    50
| "tmboundslt n (CNP m c a) = (m < n \<and> tmboundslt n a)"
haftmann@39473
    51
| "tmboundslt n (Neg a) = tmboundslt n a"
haftmann@39473
    52
| "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
haftmann@39473
    53
| "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)" 
haftmann@39473
    54
| "tmboundslt n (Mul i a) = tmboundslt n a"
haftmann@39473
    55
haftmann@39473
    56
primrec tmbound0:: "tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound 0 *) where
chaieb@33152
    57
  "tmbound0 (CP c) = True"
haftmann@39473
    58
| "tmbound0 (Bound n) = (n>0)"
haftmann@39473
    59
| "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
haftmann@39473
    60
| "tmbound0 (Neg a) = tmbound0 a"
haftmann@39473
    61
| "tmbound0 (Add a b) = (tmbound0 a \<and> tmbound0 b)"
haftmann@39473
    62
| "tmbound0 (Sub a b) = (tmbound0 a \<and> tmbound0 b)" 
haftmann@39473
    63
| "tmbound0 (Mul i a) = tmbound0 a"
chaieb@33152
    64
lemma tmbound0_I:
chaieb@33152
    65
  assumes nb: "tmbound0 a"
chaieb@33152
    66
  shows "Itm vs (b#bs) a = Itm vs (b'#bs) a"
chaieb@33152
    67
using nb
nipkow@42713
    68
by (induct a rule: tm.induct,auto)
chaieb@33152
    69
haftmann@39473
    70
primrec tmbound:: "nat \<Rightarrow> tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound n *) where
chaieb@33152
    71
  "tmbound n (CP c) = True"
haftmann@39473
    72
| "tmbound n (Bound m) = (n \<noteq> m)"
haftmann@39473
    73
| "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
haftmann@39473
    74
| "tmbound n (Neg a) = tmbound n a"
haftmann@39473
    75
| "tmbound n (Add a b) = (tmbound n a \<and> tmbound n b)"
haftmann@39473
    76
| "tmbound n (Sub a b) = (tmbound n a \<and> tmbound n b)" 
haftmann@39473
    77
| "tmbound n (Mul i a) = tmbound n a"
chaieb@33152
    78
lemma tmbound0_tmbound_iff: "tmbound 0 t = tmbound0 t" by (induct t, auto)
chaieb@33152
    79
chaieb@33152
    80
lemma tmbound_I: 
chaieb@33152
    81
  assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound n t" and le: "n \<le> length bs"
chaieb@33152
    82
  shows "Itm vs (bs[n:=x]) t = Itm vs bs t"
chaieb@33152
    83
  using nb le bnd
haftmann@39473
    84
  by (induct t rule: tm.induct , auto)
haftmann@39473
    85
krauss@42692
    86
fun decrtm0:: "tm \<Rightarrow> tm" where
krauss@42692
    87
  "decrtm0 (Bound n) = Bound (n - 1)"
krauss@42692
    88
| "decrtm0 (Neg a) = Neg (decrtm0 a)"
krauss@42692
    89
| "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)"
krauss@42692
    90
| "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)"
krauss@42692
    91
| "decrtm0 (Mul c a) = Mul c (decrtm0 a)"
krauss@42692
    92
| "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)"
krauss@42692
    93
| "decrtm0 a = a"
chaieb@33152
    94
krauss@42692
    95
fun incrtm0:: "tm \<Rightarrow> tm" where
chaieb@33152
    96
  "incrtm0 (Bound n) = Bound (n + 1)"
krauss@42692
    97
| "incrtm0 (Neg a) = Neg (incrtm0 a)"
krauss@42692
    98
| "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)"
krauss@42692
    99
| "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)"
krauss@42692
   100
| "incrtm0 (Mul c a) = Mul c (incrtm0 a)"
krauss@42692
   101
| "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)"
krauss@42692
   102
| "incrtm0 a = a"
haftmann@39473
   103
chaieb@33152
   104
lemma decrtm0: assumes nb: "tmbound0 t"
chaieb@33152
   105
  shows "Itm vs (x#bs) t = Itm vs bs (decrtm0 t)"
nipkow@42713
   106
  using nb by (induct t rule: decrtm0.induct, simp_all)
haftmann@39473
   107
chaieb@33152
   108
lemma incrtm0: "Itm vs (x#bs) (incrtm0 t) = Itm vs bs t"
nipkow@42713
   109
  by (induct t rule: decrtm0.induct, simp_all)
chaieb@33152
   110
haftmann@39473
   111
primrec decrtm:: "nat \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   112
  "decrtm m (CP c) = (CP c)"
haftmann@39473
   113
| "decrtm m (Bound n) = (if n < m then Bound n else Bound (n - 1))"
haftmann@39473
   114
| "decrtm m (Neg a) = Neg (decrtm m a)"
haftmann@39473
   115
| "decrtm m (Add a b) = Add (decrtm m a) (decrtm m b)"
haftmann@39473
   116
| "decrtm m (Sub a b) = Sub (decrtm m a) (decrtm m b)"
haftmann@39473
   117
| "decrtm m (Mul c a) = Mul c (decrtm m a)"
haftmann@39473
   118
| "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
   119
haftmann@39473
   120
primrec removen:: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list" where
chaieb@33152
   121
  "removen n [] = []"
haftmann@39473
   122
| "removen n (x#xs) = (if n=0 then xs else (x#(removen (n - 1) xs)))"
chaieb@33152
   123
chaieb@33152
   124
lemma removen_same: "n \<ge> length xs \<Longrightarrow> removen n xs = xs"
chaieb@33152
   125
  by (induct xs arbitrary: n, auto)
chaieb@33152
   126
chaieb@33152
   127
lemma nth_length_exceeds: "n \<ge> length xs \<Longrightarrow> xs!n = []!(n - length xs)"
chaieb@33152
   128
  by (induct xs arbitrary: n, auto)
chaieb@33152
   129
chaieb@33152
   130
lemma removen_length: "length (removen n xs) = (if n \<ge> length xs then length xs else length xs - 1)"
chaieb@33152
   131
  by (induct xs arbitrary: n, auto)
chaieb@33152
   132
lemma removen_nth: "(removen n xs)!m = (if n \<ge> length xs then xs!m 
chaieb@33152
   133
  else if m < n then xs!m else if m \<le> length xs then xs!(Suc m) else []!(m - (length xs - 1)))"
chaieb@33152
   134
proof(induct xs arbitrary: n m)
chaieb@33152
   135
  case Nil thus ?case by simp
chaieb@33152
   136
next
chaieb@33152
   137
  case (Cons x xs n m)
chaieb@33152
   138
  {assume nxs: "n \<ge> length (x#xs)" hence ?case using removen_same[OF nxs] by simp}
chaieb@33152
   139
  moreover
chaieb@33152
   140
  {assume nxs: "\<not> (n \<ge> length (x#xs))" 
wenzelm@42686
   141
    {assume mln: "m < n" hence ?case using Cons by (cases m, auto)}
chaieb@33152
   142
    moreover
chaieb@33152
   143
    {assume mln: "\<not> (m < n)" 
wenzelm@42686
   144
      {assume mxs: "m \<le> length (x#xs)" hence ?case using Cons by (cases m, auto)}
chaieb@33152
   145
      moreover
chaieb@33152
   146
      {assume mxs: "\<not> (m \<le> length (x#xs))" 
wenzelm@33268
   147
        have th: "length (removen n (x#xs)) = length xs" 
wenzelm@33268
   148
          using removen_length[where n="n" and xs="x#xs"] nxs by simp
wenzelm@33268
   149
        with mxs have mxs':"m \<ge> length (removen n (x#xs))" by auto
wenzelm@33268
   150
        hence "(removen n (x#xs))!m = [] ! (m - length xs)" 
wenzelm@33268
   151
          using th nth_length_exceeds[OF mxs'] by auto
wenzelm@33268
   152
        hence th: "(removen n (x#xs))!m = [] ! (m - (length (x#xs) - 1))" 
wenzelm@33268
   153
          by auto
wenzelm@33268
   154
        hence ?case using nxs mln mxs by auto }
chaieb@33152
   155
      ultimately have ?case by blast
chaieb@33152
   156
    }
chaieb@33152
   157
    ultimately have ?case by blast
wenzelm@42686
   158
  } ultimately show ?case by blast
chaieb@33152
   159
qed
chaieb@33152
   160
chaieb@33152
   161
lemma decrtm: assumes bnd: "tmboundslt (length bs) t" and nb: "tmbound m t" 
chaieb@33152
   162
  and nle: "m \<le> length bs" 
chaieb@33152
   163
  shows "Itm vs (removen m bs) (decrtm m t) = Itm vs bs t"
wenzelm@42686
   164
  using bnd nb nle by (induct t rule: tm.induct) (auto simp add: removen_nth)
chaieb@33152
   165
haftmann@39473
   166
primrec tmsubst0:: "tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   167
  "tmsubst0 t (CP c) = CP c"
haftmann@39473
   168
| "tmsubst0 t (Bound n) = (if n=0 then t else Bound n)"
haftmann@39473
   169
| "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@39473
   170
| "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
haftmann@39473
   171
| "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
haftmann@39473
   172
| "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)" 
haftmann@39473
   173
| "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
chaieb@33152
   174
lemma tmsubst0:
chaieb@33152
   175
  shows "Itm vs (x#bs) (tmsubst0 t a) = Itm vs ((Itm vs (x#bs) t)#bs) a"
nipkow@42713
   176
  by (induct a rule: tm.induct) auto
chaieb@33152
   177
chaieb@33152
   178
lemma tmsubst0_nb: "tmbound0 t \<Longrightarrow> tmbound0 (tmsubst0 t a)"
nipkow@42713
   179
  by (induct a rule: tm.induct) auto
chaieb@33152
   180
haftmann@39473
   181
primrec tmsubst:: "nat \<Rightarrow> tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   182
  "tmsubst n t (CP c) = CP c"
haftmann@39473
   183
| "tmsubst n t (Bound m) = (if n=m then t else Bound m)"
haftmann@39473
   184
| "tmsubst n t (CNP m c a) = (if n=m then Add (Mul c t) (tmsubst n t a) 
chaieb@33152
   185
             else CNP m c (tmsubst n t a))"
haftmann@39473
   186
| "tmsubst n t (Neg a) = Neg (tmsubst n t a)"
haftmann@39473
   187
| "tmsubst n t (Add a b) = Add (tmsubst n t a) (tmsubst n t b)"
haftmann@39473
   188
| "tmsubst n t (Sub a b) = Sub (tmsubst n t a) (tmsubst n t b)" 
haftmann@39473
   189
| "tmsubst n t (Mul i a) = Mul i (tmsubst n t a)"
chaieb@33152
   190
chaieb@33152
   191
lemma tmsubst: assumes nb: "tmboundslt (length bs) a" and nlt: "n \<le> length bs"
chaieb@33152
   192
  shows "Itm vs bs (tmsubst n t a) = Itm vs (bs[n:= Itm vs bs t]) a"
chaieb@33152
   193
using nb nlt
nipkow@42713
   194
by (induct a rule: tm.induct,auto)
chaieb@33152
   195
chaieb@33152
   196
lemma tmsubst_nb0: assumes tnb: "tmbound0 t"
chaieb@33152
   197
shows "tmbound0 (tmsubst 0 t a)"
chaieb@33152
   198
using tnb
haftmann@39473
   199
by (induct a rule: tm.induct, auto)
chaieb@33152
   200
chaieb@33152
   201
lemma tmsubst_nb: assumes tnb: "tmbound m t"
chaieb@33152
   202
shows "tmbound m (tmsubst m t a)"
chaieb@33152
   203
using tnb
haftmann@39473
   204
by (induct a rule: tm.induct, auto)
chaieb@33152
   205
lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)"
chaieb@33152
   206
  by (induct t, auto)
chaieb@33152
   207
  (* Simplification *)
chaieb@33152
   208
chaieb@33152
   209
consts
chaieb@33152
   210
  tmadd:: "tm \<times> tm \<Rightarrow> tm"
chaieb@33152
   211
recdef tmadd "measure (\<lambda> (t,s). size t + size s)"
chaieb@33152
   212
  "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) =
chaieb@33152
   213
  (if n1=n2 then 
chaieb@33152
   214
  (let c = c1 +\<^sub>p c2
chaieb@33152
   215
  in if c = 0\<^sub>p then tmadd(r1,r2) else CNP n1 c (tmadd (r1,r2)))
chaieb@33152
   216
  else if n1 \<le> n2 then (CNP n1 c1 (tmadd (r1,CNP n2 c2 r2))) 
chaieb@33152
   217
  else (CNP n2 c2 (tmadd (CNP n1 c1 r1,r2))))"
chaieb@33152
   218
  "tmadd (CNP n1 c1 r1,t) = CNP n1 c1 (tmadd (r1, t))"  
chaieb@33152
   219
  "tmadd (t,CNP n2 c2 r2) = CNP n2 c2 (tmadd (t,r2))" 
chaieb@33152
   220
  "tmadd (CP b1, CP b2) = CP (b1 +\<^sub>p b2)"
chaieb@33152
   221
  "tmadd (a,b) = Add a b"
chaieb@33152
   222
chaieb@33152
   223
lemma tmadd[simp]: "Itm vs bs (tmadd (t,s)) = Itm vs bs (Add t s)"
chaieb@33152
   224
apply (induct t s rule: tmadd.induct, simp_all add: Let_def)
chaieb@33152
   225
apply (case_tac "c1 +\<^sub>p c2 = 0\<^sub>p",case_tac "n1 \<le> n2", simp_all)
haftmann@36347
   226
apply (case_tac "n1 = n2", simp_all add: field_simps)
chaieb@33152
   227
apply (simp only: right_distrib[symmetric]) 
chaieb@33152
   228
by (auto simp del: polyadd simp add: polyadd[symmetric])
chaieb@33152
   229
chaieb@33152
   230
lemma tmadd_nb0[simp]: "\<lbrakk> tmbound0 t ; tmbound0 s\<rbrakk> \<Longrightarrow> tmbound0 (tmadd (t,s))"
chaieb@33152
   231
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   232
chaieb@33152
   233
lemma tmadd_nb[simp]: "\<lbrakk> tmbound n t ; tmbound n s\<rbrakk> \<Longrightarrow> tmbound n (tmadd (t,s))"
chaieb@33152
   234
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   235
lemma tmadd_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmadd (t,s))"
chaieb@33152
   236
by (induct t s rule: tmadd.induct, auto simp add: Let_def)
chaieb@33152
   237
chaieb@33152
   238
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
   239
krauss@42692
   240
fun tmmul:: "tm \<Rightarrow> poly \<Rightarrow> tm" where
chaieb@33152
   241
  "tmmul (CP j) = (\<lambda> i. CP (i *\<^sub>p j))"
krauss@42692
   242
| "tmmul (CNP n c a) = (\<lambda> i. CNP n (i *\<^sub>p c) (tmmul a i))"
krauss@42692
   243
| "tmmul t = (\<lambda> i. Mul i t)"
chaieb@33152
   244
chaieb@33152
   245
lemma tmmul[simp]: "Itm vs bs (tmmul t i) = Itm vs bs (Mul i t)"
haftmann@36347
   246
by (induct t arbitrary: i rule: tmmul.induct, simp_all add: field_simps)
chaieb@33152
   247
chaieb@33152
   248
lemma tmmul_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmmul t i)"
chaieb@33152
   249
by (induct t arbitrary: i rule: tmmul.induct, auto )
chaieb@33152
   250
chaieb@33152
   251
lemma tmmul_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (tmmul t i)"
chaieb@33152
   252
by (induct t arbitrary: n rule: tmmul.induct, auto )
chaieb@33152
   253
lemma tmmul_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmmul t i)"
chaieb@33152
   254
by (induct t arbitrary: i rule: tmmul.induct, auto simp add: Let_def)
chaieb@33152
   255
chaieb@33152
   256
lemma tmmul_allpolys_npoly[simp]: 
haftmann@36409
   257
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   258
  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
   259
haftmann@35413
   260
definition tmneg :: "tm \<Rightarrow> tm" where
chaieb@33152
   261
  "tmneg t \<equiv> tmmul t (C (- 1,1))"
chaieb@33152
   262
haftmann@35413
   263
definition tmsub :: "tm \<Rightarrow> tm \<Rightarrow> tm" where
chaieb@33152
   264
  "tmsub s t \<equiv> (if s = t then CP 0\<^sub>p else tmadd (s,tmneg t))"
chaieb@33152
   265
chaieb@33152
   266
lemma tmneg[simp]: "Itm vs bs (tmneg t) = Itm vs bs (Neg t)"
chaieb@33152
   267
using tmneg_def[of t] 
chaieb@33152
   268
apply simp
chaieb@33152
   269
apply (subst number_of_Min)
chaieb@33152
   270
apply (simp only: of_int_minus)
chaieb@33152
   271
apply simp
chaieb@33152
   272
done
chaieb@33152
   273
chaieb@33152
   274
lemma tmneg_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmneg t)"
chaieb@33152
   275
using tmneg_def by simp
chaieb@33152
   276
chaieb@33152
   277
lemma tmneg_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (tmneg t)"
chaieb@33152
   278
using tmneg_def by simp
chaieb@33152
   279
lemma tmneg_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmneg t)"
chaieb@33152
   280
using tmneg_def by simp
chaieb@33152
   281
lemma [simp]: "isnpoly (C (-1,1))" unfolding isnpoly_def by simp
chaieb@33152
   282
lemma tmneg_allpolys_npoly[simp]: 
haftmann@36409
   283
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   284
  shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly (tmneg t)" 
chaieb@33152
   285
  unfolding tmneg_def by auto
chaieb@33152
   286
chaieb@33152
   287
lemma tmsub[simp]: "Itm vs bs (tmsub a b) = Itm vs bs (Sub a b)"
chaieb@33152
   288
using tmsub_def by simp
chaieb@33152
   289
chaieb@33152
   290
lemma tmsub_nb0[simp]: "\<lbrakk> tmbound0 t ; tmbound0 s\<rbrakk> \<Longrightarrow> tmbound0 (tmsub t s)"
chaieb@33152
   291
using tmsub_def by simp
chaieb@33152
   292
lemma tmsub_nb[simp]: "\<lbrakk> tmbound n t ; tmbound n s\<rbrakk> \<Longrightarrow> tmbound n (tmsub t s)"
chaieb@33152
   293
using tmsub_def by simp
chaieb@33152
   294
lemma tmsub_blt[simp]: "\<lbrakk>tmboundslt n t ; tmboundslt n s\<rbrakk> \<Longrightarrow> tmboundslt n (tmsub t s )"
chaieb@33152
   295
using tmsub_def by simp
chaieb@33152
   296
lemma tmsub_allpolys_npoly[simp]: 
haftmann@36409
   297
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   298
  shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)" 
chaieb@33152
   299
  unfolding tmsub_def by (simp add: isnpoly_def)
chaieb@33152
   300
krauss@42692
   301
fun simptm:: "tm \<Rightarrow> tm" where
chaieb@33152
   302
  "simptm (CP j) = CP (polynate j)"
krauss@42692
   303
| "simptm (Bound n) = CNP n 1\<^sub>p (CP 0\<^sub>p)"
krauss@42692
   304
| "simptm (Neg t) = tmneg (simptm t)"
krauss@42692
   305
| "simptm (Add t s) = tmadd (simptm t,simptm s)"
krauss@42692
   306
| "simptm (Sub t s) = tmsub (simptm t) (simptm s)"
krauss@42692
   307
| "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
krauss@42692
   308
| "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
   309
chaieb@33152
   310
lemma polynate_stupid: 
haftmann@36409
   311
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
haftmann@36409
   312
  shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a::{field_char_0, field_inverse_zero})" 
chaieb@33152
   313
apply (subst polynate[symmetric])
chaieb@33152
   314
apply simp
chaieb@33152
   315
done
chaieb@33152
   316
chaieb@33152
   317
lemma simptm_ci[simp]: "Itm vs bs (simptm t) = Itm vs bs t"
chaieb@33152
   318
by (induct t rule: simptm.induct, auto simp add: tmneg tmadd tmsub tmmul Let_def polynate_stupid) 
chaieb@33152
   319
chaieb@33152
   320
lemma simptm_tmbound0[simp]: 
chaieb@33152
   321
  "tmbound0 t \<Longrightarrow> tmbound0 (simptm t)"
chaieb@33152
   322
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   323
chaieb@33152
   324
lemma simptm_nb[simp]: "tmbound n t \<Longrightarrow> tmbound n (simptm t)"
chaieb@33152
   325
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   326
lemma simptm_nlt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (simptm t)"
chaieb@33152
   327
by (induct t rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   328
chaieb@33152
   329
lemma [simp]: "isnpoly 0\<^sub>p" and [simp]: "isnpoly (C(1,1))" 
chaieb@33152
   330
  by (simp_all add: isnpoly_def)
chaieb@33152
   331
lemma simptm_allpolys_npoly[simp]: 
haftmann@36409
   332
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   333
  shows "allpolys isnpoly (simptm p)"
chaieb@33152
   334
  by (induct p rule: simptm.induct, auto simp add: Let_def)
chaieb@33152
   335
krauss@42693
   336
declare let_cong[fundef_cong del]
krauss@42693
   337
krauss@42693
   338
fun split0 :: "tm \<Rightarrow> (poly \<times> tm)" where
chaieb@33152
   339
  "split0 (Bound 0) = (1\<^sub>p, CP 0\<^sub>p)"
krauss@42693
   340
| "split0 (CNP 0 c t) = (let (c',t') = split0 t in (c +\<^sub>p c',t'))"
krauss@42693
   341
| "split0 (Neg t) = (let (c,t') = split0 t in (~\<^sub>p c,Neg t'))"
krauss@42693
   342
| "split0 (CNP n c t) = (let (c',t') = split0 t in (c',CNP n c t'))"
krauss@42693
   343
| "split0 (Add s t) = (let (c1,s') = split0 s ; (c2,t') = split0 t in (c1 +\<^sub>p c2, Add s' t'))"
krauss@42693
   344
| "split0 (Sub s t) = (let (c1,s') = split0 s ; (c2,t') = split0 t in (c1 -\<^sub>p c2, Sub s' t'))"
krauss@42693
   345
| "split0 (Mul c t) = (let (c',t') = split0 t in (c *\<^sub>p c', Mul c t'))"
krauss@42693
   346
| "split0 t = (0\<^sub>p, t)"
krauss@42693
   347
krauss@42693
   348
declare let_cong[fundef_cong]
chaieb@33152
   349
chaieb@33152
   350
lemma split0_stupid[simp]: "\<exists>x y. (x,y) = split0 p"
chaieb@33152
   351
  apply (rule exI[where x="fst (split0 p)"])
chaieb@33152
   352
  apply (rule exI[where x="snd (split0 p)"])
chaieb@33152
   353
  by simp
chaieb@33152
   354
chaieb@33152
   355
lemma split0:
chaieb@33152
   356
  "tmbound 0 (snd (split0 t)) \<and> (Itm vs bs (CNP 0 (fst (split0 t)) (snd (split0 t))) = Itm vs bs t)"
chaieb@33152
   357
  apply (induct t rule: split0.induct)
chaieb@33152
   358
  apply simp
haftmann@36347
   359
  apply (simp add: Let_def split_def field_simps)
haftmann@36347
   360
  apply (simp add: Let_def split_def field_simps)
haftmann@36347
   361
  apply (simp add: Let_def split_def field_simps)
haftmann@36347
   362
  apply (simp add: Let_def split_def field_simps)
haftmann@36347
   363
  apply (simp add: Let_def split_def field_simps)
chaieb@33152
   364
  apply (simp add: Let_def split_def mult_assoc right_distrib[symmetric])
haftmann@36347
   365
  apply (simp add: Let_def split_def field_simps)
haftmann@36347
   366
  apply (simp add: Let_def split_def field_simps)
chaieb@33152
   367
  done
chaieb@33152
   368
chaieb@33152
   369
lemma split0_ci: "split0 t = (c',t') \<Longrightarrow> Itm vs bs t = Itm vs bs (CNP 0 c' t')"
chaieb@33152
   370
proof-
chaieb@33152
   371
  fix c' t'
chaieb@33152
   372
  assume "split0 t = (c', t')" hence "c' = fst (split0 t)" and "t' = snd (split0 t)" by auto
chaieb@33152
   373
  with split0[where t="t" and bs="bs"] show "Itm vs bs t = Itm vs bs (CNP 0 c' t')" by simp
chaieb@33152
   374
qed
chaieb@33152
   375
chaieb@33152
   376
lemma split0_nb0: 
haftmann@36409
   377
  assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   378
  shows "split0 t = (c',t') \<Longrightarrow>  tmbound 0 t'"
chaieb@33152
   379
proof-
chaieb@33152
   380
  fix c' t'
chaieb@33152
   381
  assume "split0 t = (c', t')" hence "c' = fst (split0 t)" and "t' = snd (split0 t)" by auto
chaieb@33152
   382
  with conjunct1[OF split0[where t="t"]] show "tmbound 0 t'" by simp
chaieb@33152
   383
qed
chaieb@33152
   384
haftmann@36409
   385
lemma split0_nb0'[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   386
  shows "tmbound0 (snd (split0 t))"
chaieb@33152
   387
  using split0_nb0[of t "fst (split0 t)" "snd (split0 t)"] by (simp add: tmbound0_tmbound_iff)
chaieb@33152
   388
chaieb@33152
   389
chaieb@33152
   390
lemma split0_nb: assumes nb:"tmbound n t" shows "tmbound n (snd (split0 t))"
chaieb@33152
   391
  using nb by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   392
chaieb@33152
   393
lemma split0_blt: assumes nb:"tmboundslt n t" shows "tmboundslt n (snd (split0 t))"
chaieb@33152
   394
  using nb by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   395
chaieb@33152
   396
lemma tmbound_split0: "tmbound 0 t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0"
chaieb@33152
   397
 by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   398
chaieb@33152
   399
lemma tmboundslt_split0: "tmboundslt n t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0 \<or> n > 0"
chaieb@33152
   400
by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   401
chaieb@33152
   402
lemma tmboundslt0_split0: "tmboundslt 0 t \<Longrightarrow> Ipoly vs (fst(split0 t)) = 0"
chaieb@33152
   403
 by (induct t rule: split0.induct, auto simp add: Let_def split_def split0_stupid)
chaieb@33152
   404
chaieb@33152
   405
lemma allpolys_split0: "allpolys isnpoly p \<Longrightarrow> allpolys isnpoly (snd (split0 p))"
chaieb@33152
   406
by (induct p rule: split0.induct, auto simp  add: isnpoly_def Let_def split_def split0_stupid)
chaieb@33152
   407
haftmann@36409
   408
lemma isnpoly_fst_split0:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   409
  shows 
chaieb@33152
   410
  "allpolys isnpoly p \<Longrightarrow> isnpoly (fst (split0 p))"
chaieb@33152
   411
  by (induct p rule: split0.induct, 
chaieb@33152
   412
    auto simp  add: polyadd_norm polysub_norm polyneg_norm polymul_norm 
chaieb@33152
   413
    Let_def split_def split0_stupid)
chaieb@33152
   414
chaieb@33152
   415
subsection{* Formulae *}
chaieb@33152
   416
chaieb@33152
   417
datatype fm  =  T| F| Le tm | Lt tm | Eq tm | NEq tm|
chaieb@33152
   418
  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
chaieb@33152
   419
chaieb@33152
   420
chaieb@33152
   421
  (* A size for fm *)
krauss@42693
   422
fun fmsize :: "fm \<Rightarrow> nat" where
chaieb@33152
   423
  "fmsize (NOT p) = 1 + fmsize p"
krauss@42693
   424
| "fmsize (And p q) = 1 + fmsize p + fmsize q"
krauss@42693
   425
| "fmsize (Or p q) = 1 + fmsize p + fmsize q"
krauss@42693
   426
| "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
krauss@42693
   427
| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
krauss@42693
   428
| "fmsize (E p) = 1 + fmsize p"
krauss@42693
   429
| "fmsize (A p) = 4+ fmsize p"
krauss@42693
   430
| "fmsize p = 1"
chaieb@33152
   431
  (* several lemmas about fmsize *)
krauss@42693
   432
lemma fmsize_pos[termination_simp]: "fmsize p > 0"        
chaieb@33152
   433
by (induct p rule: fmsize.induct) simp_all
chaieb@33152
   434
chaieb@33152
   435
  (* Semantics of formulae (fm) *)
haftmann@39473
   436
primrec Ifm ::"'a::{linordered_field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool" where
chaieb@33152
   437
  "Ifm vs bs T = True"
haftmann@39473
   438
| "Ifm vs bs F = False"
haftmann@39473
   439
| "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
haftmann@39473
   440
| "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
haftmann@39473
   441
| "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
haftmann@39473
   442
| "Ifm vs bs (NEq a) = (Itm vs bs a \<noteq> 0)"
haftmann@39473
   443
| "Ifm vs bs (NOT p) = (\<not> (Ifm vs bs p))"
haftmann@39473
   444
| "Ifm vs bs (And p q) = (Ifm vs bs p \<and> Ifm vs bs q)"
haftmann@39473
   445
| "Ifm vs bs (Or p q) = (Ifm vs bs p \<or> Ifm vs bs q)"
haftmann@39473
   446
| "Ifm vs bs (Imp p q) = ((Ifm vs bs p) \<longrightarrow> (Ifm vs bs q))"
haftmann@39473
   447
| "Ifm vs bs (Iff p q) = (Ifm vs bs p = Ifm vs bs q)"
haftmann@39473
   448
| "Ifm vs bs (E p) = (\<exists> x. Ifm vs (x#bs) p)"
haftmann@39473
   449
| "Ifm vs bs (A p) = (\<forall> x. Ifm vs (x#bs) p)"
chaieb@33152
   450
krauss@42693
   451
fun not:: "fm \<Rightarrow> fm" where
chaieb@33152
   452
  "not (NOT (NOT p)) = not p"
krauss@42693
   453
| "not (NOT p) = p"
krauss@42693
   454
| "not T = F"
krauss@42693
   455
| "not F = T"
krauss@42693
   456
| "not (Lt t) = Le (tmneg t)"
krauss@42693
   457
| "not (Le t) = Lt (tmneg t)"
krauss@42693
   458
| "not (Eq t) = NEq t"
krauss@42693
   459
| "not (NEq t) = Eq t"
krauss@42693
   460
| "not p = NOT p"
chaieb@33152
   461
lemma not[simp]: "Ifm vs bs (not p) = Ifm vs bs (NOT p)"
chaieb@33152
   462
by (induct p rule: not.induct) auto
chaieb@33152
   463
haftmann@35413
   464
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   465
  "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
   466
   if p = q then p else And p q)"
chaieb@33152
   467
lemma conj[simp]: "Ifm vs bs (conj p q) = Ifm vs bs (And p q)"
chaieb@33152
   468
by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
chaieb@33152
   469
haftmann@35413
   470
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   471
  "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
   472
       else if p=q then p else Or p q)"
chaieb@33152
   473
chaieb@33152
   474
lemma disj[simp]: "Ifm vs bs (disj p q) = Ifm vs bs (Or p q)"
chaieb@33152
   475
by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
chaieb@33152
   476
haftmann@35413
   477
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   478
  "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
   479
    else Imp p q)"
chaieb@33152
   480
lemma imp[simp]: "Ifm vs bs (imp p q) = Ifm vs bs (Imp p q)"
chaieb@33152
   481
by (cases "p=F \<or> q=T",simp_all add: imp_def) 
chaieb@33152
   482
haftmann@35413
   483
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   484
  "iff p q \<equiv> (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else 
chaieb@33152
   485
       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
   486
  Iff p q)"
chaieb@33152
   487
lemma iff[simp]: "Ifm vs bs (iff p q) = Ifm vs bs (Iff p q)"
chaieb@33152
   488
  by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto)
krauss@42693
   489
chaieb@33152
   490
  (* Quantifier freeness *)
krauss@42693
   491
fun qfree:: "fm \<Rightarrow> bool" where
chaieb@33152
   492
  "qfree (E p) = False"
krauss@42693
   493
| "qfree (A p) = False"
krauss@42693
   494
| "qfree (NOT p) = qfree p" 
krauss@42693
   495
| "qfree (And p q) = (qfree p \<and> qfree q)" 
krauss@42693
   496
| "qfree (Or  p q) = (qfree p \<and> qfree q)" 
krauss@42693
   497
| "qfree (Imp p q) = (qfree p \<and> qfree q)" 
krauss@42693
   498
| "qfree (Iff p q) = (qfree p \<and> qfree q)"
krauss@42693
   499
| "qfree p = True"
chaieb@33152
   500
chaieb@33152
   501
  (* Boundedness and substitution *)
chaieb@33152
   502
haftmann@39473
   503
primrec boundslt :: "nat \<Rightarrow> fm \<Rightarrow> bool" where
chaieb@33152
   504
  "boundslt n T = True"
haftmann@39473
   505
| "boundslt n F = True"
haftmann@39473
   506
| "boundslt n (Lt t) = (tmboundslt n t)"
haftmann@39473
   507
| "boundslt n (Le t) = (tmboundslt n t)"
haftmann@39473
   508
| "boundslt n (Eq t) = (tmboundslt n t)"
haftmann@39473
   509
| "boundslt n (NEq t) = (tmboundslt n t)"
haftmann@39473
   510
| "boundslt n (NOT p) = boundslt n p"
haftmann@39473
   511
| "boundslt n (And p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39473
   512
| "boundslt n (Or p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39473
   513
| "boundslt n (Imp p q) = ((boundslt n p) \<and> (boundslt n q))"
haftmann@39473
   514
| "boundslt n (Iff p q) = (boundslt n p \<and> boundslt n q)"
haftmann@39473
   515
| "boundslt n (E p) = boundslt (Suc n) p"
haftmann@39473
   516
| "boundslt n (A p) = boundslt (Suc n) p"
chaieb@33152
   517
krauss@42693
   518
fun bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
chaieb@33152
   519
  "bound0 T = True"
krauss@42693
   520
| "bound0 F = True"
krauss@42693
   521
| "bound0 (Lt a) = tmbound0 a"
krauss@42693
   522
| "bound0 (Le a) = tmbound0 a"
krauss@42693
   523
| "bound0 (Eq a) = tmbound0 a"
krauss@42693
   524
| "bound0 (NEq a) = tmbound0 a"
krauss@42693
   525
| "bound0 (NOT p) = bound0 p"
krauss@42693
   526
| "bound0 (And p q) = (bound0 p \<and> bound0 q)"
krauss@42693
   527
| "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
krauss@42693
   528
| "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
krauss@42693
   529
| "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
krauss@42693
   530
| "bound0 p = False"
chaieb@33152
   531
lemma bound0_I:
chaieb@33152
   532
  assumes bp: "bound0 p"
chaieb@33152
   533
  shows "Ifm vs (b#bs) p = Ifm vs (b'#bs) p"
chaieb@33152
   534
using bp tmbound0_I[where b="b" and bs="bs" and b'="b'"]
nipkow@42713
   535
by (induct p rule: bound0.induct,auto)
chaieb@33152
   536
haftmann@39473
   537
primrec bound:: "nat \<Rightarrow> fm \<Rightarrow> bool" (* A Formula is independent of Bound n *) where
chaieb@33152
   538
  "bound m T = True"
haftmann@39473
   539
| "bound m F = True"
haftmann@39473
   540
| "bound m (Lt t) = tmbound m t"
haftmann@39473
   541
| "bound m (Le t) = tmbound m t"
haftmann@39473
   542
| "bound m (Eq t) = tmbound m t"
haftmann@39473
   543
| "bound m (NEq t) = tmbound m t"
haftmann@39473
   544
| "bound m (NOT p) = bound m p"
haftmann@39473
   545
| "bound m (And p q) = (bound m p \<and> bound m q)"
haftmann@39473
   546
| "bound m (Or p q) = (bound m p \<and> bound m q)"
haftmann@39473
   547
| "bound m (Imp p q) = ((bound m p) \<and> (bound m q))"
haftmann@39473
   548
| "bound m (Iff p q) = (bound m p \<and> bound m q)"
haftmann@39473
   549
| "bound m (E p) = bound (Suc m) p"
haftmann@39473
   550
| "bound m (A p) = bound (Suc m) p"
chaieb@33152
   551
chaieb@33152
   552
lemma bound_I:
chaieb@33152
   553
  assumes bnd: "boundslt (length bs) p" and nb: "bound n p" and le: "n \<le> length bs"
chaieb@33152
   554
  shows "Ifm vs (bs[n:=x]) p = Ifm vs bs p"
chaieb@33152
   555
  using bnd nb le tmbound_I[where bs=bs and vs = vs]
haftmann@39473
   556
proof(induct p arbitrary: bs n rule: fm.induct)
chaieb@33152
   557
  case (E p bs n) 
chaieb@33152
   558
  {fix y
wenzelm@42686
   559
    from E have bnd: "boundslt (length (y#bs)) p" 
chaieb@33152
   560
      and nb: "bound (Suc n) p" and le: "Suc n \<le> length (y#bs)" by simp+
chaieb@33152
   561
    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
   562
  thus ?case by simp 
chaieb@33152
   563
next
chaieb@33152
   564
  case (A p bs n) {fix y
wenzelm@42686
   565
    from A have bnd: "boundslt (length (y#bs)) p" 
chaieb@33152
   566
      and nb: "bound (Suc n) p" and le: "Suc n \<le> length (y#bs)" by simp+
chaieb@33152
   567
    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
   568
  thus ?case by simp 
chaieb@33152
   569
qed auto
chaieb@33152
   570
krauss@42693
   571
fun decr0 :: "fm \<Rightarrow> fm" where
chaieb@33152
   572
  "decr0 (Lt a) = Lt (decrtm0 a)"
krauss@42693
   573
| "decr0 (Le a) = Le (decrtm0 a)"
krauss@42693
   574
| "decr0 (Eq a) = Eq (decrtm0 a)"
krauss@42693
   575
| "decr0 (NEq a) = NEq (decrtm0 a)"
krauss@42693
   576
| "decr0 (NOT p) = NOT (decr0 p)" 
krauss@42693
   577
| "decr0 (And p q) = conj (decr0 p) (decr0 q)"
krauss@42693
   578
| "decr0 (Or p q) = disj (decr0 p) (decr0 q)"
krauss@42693
   579
| "decr0 (Imp p q) = imp (decr0 p) (decr0 q)"
krauss@42693
   580
| "decr0 (Iff p q) = iff (decr0 p) (decr0 q)"
krauss@42693
   581
| "decr0 p = p"
chaieb@33152
   582
chaieb@33152
   583
lemma decr0: assumes nb: "bound0 p"
chaieb@33152
   584
  shows "Ifm vs (x#bs) p = Ifm vs bs (decr0 p)"
chaieb@33152
   585
  using nb 
chaieb@33152
   586
  by (induct p rule: decr0.induct, simp_all add: decrtm0)
chaieb@33152
   587
haftmann@39473
   588
primrec decr :: "nat \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   589
  "decr m T = T"
haftmann@39473
   590
| "decr m F = F"
haftmann@39473
   591
| "decr m (Lt t) = (Lt (decrtm m t))"
haftmann@39473
   592
| "decr m (Le t) = (Le (decrtm m t))"
haftmann@39473
   593
| "decr m (Eq t) = (Eq (decrtm m t))"
haftmann@39473
   594
| "decr m (NEq t) = (NEq (decrtm m t))"
haftmann@39473
   595
| "decr m (NOT p) = NOT (decr m p)" 
haftmann@39473
   596
| "decr m (And p q) = conj (decr m p) (decr m q)"
haftmann@39473
   597
| "decr m (Or p q) = disj (decr m p) (decr m q)"
haftmann@39473
   598
| "decr m (Imp p q) = imp (decr m p) (decr m q)"
haftmann@39473
   599
| "decr m (Iff p q) = iff (decr m p) (decr m q)"
haftmann@39473
   600
| "decr m (E p) = E (decr (Suc m) p)"
haftmann@39473
   601
| "decr m (A p) = A (decr (Suc m) p)"
chaieb@33152
   602
chaieb@33152
   603
lemma decr: assumes  bnd: "boundslt (length bs) p" and nb: "bound m p" 
chaieb@33152
   604
  and nle: "m < length bs" 
chaieb@33152
   605
  shows "Ifm vs (removen m bs) (decr m p) = Ifm vs bs p"
chaieb@33152
   606
  using bnd nb nle
haftmann@39473
   607
proof(induct p arbitrary: bs m rule: fm.induct)
chaieb@33152
   608
  case (E p bs m) 
chaieb@33152
   609
  {fix x
wenzelm@42686
   610
    from E have bnd: "boundslt (length (x#bs)) p" and nb: "bound (Suc m) p" 
chaieb@33152
   611
  and nle: "Suc m < length (x#bs)" by auto
wenzelm@42686
   612
    from E(1)[OF bnd nb nle] have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p".
chaieb@33152
   613
  } thus ?case by auto 
chaieb@33152
   614
next
chaieb@33152
   615
  case (A p bs m)  
chaieb@33152
   616
  {fix x
wenzelm@42686
   617
    from A have bnd: "boundslt (length (x#bs)) p" and nb: "bound (Suc m) p" 
chaieb@33152
   618
  and nle: "Suc m < length (x#bs)" by auto
wenzelm@42686
   619
    from A(1)[OF bnd nb nle] have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p".
chaieb@33152
   620
  } thus ?case by auto
chaieb@33152
   621
qed (auto simp add: decrtm removen_nth)
chaieb@33152
   622
haftmann@39473
   623
primrec subst0:: "tm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   624
  "subst0 t T = T"
haftmann@39473
   625
| "subst0 t F = F"
haftmann@39473
   626
| "subst0 t (Lt a) = Lt (tmsubst0 t a)"
haftmann@39473
   627
| "subst0 t (Le a) = Le (tmsubst0 t a)"
haftmann@39473
   628
| "subst0 t (Eq a) = Eq (tmsubst0 t a)"
haftmann@39473
   629
| "subst0 t (NEq a) = NEq (tmsubst0 t a)"
haftmann@39473
   630
| "subst0 t (NOT p) = NOT (subst0 t p)"
haftmann@39473
   631
| "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
haftmann@39473
   632
| "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
haftmann@39473
   633
| "subst0 t (Imp p q) = Imp (subst0 t p)  (subst0 t q)"
haftmann@39473
   634
| "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
haftmann@39473
   635
| "subst0 t (E p) = E p"
haftmann@39473
   636
| "subst0 t (A p) = A p"
chaieb@33152
   637
chaieb@33152
   638
lemma subst0: assumes qf: "qfree p"
chaieb@33152
   639
  shows "Ifm vs (x#bs) (subst0 t p) = Ifm vs ((Itm vs (x#bs) t)#bs) p"
chaieb@33152
   640
using qf tmsubst0[where x="x" and bs="bs" and t="t"]
haftmann@39473
   641
by (induct p rule: fm.induct, auto)
chaieb@33152
   642
chaieb@33152
   643
lemma subst0_nb:
chaieb@33152
   644
  assumes bp: "tmbound0 t" and qf: "qfree p"
chaieb@33152
   645
  shows "bound0 (subst0 t p)"
chaieb@33152
   646
using qf tmsubst0_nb[OF bp] bp
haftmann@39473
   647
by (induct p rule: fm.induct, auto)
chaieb@33152
   648
haftmann@39473
   649
primrec subst:: "nat \<Rightarrow> tm \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   650
  "subst n t T = T"
haftmann@39473
   651
| "subst n t F = F"
haftmann@39473
   652
| "subst n t (Lt a) = Lt (tmsubst n t a)"
haftmann@39473
   653
| "subst n t (Le a) = Le (tmsubst n t a)"
haftmann@39473
   654
| "subst n t (Eq a) = Eq (tmsubst n t a)"
haftmann@39473
   655
| "subst n t (NEq a) = NEq (tmsubst n t a)"
haftmann@39473
   656
| "subst n t (NOT p) = NOT (subst n t p)"
haftmann@39473
   657
| "subst n t (And p q) = And (subst n t p) (subst n t q)"
haftmann@39473
   658
| "subst n t (Or p q) = Or (subst n t p) (subst n t q)"
haftmann@39473
   659
| "subst n t (Imp p q) = Imp (subst n t p)  (subst n t q)"
haftmann@39473
   660
| "subst n t (Iff p q) = Iff (subst n t p) (subst n t q)"
haftmann@39473
   661
| "subst n t (E p) = E (subst (Suc n) (incrtm0 t) p)"
haftmann@39473
   662
| "subst n t (A p) = A (subst (Suc n) (incrtm0 t) p)"
chaieb@33152
   663
chaieb@33152
   664
lemma subst: assumes nb: "boundslt (length bs) p" and nlm: "n \<le> length bs"
chaieb@33152
   665
  shows "Ifm vs bs (subst n t p) = Ifm vs (bs[n:= Itm vs bs t]) p"
chaieb@33152
   666
  using nb nlm
haftmann@39473
   667
proof (induct p arbitrary: bs n t rule: fm.induct)
chaieb@33152
   668
  case (E p bs n) 
chaieb@33152
   669
  {fix x 
wenzelm@42686
   670
    from E have bn: "boundslt (length (x#bs)) p" by simp 
wenzelm@42686
   671
    from E have nlm: "Suc n \<le> length (x#bs)" by simp
wenzelm@42686
   672
    from E(1)[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
   673
    hence "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs (x#bs[n:= Itm vs bs t]) p"
chaieb@33152
   674
    by (simp add: incrtm0[where x="x" and bs="bs" and t="t"]) }  
chaieb@33152
   675
thus ?case by simp 
chaieb@33152
   676
next
chaieb@33152
   677
  case (A p bs n)   
chaieb@33152
   678
  {fix x 
wenzelm@42686
   679
    from A have bn: "boundslt (length (x#bs)) p" by simp 
wenzelm@42686
   680
    from A have nlm: "Suc n \<le> length (x#bs)" by simp
wenzelm@42686
   681
    from A(1)[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
   682
    hence "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) = Ifm vs (x#bs[n:= Itm vs bs t]) p"
chaieb@33152
   683
    by (simp add: incrtm0[where x="x" and bs="bs" and t="t"]) }  
chaieb@33152
   684
thus ?case by simp 
chaieb@33152
   685
qed(auto simp add: tmsubst)
chaieb@33152
   686
chaieb@33152
   687
lemma subst_nb: assumes tnb: "tmbound m t"
chaieb@33152
   688
shows "bound m (subst m t p)"
chaieb@33152
   689
using tnb tmsubst_nb incrtm0_tmbound
haftmann@39473
   690
by (induct p arbitrary: m t rule: fm.induct, auto)
chaieb@33152
   691
chaieb@33152
   692
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
chaieb@33152
   693
by (induct p rule: not.induct, auto)
chaieb@33152
   694
lemma not_bn0[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
chaieb@33152
   695
by (induct p rule: not.induct, auto)
chaieb@33152
   696
lemma not_nb[simp]: "bound n p \<Longrightarrow> bound n (not p)"
chaieb@33152
   697
by (induct p rule: not.induct, auto)
chaieb@33152
   698
lemma not_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n (not p)"
chaieb@33152
   699
 by (induct p rule: not.induct, auto)
chaieb@33152
   700
chaieb@33152
   701
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
chaieb@33152
   702
using conj_def by auto 
chaieb@33152
   703
lemma conj_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
chaieb@33152
   704
using conj_def by auto 
chaieb@33152
   705
lemma conj_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (conj p q)"
chaieb@33152
   706
using conj_def by auto 
chaieb@33152
   707
lemma conj_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (conj p q)"
chaieb@33152
   708
using conj_def by auto 
chaieb@33152
   709
chaieb@33152
   710
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
chaieb@33152
   711
using disj_def by auto 
chaieb@33152
   712
lemma disj_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
chaieb@33152
   713
using disj_def by auto 
chaieb@33152
   714
lemma disj_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (disj p q)"
chaieb@33152
   715
using disj_def by auto 
chaieb@33152
   716
lemma disj_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (disj p q)"
chaieb@33152
   717
using disj_def by auto 
chaieb@33152
   718
chaieb@33152
   719
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
chaieb@33152
   720
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
chaieb@33152
   721
lemma imp_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
chaieb@33152
   722
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
chaieb@33152
   723
lemma imp_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (imp p q)"
chaieb@33152
   724
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
chaieb@33152
   725
lemma imp_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (imp p q)"
chaieb@33152
   726
using imp_def by auto 
chaieb@33152
   727
chaieb@33152
   728
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
chaieb@33152
   729
  by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   730
lemma iff_nb0[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
chaieb@33152
   731
using iff_def by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   732
lemma iff_nb[simp]: "\<lbrakk>bound n p ; bound n q\<rbrakk> \<Longrightarrow> bound n (iff p q)"
chaieb@33152
   733
using iff_def by (unfold iff_def,cases "p=q", auto)
chaieb@33152
   734
lemma iff_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (iff p q)"
chaieb@33152
   735
using iff_def by auto 
chaieb@33152
   736
lemma decr0_qf: "bound0 p \<Longrightarrow> qfree (decr0 p)"
chaieb@33152
   737
by (induct p, simp_all)
chaieb@33152
   738
krauss@42693
   739
fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) where
chaieb@33152
   740
  "isatom T = True"
krauss@42693
   741
| "isatom F = True"
krauss@42693
   742
| "isatom (Lt a) = True"
krauss@42693
   743
| "isatom (Le a) = True"
krauss@42693
   744
| "isatom (Eq a) = True"
krauss@42693
   745
| "isatom (NEq a) = True"
krauss@42693
   746
| "isatom p = False"
chaieb@33152
   747
chaieb@33152
   748
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
chaieb@33152
   749
by (induct p, simp_all)
chaieb@33152
   750
haftmann@35413
   751
definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   752
  "djf f p q \<equiv> (if q=T then T else if q=F then f p else 
chaieb@33152
   753
  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
haftmann@35413
   754
definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
chaieb@33152
   755
  "evaldjf f ps \<equiv> foldr (djf f) ps F"
chaieb@33152
   756
chaieb@33152
   757
lemma djf_Or: "Ifm vs bs (djf f p q) = Ifm vs bs (Or (f p) q)"
chaieb@33152
   758
by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
chaieb@33152
   759
(cases "f p", simp_all add: Let_def djf_def) 
chaieb@33152
   760
chaieb@33152
   761
lemma evaldjf_ex: "Ifm vs bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm vs bs (f p))"
chaieb@33152
   762
  by(induct ps, simp_all add: evaldjf_def djf_Or)
chaieb@33152
   763
chaieb@33152
   764
lemma evaldjf_bound0: 
chaieb@33152
   765
  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
chaieb@33152
   766
  shows "bound0 (evaldjf f xs)"
chaieb@33152
   767
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
chaieb@33152
   768
chaieb@33152
   769
lemma evaldjf_qf: 
chaieb@33152
   770
  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
chaieb@33152
   771
  shows "qfree (evaldjf f xs)"
chaieb@33152
   772
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
chaieb@33152
   773
krauss@42693
   774
fun disjuncts :: "fm \<Rightarrow> fm list" where
chaieb@33152
   775
  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
krauss@42693
   776
| "disjuncts F = []"
krauss@42693
   777
| "disjuncts p = [p]"
chaieb@33152
   778
chaieb@33152
   779
lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
   780
by(induct p rule: disjuncts.induct, auto)
chaieb@33152
   781
chaieb@33152
   782
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
chaieb@33152
   783
proof-
chaieb@33152
   784
  assume nb: "bound0 p"
chaieb@33152
   785
  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
chaieb@33152
   786
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   787
qed
chaieb@33152
   788
chaieb@33152
   789
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
chaieb@33152
   790
proof-
chaieb@33152
   791
  assume qf: "qfree p"
chaieb@33152
   792
  hence "list_all qfree (disjuncts p)"
chaieb@33152
   793
    by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   794
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   795
qed
chaieb@33152
   796
haftmann@35413
   797
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   798
  "DJ f p \<equiv> evaldjf f (disjuncts p)"
chaieb@33152
   799
chaieb@33152
   800
lemma DJ: assumes fdj: "\<forall> p q. Ifm vs bs (f (Or p q)) = Ifm vs bs (Or (f p) (f q))"
chaieb@33152
   801
  and fF: "f F = F"
chaieb@33152
   802
  shows "Ifm vs bs (DJ f p) = Ifm vs bs (f p)"
chaieb@33152
   803
proof-
chaieb@33152
   804
  have "Ifm vs bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm vs bs (f q))"
chaieb@33152
   805
    by (simp add: DJ_def evaldjf_ex) 
chaieb@33152
   806
  also have "\<dots> = Ifm vs bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   807
  finally show ?thesis .
chaieb@33152
   808
qed
chaieb@33152
   809
chaieb@33152
   810
lemma DJ_qf: assumes 
chaieb@33152
   811
  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
chaieb@33152
   812
  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
chaieb@33152
   813
proof(clarify)
chaieb@33152
   814
  fix  p assume qf: "qfree p"
chaieb@33152
   815
  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
chaieb@33152
   816
  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
chaieb@33152
   817
  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
chaieb@33152
   818
  
chaieb@33152
   819
  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
chaieb@33152
   820
qed
chaieb@33152
   821
chaieb@33152
   822
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
   823
  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
   824
proof(clarify)
chaieb@33152
   825
  fix p::fm and bs
chaieb@33152
   826
  assume qf: "qfree p"
chaieb@33152
   827
  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
chaieb@33152
   828
  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
chaieb@33152
   829
  have "Ifm vs bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm vs bs (qe q))"
chaieb@33152
   830
    by (simp add: DJ_def evaldjf_ex)
chaieb@33152
   831
  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm vs bs (E q))" using qe disjuncts_qf[OF qf] by auto
chaieb@33152
   832
  also have "\<dots> = Ifm vs bs (E p)" by (induct p rule: disjuncts.induct, auto)
chaieb@33152
   833
  finally show "qfree (DJ qe p) \<and> Ifm vs bs (DJ qe p) = Ifm vs bs (E p)" using qfth by blast
chaieb@33152
   834
qed
chaieb@33152
   835
krauss@42693
   836
fun conjuncts :: "fm \<Rightarrow> fm list" where
chaieb@33152
   837
  "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
krauss@42693
   838
| "conjuncts T = []"
krauss@42693
   839
| "conjuncts p = [p]"
chaieb@33152
   840
haftmann@35413
   841
definition list_conj :: "fm list \<Rightarrow> fm" where
chaieb@33152
   842
  "list_conj ps \<equiv> foldr conj ps T"
chaieb@33152
   843
haftmann@35413
   844
definition CJNB :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
chaieb@33152
   845
  "CJNB f p \<equiv> (let cjs = conjuncts p ; (yes,no) = partition bound0 cjs
chaieb@33152
   846
                   in conj (decr0 (list_conj yes)) (f (list_conj no)))"
chaieb@33152
   847
chaieb@33152
   848
lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). qfree q"
chaieb@33152
   849
proof-
chaieb@33152
   850
  assume qf: "qfree p"
chaieb@33152
   851
  hence "list_all qfree (conjuncts p)"
chaieb@33152
   852
    by (induct p rule: conjuncts.induct, auto)
chaieb@33152
   853
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   854
qed
chaieb@33152
   855
chaieb@33152
   856
lemma conjuncts: "(\<forall> q\<in> set (conjuncts p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
   857
by(induct p rule: conjuncts.induct, auto)
chaieb@33152
   858
chaieb@33152
   859
lemma conjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). bound0 q"
chaieb@33152
   860
proof-
chaieb@33152
   861
  assume nb: "bound0 p"
chaieb@33152
   862
  hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto)
chaieb@33152
   863
  thus ?thesis by (simp only: list_all_iff)
chaieb@33152
   864
qed
chaieb@33152
   865
chaieb@33152
   866
fun islin :: "fm \<Rightarrow> bool" where
chaieb@33152
   867
  "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
   868
| "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
   869
| "islin (Eq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   870
| "islin (NEq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   871
| "islin (Lt (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   872
| "islin (Le (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
chaieb@33152
   873
| "islin (NOT p) = False"
chaieb@33152
   874
| "islin (Imp p q) = False"
chaieb@33152
   875
| "islin (Iff p q) = False"
chaieb@33152
   876
| "islin p = bound0 p"
chaieb@33152
   877
chaieb@33152
   878
lemma islin_stupid: assumes nb: "tmbound0 p"
chaieb@33152
   879
  shows "islin (Lt p)" and "islin (Le p)" and "islin (Eq p)" and "islin (NEq p)"
chaieb@33152
   880
  using nb by (cases p, auto, case_tac nat, auto)+
chaieb@33152
   881
chaieb@33152
   882
definition "lt p = (case p of CP (C c) \<Rightarrow> if 0>\<^sub>N c then T else F| _ \<Rightarrow> Lt p)"
chaieb@33152
   883
definition "le p = (case p of CP (C c) \<Rightarrow> if 0\<ge>\<^sub>N c then T else F | _ \<Rightarrow> Le p)"
haftmann@39093
   884
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
   885
definition "neq p = not (eq p)"
chaieb@33152
   886
chaieb@33152
   887
lemma lt: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (lt p) = Ifm vs bs (Lt p)"
chaieb@33152
   888
  apply(simp add: lt_def)
chaieb@33152
   889
  apply(cases p, simp_all)
chaieb@33152
   890
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   891
  done
chaieb@33152
   892
chaieb@33152
   893
lemma le: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (le p) = Ifm vs bs (Le p)"
chaieb@33152
   894
  apply(simp add: le_def)
chaieb@33152
   895
  apply(cases p, simp_all)
chaieb@33152
   896
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   897
  done
chaieb@33152
   898
chaieb@33152
   899
lemma eq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (eq p) = Ifm vs bs (Eq p)"
chaieb@33152
   900
  apply(simp add: eq_def)
chaieb@33152
   901
  apply(cases p, simp_all)
chaieb@33152
   902
  apply (case_tac poly, simp_all add: isnpoly_def)
chaieb@33152
   903
  done
chaieb@33152
   904
chaieb@33152
   905
lemma neq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (neq p) = Ifm vs bs (NEq p)"
chaieb@33152
   906
  by(simp add: neq_def eq)
chaieb@33152
   907
chaieb@33152
   908
lemma lt_lin: "tmbound0 p \<Longrightarrow> islin (lt p)"
chaieb@33152
   909
  apply (simp add: lt_def)
chaieb@33152
   910
  apply (cases p, simp_all)
chaieb@33152
   911
  apply (case_tac poly, simp_all)
chaieb@33152
   912
  apply (case_tac nat, simp_all)
chaieb@33152
   913
  done
chaieb@33152
   914
chaieb@33152
   915
lemma le_lin: "tmbound0 p \<Longrightarrow> islin (le p)"
chaieb@33152
   916
  apply (simp add: le_def)
chaieb@33152
   917
  apply (cases p, simp_all)
chaieb@33152
   918
  apply (case_tac poly, simp_all)
chaieb@33152
   919
  apply (case_tac nat, simp_all)
chaieb@33152
   920
  done
chaieb@33152
   921
chaieb@33152
   922
lemma eq_lin: "tmbound0 p \<Longrightarrow> islin (eq p)"
chaieb@33152
   923
  apply (simp add: eq_def)
chaieb@33152
   924
  apply (cases p, simp_all)
chaieb@33152
   925
  apply (case_tac poly, simp_all)
chaieb@33152
   926
  apply (case_tac nat, simp_all)
chaieb@33152
   927
  done
chaieb@33152
   928
chaieb@33152
   929
lemma neq_lin: "tmbound0 p \<Longrightarrow> islin (neq p)"
chaieb@33152
   930
  apply (simp add: neq_def eq_def)
chaieb@33152
   931
  apply (cases p, simp_all)
chaieb@33152
   932
  apply (case_tac poly, simp_all)
chaieb@33152
   933
  apply (case_tac nat, simp_all)
chaieb@33152
   934
  done
chaieb@33152
   935
chaieb@33152
   936
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
   937
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
   938
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
   939
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
   940
haftmann@36409
   941
lemma simplt_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   942
  shows "islin (simplt t)"
chaieb@33152
   943
  unfolding simplt_def 
chaieb@33152
   944
  using split0_nb0'
chaieb@33152
   945
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
   946
  
haftmann@36409
   947
lemma simple_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   948
  shows "islin (simple t)"
chaieb@33152
   949
  unfolding simple_def 
chaieb@33152
   950
  using split0_nb0'
chaieb@33152
   951
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
   952
lemma simpeq_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   953
  shows "islin (simpeq t)"
chaieb@33152
   954
  unfolding simpeq_def 
chaieb@33152
   955
  using split0_nb0'
chaieb@33152
   956
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
   957
haftmann@36409
   958
lemma simpneq_islin[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   959
  shows "islin (simpneq t)"
chaieb@33152
   960
  unfolding simpneq_def 
chaieb@33152
   961
  using split0_nb0'
chaieb@33152
   962
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
   963
chaieb@33152
   964
lemma really_stupid: "\<not> (\<forall>c1 s'. (c1, s') \<noteq> split0 s)"
chaieb@33152
   965
  by (cases "split0 s", auto)
haftmann@36409
   966
lemma split0_npoly:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
   967
  and n: "allpolys isnpoly t"
chaieb@33152
   968
  shows "isnpoly (fst (split0 t))" and "allpolys isnpoly (snd (split0 t))"
chaieb@33152
   969
  using n
chaieb@33152
   970
  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
   971
lemma simplt[simp]:
chaieb@33152
   972
  shows "Ifm vs bs (simplt t) = Ifm vs bs (Lt t)"
chaieb@33152
   973
proof-
chaieb@33152
   974
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
   975
  let ?t = "simptm t"
chaieb@33152
   976
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
   977
      using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
   978
      by (simp add: simplt_def Let_def split_def lt)}
chaieb@33152
   979
  moreover
chaieb@33152
   980
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
   981
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simplt_def Let_def split_def)
chaieb@33152
   982
  }
chaieb@33152
   983
  ultimately show ?thesis by blast
chaieb@33152
   984
qed
chaieb@33152
   985
chaieb@33152
   986
lemma simple[simp]:
chaieb@33152
   987
  shows "Ifm vs bs (simple t) = Ifm vs bs (Le t)"
chaieb@33152
   988
proof-
chaieb@33152
   989
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
   990
  let ?t = "simptm t"
chaieb@33152
   991
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
   992
      using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
   993
      by (simp add: simple_def Let_def split_def le)}
chaieb@33152
   994
  moreover
chaieb@33152
   995
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
   996
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simple_def Let_def split_def)
chaieb@33152
   997
  }
chaieb@33152
   998
  ultimately show ?thesis by blast
chaieb@33152
   999
qed
chaieb@33152
  1000
chaieb@33152
  1001
lemma simpeq[simp]:
chaieb@33152
  1002
  shows "Ifm vs bs (simpeq t) = Ifm vs bs (Eq t)"
chaieb@33152
  1003
proof-
chaieb@33152
  1004
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
  1005
  let ?t = "simptm t"
chaieb@33152
  1006
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
  1007
      using split0[of "simptm t" vs bs] eq[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
  1008
      by (simp add: simpeq_def Let_def split_def)}
chaieb@33152
  1009
  moreover
chaieb@33152
  1010
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
  1011
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simpeq_def Let_def split_def)
chaieb@33152
  1012
  }
chaieb@33152
  1013
  ultimately show ?thesis by blast
chaieb@33152
  1014
qed
chaieb@33152
  1015
chaieb@33152
  1016
lemma simpneq[simp]:
chaieb@33152
  1017
  shows "Ifm vs bs (simpneq t) = Ifm vs bs (NEq t)"
chaieb@33152
  1018
proof-
chaieb@33152
  1019
  have n: "allpolys isnpoly (simptm t)" by simp
chaieb@33152
  1020
  let ?t = "simptm t"
chaieb@33152
  1021
  {assume "fst (split0 ?t) = 0\<^sub>p" hence ?thesis
chaieb@33152
  1022
      using split0[of "simptm t" vs bs] neq[OF split0_npoly(2)[OF n], of vs bs]
chaieb@33152
  1023
      by (simp add: simpneq_def Let_def split_def )}
chaieb@33152
  1024
  moreover
chaieb@33152
  1025
  {assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
chaieb@33152
  1026
    hence ?thesis using  split0[of "simptm t" vs bs] by (simp add: simpneq_def Let_def split_def)
chaieb@33152
  1027
  }
chaieb@33152
  1028
  ultimately show ?thesis by blast
chaieb@33152
  1029
qed
chaieb@33152
  1030
chaieb@33152
  1031
lemma lt_nb: "tmbound0 t \<Longrightarrow> bound0 (lt t)"
chaieb@33152
  1032
  apply (simp add: lt_def)
chaieb@33152
  1033
  apply (cases t, auto)
chaieb@33152
  1034
  apply (case_tac poly, auto)
chaieb@33152
  1035
  done
chaieb@33152
  1036
chaieb@33152
  1037
lemma le_nb: "tmbound0 t \<Longrightarrow> bound0 (le t)"
chaieb@33152
  1038
  apply (simp add: le_def)
chaieb@33152
  1039
  apply (cases t, auto)
chaieb@33152
  1040
  apply (case_tac poly, auto)
chaieb@33152
  1041
  done
chaieb@33152
  1042
chaieb@33152
  1043
lemma eq_nb: "tmbound0 t \<Longrightarrow> bound0 (eq t)"
chaieb@33152
  1044
  apply (simp add: eq_def)
chaieb@33152
  1045
  apply (cases t, auto)
chaieb@33152
  1046
  apply (case_tac poly, auto)
chaieb@33152
  1047
  done
chaieb@33152
  1048
chaieb@33152
  1049
lemma neq_nb: "tmbound0 t \<Longrightarrow> bound0 (neq t)"
chaieb@33152
  1050
  apply (simp add: neq_def eq_def)
chaieb@33152
  1051
  apply (cases t, auto)
chaieb@33152
  1052
  apply (case_tac poly, auto)
chaieb@33152
  1053
  done
chaieb@33152
  1054
haftmann@36409
  1055
lemma simplt_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1056
  shows "tmbound0 t \<Longrightarrow> bound0 (simplt t)"
chaieb@33152
  1057
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1058
proof(simp add: simplt_def Let_def split_def)
chaieb@33152
  1059
  assume nb: "tmbound0 t"
chaieb@33152
  1060
  hence nb': "tmbound0 (simptm t)" by simp
chaieb@33152
  1061
  let ?c = "fst (split0 (simptm t))"
chaieb@33152
  1062
  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
chaieb@33152
  1063
  have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p" by auto
chaieb@33152
  1064
  from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
chaieb@33152
  1065
  have ths: "isnpolyh ?c 0" "isnpolyh 0\<^sub>p 0" by (simp_all add: isnpoly_def)
chaieb@33152
  1066
  from iffD1[OF isnpolyh_unique[OF ths] th]
chaieb@33152
  1067
  have "fst (split0 (simptm t)) = 0\<^sub>p" . 
chaieb@33152
  1068
  thus "(fst (split0 (simptm t)) = 0\<^sub>p \<longrightarrow> bound0 (lt (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1069
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simplt_def Let_def split_def lt_nb)
chaieb@33152
  1070
qed
chaieb@33152
  1071
haftmann@36409
  1072
lemma simple_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1073
  shows "tmbound0 t \<Longrightarrow> bound0 (simple t)"
chaieb@33152
  1074
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1075
proof(simp add: simple_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 (le (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1086
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simplt_def Let_def split_def le_nb)
chaieb@33152
  1087
qed
chaieb@33152
  1088
haftmann@36409
  1089
lemma simpeq_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1090
  shows "tmbound0 t \<Longrightarrow> bound0 (simpeq t)"
chaieb@33152
  1091
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1092
proof(simp add: simpeq_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 (eq (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1103
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simpeq_def Let_def split_def eq_nb)
chaieb@33152
  1104
qed
chaieb@33152
  1105
haftmann@36409
  1106
lemma simpneq_nb[simp]:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1107
  shows "tmbound0 t \<Longrightarrow> bound0 (simpneq t)"
chaieb@33152
  1108
  using split0 [of "simptm t" vs bs]
chaieb@33152
  1109
proof(simp add: simpneq_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 (neq (snd (split0 (simptm t))))) \<and>
chaieb@33152
  1120
       fst (split0 (simptm t)) = 0\<^sub>p" by (simp add: simpneq_def Let_def split_def neq_nb)
chaieb@33152
  1121
qed
chaieb@33152
  1122
krauss@42693
  1123
fun conjs   :: "fm \<Rightarrow> fm list" where
chaieb@33152
  1124
  "conjs (And p q) = (conjs p)@(conjs q)"
krauss@42693
  1125
| "conjs T = []"
krauss@42693
  1126
| "conjs p = [p]"
chaieb@33152
  1127
lemma conjs_ci: "(\<forall> q \<in> set (conjs p). Ifm vs bs q) = Ifm vs bs p"
chaieb@33152
  1128
by (induct p rule: conjs.induct, auto)
haftmann@35413
  1129
definition list_disj :: "fm list \<Rightarrow> fm" where
chaieb@33152
  1130
  "list_disj ps \<equiv> foldr disj ps F"
chaieb@33152
  1131
chaieb@33152
  1132
lemma list_conj: "Ifm vs bs (list_conj ps) = (\<forall>p\<in> set ps. Ifm vs bs p)"
chaieb@33152
  1133
  by (induct ps, auto simp add: list_conj_def)
chaieb@33152
  1134
lemma list_conj_qf: " \<forall>p\<in> set ps. qfree p \<Longrightarrow> qfree (list_conj ps)"
chaieb@33152
  1135
  by (induct ps, auto simp add: list_conj_def conj_qf)
chaieb@33152
  1136
lemma list_disj: "Ifm vs bs (list_disj ps) = (\<exists>p\<in> set ps. Ifm vs bs p)"
chaieb@33152
  1137
  by (induct ps, auto simp add: list_disj_def)
chaieb@33152
  1138
chaieb@33152
  1139
lemma conj_boundslt: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (conj p q)"
chaieb@33152
  1140
  unfolding conj_def by auto
chaieb@33152
  1141
chaieb@33152
  1142
lemma conjs_nb: "bound n p \<Longrightarrow> \<forall>q\<in> set (conjs p). bound n q"
chaieb@33152
  1143
  apply (induct p rule: conjs.induct) 
chaieb@33152
  1144
  apply (unfold conjs.simps)
chaieb@33152
  1145
  apply (unfold set_append)
chaieb@33152
  1146
  apply (unfold ball_Un)
chaieb@33152
  1147
  apply (unfold bound.simps)
chaieb@33152
  1148
  apply auto
chaieb@33152
  1149
  done
chaieb@33152
  1150
chaieb@33152
  1151
lemma conjs_boundslt: "boundslt n p \<Longrightarrow> \<forall>q\<in> set (conjs p). boundslt n q"
chaieb@33152
  1152
  apply (induct p rule: conjs.induct) 
chaieb@33152
  1153
  apply (unfold conjs.simps)
chaieb@33152
  1154
  apply (unfold set_append)
chaieb@33152
  1155
  apply (unfold ball_Un)
chaieb@33152
  1156
  apply (unfold boundslt.simps)
chaieb@33152
  1157
  apply blast
chaieb@33152
  1158
by simp_all
chaieb@33152
  1159
chaieb@33152
  1160
lemma list_conj_boundslt: " \<forall>p\<in> set ps. boundslt n p \<Longrightarrow> boundslt n (list_conj ps)"
chaieb@33152
  1161
  unfolding list_conj_def
chaieb@33152
  1162
  by (induct ps, auto simp add: conj_boundslt)
chaieb@33152
  1163
chaieb@33152
  1164
lemma list_conj_nb: assumes bnd: "\<forall>p\<in> set ps. bound n p"
chaieb@33152
  1165
  shows "bound n (list_conj ps)"
chaieb@33152
  1166
  using bnd
chaieb@33152
  1167
  unfolding list_conj_def
chaieb@33152
  1168
  by (induct ps, auto simp add: conj_nb)
chaieb@33152
  1169
chaieb@33152
  1170
lemma list_conj_nb': "\<forall>p\<in>set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
chaieb@33152
  1171
unfolding list_conj_def by (induct ps , auto)
chaieb@33152
  1172
chaieb@33152
  1173
lemma CJNB_qe: 
chaieb@33152
  1174
  assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
chaieb@33152
  1175
  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
  1176
proof(clarify)
chaieb@33152
  1177
  fix bs p
chaieb@33152
  1178
  assume qfp: "qfree p"
chaieb@33152
  1179
  let ?cjs = "conjuncts p"
chaieb@33152
  1180
  let ?yes = "fst (partition bound0 ?cjs)"
chaieb@33152
  1181
  let ?no = "snd (partition bound0 ?cjs)"
chaieb@33152
  1182
  let ?cno = "list_conj ?no"
chaieb@33152
  1183
  let ?cyes = "list_conj ?yes"
chaieb@33152
  1184
  have part: "partition bound0 ?cjs = (?yes,?no)" by simp
chaieb@33152
  1185
  from partition_P[OF part] have "\<forall> q\<in> set ?yes. bound0 q" by blast 
chaieb@33152
  1186
  hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb') 
chaieb@33152
  1187
  hence yes_qf: "qfree (decr0 ?cyes )" by (simp add: decr0_qf)
chaieb@33152
  1188
  from conjuncts_qf[OF qfp] partition_set[OF part] 
chaieb@33152
  1189
  have " \<forall>q\<in> set ?no. qfree q" by auto
chaieb@33152
  1190
  hence no_qf: "qfree ?cno"by (simp add: list_conj_qf)
chaieb@33152
  1191
  with qe have cno_qf:"qfree (qe ?cno )" 
chaieb@33152
  1192
    and noE: "Ifm vs bs (qe ?cno) = Ifm vs bs (E ?cno)" by blast+
chaieb@33152
  1193
  from cno_qf yes_qf have qf: "qfree (CJNB qe p)" 
chaieb@33152
  1194
    by (simp add: CJNB_def Let_def conj_qf split_def)
chaieb@33152
  1195
  {fix bs
chaieb@33152
  1196
    from conjuncts have "Ifm vs bs p = (\<forall>q\<in> set ?cjs. Ifm vs bs q)" by blast
chaieb@33152
  1197
    also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm vs bs q) \<and> (\<forall>q\<in> set ?no. Ifm vs bs q))"
chaieb@33152
  1198
      using partition_set[OF part] by auto
chaieb@33152
  1199
    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
  1200
  hence "Ifm vs bs (E p) = (\<exists>x. (Ifm vs (x#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))" by simp
chaieb@33152
  1201
  also have "\<dots> = (\<exists>x. (Ifm vs (y#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
chaieb@33152
  1202
    using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
chaieb@33152
  1203
  also have "\<dots> = (Ifm vs bs (decr0 ?cyes) \<and> Ifm vs bs (E ?cno))"
hoelzl@33639
  1204
    by (auto simp add: decr0[OF yes_nb] simp del: partition_filter_conv)
chaieb@33152
  1205
  also have "\<dots> = (Ifm vs bs (conj (decr0 ?cyes) (qe ?cno)))"
chaieb@33152
  1206
    using qe[rule_format, OF no_qf] by auto
chaieb@33152
  1207
  finally have "Ifm vs bs (E p) = Ifm vs bs (CJNB qe p)" 
chaieb@33152
  1208
    by (simp add: Let_def CJNB_def split_def)
chaieb@33152
  1209
  with qf show "qfree (CJNB qe p) \<and> Ifm vs bs (CJNB qe p) = Ifm vs bs (E p)" by blast
chaieb@33152
  1210
qed
chaieb@33152
  1211
chaieb@33152
  1212
consts simpfm :: "fm \<Rightarrow> fm"
chaieb@33152
  1213
recdef simpfm "measure fmsize"
chaieb@33152
  1214
  "simpfm (Lt t) = simplt (simptm t)"
chaieb@33152
  1215
  "simpfm (Le t) = simple (simptm t)"
chaieb@33152
  1216
  "simpfm (Eq t) = simpeq(simptm t)"
chaieb@33152
  1217
  "simpfm (NEq t) = simpneq(simptm t)"
chaieb@33152
  1218
  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
chaieb@33152
  1219
  "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
chaieb@33152
  1220
  "simpfm (Imp p q) = disj (simpfm (NOT p)) (simpfm q)"
chaieb@33152
  1221
  "simpfm (Iff p q) = disj (conj (simpfm p) (simpfm q)) (conj (simpfm (NOT p)) (simpfm (NOT q)))"
chaieb@33152
  1222
  "simpfm (NOT (And p q)) = disj (simpfm (NOT p)) (simpfm (NOT q))"
chaieb@33152
  1223
  "simpfm (NOT (Or p q)) = conj (simpfm (NOT p)) (simpfm (NOT q))"
chaieb@33152
  1224
  "simpfm (NOT (Imp p q)) = conj (simpfm p) (simpfm (NOT q))"
chaieb@33152
  1225
  "simpfm (NOT (Iff p q)) = disj (conj (simpfm p) (simpfm (NOT q))) (conj (simpfm (NOT p)) (simpfm q))"
chaieb@33152
  1226
  "simpfm (NOT (Eq t)) = simpneq t"
chaieb@33152
  1227
  "simpfm (NOT (NEq t)) = simpeq t"
chaieb@33152
  1228
  "simpfm (NOT (Le t)) = simplt (Neg t)"
chaieb@33152
  1229
  "simpfm (NOT (Lt t)) = simple (Neg t)"
chaieb@33152
  1230
  "simpfm (NOT (NOT p)) = simpfm p"
chaieb@33152
  1231
  "simpfm (NOT T) = F"
chaieb@33152
  1232
  "simpfm (NOT F) = T"
chaieb@33152
  1233
  "simpfm p = p"
chaieb@33152
  1234
chaieb@33152
  1235
lemma simpfm[simp]: "Ifm vs bs (simpfm p) = Ifm vs bs p"
chaieb@33152
  1236
by(induct p arbitrary: bs rule: simpfm.induct, auto)
chaieb@33152
  1237
haftmann@36409
  1238
lemma simpfm_bound0:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1239
  shows "bound0 p \<Longrightarrow> bound0 (simpfm p)"
chaieb@33152
  1240
by (induct p rule: simpfm.induct, auto)
chaieb@33152
  1241
chaieb@33152
  1242
lemma lt_qf[simp]: "qfree (lt t)"
chaieb@33152
  1243
  apply (cases t, auto simp add: lt_def)
chaieb@33152
  1244
  by (case_tac poly, auto)
chaieb@33152
  1245
chaieb@33152
  1246
lemma le_qf[simp]: "qfree (le t)"
chaieb@33152
  1247
  apply (cases t, auto simp add: le_def)
chaieb@33152
  1248
  by (case_tac poly, auto)
chaieb@33152
  1249
chaieb@33152
  1250
lemma eq_qf[simp]: "qfree (eq t)"
chaieb@33152
  1251
  apply (cases t, auto simp add: eq_def)
chaieb@33152
  1252
  by (case_tac poly, auto)
chaieb@33152
  1253
chaieb@33152
  1254
lemma neq_qf[simp]: "qfree (neq t)" by (simp add: neq_def)
chaieb@33152
  1255
chaieb@33152
  1256
lemma simplt_qf[simp]: "qfree (simplt t)" by (simp add: simplt_def Let_def split_def)
chaieb@33152
  1257
lemma simple_qf[simp]: "qfree (simple t)" by (simp add: simple_def Let_def split_def)
chaieb@33152
  1258
lemma simpeq_qf[simp]: "qfree (simpeq t)" by (simp add: simpeq_def Let_def split_def)
chaieb@33152
  1259
lemma simpneq_qf[simp]: "qfree (simpneq t)" by (simp add: simpneq_def Let_def split_def)
chaieb@33152
  1260
chaieb@33152
  1261
lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
chaieb@33152
  1262
by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def)
chaieb@33152
  1263
chaieb@33152
  1264
lemma disj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (disj p q)" by (simp add: disj_def)
chaieb@33152
  1265
lemma conj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (conj p q)" by (simp add: conj_def)
chaieb@33152
  1266
haftmann@36409
  1267
lemma   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  1268
  shows "qfree p \<Longrightarrow> islin (simpfm p)" 
chaieb@33152
  1269
  apply (induct p rule: simpfm.induct)
chaieb@33152
  1270
  apply (simp_all add: conj_lin disj_lin)
chaieb@33152
  1271
  done
chaieb@33152
  1272
chaieb@33152
  1273
consts prep :: "fm \<Rightarrow> fm"
chaieb@33152
  1274
recdef prep "measure fmsize"
chaieb@33152
  1275
  "prep (E T) = T"
chaieb@33152
  1276
  "prep (E F) = F"
chaieb@33152
  1277
  "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
chaieb@33152
  1278
  "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
chaieb@33152
  1279
  "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" 
chaieb@33152
  1280
  "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
chaieb@33152
  1281
  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
chaieb@33152
  1282
  "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
chaieb@33152
  1283
  "prep (E p) = E (prep p)"
chaieb@33152
  1284
  "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
chaieb@33152
  1285
  "prep (A p) = prep (NOT (E (NOT p)))"
chaieb@33152
  1286
  "prep (NOT (NOT p)) = prep p"
chaieb@33152
  1287
  "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
chaieb@33152
  1288
  "prep (NOT (A p)) = prep (E (NOT p))"
chaieb@33152
  1289
  "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
chaieb@33152
  1290
  "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
chaieb@33152
  1291
  "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
chaieb@33152
  1292
  "prep (NOT p) = not (prep p)"
chaieb@33152
  1293
  "prep (Or p q) = disj (prep p) (prep q)"
chaieb@33152
  1294
  "prep (And p q) = conj (prep p) (prep q)"
chaieb@33152
  1295
  "prep (Imp p q) = prep (Or (NOT p) q)"
chaieb@33152
  1296
  "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
chaieb@33152
  1297
  "prep p = p"
chaieb@33152
  1298
(hints simp add: fmsize_pos)
chaieb@33152
  1299
lemma prep: "Ifm vs bs (prep p) = Ifm vs bs p"
chaieb@33152
  1300
by (induct p arbitrary: bs rule: prep.induct, auto)
chaieb@33152
  1301
chaieb@33152
  1302
chaieb@33152
  1303
chaieb@33152
  1304
  (* Generic quantifier elimination *)
krauss@42693
  1305
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where
chaieb@33152
  1306
  "qelim (E p) = (\<lambda> qe. DJ (CJNB qe) (qelim p qe))"
krauss@42693
  1307
| "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
krauss@42693
  1308
| "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
krauss@42693
  1309
| "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
krauss@42693
  1310
| "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
krauss@42693
  1311
| "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))"
krauss@42693
  1312
| "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
krauss@42693
  1313
| "qelim p = (\<lambda> y. simpfm p)"
krauss@42693
  1314
by pat_completeness simp_all
krauss@42693
  1315
termination by (relation "measure fmsize") auto
chaieb@33152
  1316
chaieb@33152
  1317
lemma qelim:
chaieb@33152
  1318
  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
  1319
  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm vs bs (qelim p qe) = Ifm vs bs p)"
chaieb@33152
  1320
using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]]
chaieb@33152
  1321
by (induct p rule: qelim.induct) auto
chaieb@33152
  1322
chaieb@33152
  1323
subsection{* Core Procedure *}
chaieb@33152
  1324
krauss@42693
  1325
fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*) where
chaieb@33152
  1326
  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
krauss@42693
  1327
| "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
krauss@42693
  1328
| "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
krauss@42693
  1329
| "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
krauss@42693
  1330
| "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
krauss@42693
  1331
| "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
krauss@42693
  1332
| "minusinf p = p"
chaieb@33152
  1333
krauss@42693
  1334
fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*) where
chaieb@33152
  1335
  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
krauss@42693
  1336
| "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
krauss@42693
  1337
| "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
krauss@42693
  1338
| "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
krauss@42693
  1339
| "plusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP c))"
krauss@42693
  1340
| "plusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP c))"
krauss@42693
  1341
| "plusinf p = p"
chaieb@33152
  1342
chaieb@33152
  1343
lemma minusinf_inf: assumes lp:"islin p"
chaieb@33152
  1344
  shows "\<exists>z. \<forall>x < z. Ifm vs (x#bs) (minusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
chaieb@33152
  1345
  using lp
chaieb@33152
  1346
proof (induct p rule: minusinf.induct)
chaieb@33152
  1347
  case 1 thus ?case by (auto,rule_tac x="min z za" in exI, auto)
chaieb@33152
  1348
next
chaieb@33152
  1349
  case 2 thus ?case by (auto,rule_tac x="min z za" in exI, auto)
chaieb@33152
  1350
next
chaieb@33152
  1351
  case (3 c e) hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1352
  from 3 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1353
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1354
  let ?c = "Ipoly vs c"
chaieb@33152
  1355
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1356
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1357
  moreover {assume "?c = 0" hence ?case 
chaieb@33152
  1358
      using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto}
chaieb@33152
  1359
  moreover {assume cp: "?c > 0"
chaieb@33152
  1360
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1361
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1362
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1363
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1364
        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
  1365
  moreover {assume cp: "?c < 0"
chaieb@33152
  1366
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1367
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1368
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1369
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1370
        using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto} hence ?case by auto}
chaieb@33152
  1371
  ultimately show ?case by blast
chaieb@33152
  1372
next
chaieb@33152
  1373
  case (4 c e)  hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1374
  from 4 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1375
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1376
  let ?c = "Ipoly vs c"
chaieb@33152
  1377
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1378
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1379
  moreover {assume "?c = 0" hence ?case using eqs 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) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1385
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] 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) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1391
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1392
  ultimately show ?case by blast
chaieb@33152
  1393
next
chaieb@33152
  1394
  case (5 c e)  hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1395
  from 5 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1396
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1397
  note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] lt[OF nc(2), where ?'a = 'a]
chaieb@33152
  1398
  let ?c = "Ipoly vs c"
chaieb@33152
  1399
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1400
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1401
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1402
  moreover {assume cp: "?c > 0"
chaieb@33152
  1403
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1404
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1405
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1406
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1407
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1408
  moreover {assume cp: "?c < 0"
chaieb@33152
  1409
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1410
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1411
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1412
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1413
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] cp by auto} hence ?case by auto}
chaieb@33152
  1414
  ultimately show ?case by blast
chaieb@33152
  1415
next
chaieb@33152
  1416
  case (6 c e)  hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1417
  from 6 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1418
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1419
  note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] le[OF nc(2), where ?'a = 'a]
chaieb@33152
  1420
  let ?c = "Ipoly vs c"
chaieb@33152
  1421
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1422
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1423
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1424
  moreover {assume cp: "?c > 0"
chaieb@33152
  1425
    {fix x assume xz: "x < -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1426
        using pos_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1427
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1428
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1429
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1430
  moreover {assume cp: "?c < 0"
chaieb@33152
  1431
    {fix x assume xz: "x < -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1432
        using neg_less_divide_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1433
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1434
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1435
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1436
  ultimately show ?case by blast
chaieb@33152
  1437
qed (auto)
chaieb@33152
  1438
chaieb@33152
  1439
lemma plusinf_inf: assumes lp:"islin p"
chaieb@33152
  1440
  shows "\<exists>z. \<forall>x > z. Ifm vs (x#bs) (plusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
chaieb@33152
  1441
  using lp
chaieb@33152
  1442
proof (induct p rule: plusinf.induct)
chaieb@33152
  1443
  case 1 thus ?case by (auto,rule_tac x="max z za" in exI, auto)
chaieb@33152
  1444
next
chaieb@33152
  1445
  case 2 thus ?case by (auto,rule_tac x="max z za" in exI, auto)
chaieb@33152
  1446
next
chaieb@33152
  1447
  case (3 c e) hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1448
  from 3 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1449
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1450
  let ?c = "Ipoly vs c"
chaieb@33152
  1451
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1452
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1453
  moreover {assume "?c = 0" hence ?case 
chaieb@33152
  1454
      using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto}
chaieb@33152
  1455
  moreover {assume cp: "?c > 0"
chaieb@33152
  1456
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e" 
wenzelm@33268
  1457
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1458
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1459
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1460
        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
  1461
  moreover {assume cp: "?c < 0"
chaieb@33152
  1462
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1463
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1464
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1465
      hence "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Eq (CNP 0 c e)))"
wenzelm@33268
  1466
        using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto} hence ?case by auto}
chaieb@33152
  1467
  ultimately show ?case by blast
chaieb@33152
  1468
next
wenzelm@42686
  1469
  case (4 c e) hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1470
  from 4 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1471
  note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
chaieb@33152
  1472
  let ?c = "Ipoly vs c"
chaieb@33152
  1473
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1474
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1475
  moreover {assume "?c = 0" hence ?case using eqs 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) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1481
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] 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) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (NEq (CNP 0 c e)))"
wenzelm@33268
  1487
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto} hence ?case by auto}
chaieb@33152
  1488
  ultimately show ?case by blast
chaieb@33152
  1489
next
wenzelm@42686
  1490
  case (5 c e) hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1491
  from 5 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1492
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1493
  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
  1494
  let ?c = "Ipoly vs c"
chaieb@33152
  1495
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1496
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1497
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1498
  moreover {assume cp: "?c > 0"
chaieb@33152
  1499
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1500
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1501
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1502
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1503
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1504
  moreover {assume cp: "?c < 0"
chaieb@33152
  1505
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1506
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1507
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1508
      hence "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Lt (CNP 0 c e)))"
wenzelm@33268
  1509
        using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] cp by auto} hence ?case by auto}
chaieb@33152
  1510
  ultimately show ?case by blast
chaieb@33152
  1511
next
chaieb@33152
  1512
  case (6 c e)  hence nbe: "tmbound0 e" by simp
wenzelm@42686
  1513
  from 6 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e" by simp_all
chaieb@33152
  1514
  hence nc': "allpolys isnpoly (CP (~\<^sub>p c))" by (simp add: polyneg_norm)
chaieb@33152
  1515
  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
  1516
  let ?c = "Ipoly vs c"
chaieb@33152
  1517
  let ?e = "Itm vs (y#bs) e"
chaieb@33152
  1518
  have "?c=0 \<or> ?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  1519
  moreover {assume "?c = 0" hence ?case using eqs by auto}
chaieb@33152
  1520
  moreover {assume cp: "?c > 0"
chaieb@33152
  1521
    {fix x assume xz: "x > -?e / ?c" hence "?c * x > - ?e"
wenzelm@33268
  1522
        using pos_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1523
      hence "?c * x + ?e > 0" by simp
chaieb@33152
  1524
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1525
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1526
  moreover {assume cp: "?c < 0"
chaieb@33152
  1527
    {fix x assume xz: "x > -?e / ?c" hence "?c * x < - ?e"
wenzelm@33268
  1528
        using neg_divide_less_eq[OF cp, where a="x" and b="-?e"] by (simp add: mult_commute)
chaieb@33152
  1529
      hence "?c * x + ?e < 0" by simp
chaieb@33152
  1530
      hence "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (plusinf (Le (CNP 0 c e)))"
wenzelm@33268
  1531
        using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto} hence ?case by auto}
chaieb@33152
  1532
  ultimately show ?case by blast
chaieb@33152
  1533
qed (auto)
chaieb@33152
  1534
chaieb@33152
  1535
lemma minusinf_nb: "islin p \<Longrightarrow> bound0 (minusinf p)" 
chaieb@33152
  1536
  by (induct p rule: minusinf.induct, auto simp add: eq_nb lt_nb le_nb)
chaieb@33152
  1537
lemma plusinf_nb: "islin p \<Longrightarrow> bound0 (plusinf p)" 
chaieb@33152
  1538
  by (induct p rule: minusinf.induct, auto simp add: eq_nb lt_nb le_nb)
chaieb@33152
  1539
chaieb@33152
  1540
lemma minusinf_ex: assumes lp: "islin p" and ex: "Ifm vs (x#bs) (minusinf p)"
chaieb@33152
  1541
  shows "\<exists>x. Ifm vs (x#bs) p"
chaieb@33152
  1542
proof-
chaieb@33152
  1543
  from bound0_I [OF minusinf_nb[OF lp], where b="a" and bs ="bs"] ex
chaieb@33152
  1544
  have th: "\<forall> x. Ifm vs (x#bs) (minusinf p)" by auto
chaieb@33152
  1545
  from minusinf_inf[OF lp, where bs="bs"] 
chaieb@33152
  1546
  obtain z where z_def: "\<forall>x<z. Ifm vs (x # bs) (minusinf p) = Ifm vs (x # bs) p" by blast
chaieb@33152
  1547
  from th have "Ifm vs ((z - 1)#bs) (minusinf p)" by simp
chaieb@33152
  1548
  moreover have "z - 1 < z" by simp
chaieb@33152
  1549
  ultimately show ?thesis using z_def by auto
chaieb@33152
  1550
qed
chaieb@33152
  1551
chaieb@33152
  1552
lemma plusinf_ex: assumes lp: "islin p" and ex: "Ifm vs (x#bs) (plusinf p)"
chaieb@33152
  1553
  shows "\<exists>x. Ifm vs (x#bs) p"
chaieb@33152
  1554
proof-
chaieb@33152
  1555
  from bound0_I [OF plusinf_nb[OF lp], where b="a" and bs ="bs"] ex
chaieb@33152
  1556
  have th: "\<forall> x. Ifm vs (x#bs) (plusinf p)" by auto
chaieb@33152
  1557
  from plusinf_inf[OF lp, where bs="bs"] 
chaieb@33152
  1558
  obtain z where z_def: "\<forall>x>z. Ifm vs (x # bs) (plusinf p) = Ifm vs (x # bs) p" by blast
chaieb@33152
  1559
  from th have "Ifm vs ((z + 1)#bs) (plusinf p)" by simp
chaieb@33152
  1560
  moreover have "z + 1 > z" by simp
chaieb@33152
  1561
  ultimately show ?thesis using z_def by auto
chaieb@33152
  1562
qed
chaieb@33152
  1563
chaieb@33152
  1564
fun uset :: "fm \<Rightarrow> (poly \<times> tm) list" where
chaieb@33152
  1565
  "uset (And p q) = uset p @ uset q"
chaieb@33152
  1566
| "uset (Or p q) = uset p @ uset q"
chaieb@33152
  1567
| "uset (Eq (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1568
| "uset (Le (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1569
| "uset (Lt (CNP 0 a e))  = [(a,e)]"
chaieb@33152
  1570
| "uset (NEq (CNP 0 a e)) = [(a,e)]"
chaieb@33152
  1571
| "uset p = []"
chaieb@33152
  1572
chaieb@33152
  1573
lemma uset_l:
chaieb@33152
  1574
  assumes lp: "islin p"
chaieb@33152
  1575
  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
  1576
using lp by(induct p rule: uset.induct,auto)
chaieb@33152
  1577
chaieb@33152
  1578
lemma minusinf_uset0:
chaieb@33152
  1579
  assumes lp: "islin p"
chaieb@33152
  1580
  and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))"
chaieb@33152
  1581
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1582
  shows "\<exists> (c,s) \<in> set (uset p). x \<ge> - Itm vs (x#bs) s / Ipoly vs c" 
chaieb@33152
  1583
proof-
chaieb@33152
  1584
  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
  1585
    using lp nmi ex
nipkow@42713
  1586
    apply (induct p rule: minusinf.induct, auto simp add: eq le lt polyneg_norm)
chaieb@33152
  1587
    apply (auto simp add: linorder_not_less order_le_less)
chaieb@33152
  1588
    done 
chaieb@33152
  1589
  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
  1590
  hence "x \<ge> (- Itm vs (x#bs) s) / Ipoly vs c"
chaieb@33152
  1591
    using divide_le_eq[of "- Itm vs (x#bs) s" "Ipoly vs c" x]
chaieb@33152
  1592
    by (auto simp add: mult_commute del: divide_minus_left)
chaieb@33152
  1593
  thus ?thesis using csU by auto
chaieb@33152
  1594
qed
chaieb@33152
  1595
chaieb@33152
  1596
lemma minusinf_uset:
chaieb@33152
  1597
  assumes lp: "islin p"
chaieb@33152
  1598
  and nmi: "\<not> (Ifm vs (a#bs) (minusinf p))"
chaieb@33152
  1599
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1600
  shows "\<exists> (c,s) \<in> set (uset p). x \<ge> - Itm vs (a#bs) s / Ipoly vs c" 
chaieb@33152
  1601
proof-
chaieb@33152
  1602
  from nmi have nmi': "\<not> (Ifm vs (x#bs) (minusinf p))" 
chaieb@33152
  1603
    by (simp add: bound0_I[OF minusinf_nb[OF lp], where b=x and b'=a])
chaieb@33152
  1604
  from minusinf_uset0[OF lp nmi' ex] 
chaieb@33152
  1605
  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
  1606
  from uset_l[OF lp, rule_format, OF csU] have nb: "tmbound0 s" by simp
chaieb@33152
  1607
  from th tmbound0_I[OF nb, of vs x bs a] csU show ?thesis by auto
chaieb@33152
  1608
qed
chaieb@33152
  1609
chaieb@33152
  1610
chaieb@33152
  1611
lemma plusinf_uset0:
chaieb@33152
  1612
  assumes lp: "islin p"
chaieb@33152
  1613
  and nmi: "\<not> (Ifm vs (x#bs) (plusinf p))"
chaieb@33152
  1614
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1615
  shows "\<exists> (c,s) \<in> set (uset p). x \<le> - Itm vs (x#bs) s / Ipoly vs c" 
chaieb@33152
  1616
proof-
chaieb@33152
  1617
  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
  1618
    using lp nmi ex
nipkow@42713
  1619
    apply (induct p rule: minusinf.induct, auto simp add: eq le lt polyneg_norm)
chaieb@33152
  1620
    apply (auto simp add: linorder_not_less order_le_less)
chaieb@33152
  1621
    done 
chaieb@33152
  1622
  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
  1623
  hence "x \<le> (- Itm vs (x#bs) s) / Ipoly vs c"
chaieb@33152
  1624
    using le_divide_eq[of x "- Itm vs (x#bs) s" "Ipoly vs c"]
chaieb@33152
  1625
    by (auto simp add: mult_commute del: divide_minus_left)
chaieb@33152
  1626
  thus ?thesis using csU by auto
chaieb@33152
  1627
qed
chaieb@33152
  1628
chaieb@33152
  1629
lemma plusinf_uset:
chaieb@33152
  1630
  assumes lp: "islin p"
chaieb@33152
  1631
  and nmi: "\<not> (Ifm vs (a#bs) (plusinf p))"
chaieb@33152
  1632
  and ex: "Ifm vs (x#bs) p" (is "?I x p")
chaieb@33152
  1633
  shows "\<exists> (c,s) \<in> set (uset p). x \<le> - Itm vs (a#bs) s / Ipoly vs c" 
chaieb@33152
  1634
proof-
chaieb@33152
  1635
  from nmi have nmi': "\<not> (Ifm vs (x#bs) (plusinf p))" 
chaieb@33152
  1636
    by (simp add: bound0_I[OF plusinf_nb[OF lp], where b=x and b'=a])
chaieb@33152
  1637
  from plusinf_uset0[OF lp nmi' ex] 
chaieb@33152
  1638
  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
  1639
  from uset_l[OF lp, rule_format, OF csU] have nb: "tmbound0 s" by simp
chaieb@33152
  1640
  from th tmbound0_I[OF nb, of vs x bs a] csU show ?thesis by auto
chaieb@33152
  1641
qed
chaieb@33152
  1642
chaieb@33152
  1643
lemma lin_dense: 
chaieb@33152
  1644
  assumes lp: "islin p"
chaieb@33152
  1645
  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
  1646
  (is "\<forall> t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda> (c,t). - ?Nt x t / ?N c) ` ?U p")
chaieb@33152
  1647
  and lx: "l < x" and xu:"x < u" and px:" Ifm vs (x#bs) p"
chaieb@33152
  1648
  and ly: "l < y" and yu: "y < u"
chaieb@33152
  1649
  shows "Ifm vs (y#bs) p"
chaieb@33152
  1650
using lp px noS
chaieb@33152
  1651
proof (induct p rule: islin.induct) 
chaieb@33152
  1652
  case (5 c s)
chaieb@33152
  1653
  from "5.prems" 
chaieb@33152
  1654
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1655
    and px: "Ifm vs (x # bs) (Lt (CNP 0 c s))"
chaieb@33152
  1656
    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
  1657
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1658
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1659
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1660
  moreover
chaieb@33152
  1661
  {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
  1662
  moreover
chaieb@33152
  1663
  {assume c: "?N c > 0"
chaieb@33152
  1664
      from px pos_less_divide_eq[OF c, where a="x" and b="-?Nt x s"]  
chaieb@33152
  1665
      have px': "x < - ?Nt x s / ?N c" 
haftmann@36347
  1666
        by (auto simp add: not_less field_simps) 
chaieb@33152
  1667
    {assume y: "y < - ?Nt x s / ?N c" 
chaieb@33152
  1668
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1669
        by (simp add: pos_less_divide_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36347
  1670
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1671
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1672
    moreover
chaieb@33152
  1673
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1674
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1675
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1676
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1677
    ultimately have ?case using ycs by blast
chaieb@33152
  1678
  }
chaieb@33152
  1679
  moreover
chaieb@33152
  1680
  {assume c: "?N c < 0"
chaieb@33152
  1681
      from px neg_divide_less_eq[OF c, where a="x" and b="-?Nt x s"]  
chaieb@33152
  1682
      have px': "x > - ?Nt x s / ?N c" 
haftmann@36347
  1683
        by (auto simp add: not_less field_simps) 
chaieb@33152
  1684
    {assume y: "y > - ?Nt x s / ?N c" 
chaieb@33152
  1685
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1686
        by (simp add: neg_divide_less_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36347
  1687
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1688
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1689
    moreover
chaieb@33152
  1690
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1691
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1692
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1693
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1694
    ultimately have ?case using ycs by blast
chaieb@33152
  1695
  }
chaieb@33152
  1696
  ultimately show ?case by blast
chaieb@33152
  1697
next
chaieb@33152
  1698
  case (6 c s)
chaieb@33152
  1699
  from "6.prems" 
chaieb@33152
  1700
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1701
    and px: "Ifm vs (x # bs) (Le (CNP 0 c s))"
chaieb@33152
  1702
    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
  1703
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1704
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1705
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1706
  moreover
chaieb@33152
  1707
  {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
  1708
  moreover
chaieb@33152
  1709
  {assume c: "?N c > 0"
chaieb@33152
  1710
      from px pos_le_divide_eq[OF c, where a="x" and b="-?Nt x s"]  
haftmann@36347
  1711
      have px': "x <= - ?Nt x s / ?N c" by (simp add: not_less field_simps) 
chaieb@33152
  1712
    {assume y: "y < - ?Nt x s / ?N c" 
chaieb@33152
  1713
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1714
        by (simp add: pos_less_divide_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36347
  1715
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1716
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1717
    moreover
chaieb@33152
  1718
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1719
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1720
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1721
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1722
    ultimately have ?case using ycs by blast
chaieb@33152
  1723
  }
chaieb@33152
  1724
  moreover
chaieb@33152
  1725
  {assume c: "?N c < 0"
chaieb@33152
  1726
      from px neg_divide_le_eq[OF c, where a="x" and b="-?Nt x s"]  
haftmann@36347
  1727
      have px': "x >= - ?Nt x s / ?N c" by (simp add: field_simps) 
chaieb@33152
  1728
    {assume y: "y > - ?Nt x s / ?N c" 
chaieb@33152
  1729
      hence "y * ?N c < - ?Nt x s"
wenzelm@33268
  1730
        by (simp add: neg_divide_less_eq[OF c, where a="y" and b="-?Nt x s", symmetric])
haftmann@36347
  1731
      hence "?N c * y + ?Nt x s < 0" by (simp add: field_simps)
chaieb@33152
  1732
      hence ?case using tmbound0_I[OF lin(3), where bs="bs" and b="x" and b'="y"] by simp}
chaieb@33152
  1733
    moreover
chaieb@33152
  1734
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1735
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1736
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1737
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1738
    ultimately have ?case using ycs by blast
chaieb@33152
  1739
  }
chaieb@33152
  1740
  ultimately show ?case by blast
chaieb@33152
  1741
next
chaieb@33152
  1742
    case (3 c s)
chaieb@33152
  1743
  from "3.prems" 
chaieb@33152
  1744
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1745
    and px: "Ifm vs (x # bs) (Eq (CNP 0 c s))"
chaieb@33152
  1746
    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
  1747
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1748
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1749
  have ccs: "?N c = 0 \<or> ?N c < 0 \<or> ?N c > 0" by dlo
chaieb@33152
  1750
  moreover
chaieb@33152
  1751
  {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
  1752
  moreover
chaieb@33152
  1753
  {assume c: "?N c > 0" hence cnz: "?N c \<noteq> 0" by simp
chaieb@33152
  1754
    from px eq_divide_eq[of "x" "-?Nt x s" "?N c"]  cnz
haftmann@36347
  1755
    have px': "x = - ?Nt x s / ?N c" by (simp add: field_simps)
chaieb@33152
  1756
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1757
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1758
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1759
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1760
    moreover
chaieb@33152
  1761
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1762
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1763
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1764
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1765
    ultimately have ?case using ycs by blast
chaieb@33152
  1766
  }
chaieb@33152
  1767
  moreover
chaieb@33152
  1768
  {assume c: "?N c < 0" hence cnz: "?N c \<noteq> 0" by simp
chaieb@33152
  1769
    from px eq_divide_eq[of "x" "-?Nt x s" "?N c"]  cnz
haftmann@36347
  1770
    have px': "x = - ?Nt x s / ?N c" by (simp add: field_simps)
chaieb@33152
  1771
    {assume y: "y < -?Nt x s / ?N c" 
chaieb@33152
  1772
      with ly have eu: "l < - ?Nt x s / ?N c" by auto
chaieb@33152
  1773
      with noS ly yu have th: "- ?Nt x s / ?N c \<ge> u" by (cases "- ?Nt x s / ?N c < u", auto)
chaieb@33152
  1774
      with xu px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1775
    moreover
chaieb@33152
  1776
    {assume y: "y > -?Nt x s / ?N c" 
chaieb@33152
  1777
      with yu have eu: "u > - ?Nt x s / ?N c" by auto
chaieb@33152
  1778
      with noS ly yu have th: "- ?Nt x s / ?N c \<le> l" by (cases "- ?Nt x s / ?N c > l", auto)
chaieb@33152
  1779
      with lx px' have "False" by simp  hence ?case by simp }
chaieb@33152
  1780
    ultimately have ?case using ycs by blast
chaieb@33152
  1781
  }
chaieb@33152
  1782
  ultimately show ?case by blast
chaieb@33152
  1783
next
chaieb@33152
  1784
    case (4 c s)
chaieb@33152
  1785
  from "4.prems" 
chaieb@33152
  1786
  have lin: "isnpoly c" "c \<noteq> 0\<^sub>p" "tmbound0 s" "allpolys isnpoly s"
chaieb@33152
  1787
    and px: "Ifm vs (x # bs) (NEq (CNP 0 c s))"
chaieb@33152
  1788
    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
  1789
  from ly yu noS have yne: "y \<noteq> - ?Nt x s / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" by simp
chaieb@33152
  1790
  hence ycs: "y < - ?Nt x s / ?N c \<or> y > -?Nt x s / ?N c" by auto
chaieb@33152
  1791
  have ccs: "?N c = 0 \<or> ?N c \<noteq> 0" by dlo
chaieb@33152
  1792
  moreover
chaieb@33152
  1793
  {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
  1794
  moreover
chaieb@33152
  1795
  {assume c: "?N c \<noteq> 0"
chaieb@33152
  1796
    from yne c eq_divide_eq[of "y" "- ?Nt x s" "?N c"] have ?case
haftmann@36347
  1797
      by (simp add: field_simps tmbound0_I[OF lin(3), of vs x bs y] sum_eq[symmetric]) }
chaieb@33152
  1798
  ultimately show ?case by blast
nipkow@42713
  1799
qed (auto simp add: 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
  1800
haftmann@35028
  1801
lemma one_plus_one_pos[simp]: "(1::'a::{linordered_field}) + 1 > 0"
chaieb@33152
  1802
proof-
chaieb@33152
  1803
  have op: "(1::'a) > 0" by simp
chaieb@33152
  1804
  from add_pos_pos[OF op op] show ?thesis . 
chaieb@33152
  1805
qed
chaieb@33152
  1806
haftmann@35028
  1807
lemma one_plus_one_nonzero[simp]: "(1::'a::{linordered_field}) + 1 \<noteq> 0" 
chaieb@33152
  1808
  using one_plus_one_pos[where ?'a = 'a] by (simp add: less_le) 
chaieb@33152
  1809
haftmann@35028
  1810
lemma half_sum_eq: "(u + u) / (1+1) = (u::'a::{linordered_field})" 
chaieb@33152
  1811
proof-
haftmann@36347
  1812
  have "(u + u) = (1 + 1) * u" by (simp add: field_simps)
chaieb@33152
  1813
  hence "(u + u) / (1+1) = (1 + 1)*u / (1 + 1)" by simp
chaieb@33152
  1814
  with nonzero_mult_divide_cancel_left[OF one_plus_one_nonzero, of u] show ?thesis by simp
chaieb@33152
  1815
qed
chaieb@33152
  1816
chaieb@33152
  1817
lemma inf_uset:
chaieb@33152
  1818
  assumes lp: "islin p"
chaieb@33152
  1819
  and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))" (is "\<not> (Ifm vs (x#bs) (?M p))")
chaieb@33152
  1820
  and npi: "\<not> (Ifm vs (x#bs) (plusinf p))" (is "\<not> (Ifm vs (x#bs) (?P p))")
chaieb@33152
  1821
  and ex: "\<exists> x.  Ifm vs (x#bs) p" (is "\<exists> x. ?I x p")
chaieb@33152
  1822
  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
  1823
proof-
chaieb@33152
  1824
  let ?Nt = "\<lambda> x t. Itm vs (x#bs) t"
chaieb@33152
  1825
  let ?N = "Ipoly vs"
chaieb@33152
  1826
  let ?U = "set (uset p)"
chaieb@33152
  1827
  from ex obtain a where pa: "?I a p" by blast
chaieb@33152
  1828
  from bound0_I[OF minusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] nmi
chaieb@33152
  1829
  have nmi': "\<not> (?I a (?M p))" by simp
chaieb@33152
  1830
  from bound0_I[OF plusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] npi
chaieb@33152
  1831
  have npi': "\<not> (?I a (?P p))" by simp
chaieb@33152
  1832
  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
  1833
  proof-
chaieb@33152
  1834
    let ?M = "(\<lambda> (c,t). - ?Nt a t / ?N c) ` ?U"
chaieb@33152
  1835
    have fM: "finite ?M" by auto
chaieb@33152
  1836
    from minusinf_uset[OF lp nmi pa] plusinf_uset[OF lp npi pa] 
chaieb@33152
  1837
    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
  1838
    then obtain "c" "t" "d" "s" where 
chaieb@33152
  1839
      ctU: "(c,t) \<in> ?U" and dsU: "(d,s) \<in> ?U" 
chaieb@33152
  1840
      and xs1: "a \<le> - ?Nt x s / ?N d" and tx1: "a \<ge> - ?Nt x t / ?N c" by blast
chaieb@33152
  1841
    from uset_l[OF lp] ctU dsU tmbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 
chaieb@33152
  1842
    have xs: "a \<le> - ?Nt a s / ?N d" and tx: "a \<ge> - ?Nt a t / ?N c" by auto
chaieb@33152
  1843
    from ctU have Mne: "?M \<noteq> {}" by auto
chaieb@33152
  1844
    hence Une: "?U \<noteq> {}" by simp
chaieb@33152
  1845
    let ?l = "Min ?M"
chaieb@33152
  1846
    let ?u = "Max ?M"
chaieb@33152
  1847
    have linM: "?l \<in> ?M" using fM Mne by simp
chaieb@33152
  1848
    have uinM: "?u \<in> ?M" using fM Mne by simp
chaieb@33152
  1849
    have ctM: "- ?Nt a t / ?N c \<in> ?M" using ctU by auto
chaieb@33152
  1850
    have dsM: "- ?Nt a s / ?N d \<in> ?M" using dsU by auto 
chaieb@33152
  1851
    have lM: "\<forall> t\<in> ?M. ?l \<le> t" using Mne fM by auto
chaieb@33152
  1852
    have Mu: "\<forall> t\<in> ?M. t \<le> ?u" using Mne fM by auto
chaieb@33152
  1853
    have "?l \<le> - ?Nt a t / ?N c" using ctM Mne by simp hence lx: "?l \<le> a" using tx by simp
chaieb@33152
  1854
    have "- ?Nt a s / ?N d \<le> ?u" using dsM Mne by simp hence xu: "a \<le> ?u" using xs by simp
chaieb@33152
  1855
    from finite_set_intervals2[where P="\<lambda> x. ?I x p",OF pa lx xu linM uinM fM lM Mu]
chaieb@33152
  1856
    have "(\<exists> s\<in> ?M. ?I s p) \<or> 
chaieb@33152
  1857
      (\<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
  1858
    moreover {fix u assume um: "u\<in> ?M" and pu: "?I u p"
chaieb@33152
  1859
      hence "\<exists> (nu,tu) \<in> ?U. u = - ?Nt a tu / ?N nu" by auto
chaieb@33152
  1860
      then obtain "tu" "nu" where tuU: "(nu,tu) \<in> ?U" and tuu:"u= - ?Nt a tu / ?N nu" by blast
chaieb@33152
  1861
      from half_sum_eq[of u] pu tuu 
chaieb@33152
  1862
      have "?I (((- ?Nt a tu / ?N nu) + (- ?Nt a tu / ?N nu)) / (1 + 1)) p" by simp
chaieb@33152
  1863
      with tuU have ?thesis by blast}
chaieb@33152
  1864
    moreover{
chaieb@33152
  1865
      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
  1866
      then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" 
wenzelm@33268
  1867
        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
  1868
        by blast
chaieb@33152
  1869
      from t1M have "\<exists> (t1n,t1u) \<in> ?U. t1 = - ?Nt a t1u / ?N t1n" by auto
chaieb@33152
  1870
      then obtain "t1u" "t1n" where t1uU: "(t1n,t1u) \<in> ?U" and t1u: "t1 = - ?Nt a t1u / ?N t1n" by blast
chaieb@33152
  1871
      from t2M have "\<exists> (t2n,t2u) \<in> ?U. t2 = - ?Nt a t2u / ?N t2n" by auto
chaieb@33152
  1872
      then obtain "t2u" "t2n" where t2uU: "(t2n,t2u) \<in> ?U" and t2u: "t2 = - ?Nt a t2u / ?N t2n" by blast
chaieb@33152
  1873
      from t1x xt2 have t1t2: "t1 < t2" by simp
chaieb@33152
  1874
      let ?u = "(t1 + t2) / (1 + 1)"
chaieb@33152
  1875
      from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
chaieb@33152
  1876
      from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
chaieb@33152
  1877
      with t1uU t2uU t1u t2u have ?thesis by blast}
chaieb@33152
  1878
    ultimately show ?thesis by blast
chaieb@33152
  1879
  qed
chaieb@33152
  1880
  then obtain "l" "n" "s"  "m" where lnU: "(n,l) \<in> ?U" and smU:"(m,s) \<in> ?U" 
chaieb@33152
  1881
    and pu: "?I ((- ?Nt a l / ?N n + - ?Nt a s / ?N m) / (1 + 1)) p" by blast
chaieb@33152
  1882
  from lnU smU uset_l[OF lp] have nbl: "tmbound0 l" and nbs: "tmbound0 s" by auto
chaieb@33152
  1883
  from tmbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] 
chaieb@33152
  1884
    tmbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
chaieb@33152
  1885
  have "?I ((- ?Nt x l / ?N n + - ?Nt x s / ?N m) / (1 + 1)) p" by simp
chaieb@33152
  1886
  with lnU smU
chaieb@33152
  1887
  show ?thesis by auto
chaieb@33152
  1888
qed
chaieb@33152
  1889
chaieb@33152
  1890
    (* The Ferrante - Rackoff Theorem *)
chaieb@33152
  1891
chaieb@33152
  1892
theorem fr_eq: 
chaieb@33152
  1893
  assumes lp: "islin p"
chaieb@33152
  1894
  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
  1895
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
chaieb@33152
  1896
proof
chaieb@33152
  1897
  assume px: "\<exists> x. ?I x p"
chaieb@33152
  1898
  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
chaieb@33152
  1899
  moreover {assume "?M \<or> ?P" hence "?D" by blast}
chaieb@33152
  1900
  moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
chaieb@33152
  1901
    from inf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast}
chaieb@33152
  1902
  ultimately show "?D" by blast
chaieb@33152
  1903
next
chaieb@33152
  1904
  assume "?D" 
chaieb@33152
  1905
  moreover {assume m:"?M" from minusinf_ex[OF lp m] have "?E" .}
chaieb@33152
  1906
  moreover {assume p: "?P" from plusinf_ex[OF lp p] have "?E" . }
chaieb@33152
  1907
  moreover {assume f:"?F" hence "?E" by blast}
chaieb@33152
  1908
  ultimately show "?E" by blast
chaieb@33152
  1909
qed
chaieb@33152
  1910
chaieb@33152
  1911
section{* First implementation : Naive by encoding all case splits locally *}
chaieb@33152
  1912
definition "msubsteq c t d s a r = 
chaieb@33152
  1913
  evaldjf (split conj) 
chaieb@33152
  1914
  [(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
  1915
   (conj (Eq (CP c)) (NEq (CP d)) , Eq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  1916
   (conj (NEq (CP c)) (Eq (CP d)) , Eq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  1917
   (conj (Eq (CP c)) (Eq (CP d)) , Eq r)]"
chaieb@33152
  1918
chaieb@33152
  1919
lemma msubsteq_nb: assumes lp: "islin (Eq (CNP 0 a r))" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  1920
  shows "bound0 (msubsteq c t d s a r)"
chaieb@33152
  1921
proof-
chaieb@33152
  1922
  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
  1923
   (conj (Eq (CP c)) (NEq (CP d)) , Eq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  1924
   (conj (NEq (CP c)) (Eq (CP d)) , Eq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  1925
   (conj (Eq (CP c)) (Eq (CP d)) , Eq r)]. bound0 (split conj x)"
chaieb@33152
  1926
    using lp by (simp add: Let_def t s )
chaieb@33152
  1927
  from evaldjf_bound0[OF th] show ?thesis by (simp add: msubsteq_def)
chaieb@33152
  1928
qed
chaieb@33152
  1929
chaieb@33152
  1930
lemma msubsteq: assumes lp: "islin (Eq (CNP 0 a r))"
chaieb@33152
  1931
  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
  1932
proof-
chaieb@33152
  1933
  let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
chaieb@33152
  1934
  let ?N = "\<lambda>p. Ipoly vs p"
chaieb@33152
  1935
  let ?c = "?N c"
chaieb@33152
  1936
  let ?d = "?N d"
chaieb@33152
  1937
  let ?t = "?Nt x t"
chaieb@33152
  1938
  let ?s = "?Nt x s"
chaieb@33152
  1939
  let ?a = "?N a"
chaieb@33152
  1940
  let ?r = "?Nt x r"
chaieb@33152
  1941
  from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r" by simp_all
chaieb@33152
  1942
  note r= tmbound0_I[OF lin(3), of vs _ bs x]
chaieb@33152
  1943
  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
  1944
  moreover
chaieb@33152
  1945
  {assume c: "?c = 0" and d: "?d=0"
chaieb@33152
  1946
    hence ?thesis  by (simp add: r[of 0] msubsteq_def Let_def evaldjf_ex)}
chaieb@33152
  1947
  moreover 
chaieb@33152
  1948
  {assume c: "?c = 0" and d: "?d\<noteq>0"
chaieb@33152
  1949
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?s / ((1 + 1)*?d)" by simp
chaieb@33152
  1950
    have "?rhs = Ifm vs (-?s / ((1 + 1)*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  1951
    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
  1952
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a * (-?s / ((1 + 1)*?d)) + ?r) = 0" 
chaieb@33152
  1953
      using d mult_cancel_left[of "(1 + 1)*?d" "(?a * (-?s / ((1 + 1)*?d)) + ?r)" 0] by simp
chaieb@33152
  1954
    also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * ((1 + 1)*?d / ((1 + 1)*?d)) + (1 + 1)*?d*?r= 0"
haftmann@36347
  1955
      by (simp add: field_simps right_distrib[of "(1 + 1)*?d"] del: right_distrib)
chaieb@33152
  1956
    
chaieb@33152
  1957
    also have "\<dots> \<longleftrightarrow> - (?a * ?s) + (1 + 1)*?d*?r = 0" using d by simp 
chaieb@33152
  1958
    finally have ?thesis using c d 
chaieb@33152
  1959
      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
  1960
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  1961
      apply simp
chaieb@33152
  1962
      done}
chaieb@33152
  1963
  moreover
chaieb@33152
  1964
  {assume c: "?c \<noteq> 0" and d: "?d=0"
chaieb@33152
  1965
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?t / ((1 + 1)*?c)" by simp
chaieb@33152
  1966
    have "?rhs = Ifm vs (-?t / ((1 + 1)*?c) # bs) (Eq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  1967
    also have "\<dots> \<longleftrightarrow> ?a * (-?t / ((1 + 1)*?c)) + ?r = 0" by (simp add: r[of "- (?t/ ((1 + 1)* ?c))"])
chaieb@33152
  1968
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a * (-?t / ((1 + 1)*?c)) + ?r) = 0" 
chaieb@33152
  1969
      using c mult_cancel_left[of "(1 + 1)*?c" "(?a * (-?t / ((1 + 1)*?c)) + ?r)" 0] by simp
chaieb@33152
  1970
    also have "\<dots> \<longleftrightarrow> (?a * -?t)* ((1 + 1)*?c) / ((1 + 1)*?c) + (1 + 1)*?c*?r= 0"
haftmann@36347
  1971
      by (simp add: field_simps right_distrib[of "(1 + 1)*?c"] del: right_distrib)
chaieb@33152
  1972
    also have "\<dots> \<longleftrightarrow> - (?a * ?t) + (1 + 1)*?c*?r = 0" using c by simp 
chaieb@33152
  1973
    finally have ?thesis using c d 
chaieb@33152
  1974
      apply (simp add: r[of "- (?t/ ((1 + 1)*?c))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
chaieb@33152
  1975
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  1976
      apply simp
chaieb@33152
  1977
      done }
chaieb@33152
  1978
  moreover
chaieb@33152
  1979
  {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *(1 + 1) \<noteq> 0" by simp
chaieb@33152
  1980
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  1981
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  1982
      by (simp add: field_simps)
chaieb@33152
  1983
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  1984
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r = 0" 
chaieb@33152
  1985
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  1986
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) =0 "
chaieb@33152
  1987
      using c d mult_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
chaieb@33152
  1988
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r =0" 
haftmann@36347
  1989
      using nonzero_mult_divide_cancel_left [OF dc] c d
haftmann@36347
  1990
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  1991
    finally  have ?thesis using c d 
haftmann@36347
  1992
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubsteq_def Let_def evaldjf_ex field_simps)
chaieb@33152
  1993
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  1994
      apply (simp add: field_simps)
chaieb@33152
  1995
      done }
chaieb@33152
  1996
  ultimately show ?thesis by blast
chaieb@33152
  1997
qed
chaieb@33152
  1998
chaieb@33152
  1999
chaieb@33152
  2000
definition "msubstneq c t d s a r = 
chaieb@33152
  2001
  evaldjf (split conj) 
chaieb@33152
  2002
  [(let cd = c *\<^sub>p d in (NEq (CP cd), NEq (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2003
   (conj (Eq (CP c)) (NEq (CP d)) , NEq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2004
   (conj (NEq (CP c)) (Eq (CP d)) , NEq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2005
   (conj (Eq (CP c)) (Eq (CP d)) , NEq r)]"
chaieb@33152
  2006
chaieb@33152
  2007
lemma msubstneq_nb: assumes lp: "islin (NEq (CNP 0 a r))" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  2008
  shows "bound0 (msubstneq c t d s a r)"
chaieb@33152
  2009
proof-
chaieb@33152
  2010
  have th: "\<forall>x\<in> set [(let cd = c *\<^sub>p d in (NEq (CP cd), NEq (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))), 
chaieb@33152
  2011
    (conj (Eq (CP c)) (NEq (CP d)) , NEq (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2012
    (conj (NEq (CP c)) (Eq (CP d)) , NEq (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2013
    (conj (Eq (CP c)) (Eq (CP d)) , NEq r)]. bound0 (split conj x)"
chaieb@33152
  2014
    using lp by (simp add: Let_def t s )
chaieb@33152
  2015
  from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstneq_def)
chaieb@33152
  2016
qed
chaieb@33152
  2017
chaieb@33152
  2018
lemma msubstneq: assumes lp: "islin (Eq (CNP 0 a r))"
chaieb@33152
  2019
  shows "Ifm vs (x#bs) (msubstneq 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) (NEq (CNP 0 a r))" (is "?lhs = ?rhs")
chaieb@33152
  2020
proof-
chaieb@33152
  2021
  let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
chaieb@33152
  2022
  let ?N = "\<lambda>p. Ipoly vs p"
chaieb@33152
  2023
  let ?c = "?N c"
chaieb@33152
  2024
  let ?d = "?N d"
chaieb@33152
  2025
  let ?t = "?Nt x t"
chaieb@33152
  2026
  let ?s = "?Nt x s"
chaieb@33152
  2027
  let ?a = "?N a"
chaieb@33152
  2028
  let ?r = "?Nt x r"
chaieb@33152
  2029
  from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r" by simp_all
chaieb@33152
  2030
  note r= tmbound0_I[OF lin(3), of vs _ bs x]
chaieb@33152
  2031
  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
  2032
  moreover
chaieb@33152
  2033
  {assume c: "?c = 0" and d: "?d=0"
chaieb@33152
  2034
    hence ?thesis  by (simp add: r[of 0] msubstneq_def Let_def evaldjf_ex)}
chaieb@33152
  2035
  moreover 
chaieb@33152
  2036
  {assume c: "?c = 0" and d: "?d\<noteq>0"
chaieb@33152
  2037
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?s / ((1 + 1)*?d)" by simp
chaieb@33152
  2038
    have "?rhs = Ifm vs (-?s / ((1 + 1)*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2039
    also have "\<dots> \<longleftrightarrow> ?a * (-?s / ((1 + 1)*?d)) + ?r \<noteq> 0" by (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
chaieb@33152
  2040
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a * (-?s / ((1 + 1)*?d)) + ?r) \<noteq> 0" 
chaieb@33152
  2041
      using d mult_cancel_left[of "(1 + 1)*?d" "(?a * (-?s / ((1 + 1)*?d)) + ?r)" 0] by simp
chaieb@33152
  2042
    also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * ((1 + 1)*?d / ((1 + 1)*?d)) + (1 + 1)*?d*?r\<noteq> 0"
haftmann@36347
  2043
      by (simp add: field_simps right_distrib[of "(1 + 1)*?d"] del: right_distrib)
chaieb@33152
  2044
    
chaieb@33152
  2045
    also have "\<dots> \<longleftrightarrow> - (?a * ?s) + (1 + 1)*?d*?r \<noteq> 0" using d by simp 
chaieb@33152
  2046
    finally have ?thesis using c d 
chaieb@33152
  2047
      apply (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
chaieb@33152
  2048
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2049
      apply simp
chaieb@33152
  2050
      done}
chaieb@33152
  2051
  moreover
chaieb@33152
  2052
  {assume c: "?c \<noteq> 0" and d: "?d=0"
chaieb@33152
  2053
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?t / ((1 + 1)*?c)" by simp
chaieb@33152
  2054
    have "?rhs = Ifm vs (-?t / ((1 + 1)*?c) # bs) (NEq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2055
    also have "\<dots> \<longleftrightarrow> ?a * (-?t / ((1 + 1)*?c)) + ?r \<noteq> 0" by (simp add: r[of "- (?t/ ((1 + 1)* ?c))"])
chaieb@33152
  2056
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a * (-?t / ((1 + 1)*?c)) + ?r) \<noteq> 0" 
chaieb@33152
  2057
      using c mult_cancel_left[of "(1 + 1)*?c" "(?a * (-?t / ((1 + 1)*?c)) + ?r)" 0] by simp
chaieb@33152
  2058
    also have "\<dots> \<longleftrightarrow> (?a * -?t)* ((1 + 1)*?c) / ((1 + 1)*?c) + (1 + 1)*?c*?r \<noteq> 0"
haftmann@36347
  2059
      by (simp add: field_simps right_distrib[of "(1 + 1)*?c"] del: right_distrib)
chaieb@33152
  2060
    also have "\<dots> \<longleftrightarrow> - (?a * ?t) + (1 + 1)*?c*?r \<noteq> 0" using c by simp 
chaieb@33152
  2061
    finally have ?thesis using c d 
chaieb@33152
  2062
      apply (simp add: r[of "- (?t/ ((1 + 1)*?c))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
chaieb@33152
  2063
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2064
      apply simp
chaieb@33152
  2065
      done }
chaieb@33152
  2066
  moreover
chaieb@33152
  2067
  {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *(1 + 1) \<noteq> 0" by simp
chaieb@33152
  2068
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  2069
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  2070
      by (simp add: field_simps)
chaieb@33152
  2071
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2072
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r \<noteq> 0" 
chaieb@33152
  2073
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  2074
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) \<noteq> 0 "
chaieb@33152
  2075
      using c d mult_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
chaieb@33152
  2076
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r \<noteq> 0" 
chaieb@33152
  2077
      using nonzero_mult_divide_cancel_left[OF dc] c d
haftmann@36347
  2078
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  2079
    finally  have ?thesis using c d 
haftmann@36347
  2080
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstneq_def Let_def evaldjf_ex field_simps)
chaieb@33152
  2081
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  2082
      apply (simp add: field_simps)
chaieb@33152
  2083
      done }
chaieb@33152
  2084
  ultimately show ?thesis by blast
chaieb@33152
  2085
qed
chaieb@33152
  2086
chaieb@33152
  2087
definition "msubstlt c t d s a r = 
chaieb@33152
  2088
  evaldjf (split conj) 
chaieb@33152
  2089
  [(let cd = c *\<^sub>p d in (lt (CP (~\<^sub>p cd)), Lt (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2090
  (let cd = c *\<^sub>p d in (lt (CP cd), Lt (Sub (Mul a (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2091
   (conj (lt (CP (~\<^sub>p c))) (Eq (CP d)) , Lt (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2092
   (conj (lt (CP c)) (Eq (CP d)) , Lt (Sub (Mul a t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2093
   (conj (lt (CP (~\<^sub>p d))) (Eq (CP c)) , Lt (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2094
   (conj (lt (CP d)) (Eq (CP c)) , Lt (Sub (Mul a s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2095
   (conj (Eq (CP c)) (Eq (CP d)) , Lt r)]"
chaieb@33152
  2096
chaieb@33152
  2097
lemma msubstlt_nb: assumes lp: "islin (Lt (CNP 0 a r))" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  2098
  shows "bound0 (msubstlt c t d s a r)"
chaieb@33152
  2099
proof-
chaieb@33152
  2100
  have th: "\<forall>x\<in> set [(let cd = c *\<^sub>p d in (lt (CP (~\<^sub>p cd)), Lt (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2101
  (let cd = c *\<^sub>p d in (lt (CP cd), Lt (Sub (Mul a (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2102
   (conj (lt (CP (~\<^sub>p c))) (Eq (CP d)) , Lt (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2103
   (conj (lt (CP c)) (Eq (CP d)) , Lt (Sub (Mul a t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2104
   (conj (lt (CP (~\<^sub>p d))) (Eq (CP c)) , Lt (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2105
   (conj (lt (CP d)) (Eq (CP c)) , Lt (Sub (Mul a s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2106
   (conj (Eq (CP c)) (Eq (CP d)) , Lt r)]. bound0 (split conj x)"
chaieb@33152
  2107
    using lp by (simp add: Let_def t s lt_nb )
chaieb@33152
  2108
  from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstlt_def)
chaieb@33152
  2109
qed
chaieb@33152
  2110
chaieb@33152
  2111
chaieb@33152
  2112
lemma msubstlt: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Lt (CNP 0 a r))" 
chaieb@33152
  2113
  shows "Ifm vs (x#bs) (msubstlt c t d s a r) \<longleftrightarrow> 
chaieb@33152
  2114
  Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Lt (CNP 0 a r))" (is "?lhs = ?rhs")
chaieb@33152
  2115
proof-
chaieb@33152
  2116
  let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
chaieb@33152
  2117
  let ?N = "\<lambda>p. Ipoly vs p"
chaieb@33152
  2118
  let ?c = "?N c"
chaieb@33152
  2119
  let ?d = "?N d"
chaieb@33152
  2120
  let ?t = "?Nt x t"
chaieb@33152
  2121
  let ?s = "?Nt x s"
chaieb@33152
  2122
  let ?a = "?N a"
chaieb@33152
  2123
  let ?r = "?Nt x r"
chaieb@33152
  2124
  from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r" by simp_all
chaieb@33152
  2125
  note r= tmbound0_I[OF lin(3), of vs _ bs x]
chaieb@33152
  2126
  have cd_cs: "?c * ?d < 0 \<or> ?c * ?d > 0 \<or> (?c = 0 \<and> ?d = 0) \<or> (?c = 0 \<and> ?d < 0) \<or> (?c = 0 \<and> ?d > 0) \<or> (?c < 0 \<and> ?d = 0) \<or> (?c > 0 \<and> ?d = 0)" by auto
chaieb@33152
  2127
  moreover
chaieb@33152
  2128
  {assume c: "?c=0" and d: "?d=0"
chaieb@33152
  2129
    hence ?thesis  using nc nd by (simp add: polyneg_norm lt r[of 0] msubstlt_def Let_def evaldjf_ex)}
chaieb@33152
  2130
  moreover
chaieb@33152
  2131
  {assume dc: "?c*?d > 0" 
chaieb@33152
  2132
    from mult_pos_pos[OF one_plus_one_pos dc] have dc': "(1 + 1)*?c *?d > 0" by simp
chaieb@33152
  2133
    hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
chaieb@33152
  2134
    from dc' have dc'': "\<not> (1 + 1)*?c *?d < 0" by simp
chaieb@33152
  2135
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  2136
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  2137
      by (simp add: field_simps)
chaieb@33152
  2138
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2139
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r < 0" 
chaieb@33152
  2140
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  2141
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) < 0"
chaieb@33152
  2142
      
chaieb@33152
  2143
      using dc' dc'' mult_less_cancel_left_disj[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
chaieb@33152
  2144
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r < 0" 
chaieb@33152
  2145
      using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
haftmann@36347
  2146
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  2147
    finally  have ?thesis using dc c d  nc nd dc'
haftmann@36347
  2148
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
chaieb@33152
  2149
    apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  2150
    by (simp add: field_simps order_less_not_sym[OF dc])}
chaieb@33152
  2151
  moreover
chaieb@33152
  2152
  {assume dc: "?c*?d < 0" 
chaieb@33152
  2153
chaieb@33152
  2154
    from dc one_plus_one_pos[where ?'a='a] have dc': "(1 + 1)*?c *?d < 0"
haftmann@35033
  2155
      by (simp add: mult_less_0_iff field_simps) 
chaieb@33152
  2156
    hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
chaieb@33152
  2157
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  2158
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  2159
      by (simp add: field_simps)
chaieb@33152
  2160
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2161
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r < 0" 
chaieb@33152
  2162
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  2163
chaieb@33152
  2164
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) > 0"
chaieb@33152
  2165
      
chaieb@33152
  2166
      using dc' order_less_not_sym[OF dc'] mult_less_cancel_left_disj[of "(1 + 1) * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r"] by simp
chaieb@33152
  2167
    also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - (1 + 1)*?c*?d*?r < 0" 
chaieb@33152
  2168
      using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
haftmann@36347
  2169
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  2170
    finally  have ?thesis using dc c d  nc nd
haftmann@36347
  2171
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
chaieb@33152
  2172
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  2173
      by (simp add: field_simps order_less_not_sym[OF dc]) }
chaieb@33152
  2174
  moreover
chaieb@33152
  2175
  {assume c: "?c > 0" and d: "?d=0"  
chaieb@33152
  2176
    from c have c'': "(1 + 1)*?c > 0" by (simp add: zero_less_mult_iff)
chaieb@33152
  2177
    from c have c': "(1 + 1)*?c \<noteq> 0" by simp
haftmann@36347
  2178
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
chaieb@33152
  2179
    have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2180
    also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r < 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
chaieb@33152
  2181
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) < 0"
chaieb@33152
  2182
      using c mult_less_cancel_left_disj[of "(1 + 1) * ?c" "?a* (- ?t / ((1 + 1)*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
chaieb@33152
  2183
    also have "\<dots> \<longleftrightarrow> - ?a*?t+  (1 + 1)*?c *?r < 0" 
chaieb@33152
  2184
      using nonzero_mult_divide_cancel_left[OF c'] c
haftmann@36347
  2185
      by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
chaieb@33152
  2186
    finally have ?thesis using c d nc nd 
haftmann@36347
  2187
      apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2188
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2189
      using c order_less_not_sym[OF c] less_imp_neq[OF c]
haftmann@36347
  2190
      by (simp add: field_simps )  }
chaieb@33152
  2191
  moreover
chaieb@33152
  2192
  {assume c: "?c < 0" and d: "?d=0"  hence c': "(1 + 1)*?c \<noteq> 0" by simp
chaieb@33152
  2193
    from c have c'': "(1 + 1)*?c < 0" by (simp add: mult_less_0_iff)
haftmann@36347
  2194
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
chaieb@33152
  2195
    have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2196
    also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r < 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
chaieb@33152
  2197
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) > 0"
chaieb@33152
  2198
      using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_less_cancel_left_disj[of "(1 + 1) * ?c" 0 "?a* (- ?t / ((1 + 1)*?c))+ ?r"] by simp
chaieb@33152
  2199
    also have "\<dots> \<longleftrightarrow> ?a*?t -  (1 + 1)*?c *?r < 0" 
chaieb@33152
  2200
      using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
haftmann@36347
  2201
        by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
chaieb@33152
  2202
    finally have ?thesis using c d nc nd 
haftmann@36347
  2203
      apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2204
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2205
      using c order_less_not_sym[OF c] less_imp_neq[OF c]
haftmann@36347
  2206
      by (simp add: field_simps )    }
chaieb@33152
  2207
  moreover
chaieb@33152
  2208
  moreover
chaieb@33152
  2209
  {assume c: "?c = 0" and d: "?d>0"  
chaieb@33152
  2210
    from d have d'': "(1 + 1)*?d > 0" by (simp add: zero_less_mult_iff)
chaieb@33152
  2211
    from d have d': "(1 + 1)*?d \<noteq> 0" by simp
haftmann@36347
  2212
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
chaieb@33152
  2213
    have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2214
    also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r < 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
chaieb@33152
  2215
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) < 0"
chaieb@33152
  2216
      using d mult_less_cancel_left_disj[of "(1 + 1) * ?d" "?a* (- ?s / ((1 + 1)*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
chaieb@33152
  2217
    also have "\<dots> \<longleftrightarrow> - ?a*?s+  (1 + 1)*?d *?r < 0" 
chaieb@33152
  2218
      using nonzero_mult_divide_cancel_left[OF d'] d
haftmann@36347
  2219
      by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
chaieb@33152
  2220
    finally have ?thesis using c d nc nd 
haftmann@36347
  2221
      apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2222
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2223
      using d order_less_not_sym[OF d] less_imp_neq[OF d]
haftmann@36347
  2224
      by (simp add: field_simps)  }
chaieb@33152
  2225
  moreover
chaieb@33152
  2226
  {assume c: "?c = 0" and d: "?d<0"  hence d': "(1 + 1)*?d \<noteq> 0" by simp
chaieb@33152
  2227
    from d have d'': "(1 + 1)*?d < 0" by (simp add: mult_less_0_iff)
haftmann@36347
  2228
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
chaieb@33152
  2229
    have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2230
    also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r < 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
chaieb@33152
  2231
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) > 0"
chaieb@33152
  2232
      using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_less_cancel_left_disj[of "(1 + 1) * ?d" 0 "?a* (- ?s / ((1 + 1)*?d))+ ?r"] by simp
chaieb@33152
  2233
    also have "\<dots> \<longleftrightarrow> ?a*?s -  (1 + 1)*?d *?r < 0" 
chaieb@33152
  2234
      using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
haftmann@36347
  2235
        by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
chaieb@33152
  2236
    finally have ?thesis using c d nc nd 
haftmann@36347
  2237
      apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2238
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2239
      using d order_less_not_sym[OF d] less_imp_neq[OF d]
haftmann@36347
  2240
      by (simp add: field_simps )    }
chaieb@33152
  2241
ultimately show ?thesis by blast
chaieb@33152
  2242
qed
chaieb@33152
  2243
chaieb@33152
  2244
definition "msubstle c t d s a r = 
chaieb@33152
  2245
  evaldjf (split conj) 
chaieb@33152
  2246
  [(let cd = c *\<^sub>p d in (lt (CP (~\<^sub>p cd)), Le (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2247
  (let cd = c *\<^sub>p d in (lt (CP cd), Le (Sub (Mul a (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2248
   (conj (lt (CP (~\<^sub>p c))) (Eq (CP d)) , Le (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2249
   (conj (lt (CP c)) (Eq (CP d)) , Le (Sub (Mul a t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2250
   (conj (lt (CP (~\<^sub>p d))) (Eq (CP c)) , Le (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2251
   (conj (lt (CP d)) (Eq (CP c)) , Le (Sub (Mul a s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2252
   (conj (Eq (CP c)) (Eq (CP d)) , Le r)]"
chaieb@33152
  2253
chaieb@33152
  2254
lemma msubstle_nb: assumes lp: "islin (Le (CNP 0 a r))" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  2255
  shows "bound0 (msubstle c t d s a r)"
chaieb@33152
  2256
proof-
chaieb@33152
  2257
  have th: "\<forall>x\<in> set [(let cd = c *\<^sub>p d in (lt (CP (~\<^sub>p cd)), Le (Add (Mul (~\<^sub>p a) (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2258
  (let cd = c *\<^sub>p d in (lt (CP cd), Le (Sub (Mul a (Add (Mul d t) (Mul c s))) (Mul (2\<^sub>p *\<^sub>p cd) r)))),
chaieb@33152
  2259
   (conj (lt (CP (~\<^sub>p c))) (Eq (CP d)) , Le (Add (Mul (~\<^sub>p a) t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2260
   (conj (lt (CP c)) (Eq (CP d)) , Le (Sub (Mul a t) (Mul (2\<^sub>p *\<^sub>p c) r))),
chaieb@33152
  2261
   (conj (lt (CP (~\<^sub>p d))) (Eq (CP c)) , Le (Add (Mul (~\<^sub>p a) s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2262
   (conj (lt (CP d)) (Eq (CP c)) , Le (Sub (Mul a s) (Mul (2\<^sub>p *\<^sub>p d) r))),
chaieb@33152
  2263
   (conj (Eq (CP c)) (Eq (CP d)) , Le r)]. bound0 (split conj x)"
chaieb@33152
  2264
    using lp by (simp add: Let_def t s lt_nb )
chaieb@33152
  2265
  from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstle_def)
chaieb@33152
  2266
qed
chaieb@33152
  2267
chaieb@33152
  2268
lemma msubstle: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Le (CNP 0 a r))" 
chaieb@33152
  2269
  shows "Ifm vs (x#bs) (msubstle c t d s a r) \<longleftrightarrow> 
chaieb@33152
  2270
  Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Le (CNP 0 a r))" (is "?lhs = ?rhs")
chaieb@33152
  2271
proof-
chaieb@33152
  2272
  let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
chaieb@33152
  2273
  let ?N = "\<lambda>p. Ipoly vs p"
chaieb@33152
  2274
  let ?c = "?N c"
chaieb@33152
  2275
  let ?d = "?N d"
chaieb@33152
  2276
  let ?t = "?Nt x t"
chaieb@33152
  2277
  let ?s = "?Nt x s"
chaieb@33152
  2278
  let ?a = "?N a"
chaieb@33152
  2279
  let ?r = "?Nt x r"
chaieb@33152
  2280
  from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r" by simp_all
chaieb@33152
  2281
  note r= tmbound0_I[OF lin(3), of vs _ bs x]
chaieb@33152
  2282
  have cd_cs: "?c * ?d < 0 \<or> ?c * ?d > 0 \<or> (?c = 0 \<and> ?d = 0) \<or> (?c = 0 \<and> ?d < 0) \<or> (?c = 0 \<and> ?d > 0) \<or> (?c < 0 \<and> ?d = 0) \<or> (?c > 0 \<and> ?d = 0)" by auto
chaieb@33152
  2283
  moreover
chaieb@33152
  2284
  {assume c: "?c=0" and d: "?d=0"
chaieb@33152
  2285
    hence ?thesis  using nc nd by (simp add: polyneg_norm polymul_norm lt r[of 0] msubstle_def Let_def evaldjf_ex)}
chaieb@33152
  2286
  moreover
chaieb@33152
  2287
  {assume dc: "?c*?d > 0" 
chaieb@33152
  2288
    from mult_pos_pos[OF one_plus_one_pos dc] have dc': "(1 + 1)*?c *?d > 0" by simp
chaieb@33152
  2289
    hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
chaieb@33152
  2290
    from dc' have dc'': "\<not> (1 + 1)*?c *?d < 0" by simp
chaieb@33152
  2291
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  2292
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  2293
      by (simp add: field_simps)
chaieb@33152
  2294
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2295
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r <= 0" 
chaieb@33152
  2296
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  2297
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) <= 0"
chaieb@33152
  2298
      
chaieb@33152
  2299
      using dc' dc'' mult_le_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
chaieb@33152
  2300
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r <= 0" 
chaieb@33152
  2301
      using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
haftmann@36347
  2302
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  2303
    finally  have ?thesis using dc c d  nc nd dc'
haftmann@36347
  2304
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
chaieb@33152
  2305
    apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  2306
    by (simp add: field_simps order_less_not_sym[OF dc])}
chaieb@33152
  2307
  moreover
chaieb@33152
  2308
  {assume dc: "?c*?d < 0" 
chaieb@33152
  2309
chaieb@33152
  2310
    from dc one_plus_one_pos[where ?'a='a] have dc': "(1 + 1)*?c *?d < 0"
chaieb@33152
  2311
      by (simp add: mult_less_0_iff field_simps add_neg_neg add_pos_pos)
chaieb@33152
  2312
    hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
chaieb@33152
  2313
    from add_frac_eq[OF c d, of "- ?t" "- ?s"]
chaieb@33152
  2314
    have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
haftmann@36347
  2315
      by (simp add: field_simps)
chaieb@33152
  2316
    have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2317
    also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r <= 0" 
chaieb@33152
  2318
      by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
chaieb@33152
  2319
chaieb@33152
  2320
    also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) >= 0"
chaieb@33152
  2321
      
chaieb@33152
  2322
      using dc' order_less_not_sym[OF dc'] mult_le_cancel_left[of "(1 + 1) * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r"] by simp
chaieb@33152
  2323
    also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - (1 + 1)*?c*?d*?r <= 0" 
chaieb@33152
  2324
      using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
haftmann@36347
  2325
      by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
chaieb@33152
  2326
    finally  have ?thesis using dc c d  nc nd
haftmann@36347
  2327
      apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
chaieb@33152
  2328
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
haftmann@36347
  2329
      by (simp add: field_simps order_less_not_sym[OF dc]) }
chaieb@33152
  2330
  moreover
chaieb@33152
  2331
  {assume c: "?c > 0" and d: "?d=0"  
chaieb@33152
  2332
    from c have c'': "(1 + 1)*?c > 0" by (simp add: zero_less_mult_iff)
chaieb@33152
  2333
    from c have c': "(1 + 1)*?c \<noteq> 0" by simp
haftmann@36347
  2334
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
chaieb@33152
  2335
    have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2336
    also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r <= 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
chaieb@33152
  2337
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) <= 0"
chaieb@33152
  2338
      using c mult_le_cancel_left[of "(1 + 1) * ?c" "?a* (- ?t / ((1 + 1)*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
chaieb@33152
  2339
    also have "\<dots> \<longleftrightarrow> - ?a*?t+  (1 + 1)*?c *?r <= 0" 
chaieb@33152
  2340
      using nonzero_mult_divide_cancel_left[OF c'] c
haftmann@36347
  2341
      by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
chaieb@33152
  2342
    finally have ?thesis using c d nc nd 
haftmann@36347
  2343
      apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2344
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2345
      using c order_less_not_sym[OF c] less_imp_neq[OF c]
haftmann@36347
  2346
      by (simp add: field_simps )  }
chaieb@33152
  2347
  moreover
chaieb@33152
  2348
  {assume c: "?c < 0" and d: "?d=0"  hence c': "(1 + 1)*?c \<noteq> 0" by simp
chaieb@33152
  2349
    from c have c'': "(1 + 1)*?c < 0" by (simp add: mult_less_0_iff)
haftmann@36347
  2350
    from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
chaieb@33152
  2351
    have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2352
    also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r <= 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
chaieb@33152
  2353
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) >= 0"
chaieb@33152
  2354
      using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_le_cancel_left[of "(1 + 1) * ?c" 0 "?a* (- ?t / ((1 + 1)*?c))+ ?r"] by simp
chaieb@33152
  2355
    also have "\<dots> \<longleftrightarrow> ?a*?t -  (1 + 1)*?c *?r <= 0" 
chaieb@33152
  2356
      using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
haftmann@36347
  2357
        by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
chaieb@33152
  2358
    finally have ?thesis using c d nc nd 
haftmann@36347
  2359
      apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2360
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2361
      using c order_less_not_sym[OF c] less_imp_neq[OF c]
haftmann@36347
  2362
      by (simp add: field_simps )    }
chaieb@33152
  2363
  moreover
chaieb@33152
  2364
  moreover
chaieb@33152
  2365
  {assume c: "?c = 0" and d: "?d>0"  
chaieb@33152
  2366
    from d have d'': "(1 + 1)*?d > 0" by (simp add: zero_less_mult_iff)
chaieb@33152
  2367
    from d have d': "(1 + 1)*?d \<noteq> 0" by simp
haftmann@36347
  2368
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
chaieb@33152
  2369
    have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2370
    also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r <= 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
chaieb@33152
  2371
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) <= 0"
chaieb@33152
  2372
      using d mult_le_cancel_left[of "(1 + 1) * ?d" "?a* (- ?s / ((1 + 1)*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
chaieb@33152
  2373
    also have "\<dots> \<longleftrightarrow> - ?a*?s+  (1 + 1)*?d *?r <= 0" 
chaieb@33152
  2374
      using nonzero_mult_divide_cancel_left[OF d'] d
haftmann@36347
  2375
      by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
chaieb@33152
  2376
    finally have ?thesis using c d nc nd 
haftmann@36347
  2377
      apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2378
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2379
      using d order_less_not_sym[OF d] less_imp_neq[OF d]
haftmann@36347
  2380
      by (simp add: field_simps )  }
chaieb@33152
  2381
  moreover
chaieb@33152
  2382
  {assume c: "?c = 0" and d: "?d<0"  hence d': "(1 + 1)*?d \<noteq> 0" by simp
chaieb@33152
  2383
    from d have d'': "(1 + 1)*?d < 0" by (simp add: mult_less_0_iff)
haftmann@36347
  2384
    from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
chaieb@33152
  2385
    have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
chaieb@33152
  2386
    also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r <= 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
chaieb@33152
  2387
    also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) >= 0"
chaieb@33152
  2388
      using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_le_cancel_left[of "(1 + 1) * ?d" 0 "?a* (- ?s / ((1 + 1)*?d))+ ?r"] by simp
chaieb@33152
  2389
    also have "\<dots> \<longleftrightarrow> ?a*?s -  (1 + 1)*?d *?r <= 0" 
chaieb@33152
  2390
      using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
haftmann@36347
  2391
        by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
chaieb@33152
  2392
    finally have ?thesis using c d nc nd 
haftmann@36347
  2393
      apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
chaieb@33152
  2394
      apply (simp only: one_add_one_is_two[symmetric] of_int_add)
chaieb@33152
  2395
      using d order_less_not_sym[OF d] less_imp_neq[OF d]
haftmann@36347
  2396
      by (simp add: field_simps )    }
chaieb@33152
  2397
ultimately show ?thesis by blast
chaieb@33152
  2398
qed
chaieb@33152
  2399
chaieb@33152
  2400
chaieb@33152
  2401
fun msubst :: "fm \<Rightarrow> (poly \<times> tm) \<times> (poly \<times> tm) \<Rightarrow> fm" where
chaieb@33152
  2402
  "msubst (And p q) ((c,t), (d,s)) = conj (msubst p ((c,t),(d,s))) (msubst q ((c,t),(d,s)))"
chaieb@33152
  2403
| "msubst (Or p q) ((c,t), (d,s)) = disj (msubst p ((c,t),(d,s))) (msubst q ((c,t), (d,s)))"
chaieb@33152
  2404
| "msubst (Eq (CNP 0 a r)) ((c,t),(d,s)) = msubsteq c t d s a r"
chaieb@33152
  2405
| "msubst (NEq (CNP 0 a r)) ((c,t),(d,s)) = msubstneq c t d s a r"
chaieb@33152
  2406
| "msubst (Lt (CNP 0 a r)) ((c,t),(d,s)) = msubstlt c t d s a r"
chaieb@33152
  2407
| "msubst (Le (CNP 0 a r)) ((c,t),(d,s)) = msubstle c t d s a r"
chaieb@33152
  2408
| "msubst p ((c,t),(d,s)) = p"
chaieb@33152
  2409
chaieb@33152
  2410
lemma msubst_I: assumes lp: "islin p" and nc: "isnpoly c" and nd: "isnpoly d"
chaieb@33152
  2411
  shows "Ifm vs (x#bs) (msubst p ((c,t),(d,s))) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) p"
chaieb@33152
  2412
  using lp
chaieb@33152
  2413
by (induct p rule: islin.induct, auto simp add: tmbound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) /(1 + 1)" and b'=x and bs = bs and vs=vs] bound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) /(1 + 1)" and b'=x and bs = bs and vs=vs] msubsteq msubstneq msubstlt[OF nc nd] msubstle[OF nc nd])
chaieb@33152
  2414
chaieb@33152
  2415
lemma msubst_nb: assumes lp: "islin p" and t: "tmbound0 t" and s: "tmbound0 s"
chaieb@33152
  2416
  shows "bound0 (msubst p ((c,t),(d,s)))"
chaieb@33152
  2417
  using lp t s
chaieb@33152
  2418
  by (induct p rule: islin.induct, auto simp add: msubsteq_nb msubstneq_nb msubstlt_nb msubstle_nb)
chaieb@33152
  2419
chaieb@33152
  2420
lemma fr_eq_msubst: 
chaieb@33152
  2421
  assumes lp: "islin p"
chaieb@33152
  2422
  shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst p ((c,t),(d,s)))))"
chaieb@33152
  2423
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
chaieb@33152
  2424
proof-
chaieb@33152
  2425
from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
chaieb@33152
  2426
{fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
chaieb@33152
  2427
  and pts: "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p"
chaieb@33152
  2428
  from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
chaieb@33152
  2429
  from msubst_I[OF lp norm, of vs x bs t s] pts
chaieb@33152
  2430
  have "Ifm vs (x # bs) (msubst p ((c, t), d, s))" ..}
chaieb@33152
  2431
moreover
chaieb@33152
  2432
{fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
chaieb@33152
  2433
  and pts: "Ifm vs (x # bs) (msubst p ((c, t), d, s))"
chaieb@33152
  2434
  from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
chaieb@33152
  2435
  from msubst_I[OF lp norm, of vs x bs t s] pts
chaieb@33152
  2436
  have "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p" ..}
chaieb@33152
  2437
ultimately have th': "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p) \<longleftrightarrow> ?F" by blast
chaieb@33152
  2438
from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
chaieb@33152
  2439
qed 
chaieb@33152
  2440
haftmann@36409
  2441
lemma simpfm_lin:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
chaieb@33152
  2442
  shows "qfree p \<Longrightarrow> islin (simpfm p)"
chaieb@33152
  2443
  by (induct p rule: simpfm.induct, auto simp add: conj_lin disj_lin)
chaieb@33152
  2444
chaieb@33152
  2445
definition 
chaieb@33152
  2446
  "ferrack p \<equiv> let q = simpfm p ; mp = minusinf q ; pp = plusinf q
chaieb@33152
  2447
  in if (mp = T \<or> pp = T) then T 
krauss@42694
  2448
     else (let U = alluopairs (remdups (uset  q))
chaieb@33152
  2449
           in decr0 (disj mp (disj pp (evaldjf (simpfm o (msubst q)) U ))))"
chaieb@33152
  2450
chaieb@33152
  2451
lemma ferrack: 
chaieb@33152
  2452
  assumes qf: "qfree p"
chaieb@33152
  2453
  shows "qfree (ferrack p) \<and> ((Ifm vs bs (ferrack p)) = (Ifm vs bs (E p)))"
chaieb@33152
  2454
  (is "_ \<and> (?rhs = ?lhs)")
chaieb@33152
  2455
proof-
chaieb@33152
  2456
  let ?I = "\<lambda> x p. Ifm vs (x#bs) p"
chaieb@33152
  2457
  let ?N = "\<lambda> t. Ipoly vs t"
chaieb@33152
  2458
  let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
chaieb@33152
  2459
  let ?q = "simpfm p" 
krauss@42694
  2460
  let ?U = "remdups(uset ?q)"
chaieb@33152
  2461
  let ?Up = "alluopairs ?U"
chaieb@33152
  2462
  let ?mp = "minusinf ?q"
chaieb@33152
  2463
  let ?pp = "plusinf ?q"
chaieb@33152
  2464
  let ?I = "\<lambda>p. Ifm vs (x#bs) p"
chaieb@33152
  2465
  from simpfm_lin[OF qf] simpfm_qf[OF qf] have lq: "islin ?q" and q_qf: "qfree ?q" .
chaieb@33152
  2466
  from minusinf_nb[OF lq] plusinf_nb[OF lq] have mp_nb: "bound0 ?mp" and pp_nb: "bound0 ?pp" .
chaieb@33152
  2467
  from bound0_qf[OF mp_nb] bound0_qf[OF pp_nb] have mp_qf: "qfree ?mp" and pp_qf: "qfree ?pp" .
chaieb@33152
  2468
  from uset_l[OF lq] have U_l: "\<forall>(c, s)\<in>set ?U. isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s"
chaieb@33152
  2469
    by simp
chaieb@33152
  2470
  {fix c t d s assume ctU: "(c,t) \<in> set ?U" and dsU: "(d,s) \<in> set ?U"
chaieb@33152
  2471
    from U_l ctU dsU have norm: "isnpoly c" "isnpoly d" by auto
chaieb@33152
  2472
    from msubst_I[OF lq norm, of vs x bs t s] msubst_I[OF lq norm(2,1), of vs x bs s t]
haftmann@36347
  2473
    have "?I (msubst ?q ((c,t),(d,s))) = ?I (msubst ?q ((d,s),(c,t)))" by (simp add: field_simps)}
chaieb@33152
  2474
  hence th0: "\<forall>x \<in> set ?U. \<forall>y \<in> set ?U. ?I (msubst ?q (x, y)) \<longleftrightarrow> ?I (msubst ?q (y, x))" by clarsimp
chaieb@33152
  2475
  {fix x assume xUp: "x \<in> set ?Up" 
chaieb@33152
  2476
    then  obtain c t d s where ctU: "(c,t) \<in> set ?U" and dsU: "(d,s) \<in> set ?U" 
chaieb@33152
  2477
      and x: "x = ((c,t),(d,s))" using alluopairs_set1[of ?U] by auto  
chaieb@33152
  2478
    from U_l[rule_format, OF ctU] U_l[rule_format, OF dsU] 
chaieb@33152
  2479
    have nbs: "tmbound0 t" "tmbound0 s" by simp_all
chaieb@33152
  2480
    from simpfm_bound0[OF msubst_nb[OF lq nbs, of c d]] 
chaieb@33152
  2481
    have "bound0 ((simpfm o (msubst (simpfm p))) x)" using x by simp}
chaieb@33152
  2482
  with evaldjf_bound0[of ?Up "(simpfm o (msubst (simpfm p)))"]
chaieb@33152
  2483
  have "bound0 (evaldjf (simpfm o (msubst (simpfm p))) ?Up)" by blast
chaieb@33152
  2484
  with mp_nb pp_nb 
chaieb@33152
  2485
  have th1: "bound0 (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up )))" by (simp add: disj_nb)
chaieb@33152
  2486
  from decr0_qf[OF th1] have thqf: "qfree (ferrack p)" by (simp add: ferrack_def Let_def)
chaieb@33152
  2487
  have "?lhs \<longleftrightarrow> (\<exists>x. Ifm vs (x#bs) ?q)" by simp
chaieb@33152
  2488
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists>(c, t)\<in>set ?U. \<exists>(d, s)\<in>set ?U. ?I (msubst (simpfm p) ((c, t), d, s)))" using fr_eq_msubst[OF lq, of vs bs x] by simp
nipkow@42720
  2489
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> (\<exists> (x,y) \<in> set ?Up. ?I ((simpfm o (msubst ?q)) (x,y)))" using alluopairs_bex[OF th0] by simp
chaieb@33152
  2490
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (evaldjf (simpfm o (msubst ?q)) ?Up)" 
chaieb@33152
  2491
    by (simp add: evaldjf_ex)
chaieb@33152
  2492
  also have "\<dots> \<longleftrightarrow> ?I (disj ?mp (disj ?pp (evaldjf (simpfm o (msubst ?q)) ?Up)))" by simp
chaieb@33152
  2493
  also have "\<dots> \<longleftrightarrow> ?rhs" using decr0[OF th1, of vs x bs]
chaieb@33152
  2494
    apply (simp add: ferrack_def Let_def)
chaieb@33152
  2495
    by (cases "?mp = T \<or> ?pp = T", auto)
chaieb@33152
  2496
  finally show ?thesis using thqf by blast
chaieb@33152
  2497
qed
chaieb@33152
  2498
chaieb@33152
  2499
definition "frpar p = simpfm (qelim p ferrack)"
chaieb@33152
  2500
lemma frpar: "qfree (frpar p) \<and> (Ifm vs bs (frpar p) \<longleftrightarrow> Ifm vs bs p)"
chaieb@33152
  2501
proof-
chaieb@33152
  2502
  from ferrack have th: "\<forall>bs p. qfree p \<longrightarrow> qfree (ferrack p) \<and> Ifm vs bs (ferrack p) = Ifm vs bs (E p)" by blast
chaieb@33152
  2503
  from qelim[OF th, of p bs] show ?thesis  unfolding frpar_def by auto
chaieb@33152
  2504
qed
chaieb@33152
  2505
chaieb@33152
  2506
chaieb@33152
  2507
section{* Second implemenation: Case splits not local *}
chaieb@33152
  2508
chaieb@33152
  2509
lemma fr_eq2:  assumes lp: "islin p"
chaieb@33152
  2510
  shows "(\<exists> x. Ifm vs (x#bs) p) \<longleftrightarrow> 
chaieb@33152
  2511
   ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> 
chaieb@33152
  2512
    (Ifm vs (0#bs) p) \<or> 
chaieb@33152
  2513
    (\<exists> (n,t) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ifm vs ((- Itm vs (x#bs) t /  (Ipoly vs n * (1 + 1)))#bs) p) \<or> 
chaieb@33152
  2514
    (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ipoly vs m \<noteq> 0 \<and> Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) /(1 + 1))#bs) p))"
chaieb@33152
  2515
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?Z \<or> ?U \<or> ?F)" is "?E = ?D")
chaieb@33152
  2516
proof
chaieb@33152
  2517
  assume px: "\<exists> x. ?I x p"
chaieb@33152
  2518
  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
chaieb@33152
  2519
  moreover {assume "?M \<or> ?P" hence "?D" by blast}
chaieb@33152
  2520
  moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
chaieb@33152
  2521
    from inf_uset[OF lp nmi npi, OF px] 
chaieb@33152
  2522
    obtain c t d s where ct: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" "?I ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / ((1\<Colon>'a) + (1\<Colon>'a))) p"
chaieb@33152
  2523
      by auto
chaieb@33152
  2524
    let ?c = "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
chaieb@33152
  2525
    let ?d = "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
chaieb@33152
  2526
    let ?s = "Itm vs (x # bs) s"
chaieb@33152
  2527
    let ?t = "Itm vs (x # bs) t"
chaieb@33152
  2528
    have eq2: "\<And>(x::'a). x + x = (1 + 1) * x"
haftmann@36347
  2529
      by  (simp add: field_simps)
chaieb@33152
  2530
    {assume "?c = 0 \<and> ?d = 0"
chaieb@33152
  2531
      with ct have ?D by simp}
chaieb@33152
  2532
    moreover
chaieb@33152
  2533
    {assume z: "?c = 0" "?d \<noteq> 0"
chaieb@33152
  2534
      from z have ?D using ct by auto}
chaieb@33152
  2535
    moreover
chaieb@33152
  2536
    {assume z: "?c \<noteq> 0" "?d = 0"
chaieb@33152
  2537
      with ct have ?D by auto }
chaieb@33152
  2538
    moreover
chaieb@33152
  2539
    {assume z: "?c \<noteq> 0" "?d \<noteq> 0"
chaieb@33152
  2540
      from z have ?F using ct
wenzelm@33268
  2541
        apply - apply (rule bexI[where x = "(c,t)"], simp_all)
wenzelm@33268
  2542
        by (rule bexI[where x = "(d,s)"], simp_all)
chaieb@33152
  2543
      hence ?D by blast}
chaieb@33152
  2544
    ultimately have ?D by auto}
chaieb@33152
  2545
  ultimately show "?D" by blast
chaieb@33152
  2546
next
chaieb@33152
  2547
  assume "?D" 
chaieb@33152
  2548
  moreover {assume m:"?M" from minusinf_ex[OF lp m] have "?E" .}
chaieb@33152
  2549
  moreover {assume p: "?P" from plusinf_ex[OF lp p] have "?E" . }
chaieb@33152
  2550
  moreover {assume f:"?F" hence "?E" by blast}
chaieb@33152
  2551
  ultimately show "?E" by blast
chaieb@33152
  2552
qed
chaieb@33152
  2553
chaieb@33152
  2554
definition "msubsteq2 c t a b = Eq (Add (Mul a t) (Mul c b))"
chaieb@33152
  2555
definition "msubstltpos c t a b = Lt (Add (Mul a t) (Mul c b))"
chaieb@33152
  2556
definition "msubstlepos c t a b = Le (Add (Mul a t) (Mul c b))"
chaieb@33152
  2557
definition "msubstltneg c t a b = Lt (Neg (Add (Mul a t) (Mul c b)))"
chaieb@33152
  2558
definition "msubstleneg c t a b = Le (Neg (Add (Mul a t) (Mul c b)))"
chaieb@33152
  2559
chaieb@33152
  2560
lemma msubsteq2: 
chaieb@33152
  2561
  assumes nz: "Ipoly vs c \<noteq> 0" and l: "islin (Eq (CNP 0 a b))"
chaieb@33152
  2562
  shows "Ifm vs (x#bs) (msubsteq2 c t a b) = Ifm vs (((Itm vs (x#bs) t /  Ipoly vs c ))#bs) (Eq (CNP 0 a b))" (is "?lhs = ?rhs")
chaieb@33152
  2563
  using nz l tmbound0_I[of b vs x bs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" , symmetric]
chaieb@33152
  2564
  by (simp add: msubsteq2_def field_simps)
chaieb@33152
  2565
chaieb@33152
  2566
lemma msubstltpos: 
chaieb@33152
  2567
  assumes nz: "Ipoly vs c > 0" and l: "islin (Lt (CNP 0 a b))"
chaieb@33152
  2568
  shows "Ifm vs (x#bs) (msubstltpos c t a b) = Ifm vs (((Itm vs (x#bs) t /  Ipoly vs c ))#bs) (Lt (CNP 0 a b))" (is "?lhs = ?rhs")
chaieb@33152
  2569
  using nz l tmbound0_I[of b vs x bs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" , symmetric]
chaieb@33152
  2570
  by (simp add: msubstltpos_def field_simps)
chaieb@33152
  2571
chaieb@33152
  2572
lemma msubstlepos: 
chaieb@33152
  2573
  assumes nz: "Ipoly vs c > 0" and l: "islin (Le (CNP 0 a b))"
chaieb@33152
  2574
  shows "Ifm vs (x#bs) (msubstlepos c t a b) = Ifm vs (((Itm vs (x#bs) t /  Ipoly vs c ))#bs) (Le (CNP 0 a b))" (is "?lhs = ?rhs")
chaieb@33152
  2575
  using nz l tmbound0_I[of b vs x bs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" , symmetric]
chaieb@33152
  2576
  by (simp add: msubstlepos_def field_simps)
chaieb@33152
  2577
chaieb@33152
  2578
lemma msubstltneg: 
chaieb@33152
  2579
  assumes nz: "Ipoly vs c < 0" and l: "islin (Lt (CNP 0 a b))"
chaieb@33152
  2580
  shows "Ifm vs (x#bs) (msubstltneg c t a b) = Ifm vs (((Itm vs (x#bs) t /  Ipoly vs c ))#bs) (Lt (CNP 0 a b))" (is "?lhs = ?rhs")
chaieb@33152
  2581
  using nz l tmbound0_I[of b vs x bs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" , symmetric]
chaieb@33152
  2582
  by (simp add: msubstltneg_def field_simps del: minus_add_distrib)
chaieb@33152
  2583
chaieb@33152
  2584
lemma msubstleneg: 
chaieb@33152
  2585
  assumes nz: "Ipoly vs c < 0" and l: "islin (Le (CNP 0 a b))"
chaieb@33152
  2586
  shows "Ifm vs (x#bs) (msubstleneg c t a b) = Ifm vs (((Itm vs (x#bs) t /  Ipoly vs c ))#bs) (Le (CNP 0 a b))" (is "?lhs = ?rhs")
chaieb@33152
  2587
  using nz l tmbound0_I[of b vs x bs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" , symmetric]
chaieb@33152
  2588
  by (simp add: msubstleneg_def field_simps del: minus_add_distrib)
chaieb@33152
  2589
chaieb@33152
  2590
fun msubstpos :: "fm \<Rightarrow> poly \<Rightarrow> tm \<Rightarrow> fm" where
chaieb@33152
  2591
  "msubstpos (And p q) c t = And (msubstpos p c t) (msubstpos q c t)"
chaieb@33152
  2592
| "msubstpos (Or p q) c t = Or (msubstpos p c t) (msubstpos q c t)"
chaieb@33152
  2593
| "msubstpos (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
chaieb@33152
  2594
| "msubstpos (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
chaieb@33152
  2595
| "msubstpos (Lt (CNP 0 a r)) c t = msubstltpos c t a r"
chaieb@33152
  2596
| "msubstpos (Le (CNP 0 a r)) c t = msubstlepos c t a r"
chaieb@33152
  2597
| "msubstpos p c t = p"
chaieb@33152
  2598
    
chaieb@33152
  2599
lemma msubstpos_I: 
chaieb@33152
  2600
  assumes lp: "islin p" and pos: "Ipoly vs c > 0"
chaieb@33152
  2601
  shows "Ifm vs (x#bs) (msubstpos p c t) = Ifm vs (Itm vs (x#bs) t /  Ipoly vs c #bs) p"
chaieb@33152
  2602
  using lp pos
chaieb@33152
  2603
  by (induct p rule: islin.induct, auto simp add: msubsteq2 msubstltpos[OF pos] msubstlepos[OF pos] tmbound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] bound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] field_simps)
chaieb@33152
  2604
chaieb@33152
  2605
fun msubstneg :: "fm \<Rightarrow> poly \<Rightarrow> tm \<Rightarrow> fm" where
chaieb@33152
  2606
  "msubstneg (And p q) c t = And (msubstneg p c t) (msubstneg q c t)"
chaieb@33152
  2607
| "msubstneg (Or p q) c t = Or (msubstneg p c t) (msubstneg q c t)"
chaieb@33152
  2608
| "msubstneg (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
chaieb@33152
  2609
| "msubstneg (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
chaieb@33152
  2610
| "msubstneg (Lt (CNP 0 a r)) c t = msubstltneg c t a r"
chaieb@33152
  2611
| "msubstneg (Le (CNP 0 a r)) c t = msubstleneg c t a r"
chaieb@33152
  2612
| "msubstneg p c t = p"
chaieb@33152
  2613
chaieb@33152
  2614
lemma msubstneg_I: 
chaieb@33152
  2615
  assumes lp: "islin p" and pos: "Ipoly vs c < 0"
chaieb@33152
  2616
  shows "Ifm vs (x#bs) (msubstneg p c t) = Ifm vs (Itm vs (x#bs) t /  Ipoly vs c #bs) p"
chaieb@33152
  2617
  using lp pos
chaieb@33152
  2618
  by (induct p rule: islin.induct, auto simp add: msubsteq2 msubstltneg[OF pos] msubstleneg[OF pos] tmbound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] bound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] field_simps)
chaieb@33152
  2619
chaieb@33152
  2620
chaieb@33152
  2621
definition "msubst2 p c t = disj (conj (lt (CP (polyneg c))) (simpfm (msubstpos p c t))) (conj (lt (CP c)) (simpfm (msubstneg p c t)))"
chaieb@33152
  2622
chaieb@33152
  2623
lemma msubst2: assumes lp: "islin p" and nc: "isnpoly c" and nz: "Ipoly vs c \<noteq> 0"
chaieb@33152
  2624
  shows "Ifm vs (x#bs) (msubst2 p c t) = Ifm vs (Itm vs (x#bs) t /  Ipoly vs c #bs) p"
chaieb@33152
  2625
proof-
chaieb@33152
  2626
  let ?c = "Ipoly vs c"
chaieb@33152
  2627
  from nc have anc: "allpolys isnpoly (CP c)" "allpolys isnpoly (CP (~\<^sub>p c))" 
chaieb@33152
  2628
    by (simp_all add: polyneg_norm)
chaieb@33152
  2629
  from nz have "?c > 0 \<or> ?c < 0" by arith
chaieb@33152
  2630
  moreover
chaieb@33152
  2631
  {assume c: "?c < 0"
chaieb@33152
  2632
    from c msubstneg_I[OF lp c, of x bs t] lt[OF anc(1), of vs "x#bs"] lt[OF anc(2), of vs "x#bs"]
chaieb@33152
  2633
    have ?thesis by (auto simp add: msubst2_def)}
chaieb@33152
  2634
  moreover
chaieb@33152
  2635
  {assume c: "?c > 0"
chaieb@33152
  2636
    from c msubstpos_I[OF lp c, of x bs t] lt[OF anc(1), of vs "x#bs"] lt[OF anc(2), of vs "x#bs"]
chaieb@33152
  2637
    have ?thesis by (auto simp add: msubst2_def)}
chaieb@33152
  2638
  ultimately show ?thesis by blast
chaieb@33152
  2639
qed
chaieb@33152
  2640
chaieb@33152
  2641
term msubsteq2
chaieb@33152
  2642
lemma msubsteq2_nb: "tmbound0 t \<Longrightarrow> islin (Eq (CNP 0 a r)) \<Longrightarrow> bound0 (msubsteq2 c t a r)"
chaieb@33152
  2643
  by (simp add: msubsteq2_def)
chaieb@33152
  2644
chaieb@33152
  2645
lemma msubstltpos_nb: "tmbound0 t \<Longrightarrow> islin (Lt (CNP 0 a r)) \<Longrightarrow> bound0 (msubstltpos c t a r)"
chaieb@33152
  2646
  by (simp add: msubstltpos_def)
chaieb@33152
  2647
lemma msubstltneg_nb: "tmbound0 t \<Longrightarrow> islin (Lt (CNP 0 a r)) \<Longrightarrow> bound0 (msubstltneg c t a r)"
chaieb@33152
  2648
  by (simp add: msubstltneg_def)
chaieb@33152
  2649
chaieb@33152
  2650
lemma msubstlepos_nb: "tmbound0 t \<Longrightarrow> islin (Le (CNP 0 a r)) \<Longrightarrow> bound0 (msubstlepos c t a r)"
chaieb@33152
  2651
  by (simp add: msubstlepos_def)
chaieb@33152
  2652
lemma msubstleneg_nb: "tmbound0 t \<Longrightarrow> islin (Le (CNP 0 a r)) \<Longrightarrow> bound0 (msubstleneg c t a r)"
chaieb@33152
  2653
  by (simp add: msubstleneg_def)
chaieb@33152
  2654
chaieb@33152
  2655
lemma msubstpos_nb: assumes lp: "islin p" and tnb: "tmbound0 t"
chaieb@33152
  2656
  shows "bound0 (msubstpos p c t)"
chaieb@33152
  2657
using lp tnb
chaieb@33152
  2658
by (induct p c t rule: msubstpos.induct, auto simp add: msubsteq2_nb msubstltpos_nb msubstlepos_nb)
chaieb@33152
  2659
haftmann@36409
  2660
lemma msubstneg_nb: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" and lp: "islin p" and tnb: "tmbound0 t"
chaieb@33152
  2661
  shows "bound0 (msubstneg p c t)"
chaieb@33152
  2662
using lp tnb
chaieb@33152
  2663
by (induct p c t rule: msubstneg.induct, auto simp add: msubsteq2_nb msubstltneg_nb msubstleneg_nb)
chaieb@33152
  2664
haftmann@36409
  2665
lemma msubst2_nb: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" and lp: "islin p" and tnb: "tmbound0 t"
chaieb@33152
  2666
  shows "bound0 (msubst2 p c t)"
chaieb@33152
  2667
using lp tnb
chaieb@33152
  2668
by (simp add: msubst2_def msubstneg_nb msubstpos_nb conj_nb disj_nb lt_nb simpfm_bound0)
chaieb@33152
  2669
    
chaieb@33152
  2670
lemma of_int2: "of_int 2 = 1 + 1"
chaieb@33152
  2671
proof-
chaieb@33152
  2672
  have "(2::int) = 1 + 1" by simp
chaieb@33152
  2673
  hence "of_int 2 = of_int (1 + 1)" by simp
chaieb@33152
  2674
  thus ?thesis unfolding of_int_add by simp
chaieb@33152
  2675
qed
chaieb@33152
  2676
chaieb@33152
  2677
lemma of_int_minus2: "of_int (-2) = - (1 + 1)"
chaieb@33152
  2678
proof-
chaieb@33152
  2679
  have th: "(-2::int) = - 2" by simp
chaieb@33152
  2680
  show ?thesis unfolding th by (simp only: of_int_minus of_int2)
chaieb@33152
  2681
qed
chaieb@33152
  2682
chaieb@33152
  2683
chaieb@33152
  2684
lemma islin_qf: "islin p \<Longrightarrow> qfree p"
chaieb@33152
  2685
  by (induct p rule: islin.induct, auto simp add: bound0_qf)
chaieb@33152
  2686
lemma fr_eq_msubst2: 
chaieb@33152
  2687
  assumes lp: "islin p"
chaieb@33152
  2688
  shows "(\<exists> x. Ifm vs (x#bs) p) \<longleftrightarrow> ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> Ifm vs (x#bs) (subst0 (CP 0\<^sub>p) p) \<or> (\<exists>(n, t)\<in>set (uset p). Ifm vs (x# bs) (msubst2 p (n *\<^sub>p (C (-2,1))) t)) \<or> (\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))))"
chaieb@33152
  2689
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?Pz \<or> ?PU \<or> ?F)" is "?E = ?D")
chaieb@33152
  2690
proof-
chaieb@33152
  2691
  from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
chaieb@33152
  2692
  let ?I = "\<lambda>p. Ifm vs (x#bs) p"
chaieb@33152
  2693
  have n2: "isnpoly (C (-2,1))" by (simp add: isnpoly_def)
chaieb@33152
  2694
  note eq0 = subst0[OF islin_qf[OF lp], of vs x bs "CP 0\<^sub>p", simplified]
chaieb@33152
  2695
  
chaieb@33152
  2696
  have eq1: "(\<exists>(n, t)\<in>set (uset p). ?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p)"
chaieb@33152
  2697
  proof-
chaieb@33152
  2698
    {fix n t assume H: "(n, t)\<in>set (uset p)" "?I(msubst2 p (n *\<^sub>p C (-2, 1)) t)"
chaieb@33152
  2699
      from H(1) th have "isnpoly n" by blast
chaieb@33152
  2700
      hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" by (simp_all add: polymul_norm n2)
chaieb@33152
  2701
      have nn': "allpolys isnpoly (CP (~\<^sub>p (n *\<^sub>p C (-2, 1))))"
wenzelm@33268
  2702
        by (simp add: polyneg_norm nn)
chaieb@33152
  2703
      hence nn2: "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>n \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" using H(2) nn' nn 
wenzelm@33268
  2704
        by (auto simp add: msubst2_def lt zero_less_mult_iff mult_less_0_iff)
chaieb@33152
  2705
      from msubst2[OF lp nn nn2(1), of x bs t]
chaieb@33152
  2706
      have "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p"
wenzelm@33268
  2707
        using H(2) nn2 by (simp add: of_int_minus2 del: minus_add_distrib)}
chaieb@33152
  2708
    moreover
chaieb@33152
  2709
    {fix n t assume H: "(n, t)\<in>set (uset p)" "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p"
chaieb@33152
  2710
      from H(1) th have "isnpoly n" by blast
chaieb@33152
  2711
      hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
wenzelm@33268
  2712
        using H(2) by (simp_all add: polymul_norm n2)
chaieb@33152
  2713
      from msubst2[OF lp nn, of x bs t] have "?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)" using H(2,3) by (simp add: of_int_minus2 del: minus_add_distrib)}
chaieb@33152
  2714
    ultimately show ?thesis by blast
chaieb@33152
  2715
  qed
chaieb@33152
  2716
  have eq2: "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p).
chaieb@33152
  2717
     \<exists>(m, s)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p)" 
chaieb@33152
  2718
  proof-
chaieb@33152
  2719
    {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
chaieb@33152
  2720
     "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))"
chaieb@33152
  2721
      from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
chaieb@33152
  2722
      hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" 
wenzelm@33268
  2723
        by (simp_all add: polymul_norm n2)
chaieb@33152
  2724
      have stupid: "allpolys isnpoly (CP (~\<^sub>p (C (-2, 1) *\<^sub>p c *\<^sub>p d)))" "allpolys isnpoly (CP ((C (-2, 1) *\<^sub>p c *\<^sub>p d)))"
wenzelm@33268
  2725
        by (simp_all add: polyneg_norm nn)
chaieb@33152
  2726
      have nn': "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
wenzelm@33268
  2727
        using H(3) by (auto simp add: msubst2_def lt[OF stupid(1)]  lt[OF stupid(2)] zero_less_mult_iff mult_less_0_iff)
chaieb@33152
  2728
      from msubst2[OF lp nn nn'(1), of x bs ] H(3) nn'
chaieb@33152
  2729
      have "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p" 
wenzelm@33268
  2730
        apply (simp add: add_divide_distrib of_int_minus2 del: minus_add_distrib)
wenzelm@33268
  2731
        by (simp add: mult_commute)}
chaieb@33152
  2732
    moreover
chaieb@33152
  2733
    {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
chaieb@33152
  2734
      "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p"
chaieb@33152
  2735
     from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
chaieb@33152
  2736
      hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
wenzelm@33268
  2737
        using H(3,4) by (simp_all add: polymul_norm n2)
chaieb@33152
  2738
      from msubst2[OF lp nn, of x bs ] H(3,4,5) 
chaieb@33152
  2739
      have "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))" apply (simp add: add_divide_distrib of_int_minus2 del: minus_add_distrib)by (simp add: mult_commute)}
chaieb@33152
  2740
    ultimately show ?thesis by blast
chaieb@33152
  2741
  qed
chaieb@33152
  2742
  from fr_eq2[OF lp, of vs bs x] show ?thesis
chaieb@33152
  2743
    unfolding eq0 eq1 eq2 by blast  
chaieb@33152
  2744
qed
chaieb@33152
  2745
chaieb@33152
  2746
definition 
chaieb@33152
  2747
"ferrack2 p \<equiv> let q = simpfm p ; mp = minusinf q ; pp = plusinf q
chaieb@33152
  2748
 in if (mp = T \<or> pp = T) then T 
krauss@42694
  2749
  else (let U = remdups (uset  q)
chaieb@33152
  2750
    in decr0 (list_disj [mp, pp, simpfm (subst0 (CP 0\<^sub>p) q), evaldjf (\<lambda>(c,t). msubst2 q (c *\<^sub>p C (-2, 1)) t) U, 
chaieb@33152
  2751
   evaldjf (\<lambda>((b,a),(d,c)). msubst2 q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) (alluopairs U)]))"
chaieb@33152
  2752
chaieb@33152
  2753
definition "frpar2 p = simpfm (qelim (prep p) ferrack2)"
chaieb@33152
  2754
chaieb@33152
  2755
lemma ferrack2: assumes qf: "qfree p"
chaieb@33152
  2756
  shows "qfree (ferrack2 p) \<and> ((Ifm vs bs (ferrack2 p)) = (Ifm vs bs (E p)))"
chaieb@33152
  2757
  (is "_ \<and> (?rhs = ?lhs)")
chaieb@33152
  2758
proof-
chaieb@33152
  2759
  let ?J = "\<lambda> x p. Ifm vs (x#bs) p"
chaieb@33152
  2760
  let ?N = "\<lambda> t. Ipoly vs t"
chaieb@33152
  2761
  let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
chaieb@33152
  2762
  let ?q = "simpfm p" 
chaieb@33152
  2763
  let ?qz = "subst0 (CP 0\<^sub>p) ?q"
krauss@42694
  2764
  let ?U = "remdups(uset ?q)"
chaieb@33152
  2765
  let ?Up = "alluopairs ?U"
chaieb@33152
  2766
  let ?mp = "minusinf ?q"
chaieb@33152
  2767
  let ?pp = "plusinf ?q"
chaieb@33152
  2768
  let ?I = "\<lambda>p. Ifm vs (x#bs) p"
chaieb@33152
  2769
  from simpfm_lin[OF qf] simpfm_qf[OF qf] have lq: "islin ?q" and q_qf: "qfree ?q" .
chaieb@33152
  2770
  from minusinf_nb[OF lq] plusinf_nb[OF lq] have mp_nb: "bound0 ?mp" and pp_nb: "bound0 ?pp" .
chaieb@33152
  2771
  from bound0_qf[OF mp_nb] bound0_qf[OF pp_nb] have mp_qf: "qfree ?mp" and pp_qf: "qfree ?pp" .
chaieb@33152
  2772
  from uset_l[OF lq] have U_l: "\<forall>(c, s)\<in>set ?U. isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s"
chaieb@33152
  2773
    by simp
chaieb@33152
  2774
  have bnd0: "\<forall>x \<in> set ?U. bound0 ((\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) x)" 
chaieb@33152
  2775
  proof-
chaieb@33152
  2776
    {fix c t assume ct: "(c,t) \<in> set ?U"
chaieb@33152
  2777
      hence tnb: "tmbound0 t" using U_l by blast
chaieb@33152
  2778
      from msubst2_nb[OF lq tnb]
chaieb@33152
  2779
      have "bound0 ((\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) (c,t))" by simp}
chaieb@33152
  2780
    thus ?thesis by auto
chaieb@33152
  2781
  qed
chaieb@33152
  2782
  have bnd1: "\<forall>x \<in> set ?Up. bound0 ((\<lambda>((b,a),(d,c)). msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) x)" 
chaieb@33152
  2783
  proof-
chaieb@33152
  2784
    {fix b a d c assume badc: "((b,a),(d,c)) \<in> set ?Up"
chaieb@33152
  2785
      from badc U_l alluopairs_set1[of ?U] 
chaieb@33152
  2786
      have nb: "tmbound0 (Add (Mul d a) (Mul b c))" by auto
chaieb@33152
  2787
      from msubst2_nb[OF lq nb] have "bound0 ((\<lambda>((b,a),(d,c)). msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) ((b,a),(d,c)))" by simp}
chaieb@33152
  2788
    thus ?thesis by auto
chaieb@33152
  2789
  qed
chaieb@33152
  2790
  have stupid: "bound0 F" by simp
chaieb@33152
  2791
  let ?R = "list_disj [?mp, ?pp, simpfm (subst0 (CP 0\<^sub>p) ?q), evaldjf (\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) ?U, 
chaieb@33152
  2792
   evaldjf (\<lambda>((b,a),(d,c)). msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) (alluopairs ?U)]"
chaieb@33152
  2793
  from subst0_nb[of "CP 0\<^sub>p" ?q] q_qf evaldjf_bound0[OF bnd1] evaldjf_bound0[OF bnd0] mp_nb pp_nb stupid
chaieb@33152
  2794
  have nb: "bound0 ?R "
chaieb@33152
  2795
    by (simp add: list_disj_def disj_nb0 simpfm_bound0)
chaieb@33152
  2796
  let ?s = "\<lambda>((b,a),(d,c)). msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))"
chaieb@33152
  2797
chaieb@33152
  2798
  {fix b a d c assume baU: "(b,a) \<in> set ?U" and dcU: "(d,c) \<in> set ?U"
chaieb@33152
  2799
    from U_l baU dcU have norm: "isnpoly b" "isnpoly d" "isnpoly (C (-2, 1))" 
chaieb@33152
  2800
      by auto (simp add: isnpoly_def)
chaieb@33152
  2801
    have norm2: "isnpoly (C (-2, 1) *\<^sub>p b*\<^sub>p d)" "isnpoly (C (-2, 1) *\<^sub>p d*\<^sub>p b)"
chaieb@33152
  2802
      using norm by (simp_all add: polymul_norm)
chaieb@33152
  2803
    have stupid: "allpolys isnpoly (CP (C (-2, 1) *\<^sub>p b*\<^sub>p d))" "allpolys isnpoly (CP (C (-2, 1) *\<^sub>p d*\<^sub>p b))" "allpolys isnpoly (CP (~\<^sub>p(C (-2, 1) *\<^sub>p b*\<^sub>p d)))" "allpolys isnpoly (CP (~\<^sub>p(C (-2, 1) *\<^sub>p d*\<^sub>p b)))"
chaieb@33152
  2804
      by (simp_all add: polyneg_norm norm2)
chaieb@33152
  2805
    have "?I (msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) = ?I (msubst2 ?q (C (-2, 1) *\<^sub>p d*\<^sub>p b) (Add (Mul b c) (Mul d a)))" (is "?lhs \<longleftrightarrow> ?rhs")
chaieb@33152
  2806
    proof
chaieb@33152
  2807
      assume H: ?lhs
chaieb@33152
  2808
      hence z: "\<lparr>C (-2, 1) *\<^sub>p b *\<^sub>p d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>C (-2, 1) *\<^sub>p d *\<^sub>p b\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" 
wenzelm@33268
  2809
        by (auto simp add: msubst2_def lt[OF stupid(3)] lt[OF stupid(1)] mult_less_0_iff zero_less_mult_iff)
chaieb@33152
  2810
      from msubst2[OF lq norm2(1) z(1), of x bs] 
wenzelm@33268
  2811
        msubst2[OF lq norm2(2) z(2), of x bs] H 
haftmann@36347
  2812
      show ?rhs by (simp add: field_simps)
chaieb@33152
  2813
    next
chaieb@33152
  2814
      assume H: ?rhs
chaieb@33152
  2815
      hence z: "\<lparr>C (-2, 1) *\<^sub>p b *\<^sub>p d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>C (-2, 1) *\<^sub>p d *\<^sub>p b\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" 
wenzelm@33268
  2816
        by (auto simp add: msubst2_def lt[OF stupid(4)] lt[OF stupid(2)] mult_less_0_iff zero_less_mult_iff)
chaieb@33152
  2817
      from msubst2[OF lq norm2(1) z(1), of x bs] 
wenzelm@33268
  2818
        msubst2[OF lq norm2(2) z(2), of x bs] H 
haftmann@36347
  2819
      show ?lhs by (simp add: field_simps)
chaieb@33152
  2820
    qed}
chaieb@33152
  2821
  hence th0: "\<forall>x \<in> set ?U. \<forall>y \<in> set ?U. ?I (?s (x, y)) \<longleftrightarrow> ?I (?s (y, x))"
chaieb@33152
  2822
    by clarsimp
chaieb@33152
  2823
chaieb@33152
  2824
  have "?lhs \<longleftrightarrow> (\<exists>x. Ifm vs (x#bs) ?q)" by simp
chaieb@33152
  2825
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists>(b, a)\<in>set ?U. \<exists>(d, c)\<in>set ?U. ?I (msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))))"
chaieb@33152
  2826
    using fr_eq_msubst2[OF lq, of vs bs x] by simp
chaieb@33152
  2827
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> x\<in>set ?U. \<exists> y \<in>set ?U. ?I (?s (x,y)))"
chaieb@33152
  2828
    by (simp add: split_def)
chaieb@33152
  2829
  also have "\<dots> \<longleftrightarrow> ?I ?mp \<or> ?I ?pp \<or> ?I (subst0 (CP 0\<^sub>p) ?q) \<or> (\<exists>(n,t) \<in> set ?U. ?I (msubst2 ?q (n *\<^sub>p C (-2, 1)) t)) \<or> (\<exists> (x,y) \<in> set ?Up. ?I (?s (x,y)))"
nipkow@42720
  2830
    using alluopairs_bex[OF th0] by simp 
chaieb@33152
  2831
  also have "\<dots> \<longleftrightarrow> ?I ?R" 
chaieb@33152
  2832
    by (simp add: list_disj_def evaldjf_ex split_def)
chaieb@33152
  2833
  also have "\<dots> \<longleftrightarrow> ?rhs"
chaieb@33152
  2834
    unfolding ferrack2_def
chaieb@33152
  2835
    apply (cases "?mp = T") 
chaieb@33152
  2836
    apply (simp add: list_disj_def)
chaieb@33152
  2837
    apply (cases "?pp = T") 
chaieb@33152
  2838
    apply (simp add: list_disj_def)
chaieb@33152
  2839
    by (simp_all add: Let_def decr0[OF nb])
chaieb@33152
  2840
  finally show ?thesis using decr0_qf[OF nb]  
chaieb@33152
  2841
    by (simp  add: ferrack2_def Let_def)
chaieb@33152
  2842
qed
chaieb@33152
  2843
chaieb@33152
  2844
lemma frpar2: "qfree (frpar2 p) \<and> (Ifm vs bs (frpar2 p) \<longleftrightarrow> Ifm vs bs p)"
chaieb@33152
  2845
proof-
chaieb@33152
  2846
  from ferrack2 have th: "\<forall>bs p. qfree p \<longrightarrow> qfree (ferrack2 p) \<and> Ifm vs bs (ferrack2 p) = Ifm vs bs (E p)" by blast
chaieb@33152
  2847
  from qelim[OF th, of "prep p" bs] 
chaieb@33152
  2848
show ?thesis  unfolding frpar2_def by (auto simp add: prep)
chaieb@33152
  2849
qed
chaieb@33152
  2850
haftmann@35045
  2851
ML {* 
chaieb@33152
  2852
structure ReflectedFRPar = 
chaieb@33152
  2853
struct
chaieb@33152
  2854
chaieb@33152
  2855
val bT = HOLogic.boolT;
chaieb@33152
  2856
fun num rT x = HOLogic.mk_number rT x;
chaieb@33152
  2857
fun rrelT rT = [rT,rT] ---> rT;
chaieb@33152
  2858
fun rrT rT = [rT, rT] ---> bT;
haftmann@35084
  2859
fun divt rT = Const(@{const_name Rings.divide},rrelT rT);
haftmann@35267
  2860
fun timest rT = Const(@{const_name Groups.times},rrelT rT);
haftmann@35267
  2861
fun plust rT = Const(@{const_name Groups.plus},rrelT rT);
haftmann@35267
  2862
fun minust rT = Const(@{const_name Groups.minus},rrelT rT);
haftmann@35267
  2863
fun uminust rT = Const(@{const_name Groups.uminus}, rT --> rT);
chaieb@33152
  2864
fun powt rT = Const(@{const_name "power"}, [rT,@{typ "nat"}] ---> rT);
chaieb@33152
  2865
val brT = [bT, bT] ---> bT;
chaieb@33152
  2866
val nott = @{term "Not"};
haftmann@39028
  2867
val conjt = @{term HOL.conj};
haftmann@39028
  2868
val disjt = @{term HOL.disj};
haftmann@39019
  2869
val impt = @{term HOL.implies};
chaieb@33152
  2870
val ifft = @{term "op = :: bool => _"}
haftmann@35092
  2871
fun llt rT = Const(@{const_name Orderings.less},rrT rT);
haftmann@35092
  2872
fun lle rT = Const(@{const_name Orderings.less},rrT rT);
haftmann@39093
  2873
fun eqt rT = Const(@{const_name HOL.eq},rrT rT);
haftmann@35267
  2874
fun rz rT = Const(@{const_name Groups.zero},rT);
chaieb@33152
  2875
chaieb@33152
  2876
fun dest_nat t = case t of
haftmann@37362
  2877
  Const (@{const_name Suc}, _) $ t' => 1 + dest_nat t'
chaieb@33152
  2878
| _ => (snd o HOLogic.dest_number) t;
chaieb@33152
  2879
chaieb@33152
  2880
fun num_of_term m t = 
chaieb@33152
  2881
 case t of
haftmann@35267
  2882
   Const(@{const_name Groups.uminus},_)$t => @{code poly.Neg} (num_of_term m t)
haftmann@35267
  2883
 | Const(@{const_name Groups.plus},_)$a$b => @{code poly.Add} (num_of_term m a, num_of_term m b)
haftmann@35267
  2884
 | Const(@{const_name Groups.minus},_)$a$b => @{code poly.Sub} (num_of_term m a, num_of_term m b)
haftmann@35267
  2885
 | Const(@{const_name Groups.times},_)$a$b => @{code poly.Mul} (num_of_term m a, num_of_term m b)
haftmann@35045
  2886
 | Const(@{const_name Power.power},_)$a$n => @{code poly.Pw} (num_of_term m a, dest_nat n)
haftmann@35084
  2887
 | Const(@{const_name Rings.divide},_)$a$b => @{code poly.C} (HOLogic.dest_number a |> snd, HOLogic.dest_number b |> snd)
haftmann@35045
  2888
 | _ => (@{code poly.C} (HOLogic.dest_number t |> snd,1) 
haftmann@35045
  2889
         handle TERM _ => @{code poly.Bound} (AList.lookup (op aconv) m t |> the));
chaieb@33152
  2890
chaieb@33152
  2891
fun tm_of_term m m' t = 
chaieb@33152
  2892
 case t of
haftmann@35267
  2893
   Const(@{const_name Groups.uminus},_)$t => @{code Neg} (tm_of_term m m' t)
haftmann@35267
  2894
 | Const(@{const_name Groups.plus},_)$a$b => @{code Add} (tm_of_term m m' a, tm_of_term m m' b)
haftmann@35267
  2895
 | Const(@{const_name Groups.minus},_)$a$b => @{code Sub} (tm_of_term m m' a, tm_of_term m m' b)
haftmann@35267
  2896
 | Const(@{const_name Groups.times},_)$a$b => @{code Mul} (num_of_term m' a, tm_of_term m m' b)
haftmann@35045
  2897
 | _ => (@{code CP} (num_of_term m' t) 
haftmann@35045
  2898
         handle TERM _ => @{code Bound} (AList.lookup (op aconv) m t |> the)
haftmann@35045
  2899
              | Option => @{code Bound} (AList.lookup (op aconv) m t |> the));
chaieb@33152
  2900
chaieb@33152
  2901
fun term_of_num T m t = 
chaieb@33152
  2902
 case t of
haftmann@35045
  2903
  @{code poly.C} (a,b) => (if b = 1 then num T a else if b=0 then (rz T) 
chaieb@33152
  2904
                                        else (divt T) $ num T a $ num T b)
haftmann@35045
  2905
| @{code poly.Bound} i => AList.lookup (op = : int*int -> bool) m i |> the
haftmann@35045
  2906
| @{code poly.Add} (a,b) => (plust T)$(term_of_num T m a)$(term_of_num T m b)
haftmann@35045
  2907
| @{code poly.Mul} (a,b) => (timest T)$(term_of_num T m a)$(term_of_num T m b)
haftmann@35045
  2908
| @{code poly.Sub} (a,b) => (minust T)$(term_of_num T m a)$(term_of_num T m b)
haftmann@35045
  2909
| @{code poly.Neg} a => (uminust T)$(term_of_num T m a)
haftmann@35045
  2910
| @{code poly.Pw} (a,n) => (powt T)$(term_of_num T m t)$(HOLogic.mk_number HOLogic.natT n)
haftmann@35045
  2911
| @{code poly.CN} (c,n,p) => term_of_num T m (@{code poly.Add} (c, @{code poly.Mul} (@{code poly.Bound} n, p)))
chaieb@33152
  2912
| _ => error "term_of_num: Unknown term";
chaieb@33152
  2913
chaieb@33152
  2914
fun term_of_tm T m m' t = 
chaieb@33152
  2915
 case t of
haftmann@35045
  2916
  @{code CP} p => term_of_num T m' p
haftmann@35045
  2917
| @{code Bound} i => AList.lookup (op = : int*int -> bool) m i |> the
haftmann@35045
  2918
| @{code Add} (a,b) => (plust T)$(term_of_tm T m m' a)$(term_of_tm T m m' b)
haftmann@35045
  2919
| @{code Mul} (a,b) => (timest T)$(term_of_num T m' a)$(term_of_tm T m m' b)
haftmann@35045
  2920
| @{code Sub} (a,b) => (minust T)$(term_of_tm T m m' a)$(term_of_tm T m m' b)
haftmann@35045
  2921
| @{code Neg} a => (uminust T)$(term_of_tm T m m' a)
haftmann@35045
  2922
| @{code CNP} (n,c,p) => term_of_tm T m m' (@{code Add}
haftmann@35045
  2923
     (@{code Mul} (c, @{code Bound} n), p))
chaieb@33152
  2924
| _ => error "term_of_tm: Unknown term";
chaieb@33152
  2925
chaieb@33152
  2926
fun fm_of_term m m' fm = 
chaieb@33152
  2927
 case fm of
haftmann@38783
  2928
    Const(@{const_name True},_) => @{code T}
haftmann@38783
  2929
  | Const(@{const_name False},_) => @{code F}
haftmann@38783
  2930
  | Const(@{const_name Not},_)$p => @{code NOT} (fm_of_term m m' p)
haftmann@39028
  2931
  | Const(@{const_name HOL.conj},_)$p$q => @{code And} (fm_of_term m m' p, fm_of_term m m' q)
haftmann@39028
  2932
  | Const(@{const_name HOL.disj},_)$p$q => @{code Or} (fm_of_term m m' p, fm_of_term m m' q)
haftmann@39019
  2933
  | Const(@{const_name HOL.implies},_)$p$q => @{code Imp} (fm_of_term m m' p, fm_of_term m m' q)
haftmann@39093
  2934
  | Const(@{const_name HOL.eq},ty)$p$q => 
haftmann@35045
  2935
       if domain_type ty = bT then @{code Iff} (fm_of_term m m' p, fm_of_term m m' q)
haftmann@35045
  2936
       else @{code Eq} (@{code Sub} (tm_of_term m m' p, tm_of_term m m' q))
haftmann@35092
  2937
  | Const(@{const_name Orderings.less},_)$p$q => 
haftmann@35045
  2938
        @{code Lt} (@{code Sub} (tm_of_term m m' p, tm_of_term m m' q))
haftmann@35092
  2939
  | Const(@{const_name Orderings.less_eq},_)$p$q => 
haftmann@35045
  2940
        @{code Le} (@{code Sub} (tm_of_term m m' p, tm_of_term m m' q))
haftmann@38783
  2941
  | Const(@{const_name Ex},_)$Abs(xn,xT,p) => 
wenzelm@43156
  2942
     let val (xn', p') = Syntax_Trans.variant_abs (xn,xT,p)  (* FIXME !? *)
chaieb@33152
  2943
         val x = Free(xn',xT)
chaieb@33152
  2944
         fun incr i = i + 1
chaieb@33152
  2945
         val m0 = (x,0):: (map (apsnd incr) m)
haftmann@35045
  2946
      in @{code E} (fm_of_term m0 m' p') end
haftmann@38783
  2947
  | Const(@{const_name All},_)$Abs(xn,xT,p) => 
wenzelm@43156
  2948
     let val (xn', p') = Syntax_Trans.variant_abs (xn,xT,p)  (* FIXME !? *)
chaieb@33152
  2949
         val x = Free(xn',xT)
chaieb@33152
  2950
         fun incr i = i + 1
chaieb@33152
  2951
         val m0 = (x,0):: (map (apsnd incr) m)
haftmann@35045
  2952
      in @{code A} (fm_of_term m0 m' p') end
chaieb@33152
  2953
  | _ => error "fm_of_term";
chaieb@33152
  2954
chaieb@33152
  2955
chaieb@33152
  2956
fun term_of_fm T m m' t = 
chaieb@33152
  2957
  case t of
haftmann@38783
  2958
    @{code T} => Const(@{const_name True},bT)
haftmann@38783
  2959
  | @{code F} => Const(@{const_name False},bT)
haftmann@35045
  2960
  | @{code NOT} p => nott $ (term_of_fm T m m' p)
haftmann@35045
  2961
  | @{code And} (p,q) => conjt $ (term_of_fm T m m' p) $ (term_of_fm T m m' q)
haftmann@35045
  2962
  | @{code Or} (p,q) => disjt $ (term_of_fm T m m' p) $ (term_of_fm T m m' q)
haftmann@35045
  2963
  | @{code Imp} (p,q) => impt $ (term_of_fm T m m' p) $ (term_of_fm T m m' q)
haftmann@35045
  2964
  | @{code Iff} (p,q) => ifft $ (term_of_fm T m m' p) $ (term_of_fm T m m' q)
haftmann@35045
  2965
  | @{code Lt} p => (llt T) $ (term_of_tm T m m' p) $ (rz T)
haftmann@35045
  2966
  | @{code Le} p => (lle T) $ (term_of_tm T m m' p) $ (rz T)
haftmann@35045
  2967
  | @{code Eq} p => (eqt T) $ (term_of_tm T m m' p) $ (rz T)
haftmann@35045
  2968
  | @{code NEq} p => nott $ ((eqt T) $ (term_of_tm T m m' p) $ (rz T))
chaieb@33152
  2969
  | _ => error "term_of_fm: quantifiers!!!!???";
chaieb@33152
  2970
chaieb@33152
  2971
fun frpar_oracle (T,m, m', fm) = 
chaieb@33152
  2972
 let 
chaieb@33152
  2973
   val t = HOLogic.dest_Trueprop fm
chaieb@33152
  2974
   val im = 0 upto (length m - 1)
chaieb@33152
  2975
   val im' = 0 upto (length m' - 1)   
chaieb@33152
  2976
 in HOLogic.mk_Trueprop (HOLogic.mk_eq(t, term_of_fm T (im ~~ m) (im' ~~ m')  
haftmann@35045
  2977
                                                     (@{code frpar} (fm_of_term (m ~~ im) (m' ~~ im') t))))
chaieb@33152
  2978
 end;
chaieb@33152
  2979
chaieb@33152
  2980
fun frpar_oracle2 (T,m, m', fm) = 
chaieb@33152
  2981
 let 
chaieb@33152
  2982
   val t = HOLogic.dest_Trueprop fm
chaieb@33152
  2983
   val im = 0 upto (length m - 1)
chaieb@33152
  2984
   val im' = 0 upto (length m' - 1)   
chaieb@33152
  2985
 in HOLogic.mk_Trueprop (HOLogic.mk_eq(t, term_of_fm T (im ~~ m) (im' ~~ m')  
haftmann@35045
  2986
                                                     (@{code frpar2} (fm_of_term (m ~~ im) (m' ~~ im') t))))
chaieb@33152
  2987
 end;
chaieb@33152
  2988
chaieb@33152
  2989
end;
chaieb@33152
  2990
chaieb@33152
  2991
chaieb@33152
  2992
*}
chaieb@33152
  2993
chaieb@33152
  2994
oracle frpar_oracle = {* fn (ty, ts, ts', ct) => 
chaieb@33152
  2995
 let 
chaieb@33152
  2996
  val thy = Thm.theory_of_cterm ct
chaieb@33152
  2997
 in cterm_of thy (ReflectedFRPar.frpar_oracle (ty,ts, ts', term_of ct))
chaieb@33152
  2998
 end *}
chaieb@33152
  2999
chaieb@33152
  3000
oracle frpar_oracle2 = {* fn (ty, ts, ts', ct) => 
chaieb@33152
  3001
 let 
chaieb@33152
  3002
  val thy = Thm.theory_of_cterm ct
chaieb@33152
  3003
 in cterm_of thy (ReflectedFRPar.frpar_oracle2 (ty,ts, ts', term_of ct))
chaieb@33152
  3004
 end *}
chaieb@33152
  3005
chaieb@33152
  3006
ML{* 
chaieb@33152
  3007
structure FRParTac = 
chaieb@33152
  3008
struct
chaieb@33152
  3009
wenzelm@43239
  3010
fun frpar_tac T ps ctxt = 
wenzelm@43239
  3011
 Object_Logic.full_atomize_tac
wenzelm@43239
  3012
 THEN' CSUBGOAL (fn (g, i) =>
chaieb@33152
  3013
  let
wenzelm@43232
  3014
    val thy = Proof_Context.theory_of ctxt
chaieb@33152
  3015
    val fs = subtract (op aconv) (map Free (Term.add_frees (term_of g) [])) ps
wenzelm@43239
  3016
    val th = frpar_oracle (T, fs, ps, (* Pattern.eta_long [] *) g)
wenzelm@43239
  3017
  in rtac (th RS iffD2) i end);
chaieb@33152
  3018
wenzelm@43239
  3019
fun frpar2_tac T ps ctxt = 
wenzelm@43239
  3020
 Object_Logic.full_atomize_tac
wenzelm@43239
  3021
 THEN' CSUBGOAL (fn (g, i) =>
chaieb@33152
  3022
  let
wenzelm@43232
  3023
    val thy = Proof_Context.theory_of ctxt
chaieb@33152
  3024
    val fs = subtract (op aconv) (map Free (Term.add_frees (term_of g) [])) ps
wenzelm@43239
  3025
    val th = frpar_oracle2 (T, fs, ps, (* Pattern.eta_long [] *) g)
wenzelm@43239
  3026
  in rtac (th RS iffD2) i end);
chaieb@33152
  3027
chaieb@33152
  3028
end;
chaieb@33152
  3029
chaieb@33152
  3030
*}
chaieb@33152
  3031
chaieb@33152
  3032
method_setup frpar = {*
chaieb@33152
  3033
let
chaieb@33152
  3034
 fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()
chaieb@33152
  3035
 fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()
chaieb@33152
  3036
 val parsN = "pars"
chaieb@33152
  3037
 val typN = "type"
chaieb@33152
  3038
 val any_keyword = keyword parsN || keyword typN
chaieb@33152
  3039
 val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat
chaieb@33152
  3040
 val cterms = thms >> map Drule.dest_term;
chaieb@33152
  3041
 val terms = Scan.repeat (Scan.unless any_keyword Args.term)
chaieb@33152
  3042
 val typ = Scan.unless any_keyword Args.typ
chaieb@33152
  3043
in
chaieb@33152
  3044
 (keyword typN |-- typ) -- (keyword parsN |-- terms) >>
chaieb@33152
  3045
  (fn (T,ps) => fn ctxt => SIMPLE_METHOD' (FRParTac.frpar_tac T ps ctxt))
chaieb@33152
  3046
end
wenzelm@43685
  3047
*} "parametric QE for linear Arithmetic over fields, Version 1"
chaieb@33152
  3048
chaieb@33152
  3049
method_setup frpar2 = {*
chaieb@33152
  3050
let
chaieb@33152
  3051
 fun keyword k = Scan.lift (Args.$$$ k -- Args.colon) >> K ()
chaieb@33152
  3052
 fun simple_keyword k = Scan.lift (Args.$$$ k) >> K ()
chaieb@33152
  3053
 val parsN = "pars"
chaieb@33152
  3054
 val typN = "type"
chaieb@33152
  3055
 val any_keyword = keyword parsN || keyword typN
chaieb@33152
  3056
 val thms = Scan.repeat (Scan.unless any_keyword Attrib.multi_thm) >> flat
chaieb@33152
  3057
 val cterms = thms >> map Drule.dest_term;
chaieb@33152
  3058
 val terms = Scan.repeat (Scan.unless any_keyword Args.term)
chaieb@33152
  3059
 val typ = Scan.unless any_keyword Args.typ
chaieb@33152
  3060
in
chaieb@33152
  3061
 (keyword typN |-- typ) -- (keyword parsN |-- terms) >>
chaieb@33152
  3062
  (fn (T,ps) => fn ctxt => SIMPLE_METHOD' (FRParTac.frpar2_tac T ps ctxt))
chaieb@33152
  3063
end
wenzelm@43685
  3064
*} "parametric QE for linear Arithmetic over fields, Version 2"
chaieb@33152
  3065
chaieb@33152
  3066
haftmann@36409
  3067
lemma "\<exists>(x::'a::{linordered_field_inverse_zero, number_ring}). y \<noteq> -1 \<longrightarrow> (y + 1)*x < 0"
haftmann@36409
  3068
  apply (frpar type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "y::'a::{linordered_field_inverse_zero, number_ring}")
haftmann@36347
  3069
  apply (simp add: field_simps)
chaieb@33152
  3070
  apply (rule spec[where x=y])
haftmann@36409
  3071
  apply (frpar type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "z::'a::{linordered_field_inverse_zero, number_ring}")
chaieb@33152
  3072
  by simp
chaieb@33152
  3073
chaieb@33152
  3074
text{* Collins/Jones Problem *}
chaieb@33152
  3075
(*
haftmann@36409
  3076
lemma "\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
chaieb@33152
  3077
proof-
haftmann@36409
  3078
  have "(\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
haftmann@36347
  3079
by (simp add: field_simps)
chaieb@33152
  3080
have "?rhs"
chaieb@33152
  3081
haftmann@36409
  3082
  apply (frpar type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "a::'a::{linordered_field_inverse_zero, number_ring}" "b::'a::{linordered_field_inverse_zero, number_ring}")
haftmann@36347
  3083
  apply (simp add: field_simps)
chaieb@33152
  3084
oops
chaieb@33152
  3085
*)
chaieb@33152
  3086
(*
haftmann@36409
  3087
lemma "ALL (x::'a::{linordered_field_inverse_zero, number_ring}) y. (1 - t)*x \<le> (1+t)*y \<and> (1 - t)*y \<le> (1+t)*x --> 0 \<le> y"
haftmann@36409
  3088
apply (frpar type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "t::'a::{linordered_field_inverse_zero, number_ring}")
chaieb@33152
  3089
oops
chaieb@33152
  3090
*)
chaieb@33152
  3091
haftmann@36409
  3092
lemma "\<exists>(x::'a::{linordered_field_inverse_zero, number_ring}). y \<noteq> -1 \<longrightarrow> (y + 1)*x < 0"
haftmann@36409
  3093
  apply (frpar2 type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "y::'a::{linordered_field_inverse_zero, number_ring}")
haftmann@36347
  3094
  apply (simp add: field_simps)
chaieb@33152
  3095
  apply (rule spec[where x=y])
haftmann@36409
  3096
  apply (frpar2 type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "z::'a::{linordered_field_inverse_zero, number_ring}")
chaieb@33152
  3097
  by simp
chaieb@33152
  3098
chaieb@33152
  3099
text{* Collins/Jones Problem *}
chaieb@33152
  3100
chaieb@33152
  3101
(*
haftmann@36409
  3102
lemma "\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
chaieb@33152
  3103
proof-
haftmann@36409
  3104
  have "(\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field_inverse_zero, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
haftmann@36347
  3105
by (simp add: field_simps)
chaieb@33152
  3106
have "?rhs"
haftmann@36409
  3107
  apply (frpar2 type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "a::'a::{linordered_field_inverse_zero, number_ring}" "b::'a::{linordered_field_inverse_zero, number_ring}")
chaieb@33152
  3108
  apply simp
chaieb@33152
  3109
oops
chaieb@33152
  3110
*)
chaieb@33152
  3111
chaieb@33152
  3112
(*
haftmann@36409
  3113
lemma "ALL (x::'a::{linordered_field_inverse_zero, number_ring}) y. (1 - t)*x \<le> (1+t)*y \<and> (1 - t)*y \<le> (1+t)*x --> 0 \<le> y"
haftmann@36409
  3114
apply (frpar2 type: "'a::{linordered_field_inverse_zero, number_ring}" pars: "t::'a::{linordered_field_inverse_zero, number_ring}")
chaieb@33152
  3115
apply (simp add: field_simps linorder_neq_iff[symmetric])
chaieb@33152
  3116
apply ferrack
chaieb@33152
  3117
oops
chaieb@33152
  3118
*)
chaieb@33152
  3119
end