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