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