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