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