src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
changeset 60560 ce7030d9191d
parent 60533 1e7ccd864b62
child 60561 85aed595feb4
equal deleted inserted replaced
60559:48d7b203c0ea 60560:ce7030d9191d
     1 (*  Title:      HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
     1 (*  Title:      HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
     2     Author:     Amine Chaieb
     2     Author:     Amine Chaieb
     3 *)
     3 *)
     4 
     4 
     5 section\<open>A formalization of Ferrante and Rackoff's procedure with polynomial parameters, see Paper in CALCULEMUS 2008\<close>
     5 section \<open>A formalization of Ferrante and Rackoff's procedure with polynomial parameters, see Paper in CALCULEMUS 2008\<close>
     6 
     6 
     7 theory Parametric_Ferrante_Rackoff
     7 theory Parametric_Ferrante_Rackoff
     8 imports
     8 imports
     9   Reflected_Multivariate_Polynomial
     9   Reflected_Multivariate_Polynomial
    10   Dense_Linear_Order
    10   Dense_Linear_Order
    16 subsection \<open>Terms\<close>
    16 subsection \<open>Terms\<close>
    17 
    17 
    18 datatype tm = CP poly | Bound nat | Add tm tm | Mul poly tm
    18 datatype tm = CP poly | Bound nat | Add tm tm | Mul poly tm
    19   | Neg tm | Sub tm tm | CNP nat poly tm
    19   | Neg tm | Sub tm tm | CNP nat poly tm
    20 
    20 
    21 (* A size for poly to make inductive proofs simpler*)
    21 text \<open>A size for poly to make inductive proofs simpler.\<close>
    22 primrec tmsize :: "tm \<Rightarrow> nat"
    22 primrec tmsize :: "tm \<Rightarrow> nat"
    23 where
    23 where
    24   "tmsize (CP c) = polysize c"
    24   "tmsize (CP c) = polysize c"
    25 | "tmsize (Bound n) = 1"
    25 | "tmsize (Bound n) = 1"
    26 | "tmsize (Neg a) = 1 + tmsize a"
    26 | "tmsize (Neg a) = 1 + tmsize a"
    27 | "tmsize (Add a b) = 1 + tmsize a + tmsize b"
    27 | "tmsize (Add a b) = 1 + tmsize a + tmsize b"
    28 | "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
    28 | "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
    29 | "tmsize (Mul c a) = 1 + polysize c + tmsize a"
    29 | "tmsize (Mul c a) = 1 + polysize c + tmsize a"
    30 | "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
    30 | "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
    31 
    31 
    32 (* Semantics of terms tm *)
    32 text \<open>Semantics of terms tm.\<close>
    33 primrec Itm :: "'a::{field_char_0, field} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a"
    33 primrec Itm :: "'a::{field_char_0,field} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a"
    34 where
    34 where
    35   "Itm vs bs (CP c) = (Ipoly vs c)"
    35   "Itm vs bs (CP c) = (Ipoly vs c)"
    36 | "Itm vs bs (Bound n) = bs!n"
    36 | "Itm vs bs (Bound n) = bs!n"
    37 | "Itm vs bs (Neg a) = -(Itm vs bs a)"
    37 | "Itm vs bs (Neg a) = -(Itm vs bs a)"
    38 | "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    38 | "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    58 | "tmboundslt n (Neg a) = tmboundslt n a"
    58 | "tmboundslt n (Neg a) = tmboundslt n a"
    59 | "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
    59 | "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
    60 | "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)"
    60 | "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)"
    61 | "tmboundslt n (Mul i a) = tmboundslt n a"
    61 | "tmboundslt n (Mul i a) = tmboundslt n a"
    62 
    62 
    63 primrec tmbound0 :: "tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound 0 *)
    63 primrec tmbound0 :: "tm \<Rightarrow> bool"  -- \<open>a tm is INDEPENDENT of Bound 0\<close>
    64 where
    64 where
    65   "tmbound0 (CP c) = True"
    65   "tmbound0 (CP c) = True"
    66 | "tmbound0 (Bound n) = (n>0)"
    66 | "tmbound0 (Bound n) = (n>0)"
    67 | "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
    67 | "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
    68 | "tmbound0 (Neg a) = tmbound0 a"
    68 | "tmbound0 (Neg a) = tmbound0 a"
    72 
    72 
    73 lemma tmbound0_I:
    73 lemma tmbound0_I:
    74   assumes nb: "tmbound0 a"
    74   assumes nb: "tmbound0 a"
    75   shows "Itm vs (b#bs) a = Itm vs (b'#bs) a"
    75   shows "Itm vs (b#bs) a = Itm vs (b'#bs) a"
    76   using nb
    76   using nb
    77   by (induct a rule: tm.induct,auto)
    77   by (induct a rule: tm.induct) auto
    78 
    78 
    79 primrec tmbound :: "nat \<Rightarrow> tm \<Rightarrow> bool" (* a tm is INDEPENDENT of Bound n *)
    79 primrec tmbound :: "nat \<Rightarrow> tm \<Rightarrow> bool"  -- \<open>a tm is INDEPENDENT of Bound n\<close>
    80 where
    80 where
    81   "tmbound n (CP c) = True"
    81   "tmbound n (CP c) = True"
    82 | "tmbound n (Bound m) = (n \<noteq> m)"
    82 | "tmbound n (Bound m) = (n \<noteq> m)"
    83 | "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
    83 | "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
    84 | "tmbound n (Neg a) = tmbound n a"
    84 | "tmbound n (Neg a) = tmbound n a"
   144   by (induct xs arbitrary: n) auto
   144   by (induct xs arbitrary: n) auto
   145 
   145 
   146 lemma nth_length_exceeds: "n \<ge> length xs \<Longrightarrow> xs!n = []!(n - length xs)"
   146 lemma nth_length_exceeds: "n \<ge> length xs \<Longrightarrow> xs!n = []!(n - length xs)"
   147   by (induct xs arbitrary: n) auto
   147   by (induct xs arbitrary: n) auto
   148 
   148 
   149 lemma removen_length:
   149 lemma removen_length: "length (removen n xs) = (if n \<ge> length xs then length xs else length xs - 1)"
   150   "length (removen n xs) = (if n \<ge> length xs then length xs else length xs - 1)"
       
   151   by (induct xs arbitrary: n, auto)
   150   by (induct xs arbitrary: n, auto)
   152 
   151 
   153 lemma removen_nth:
   152 lemma removen_nth:
   154   "(removen n xs)!m =
   153   "(removen n xs)!m =
   155     (if n \<ge> length xs then xs!m
   154     (if n \<ge> length xs then xs!m
   158      else []!(m - (length xs - 1)))"
   157      else []!(m - (length xs - 1)))"
   159 proof (induct xs arbitrary: n m)
   158 proof (induct xs arbitrary: n m)
   160   case Nil
   159   case Nil
   161   then show ?case by simp
   160   then show ?case by simp
   162 next
   161 next
   163   case (Cons x xs n m)
   162   case (Cons x xs)
   164   {
   163   let ?l = "length (x # xs)"
   165     assume nxs: "n \<ge> length (x#xs)"
   164   consider "n \<ge> ?l" | "n < ?l" by arith
   166     then have ?case using removen_same[OF nxs] by simp
   165   then show ?case
   167   }
   166   proof cases
   168   moreover
   167     case 1 
   169   {
   168     then show ?thesis
   170     assume nxs: "\<not> (n \<ge> length (x#xs))"
   169       using removen_same[OF 1] by simp
   171     {
   170   next
   172       assume mln: "m < n"
   171     case 2
   173       then have ?case using Cons by (cases m) auto
   172     consider "m < n" | "m \<ge> n" by arith
   174     }
   173     then show ?thesis
   175     moreover
   174     proof cases
   176     {
   175       case 1
   177       assume mln: "\<not> (m < n)"
   176       then show ?thesis
   178       {
   177         using Cons by (cases m) auto
   179         assume mxs: "m \<le> length (x#xs)"
   178     next
   180         then have ?case using Cons by (cases m) auto
   179       case 2
   181       }
   180       consider "m \<le> ?l" | "m > ?l" by arith
   182       moreover
   181       then show ?thesis
   183       {
   182       proof cases
   184         assume mxs: "\<not> (m \<le> length (x#xs))"
   183         case 1
   185         have th: "length (removen n (x#xs)) = length xs"
   184         then show ?thesis
   186           using removen_length[where n="n" and xs="x#xs"] nxs by simp
   185           using Cons by (cases m) auto
   187         with mxs have mxs':"m \<ge> length (removen n (x#xs))"
   186       next
       
   187         case 2
       
   188         have th: "length (removen n (x # xs)) = length xs"
       
   189           using removen_length[where n = n and xs= "x # xs"] \<open>n < ?l\<close> by simp
       
   190         with \<open>m > ?l\<close> have "m \<ge> length (removen n (x # xs))"
   188           by auto
   191           by auto
   189         then have "(removen n (x#xs))!m = [] ! (m - length xs)"
   192         from th nth_length_exceeds[OF this] have "(removen n (x # xs))!m = [] ! (m - length xs)"
   190           using th nth_length_exceeds[OF mxs'] by auto
   193            by auto
   191         then have th: "(removen n (x#xs))!m = [] ! (m - (length (x#xs) - 1))"
   194         then have "(removen n (x # xs))!m = [] ! (m - (length (x # xs) - 1))"
   192           by auto
   195           by auto
   193         then have ?case
   196         then show ?thesis
   194           using nxs mln mxs by auto
   197           using \<open>n < ?l\<close> \<open>m > ?l\<close> \<open>m > ?l\<close> by auto
   195       }
   198       qed
   196       ultimately have ?case by blast
   199     qed
   197     }
   200   qed
   198     ultimately have ?case by blast
       
   199   }
       
   200   ultimately show ?case by blast
       
   201 qed
   201 qed
   202 
   202 
   203 lemma decrtm:
   203 lemma decrtm:
   204   assumes bnd: "tmboundslt (length bs) t"
   204   assumes bnd: "tmboundslt (length bs) t"
   205     and nb: "tmbound m t"
   205     and nb: "tmbound m t"
   215 | "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
   215 | "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
   216 | "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
   216 | "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
   217 | "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)"
   217 | "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)"
   218 | "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
   218 | "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
   219 
   219 
   220 lemma tmsubst0: "Itm vs (x#bs) (tmsubst0 t a) = Itm vs ((Itm vs (x#bs) t)#bs) a"
   220 lemma tmsubst0: "Itm vs (x # bs) (tmsubst0 t a) = Itm vs (Itm vs (x # bs) t # bs) a"
   221   by (induct a rule: tm.induct) auto
   221   by (induct a rule: tm.induct) auto
   222 
   222 
   223 lemma tmsubst0_nb: "tmbound0 t \<Longrightarrow> tmbound0 (tmsubst0 t a)"
   223 lemma tmsubst0_nb: "tmbound0 t \<Longrightarrow> tmbound0 (tmsubst0 t a)"
   224   by (induct a rule: tm.induct) auto
   224   by (induct a rule: tm.induct) auto
   225 
   225 
   254   by (induct a rule: tm.induct) auto
   254   by (induct a rule: tm.induct) auto
   255 
   255 
   256 lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)"
   256 lemma incrtm0_tmbound: "tmbound n t \<Longrightarrow> tmbound (Suc n) (incrtm0 t)"
   257   by (induct t) auto
   257   by (induct t) auto
   258 
   258 
   259 (* Simplification *)
   259 
       
   260 text \<open>Simplification.\<close>
   260 
   261 
   261 consts tmadd:: "tm \<times> tm \<Rightarrow> tm"
   262 consts tmadd:: "tm \<times> tm \<Rightarrow> tm"
   262 recdef tmadd "measure (\<lambda>(t,s). size t + size s)"
   263 recdef tmadd "measure (\<lambda>(t,s). size t + size s)"
   263   "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) =
   264   "tmadd (CNP n1 c1 r1,CNP n2 c2 r2) =
   264     (if n1 = n2 then
   265     (if n1 = n2 then
   270   "tmadd (t, CNP n2 c2 r2) = CNP n2 c2 (tmadd (t, r2))"
   271   "tmadd (t, CNP n2 c2 r2) = CNP n2 c2 (tmadd (t, r2))"
   271   "tmadd (CP b1, CP b2) = CP (b1 +\<^sub>p b2)"
   272   "tmadd (CP b1, CP b2) = CP (b1 +\<^sub>p b2)"
   272   "tmadd (a, b) = Add a b"
   273   "tmadd (a, b) = Add a b"
   273 
   274 
   274 lemma tmadd[simp]: "Itm vs bs (tmadd (t, s)) = Itm vs bs (Add t s)"
   275 lemma tmadd[simp]: "Itm vs bs (tmadd (t, s)) = Itm vs bs (Add t s)"
   275   apply (induct t s rule: tmadd.induct, simp_all add: Let_def)
   276   apply (induct t s rule: tmadd.induct)
   276   apply (case_tac "c1 +\<^sub>p c2 = 0\<^sub>p",case_tac "n1 \<le> n2", simp_all)
   277   apply (simp_all add: Let_def)
   277   apply (case_tac "n1 = n2", simp_all add: field_simps)
   278   apply (case_tac "c1 +\<^sub>p c2 = 0\<^sub>p")
       
   279   apply (case_tac "n1 \<le> n2")
       
   280   apply simp_all
       
   281   apply (case_tac "n1 = n2")
       
   282   apply (simp_all add: field_simps)
   278   apply (simp only: distrib_left[symmetric])
   283   apply (simp only: distrib_left[symmetric])
   279   apply (auto simp del: polyadd simp add: polyadd[symmetric])
   284   apply (auto simp del: polyadd simp add: polyadd[symmetric])
   280   done
   285   done
   281 
   286 
   282 lemma tmadd_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 s \<Longrightarrow> tmbound0 (tmadd (t, s))"
   287 lemma tmadd_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 s \<Longrightarrow> tmbound0 (tmadd (t, s))"
   309 
   314 
   310 lemma tmmul_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmmul t i)"
   315 lemma tmmul_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (tmmul t i)"
   311   by (induct t arbitrary: i rule: tmmul.induct) (auto simp add: Let_def)
   316   by (induct t arbitrary: i rule: tmmul.induct) (auto simp add: Let_def)
   312 
   317 
   313 lemma tmmul_allpolys_npoly[simp]:
   318 lemma tmmul_allpolys_npoly[simp]:
   314   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   319   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   315   shows "allpolys isnpoly t \<Longrightarrow> isnpoly c \<Longrightarrow> allpolys isnpoly (tmmul t c)"
   320   shows "allpolys isnpoly t \<Longrightarrow> isnpoly c \<Longrightarrow> allpolys isnpoly (tmmul t c)"
   316   by (induct t rule: tmmul.induct) (simp_all add: Let_def polymul_norm)
   321   by (induct t rule: tmmul.induct) (simp_all add: Let_def polymul_norm)
   317 
   322 
   318 definition tmneg :: "tm \<Rightarrow> tm"
   323 definition tmneg :: "tm \<Rightarrow> tm"
   319   where "tmneg t \<equiv> tmmul t (C (- 1,1))"
   324   where "tmneg t \<equiv> tmmul t (C (- 1,1))"
   335 
   340 
   336 lemma [simp]: "isnpoly (C (-1, 1))"
   341 lemma [simp]: "isnpoly (C (-1, 1))"
   337   unfolding isnpoly_def by simp
   342   unfolding isnpoly_def by simp
   338 
   343 
   339 lemma tmneg_allpolys_npoly[simp]:
   344 lemma tmneg_allpolys_npoly[simp]:
   340   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   345   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   341   shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly (tmneg t)"
   346   shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly (tmneg t)"
   342   unfolding tmneg_def by auto
   347   unfolding tmneg_def by auto
   343 
   348 
   344 lemma tmsub[simp]: "Itm vs bs (tmsub a b) = Itm vs bs (Sub a b)"
   349 lemma tmsub[simp]: "Itm vs bs (tmsub a b) = Itm vs bs (Sub a b)"
   345   using tmsub_def by simp
   350   using tmsub_def by simp
   352 
   357 
   353 lemma tmsub_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n s \<Longrightarrow> tmboundslt n (tmsub t s)"
   358 lemma tmsub_blt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n s \<Longrightarrow> tmboundslt n (tmsub t s)"
   354   using tmsub_def by simp
   359   using tmsub_def by simp
   355 
   360 
   356 lemma tmsub_allpolys_npoly[simp]:
   361 lemma tmsub_allpolys_npoly[simp]:
   357   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   362   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   358   shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)"
   363   shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)"
   359   unfolding tmsub_def by (simp add: isnpoly_def)
   364   unfolding tmsub_def by (simp add: isnpoly_def)
   360 
   365 
   361 fun simptm :: "tm \<Rightarrow> tm"
   366 fun simptm :: "tm \<Rightarrow> tm"
   362 where
   367 where
   369     (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   374     (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   370 | "simptm (CNP n c t) =
   375 | "simptm (CNP n c t) =
   371     (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))"
   376     (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))"
   372 
   377 
   373 lemma polynate_stupid:
   378 lemma polynate_stupid:
   374   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   379   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   375   shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a)"
   380   shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a)"
   376   apply (subst polynate[symmetric])
   381   apply (subst polynate[symmetric])
   377   apply simp
   382   apply simp
   378   done
   383   done
   379 
   384 
   388 
   393 
   389 lemma simptm_nlt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (simptm t)"
   394 lemma simptm_nlt[simp]: "tmboundslt n t \<Longrightarrow> tmboundslt n (simptm t)"
   390   by (induct t rule: simptm.induct) (auto simp add: Let_def)
   395   by (induct t rule: simptm.induct) (auto simp add: Let_def)
   391 
   396 
   392 lemma [simp]: "isnpoly 0\<^sub>p"
   397 lemma [simp]: "isnpoly 0\<^sub>p"
   393   and [simp]: "isnpoly (C(1,1))"
   398   and [simp]: "isnpoly (C (1, 1))"
   394   by (simp_all add: isnpoly_def)
   399   by (simp_all add: isnpoly_def)
   395 
   400 
   396 lemma simptm_allpolys_npoly[simp]:
   401 lemma simptm_allpolys_npoly[simp]:
   397   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   402   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   398   shows "allpolys isnpoly (simptm p)"
   403   shows "allpolys isnpoly (simptm p)"
   399   by (induct p rule: simptm.induct) (auto simp add: Let_def)
   404   by (induct p rule: simptm.induct) (auto simp add: Let_def)
   400 
   405 
   401 declare let_cong[fundef_cong del]
   406 declare let_cong[fundef_cong del]
   402 
   407 
   403 fun split0 :: "tm \<Rightarrow> (poly \<times> tm)"
   408 fun split0 :: "tm \<Rightarrow> poly \<times> tm"
   404 where
   409 where
   405   "split0 (Bound 0) = ((1)\<^sub>p, CP 0\<^sub>p)"
   410   "split0 (Bound 0) = ((1)\<^sub>p, CP 0\<^sub>p)"
   406 | "split0 (CNP 0 c t) = (let (c', t') = split0 t in (c +\<^sub>p c', t'))"
   411 | "split0 (CNP 0 c t) = (let (c', t') = split0 t in (c +\<^sub>p c', t'))"
   407 | "split0 (Neg t) = (let (c, t') = split0 t in (~\<^sub>p c, Neg t'))"
   412 | "split0 (Neg t) = (let (c, t') = split0 t in (~\<^sub>p c, Neg t'))"
   408 | "split0 (CNP n c t) = (let (c', t') = split0 t in (c', CNP n c t'))"
   413 | "split0 (CNP n c t) = (let (c', t') = split0 t in (c', CNP n c t'))"
   418   apply (rule exI[where x="snd (split0 p)"])
   423   apply (rule exI[where x="snd (split0 p)"])
   419   apply simp
   424   apply simp
   420   done
   425   done
   421 
   426 
   422 lemma split0:
   427 lemma split0:
   423   "tmbound 0 (snd (split0 t)) \<and> (Itm vs bs (CNP 0 (fst (split0 t)) (snd (split0 t))) = Itm vs bs t)"
   428   "tmbound 0 (snd (split0 t)) \<and> Itm vs bs (CNP 0 (fst (split0 t)) (snd (split0 t))) = Itm vs bs t"
   424   apply (induct t rule: split0.induct)
   429   apply (induct t rule: split0.induct)
   425   apply simp
   430   apply simp
   426   apply (simp add: Let_def split_def field_simps)
   431   apply (simp add: Let_def split_def field_simps)
   427   apply (simp add: Let_def split_def field_simps)
   432   apply (simp add: Let_def split_def field_simps)
   428   apply (simp add: Let_def split_def field_simps)
   433   apply (simp add: Let_def split_def field_simps)
   443   show "Itm vs bs t = Itm vs bs (CNP 0 c' t')"
   448   show "Itm vs bs t = Itm vs bs (CNP 0 c' t')"
   444     by simp
   449     by simp
   445 qed
   450 qed
   446 
   451 
   447 lemma split0_nb0:
   452 lemma split0_nb0:
   448   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   453   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   449   shows "split0 t = (c',t') \<Longrightarrow>  tmbound 0 t'"
   454   shows "split0 t = (c',t') \<Longrightarrow>  tmbound 0 t'"
   450 proof -
   455 proof -
   451   fix c' t'
   456   fix c' t'
   452   assume "split0 t = (c', t')"
   457   assume "split0 t = (c', t')"
   453   then have "c' = fst (split0 t)" and "t' = snd (split0 t)"
   458   then have "c' = fst (split0 t)" and "t' = snd (split0 t)"
   455   with conjunct1[OF split0[where t="t"]] show "tmbound 0 t'"
   460   with conjunct1[OF split0[where t="t"]] show "tmbound 0 t'"
   456     by simp
   461     by simp
   457 qed
   462 qed
   458 
   463 
   459 lemma split0_nb0'[simp]:
   464 lemma split0_nb0'[simp]:
   460   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   465   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   461   shows "tmbound0 (snd (split0 t))"
   466   shows "tmbound0 (snd (split0 t))"
   462   using split0_nb0[of t "fst (split0 t)" "snd (split0 t)"]
   467   using split0_nb0[of t "fst (split0 t)" "snd (split0 t)"]
   463   by (simp add: tmbound0_tmbound_iff)
   468   by (simp add: tmbound0_tmbound_iff)
   464 
   469 
   465 lemma split0_nb:
   470 lemma split0_nb:
   483 
   488 
   484 lemma allpolys_split0: "allpolys isnpoly p \<Longrightarrow> allpolys isnpoly (snd (split0 p))"
   489 lemma allpolys_split0: "allpolys isnpoly p \<Longrightarrow> allpolys isnpoly (snd (split0 p))"
   485   by (induct p rule: split0.induct) (auto simp  add: isnpoly_def Let_def split_def)
   490   by (induct p rule: split0.induct) (auto simp  add: isnpoly_def Let_def split_def)
   486 
   491 
   487 lemma isnpoly_fst_split0:
   492 lemma isnpoly_fst_split0:
   488   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
   493   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   489   shows "allpolys isnpoly p \<Longrightarrow> isnpoly (fst (split0 p))"
   494   shows "allpolys isnpoly p \<Longrightarrow> isnpoly (fst (split0 p))"
   490   by (induct p rule: split0.induct)
   495   by (induct p rule: split0.induct)
   491     (auto simp  add: polyadd_norm polysub_norm polyneg_norm polymul_norm Let_def split_def)
   496     (auto simp  add: polyadd_norm polysub_norm polyneg_norm polymul_norm Let_def split_def)
   492 
   497 
   493 
   498 
   494 subsection\<open>Formulae\<close>
   499 subsection \<open>Formulae\<close>
   495 
   500 
   496 datatype fm  =  T| F| Le tm | Lt tm | Eq tm | NEq tm|
   501 datatype fm  =  T| F| Le tm | Lt tm | Eq tm | NEq tm|
   497   NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
   502   NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
   498 
   503 
   499 
   504 
   512 (* several lemmas about fmsize *)
   517 (* several lemmas about fmsize *)
   513 lemma fmsize_pos[termination_simp]: "fmsize p > 0"
   518 lemma fmsize_pos[termination_simp]: "fmsize p > 0"
   514   by (induct p rule: fmsize.induct) simp_all
   519   by (induct p rule: fmsize.induct) simp_all
   515 
   520 
   516   (* Semantics of formulae (fm) *)
   521   (* Semantics of formulae (fm) *)
   517 primrec Ifm ::"'a::{linordered_field} list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool"
   522 primrec Ifm ::"'a::linordered_field list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool"
   518 where
   523 where
   519   "Ifm vs bs T = True"
   524   "Ifm vs bs T = True"
   520 | "Ifm vs bs F = False"
   525 | "Ifm vs bs F = False"
   521 | "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   526 | "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   522 | "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   527 | "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   729     and nle: "m < length bs"
   734     and nle: "m < length bs"
   730   shows "Ifm vs (removen m bs) (decr m p) = Ifm vs bs p"
   735   shows "Ifm vs (removen m bs) (decr m p) = Ifm vs bs p"
   731   using bnd nb nle
   736   using bnd nb nle
   732 proof (induct p arbitrary: bs m rule: fm.induct)
   737 proof (induct p arbitrary: bs m rule: fm.induct)
   733   case (E p bs m)
   738   case (E p bs m)
   734   { fix x
   739   have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p" for x
       
   740   proof -
   735     from E
   741     from E
   736     have bnd: "boundslt (length (x#bs)) p"
   742     have bnd: "boundslt (length (x#bs)) p"
   737       and nb: "bound (Suc m) p"
   743       and nb: "bound (Suc m) p"
   738       and nle: "Suc m < length (x#bs)"
   744       and nle: "Suc m < length (x#bs)"
   739       by auto
   745       by auto
   740     from E(1)[OF bnd nb nle]
   746     from E(1)[OF bnd nb nle] show ?thesis .
   741     have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p" .
   747   qed
   742   }
       
   743   then show ?case by auto
   748   then show ?case by auto
   744 next
   749 next
   745   case (A p bs m)
   750   case (A p bs m)
   746   { fix x
   751   have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p" for x
       
   752   proof -
   747     from A
   753     from A
   748     have bnd: "boundslt (length (x#bs)) p"
   754     have bnd: "boundslt (length (x#bs)) p"
   749       and nb: "bound (Suc m) p"
   755       and nb: "bound (Suc m) p"
   750       and nle: "Suc m < length (x#bs)"
   756       and nle: "Suc m < length (x#bs)"
   751       by auto
   757       by auto
   752     from A(1)[OF bnd nb nle]
   758     from A(1)[OF bnd nb nle] show ?thesis .
   753     have "Ifm vs (removen (Suc m) (x#bs)) (decr (Suc m) p) = Ifm vs (x#bs) p" .
   759   qed
   754   }
       
   755   then show ?case by auto
   760   then show ?case by auto
   756 qed (auto simp add: decrtm removen_nth)
   761 qed (auto simp add: decrtm removen_nth)
   757 
   762 
   758 primrec subst0 :: "tm \<Rightarrow> fm \<Rightarrow> fm"
   763 primrec subst0 :: "tm \<Rightarrow> fm \<Rightarrow> fm"
   759 where
   764 where
   805     and nlm: "n \<le> length bs"
   810     and nlm: "n \<le> length bs"
   806   shows "Ifm vs bs (subst n t p) = Ifm vs (bs[n:= Itm vs bs t]) p"
   811   shows "Ifm vs bs (subst n t p) = Ifm vs (bs[n:= Itm vs bs t]) p"
   807   using nb nlm
   812   using nb nlm
   808 proof (induct p arbitrary: bs n t rule: fm.induct)
   813 proof (induct p arbitrary: bs n t rule: fm.induct)
   809   case (E p bs n)
   814   case (E p bs n)
   810   {
   815   have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   811     fix x
   816         Ifm vs (x#bs[n:= Itm vs bs t]) p" for x
       
   817   proof -
   812     from E have bn: "boundslt (length (x#bs)) p"
   818     from E have bn: "boundslt (length (x#bs)) p"
   813       by simp
   819       by simp
   814     from E have nlm: "Suc n \<le> length (x#bs)"
   820     from E have nlm: "Suc n \<le> length (x#bs)"
   815       by simp
   821       by simp
   816     from E(1)[OF bn nlm]
   822     from E(1)[OF bn nlm]
   817     have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   823     have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   818         Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p"
   824         Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p"
   819       by simp
   825       by simp
   820     then have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   826     then show ?thesis
   821         Ifm vs (x#bs[n:= Itm vs bs t]) p"
       
   822       by (simp add: incrtm0[where x="x" and bs="bs" and t="t"])
   827       by (simp add: incrtm0[where x="x" and bs="bs" and t="t"])
   823   }
   828   qed
   824   then show ?case by simp
   829   then show ?case by simp
   825 next
   830 next
   826   case (A p bs n)
   831   case (A p bs n)
   827   {
   832   have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   828     fix x
   833         Ifm vs (x#bs[n:= Itm vs bs t]) p" for x
       
   834   proof -
   829     from A have bn: "boundslt (length (x#bs)) p"
   835     from A have bn: "boundslt (length (x#bs)) p"
   830       by simp
   836       by simp
   831     from A have nlm: "Suc n \<le> length (x#bs)"
   837     from A have nlm: "Suc n \<le> length (x#bs)"
   832       by simp
   838       by simp
   833     from A(1)[OF bn nlm]
   839     from A(1)[OF bn nlm]
   834     have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   840     have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   835         Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p"
   841         Ifm vs ((x#bs)[Suc n:= Itm vs (x#bs) (incrtm0 t)]) p"
   836       by simp
   842       by simp
   837     then have "Ifm vs (x#bs) (subst (Suc n) (incrtm0 t) p) =
   843     then show ?thesis
   838         Ifm vs (x#bs[n:= Itm vs bs t]) p"
       
   839       by (simp add: incrtm0[where x="x" and bs="bs" and t="t"])
   844       by (simp add: incrtm0[where x="x" and bs="bs" and t="t"])
   840   }
   845   qed
   841   then show ?case by simp
   846   then show ?case by simp
   842 qed (auto simp add: tmsubst)
   847 qed (auto simp add: tmsubst)
   843 
   848 
   844 lemma subst_nb:
   849 lemma subst_nb:
   845   assumes tnb: "tmbound m t"
   850   assumes tnb: "tmbound m t"
   892 lemma iff_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (iff p q)"
   897 lemma iff_blt[simp]: "boundslt n p \<Longrightarrow> boundslt n q \<Longrightarrow> boundslt n (iff p q)"
   893   using iff_def by auto
   898   using iff_def by auto
   894 lemma decr0_qf: "bound0 p \<Longrightarrow> qfree (decr0 p)"
   899 lemma decr0_qf: "bound0 p \<Longrightarrow> qfree (decr0 p)"
   895   by (induct p) simp_all
   900   by (induct p) simp_all
   896 
   901 
   897 fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *)
   902 fun isatom :: "fm \<Rightarrow> bool"  -- \<open>test for atomicity\<close>
   898 where
   903 where
   899   "isatom T = True"
   904   "isatom T = True"
   900 | "isatom F = True"
   905 | "isatom F = True"
   901 | "isatom (Lt a) = True"
   906 | "isatom (Lt a) = True"
   902 | "isatom (Le a) = True"
   907 | "isatom (Le a) = True"
   916 
   921 
   917 definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm"
   922 definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm"
   918   where "evaldjf f ps \<equiv> foldr (djf f) ps F"
   923   where "evaldjf f ps \<equiv> foldr (djf f) ps F"
   919 
   924 
   920 lemma djf_Or: "Ifm vs bs (djf f p q) = Ifm vs bs (Or (f p) q)"
   925 lemma djf_Or: "Ifm vs bs (djf f p q) = Ifm vs bs (Or (f p) q)"
   921   by (cases "q=T", simp add: djf_def,cases "q=F", simp add: djf_def)
   926   apply (cases "q = T")
   922     (cases "f p", simp_all add: Let_def djf_def)
   927   apply (simp add: djf_def)
       
   928   apply (cases "q = F")
       
   929   apply (simp add: djf_def)
       
   930   apply (cases "f p")
       
   931   apply (simp_all add: Let_def djf_def)
       
   932   done
   923 
   933 
   924 lemma evaldjf_ex: "Ifm vs bs (evaldjf f ps) \<longleftrightarrow> (\<exists>p \<in> set ps. Ifm vs bs (f p))"
   934 lemma evaldjf_ex: "Ifm vs bs (evaldjf f ps) \<longleftrightarrow> (\<exists>p \<in> set ps. Ifm vs bs (f p))"
   925   by (induct ps) (simp_all add: evaldjf_def djf_Or)
   935   by (induct ps) (simp_all add: evaldjf_def djf_Or)
   926 
   936 
   927 lemma evaldjf_bound0:
   937 lemma evaldjf_bound0:
   928   assumes nb: "\<forall>x\<in> set xs. bound0 (f x)"
   938   assumes nb: "\<forall>x\<in> set xs. bound0 (f x)"
   929   shows "bound0 (evaldjf f xs)"
   939   shows "bound0 (evaldjf f xs)"
   930   using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto)
   940   using nb
       
   941   apply (induct xs)
       
   942   apply (auto simp add: evaldjf_def djf_def Let_def)
       
   943   apply (case_tac "f a")
       
   944   apply auto
       
   945   done
   931 
   946 
   932 lemma evaldjf_qf:
   947 lemma evaldjf_qf:
   933   assumes nb: "\<forall>x\<in> set xs. qfree (f x)"
   948   assumes nb: "\<forall>x\<in> set xs. qfree (f x)"
   934   shows "qfree (evaldjf f xs)"
   949   shows "qfree (evaldjf f xs)"
   935   using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto)
   950   using nb
       
   951   apply (induct xs)
       
   952   apply (auto simp add: evaldjf_def djf_def Let_def)
       
   953   apply (case_tac "f a")
       
   954   apply auto
       
   955   done
   936 
   956 
   937 fun disjuncts :: "fm \<Rightarrow> fm list"
   957 fun disjuncts :: "fm \<Rightarrow> fm list"
   938 where
   958 where
   939   "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   959   "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   940 | "disjuncts F = []"
   960 | "disjuncts F = []"
   950     by (induct p rule:disjuncts.induct) auto
   970     by (induct p rule:disjuncts.induct) auto
   951   then show ?thesis
   971   then show ?thesis
   952     by (simp only: list_all_iff)
   972     by (simp only: list_all_iff)
   953 qed
   973 qed
   954 
   974 
   955 lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall>q\<in> set (disjuncts p). qfree q"
   975 lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall>q \<in> set (disjuncts p). qfree q"
   956 proof-
   976 proof -
   957   assume qf: "qfree p"
   977   assume qf: "qfree p"
   958   then have "list_all qfree (disjuncts p)"
   978   then have "list_all qfree (disjuncts p)"
   959     by (induct p rule: disjuncts.induct) auto
   979     by (induct p rule: disjuncts.induct) auto
   960   then show ?thesis by (simp only: list_all_iff)
   980   then show ?thesis by (simp only: list_all_iff)
   961 qed
   981 qed
  1024   "CJNB f p \<equiv>
  1044   "CJNB f p \<equiv>
  1025     (let cjs = conjuncts p;
  1045     (let cjs = conjuncts p;
  1026       (yes, no) = partition bound0 cjs
  1046       (yes, no) = partition bound0 cjs
  1027      in conj (decr0 (list_conj yes)) (f (list_conj no)))"
  1047      in conj (decr0 (list_conj yes)) (f (list_conj no)))"
  1028 
  1048 
  1029 lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall>q\<in> set (conjuncts p). qfree q"
  1049 lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall>q \<in> set (conjuncts p). qfree q"
  1030 proof -
  1050 proof -
  1031   assume qf: "qfree p"
  1051   assume qf: "qfree p"
  1032   then have "list_all qfree (conjuncts p)"
  1052   then have "list_all qfree (conjuncts p)"
  1033     by (induct p rule: conjuncts.induct) auto
  1053     by (induct p rule: conjuncts.induct) auto
  1034   then show ?thesis
  1054   then show ?thesis
  1144 definition "simple t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then le s else Le (CNP 0 c s))"
  1164 definition "simple t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then le s else Le (CNP 0 c s))"
  1145 definition "simpeq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then eq s else Eq (CNP 0 c s))"
  1165 definition "simpeq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then eq s else Eq (CNP 0 c s))"
  1146 definition "simpneq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then neq s else NEq (CNP 0 c s))"
  1166 definition "simpneq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then neq s else NEq (CNP 0 c s))"
  1147 
  1167 
  1148 lemma simplt_islin[simp]:
  1168 lemma simplt_islin[simp]:
  1149   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1169   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1150   shows "islin (simplt t)"
  1170   shows "islin (simplt t)"
  1151   unfolding simplt_def
  1171   unfolding simplt_def
  1152   using split0_nb0'
  1172   using split0_nb0'
  1153   by (auto simp add: lt_lin Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1173   by (auto simp add: lt_lin Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1154       islin_stupid allpolys_split0[OF simptm_allpolys_npoly])
  1174       islin_stupid allpolys_split0[OF simptm_allpolys_npoly])
  1155 
  1175 
  1156 lemma simple_islin[simp]:
  1176 lemma simple_islin[simp]:
  1157   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1177   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1158   shows "islin (simple t)"
  1178   shows "islin (simple t)"
  1159   unfolding simple_def
  1179   unfolding simple_def
  1160   using split0_nb0'
  1180   using split0_nb0'
  1161   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1181   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1162       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] le_lin)
  1182       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] le_lin)
  1163 
  1183 
  1164 lemma simpeq_islin[simp]:
  1184 lemma simpeq_islin[simp]:
  1165   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1185   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1166   shows "islin (simpeq t)"
  1186   shows "islin (simpeq t)"
  1167   unfolding simpeq_def
  1187   unfolding simpeq_def
  1168   using split0_nb0'
  1188   using split0_nb0'
  1169   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1189   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1170       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] eq_lin)
  1190       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] eq_lin)
  1171 
  1191 
  1172 lemma simpneq_islin[simp]:
  1192 lemma simpneq_islin[simp]:
  1173   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1193   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1174   shows "islin (simpneq t)"
  1194   shows "islin (simpneq t)"
  1175   unfolding simpneq_def
  1195   unfolding simpneq_def
  1176   using split0_nb0'
  1196   using split0_nb0'
  1177   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1197   by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  1178       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] neq_lin)
  1198       islin_stupid allpolys_split0[OF simptm_allpolys_npoly] neq_lin)
  1179 
  1199 
  1180 lemma really_stupid: "\<not> (\<forall>c1 s'. (c1, s') \<noteq> split0 s)"
  1200 lemma really_stupid: "\<not> (\<forall>c1 s'. (c1, s') \<noteq> split0 s)"
  1181   by (cases "split0 s") auto
  1201   by (cases "split0 s") auto
  1182 
  1202 
  1183 lemma split0_npoly:
  1203 lemma split0_npoly:
  1184   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1204   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1185     and n: "allpolys isnpoly t"
  1205     and n: "allpolys isnpoly t"
  1186   shows "isnpoly (fst (split0 t))"
  1206   shows "isnpoly (fst (split0 t))"
  1187     and "allpolys isnpoly (snd (split0 t))"
  1207     and "allpolys isnpoly (snd (split0 t))"
  1188   using n
  1208   using n
  1189   by (induct t rule: split0.induct)
  1209   by (induct t rule: split0.induct)
  1193 lemma simplt[simp]: "Ifm vs bs (simplt t) = Ifm vs bs (Lt t)"
  1213 lemma simplt[simp]: "Ifm vs bs (simplt t) = Ifm vs bs (Lt t)"
  1194 proof -
  1214 proof -
  1195   have n: "allpolys isnpoly (simptm t)"
  1215   have n: "allpolys isnpoly (simptm t)"
  1196     by simp
  1216     by simp
  1197   let ?t = "simptm t"
  1217   let ?t = "simptm t"
  1198   {
  1218   show ?thesis
  1199     assume "fst (split0 ?t) = 0\<^sub>p"
  1219   proof (cases "fst (split0 ?t) = 0\<^sub>p")
  1200     then have ?thesis
  1220     case True
       
  1221     then show ?thesis
  1201       using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF n], of vs bs]
  1222       using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF n], of vs bs]
  1202       by (simp add: simplt_def Let_def split_def lt)
  1223       by (simp add: simplt_def Let_def split_def lt)
  1203   }
  1224   next
  1204   moreover
  1225     case False
  1205   {
  1226     then show ?thesis
  1206     assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
  1227       using split0[of "simptm t" vs bs]
  1207     then have ?thesis
       
  1208       using  split0[of "simptm t" vs bs]
       
  1209       by (simp add: simplt_def Let_def split_def)
  1228       by (simp add: simplt_def Let_def split_def)
  1210   }
  1229   qed
  1211   ultimately show ?thesis by blast
       
  1212 qed
  1230 qed
  1213 
  1231 
  1214 lemma simple[simp]: "Ifm vs bs (simple t) = Ifm vs bs (Le t)"
  1232 lemma simple[simp]: "Ifm vs bs (simple t) = Ifm vs bs (Le t)"
  1215 proof -
  1233 proof -
  1216   have n: "allpolys isnpoly (simptm t)"
  1234   have n: "allpolys isnpoly (simptm t)"
  1217     by simp
  1235     by simp
  1218   let ?t = "simptm t"
  1236   let ?t = "simptm t"
  1219   {
  1237   show ?thesis
  1220     assume "fst (split0 ?t) = 0\<^sub>p"
  1238   proof (cases "fst (split0 ?t) = 0\<^sub>p")
  1221     then have ?thesis
  1239     case True
       
  1240     then show ?thesis
  1222       using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF n], of vs bs]
  1241       using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF n], of vs bs]
  1223       by (simp add: simple_def Let_def split_def le)
  1242       by (simp add: simple_def Let_def split_def le)
  1224   }
  1243   next
  1225   moreover
  1244     case False
  1226   {
  1245     then show ?thesis
  1227     assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
       
  1228     then have ?thesis
       
  1229       using split0[of "simptm t" vs bs]
  1246       using split0[of "simptm t" vs bs]
  1230       by (simp add: simple_def Let_def split_def)
  1247       by (simp add: simple_def Let_def split_def)
  1231   }
  1248   qed
  1232   ultimately show ?thesis by blast
       
  1233 qed
  1249 qed
  1234 
  1250 
  1235 lemma simpeq[simp]: "Ifm vs bs (simpeq t) = Ifm vs bs (Eq t)"
  1251 lemma simpeq[simp]: "Ifm vs bs (simpeq t) = Ifm vs bs (Eq t)"
  1236 proof -
  1252 proof -
  1237   have n: "allpolys isnpoly (simptm t)"
  1253   have n: "allpolys isnpoly (simptm t)"
  1238     by simp
  1254     by simp
  1239   let ?t = "simptm t"
  1255   let ?t = "simptm t"
  1240   {
  1256   show ?thesis
  1241     assume "fst (split0 ?t) = 0\<^sub>p"
  1257   proof (cases "fst (split0 ?t) = 0\<^sub>p")
  1242     then have ?thesis
  1258     case True
       
  1259     then show ?thesis
  1243       using split0[of "simptm t" vs bs] eq[OF split0_npoly(2)[OF n], of vs bs]
  1260       using split0[of "simptm t" vs bs] eq[OF split0_npoly(2)[OF n], of vs bs]
  1244       by (simp add: simpeq_def Let_def split_def)
  1261       by (simp add: simpeq_def Let_def split_def)
  1245   }
  1262   next
  1246   moreover
  1263     case False
  1247   {
  1264     then show ?thesis using  split0[of "simptm t" vs bs]
  1248     assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
       
  1249     then have ?thesis using  split0[of "simptm t" vs bs]
       
  1250       by (simp add: simpeq_def Let_def split_def)
  1265       by (simp add: simpeq_def Let_def split_def)
  1251   }
  1266   qed
  1252   ultimately show ?thesis by blast
       
  1253 qed
  1267 qed
  1254 
  1268 
  1255 lemma simpneq[simp]: "Ifm vs bs (simpneq t) = Ifm vs bs (NEq t)"
  1269 lemma simpneq[simp]: "Ifm vs bs (simpneq t) = Ifm vs bs (NEq t)"
  1256 proof -
  1270 proof -
  1257   have n: "allpolys isnpoly (simptm t)"
  1271   have n: "allpolys isnpoly (simptm t)"
  1258     by simp
  1272     by simp
  1259   let ?t = "simptm t"
  1273   let ?t = "simptm t"
  1260   {
  1274   show ?thesis
  1261     assume "fst (split0 ?t) = 0\<^sub>p"
  1275   proof (cases "fst (split0 ?t) = 0\<^sub>p")
  1262     then have ?thesis
  1276     case True
       
  1277     then show ?thesis
  1263       using split0[of "simptm t" vs bs] neq[OF split0_npoly(2)[OF n], of vs bs]
  1278       using split0[of "simptm t" vs bs] neq[OF split0_npoly(2)[OF n], of vs bs]
  1264       by (simp add: simpneq_def Let_def split_def)
  1279       by (simp add: simpneq_def Let_def split_def)
  1265   }
  1280   next
  1266   moreover
  1281     case False
  1267   {
  1282     then show ?thesis
  1268     assume "fst (split0 ?t) \<noteq> 0\<^sub>p"
       
  1269     then have ?thesis
       
  1270       using split0[of "simptm t" vs bs] by (simp add: simpneq_def Let_def split_def)
  1283       using split0[of "simptm t" vs bs] by (simp add: simpneq_def Let_def split_def)
  1271   }
  1284   qed
  1272   ultimately show ?thesis by blast
       
  1273 qed
  1285 qed
  1274 
  1286 
  1275 lemma lt_nb: "tmbound0 t \<Longrightarrow> bound0 (lt t)"
  1287 lemma lt_nb: "tmbound0 t \<Longrightarrow> bound0 (lt t)"
  1276   apply (simp add: lt_def)
  1288   apply (simp add: lt_def)
  1277   apply (cases t)
  1289   apply (cases t)
  1303   apply (rename_tac poly, case_tac poly)
  1315   apply (rename_tac poly, case_tac poly)
  1304   apply auto
  1316   apply auto
  1305   done
  1317   done
  1306 
  1318 
  1307 lemma simplt_nb[simp]:
  1319 lemma simplt_nb[simp]:
  1308   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1320   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1309   shows "tmbound0 t \<Longrightarrow> bound0 (simplt t)"
  1321   shows "tmbound0 t \<Longrightarrow> bound0 (simplt t)"
  1310 proof (simp add: simplt_def Let_def split_def)
  1322 proof (simp add: simplt_def Let_def split_def)
  1311   assume nb: "tmbound0 t"
  1323   assume nb: "tmbound0 t"
  1312   then have nb': "tmbound0 (simptm t)"
  1324   then have nb': "tmbound0 (simptm t)"
  1313     by simp
  1325     by simp
  1324       fst (split0 (simptm t)) = 0\<^sub>p"
  1336       fst (split0 (simptm t)) = 0\<^sub>p"
  1325     by (simp add: simplt_def Let_def split_def lt_nb)
  1337     by (simp add: simplt_def Let_def split_def lt_nb)
  1326 qed
  1338 qed
  1327 
  1339 
  1328 lemma simple_nb[simp]:
  1340 lemma simple_nb[simp]:
  1329   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1341   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1330   shows "tmbound0 t \<Longrightarrow> bound0 (simple t)"
  1342   shows "tmbound0 t \<Longrightarrow> bound0 (simple t)"
  1331 proof(simp add: simple_def Let_def split_def)
  1343 proof(simp add: simple_def Let_def split_def)
  1332   assume nb: "tmbound0 t"
  1344   assume nb: "tmbound0 t"
  1333   then have nb': "tmbound0 (simptm t)"
  1345   then have nb': "tmbound0 (simptm t)"
  1334     by simp
  1346     by simp
  1345       fst (split0 (simptm t)) = 0\<^sub>p"
  1357       fst (split0 (simptm t)) = 0\<^sub>p"
  1346     by (simp add: simplt_def Let_def split_def le_nb)
  1358     by (simp add: simplt_def Let_def split_def le_nb)
  1347 qed
  1359 qed
  1348 
  1360 
  1349 lemma simpeq_nb[simp]:
  1361 lemma simpeq_nb[simp]:
  1350   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1362   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1351   shows "tmbound0 t \<Longrightarrow> bound0 (simpeq t)"
  1363   shows "tmbound0 t \<Longrightarrow> bound0 (simpeq t)"
  1352 proof (simp add: simpeq_def Let_def split_def)
  1364 proof (simp add: simpeq_def Let_def split_def)
  1353   assume nb: "tmbound0 t"
  1365   assume nb: "tmbound0 t"
  1354   then have nb': "tmbound0 (simptm t)"
  1366   then have nb': "tmbound0 (simptm t)"
  1355     by simp
  1367     by simp
  1366       fst (split0 (simptm t)) = 0\<^sub>p"
  1378       fst (split0 (simptm t)) = 0\<^sub>p"
  1367     by (simp add: simpeq_def Let_def split_def eq_nb)
  1379     by (simp add: simpeq_def Let_def split_def eq_nb)
  1368 qed
  1380 qed
  1369 
  1381 
  1370 lemma simpneq_nb[simp]:
  1382 lemma simpneq_nb[simp]:
  1371   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1383   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1372   shows "tmbound0 t \<Longrightarrow> bound0 (simpneq t)"
  1384   shows "tmbound0 t \<Longrightarrow> bound0 (simpneq t)"
  1373 proof (simp add: simpneq_def Let_def split_def)
  1385 proof (simp add: simpneq_def Let_def split_def)
  1374   assume nb: "tmbound0 t"
  1386   assume nb: "tmbound0 t"
  1375   then have nb': "tmbound0 (simptm t)"
  1387   then have nb': "tmbound0 (simptm t)"
  1376     by simp
  1388     by simp
  1472   with qe have cno_qf:"qfree (qe ?cno)"
  1484   with qe have cno_qf:"qfree (qe ?cno)"
  1473     and noE: "Ifm vs bs (qe ?cno) = Ifm vs bs (E ?cno)"
  1485     and noE: "Ifm vs bs (qe ?cno) = Ifm vs bs (E ?cno)"
  1474     by blast+
  1486     by blast+
  1475   from cno_qf yes_qf have qf: "qfree (CJNB qe p)"
  1487   from cno_qf yes_qf have qf: "qfree (CJNB qe p)"
  1476     by (simp add: CJNB_def Let_def split_def)
  1488     by (simp add: CJNB_def Let_def split_def)
  1477   {
  1489   have "Ifm vs bs p = ((Ifm vs bs ?cyes) \<and> (Ifm vs bs ?cno))" for bs
  1478     fix bs
  1490   proof -
  1479     from conjuncts have "Ifm vs bs p = (\<forall>q\<in> set ?cjs. Ifm vs bs q)"
  1491     from conjuncts have "Ifm vs bs p = (\<forall>q\<in> set ?cjs. Ifm vs bs q)"
  1480       by blast
  1492       by blast
  1481     also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm vs bs q) \<and> (\<forall>q\<in> set ?no. Ifm vs bs q))"
  1493     also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm vs bs q) \<and> (\<forall>q\<in> set ?no. Ifm vs bs q))"
  1482       using partition_set[OF part] by auto
  1494       using partition_set[OF part] by auto
  1483     finally have "Ifm vs bs p = ((Ifm vs bs ?cyes) \<and> (Ifm vs bs ?cno))"
  1495     finally show ?thesis
  1484       using list_conj[of vs bs] by simp
  1496       using list_conj[of vs bs] by simp
  1485   }
  1497   qed
  1486   then have "Ifm vs bs (E p) = (\<exists>x. (Ifm vs (x#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
  1498   then have "Ifm vs bs (E p) = (\<exists>x. (Ifm vs (x#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
  1487     by simp
  1499     by simp
  1488   also fix y have "\<dots> = (\<exists>x. (Ifm vs (y#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
  1500   also fix y have "\<dots> = (\<exists>x. (Ifm vs (y#bs) ?cyes) \<and> (Ifm vs (x#bs) ?cno))"
  1489     using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
  1501     using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
  1490   also have "\<dots> = (Ifm vs bs (decr0 ?cyes) \<and> Ifm vs bs (E ?cno))"
  1502   also have "\<dots> = (Ifm vs bs (decr0 ?cyes) \<and> Ifm vs bs (E ?cno))"
  1524 
  1536 
  1525 lemma simpfm[simp]: "Ifm vs bs (simpfm p) = Ifm vs bs p"
  1537 lemma simpfm[simp]: "Ifm vs bs (simpfm p) = Ifm vs bs p"
  1526   by (induct p arbitrary: bs rule: simpfm.induct) auto
  1538   by (induct p arbitrary: bs rule: simpfm.induct) auto
  1527 
  1539 
  1528 lemma simpfm_bound0:
  1540 lemma simpfm_bound0:
  1529   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1541   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1530   shows "bound0 p \<Longrightarrow> bound0 (simpfm p)"
  1542   shows "bound0 p \<Longrightarrow> bound0 (simpfm p)"
  1531   by (induct p rule: simpfm.induct) auto
  1543   by (induct p rule: simpfm.induct) auto
  1532 
  1544 
  1533 lemma lt_qf[simp]: "qfree (lt t)"
  1545 lemma lt_qf[simp]: "qfree (lt t)"
  1534   apply (cases t)
  1546   apply (cases t)
  1549   apply (auto simp add: eq_def)
  1561   apply (auto simp add: eq_def)
  1550   apply (rename_tac poly, case_tac poly)
  1562   apply (rename_tac poly, case_tac poly)
  1551   apply auto
  1563   apply auto
  1552   done
  1564   done
  1553 
  1565 
  1554 lemma neq_qf[simp]: "qfree (neq t)" by (simp add: neq_def)
  1566 lemma neq_qf[simp]: "qfree (neq t)"
  1555 
  1567   by (simp add: neq_def)
  1556 lemma simplt_qf[simp]: "qfree (simplt t)" by (simp add: simplt_def Let_def split_def)
  1568 
  1557 lemma simple_qf[simp]: "qfree (simple t)" by (simp add: simple_def Let_def split_def)
  1569 lemma simplt_qf[simp]: "qfree (simplt t)"
  1558 lemma simpeq_qf[simp]: "qfree (simpeq t)" by (simp add: simpeq_def Let_def split_def)
  1570   by (simp add: simplt_def Let_def split_def)
  1559 lemma simpneq_qf[simp]: "qfree (simpneq t)" by (simp add: simpneq_def Let_def split_def)
  1571 
       
  1572 lemma simple_qf[simp]: "qfree (simple t)"
       
  1573   by (simp add: simple_def Let_def split_def)
       
  1574 
       
  1575 lemma simpeq_qf[simp]: "qfree (simpeq t)"
       
  1576   by (simp add: simpeq_def Let_def split_def)
       
  1577 
       
  1578 lemma simpneq_qf[simp]: "qfree (simpneq t)"
       
  1579   by (simp add: simpneq_def Let_def split_def)
  1560 
  1580 
  1561 lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
  1581 lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
  1562   by (induct p rule: simpfm.induct) auto
  1582   by (induct p rule: simpfm.induct) auto
  1563 
  1583 
  1564 lemma disj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (disj p q)"
  1584 lemma disj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (disj p q)"
  1565   by (simp add: disj_def)
  1585   by (simp add: disj_def)
  1566 lemma conj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (conj p q)"
  1586 lemma conj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (conj p q)"
  1567   by (simp add: conj_def)
  1587   by (simp add: conj_def)
  1568 
  1588 
  1569 lemma
  1589 lemma
  1570   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  1590   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  1571   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  1591   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  1572   by (induct p rule: simpfm.induct) (simp_all add: conj_lin disj_lin)
  1592   by (induct p rule: simpfm.induct) (simp_all add: conj_lin disj_lin)
  1573 
  1593 
  1574 consts prep :: "fm \<Rightarrow> fm"
  1594 consts prep :: "fm \<Rightarrow> fm"
  1575 recdef prep "measure fmsize"
  1595 recdef prep "measure fmsize"
  1594   "prep (Or p q) = disj (prep p) (prep q)"
  1614   "prep (Or p q) = disj (prep p) (prep q)"
  1595   "prep (And p q) = conj (prep p) (prep q)"
  1615   "prep (And p q) = conj (prep p) (prep q)"
  1596   "prep (Imp p q) = prep (Or (NOT p) q)"
  1616   "prep (Imp p q) = prep (Or (NOT p) q)"
  1597   "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  1617   "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  1598   "prep p = p"
  1618   "prep p = p"
  1599 (hints simp add: fmsize_pos)
  1619   (hints simp add: fmsize_pos)
  1600 
  1620 
  1601 lemma prep: "Ifm vs bs (prep p) = Ifm vs bs p"
  1621 lemma prep: "Ifm vs bs (prep p) = Ifm vs bs p"
  1602   by (induct p arbitrary: bs rule: prep.induct) auto
  1622   by (induct p arbitrary: bs rule: prep.induct) auto
  1603 
  1623 
  1604 
  1624 
  1605 (* Generic quantifier elimination *)
  1625 text \<open>Generic quantifier elimination.\<close>
  1606 function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
  1626 function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
  1607 where
  1627 where
  1608   "qelim (E p) = (\<lambda>qe. DJ (CJNB qe) (qelim p qe))"
  1628   "qelim (E p) = (\<lambda>qe. DJ (CJNB qe) (qelim p qe))"
  1609 | "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
  1629 | "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
  1610 | "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
  1630 | "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
  1611 | "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
  1631 | "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
  1612 | "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
  1632 | "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
  1613 | "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
  1633 | "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
  1614 | "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
  1634 | "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
  1615 | "qelim p = (\<lambda>y. simpfm p)"
  1635 | "qelim p = (\<lambda>y. simpfm p)"
  1616 by pat_completeness simp_all
  1636   by pat_completeness simp_all
  1617 termination by (relation "measure fmsize") auto
  1637 termination by (relation "measure fmsize") auto
  1618 
  1638 
  1619 lemma qelim:
  1639 lemma qelim:
  1620   assumes qe_inv: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
  1640   assumes qe_inv: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
  1621   shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm vs bs (qelim p qe) = Ifm vs bs p)"
  1641   shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm vs bs (qelim p qe) = Ifm vs bs p)"
  1623   by (induct p rule: qelim.induct) auto
  1643   by (induct p rule: qelim.induct) auto
  1624 
  1644 
  1625 
  1645 
  1626 subsection \<open>Core Procedure\<close>
  1646 subsection \<open>Core Procedure\<close>
  1627 
  1647 
  1628 fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*)
  1648 fun minusinf:: "fm \<Rightarrow> fm"  -- \<open>Virtual substitution of -\<infinity>\<close>
  1629 where
  1649 where
  1630   "minusinf (And p q) = conj (minusinf p) (minusinf q)"
  1650   "minusinf (And p q) = conj (minusinf p) (minusinf q)"
  1631 | "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
  1651 | "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
  1632 | "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  1652 | "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  1633 | "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  1653 | "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  1634 | "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
  1654 | "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
  1635 | "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
  1655 | "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
  1636 | "minusinf p = p"
  1656 | "minusinf p = p"
  1637 
  1657 
  1638 fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*)
  1658 fun plusinf:: "fm \<Rightarrow> fm"  -- \<open>Virtual substitution of +\<infinity>\<close>
  1639 where
  1659 where
  1640   "plusinf (And p q) = conj (plusinf p) (plusinf q)"
  1660   "plusinf (And p q) = conj (plusinf p) (plusinf q)"
  1641 | "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
  1661 | "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
  1642 | "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  1662 | "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  1643 | "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  1663 | "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  1671     by simp_all
  1691     by simp_all
  1672   note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
  1692   note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
  1673   let ?c = "Ipoly vs c"
  1693   let ?c = "Ipoly vs c"
  1674   fix y
  1694   fix y
  1675   let ?e = "Itm vs (y#bs) e"
  1695   let ?e = "Itm vs (y#bs) e"
  1676   have "?c = 0 \<or> ?c > 0 \<or> ?c < 0" by arith
  1696   consider "?c = 0" | "?c > 0" | "?c < 0" by arith
  1677   moreover {
  1697   then show ?case
  1678     assume "?c = 0"
  1698   proof cases
  1679     then have ?case
  1699     case 1
       
  1700     then show ?thesis
  1680       using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto
  1701       using eq[OF nc(2), of vs] eq[OF nc(1), of vs] by auto
  1681   }
  1702   next
  1682   moreover {
  1703     case 2
  1683     assume cp: "?c > 0"
  1704     have "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
  1684     {
  1705       if "x < -?e / ?c" for x
  1685       fix x
  1706     proof -
  1686       assume xz: "x < -?e / ?c"
  1707       from that have "?c * x < - ?e"
  1687       then have "?c * x < - ?e"
  1708         using pos_less_divide_eq[OF \<open>?c > 0\<close>, where a="x" and b="-?e"]
  1688         using pos_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1689         by (simp add: mult.commute)
  1709         by (simp add: mult.commute)
  1690       then have "?c * x + ?e < 0"
  1710       then have "?c * x + ?e < 0"
  1691         by simp
  1711         by simp
  1692       then have "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
  1712       then show ?thesis
  1693         using eqs tmbound0_I[OF nbe, where b="y" and b'="x" and vs=vs and bs=bs] by auto
  1713         using eqs tmbound0_I[OF nbe, where b="y" and b'="x" and vs=vs and bs=bs] by auto
  1694     }
  1714     qed
  1695     then have ?case by auto
  1715     then show ?thesis by auto
  1696   }
  1716   next
  1697   moreover {
  1717     case 3
  1698     assume cp: "?c < 0"
  1718     have "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
  1699     {
  1719       if "x < -?e / ?c" for x
  1700       fix x
  1720     proof -
  1701       assume xz: "x < -?e / ?c"
  1721       from that have "?c * x > - ?e"
  1702       then have "?c * x > - ?e"
  1722         using neg_less_divide_eq[OF \<open>?c < 0\<close>, where a="x" and b="-?e"]
  1703         using neg_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1704         by (simp add: mult.commute)
  1723         by (simp add: mult.commute)
  1705       then have "?c * x + ?e > 0"
  1724       then have "?c * x + ?e > 0"
  1706         by simp
  1725         by simp
  1707       then have "Ifm vs (x#bs) (Eq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Eq (CNP 0 c e)))"
  1726       then show ?thesis
  1708         using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto
  1727         using tmbound0_I[OF nbe, where b="y" and b'="x"] eqs by auto
  1709     }
  1728     qed
  1710     then have ?case by auto
  1729     then show ?thesis by auto
  1711   }
  1730   qed
  1712   ultimately show ?case by blast
       
  1713 next
  1731 next
  1714   case (4 c e)
  1732   case (4 c e)
  1715   then have nbe: "tmbound0 e"
  1733   then have nbe: "tmbound0 e"
  1716     by simp
  1734     by simp
  1717   from 4 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1735   from 4 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1718     by simp_all
  1736     by simp_all
  1719   note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
  1737   note eqs = eq[OF nc(1), where ?'a = 'a] eq[OF nc(2), where ?'a = 'a]
  1720   let ?c = "Ipoly vs c"
  1738   let ?c = "Ipoly vs c"
  1721   fix y
  1739   fix y
  1722   let ?e = "Itm vs (y#bs) e"
  1740   let ?e = "Itm vs (y#bs) e"
  1723   have "?c=0 \<or> ?c > 0 \<or> ?c < 0"
  1741   consider "?c = 0" | "?c > 0" | "?c < 0"
  1724     by arith
  1742     by arith
  1725   moreover {
  1743   then show ?case
  1726     assume "?c = 0"
  1744   proof cases
  1727     then have ?case
  1745     case 1
       
  1746     then show ?thesis
  1728       using eqs by auto
  1747       using eqs by auto
  1729   }
  1748   next
  1730   moreover {
  1749     case 2
  1731     assume cp: "?c > 0"
  1750     have "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
  1732     {
  1751       if "x < -?e / ?c" for x
  1733       fix x
  1752     proof -
  1734       assume xz: "x < -?e / ?c"
  1753       from that have "?c * x < - ?e"
  1735       then have "?c * x < - ?e"
  1754         using pos_less_divide_eq[OF \<open>?c > 0\<close>, where a="x" and b="-?e"]
  1736         using pos_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1737         by (simp add: mult.commute)
  1755         by (simp add: mult.commute)
  1738       then have "?c * x + ?e < 0"
  1756       then have "?c * x + ?e < 0"
  1739         by simp
  1757         by simp
  1740       then have "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
  1758       then show ?thesis
  1741         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto
  1759         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto
  1742     }
  1760     qed
  1743     then have ?case by auto
  1761     then show ?thesis by auto
  1744   }
  1762   next
  1745   moreover {
  1763     case 3
  1746     assume cp: "?c < 0"
  1764     have "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
  1747     {
  1765       if "x < -?e / ?c" for x
  1748       fix x
  1766     proof -
  1749       assume xz: "x < -?e / ?c"
  1767       from that have "?c * x > - ?e"
  1750       then have "?c * x > - ?e"
  1768         using neg_less_divide_eq[OF \<open>?c < 0\<close>, where a="x" and b="-?e"]
  1751         using neg_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1752         by (simp add: mult.commute)
  1769         by (simp add: mult.commute)
  1753       then have "?c * x + ?e > 0"
  1770       then have "?c * x + ?e > 0"
  1754         by simp
  1771         by simp
  1755       then have "Ifm vs (x#bs) (NEq (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (NEq (CNP 0 c e)))"
  1772       then show ?thesis
  1756         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto
  1773         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] by auto
  1757     }
  1774     qed
  1758     then have ?case by auto
  1775     then show ?thesis by auto
  1759   }
  1776   qed
  1760   ultimately show ?case by blast
       
  1761 next
  1777 next
  1762   case (5 c e)
  1778   case (5 c e)
  1763   then have nbe: "tmbound0 e"
  1779   then have nbe: "tmbound0 e"
  1764     by simp
  1780     by simp
  1765   from 5 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1781   from 5 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1768     by (simp add: polyneg_norm)
  1784     by (simp add: polyneg_norm)
  1769   note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] lt[OF nc(2), where ?'a = 'a]
  1785   note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] lt[OF nc(2), where ?'a = 'a]
  1770   let ?c = "Ipoly vs c"
  1786   let ?c = "Ipoly vs c"
  1771   fix y
  1787   fix y
  1772   let ?e = "Itm vs (y#bs) e"
  1788   let ?e = "Itm vs (y#bs) e"
  1773   have "?c=0 \<or> ?c > 0 \<or> ?c < 0"
  1789   consider "?c = 0" | "?c > 0" | "?c < 0"
  1774     by arith
  1790     by arith
  1775   moreover {
  1791   then show ?case
  1776     assume "?c = 0"
  1792   proof cases
  1777     then have ?case using eqs by auto
  1793     case 1
  1778   }
  1794     then show ?thesis using eqs by auto
  1779   moreover {
  1795   next
  1780     assume cp: "?c > 0"
  1796     case 2
  1781     {
  1797     have "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
  1782       fix x
  1798       if "x < -?e / ?c" for x
  1783       assume xz: "x < -?e / ?c"
  1799     proof -
  1784       then have "?c * x < - ?e"
  1800       from that have "?c * x < - ?e"
  1785         using pos_less_divide_eq[OF cp, where a="x" and b="-?e"]
  1801         using pos_less_divide_eq[OF \<open>?c > 0\<close>, where a="x" and b="-?e"]
  1786         by (simp add: mult.commute)
  1802         by (simp add: mult.commute)
  1787       then have "?c * x + ?e < 0" by simp
  1803       then have "?c * x + ?e < 0" by simp
  1788       then have "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
  1804       then show ?thesis
  1789         using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs by auto
  1805         using tmbound0_I[OF nbe, where b="y" and b'="x"] \<open>?c > 0\<close> eqs by auto
  1790     }
  1806     qed
  1791     then have ?case by auto
  1807     then show ?thesis by auto
  1792   }
  1808   next
  1793   moreover {
  1809     case 3
  1794     assume cp: "?c < 0"
  1810     have "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
  1795     {
  1811       if "x < -?e / ?c" for x
  1796       fix x
  1812     proof -
  1797       assume xz: "x < -?e / ?c"
  1813       from that have "?c * x > - ?e"
  1798       then have "?c * x > - ?e"
  1814         using neg_less_divide_eq[OF \<open>?c < 0\<close>, where a="x" and b="-?e"]
  1799         using neg_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1800         by (simp add: mult.commute)
  1815         by (simp add: mult.commute)
  1801       then have "?c * x + ?e > 0"
  1816       then have "?c * x + ?e > 0"
  1802         by simp
  1817         by simp
  1803       then have "Ifm vs (x#bs) (Lt (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Lt (CNP 0 c e)))"
  1818       then show ?thesis
  1804         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] cp by auto
  1819         using eqs tmbound0_I[OF nbe, where b="y" and b'="x"] \<open>?c < 0\<close> by auto
  1805     }
  1820     qed
  1806     then have ?case by auto
  1821     then show ?thesis by auto
  1807   }
  1822   qed
  1808   ultimately show ?case by blast
       
  1809 next
  1823 next
  1810   case (6 c e)
  1824   case (6 c e)
  1811   then have nbe: "tmbound0 e"
  1825   then have nbe: "tmbound0 e"
  1812     by simp
  1826     by simp
  1813   from 6 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1827   from 6 have nc: "allpolys isnpoly (CP c)" "allpolys isnpoly e"
  1816     by (simp add: polyneg_norm)
  1830     by (simp add: polyneg_norm)
  1817   note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] le[OF nc(2), where ?'a = 'a]
  1831   note eqs = lt[OF nc', where ?'a = 'a] eq [OF nc(1), where ?'a = 'a] le[OF nc(2), where ?'a = 'a]
  1818   let ?c = "Ipoly vs c"
  1832   let ?c = "Ipoly vs c"
  1819   fix y
  1833   fix y
  1820   let ?e = "Itm vs (y#bs) e"
  1834   let ?e = "Itm vs (y#bs) e"
  1821   have "?c = 0 \<or> ?c > 0 \<or> ?c < 0" by arith
  1835   consider "?c = 0" | "?c > 0" | "?c < 0" by arith
  1822   moreover {
  1836   then show ?case
  1823     assume "?c = 0"
  1837   proof cases
  1824     then have ?case using eqs by auto
  1838     case 1
  1825   }
  1839     then show ?thesis using eqs by auto
  1826   moreover {
  1840   next
  1827     assume cp: "?c > 0"
  1841     case 2
  1828     {
  1842     have "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
  1829       fix x
  1843       if "x < -?e / ?c" for x
  1830       assume xz: "x < -?e / ?c"
  1844     proof -
  1831       then have "?c * x < - ?e"
  1845       from that have "?c * x < - ?e"
  1832         using pos_less_divide_eq[OF cp, where a="x" and b="-?e"]
  1846         using pos_less_divide_eq[OF \<open>?c > 0\<close>, where a="x" and b="-?e"]
  1833         by (simp add: mult.commute)
  1847         by (simp add: mult.commute)
  1834       then have "?c * x + ?e < 0"
  1848       then have "?c * x + ?e < 0"
  1835         by simp
  1849         by simp
  1836       then have "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
  1850       then show ?thesis
  1837         using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs
  1851         using tmbound0_I[OF nbe, where b="y" and b'="x"] \<open>?c > 0\<close> eqs
  1838         by auto
  1852         by auto
  1839     }
  1853     qed
  1840     then have ?case by auto
  1854     then show ?thesis by auto
  1841   }
  1855   next
  1842   moreover {
  1856     case 3
  1843     assume cp: "?c < 0"
  1857     have "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
  1844     {
  1858       if "x < -?e / ?c" for x
  1845       fix x
  1859     proof -
  1846       assume xz: "x < -?e / ?c"
  1860       from that have "?c * x > - ?e"
  1847       then have "?c * x > - ?e"
  1861         using neg_less_divide_eq[OF \<open>?c < 0\<close>, where a="x" and b="-?e"]
  1848         using neg_less_divide_eq[OF cp, where a="x" and b="-?e"]
       
  1849         by (simp add: mult.commute)
  1862         by (simp add: mult.commute)
  1850       then have "?c * x + ?e > 0"
  1863       then have "?c * x + ?e > 0"
  1851         by simp
  1864         by simp
  1852       then have "Ifm vs (x#bs) (Le (CNP 0 c e)) = Ifm vs (x#bs) (minusinf (Le (CNP 0 c e)))"
  1865       then show ?thesis
  1853         using tmbound0_I[OF nbe, where b="y" and b'="x"] cp eqs
  1866         using tmbound0_I[OF nbe, where b="y" and b'="x"] \<open>?c < 0\<close> eqs
  1854         by auto
  1867         by auto
  1855     }
  1868     qed
  1856     then have ?case by auto
  1869     then show ?thesis by auto
  1857   }
  1870   qed
  1858   ultimately show ?case by blast
       
  1859 qed auto
  1871 qed auto
  1860 
  1872 
  1861 lemma plusinf_inf:
  1873 lemma plusinf_inf:
  1862   assumes lp: "islin p"
  1874   assumes lp: "islin p"
  1863   shows "\<exists>z. \<forall>x > z. Ifm vs (x#bs) (plusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
  1875   shows "\<exists>z. \<forall>x > z. Ifm vs (x#bs) (plusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
  2171 lemma plusinf_uset0:
  2183 lemma plusinf_uset0:
  2172   assumes lp: "islin p"
  2184   assumes lp: "islin p"
  2173     and nmi: "\<not> (Ifm vs (x#bs) (plusinf p))"
  2185     and nmi: "\<not> (Ifm vs (x#bs) (plusinf p))"
  2174     and ex: "Ifm vs (x#bs) p" (is "?I x p")
  2186     and ex: "Ifm vs (x#bs) p" (is "?I x p")
  2175   shows "\<exists>(c, s) \<in> set (uset p). x \<le> - Itm vs (x#bs) s / Ipoly vs c"
  2187   shows "\<exists>(c, s) \<in> set (uset p). x \<le> - Itm vs (x#bs) s / Ipoly vs c"
  2176 proof-
  2188 proof -
  2177   have "\<exists>(c, s) \<in> set (uset p).
  2189   have "\<exists>(c, s) \<in> set (uset p).
  2178       Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s \<or>
  2190       Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s \<or>
  2179       Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s"
  2191       Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s"
  2180     using lp nmi ex
  2192     using lp nmi ex
  2181     apply (induct p rule: minusinf.induct)
  2193     apply (induct p rule: minusinf.induct)
  3377     by blast
  3389     by blast
  3378   from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
  3390   from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
  3379 qed
  3391 qed
  3380 
  3392 
  3381 lemma simpfm_lin:
  3393 lemma simpfm_lin:
  3382   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  3394   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  3383   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  3395   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  3384   by (induct p rule: simpfm.induct) (auto simp add: conj_lin disj_lin)
  3396   by (induct p rule: simpfm.induct) (auto simp add: conj_lin disj_lin)
  3385 
  3397 
  3386 definition "ferrack p \<equiv>
  3398 definition "ferrack p \<equiv>
  3387   let
  3399   let
  3702   using lp tnb
  3714   using lp tnb
  3703   by (induct p c t rule: msubstpos.induct)
  3715   by (induct p c t rule: msubstpos.induct)
  3704     (auto simp add: msubsteq2_nb msubstltpos_nb msubstlepos_nb)
  3716     (auto simp add: msubsteq2_nb msubstltpos_nb msubstlepos_nb)
  3705 
  3717 
  3706 lemma msubstneg_nb:
  3718 lemma msubstneg_nb:
  3707   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  3719   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  3708     and lp: "islin p"
  3720     and lp: "islin p"
  3709     and tnb: "tmbound0 t"
  3721     and tnb: "tmbound0 t"
  3710   shows "bound0 (msubstneg p c t)"
  3722   shows "bound0 (msubstneg p c t)"
  3711   using lp tnb
  3723   using lp tnb
  3712   by (induct p c t rule: msubstneg.induct)
  3724   by (induct p c t rule: msubstneg.induct)
  3713     (auto simp add: msubsteq2_nb msubstltneg_nb msubstleneg_nb)
  3725     (auto simp add: msubsteq2_nb msubstltneg_nb msubstleneg_nb)
  3714 
  3726 
  3715 lemma msubst2_nb:
  3727 lemma msubst2_nb:
  3716   assumes "SORT_CONSTRAINT('a::{field_char_0, field})"
  3728   assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  3717     and lp: "islin p"
  3729     and lp: "islin p"
  3718     and tnb: "tmbound0 t"
  3730     and tnb: "tmbound0 t"
  3719   shows "bound0 (msubst2 p c t)"
  3731   shows "bound0 (msubst2 p c t)"
  3720   using lp tnb
  3732   using lp tnb
  3721   by (simp add: msubst2_def msubstneg_nb msubstpos_nb lt_nb simpfm_bound0)
  3733   by (simp add: msubst2_def msubstneg_nb msubstpos_nb lt_nb simpfm_bound0)
  4194 
  4206 
  4195 method_setup frpar2 = \<open>
  4207 method_setup frpar2 = \<open>
  4196   Parametric_Ferrante_Rackoff.method true
  4208   Parametric_Ferrante_Rackoff.method true
  4197 \<close> "parametric QE for linear Arithmetic over fields, Version 2"
  4209 \<close> "parametric QE for linear Arithmetic over fields, Version 2"
  4198 
  4210 
  4199 lemma "\<exists>(x::'a::{linordered_field}). y \<noteq> -1 \<longrightarrow> (y + 1) * x < 0"
  4211 lemma "\<exists>(x::'a::linordered_field). y \<noteq> -1 \<longrightarrow> (y + 1) * x < 0"
  4200   apply (frpar type: 'a pars: y)
  4212   apply (frpar type: 'a pars: y)
  4201   apply (simp add: field_simps)
  4213   apply (simp add: field_simps)
  4202   apply (rule spec[where x=y])
  4214   apply (rule spec[where x=y])
  4203   apply (frpar type: 'a pars: "z::'a")
  4215   apply (frpar type: 'a pars: "z::'a")
  4204   apply simp
  4216   apply simp
  4205   done
  4217   done
  4206 
  4218 
  4207 lemma "\<exists>(x::'a::{linordered_field}). y \<noteq> -1 \<longrightarrow> (y + 1)*x < 0"
  4219 lemma "\<exists>(x::'a::linordered_field). y \<noteq> -1 \<longrightarrow> (y + 1)*x < 0"
  4208   apply (frpar2 type: 'a pars: y)
  4220   apply (frpar2 type: 'a pars: y)
  4209   apply (simp add: field_simps)
  4221   apply (simp add: field_simps)
  4210   apply (rule spec[where x=y])
  4222   apply (rule spec[where x=y])
  4211   apply (frpar2 type: 'a pars: "z::'a")
  4223   apply (frpar2 type: 'a pars: "z::'a")
  4212   apply simp
  4224   apply simp
  4213   done
  4225   done
  4214 
  4226 
  4215 text\<open>Collins/Jones Problem\<close>
  4227 text \<open>Collins/Jones Problem\<close>
  4216 (*
  4228 (*
  4217 lemma "\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
  4229 lemma "\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
  4218 proof-
  4230 proof -
  4219   have "(\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
  4231   have "(\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
  4220 by (simp add: field_simps)
  4232 by (simp add: field_simps)
  4221 have "?rhs"
  4233 have "?rhs"
  4222 
  4234 
  4223   apply (frpar type: "'a::{linordered_field, number_ring}" pars: "a::'a::{linordered_field, number_ring}" "b::'a::{linordered_field, number_ring}")
  4235   apply (frpar type: "'a::{linordered_field, number_ring}" pars: "a::'a::{linordered_field, number_ring}" "b::'a::{linordered_field, number_ring}")
  4228 lemma "ALL (x::'a::{linordered_field, number_ring}) y. (1 - t)*x \<le> (1+t)*y \<and> (1 - t)*y \<le> (1+t)*x --> 0 \<le> y"
  4240 lemma "ALL (x::'a::{linordered_field, number_ring}) y. (1 - t)*x \<le> (1+t)*y \<and> (1 - t)*y \<le> (1+t)*x --> 0 \<le> y"
  4229 apply (frpar type: "'a::{linordered_field, number_ring}" pars: "t::'a::{linordered_field, number_ring}")
  4241 apply (frpar type: "'a::{linordered_field, number_ring}" pars: "t::'a::{linordered_field, number_ring}")
  4230 oops
  4242 oops
  4231 *)
  4243 *)
  4232 
  4244 
  4233 text\<open>Collins/Jones Problem\<close>
  4245 text \<open>Collins/Jones Problem\<close>
  4234 
  4246 
  4235 (*
  4247 (*
  4236 lemma "\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
  4248 lemma "\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0"
  4237 proof-
  4249 proof -
  4238   have "(\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
  4250   have "(\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < (2 - 3*r) *(a^2 + b^2) + (2*a)*r \<and> (2 - 3*r) *(a^2 + b^2) + 4*a*r - 2*a - r < 0) \<longleftrightarrow> (\<exists>(r::'a::{linordered_field, number_ring}). 0 < r \<and> r < 1 \<and> 0 < 2 *(a^2 + b^2) - (3*(a^2 + b^2)) * r + (2*a)*r \<and> 2*(a^2 + b^2) - (3*(a^2 + b^2) - 4*a + 1)*r - 2*a < 0)" (is "?lhs \<longleftrightarrow> ?rhs")
  4239 by (simp add: field_simps)
  4251 by (simp add: field_simps)
  4240 have "?rhs"
  4252 have "?rhs"
  4241   apply (frpar2 type: "'a::{linordered_field, number_ring}" pars: "a::'a::{linordered_field, number_ring}" "b::'a::{linordered_field, number_ring}")
  4253   apply (frpar2 type: "'a::{linordered_field, number_ring}" pars: "a::'a::{linordered_field, number_ring}" "b::'a::{linordered_field, number_ring}")
  4242   apply simp
  4254   apply simp