src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
changeset 45499 849d697adf1e
parent 44064 5bce8ff0d9ae
child 47108 2a1953f0d20d
equal deleted inserted replaced
45498:2dc373f1867a 45499:849d697adf1e
    23 | "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
    23 | "tmsize (Sub a b) = 3 + tmsize a + tmsize b"
    24 | "tmsize (Mul c a) = 1 + polysize c + tmsize a"
    24 | "tmsize (Mul c a) = 1 + polysize c + tmsize a"
    25 | "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
    25 | "tmsize (CNP n c a) = 3 + polysize c + tmsize a "
    26 
    26 
    27   (* Semantics of terms tm *)
    27   (* Semantics of terms tm *)
    28 primrec Itm :: "'a::{field_char_0, field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a" where
    28 primrec Itm :: "'a::{field_char_0, field_inverse_zero, number_ring} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a" where
    29   "Itm vs bs (CP c) = (Ipoly vs c)"
    29   "Itm vs bs (CP c) = (Ipoly vs c)"
    30 | "Itm vs bs (Bound n) = bs!n"
    30 | "Itm vs bs (Bound n) = bs!n"
    31 | "Itm vs bs (Neg a) = -(Itm vs bs a)"
    31 | "Itm vs bs (Neg a) = -(Itm vs bs a)"
    32 | "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    32 | "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    33 | "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
    33 | "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
   264   "tmsub s t \<equiv> (if s = t then CP 0\<^sub>p else tmadd (s,tmneg t))"
   264   "tmsub s t \<equiv> (if s = t then CP 0\<^sub>p else tmadd (s,tmneg t))"
   265 
   265 
   266 lemma tmneg[simp]: "Itm vs bs (tmneg t) = Itm vs bs (Neg t)"
   266 lemma tmneg[simp]: "Itm vs bs (tmneg t) = Itm vs bs (Neg t)"
   267 using tmneg_def[of t] 
   267 using tmneg_def[of t] 
   268 apply simp
   268 apply simp
   269 apply (subst number_of_Min)
       
   270 apply (simp only: of_int_minus)
       
   271 apply simp
       
   272 done
   269 done
   273 
   270 
   274 lemma tmneg_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmneg t)"
   271 lemma tmneg_nb0[simp]: "tmbound0 t \<Longrightarrow> tmbound0 (tmneg t)"
   275 using tmneg_def by simp
   272 using tmneg_def by simp
   276 
   273 
   307 | "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   304 | "simptm (Mul i t) = (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   308 | "simptm (CNP n c t) = (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))"
   305 | "simptm (CNP n c t) = (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p ), simptm t))"
   309 
   306 
   310 lemma polynate_stupid: 
   307 lemma polynate_stupid: 
   311   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   308   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   312   shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a::{field_char_0, field_inverse_zero})" 
   309   shows "polynate t = 0\<^sub>p \<Longrightarrow> Ipoly bs t = (0::'a)"
   313 apply (subst polynate[symmetric])
   310 apply (subst polynate[symmetric])
   314 apply simp
   311 apply simp
   315 done
   312 done
   316 
   313 
   317 lemma simptm_ci[simp]: "Itm vs bs (simptm t) = Itm vs bs t"
   314 lemma simptm_ci[simp]: "Itm vs bs (simptm t) = Itm vs bs t"
   431   (* several lemmas about fmsize *)
   428   (* several lemmas about fmsize *)
   432 lemma fmsize_pos[termination_simp]: "fmsize p > 0"        
   429 lemma fmsize_pos[termination_simp]: "fmsize p > 0"        
   433 by (induct p rule: fmsize.induct) simp_all
   430 by (induct p rule: fmsize.induct) simp_all
   434 
   431 
   435   (* Semantics of formulae (fm) *)
   432   (* Semantics of formulae (fm) *)
   436 primrec Ifm ::"'a::{linordered_field_inverse_zero} list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool" where
   433 primrec Ifm ::"'a::{linordered_field_inverse_zero, number_ring} list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool" where
   437   "Ifm vs bs T = True"
   434   "Ifm vs bs T = True"
   438 | "Ifm vs bs F = False"
   435 | "Ifm vs bs F = False"
   439 | "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   436 | "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   440 | "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   437 | "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   441 | "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
   438 | "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
  1796     from yne c eq_divide_eq[of "y" "- ?Nt x s" "?N c"] have ?case
  1793     from yne c eq_divide_eq[of "y" "- ?Nt x s" "?N c"] have ?case
  1797       by (simp add: field_simps tmbound0_I[OF lin(3), of vs x bs y] sum_eq[symmetric]) }
  1794       by (simp add: field_simps tmbound0_I[OF lin(3), of vs x bs y] sum_eq[symmetric]) }
  1798   ultimately show ?case by blast
  1795   ultimately show ?case by blast
  1799 qed (auto simp add: tmbound0_I[where vs=vs and bs="bs" and b="y" and b'="x"] bound0_I[where vs=vs and bs="bs" and b="y" and b'="x"])
  1796 qed (auto simp add: tmbound0_I[where vs=vs and bs="bs" and b="y" and b'="x"] bound0_I[where vs=vs and bs="bs" and b="y" and b'="x"])
  1800 
  1797 
  1801 lemma one_plus_one_pos[simp]: "(1::'a::{linordered_field}) + 1 > 0"
       
  1802 proof-
       
  1803   have op: "(1::'a) > 0" by simp
       
  1804   from add_pos_pos[OF op op] show ?thesis . 
       
  1805 qed
       
  1806 
       
  1807 lemma one_plus_one_nonzero[simp]: "(1::'a::{linordered_field}) + 1 \<noteq> 0" 
       
  1808   using one_plus_one_pos[where ?'a = 'a] by (simp add: less_le) 
       
  1809 
       
  1810 lemma half_sum_eq: "(u + u) / (1+1) = (u::'a::{linordered_field})" 
       
  1811 proof-
       
  1812   have "(u + u) = (1 + 1) * u" by (simp add: field_simps)
       
  1813   hence "(u + u) / (1+1) = (1 + 1)*u / (1 + 1)" by simp
       
  1814   with nonzero_mult_divide_cancel_left[OF one_plus_one_nonzero, of u] show ?thesis by simp
       
  1815 qed
       
  1816 
       
  1817 lemma inf_uset:
  1798 lemma inf_uset:
  1818   assumes lp: "islin p"
  1799   assumes lp: "islin p"
  1819   and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))" (is "\<not> (Ifm vs (x#bs) (?M p))")
  1800   and nmi: "\<not> (Ifm vs (x#bs) (minusinf p))" (is "\<not> (Ifm vs (x#bs) (?M p))")
  1820   and npi: "\<not> (Ifm vs (x#bs) (plusinf p))" (is "\<not> (Ifm vs (x#bs) (?P p))")
  1801   and npi: "\<not> (Ifm vs (x#bs) (plusinf p))" (is "\<not> (Ifm vs (x#bs) (?P p))")
  1821   and ex: "\<exists> x.  Ifm vs (x#bs) p" (is "\<exists> x. ?I x p")
  1802   and ex: "\<exists> x.  Ifm vs (x#bs) p" (is "\<exists> x. ?I x p")
  1822   shows "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- Itm vs (x#bs) t / Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) / (1 + 1)) p" 
  1803   shows "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- Itm vs (x#bs) t / Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) / 2) p" 
  1823 proof-
  1804 proof-
  1824   let ?Nt = "\<lambda> x t. Itm vs (x#bs) t"
  1805   let ?Nt = "\<lambda> x t. Itm vs (x#bs) t"
  1825   let ?N = "Ipoly vs"
  1806   let ?N = "Ipoly vs"
  1826   let ?U = "set (uset p)"
  1807   let ?U = "set (uset p)"
  1827   from ex obtain a where pa: "?I a p" by blast
  1808   from ex obtain a where pa: "?I a p" by blast
  1828   from bound0_I[OF minusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] nmi
  1809   from bound0_I[OF minusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] nmi
  1829   have nmi': "\<not> (?I a (?M p))" by simp
  1810   have nmi': "\<not> (?I a (?M p))" by simp
  1830   from bound0_I[OF plusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] npi
  1811   from bound0_I[OF plusinf_nb[OF lp], where bs="bs" and b="x" and b'="a"] npi
  1831   have npi': "\<not> (?I a (?P p))" by simp
  1812   have npi': "\<not> (?I a (?P p))" by simp
  1832   have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- ?Nt a t/?N c + - ?Nt a s /?N d) / (1 + 1)) p"
  1813   have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). ?I ((- ?Nt a t/?N c + - ?Nt a s /?N d) / 2) p"
  1833   proof-
  1814   proof-
  1834     let ?M = "(\<lambda> (c,t). - ?Nt a t / ?N c) ` ?U"
  1815     let ?M = "(\<lambda> (c,t). - ?Nt a t / ?N c) ` ?U"
  1835     have fM: "finite ?M" by auto
  1816     have fM: "finite ?M" by auto
  1836     from minusinf_uset[OF lp nmi pa] plusinf_uset[OF lp npi pa] 
  1817     from minusinf_uset[OF lp nmi pa] plusinf_uset[OF lp npi pa] 
  1837     have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). a \<le> - ?Nt x t / ?N c \<and> a \<ge> - ?Nt x s / ?N d" by blast
  1818     have "\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). a \<le> - ?Nt x t / ?N c \<and> a \<ge> - ?Nt x s / ?N d" by blast
  1856     have "(\<exists> s\<in> ?M. ?I s p) \<or> 
  1837     have "(\<exists> s\<in> ?M. ?I s p) \<or> 
  1857       (\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p)" .
  1838       (\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p)" .
  1858     moreover {fix u assume um: "u\<in> ?M" and pu: "?I u p"
  1839     moreover {fix u assume um: "u\<in> ?M" and pu: "?I u p"
  1859       hence "\<exists> (nu,tu) \<in> ?U. u = - ?Nt a tu / ?N nu" by auto
  1840       hence "\<exists> (nu,tu) \<in> ?U. u = - ?Nt a tu / ?N nu" by auto
  1860       then obtain "tu" "nu" where tuU: "(nu,tu) \<in> ?U" and tuu:"u= - ?Nt a tu / ?N nu" by blast
  1841       then obtain "tu" "nu" where tuU: "(nu,tu) \<in> ?U" and tuu:"u= - ?Nt a tu / ?N nu" by blast
  1861       from half_sum_eq[of u] pu tuu 
  1842       from pu tuu
  1862       have "?I (((- ?Nt a tu / ?N nu) + (- ?Nt a tu / ?N nu)) / (1 + 1)) p" by simp
  1843       have "?I (((- ?Nt a tu / ?N nu) + (- ?Nt a tu / ?N nu)) / 2) p" by simp
  1863       with tuU have ?thesis by blast}
  1844       with tuU have ?thesis by blast}
  1864     moreover{
  1845     moreover{
  1865       assume "\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p"
  1846       assume "\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p"
  1866       then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" 
  1847       then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" 
  1867         and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p"
  1848         and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p"
  1869       from t1M have "\<exists> (t1n,t1u) \<in> ?U. t1 = - ?Nt a t1u / ?N t1n" by auto
  1850       from t1M have "\<exists> (t1n,t1u) \<in> ?U. t1 = - ?Nt a t1u / ?N t1n" by auto
  1870       then obtain "t1u" "t1n" where t1uU: "(t1n,t1u) \<in> ?U" and t1u: "t1 = - ?Nt a t1u / ?N t1n" by blast
  1851       then obtain "t1u" "t1n" where t1uU: "(t1n,t1u) \<in> ?U" and t1u: "t1 = - ?Nt a t1u / ?N t1n" by blast
  1871       from t2M have "\<exists> (t2n,t2u) \<in> ?U. t2 = - ?Nt a t2u / ?N t2n" by auto
  1852       from t2M have "\<exists> (t2n,t2u) \<in> ?U. t2 = - ?Nt a t2u / ?N t2n" by auto
  1872       then obtain "t2u" "t2n" where t2uU: "(t2n,t2u) \<in> ?U" and t2u: "t2 = - ?Nt a t2u / ?N t2n" by blast
  1853       then obtain "t2u" "t2n" where t2uU: "(t2n,t2u) \<in> ?U" and t2u: "t2 = - ?Nt a t2u / ?N t2n" by blast
  1873       from t1x xt2 have t1t2: "t1 < t2" by simp
  1854       from t1x xt2 have t1t2: "t1 < t2" by simp
  1874       let ?u = "(t1 + t2) / (1 + 1)"
  1855       let ?u = "(t1 + t2) / 2"
  1875       from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
  1856       from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
  1876       from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
  1857       from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
  1877       with t1uU t2uU t1u t2u have ?thesis by blast}
  1858       with t1uU t2uU t1u t2u have ?thesis by blast}
  1878     ultimately show ?thesis by blast
  1859     ultimately show ?thesis by blast
  1879   qed
  1860   qed
  1880   then obtain "l" "n" "s"  "m" where lnU: "(n,l) \<in> ?U" and smU:"(m,s) \<in> ?U" 
  1861   then obtain "l" "n" "s"  "m" where lnU: "(n,l) \<in> ?U" and smU:"(m,s) \<in> ?U" 
  1881     and pu: "?I ((- ?Nt a l / ?N n + - ?Nt a s / ?N m) / (1 + 1)) p" by blast
  1862     and pu: "?I ((- ?Nt a l / ?N n + - ?Nt a s / ?N m) / 2) p" by blast
  1882   from lnU smU uset_l[OF lp] have nbl: "tmbound0 l" and nbs: "tmbound0 s" by auto
  1863   from lnU smU uset_l[OF lp] have nbl: "tmbound0 l" and nbs: "tmbound0 s" by auto
  1883   from tmbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] 
  1864   from tmbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] 
  1884     tmbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
  1865     tmbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
  1885   have "?I ((- ?Nt x l / ?N n + - ?Nt x s / ?N m) / (1 + 1)) p" by simp
  1866   have "?I ((- ?Nt x l / ?N n + - ?Nt x s / ?N m) / 2) p" by simp
  1886   with lnU smU
  1867   with lnU smU
  1887   show ?thesis by auto
  1868   show ?thesis by auto
  1888 qed
  1869 qed
  1889 
  1870 
  1890     (* The Ferrante - Rackoff Theorem *)
  1871     (* The Ferrante - Rackoff Theorem *)
  1891 
  1872 
  1892 theorem fr_eq: 
  1873 theorem fr_eq: 
  1893   assumes lp: "islin p"
  1874   assumes lp: "islin p"
  1894   shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) /(1 + 1))#bs) p))"
  1875   shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) / 2)#bs) p))"
  1895   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
  1876   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
  1896 proof
  1877 proof
  1897   assume px: "\<exists> x. ?I x p"
  1878   assume px: "\<exists> x. ?I x p"
  1898   have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
  1879   have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
  1899   moreover {assume "?M \<or> ?P" hence "?D" by blast}
  1880   moreover {assume "?M \<or> ?P" hence "?D" by blast}
  1926     using lp by (simp add: Let_def t s )
  1907     using lp by (simp add: Let_def t s )
  1927   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubsteq_def)
  1908   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubsteq_def)
  1928 qed
  1909 qed
  1929 
  1910 
  1930 lemma msubsteq: assumes lp: "islin (Eq (CNP 0 a r))"
  1911 lemma msubsteq: assumes lp: "islin (Eq (CNP 0 a r))"
  1931   shows "Ifm vs (x#bs) (msubsteq c t d s a r) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Eq (CNP 0 a r))" (is "?lhs = ?rhs")
  1912   shows "Ifm vs (x#bs) (msubsteq c t d s a r) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) / 2)#bs) (Eq (CNP 0 a r))" (is "?lhs = ?rhs")
  1932 proof-
  1913 proof-
  1933   let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
  1914   let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
  1934   let ?N = "\<lambda>p. Ipoly vs p"
  1915   let ?N = "\<lambda>p. Ipoly vs p"
  1935   let ?c = "?N c"
  1916   let ?c = "?N c"
  1936   let ?d = "?N d"
  1917   let ?d = "?N d"
  1944   moreover
  1925   moreover
  1945   {assume c: "?c = 0" and d: "?d=0"
  1926   {assume c: "?c = 0" and d: "?d=0"
  1946     hence ?thesis  by (simp add: r[of 0] msubsteq_def Let_def evaldjf_ex)}
  1927     hence ?thesis  by (simp add: r[of 0] msubsteq_def Let_def evaldjf_ex)}
  1947   moreover 
  1928   moreover 
  1948   {assume c: "?c = 0" and d: "?d\<noteq>0"
  1929   {assume c: "?c = 0" and d: "?d\<noteq>0"
  1949     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?s / ((1 + 1)*?d)" by simp
  1930     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = -?s / (2*?d)" by simp
  1950     have "?rhs = Ifm vs (-?s / ((1 + 1)*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1931     have "?rhs = Ifm vs (-?s / (2*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1951     also have "\<dots> \<longleftrightarrow> ?a * (-?s / ((1 + 1)*?d)) + ?r = 0" by (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
  1932     also have "\<dots> \<longleftrightarrow> ?a * (-?s / (2*?d)) + ?r = 0" by (simp add: r[of "- (Itm vs (x # bs) s / (2 * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
  1952     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a * (-?s / ((1 + 1)*?d)) + ?r) = 0" 
  1933     also have "\<dots> \<longleftrightarrow> 2*?d * (?a * (-?s / (2*?d)) + ?r) = 0"
  1953       using d mult_cancel_left[of "(1 + 1)*?d" "(?a * (-?s / ((1 + 1)*?d)) + ?r)" 0] by simp
  1934       using d mult_cancel_left[of "2*?d" "(?a * (-?s / (2*?d)) + ?r)" 0] by simp
  1954     also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * ((1 + 1)*?d / ((1 + 1)*?d)) + (1 + 1)*?d*?r= 0"
  1935     also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * (2*?d / (2*?d)) + 2*?d*?r= 0"
  1955       by (simp add: field_simps right_distrib[of "(1 + 1)*?d"] del: right_distrib)
  1936       by (simp add: field_simps right_distrib[of "2*?d"] del: right_distrib)
  1956     
  1937     
  1957     also have "\<dots> \<longleftrightarrow> - (?a * ?s) + (1 + 1)*?d*?r = 0" using d by simp 
  1938     also have "\<dots> \<longleftrightarrow> - (?a * ?s) + 2*?d*?r = 0" using d by simp 
  1958     finally have ?thesis using c d 
  1939     finally have ?thesis using c d 
  1959       apply (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
  1940       by (simp add: r[of "- (Itm vs (x # bs) s / (2 * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
  1960       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  1941   }
  1961       apply simp
       
  1962       done}
       
  1963   moreover
  1942   moreover
  1964   {assume c: "?c \<noteq> 0" and d: "?d=0"
  1943   {assume c: "?c \<noteq> 0" and d: "?d=0"
  1965     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?t / ((1 + 1)*?c)" by simp
  1944     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = -?t / (2*?c)" by simp
  1966     have "?rhs = Ifm vs (-?t / ((1 + 1)*?c) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1945     have "?rhs = Ifm vs (-?t / (2*?c) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1967     also have "\<dots> \<longleftrightarrow> ?a * (-?t / ((1 + 1)*?c)) + ?r = 0" by (simp add: r[of "- (?t/ ((1 + 1)* ?c))"])
  1946     also have "\<dots> \<longleftrightarrow> ?a * (-?t / (2*?c)) + ?r = 0" by (simp add: r[of "- (?t/ (2 * ?c))"])
  1968     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a * (-?t / ((1 + 1)*?c)) + ?r) = 0" 
  1947     also have "\<dots> \<longleftrightarrow> 2*?c * (?a * (-?t / (2*?c)) + ?r) = 0" 
  1969       using c mult_cancel_left[of "(1 + 1)*?c" "(?a * (-?t / ((1 + 1)*?c)) + ?r)" 0] by simp
  1948       using c mult_cancel_left[of "2*?c" "(?a * (-?t / (2*?c)) + ?r)" 0] by simp
  1970     also have "\<dots> \<longleftrightarrow> (?a * -?t)* ((1 + 1)*?c) / ((1 + 1)*?c) + (1 + 1)*?c*?r= 0"
  1949     also have "\<dots> \<longleftrightarrow> (?a * -?t)* (2*?c) / (2*?c) + 2*?c*?r= 0"
  1971       by (simp add: field_simps right_distrib[of "(1 + 1)*?c"] del: right_distrib)
  1950       by (simp add: field_simps right_distrib[of "2*?c"] del: right_distrib)
  1972     also have "\<dots> \<longleftrightarrow> - (?a * ?t) + (1 + 1)*?c*?r = 0" using c by simp 
  1951     also have "\<dots> \<longleftrightarrow> - (?a * ?t) + 2*?c*?r = 0" using c by simp 
  1973     finally have ?thesis using c d 
  1952     finally have ?thesis using c d 
  1974       apply (simp add: r[of "- (?t/ ((1 + 1)*?c))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
  1953       by (simp add: r[of "- (?t/ (2*?c))"] msubsteq_def Let_def evaldjf_ex del: one_add_one_is_two)
  1975       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  1954   }
  1976       apply simp
  1955   moreover
  1977       done }
  1956   {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *2 \<noteq> 0" by simp
  1978   moreover
       
  1979   {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *(1 + 1) \<noteq> 0" by simp
       
  1980     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  1957     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  1981     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  1958     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  1982       by (simp add: field_simps)
  1959       by (simp add: field_simps)
  1983     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1960     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (Eq (CNP 0 a r))" by (simp only: th)
  1984     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r = 0" 
  1961     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r = 0" 
  1985       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  1962       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  1986     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) =0 "
  1963     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) =0 "
  1987       using c d mult_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
  1964       using c d mult_cancel_left[of "2 * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r" 0] by simp
  1988     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r =0" 
  1965     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + 2*?c*?d*?r =0" 
  1989       using nonzero_mult_divide_cancel_left [OF dc] c d
  1966       using nonzero_mult_divide_cancel_left [OF dc] c d
  1990       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  1967       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  1991     finally  have ?thesis using c d 
  1968     finally  have ?thesis using c d 
  1992       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubsteq_def Let_def evaldjf_ex field_simps)
  1969       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubsteq_def Let_def evaldjf_ex field_simps)
  1993       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  1970   }
  1994       apply (simp add: field_simps)
       
  1995       done }
       
  1996   ultimately show ?thesis by blast
  1971   ultimately show ?thesis by blast
  1997 qed
  1972 qed
  1998 
  1973 
  1999 
  1974 
  2000 definition "msubstneq c t d s a r = 
  1975 definition "msubstneq c t d s a r = 
  2014     using lp by (simp add: Let_def t s )
  1989     using lp by (simp add: Let_def t s )
  2015   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstneq_def)
  1990   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstneq_def)
  2016 qed
  1991 qed
  2017 
  1992 
  2018 lemma msubstneq: assumes lp: "islin (Eq (CNP 0 a r))"
  1993 lemma msubstneq: assumes lp: "islin (Eq (CNP 0 a r))"
  2019   shows "Ifm vs (x#bs) (msubstneq c t d s a r) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (NEq (CNP 0 a r))" (is "?lhs = ?rhs")
  1994   shows "Ifm vs (x#bs) (msubstneq c t d s a r) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /2)#bs) (NEq (CNP 0 a r))" (is "?lhs = ?rhs")
  2020 proof-
  1995 proof-
  2021   let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
  1996   let ?Nt = "\<lambda>(x::'a) t. Itm vs (x#bs) t"
  2022   let ?N = "\<lambda>p. Ipoly vs p"
  1997   let ?N = "\<lambda>p. Ipoly vs p"
  2023   let ?c = "?N c"
  1998   let ?c = "?N c"
  2024   let ?d = "?N d"
  1999   let ?d = "?N d"
  2032   moreover
  2007   moreover
  2033   {assume c: "?c = 0" and d: "?d=0"
  2008   {assume c: "?c = 0" and d: "?d=0"
  2034     hence ?thesis  by (simp add: r[of 0] msubstneq_def Let_def evaldjf_ex)}
  2009     hence ?thesis  by (simp add: r[of 0] msubstneq_def Let_def evaldjf_ex)}
  2035   moreover 
  2010   moreover 
  2036   {assume c: "?c = 0" and d: "?d\<noteq>0"
  2011   {assume c: "?c = 0" and d: "?d\<noteq>0"
  2037     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?s / ((1 + 1)*?d)" by simp
  2012     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = -?s / (2*?d)" by simp
  2038     have "?rhs = Ifm vs (-?s / ((1 + 1)*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2013     have "?rhs = Ifm vs (-?s / (2*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2039     also have "\<dots> \<longleftrightarrow> ?a * (-?s / ((1 + 1)*?d)) + ?r \<noteq> 0" by (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
  2014     also have "\<dots> \<longleftrightarrow> ?a * (-?s / (2*?d)) + ?r \<noteq> 0" by (simp add: r[of "- (Itm vs (x # bs) s / (2 * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"])
  2040     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a * (-?s / ((1 + 1)*?d)) + ?r) \<noteq> 0" 
  2015     also have "\<dots> \<longleftrightarrow> 2*?d * (?a * (-?s / (2*?d)) + ?r) \<noteq> 0" 
  2041       using d mult_cancel_left[of "(1 + 1)*?d" "(?a * (-?s / ((1 + 1)*?d)) + ?r)" 0] by simp
  2016       using d mult_cancel_left[of "2*?d" "(?a * (-?s / (2*?d)) + ?r)" 0] by simp
  2042     also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * ((1 + 1)*?d / ((1 + 1)*?d)) + (1 + 1)*?d*?r\<noteq> 0"
  2017     also have "\<dots> \<longleftrightarrow> (- ?a * ?s) * (2*?d / (2*?d)) + 2*?d*?r\<noteq> 0"
  2043       by (simp add: field_simps right_distrib[of "(1 + 1)*?d"] del: right_distrib)
  2018       by (simp add: field_simps right_distrib[of "2*?d"] del: right_distrib)
  2044     
  2019     
  2045     also have "\<dots> \<longleftrightarrow> - (?a * ?s) + (1 + 1)*?d*?r \<noteq> 0" using d by simp 
  2020     also have "\<dots> \<longleftrightarrow> - (?a * ?s) + 2*?d*?r \<noteq> 0" using d by simp 
  2046     finally have ?thesis using c d 
  2021     finally have ?thesis using c d 
  2047       apply (simp add: r[of "- (Itm vs (x # bs) s / ((1 + 1) * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
  2022       by (simp add: r[of "- (Itm vs (x # bs) s / (2 * \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
  2048       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2023   }
  2049       apply simp
       
  2050       done}
       
  2051   moreover
  2024   moreover
  2052   {assume c: "?c \<noteq> 0" and d: "?d=0"
  2025   {assume c: "?c \<noteq> 0" and d: "?d=0"
  2053     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = -?t / ((1 + 1)*?c)" by simp
  2026     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = -?t / (2*?c)" by simp
  2054     have "?rhs = Ifm vs (-?t / ((1 + 1)*?c) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2027     have "?rhs = Ifm vs (-?t / (2*?c) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2055     also have "\<dots> \<longleftrightarrow> ?a * (-?t / ((1 + 1)*?c)) + ?r \<noteq> 0" by (simp add: r[of "- (?t/ ((1 + 1)* ?c))"])
  2028     also have "\<dots> \<longleftrightarrow> ?a * (-?t / (2*?c)) + ?r \<noteq> 0" by (simp add: r[of "- (?t/ (2 * ?c))"])
  2056     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a * (-?t / ((1 + 1)*?c)) + ?r) \<noteq> 0" 
  2029     also have "\<dots> \<longleftrightarrow> 2*?c * (?a * (-?t / (2*?c)) + ?r) \<noteq> 0" 
  2057       using c mult_cancel_left[of "(1 + 1)*?c" "(?a * (-?t / ((1 + 1)*?c)) + ?r)" 0] by simp
  2030       using c mult_cancel_left[of "2*?c" "(?a * (-?t / (2*?c)) + ?r)" 0] by simp
  2058     also have "\<dots> \<longleftrightarrow> (?a * -?t)* ((1 + 1)*?c) / ((1 + 1)*?c) + (1 + 1)*?c*?r \<noteq> 0"
  2031     also have "\<dots> \<longleftrightarrow> (?a * -?t)* (2*?c) / (2*?c) + 2*?c*?r \<noteq> 0"
  2059       by (simp add: field_simps right_distrib[of "(1 + 1)*?c"] del: right_distrib)
  2032       by (simp add: field_simps right_distrib[of "2*?c"] del: right_distrib)
  2060     also have "\<dots> \<longleftrightarrow> - (?a * ?t) + (1 + 1)*?c*?r \<noteq> 0" using c by simp 
  2033     also have "\<dots> \<longleftrightarrow> - (?a * ?t) + 2*?c*?r \<noteq> 0" using c by simp 
  2061     finally have ?thesis using c d 
  2034     finally have ?thesis using c d 
  2062       apply (simp add: r[of "- (?t/ ((1 + 1)*?c))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
  2035       by (simp add: r[of "- (?t/ (2*?c))"] msubstneq_def Let_def evaldjf_ex del: one_add_one_is_two)
  2063       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2036   }
  2064       apply simp
  2037   moreover
  2065       done }
  2038   {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *2 \<noteq> 0" by simp
  2066   moreover
       
  2067   {assume c: "?c \<noteq> 0" and d: "?d\<noteq>0" hence dc: "?c * ?d *(1 + 1) \<noteq> 0" by simp
       
  2068     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2039     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2069     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  2040     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  2070       by (simp add: field_simps)
  2041       by (simp add: field_simps)
  2071     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2042     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (NEq (CNP 0 a r))" by (simp only: th)
  2072     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r \<noteq> 0" 
  2043     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r \<noteq> 0" 
  2073       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  2044       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  2074     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) \<noteq> 0 "
  2045     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) \<noteq> 0 "
  2075       using c d mult_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
  2046       using c d mult_cancel_left[of "2 * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r" 0] by simp
  2076     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r \<noteq> 0" 
  2047     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + 2*?c*?d*?r \<noteq> 0" 
  2077       using nonzero_mult_divide_cancel_left[OF dc] c d
  2048       using nonzero_mult_divide_cancel_left[OF dc] c d
  2078       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2049       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2079     finally  have ?thesis using c d 
  2050     finally  have ?thesis using c d 
  2080       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstneq_def Let_def evaldjf_ex field_simps)
  2051       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstneq_def Let_def evaldjf_ex field_simps)
  2081       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2052   }
  2082       apply (simp add: field_simps)
       
  2083       done }
       
  2084   ultimately show ?thesis by blast
  2053   ultimately show ?thesis by blast
  2085 qed
  2054 qed
  2086 
  2055 
  2087 definition "msubstlt c t d s a r = 
  2056 definition "msubstlt c t d s a r = 
  2088   evaldjf (split conj) 
  2057   evaldjf (split conj) 
  2109 qed
  2078 qed
  2110 
  2079 
  2111 
  2080 
  2112 lemma msubstlt: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Lt (CNP 0 a r))" 
  2081 lemma msubstlt: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Lt (CNP 0 a r))" 
  2113   shows "Ifm vs (x#bs) (msubstlt c t d s a r) \<longleftrightarrow> 
  2082   shows "Ifm vs (x#bs) (msubstlt c t d s a r) \<longleftrightarrow> 
  2114   Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Lt (CNP 0 a r))" (is "?lhs = ?rhs")
  2083   Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /2)#bs) (Lt (CNP 0 a r))" (is "?lhs = ?rhs")
  2115 proof-
  2084 proof-
  2116   let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
  2085   let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
  2117   let ?N = "\<lambda>p. Ipoly vs p"
  2086   let ?N = "\<lambda>p. Ipoly vs p"
  2118   let ?c = "?N c"
  2087   let ?c = "?N c"
  2119   let ?d = "?N d"
  2088   let ?d = "?N d"
  2127   moreover
  2096   moreover
  2128   {assume c: "?c=0" and d: "?d=0"
  2097   {assume c: "?c=0" and d: "?d=0"
  2129     hence ?thesis  using nc nd by (simp add: polyneg_norm lt r[of 0] msubstlt_def Let_def evaldjf_ex)}
  2098     hence ?thesis  using nc nd by (simp add: polyneg_norm lt r[of 0] msubstlt_def Let_def evaldjf_ex)}
  2130   moreover
  2099   moreover
  2131   {assume dc: "?c*?d > 0" 
  2100   {assume dc: "?c*?d > 0" 
  2132     from mult_pos_pos[OF one_plus_one_pos dc] have dc': "(1 + 1)*?c *?d > 0" by simp
  2101     from dc have dc': "2*?c *?d > 0" by simp
  2133     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2102     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2134     from dc' have dc'': "\<not> (1 + 1)*?c *?d < 0" by simp
  2103     from dc' have dc'': "\<not> 2*?c *?d < 0" by simp
  2135     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2104     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2136     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  2105     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  2137       by (simp add: field_simps)
  2106       by (simp add: field_simps)
  2138     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2107     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2139     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r < 0" 
  2108     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r < 0" 
  2140       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  2109       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  2141     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) < 0"
  2110     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) < 0"
  2142       
  2111       
  2143       using dc' dc'' mult_less_cancel_left_disj[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
  2112       using dc' dc'' mult_less_cancel_left_disj[of "2 * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r" 0] by simp
  2144     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r < 0" 
  2113     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + 2*?c*?d*?r < 0" 
  2145       using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
  2114       using nonzero_mult_divide_cancel_left[of "2*?c*?d"] c d
  2146       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2115       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2147     finally  have ?thesis using dc c d  nc nd dc'
  2116     finally  have ?thesis using dc c d  nc nd dc'
  2148       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2117       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2149     apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2118   }
  2150     by (simp add: field_simps order_less_not_sym[OF dc])}
       
  2151   moreover
  2119   moreover
  2152   {assume dc: "?c*?d < 0" 
  2120   {assume dc: "?c*?d < 0" 
  2153 
  2121 
  2154     from dc one_plus_one_pos[where ?'a='a] have dc': "(1 + 1)*?c *?d < 0"
  2122     from dc have dc': "2*?c *?d < 0"
  2155       by (simp add: mult_less_0_iff field_simps) 
  2123       by (simp add: mult_less_0_iff field_simps) 
  2156     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2124     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2157     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2125     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2158     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  2126     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  2159       by (simp add: field_simps)
  2127       by (simp add: field_simps)
  2160     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2128     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2161     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r < 0" 
  2129     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r < 0" 
  2162       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  2130       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  2163 
  2131 
  2164     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) > 0"
  2132     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) > 0"
  2165       
  2133       
  2166       using dc' order_less_not_sym[OF dc'] mult_less_cancel_left_disj[of "(1 + 1) * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r"] by simp
  2134       using dc' order_less_not_sym[OF dc'] mult_less_cancel_left_disj[of "2 * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r"] by simp
  2167     also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - (1 + 1)*?c*?d*?r < 0" 
  2135     also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - 2*?c*?d*?r < 0" 
  2168       using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
  2136       using nonzero_mult_divide_cancel_left[of "2*?c*?d"] c d
  2169       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2137       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2170     finally  have ?thesis using dc c d  nc nd
  2138     finally  have ?thesis using dc c d  nc nd
  2171       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2139       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2172       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2140   }
  2173       by (simp add: field_simps order_less_not_sym[OF dc]) }
       
  2174   moreover
  2141   moreover
  2175   {assume c: "?c > 0" and d: "?d=0"  
  2142   {assume c: "?c > 0" and d: "?d=0"  
  2176     from c have c'': "(1 + 1)*?c > 0" by (simp add: zero_less_mult_iff)
  2143     from c have c'': "2*?c > 0" by (simp add: zero_less_mult_iff)
  2177     from c have c': "(1 + 1)*?c \<noteq> 0" by simp
  2144     from c have c': "2*?c \<noteq> 0" by simp
  2178     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
  2145     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?t / (2*?c)"  by (simp add: field_simps)
  2179     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2146     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / (2*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2180     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r < 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
  2147     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / (2*?c))+ ?r < 0" by (simp add: r[of "- (?t / (2*?c))"])
  2181     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) < 0"
  2148     also have "\<dots> \<longleftrightarrow> 2*?c * (?a* (- ?t / (2*?c))+ ?r) < 0"
  2182       using c mult_less_cancel_left_disj[of "(1 + 1) * ?c" "?a* (- ?t / ((1 + 1)*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
  2149       using c mult_less_cancel_left_disj[of "2 * ?c" "?a* (- ?t / (2*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
  2183     also have "\<dots> \<longleftrightarrow> - ?a*?t+  (1 + 1)*?c *?r < 0" 
  2150     also have "\<dots> \<longleftrightarrow> - ?a*?t+  2*?c *?r < 0" 
  2184       using nonzero_mult_divide_cancel_left[OF c'] c
  2151       using nonzero_mult_divide_cancel_left[OF c'] c
  2185       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2152       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2186     finally have ?thesis using c d nc nd 
  2153     finally have ?thesis using c d nc nd 
  2187       apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2154       by(simp add: r[of "- (?t / (2*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2188       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2155   }
  2189       using c order_less_not_sym[OF c] less_imp_neq[OF c]
  2156   moreover
  2190       by (simp add: field_simps )  }
  2157   {assume c: "?c < 0" and d: "?d=0"  hence c': "2*?c \<noteq> 0" by simp
  2191   moreover
  2158     from c have c'': "2*?c < 0" by (simp add: mult_less_0_iff)
  2192   {assume c: "?c < 0" and d: "?d=0"  hence c': "(1 + 1)*?c \<noteq> 0" by simp
  2159     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?t / (2*?c)"  by (simp add: field_simps)
  2193     from c have c'': "(1 + 1)*?c < 0" by (simp add: mult_less_0_iff)
  2160     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / (2*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2194     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
  2161     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / (2*?c))+ ?r < 0" by (simp add: r[of "- (?t / (2*?c))"])
  2195     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2162     also have "\<dots> \<longleftrightarrow> 2*?c * (?a* (- ?t / (2*?c))+ ?r) > 0"
  2196     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r < 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
  2163       using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_less_cancel_left_disj[of "2 * ?c" 0 "?a* (- ?t / (2*?c))+ ?r"] by simp
  2197     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) > 0"
  2164     also have "\<dots> \<longleftrightarrow> ?a*?t -  2*?c *?r < 0" 
  2198       using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_less_cancel_left_disj[of "(1 + 1) * ?c" 0 "?a* (- ?t / ((1 + 1)*?c))+ ?r"] by simp
       
  2199     also have "\<dots> \<longleftrightarrow> ?a*?t -  (1 + 1)*?c *?r < 0" 
       
  2200       using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
  2165       using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
  2201         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2166         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2202     finally have ?thesis using c d nc nd 
  2167     finally have ?thesis using c d nc nd 
  2203       apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2168       by(simp add: r[of "- (?t / (2*?c))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2204       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2169   }
  2205       using c order_less_not_sym[OF c] less_imp_neq[OF c]
       
  2206       by (simp add: field_simps )    }
       
  2207   moreover
  2170   moreover
  2208   moreover
  2171   moreover
  2209   {assume c: "?c = 0" and d: "?d>0"  
  2172   {assume c: "?c = 0" and d: "?d>0"  
  2210     from d have d'': "(1 + 1)*?d > 0" by (simp add: zero_less_mult_iff)
  2173     from d have d'': "2*?d > 0" by (simp add: zero_less_mult_iff)
  2211     from d have d': "(1 + 1)*?d \<noteq> 0" by simp
  2174     from d have d': "2*?d \<noteq> 0" by simp
  2212     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
  2175     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?s / (2*?d)"  by (simp add: field_simps)
  2213     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2176     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / (2*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2214     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r < 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
  2177     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / (2*?d))+ ?r < 0" by (simp add: r[of "- (?s / (2*?d))"])
  2215     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) < 0"
  2178     also have "\<dots> \<longleftrightarrow> 2*?d * (?a* (- ?s / (2*?d))+ ?r) < 0"
  2216       using d mult_less_cancel_left_disj[of "(1 + 1) * ?d" "?a* (- ?s / ((1 + 1)*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
  2179       using d mult_less_cancel_left_disj[of "2 * ?d" "?a* (- ?s / (2*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
  2217     also have "\<dots> \<longleftrightarrow> - ?a*?s+  (1 + 1)*?d *?r < 0" 
  2180     also have "\<dots> \<longleftrightarrow> - ?a*?s+  2*?d *?r < 0" 
  2218       using nonzero_mult_divide_cancel_left[OF d'] d
  2181       using nonzero_mult_divide_cancel_left[OF d'] d
  2219       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2182       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2220     finally have ?thesis using c d nc nd 
  2183     finally have ?thesis using c d nc nd 
  2221       apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2184       by(simp add: r[of "- (?s / (2*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2222       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2185   }
  2223       using d order_less_not_sym[OF d] less_imp_neq[OF d]
  2186   moreover
  2224       by (simp add: field_simps)  }
  2187   {assume c: "?c = 0" and d: "?d<0"  hence d': "2*?d \<noteq> 0" by simp
  2225   moreover
  2188     from d have d'': "2*?d < 0" by (simp add: mult_less_0_iff)
  2226   {assume c: "?c = 0" and d: "?d<0"  hence d': "(1 + 1)*?d \<noteq> 0" by simp
  2189     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?s / (2*?d)"  by (simp add: field_simps)
  2227     from d have d'': "(1 + 1)*?d < 0" by (simp add: mult_less_0_iff)
  2190     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / (2*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2228     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
  2191     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / (2*?d))+ ?r < 0" by (simp add: r[of "- (?s / (2*?d))"])
  2229     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Lt (CNP 0 a r))" by (simp only: th)
  2192     also have "\<dots> \<longleftrightarrow> 2*?d * (?a* (- ?s / (2*?d))+ ?r) > 0"
  2230     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r < 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
  2193       using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_less_cancel_left_disj[of "2 * ?d" 0 "?a* (- ?s / (2*?d))+ ?r"] by simp
  2231     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) > 0"
  2194     also have "\<dots> \<longleftrightarrow> ?a*?s -  2*?d *?r < 0" 
  2232       using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_less_cancel_left_disj[of "(1 + 1) * ?d" 0 "?a* (- ?s / ((1 + 1)*?d))+ ?r"] by simp
       
  2233     also have "\<dots> \<longleftrightarrow> ?a*?s -  (1 + 1)*?d *?r < 0" 
       
  2234       using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
  2195       using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
  2235         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2196         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2236     finally have ?thesis using c d nc nd 
  2197     finally have ?thesis using c d nc nd 
  2237       apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2198       by(simp add: r[of "- (?s / (2*?d))"] msubstlt_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2238       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2199   }
  2239       using d order_less_not_sym[OF d] less_imp_neq[OF d]
       
  2240       by (simp add: field_simps )    }
       
  2241 ultimately show ?thesis by blast
  2200 ultimately show ?thesis by blast
  2242 qed
  2201 qed
  2243 
  2202 
  2244 definition "msubstle c t d s a r = 
  2203 definition "msubstle c t d s a r = 
  2245   evaldjf (split conj) 
  2204   evaldjf (split conj) 
  2265   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstle_def)
  2224   from evaldjf_bound0[OF th] show ?thesis by (simp add: msubstle_def)
  2266 qed
  2225 qed
  2267 
  2226 
  2268 lemma msubstle: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Le (CNP 0 a r))" 
  2227 lemma msubstle: assumes nc: "isnpoly c" and nd: "isnpoly d" and lp: "islin (Le (CNP 0 a r))" 
  2269   shows "Ifm vs (x#bs) (msubstle c t d s a r) \<longleftrightarrow> 
  2228   shows "Ifm vs (x#bs) (msubstle c t d s a r) \<longleftrightarrow> 
  2270   Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) (Le (CNP 0 a r))" (is "?lhs = ?rhs")
  2229   Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /2)#bs) (Le (CNP 0 a r))" (is "?lhs = ?rhs")
  2271 proof-
  2230 proof-
  2272   let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
  2231   let ?Nt = "\<lambda>x t. Itm vs (x#bs) t"
  2273   let ?N = "\<lambda>p. Ipoly vs p"
  2232   let ?N = "\<lambda>p. Ipoly vs p"
  2274   let ?c = "?N c"
  2233   let ?c = "?N c"
  2275   let ?d = "?N d"
  2234   let ?d = "?N d"
  2283   moreover
  2242   moreover
  2284   {assume c: "?c=0" and d: "?d=0"
  2243   {assume c: "?c=0" and d: "?d=0"
  2285     hence ?thesis  using nc nd by (simp add: polyneg_norm polymul_norm lt r[of 0] msubstle_def Let_def evaldjf_ex)}
  2244     hence ?thesis  using nc nd by (simp add: polyneg_norm polymul_norm lt r[of 0] msubstle_def Let_def evaldjf_ex)}
  2286   moreover
  2245   moreover
  2287   {assume dc: "?c*?d > 0" 
  2246   {assume dc: "?c*?d > 0" 
  2288     from mult_pos_pos[OF one_plus_one_pos dc] have dc': "(1 + 1)*?c *?d > 0" by simp
  2247     from dc have dc': "2*?c *?d > 0" by simp
  2289     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2248     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2290     from dc' have dc'': "\<not> (1 + 1)*?c *?d < 0" by simp
  2249     from dc' have dc'': "\<not> 2*?c *?d < 0" by simp
  2291     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2250     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2292     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  2251     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  2293       by (simp add: field_simps)
  2252       by (simp add: field_simps)
  2294     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2253     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2295     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r <= 0" 
  2254     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r <= 0" 
  2296       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  2255       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  2297     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) <= 0"
  2256     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) <= 0"
  2298       
  2257       
  2299       using dc' dc'' mult_le_cancel_left[of "(1 + 1) * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r" 0] by simp
  2258       using dc' dc'' mult_le_cancel_left[of "2 * ?c * ?d" "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r" 0] by simp
  2300     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + (1 + 1)*?c*?d*?r <= 0" 
  2259     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + 2*?c*?d*?r <= 0" 
  2301       using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
  2260       using nonzero_mult_divide_cancel_left[of "2*?c*?d"] c d
  2302       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2261       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2303     finally  have ?thesis using dc c d  nc nd dc'
  2262     finally  have ?thesis using dc c d  nc nd dc'
  2304       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2263       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2305     apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2264   }
  2306     by (simp add: field_simps order_less_not_sym[OF dc])}
       
  2307   moreover
  2265   moreover
  2308   {assume dc: "?c*?d < 0" 
  2266   {assume dc: "?c*?d < 0" 
  2309 
  2267 
  2310     from dc one_plus_one_pos[where ?'a='a] have dc': "(1 + 1)*?c *?d < 0"
  2268     from dc have dc': "2*?c *?d < 0"
  2311       by (simp add: mult_less_0_iff field_simps add_neg_neg add_pos_pos)
  2269       by (simp add: mult_less_0_iff field_simps add_neg_neg add_pos_pos)
  2312     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2270     hence c:"?c \<noteq> 0" and d: "?d\<noteq> 0" by auto
  2313     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2271     from add_frac_eq[OF c d, of "- ?t" "- ?s"]
  2314     have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)" 
  2272     have th: "(- ?t / ?c + - ?s / ?d)/2 = - (?d * ?t + ?c* ?s )/ (2*?c*?d)" 
  2315       by (simp add: field_simps)
  2273       by (simp add: field_simps)
  2316     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2274     have "?rhs \<longleftrightarrow> Ifm vs (- (?d * ?t + ?c* ?s )/ (2*?c*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2317     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r <= 0" 
  2275     also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r <= 0" 
  2318       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"])
  2276       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"])
  2319 
  2277 
  2320     also have "\<dots> \<longleftrightarrow> ((1 + 1) * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ ((1 + 1)*?c*?d)) + ?r) >= 0"
  2278     also have "\<dots> \<longleftrightarrow> (2 * ?c * ?d) * (?a * (- (?d * ?t + ?c* ?s )/ (2*?c*?d)) + ?r) >= 0"
  2321       
  2279       
  2322       using dc' order_less_not_sym[OF dc'] mult_le_cancel_left[of "(1 + 1) * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ ((1 + 1)*?c*?d)) + ?r"] by simp
  2280       using dc' order_less_not_sym[OF dc'] mult_le_cancel_left[of "2 * ?c * ?d" 0 "?a * (- (?d * ?t + ?c* ?s)/ (2*?c*?d)) + ?r"] by simp
  2323     also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - (1 + 1)*?c*?d*?r <= 0" 
  2281     also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - 2*?c*?d*?r <= 0" 
  2324       using nonzero_mult_divide_cancel_left[of "(1 + 1)*?c*?d"] c d
  2282       using nonzero_mult_divide_cancel_left[of "2*?c*?d"] c d
  2325       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2283       by (simp add: algebra_simps diff_divide_distrib del: left_distrib)
  2326     finally  have ?thesis using dc c d  nc nd
  2284     finally  have ?thesis using dc c d  nc nd
  2327       apply (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / ((1 + 1) * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2285       by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm) 
  2328       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2286   }
  2329       by (simp add: field_simps order_less_not_sym[OF dc]) }
       
  2330   moreover
  2287   moreover
  2331   {assume c: "?c > 0" and d: "?d=0"  
  2288   {assume c: "?c > 0" and d: "?d=0"  
  2332     from c have c'': "(1 + 1)*?c > 0" by (simp add: zero_less_mult_iff)
  2289     from c have c'': "2*?c > 0" by (simp add: zero_less_mult_iff)
  2333     from c have c': "(1 + 1)*?c \<noteq> 0" by simp
  2290     from c have c': "2*?c \<noteq> 0" by simp
  2334     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
  2291     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?t / (2*?c)"  by (simp add: field_simps)
  2335     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2292     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / (2*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2336     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r <= 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
  2293     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / (2*?c))+ ?r <= 0" by (simp add: r[of "- (?t / (2*?c))"])
  2337     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) <= 0"
  2294     also have "\<dots> \<longleftrightarrow> 2*?c * (?a* (- ?t / (2*?c))+ ?r) <= 0"
  2338       using c mult_le_cancel_left[of "(1 + 1) * ?c" "?a* (- ?t / ((1 + 1)*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
  2295       using c mult_le_cancel_left[of "2 * ?c" "?a* (- ?t / (2*?c))+ ?r" 0] c' c'' order_less_not_sym[OF c''] by simp
  2339     also have "\<dots> \<longleftrightarrow> - ?a*?t+  (1 + 1)*?c *?r <= 0" 
  2296     also have "\<dots> \<longleftrightarrow> - ?a*?t+  2*?c *?r <= 0" 
  2340       using nonzero_mult_divide_cancel_left[OF c'] c
  2297       using nonzero_mult_divide_cancel_left[OF c'] c
  2341       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2298       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2342     finally have ?thesis using c d nc nd 
  2299     finally have ?thesis using c d nc nd 
  2343       apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2300       by(simp add: r[of "- (?t / (2*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2344       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2301   }
  2345       using c order_less_not_sym[OF c] less_imp_neq[OF c]
  2302   moreover
  2346       by (simp add: field_simps )  }
  2303   {assume c: "?c < 0" and d: "?d=0"  hence c': "2*?c \<noteq> 0" by simp
  2347   moreover
  2304     from c have c'': "2*?c < 0" by (simp add: mult_less_0_iff)
  2348   {assume c: "?c < 0" and d: "?d=0"  hence c': "(1 + 1)*?c \<noteq> 0" by simp
  2305     from d have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?t / (2*?c)"  by (simp add: field_simps)
  2349     from c have c'': "(1 + 1)*?c < 0" by (simp add: mult_less_0_iff)
  2306     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / (2*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2350     from d have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?t / ((1 + 1)*?c)"  by (simp add: field_simps)
  2307     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / (2*?c))+ ?r <= 0" by (simp add: r[of "- (?t / (2*?c))"])
  2351     have "?rhs \<longleftrightarrow> Ifm vs (- ?t / ((1 + 1)*?c) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2308     also have "\<dots> \<longleftrightarrow> 2*?c * (?a* (- ?t / (2*?c))+ ?r) >= 0"
  2352     also have "\<dots> \<longleftrightarrow> ?a* (- ?t / ((1 + 1)*?c))+ ?r <= 0" by (simp add: r[of "- (?t / ((1 + 1)*?c))"])
  2309       using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_le_cancel_left[of "2 * ?c" 0 "?a* (- ?t / (2*?c))+ ?r"] by simp
  2353     also have "\<dots> \<longleftrightarrow> (1 + 1)*?c * (?a* (- ?t / ((1 + 1)*?c))+ ?r) >= 0"
  2310     also have "\<dots> \<longleftrightarrow> ?a*?t -  2*?c *?r <= 0" 
  2354       using c order_less_not_sym[OF c''] less_imp_neq[OF c''] c'' mult_le_cancel_left[of "(1 + 1) * ?c" 0 "?a* (- ?t / ((1 + 1)*?c))+ ?r"] by simp
       
  2355     also have "\<dots> \<longleftrightarrow> ?a*?t -  (1 + 1)*?c *?r <= 0" 
       
  2356       using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
  2311       using nonzero_mult_divide_cancel_left[OF c'] c order_less_not_sym[OF c''] less_imp_neq[OF c''] c''
  2357         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2312         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2358     finally have ?thesis using c d nc nd 
  2313     finally have ?thesis using c d nc nd 
  2359       apply(simp add: r[of "- (?t / ((1 + 1)*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2314       by(simp add: r[of "- (?t / (2*?c))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2360       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2315   }
  2361       using c order_less_not_sym[OF c] less_imp_neq[OF c]
       
  2362       by (simp add: field_simps )    }
       
  2363   moreover
  2316   moreover
  2364   moreover
  2317   moreover
  2365   {assume c: "?c = 0" and d: "?d>0"  
  2318   {assume c: "?c = 0" and d: "?d>0"  
  2366     from d have d'': "(1 + 1)*?d > 0" by (simp add: zero_less_mult_iff)
  2319     from d have d'': "2*?d > 0" by (simp add: zero_less_mult_iff)
  2367     from d have d': "(1 + 1)*?d \<noteq> 0" by simp
  2320     from d have d': "2*?d \<noteq> 0" by simp
  2368     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
  2321     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?s / (2*?d)"  by (simp add: field_simps)
  2369     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2322     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / (2*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2370     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r <= 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
  2323     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / (2*?d))+ ?r <= 0" by (simp add: r[of "- (?s / (2*?d))"])
  2371     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) <= 0"
  2324     also have "\<dots> \<longleftrightarrow> 2*?d * (?a* (- ?s / (2*?d))+ ?r) <= 0"
  2372       using d mult_le_cancel_left[of "(1 + 1) * ?d" "?a* (- ?s / ((1 + 1)*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
  2325       using d mult_le_cancel_left[of "2 * ?d" "?a* (- ?s / (2*?d))+ ?r" 0] d' d'' order_less_not_sym[OF d''] by simp
  2373     also have "\<dots> \<longleftrightarrow> - ?a*?s+  (1 + 1)*?d *?r <= 0" 
  2326     also have "\<dots> \<longleftrightarrow> - ?a*?s+  2*?d *?r <= 0" 
  2374       using nonzero_mult_divide_cancel_left[OF d'] d
  2327       using nonzero_mult_divide_cancel_left[OF d'] d
  2375       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2328       by (simp add: algebra_simps diff_divide_distrib less_le del: left_distrib)
  2376     finally have ?thesis using c d nc nd 
  2329     finally have ?thesis using c d nc nd 
  2377       apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2330       by(simp add: r[of "- (?s / (2*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2378       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2331   }
  2379       using d order_less_not_sym[OF d] less_imp_neq[OF d]
  2332   moreover
  2380       by (simp add: field_simps )  }
  2333   {assume c: "?c = 0" and d: "?d<0"  hence d': "2*?d \<noteq> 0" by simp
  2381   moreover
  2334     from d have d'': "2*?d < 0" by (simp add: mult_less_0_iff)
  2382   {assume c: "?c = 0" and d: "?d<0"  hence d': "(1 + 1)*?d \<noteq> 0" by simp
  2335     from c have th: "(- ?t / ?c + - ?s / ?d)/2 = - ?s / (2*?d)"  by (simp add: field_simps)
  2383     from d have d'': "(1 + 1)*?d < 0" by (simp add: mult_less_0_iff)
  2336     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / (2*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2384     from c have th: "(- ?t / ?c + - ?s / ?d)/(1 + 1) = - ?s / ((1 + 1)*?d)"  by (simp add: field_simps)
  2337     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / (2*?d))+ ?r <= 0" by (simp add: r[of "- (?s / (2*?d))"])
  2385     have "?rhs \<longleftrightarrow> Ifm vs (- ?s / ((1 + 1)*?d) # bs) (Le (CNP 0 a r))" by (simp only: th)
  2338     also have "\<dots> \<longleftrightarrow> 2*?d * (?a* (- ?s / (2*?d))+ ?r) >= 0"
  2386     also have "\<dots> \<longleftrightarrow> ?a* (- ?s / ((1 + 1)*?d))+ ?r <= 0" by (simp add: r[of "- (?s / ((1 + 1)*?d))"])
  2339       using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_le_cancel_left[of "2 * ?d" 0 "?a* (- ?s / (2*?d))+ ?r"] by simp
  2387     also have "\<dots> \<longleftrightarrow> (1 + 1)*?d * (?a* (- ?s / ((1 + 1)*?d))+ ?r) >= 0"
  2340     also have "\<dots> \<longleftrightarrow> ?a*?s -  2*?d *?r <= 0" 
  2388       using d order_less_not_sym[OF d''] less_imp_neq[OF d''] d'' mult_le_cancel_left[of "(1 + 1) * ?d" 0 "?a* (- ?s / ((1 + 1)*?d))+ ?r"] by simp
       
  2389     also have "\<dots> \<longleftrightarrow> ?a*?s -  (1 + 1)*?d *?r <= 0" 
       
  2390       using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
  2341       using nonzero_mult_divide_cancel_left[OF d'] d order_less_not_sym[OF d''] less_imp_neq[OF d''] d''
  2391         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2342         by (simp add: algebra_simps diff_divide_distrib del:  left_distrib)
  2392     finally have ?thesis using c d nc nd 
  2343     finally have ?thesis using c d nc nd 
  2393       apply(simp add: r[of "- (?s / ((1 + 1)*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2344       by(simp add: r[of "- (?s / (2*?d))"] msubstle_def Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  2394       apply (simp only: one_add_one_is_two[symmetric] of_int_add)
  2345   }
  2395       using d order_less_not_sym[OF d] less_imp_neq[OF d]
       
  2396       by (simp add: field_simps )    }
       
  2397 ultimately show ?thesis by blast
  2346 ultimately show ?thesis by blast
  2398 qed
  2347 qed
  2399 
  2348 
  2400 
  2349 
  2401 fun msubst :: "fm \<Rightarrow> (poly \<times> tm) \<times> (poly \<times> tm) \<Rightarrow> fm" where
  2350 fun msubst :: "fm \<Rightarrow> (poly \<times> tm) \<times> (poly \<times> tm) \<Rightarrow> fm" where
  2406 | "msubst (Lt (CNP 0 a r)) ((c,t),(d,s)) = msubstlt c t d s a r"
  2355 | "msubst (Lt (CNP 0 a r)) ((c,t),(d,s)) = msubstlt c t d s a r"
  2407 | "msubst (Le (CNP 0 a r)) ((c,t),(d,s)) = msubstle c t d s a r"
  2356 | "msubst (Le (CNP 0 a r)) ((c,t),(d,s)) = msubstle c t d s a r"
  2408 | "msubst p ((c,t),(d,s)) = p"
  2357 | "msubst p ((c,t),(d,s)) = p"
  2409 
  2358 
  2410 lemma msubst_I: assumes lp: "islin p" and nc: "isnpoly c" and nd: "isnpoly d"
  2359 lemma msubst_I: assumes lp: "islin p" and nc: "isnpoly c" and nd: "isnpoly d"
  2411   shows "Ifm vs (x#bs) (msubst p ((c,t),(d,s))) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /(1 + 1))#bs) p"
  2360   shows "Ifm vs (x#bs) (msubst p ((c,t),(d,s))) = Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs c + - Itm vs (x#bs) s / Ipoly vs d) /2)#bs) p"
  2412   using lp
  2361   using lp
  2413 by (induct p rule: islin.induct, auto simp add: tmbound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) /(1 + 1)" and b'=x and bs = bs and vs=vs] bound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) /(1 + 1)" and b'=x and bs = bs and vs=vs] msubsteq msubstneq msubstlt[OF nc nd] msubstle[OF nc nd])
  2362 by (induct p rule: islin.induct, auto simp add: tmbound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) / 2" and b'=x and bs = bs and vs=vs] bound0_I[where b="(- (Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>) + - (Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>)) / 2" and b'=x and bs = bs and vs=vs] msubsteq msubstneq msubstlt[OF nc nd] msubstle[OF nc nd])
  2414 
  2363 
  2415 lemma msubst_nb: assumes lp: "islin p" and t: "tmbound0 t" and s: "tmbound0 s"
  2364 lemma msubst_nb: assumes lp: "islin p" and t: "tmbound0 t" and s: "tmbound0 s"
  2416   shows "bound0 (msubst p ((c,t),(d,s)))"
  2365   shows "bound0 (msubst p ((c,t),(d,s)))"
  2417   using lp t s
  2366   using lp t s
  2418   by (induct p rule: islin.induct, auto simp add: msubsteq_nb msubstneq_nb msubstlt_nb msubstle_nb)
  2367   by (induct p rule: islin.induct, auto simp add: msubsteq_nb msubstneq_nb msubstlt_nb msubstle_nb)
  2422   shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst p ((c,t),(d,s)))))"
  2371   shows "(\<exists> x. Ifm vs (x#bs) p) = ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> (\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst p ((c,t),(d,s)))))"
  2423   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
  2372   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
  2424 proof-
  2373 proof-
  2425 from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
  2374 from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
  2426 {fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
  2375 {fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
  2427   and pts: "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p"
  2376   and pts: "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p"
  2428   from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
  2377   from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
  2429   from msubst_I[OF lp norm, of vs x bs t s] pts
  2378   from msubst_I[OF lp norm, of vs x bs t s] pts
  2430   have "Ifm vs (x # bs) (msubst p ((c, t), d, s))" ..}
  2379   have "Ifm vs (x # bs) (msubst p ((c, t), d, s))" ..}
  2431 moreover
  2380 moreover
  2432 {fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
  2381 {fix c t d s assume ctU: "(c,t) \<in>set (uset p)" and dsU: "(d,s) \<in>set (uset p)" 
  2433   and pts: "Ifm vs (x # bs) (msubst p ((c, t), d, s))"
  2382   and pts: "Ifm vs (x # bs) (msubst p ((c, t), d, s))"
  2434   from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
  2383   from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d" by simp_all
  2435   from msubst_I[OF lp norm, of vs x bs t s] pts
  2384   from msubst_I[OF lp norm, of vs x bs t s] pts
  2436   have "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p" ..}
  2385   have "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p" ..}
  2437 ultimately have th': "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1+1) # bs) p) \<longleftrightarrow> ?F" by blast
  2386 ultimately have th': "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p) \<longleftrightarrow> ?F" by blast
  2438 from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
  2387 from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
  2439 qed 
  2388 qed 
  2440 
  2389 
  2441 lemma simpfm_lin:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
  2390 lemma simpfm_lin:   assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
  2442   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  2391   shows "qfree p \<Longrightarrow> islin (simpfm p)"
  2508 
  2457 
  2509 lemma fr_eq2:  assumes lp: "islin p"
  2458 lemma fr_eq2:  assumes lp: "islin p"
  2510   shows "(\<exists> x. Ifm vs (x#bs) p) \<longleftrightarrow> 
  2459   shows "(\<exists> x. Ifm vs (x#bs) p) \<longleftrightarrow> 
  2511    ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> 
  2460    ((Ifm vs (x#bs) (minusinf p)) \<or> (Ifm vs (x#bs) (plusinf p)) \<or> 
  2512     (Ifm vs (0#bs) p) \<or> 
  2461     (Ifm vs (0#bs) p) \<or> 
  2513     (\<exists> (n,t) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ifm vs ((- Itm vs (x#bs) t /  (Ipoly vs n * (1 + 1)))#bs) p) \<or> 
  2462     (\<exists> (n,t) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ifm vs ((- Itm vs (x#bs) t /  (Ipoly vs n * 2))#bs) p) \<or> 
  2514     (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ipoly vs m \<noteq> 0 \<and> Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) /(1 + 1))#bs) p))"
  2463     (\<exists> (n,t) \<in> set (uset p). \<exists> (m,s) \<in> set (uset p). Ipoly vs n \<noteq> 0 \<and> Ipoly vs m \<noteq> 0 \<and> Ifm vs (((- Itm vs (x#bs) t /  Ipoly vs n + - Itm vs (x#bs) s / Ipoly vs m) /2)#bs) p))"
  2515   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?Z \<or> ?U \<or> ?F)" is "?E = ?D")
  2464   (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?Z \<or> ?U \<or> ?F)" is "?E = ?D")
  2516 proof
  2465 proof
  2517   assume px: "\<exists> x. ?I x p"
  2466   assume px: "\<exists> x. ?I x p"
  2518   have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
  2467   have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
  2519   moreover {assume "?M \<or> ?P" hence "?D" by blast}
  2468   moreover {assume "?M \<or> ?P" hence "?D" by blast}
  2523       by auto
  2472       by auto
  2524     let ?c = "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
  2473     let ?c = "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
  2525     let ?d = "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
  2474     let ?d = "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>"
  2526     let ?s = "Itm vs (x # bs) s"
  2475     let ?s = "Itm vs (x # bs) s"
  2527     let ?t = "Itm vs (x # bs) t"
  2476     let ?t = "Itm vs (x # bs) t"
  2528     have eq2: "\<And>(x::'a). x + x = (1 + 1) * x"
  2477     have eq2: "\<And>(x::'a). x + x = 2 * x"
  2529       by  (simp add: field_simps)
  2478       by  (simp add: field_simps)
  2530     {assume "?c = 0 \<and> ?d = 0"
  2479     {assume "?c = 0 \<and> ?d = 0"
  2531       with ct have ?D by simp}
  2480       with ct have ?D by simp}
  2532     moreover
  2481     moreover
  2533     {assume z: "?c = 0" "?d \<noteq> 0"
  2482     {assume z: "?c = 0" "?d \<noteq> 0"
  2664 
  2613 
  2665 lemma msubst2_nb: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" and lp: "islin p" and tnb: "tmbound0 t"
  2614 lemma msubst2_nb: assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})" and lp: "islin p" and tnb: "tmbound0 t"
  2666   shows "bound0 (msubst2 p c t)"
  2615   shows "bound0 (msubst2 p c t)"
  2667 using lp tnb
  2616 using lp tnb
  2668 by (simp add: msubst2_def msubstneg_nb msubstpos_nb conj_nb disj_nb lt_nb simpfm_bound0)
  2617 by (simp add: msubst2_def msubstneg_nb msubstpos_nb conj_nb disj_nb lt_nb simpfm_bound0)
  2669     
  2618 
  2670 lemma of_int2: "of_int 2 = 1 + 1"
  2619 lemma mult_minus2_left: "-2 * (x::'a::number_ring) = - (2 * x)"
  2671 proof-
  2620   by simp
  2672   have "(2::int) = 1 + 1" by simp
  2621 
  2673   hence "of_int 2 = of_int (1 + 1)" by simp
  2622 lemma mult_minus2_right: "(x::'a::number_ring) * -2 = - (x * 2)"
  2674   thus ?thesis unfolding of_int_add by simp
  2623   by simp
  2675 qed
       
  2676 
       
  2677 lemma of_int_minus2: "of_int (-2) = - (1 + 1)"
       
  2678 proof-
       
  2679   have th: "(-2::int) = - 2" by simp
       
  2680   show ?thesis unfolding th by (simp only: of_int_minus of_int2)
       
  2681 qed
       
  2682 
       
  2683 
  2624 
  2684 lemma islin_qf: "islin p \<Longrightarrow> qfree p"
  2625 lemma islin_qf: "islin p \<Longrightarrow> qfree p"
  2685   by (induct p rule: islin.induct, auto simp add: bound0_qf)
  2626   by (induct p rule: islin.induct, auto simp add: bound0_qf)
  2686 lemma fr_eq_msubst2: 
  2627 lemma fr_eq_msubst2: 
  2687   assumes lp: "islin p"
  2628   assumes lp: "islin p"
  2691   from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
  2632   from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s" by blast
  2692   let ?I = "\<lambda>p. Ifm vs (x#bs) p"
  2633   let ?I = "\<lambda>p. Ifm vs (x#bs) p"
  2693   have n2: "isnpoly (C (-2,1))" by (simp add: isnpoly_def)
  2634   have n2: "isnpoly (C (-2,1))" by (simp add: isnpoly_def)
  2694   note eq0 = subst0[OF islin_qf[OF lp], of vs x bs "CP 0\<^sub>p", simplified]
  2635   note eq0 = subst0[OF islin_qf[OF lp], of vs x bs "CP 0\<^sub>p", simplified]
  2695   
  2636   
  2696   have eq1: "(\<exists>(n, t)\<in>set (uset p). ?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p)"
  2637   have eq1: "(\<exists>(n, t)\<in>set (uset p). ?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * 2) # bs) p)"
  2697   proof-
  2638   proof-
  2698     {fix n t assume H: "(n, t)\<in>set (uset p)" "?I(msubst2 p (n *\<^sub>p C (-2, 1)) t)"
  2639     {fix n t assume H: "(n, t)\<in>set (uset p)" "?I(msubst2 p (n *\<^sub>p C (-2, 1)) t)"
  2699       from H(1) th have "isnpoly n" by blast
  2640       from H(1) th have "isnpoly n" by blast
  2700       hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" by (simp_all add: polymul_norm n2)
  2641       hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" by (simp_all add: polymul_norm n2)
  2701       have nn': "allpolys isnpoly (CP (~\<^sub>p (n *\<^sub>p C (-2, 1))))"
  2642       have nn': "allpolys isnpoly (CP (~\<^sub>p (n *\<^sub>p C (-2, 1))))"
  2702         by (simp add: polyneg_norm nn)
  2643         by (simp add: polyneg_norm nn)
  2703       hence nn2: "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>n \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" using H(2) nn' nn 
  2644       hence nn2: "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>n \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" using H(2) nn' nn 
  2704         by (auto simp add: msubst2_def lt zero_less_mult_iff mult_less_0_iff)
  2645         by (auto simp add: msubst2_def lt zero_less_mult_iff mult_less_0_iff)
  2705       from msubst2[OF lp nn nn2(1), of x bs t]
  2646       from msubst2[OF lp nn nn2(1), of x bs t]
  2706       have "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p"
  2647       have "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * 2) # bs) p"
  2707         using H(2) nn2 by (simp add: of_int_minus2 del: minus_add_distrib)}
  2648         using H(2) nn2 by (simp add: mult_minus2_right)}
  2708     moreover
  2649     moreover
  2709     {fix n t assume H: "(n, t)\<in>set (uset p)" "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * (1 + 1)) # bs) p"
  2650     {fix n t assume H: "(n, t)\<in>set (uset p)" "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * 2) # bs) p"
  2710       from H(1) th have "isnpoly n" by blast
  2651       from H(1) th have "isnpoly n" by blast
  2711       hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2652       hence nn: "isnpoly (n *\<^sub>p (C (-2,1)))" "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2712         using H(2) by (simp_all add: polymul_norm n2)
  2653         using H(2) by (simp_all add: polymul_norm n2)
  2713       from msubst2[OF lp nn, of x bs t] have "?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)" using H(2,3) by (simp add: of_int_minus2 del: minus_add_distrib)}
  2654       from msubst2[OF lp nn, of x bs t] have "?I (msubst2 p (n *\<^sub>p (C (-2,1))) t)" using H(2,3) by (simp add: mult_minus2_right)}
  2714     ultimately show ?thesis by blast
  2655     ultimately show ?thesis by blast
  2715   qed
  2656   qed
  2716   have eq2: "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p).
  2657   have eq2: "(\<exists> (c,t) \<in> set (uset p). \<exists> (d,s) \<in> set (uset p). Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))) \<longleftrightarrow> (\<exists>(n, t)\<in>set (uset p).
  2717      \<exists>(m, s)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p)" 
  2658      \<exists>(m, s)\<in>set (uset p). \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>m\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p)" 
  2718   proof-
  2659   proof-
  2719     {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
  2660     {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
  2720      "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))"
  2661      "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))"
  2721       from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
  2662       from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
  2722       hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" 
  2663       hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" 
  2724       have stupid: "allpolys isnpoly (CP (~\<^sub>p (C (-2, 1) *\<^sub>p c *\<^sub>p d)))" "allpolys isnpoly (CP ((C (-2, 1) *\<^sub>p c *\<^sub>p d)))"
  2665       have stupid: "allpolys isnpoly (CP (~\<^sub>p (C (-2, 1) *\<^sub>p c *\<^sub>p d)))" "allpolys isnpoly (CP ((C (-2, 1) *\<^sub>p c *\<^sub>p d)))"
  2725         by (simp_all add: polyneg_norm nn)
  2666         by (simp_all add: polyneg_norm nn)
  2726       have nn': "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2667       have nn': "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2727         using H(3) by (auto simp add: msubst2_def lt[OF stupid(1)]  lt[OF stupid(2)] zero_less_mult_iff mult_less_0_iff)
  2668         using H(3) by (auto simp add: msubst2_def lt[OF stupid(1)]  lt[OF stupid(2)] zero_less_mult_iff mult_less_0_iff)
  2728       from msubst2[OF lp nn nn'(1), of x bs ] H(3) nn'
  2669       from msubst2[OF lp nn nn'(1), of x bs ] H(3) nn'
  2729       have "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p" 
  2670       have "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0 \<and> Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p"
  2730         apply (simp add: add_divide_distrib of_int_minus2 del: minus_add_distrib)
  2671         apply (simp add: add_divide_distrib mult_minus2_left)
  2731         by (simp add: mult_commute)}
  2672         by (simp add: mult_commute)}
  2732     moreover
  2673     moreover
  2733     {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
  2674     {fix c t d s assume H: "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)" 
  2734       "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / (1 + 1) # bs) p"
  2675       "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0" "Ifm vs ((- Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> + - Itm vs (x # bs) s / \<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup>) / 2 # bs) p"
  2735      from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
  2676      from H(1,2) th have "isnpoly c" "isnpoly d" by blast+
  2736       hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2677       hence nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)" "\<lparr>(C (-2, 1) *\<^sub>p c*\<^sub>p d)\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  2737         using H(3,4) by (simp_all add: polymul_norm n2)
  2678         using H(3,4) by (simp_all add: polymul_norm n2)
  2738       from msubst2[OF lp nn, of x bs ] H(3,4,5) 
  2679       from msubst2[OF lp nn, of x bs ] H(3,4,5) 
  2739       have "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))" apply (simp add: add_divide_distrib of_int_minus2 del: minus_add_distrib)by (simp add: mult_commute)}
  2680       have "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))" apply (simp add: add_divide_distrib mult_minus2_left) by (simp add: mult_commute)}
  2740     ultimately show ?thesis by blast
  2681     ultimately show ?thesis by blast
  2741   qed
  2682   qed
  2742   from fr_eq2[OF lp, of vs bs x] show ?thesis
  2683   from fr_eq2[OF lp, of vs bs x] show ?thesis
  2743     unfolding eq0 eq1 eq2 by blast  
  2684     unfolding eq0 eq1 eq2 by blast  
  2744 qed
  2685 qed