src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy
changeset 52803 bcaa5bbf7e6b
parent 52658 1e7896c7f781
child 53374 a14d2a854c02
     1.1 --- a/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Tue Jul 30 22:43:11 2013 +0200
     1.2 +++ b/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Tue Jul 30 23:16:17 2013 +0200
     1.3 @@ -8,7 +8,7 @@
     1.4  imports Complex_Main "~~/src/HOL/Library/Abstract_Rat" Polynomial_List
     1.5  begin
     1.6  
     1.7 -subsection{* Datatype of polynomial expressions *} 
     1.8 +subsection{* Datatype of polynomial expressions *}
     1.9  
    1.10  datatype poly = C Num| Bound nat| Add poly poly|Sub poly poly
    1.11    | Mul poly poly| Neg poly| Pw poly nat| CN poly nat poly
    1.12 @@ -36,7 +36,7 @@
    1.13  | "polybound0 (Bound n) = (n>0)"
    1.14  | "polybound0 (Neg a) = polybound0 a"
    1.15  | "polybound0 (Add a b) = (polybound0 a \<and> polybound0 b)"
    1.16 -| "polybound0 (Sub a b) = (polybound0 a \<and> polybound0 b)" 
    1.17 +| "polybound0 (Sub a b) = (polybound0 a \<and> polybound0 b)"
    1.18  | "polybound0 (Mul a b) = (polybound0 a \<and> polybound0 b)"
    1.19  | "polybound0 (Pw p n) = (polybound0 p)"
    1.20  | "polybound0 (CN c n p) = (n \<noteq> 0 \<and> polybound0 c \<and> polybound0 p)"
    1.21 @@ -47,13 +47,13 @@
    1.22  | "polysubst0 t (Bound n) = (if n=0 then t else Bound n)"
    1.23  | "polysubst0 t (Neg a) = Neg (polysubst0 t a)"
    1.24  | "polysubst0 t (Add a b) = Add (polysubst0 t a) (polysubst0 t b)"
    1.25 -| "polysubst0 t (Sub a b) = Sub (polysubst0 t a) (polysubst0 t b)" 
    1.26 +| "polysubst0 t (Sub a b) = Sub (polysubst0 t a) (polysubst0 t b)"
    1.27  | "polysubst0 t (Mul a b) = Mul (polysubst0 t a) (polysubst0 t b)"
    1.28  | "polysubst0 t (Pw p n) = Pw (polysubst0 t p) n"
    1.29  | "polysubst0 t (CN c n p) = (if n=0 then Add (polysubst0 t c) (Mul t (polysubst0 t p))
    1.30                               else CN (polysubst0 t c) n (polysubst0 t p))"
    1.31  
    1.32 -fun decrpoly:: "poly \<Rightarrow> poly" 
    1.33 +fun decrpoly:: "poly \<Rightarrow> poly"
    1.34  where
    1.35    "decrpoly (Bound n) = Bound (n - 1)"
    1.36  | "decrpoly (Neg a) = Neg (decrpoly a)"
    1.37 @@ -117,12 +117,12 @@
    1.38  fun polyadd :: "poly \<Rightarrow> poly \<Rightarrow> poly" (infixl "+\<^sub>p" 60)
    1.39  where
    1.40    "polyadd (C c) (C c') = C (c+\<^sub>Nc')"
    1.41 -|  "polyadd (C c) (CN c' n' p') = CN (polyadd (C c) c') n' p'"
    1.42 +| "polyadd (C c) (CN c' n' p') = CN (polyadd (C c) c') n' p'"
    1.43  | "polyadd (CN c n p) (C c') = CN (polyadd c (C c')) n p"
    1.44  | "polyadd (CN c n p) (CN c' n' p') =
    1.45      (if n < n' then CN (polyadd c (CN c' n' p')) n p
    1.46       else if n'<n then CN (polyadd (CN c n p) c') n' p'
    1.47 -     else (let cc' = polyadd c c' ; 
    1.48 +     else (let cc' = polyadd c c' ;
    1.49                 pp' = polyadd p p'
    1.50             in (if pp' = 0\<^sub>p then cc' else CN cc' n pp')))"
    1.51  | "polyadd a b = Add a b"
    1.52 @@ -140,13 +140,13 @@
    1.53  fun polymul :: "poly \<Rightarrow> poly \<Rightarrow> poly" (infixl "*\<^sub>p" 60)
    1.54  where
    1.55    "polymul (C c) (C c') = C (c*\<^sub>Nc')"
    1.56 -| "polymul (C c) (CN c' n' p') = 
    1.57 +| "polymul (C c) (CN c' n' p') =
    1.58        (if c = 0\<^sub>N then 0\<^sub>p else CN (polymul (C c) c') n' (polymul (C c) p'))"
    1.59 -| "polymul (CN c n p) (C c') = 
    1.60 +| "polymul (CN c n p) (C c') =
    1.61        (if c' = 0\<^sub>N  then 0\<^sub>p else CN (polymul c (C c')) n (polymul p (C c')))"
    1.62 -| "polymul (CN c n p) (CN c' n' p') = 
    1.63 +| "polymul (CN c n p) (CN c' n' p') =
    1.64    (if n<n' then CN (polymul c (CN c' n' p')) n (polymul p (CN c' n' p'))
    1.65 -  else if n' < n 
    1.66 +  else if n' < n
    1.67    then CN (polymul (CN c n p) c') n' (polymul (CN c n p) p')
    1.68    else polyadd (polymul (CN c n p) c') (CN 0\<^sub>p n' (polymul (CN c n p) p')))"
    1.69  | "polymul a b = Mul a b"
    1.70 @@ -157,7 +157,7 @@
    1.71  fun polypow :: "nat \<Rightarrow> poly \<Rightarrow> poly"
    1.72  where
    1.73    "polypow 0 = (\<lambda>p. (1)\<^sub>p)"
    1.74 -| "polypow n = (\<lambda>p. let q = polypow (n div 2) p ; d = polymul q q in 
    1.75 +| "polypow n = (\<lambda>p. let q = polypow (n div 2) p ; d = polymul q q in
    1.76                      if even n then d else polymul p d)"
    1.77  
    1.78  abbreviation poly_pow :: "poly \<Rightarrow> nat \<Rightarrow> poly" (infixl "^\<^sub>p" 60)
    1.79 @@ -196,13 +196,15 @@
    1.80  
    1.81  partial_function (tailrec) polydivide_aux :: "poly \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> nat \<times> poly"
    1.82  where
    1.83 -  "polydivide_aux a n p k s = 
    1.84 +  "polydivide_aux a n p k s =
    1.85      (if s = 0\<^sub>p then (k,s)
    1.86 -    else (let b = head s; m = degree s in
    1.87 -    (if m < n then (k,s) else 
    1.88 -    (let p'= funpow (m - n) shift1 p in 
    1.89 -    (if a = b then polydivide_aux a n p k (s -\<^sub>p p') 
    1.90 -    else polydivide_aux a n p (Suc k) ((a *\<^sub>p s) -\<^sub>p (b *\<^sub>p p')))))))"
    1.91 +     else
    1.92 +      (let b = head s; m = degree s in
    1.93 +        (if m < n then (k,s)
    1.94 +         else
    1.95 +          (let p'= funpow (m - n) shift1 p in
    1.96 +            (if a = b then polydivide_aux a n p k (s -\<^sub>p p')
    1.97 +             else polydivide_aux a n p (Suc k) ((a *\<^sub>p s) -\<^sub>p (b *\<^sub>p p')))))))"
    1.98  
    1.99  definition polydivide :: "poly \<Rightarrow> poly \<Rightarrow> (nat \<times> poly)"
   1.100    where "polydivide s p \<equiv> polydivide_aux (head p) (degree p) p 0 s"
   1.101 @@ -234,9 +236,9 @@
   1.102    Ipoly_syntax :: "poly \<Rightarrow> 'a list \<Rightarrow>'a::{field_char_0, field_inverse_zero, power}" ("\<lparr>_\<rparr>\<^sub>p\<^bsup>_\<^esup>")
   1.103    where "\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<equiv> Ipoly bs p"
   1.104  
   1.105 -lemma Ipoly_CInt: "Ipoly bs (C (i,1)) = of_int i" 
   1.106 +lemma Ipoly_CInt: "Ipoly bs (C (i,1)) = of_int i"
   1.107    by (simp add: INum_def)
   1.108 -lemma Ipoly_CRat: "Ipoly bs (C (i, j)) = of_int i / of_int j" 
   1.109 +lemma Ipoly_CRat: "Ipoly bs (C (i, j)) = of_int i / of_int j"
   1.110    by (simp  add: INum_def)
   1.111  
   1.112  lemmas RIpoly_eqs = Ipoly.simps(2-7) Ipoly_CInt Ipoly_CRat
   1.113 @@ -258,49 +260,52 @@
   1.114  
   1.115  text{* polyadd preserves normal forms *}
   1.116  
   1.117 -lemma polyadd_normh: "\<lbrakk>isnpolyh p n0 ; isnpolyh q n1\<rbrakk> 
   1.118 +lemma polyadd_normh: "\<lbrakk>isnpolyh p n0 ; isnpolyh q n1\<rbrakk>
   1.119        \<Longrightarrow> isnpolyh (polyadd p q) (min n0 n1)"
   1.120 -proof(induct p q arbitrary: n0 n1 rule: polyadd.induct)
   1.121 +proof (induct p q arbitrary: n0 n1 rule: polyadd.induct)
   1.122    case (2 ab c' n' p' n0 n1)
   1.123 -  from 2 have  th1: "isnpolyh (C ab) (Suc n')" by simp 
   1.124 +  from 2 have  th1: "isnpolyh (C ab) (Suc n')" by simp
   1.125    from 2(3) have th2: "isnpolyh c' (Suc n')"  and nplen1: "n' \<ge> n1" by simp_all
   1.126    with isnpolyh_mono have cp: "isnpolyh c' (Suc n')" by simp
   1.127    with 2(1)[OF th1 th2] have th3:"isnpolyh (C ab +\<^sub>p c') (Suc n')" by simp
   1.128 -  from nplen1 have n01len1: "min n0 n1 \<le> n'" by simp 
   1.129 +  from nplen1 have n01len1: "min n0 n1 \<le> n'" by simp
   1.130    thus ?case using 2 th3 by simp
   1.131  next
   1.132    case (3 c' n' p' ab n1 n0)
   1.133 -  from 3 have  th1: "isnpolyh (C ab) (Suc n')" by simp 
   1.134 +  from 3 have  th1: "isnpolyh (C ab) (Suc n')" by simp
   1.135    from 3(2) have th2: "isnpolyh c' (Suc n')"  and nplen1: "n' \<ge> n1" by simp_all
   1.136    with isnpolyh_mono have cp: "isnpolyh c' (Suc n')" by simp
   1.137    with 3(1)[OF th2 th1] have th3:"isnpolyh (c' +\<^sub>p C ab) (Suc n')" by simp
   1.138 -  from nplen1 have n01len1: "min n0 n1 \<le> n'" by simp 
   1.139 +  from nplen1 have n01len1: "min n0 n1 \<le> n'" by simp
   1.140    thus ?case using 3 th3 by simp
   1.141  next
   1.142    case (4 c n p c' n' p' n0 n1)
   1.143    hence nc: "isnpolyh c (Suc n)" and np: "isnpolyh p n" by simp_all
   1.144 -  from 4 have nc': "isnpolyh c' (Suc n')" and np': "isnpolyh p' n'" by simp_all 
   1.145 +  from 4 have nc': "isnpolyh c' (Suc n')" and np': "isnpolyh p' n'" by simp_all
   1.146    from 4 have ngen0: "n \<ge> n0" by simp
   1.147 -  from 4 have n'gen1: "n' \<ge> n1" by simp 
   1.148 +  from 4 have n'gen1: "n' \<ge> n1" by simp
   1.149    have "n < n' \<or> n' < n \<or> n = n'" by auto
   1.150 -  moreover {assume eq: "n = n'"
   1.151 -    with "4.hyps"(3)[OF nc nc'] 
   1.152 +  moreover {
   1.153 +    assume eq: "n = n'"
   1.154 +    with "4.hyps"(3)[OF nc nc']
   1.155      have ncc':"isnpolyh (c +\<^sub>p c') (Suc n)" by auto
   1.156      hence ncc'n01: "isnpolyh (c +\<^sub>p c') (min n0 n1)"
   1.157        using isnpolyh_mono[where n'="min n0 n1" and n="Suc n"] ngen0 n'gen1 by auto
   1.158      from eq "4.hyps"(4)[OF np np'] have npp': "isnpolyh (p +\<^sub>p p') n" by simp
   1.159      have minle: "min n0 n1 \<le> n'" using ngen0 n'gen1 eq by simp
   1.160 -    from minle npp' ncc'n01 4 eq ngen0 n'gen1 ncc' have ?case by (simp add: Let_def)}
   1.161 -  moreover {assume lt: "n < n'"
   1.162 +    from minle npp' ncc'n01 4 eq ngen0 n'gen1 ncc' have ?case by (simp add: Let_def) }
   1.163 +  moreover {
   1.164 +    assume lt: "n < n'"
   1.165      have "min n0 n1 \<le> n0" by simp
   1.166 -    with 4 lt have th1:"min n0 n1 \<le> n" by auto 
   1.167 +    with 4 lt have th1:"min n0 n1 \<le> n" by auto
   1.168      from 4 have th21: "isnpolyh c (Suc n)" by simp
   1.169      from 4 have th22: "isnpolyh (CN c' n' p') n'" by simp
   1.170      from lt have th23: "min (Suc n) n' = Suc n" by arith
   1.171      from "4.hyps"(1)[OF th21 th22]
   1.172      have "isnpolyh (polyadd c (CN c' n' p')) (Suc n)" using th23 by simp
   1.173 -    with 4 lt th1 have ?case by simp } 
   1.174 -  moreover {assume gt: "n' < n" hence gt': "n' < n \<and> \<not> n < n'" by simp
   1.175 +    with 4 lt th1 have ?case by simp }
   1.176 +  moreover {
   1.177 +    assume gt: "n' < n" hence gt': "n' < n \<and> \<not> n < n'" by simp
   1.178      have "min n0 n1 \<le> n1"  by simp
   1.179      with 4 gt have th1:"min n0 n1 \<le> n'" by auto
   1.180      from 4 have th21: "isnpolyh c' (Suc n')" by simp_all
   1.181 @@ -308,8 +313,8 @@
   1.182      from gt have th23: "min n (Suc n') = Suc n'" by arith
   1.183      from "4.hyps"(2)[OF th22 th21]
   1.184      have "isnpolyh (polyadd (CN c n p) c') (Suc n')" using th23 by simp
   1.185 -    with 4 gt th1 have ?case by simp}
   1.186 -      ultimately show ?case by blast
   1.187 +    with 4 gt th1 have ?case by simp }
   1.188 +  ultimately show ?case by blast
   1.189  qed auto
   1.190  
   1.191  lemma polyadd[simp]: "Ipoly bs (polyadd p q) = Ipoly bs p + Ipoly bs q"
   1.192 @@ -321,8 +326,8 @@
   1.193  
   1.194  text{* The degree of addition and other general lemmas needed for the normal form of polymul *}
   1.195  
   1.196 -lemma polyadd_different_degreen: 
   1.197 -  "\<lbrakk>isnpolyh p n0 ; isnpolyh q n1; degreen p m \<noteq> degreen q m ; m \<le> min n0 n1\<rbrakk> \<Longrightarrow> 
   1.198 +lemma polyadd_different_degreen:
   1.199 +  "\<lbrakk>isnpolyh p n0 ; isnpolyh q n1; degreen p m \<noteq> degreen q m ; m \<le> min n0 n1\<rbrakk> \<Longrightarrow>
   1.200    degreen (polyadd p q) m = max (degreen p m) (degreen q m)"
   1.201  proof (induct p q arbitrary: m n0 n1 rule: polyadd.induct)
   1.202    case (4 c n p c' n' p' m n0 n1)
   1.203 @@ -362,11 +367,13 @@
   1.204    shows "degreen (p +\<^sub>p q) m \<le> max (degreen p m) (degreen q m)"
   1.205    using np nq m
   1.206  proof (induct p q arbitrary: n0 n1 m rule: polyadd.induct)
   1.207 -  case (2 c c' n' p' n0 n1) thus ?case  by (cases n') simp_all
   1.208 +  case (2 c c' n' p' n0 n1)
   1.209 +  thus ?case  by (cases n') simp_all
   1.210  next
   1.211 -  case (3 c n p c' n0 n1) thus ?case by (cases n) auto
   1.212 +  case (3 c n p c' n0 n1)
   1.213 +  thus ?case by (cases n) auto
   1.214  next
   1.215 -  case (4 c n p c' n' p' n0 n1 m) 
   1.216 +  case (4 c n p c' n' p' n0 n1 m)
   1.217    have "n' = n \<or> n < n' \<or> n' < n" by arith
   1.218    thus ?case
   1.219    proof (elim disjE)
   1.220 @@ -376,21 +383,21 @@
   1.221    qed simp_all
   1.222  qed auto
   1.223  
   1.224 -lemma polyadd_eq_const_degreen: "\<lbrakk> isnpolyh p n0 ; isnpolyh q n1 ; polyadd p q = C c\<rbrakk> 
   1.225 +lemma polyadd_eq_const_degreen: "\<lbrakk> isnpolyh p n0 ; isnpolyh q n1 ; polyadd p q = C c\<rbrakk>
   1.226    \<Longrightarrow> degreen p m = degreen q m"
   1.227  proof (induct p q arbitrary: m n0 n1 c rule: polyadd.induct)
   1.228 -  case (4 c n p c' n' p' m n0 n1 x) 
   1.229 -  {assume nn': "n' < n" hence ?case using 4 by simp}
   1.230 -  moreover 
   1.231 -  {assume nn':"\<not> n' < n" hence "n < n' \<or> n = n'" by arith
   1.232 -    moreover {assume "n < n'" with 4 have ?case by simp }
   1.233 -    moreover {assume eq: "n = n'" hence ?case using 4 
   1.234 +  case (4 c n p c' n' p' m n0 n1 x)
   1.235 +  { assume nn': "n' < n" hence ?case using 4 by simp }
   1.236 +  moreover
   1.237 +  { assume nn':"\<not> n' < n" hence "n < n' \<or> n = n'" by arith
   1.238 +    moreover { assume "n < n'" with 4 have ?case by simp }
   1.239 +    moreover { assume eq: "n = n'" hence ?case using 4
   1.240          apply (cases "p +\<^sub>p p' = 0\<^sub>p")
   1.241          apply (auto simp add: Let_def)
   1.242          apply blast
   1.243          done
   1.244 -      }
   1.245 -    ultimately have ?case by blast}
   1.246 +    }
   1.247 +    ultimately have ?case by blast }
   1.248    ultimately show ?case by blast
   1.249  qed simp_all
   1.250  
   1.251 @@ -399,37 +406,37 @@
   1.252      and np: "isnpolyh p n0"
   1.253      and nq: "isnpolyh q n1"
   1.254      and m: "m \<le> min n0 n1"
   1.255 -  shows "isnpolyh (p *\<^sub>p q) (min n0 n1)" 
   1.256 -    and "(p *\<^sub>p q = 0\<^sub>p) = (p = 0\<^sub>p \<or> q = 0\<^sub>p)" 
   1.257 +  shows "isnpolyh (p *\<^sub>p q) (min n0 n1)"
   1.258 +    and "(p *\<^sub>p q = 0\<^sub>p) = (p = 0\<^sub>p \<or> q = 0\<^sub>p)"
   1.259      and "degreen (p *\<^sub>p q) m = (if (p = 0\<^sub>p \<or> q = 0\<^sub>p) then 0 else degreen p m + degreen q m)"
   1.260    using np nq m
   1.261  proof (induct p q arbitrary: n0 n1 m rule: polymul.induct)
   1.262 -  case (2 c c' n' p') 
   1.263 -  { case (1 n0 n1) 
   1.264 +  case (2 c c' n' p')
   1.265 +  { case (1 n0 n1)
   1.266      with "2.hyps"(4-6)[of n' n' n']
   1.267        and "2.hyps"(1-3)[of "Suc n'" "Suc n'" n']
   1.268      show ?case by (auto simp add: min_def)
   1.269    next
   1.270 -    case (2 n0 n1) thus ?case by auto 
   1.271 +    case (2 n0 n1) thus ?case by auto
   1.272    next
   1.273 -    case (3 n0 n1) thus ?case  using "2.hyps" by auto } 
   1.274 +    case (3 n0 n1) thus ?case  using "2.hyps" by auto }
   1.275  next
   1.276    case (3 c n p c')
   1.277 -  { case (1 n0 n1) 
   1.278 +  { case (1 n0 n1)
   1.279      with "3.hyps"(4-6)[of n n n]
   1.280        "3.hyps"(1-3)[of "Suc n" "Suc n" n]
   1.281      show ?case by (auto simp add: min_def)
   1.282    next
   1.283      case (2 n0 n1) thus ?case by auto
   1.284    next
   1.285 -    case (3 n0 n1) thus ?case  using "3.hyps" by auto } 
   1.286 +    case (3 n0 n1) thus ?case  using "3.hyps" by auto }
   1.287  next
   1.288    case (4 c n p c' n' p')
   1.289    let ?cnp = "CN c n p" let ?cnp' = "CN c' n' p'"
   1.290      {
   1.291        case (1 n0 n1)
   1.292        hence cnp: "isnpolyh ?cnp n" and cnp': "isnpolyh ?cnp' n'"
   1.293 -        and np: "isnpolyh p n" and nc: "isnpolyh c (Suc n)" 
   1.294 +        and np: "isnpolyh p n" and nc: "isnpolyh c (Suc n)"
   1.295          and np': "isnpolyh p' n'" and nc': "isnpolyh c' (Suc n')"
   1.296          and nn0: "n \<ge> n0" and nn1:"n' \<ge> n1"
   1.297          by simp_all
   1.298 @@ -462,23 +469,24 @@
   1.299        let ?d2 = "degreen ?cnp' m"
   1.300        let ?eq = "?d = (if ?cnp = 0\<^sub>p \<or> ?cnp' = 0\<^sub>p then 0  else ?d1 + ?d2)"
   1.301        have "n'<n \<or> n < n' \<or> n' = n" by auto
   1.302 -      moreover 
   1.303 +      moreover
   1.304        {assume "n' < n \<or> n < n'"
   1.305 -        with "4.hyps"(3,6,18) np np' m 
   1.306 +        with "4.hyps"(3,6,18) np np' m
   1.307          have ?eq by auto }
   1.308        moreover
   1.309 -      {assume nn': "n' = n" hence nn:"\<not> n' < n \<and> \<not> n < n'" by arith
   1.310 +      { assume nn': "n' = n"
   1.311 +        hence nn: "\<not> n' < n \<and> \<not> n < n'" by arith
   1.312          from "4.hyps"(16,18)[of n n' n]
   1.313            "4.hyps"(13,14)[of n "Suc n'" n]
   1.314            np np' nn'
   1.315          have norm: "isnpolyh ?cnp n" "isnpolyh c' (Suc n)" "isnpolyh (?cnp *\<^sub>p c') n"
   1.316            "isnpolyh p' n" "isnpolyh (?cnp *\<^sub>p p') n" "isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
   1.317 -          "(?cnp *\<^sub>p c' = 0\<^sub>p) = (c' = 0\<^sub>p)" 
   1.318 +          "(?cnp *\<^sub>p c' = 0\<^sub>p) = (c' = 0\<^sub>p)"
   1.319            "?cnp *\<^sub>p p' \<noteq> 0\<^sub>p" by (auto simp add: min_def)
   1.320 -        {assume mn: "m = n" 
   1.321 +        { assume mn: "m = n"
   1.322            from "4.hyps"(17,18)[OF norm(1,4), of n]
   1.323              "4.hyps"(13,15)[OF norm(1,2), of n] norm nn' mn
   1.324 -          have degs:  "degreen (?cnp *\<^sub>p c') n = 
   1.325 +          have degs:  "degreen (?cnp *\<^sub>p c') n =
   1.326              (if c'=0\<^sub>p then 0 else ?d1 + degreen c' n)"
   1.327              "degreen (?cnp *\<^sub>p p') n = ?d1  + degreen p' n" by (simp_all add: min_def)
   1.328            from degs norm
   1.329 @@ -487,31 +495,31 @@
   1.330              by simp
   1.331            have nmin: "n \<le> min n n" by (simp add: min_def)
   1.332            from polyadd_different_degreen[OF norm(3,6) neq nmin] th1
   1.333 -          have deg: "degreen (CN c n p *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n = degreen (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp 
   1.334 +          have deg: "degreen (CN c n p *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n = degreen (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp
   1.335            from "4.hyps"(16-18)[OF norm(1,4), of n]
   1.336              "4.hyps"(13-15)[OF norm(1,2), of n]
   1.337              mn norm m nn' deg
   1.338 -          have ?eq by simp}
   1.339 +          have ?eq by simp }
   1.340          moreover
   1.341 -        {assume mn: "m \<noteq> n" hence mn': "m < n" using m np by auto
   1.342 -          from nn' m np have max1: "m \<le> max n n"  by simp 
   1.343 -          hence min1: "m \<le> min n n" by simp     
   1.344 +        { assume mn: "m \<noteq> n" hence mn': "m < n" using m np by auto
   1.345 +          from nn' m np have max1: "m \<le> max n n"  by simp
   1.346 +          hence min1: "m \<le> min n n" by simp
   1.347            hence min2: "m \<le> min n (Suc n)" by simp
   1.348            from "4.hyps"(16-18)[OF norm(1,4) min1]
   1.349              "4.hyps"(13-15)[OF norm(1,2) min2]
   1.350              degreen_polyadd[OF norm(3,6) max1]
   1.351  
   1.352 -          have "degreen (?cnp *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (?cnp *\<^sub>p p')) m 
   1.353 +          have "degreen (?cnp *\<^sub>p c' +\<^sub>p CN 0\<^sub>p n (?cnp *\<^sub>p p')) m
   1.354              \<le> max (degreen (?cnp *\<^sub>p c') m) (degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) m)"
   1.355              using mn nn' np np' by simp
   1.356            with "4.hyps"(16-18)[OF norm(1,4) min1]
   1.357              "4.hyps"(13-15)[OF norm(1,2) min2]
   1.358              degreen_0[OF norm(3) mn']
   1.359 -          have ?eq using nn' mn np np' by clarsimp}
   1.360 -        ultimately have ?eq by blast}
   1.361 -      ultimately show ?eq by blast}
   1.362 +          have ?eq using nn' mn np np' by clarsimp }
   1.363 +        ultimately have ?eq by blast }
   1.364 +      ultimately show ?eq by blast }
   1.365      { case (2 n0 n1)
   1.366 -      hence np: "isnpolyh ?cnp n0" and np': "isnpolyh ?cnp' n1" 
   1.367 +      hence np: "isnpolyh ?cnp n0" and np': "isnpolyh ?cnp' n1"
   1.368          and m: "m \<le> min n0 n1" by simp_all
   1.369        hence mn: "m \<le> n" by simp
   1.370        let ?c0p = "CN 0\<^sub>p n (?cnp *\<^sub>p p')"
   1.371 @@ -522,32 +530,32 @@
   1.372            np np' C(2) mn
   1.373          have norm: "isnpolyh ?cnp n" "isnpolyh c' (Suc n)" "isnpolyh (?cnp *\<^sub>p c') n"
   1.374            "isnpolyh p' n" "isnpolyh (?cnp *\<^sub>p p') n" "isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n"
   1.375 -          "(?cnp *\<^sub>p c' = 0\<^sub>p) = (c' = 0\<^sub>p)" 
   1.376 -          "?cnp *\<^sub>p p' \<noteq> 0\<^sub>p" 
   1.377 +          "(?cnp *\<^sub>p c' = 0\<^sub>p) = (c' = 0\<^sub>p)"
   1.378 +          "?cnp *\<^sub>p p' \<noteq> 0\<^sub>p"
   1.379            "degreen (?cnp *\<^sub>p c') n = (if c'=0\<^sub>p then 0 else degreen ?cnp n + degreen c' n)"
   1.380              "degreen (?cnp *\<^sub>p p') n = degreen ?cnp n + degreen p' n"
   1.381            by (simp_all add: min_def)
   1.382 -            
   1.383 +
   1.384            from norm have cn: "isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp
   1.385 -          have degneq: "degreen (?cnp *\<^sub>p c') n < degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n" 
   1.386 +          have degneq: "degreen (?cnp *\<^sub>p c') n < degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n"
   1.387              using norm by simp
   1.388          from polyadd_eq_const_degreen[OF norm(3) cn C(1), where m="n"]  degneq
   1.389          have "False" by simp }
   1.390 -      thus ?case using "4.hyps" by clarsimp}
   1.391 +      thus ?case using "4.hyps" by clarsimp }
   1.392  qed auto
   1.393  
   1.394  lemma polymul[simp]: "Ipoly bs (p *\<^sub>p q) = (Ipoly bs p) * (Ipoly bs q)"
   1.395    by (induct p q rule: polymul.induct) (auto simp add: field_simps)
   1.396  
   1.397 -lemma polymul_normh: 
   1.398 +lemma polymul_normh:
   1.399    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.400    shows "\<lbrakk>isnpolyh p n0 ; isnpolyh q n1\<rbrakk> \<Longrightarrow> isnpolyh (p *\<^sub>p q) (min n0 n1)"
   1.401 -  using polymul_properties(1)  by blast
   1.402 +  using polymul_properties(1) by blast
   1.403  
   1.404 -lemma polymul_eq0_iff: 
   1.405 +lemma polymul_eq0_iff:
   1.406    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.407    shows "\<lbrakk> isnpolyh p n0 ; isnpolyh q n1\<rbrakk> \<Longrightarrow> (p *\<^sub>p q = 0\<^sub>p) = (p = 0\<^sub>p \<or> q = 0\<^sub>p) "
   1.408 -  using polymul_properties(2)  by blast
   1.409 +  using polymul_properties(2) by blast
   1.410  
   1.411  lemma polymul_degreen:  (* FIXME duplicate? *)
   1.412    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.413 @@ -555,7 +563,7 @@
   1.414      degreen (p *\<^sub>p q) m = (if (p = 0\<^sub>p \<or> q = 0\<^sub>p) then 0 else degreen p m + degreen q m)"
   1.415    using polymul_properties(3) by blast
   1.416  
   1.417 -lemma polymul_norm:   
   1.418 +lemma polymul_norm:
   1.419    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.420    shows "\<lbrakk> isnpoly p; isnpoly q\<rbrakk> \<Longrightarrow> isnpoly (polymul p q)"
   1.421    using polymul_normh[of "p" "0" "q" "0"] isnpoly_def by simp
   1.422 @@ -567,14 +575,14 @@
   1.423    by (induct p arbitrary: n0) auto
   1.424  
   1.425  lemma monic_eqI:
   1.426 -  assumes np: "isnpolyh p n0" 
   1.427 +  assumes np: "isnpolyh p n0"
   1.428    shows "INum (headconst p) * Ipoly bs (fst (monic p)) =
   1.429      (Ipoly bs p ::'a::{field_char_0, field_inverse_zero, power})"
   1.430    unfolding monic_def Let_def
   1.431  proof (cases "headconst p = 0\<^sub>N", simp_all add: headconst_zero[OF np])
   1.432    let ?h = "headconst p"
   1.433    assume pz: "p \<noteq> 0\<^sub>p"
   1.434 -  {assume hz: "INum ?h = (0::'a)"
   1.435 +  { assume hz: "INum ?h = (0::'a)"
   1.436      from headconst_isnormNum[OF np] have norm: "isnormNum ?h" "isnormNum 0\<^sub>N" by simp_all
   1.437      from isnormNum_unique[where ?'a = 'a, OF norm] hz have "?h = 0\<^sub>N" by simp
   1.438      with headconst_zero[OF np] have "p =0\<^sub>p" by blast with pz have "False" by blast}
   1.439 @@ -602,18 +610,19 @@
   1.440  
   1.441  lemma polysub[simp]: "Ipoly bs (polysub p q) = (Ipoly bs p) - (Ipoly bs q)"
   1.442    by (simp add: polysub_def)
   1.443 -lemma polysub_normh: "\<And> n0 n1. \<lbrakk> isnpolyh p n0 ; isnpolyh q n1\<rbrakk> \<Longrightarrow> isnpolyh (polysub p q) (min n0 n1)"
   1.444 +lemma polysub_normh:
   1.445 +  "\<And>n0 n1. \<lbrakk> isnpolyh p n0 ; isnpolyh q n1\<rbrakk> \<Longrightarrow> isnpolyh (polysub p q) (min n0 n1)"
   1.446    by (simp add: polysub_def polyneg_normh polyadd_normh)
   1.447  
   1.448  lemma polysub_norm: "\<lbrakk> isnpoly p; isnpoly q\<rbrakk> \<Longrightarrow> isnpoly (polysub p q)"
   1.449 -  using polyadd_norm polyneg_norm by (simp add: polysub_def) 
   1.450 +  using polyadd_norm polyneg_norm by (simp add: polysub_def)
   1.451  lemma polysub_same_0[simp]:
   1.452    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.453    shows "isnpolyh p n0 \<Longrightarrow> polysub p p = 0\<^sub>p"
   1.454    unfolding polysub_def split_def fst_conv snd_conv
   1.455    by (induct p arbitrary: n0) (auto simp add: Let_def Nsub0[simplified Nsub_def])
   1.456  
   1.457 -lemma polysub_0: 
   1.458 +lemma polysub_0:
   1.459    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.460    shows "\<lbrakk> isnpolyh p n0 ; isnpolyh q n1\<rbrakk> \<Longrightarrow> (p -\<^sub>p q = 0\<^sub>p) = (p = q)"
   1.461    unfolding polysub_def split_def fst_conv snd_conv
   1.462 @@ -631,8 +640,8 @@
   1.463    let ?q = "polypow ((Suc n) div 2) p"
   1.464    let ?d = "polymul ?q ?q"
   1.465    have "odd (Suc n) \<or> even (Suc n)" by simp
   1.466 -  moreover 
   1.467 -  {assume odd: "odd (Suc n)"
   1.468 +  moreover
   1.469 +  { assume odd: "odd (Suc n)"
   1.470      have th: "(Suc (Suc (Suc (0\<Colon>nat)) * (Suc n div Suc (Suc (0\<Colon>nat))))) = Suc n div 2 + Suc n div 2 + 1"
   1.471        by arith
   1.472      from odd have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs (polymul p ?d)" by (simp add: Let_def)
   1.473 @@ -642,10 +651,10 @@
   1.474        by (simp only: power_add power_one_right) simp
   1.475      also have "\<dots> = (Ipoly bs p) ^ (Suc (Suc (Suc (0\<Colon>nat)) * (Suc n div Suc (Suc (0\<Colon>nat)))))"
   1.476        by (simp only: th)
   1.477 -    finally have ?case 
   1.478 +    finally have ?case
   1.479      using odd_nat_div_two_times_two_plus_one[OF odd, symmetric] by simp  }
   1.480 -  moreover 
   1.481 -  {assume even: "even (Suc n)"
   1.482 +  moreover
   1.483 +  { assume even: "even (Suc n)"
   1.484      have th: "(Suc (Suc (0\<Colon>nat))) * (Suc n div Suc (Suc (0\<Colon>nat))) = Suc n div 2 + Suc n div 2"
   1.485        by arith
   1.486      from even have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs ?d" by (simp add: Let_def)
   1.487 @@ -655,7 +664,7 @@
   1.488    ultimately show ?case by blast
   1.489  qed
   1.490  
   1.491 -lemma polypow_normh: 
   1.492 +lemma polypow_normh:
   1.493    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.494    shows "isnpolyh p n \<Longrightarrow> isnpolyh (polypow k p) n"
   1.495  proof (induct k arbitrary: n rule: polypow.induct)
   1.496 @@ -666,9 +675,9 @@
   1.497    from polymul_normh[OF th1 th1] have dn: "isnpolyh ?d n" by simp
   1.498    from polymul_normh[OF th2 dn] have on: "isnpolyh (polymul p ?d) n" by simp
   1.499    from dn on show ?case by (simp add: Let_def)
   1.500 -qed auto 
   1.501 +qed auto
   1.502  
   1.503 -lemma polypow_norm:   
   1.504 +lemma polypow_norm:
   1.505    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.506    shows "isnpoly p \<Longrightarrow> isnpoly (polypow k p)"
   1.507    by (simp add: polypow_normh isnpoly_def)
   1.508 @@ -679,7 +688,7 @@
   1.509    "Ipoly bs (polynate p) = (Ipoly bs p :: 'a ::{field_char_0, field_inverse_zero})"
   1.510    by (induct p rule:polynate.induct) auto
   1.511  
   1.512 -lemma polynate_norm[simp]: 
   1.513 +lemma polynate_norm[simp]:
   1.514    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.515    shows "isnpoly (polynate p)"
   1.516    by (induct p rule: polynate.induct)
   1.517 @@ -692,7 +701,7 @@
   1.518  lemma shift1: "Ipoly bs (shift1 p) = Ipoly bs (Mul (Bound 0) p)"
   1.519    by (simp add: shift1_def)
   1.520  
   1.521 -lemma shift1_isnpoly: 
   1.522 +lemma shift1_isnpoly:
   1.523    assumes pn: "isnpoly p"
   1.524      and pnz: "p \<noteq> 0\<^sub>p"
   1.525    shows "isnpoly (shift1 p) "
   1.526 @@ -700,11 +709,11 @@
   1.527  
   1.528  lemma shift1_nz[simp]:"shift1 p \<noteq> 0\<^sub>p"
   1.529    by (simp add: shift1_def)
   1.530 -lemma funpow_shift1_isnpoly: 
   1.531 +lemma funpow_shift1_isnpoly:
   1.532    "\<lbrakk> isnpoly p ; p \<noteq> 0\<^sub>p\<rbrakk> \<Longrightarrow> isnpoly (funpow n shift1 p)"
   1.533    by (induct n arbitrary: p) (auto simp add: shift1_isnpoly funpow_swap1)
   1.534  
   1.535 -lemma funpow_isnpolyh: 
   1.536 +lemma funpow_isnpolyh:
   1.537    assumes f: "\<And> p. isnpolyh p n \<Longrightarrow> isnpolyh (f p) n"
   1.538      and np: "isnpolyh p n"
   1.539    shows "isnpolyh (funpow k f p) n"
   1.540 @@ -718,7 +727,7 @@
   1.541  lemma shift1_isnpolyh: "isnpolyh p n0 \<Longrightarrow> p\<noteq> 0\<^sub>p \<Longrightarrow> isnpolyh (shift1 p) 0"
   1.542    using isnpolyh_mono[where n="n0" and n'="0" and p="p"] by (simp add: shift1_def)
   1.543  
   1.544 -lemma funpow_shift1_1: 
   1.545 +lemma funpow_shift1_1:
   1.546    "(Ipoly bs (funpow n shift1 p) :: 'a :: {field_char_0, field_inverse_zero}) =
   1.547      Ipoly bs (funpow n shift1 (1)\<^sub>p *\<^sub>p p)"
   1.548    by (simp add: funpow_shift1)
   1.549 @@ -733,8 +742,8 @@
   1.550    using np
   1.551  proof (induct p arbitrary: n rule: behead.induct)
   1.552    case (1 c p n) hence pn: "isnpolyh p n" by simp
   1.553 -  from 1(1)[OF pn] 
   1.554 -  have th:"Ipoly bs (Add (Mul (head p) (Pw (Bound 0) (degree p))) (behead p)) = Ipoly bs p" . 
   1.555 +  from 1(1)[OF pn]
   1.556 +  have th:"Ipoly bs (Add (Mul (head p) (Pw (Bound 0) (degree p))) (behead p)) = Ipoly bs p" .
   1.557    then show ?case using "1.hyps"
   1.558      apply (simp add: Let_def,cases "behead p = 0\<^sub>p")
   1.559      apply (simp_all add: th[symmetric] field_simps)
   1.560 @@ -778,7 +787,7 @@
   1.561    assumes nb: "polybound0 a"
   1.562    shows "Ipoly (b#bs) a = Ipoly (b'#bs) a"
   1.563    using nb
   1.564 -  by (induct a rule: poly.induct) auto 
   1.565 +  by (induct a rule: poly.induct) auto
   1.566  
   1.567  lemma polysubst0_I: "Ipoly (b#bs) (polysubst0 a t) = Ipoly ((Ipoly (b#bs) a)#bs) t"
   1.568    by (induct t) simp_all
   1.569 @@ -816,15 +825,15 @@
   1.570  
   1.571  lemma wf_bs_coefficients: "wf_bs bs p \<Longrightarrow> \<forall> c \<in> set (coefficients p). wf_bs bs c"
   1.572  proof (induct p rule: coefficients.induct)
   1.573 -  case (1 c p) 
   1.574 -  show ?case 
   1.575 +  case (1 c p)
   1.576 +  show ?case
   1.577    proof
   1.578      fix x assume xc: "x \<in> set (coefficients (CN c 0 p))"
   1.579      hence "x = c \<or> x \<in> set (coefficients p)" by simp
   1.580 -    moreover 
   1.581 +    moreover
   1.582      {assume "x = c" hence "wf_bs bs x" using "1.prems"  unfolding wf_bs_def by simp}
   1.583 -    moreover 
   1.584 -    {assume H: "x \<in> set (coefficients p)" 
   1.585 +    moreover
   1.586 +    {assume H: "x \<in> set (coefficients p)"
   1.587        from "1.prems" have "wf_bs bs p" unfolding wf_bs_def by simp
   1.588        with "1.hyps" H have "wf_bs bs x" by blast }
   1.589      ultimately  show "wf_bs bs x" by blast
   1.590 @@ -838,7 +847,7 @@
   1.591    unfolding wf_bs_def by (induct p) (auto simp add: nth_append)
   1.592  
   1.593  lemma take_maxindex_wf:
   1.594 -  assumes wf: "wf_bs bs p" 
   1.595 +  assumes wf: "wf_bs bs p"
   1.596    shows "Ipoly (take (maxindex p) bs) p = Ipoly bs p"
   1.597  proof-
   1.598    let ?ip = "maxindex p"
   1.599 @@ -885,14 +894,14 @@
   1.600    done
   1.601  
   1.602  lemma wf_bs_polyadd: "wf_bs bs p \<and> wf_bs bs q \<longrightarrow> wf_bs bs (p +\<^sub>p q)"
   1.603 -  unfolding wf_bs_def 
   1.604 +  unfolding wf_bs_def
   1.605    apply (induct p q rule: polyadd.induct)
   1.606    apply (auto simp add: Let_def)
   1.607    done
   1.608  
   1.609  lemma wf_bs_polyul: "wf_bs bs p \<Longrightarrow> wf_bs bs q \<Longrightarrow> wf_bs bs (p *\<^sub>p q)"
   1.610 -  unfolding wf_bs_def 
   1.611 -  apply (induct p q arbitrary: bs rule: polymul.induct) 
   1.612 +  unfolding wf_bs_def
   1.613 +  apply (induct p q arbitrary: bs rule: polymul.induct)
   1.614    apply (simp_all add: wf_bs_polyadd)
   1.615    apply clarsimp
   1.616    apply (rule wf_bs_polyadd[unfolded wf_bs_def, rule_format])
   1.617 @@ -918,12 +927,12 @@
   1.618    have cp: "isnpolyh (CN c 0 p) n0" by fact
   1.619    hence norm: "isnpolyh c 0" "isnpolyh p 0" "p \<noteq> 0\<^sub>p" "n0 = 0"
   1.620      by (auto simp add: isnpolyh_mono[where n'=0])
   1.621 -  from "1.hyps"[OF norm(2)] norm(1) norm(4)  show ?case by simp 
   1.622 +  from "1.hyps"[OF norm(2)] norm(1) norm(4)  show ?case by simp
   1.623  qed auto
   1.624  
   1.625  lemma coefficients_isconst:
   1.626    "isnpolyh p n \<Longrightarrow> \<forall>q\<in>set (coefficients p). isconstant q"
   1.627 -  by (induct p arbitrary: n rule: coefficients.induct) 
   1.628 +  by (induct p arbitrary: n rule: coefficients.induct)
   1.629      (auto simp add: isnpolyh_Suc_const)
   1.630  
   1.631  lemma polypoly_polypoly':
   1.632 @@ -940,17 +949,17 @@
   1.633    hence "\<forall>q \<in> ?cf. Ipoly (x#bs) q = Ipoly bs (decrpoly q)"
   1.634      using polybound0_I[where b=x and bs=bs and b'=y] decrpoly[where x=x and bs=bs]
   1.635      by auto
   1.636 -  
   1.637 -  thus ?thesis unfolding polypoly_def polypoly'_def by simp 
   1.638 +
   1.639 +  thus ?thesis unfolding polypoly_def polypoly'_def by simp
   1.640  qed
   1.641  
   1.642  lemma polypoly_poly:
   1.643    assumes np: "isnpolyh p n0"
   1.644    shows "Ipoly (x#bs) p = poly (polypoly (x#bs) p) x"
   1.645 -  using np 
   1.646 +  using np
   1.647    by (induct p arbitrary: n0 bs rule: coefficients.induct) (auto simp add: polypoly_def)
   1.648  
   1.649 -lemma polypoly'_poly: 
   1.650 +lemma polypoly'_poly:
   1.651    assumes np: "isnpolyh p n0"
   1.652    shows "\<lparr>p\<rparr>\<^sub>p\<^bsup>x # bs\<^esup> = poly (polypoly' bs p) x"
   1.653    using polypoly_poly[OF np, simplified polypoly_polypoly'[OF np]] .
   1.654 @@ -959,14 +968,14 @@
   1.655  lemma polypoly_poly_polybound0:
   1.656    assumes np: "isnpolyh p n0" and nb: "polybound0 p"
   1.657    shows "polypoly bs p = [Ipoly bs p]"
   1.658 -  using np nb unfolding polypoly_def 
   1.659 +  using np nb unfolding polypoly_def
   1.660    apply (cases p)
   1.661    apply auto
   1.662    apply (case_tac nat)
   1.663    apply auto
   1.664    done
   1.665  
   1.666 -lemma head_isnpolyh: "isnpolyh p n0 \<Longrightarrow> isnpolyh (head p) n0" 
   1.667 +lemma head_isnpolyh: "isnpolyh p n0 \<Longrightarrow> isnpolyh (head p) n0"
   1.668    by (induct p rule: head.induct) auto
   1.669  
   1.670  lemma headn_nz[simp]: "isnpolyh p n0 \<Longrightarrow> (headn p m = 0\<^sub>p) = (p = 0\<^sub>p)"
   1.671 @@ -978,7 +987,7 @@
   1.672  lemma head_nz[simp]: "isnpolyh p n0 \<Longrightarrow> (head p = 0\<^sub>p) = (p = 0\<^sub>p)"
   1.673    by (simp add: head_eq_headn0)
   1.674  
   1.675 -lemma isnpolyh_zero_iff: 
   1.676 +lemma isnpolyh_zero_iff:
   1.677    assumes nq: "isnpolyh p n0"
   1.678      and eq :"\<forall>bs. wf_bs bs p \<longrightarrow> \<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a::{field_char_0, field_inverse_zero, power})"
   1.679    shows "p = 0\<^sub>p"
   1.680 @@ -994,10 +1003,10 @@
   1.681      let ?h = "head p"
   1.682      let ?hd = "decrpoly ?h"
   1.683      let ?ihd = "maxindex ?hd"
   1.684 -    from head_isnpolyh[OF np] head_polybound0[OF np] have h:"isnpolyh ?h n0" "polybound0 ?h" 
   1.685 +    from head_isnpolyh[OF np] head_polybound0[OF np] have h:"isnpolyh ?h n0" "polybound0 ?h"
   1.686        by simp_all
   1.687      hence nhd: "isnpolyh ?hd (n0 - 1)" using decrpoly_normh by blast
   1.688 -    
   1.689 +
   1.690      from maxindex_coefficients[of p] coefficients_head[of p, symmetric]
   1.691      have mihn: "maxindex ?h \<le> maxindex p" by auto
   1.692      with decr_maxindex[OF h(2)] nz  have ihd_lt_n: "?ihd < maxindex p" by auto
   1.693 @@ -1023,21 +1032,21 @@
   1.694        with th0 wf_bs_I[of ?ts ?hd xs] have "Ipoly ?ts ?hd = 0" by simp
   1.695        with wf'' wf_bs_I[of ?ts ?hd ?rs] bs_ts_eq have "\<lparr>?hd\<rparr>\<^sub>p\<^bsup>bs\<^esup> = 0" by simp }
   1.696      then have hdz: "\<forall>bs. wf_bs bs ?hd \<longrightarrow> \<lparr>?hd\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)" by blast
   1.697 -    
   1.698 +
   1.699      from less(1)[OF ihd_lt_n nhd] hdz have "?hd = 0\<^sub>p" by blast
   1.700      hence "?h = 0\<^sub>p" by simp
   1.701      with head_nz[OF np] have "p = 0\<^sub>p" by simp}
   1.702    ultimately show "p = 0\<^sub>p" by blast
   1.703  qed
   1.704  
   1.705 -lemma isnpolyh_unique:  
   1.706 +lemma isnpolyh_unique:
   1.707    assumes np:"isnpolyh p n0"
   1.708      and nq: "isnpolyh q n1"
   1.709    shows "(\<forall>bs. \<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (\<lparr>q\<rparr>\<^sub>p\<^bsup>bs\<^esup> :: 'a::{field_char_0, field_inverse_zero, power})) \<longleftrightarrow>  p = q"
   1.710  proof(auto)
   1.711    assume H: "\<forall>bs. (\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> ::'a)= \<lparr>q\<rparr>\<^sub>p\<^bsup>bs\<^esup>"
   1.712    hence "\<forall>bs.\<lparr>p -\<^sub>p q\<rparr>\<^sub>p\<^bsup>bs\<^esup>= (0::'a)" by simp
   1.713 -  hence "\<forall>bs. wf_bs bs (p -\<^sub>p q) \<longrightarrow> \<lparr>p -\<^sub>p q\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)" 
   1.714 +  hence "\<forall>bs. wf_bs bs (p -\<^sub>p q) \<longrightarrow> \<lparr>p -\<^sub>p q\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)"
   1.715      using wf_bs_polysub[where p=p and q=q] by auto
   1.716    with isnpolyh_zero_iff[OF polysub_normh[OF np nq]] polysub_0[OF np nq]
   1.717    show "p = q" by blast
   1.718 @@ -1056,28 +1065,28 @@
   1.719  lemma zero_normh: "isnpolyh 0\<^sub>p n" by simp
   1.720  lemma one_normh: "isnpolyh (1)\<^sub>p n" by simp
   1.721  
   1.722 -lemma polyadd_0[simp]: 
   1.723 +lemma polyadd_0[simp]:
   1.724    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.725      and np: "isnpolyh p n0"
   1.726    shows "p +\<^sub>p 0\<^sub>p = p" and "0\<^sub>p +\<^sub>p p = p"
   1.727 -  using isnpolyh_unique[OF polyadd_normh[OF np zero_normh] np] 
   1.728 +  using isnpolyh_unique[OF polyadd_normh[OF np zero_normh] np]
   1.729      isnpolyh_unique[OF polyadd_normh[OF zero_normh np] np] by simp_all
   1.730  
   1.731 -lemma polymul_1[simp]: 
   1.732 +lemma polymul_1[simp]:
   1.733    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.734      and np: "isnpolyh p n0"
   1.735    shows "p *\<^sub>p (1)\<^sub>p = p" and "(1)\<^sub>p *\<^sub>p p = p"
   1.736 -  using isnpolyh_unique[OF polymul_normh[OF np one_normh] np] 
   1.737 +  using isnpolyh_unique[OF polymul_normh[OF np one_normh] np]
   1.738      isnpolyh_unique[OF polymul_normh[OF one_normh np] np] by simp_all
   1.739  
   1.740 -lemma polymul_0[simp]: 
   1.741 +lemma polymul_0[simp]:
   1.742    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.743      and np: "isnpolyh p n0"
   1.744    shows "p *\<^sub>p 0\<^sub>p = 0\<^sub>p" and "0\<^sub>p *\<^sub>p p = 0\<^sub>p"
   1.745 -  using isnpolyh_unique[OF polymul_normh[OF np zero_normh] zero_normh] 
   1.746 +  using isnpolyh_unique[OF polymul_normh[OF np zero_normh] zero_normh]
   1.747      isnpolyh_unique[OF polymul_normh[OF zero_normh np] zero_normh] by simp_all
   1.748  
   1.749 -lemma polymul_commute: 
   1.750 +lemma polymul_commute:
   1.751    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.752      and np:"isnpolyh p n0"
   1.753      and nq: "isnpolyh q n1"
   1.754 @@ -1086,15 +1095,15 @@
   1.755    by simp
   1.756  
   1.757  declare polyneg_polyneg [simp]
   1.758 -  
   1.759 -lemma isnpolyh_polynate_id [simp]: 
   1.760 +
   1.761 +lemma isnpolyh_polynate_id [simp]:
   1.762    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.763      and np:"isnpolyh p n0"
   1.764    shows "polynate p = p"
   1.765    using isnpolyh_unique[where ?'a= "'a::{field_char_0, field_inverse_zero}", OF polynate_norm[of p, unfolded isnpoly_def] np] polynate[where ?'a = "'a::{field_char_0, field_inverse_zero}"]
   1.766    by simp
   1.767  
   1.768 -lemma polynate_idempotent[simp]: 
   1.769 +lemma polynate_idempotent[simp]:
   1.770    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.771    shows "polynate (polynate p) = polynate p"
   1.772    using isnpolyh_polynate_id[OF polynate_norm[of p, unfolded isnpoly_def]] .
   1.773 @@ -1137,34 +1146,34 @@
   1.774    from degree_polyadd[OF np nq'] show ?thesis by (simp add: polysub_def degree_polyneg[OF nq])
   1.775  qed
   1.776  
   1.777 -lemma degree_polysub_samehead: 
   1.778 +lemma degree_polysub_samehead:
   1.779    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.780 -    and np: "isnpolyh p n0" and nq: "isnpolyh q n1" and h: "head p = head q" 
   1.781 +    and np: "isnpolyh p n0" and nq: "isnpolyh q n1" and h: "head p = head q"
   1.782      and d: "degree p = degree q"
   1.783    shows "degree (p -\<^sub>p q) < degree p \<or> (p -\<^sub>p q = 0\<^sub>p)"
   1.784    unfolding polysub_def split_def fst_conv snd_conv
   1.785    using np nq h d
   1.786  proof (induct p q rule: polyadd.induct)
   1.787    case (1 c c')
   1.788 -  thus ?case by (simp add: Nsub_def Nsub0[simplified Nsub_def]) 
   1.789 +  thus ?case by (simp add: Nsub_def Nsub0[simplified Nsub_def])
   1.790  next
   1.791 -  case (2 c c' n' p') 
   1.792 +  case (2 c c' n' p')
   1.793    from 2 have "degree (C c) = degree (CN c' n' p')" by simp
   1.794    hence nz:"n' > 0" by (cases n') auto
   1.795    hence "head (CN c' n' p') = CN c' n' p'" by (cases n') auto
   1.796    with 2 show ?case by simp
   1.797  next
   1.798 -  case (3 c n p c') 
   1.799 +  case (3 c n p c')
   1.800    hence "degree (C c') = degree (CN c n p)" by simp
   1.801    hence nz:"n > 0" by (cases n) auto
   1.802    hence "head (CN c n p) = CN c n p" by (cases n) auto
   1.803    with 3 show ?case by simp
   1.804  next
   1.805    case (4 c n p c' n' p')
   1.806 -  hence H: "isnpolyh (CN c n p) n0" "isnpolyh (CN c' n' p') n1" 
   1.807 +  hence H: "isnpolyh (CN c n p) n0" "isnpolyh (CN c' n' p') n1"
   1.808      "head (CN c n p) = head (CN c' n' p')" "degree (CN c n p) = degree (CN c' n' p')" by simp+
   1.809 -  hence degc: "degree c = 0" and degc': "degree c' = 0" by simp_all  
   1.810 -  hence degnc: "degree (~\<^sub>p c) = 0" and degnc': "degree (~\<^sub>p c') = 0" 
   1.811 +  hence degc: "degree c = 0" and degc': "degree c' = 0" by simp_all
   1.812 +  hence degnc: "degree (~\<^sub>p c) = 0" and degnc': "degree (~\<^sub>p c') = 0"
   1.813      using H(1-2) degree_polyneg by auto
   1.814    from H have cnh: "isnpolyh c (Suc n)" and c'nh: "isnpolyh c' (Suc n')"  by simp+
   1.815    from degree_polysub[OF cnh c'nh, simplified polysub_def] degc degc' have degcmc': "degree (c +\<^sub>p  ~\<^sub>pc') = 0"  by simp
   1.816 @@ -1178,10 +1187,10 @@
   1.817        with nn' H(3) have  cc':"c = c'" and pp': "p = p'" by (cases n, auto)+
   1.818        hence ?case
   1.819          using polysub_same_0[OF p'nh, simplified polysub_def split_def fst_conv snd_conv] polysub_same_0[OF c'nh, simplified polysub_def]
   1.820 -        using nn' 4 by (simp add: Let_def)}
   1.821 +        using nn' 4 by (simp add: Let_def) }
   1.822      ultimately have ?case by blast}
   1.823    moreover
   1.824 -  {assume nn': "n < n'" hence n'p: "n' > 0" by simp 
   1.825 +  {assume nn': "n < n'" hence n'p: "n' > 0" by simp
   1.826      hence headcnp':"head (CN c' n' p') = CN c' n' p'"  by (cases n') simp_all
   1.827      have degcnp': "degree (CN c' n' p') = 0" and degcnpeq: "degree (CN c n p) = degree (CN c' n' p')"
   1.828        using 4 nn' by (cases n', simp_all)
   1.829 @@ -1189,7 +1198,7 @@
   1.830      hence headcnp: "head (CN c n p) = CN c n p" by (cases n) auto
   1.831      from H(3) headcnp headcnp' nn' have ?case by auto}
   1.832    moreover
   1.833 -  {assume nn': "n > n'"  hence np: "n > 0" by simp 
   1.834 +  {assume nn': "n > n'"  hence np: "n > 0" by simp
   1.835      hence headcnp:"head (CN c n p) = CN c n p"  by (cases n) simp_all
   1.836      from 4 have degcnpeq: "degree (CN c' n' p') = degree (CN c n p)" by simp
   1.837      from np have degcnp: "degree (CN c n p) = 0" by (cases n) simp_all
   1.838 @@ -1198,7 +1207,7 @@
   1.839      from H(3) headcnp headcnp' nn' have ?case by auto}
   1.840    ultimately show ?case  by blast
   1.841  qed auto
   1.842 - 
   1.843 +
   1.844  lemma shift1_head : "isnpolyh p n0 \<Longrightarrow> head (shift1 p) = head p"
   1.845    by (induct p arbitrary: n0 rule: head.induct) (simp_all add: shift1_def)
   1.846  
   1.847 @@ -1210,7 +1219,7 @@
   1.848    case (Suc k n0 p)
   1.849    hence "isnpolyh (shift1 p) 0" by (simp add: shift1_isnpolyh)
   1.850    with Suc have "head (funpow k shift1 (shift1 p)) = head (shift1 p)"
   1.851 -    and "head (shift1 p) = head p" by (simp_all add: shift1_head) 
   1.852 +    and "head (shift1 p) = head p" by (simp_all add: shift1_head)
   1.853    thus ?case by (simp add: funpow_swap1)
   1.854  qed
   1.855  
   1.856 @@ -1231,7 +1240,7 @@
   1.857  lemma head_head[simp]: "isnpolyh p n0 \<Longrightarrow> head (head p) = head p"
   1.858    by (induct p rule: head.induct) auto
   1.859  
   1.860 -lemma polyadd_eq_const_degree: 
   1.861 +lemma polyadd_eq_const_degree:
   1.862    "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> polyadd p q = C c \<Longrightarrow> degree p = degree q"
   1.863    using polyadd_eq_const_degreen degree_eq_degreen0 by simp
   1.864  
   1.865 @@ -1255,15 +1264,15 @@
   1.866    apply (metis degree.simps(9) gr0_conv_Suc nat_less_le order_le_less_trans)
   1.867    done
   1.868  
   1.869 -lemma polymul_head_polyeq: 
   1.870 +lemma polymul_head_polyeq:
   1.871    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
   1.872    shows "\<lbrakk>isnpolyh p n0; isnpolyh q n1 ; p \<noteq> 0\<^sub>p ; q \<noteq> 0\<^sub>p \<rbrakk> \<Longrightarrow> head (p *\<^sub>p q) = head p *\<^sub>p head q"
   1.873  proof (induct p q arbitrary: n0 n1 rule: polymul.induct)
   1.874    case (2 c c' n' p' n0 n1)
   1.875    hence "isnpolyh (head (CN c' n' p')) n1" "isnormNum c"  by (simp_all add: head_isnpolyh)
   1.876    thus ?case using 2 by (cases n') auto
   1.877 -next 
   1.878 -  case (3 c n p c' n0 n1) 
   1.879 +next
   1.880 +  case (3 c n p c' n0 n1)
   1.881    hence "isnpolyh (head (CN c n p)) n0" "isnormNum c'"  by (simp_all add: head_isnpolyh)
   1.882    thus ?case using 3 by (cases n) auto
   1.883  next
   1.884 @@ -1272,8 +1281,8 @@
   1.885      "isnpolyh (CN c n p) n" "isnpolyh (CN c' n' p') n'"
   1.886      by simp_all
   1.887    have "n < n' \<or> n' < n \<or> n = n'" by arith
   1.888 -  moreover 
   1.889 -  {assume nn': "n < n'" hence ?case 
   1.890 +  moreover
   1.891 +  {assume nn': "n < n'" hence ?case
   1.892        using norm "4.hyps"(2)[OF norm(1,6)] "4.hyps"(1)[OF norm(2,6)]
   1.893        apply simp
   1.894        apply (cases n)
   1.895 @@ -1283,7 +1292,7 @@
   1.896        done }
   1.897    moreover {assume nn': "n'< n"
   1.898      hence ?case
   1.899 -      using norm "4.hyps"(6) [OF norm(5,3)] "4.hyps"(5)[OF norm(5,4)] 
   1.900 +      using norm "4.hyps"(6) [OF norm(5,3)] "4.hyps"(5)[OF norm(5,4)]
   1.901        apply simp
   1.902        apply (cases n')
   1.903        apply simp
   1.904 @@ -1291,14 +1300,14 @@
   1.905        apply auto
   1.906        done }
   1.907    moreover {assume nn': "n' = n"
   1.908 -    from nn' polymul_normh[OF norm(5,4)] 
   1.909 +    from nn' polymul_normh[OF norm(5,4)]
   1.910      have ncnpc':"isnpolyh (CN c n p *\<^sub>p c') n" by (simp add: min_def)
   1.911 -    from nn' polymul_normh[OF norm(5,3)] norm 
   1.912 +    from nn' polymul_normh[OF norm(5,3)] norm
   1.913      have ncnpp':"isnpolyh (CN c n p *\<^sub>p p') n" by simp
   1.914      from nn' ncnpp' polymul_eq0_iff[OF norm(5,3)] norm(6)
   1.915 -    have ncnpp0':"isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp 
   1.916 -    from polyadd_normh[OF ncnpc' ncnpp0'] 
   1.917 -    have nth: "isnpolyh ((CN c n p *\<^sub>p c') +\<^sub>p (CN 0\<^sub>p n (CN c n p *\<^sub>p p'))) n" 
   1.918 +    have ncnpp0':"isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp
   1.919 +    from polyadd_normh[OF ncnpc' ncnpp0']
   1.920 +    have nth: "isnpolyh ((CN c n p *\<^sub>p c') +\<^sub>p (CN 0\<^sub>p n (CN c n p *\<^sub>p p'))) n"
   1.921        by (simp add: min_def)
   1.922      {assume np: "n > 0"
   1.923        with nn' head_isnpolyh_Suc'[OF np nth]
   1.924 @@ -1314,7 +1323,7 @@
   1.925      from polyadd_head[OF ncnpc'[simplified nz] ncnpp0'[simplified nz] dth'] dth
   1.926      have ?case   using norm "4.hyps"(6)[OF norm(5,3)]
   1.927          "4.hyps"(5)[OF norm(5,4)] nn' nz by simp }
   1.928 -    ultimately have ?case by (cases n) auto} 
   1.929 +    ultimately have ?case by (cases n) auto}
   1.930    ultimately show ?case by blast
   1.931  qed simp_all
   1.932  
   1.933 @@ -1359,25 +1368,29 @@
   1.934      and ns: "isnpolyh s n1"
   1.935      and ap: "head p = a"
   1.936      and ndp: "degree p = n" and pnz: "p \<noteq> 0\<^sub>p"
   1.937 -  shows "(polydivide_aux a n p k s = (k',r) \<longrightarrow> (k' \<ge> k) \<and> (degree r = 0 \<or> degree r < degree p) 
   1.938 +  shows "(polydivide_aux a n p k s = (k',r) \<longrightarrow> (k' \<ge> k) \<and> (degree r = 0 \<or> degree r < degree p)
   1.939            \<and> (\<exists>nr. isnpolyh r nr) \<and> (\<exists>q n1. isnpolyh q n1 \<and> ((polypow (k' - k) a) *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)))"
   1.940    using ns
   1.941  proof (induct "degree s" arbitrary: s k k' r n1 rule: less_induct)
   1.942    case less
   1.943    let ?qths = "\<exists>q n1. isnpolyh q n1 \<and> (a ^\<^sub>p (k' - k) *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)"
   1.944 -  let ?ths = "polydivide_aux a n p k s = (k', r) \<longrightarrow>  k \<le> k' \<and> (degree r = 0 \<or> degree r < degree p) 
   1.945 +  let ?ths = "polydivide_aux a n p k s = (k', r) \<longrightarrow>  k \<le> k' \<and> (degree r = 0 \<or> degree r < degree p)
   1.946      \<and> (\<exists>nr. isnpolyh r nr) \<and> ?qths"
   1.947    let ?b = "head s"
   1.948    let ?p' = "funpow (degree s - n) shift1 p"
   1.949    let ?xdn = "funpow (degree s - n) shift1 (1)\<^sub>p"
   1.950    let ?akk' = "a ^\<^sub>p (k' - k)"
   1.951    note ns = `isnpolyh s n1`
   1.952 -  from np have np0: "isnpolyh p 0" 
   1.953 -    using isnpolyh_mono[where n="n0" and n'="0" and p="p"]  by simp
   1.954 -  have np': "isnpolyh ?p' 0" using funpow_shift1_isnpoly[OF np0[simplified isnpoly_def[symmetric]] pnz, where n="degree s - n"] isnpoly_def by simp
   1.955 -  have headp': "head ?p' = head p" using funpow_shift1_head[OF np pnz] by simp
   1.956 -  from funpow_shift1_isnpoly[where p="(1)\<^sub>p"] have nxdn: "isnpolyh ?xdn 0" by (simp add: isnpoly_def)
   1.957 -  from polypow_normh [OF head_isnpolyh[OF np0], where k="k' - k"] ap 
   1.958 +  from np have np0: "isnpolyh p 0"
   1.959 +    using isnpolyh_mono[where n="n0" and n'="0" and p="p"] by simp
   1.960 +  have np': "isnpolyh ?p' 0"
   1.961 +    using funpow_shift1_isnpoly[OF np0[simplified isnpoly_def[symmetric]] pnz, where n="degree s - n"] isnpoly_def
   1.962 +    by simp
   1.963 +  have headp': "head ?p' = head p"
   1.964 +    using funpow_shift1_head[OF np pnz] by simp
   1.965 +  from funpow_shift1_isnpoly[where p="(1)\<^sub>p"] have nxdn: "isnpolyh ?xdn 0"
   1.966 +    by (simp add: isnpoly_def)
   1.967 +  from polypow_normh [OF head_isnpolyh[OF np0], where k="k' - k"] ap
   1.968    have nakk':"isnpolyh ?akk' 0" by blast
   1.969    { assume sz: "s = 0\<^sub>p"
   1.970      hence ?ths using np polydivide_aux.simps
   1.971 @@ -1386,67 +1399,82 @@
   1.972        apply simp
   1.973        done }
   1.974    moreover
   1.975 -  {assume sz: "s \<noteq> 0\<^sub>p"
   1.976 -    {assume dn: "degree s < n"
   1.977 +  { assume sz: "s \<noteq> 0\<^sub>p"
   1.978 +    { assume dn: "degree s < n"
   1.979        hence "?ths" using ns ndp np polydivide_aux.simps
   1.980          apply auto
   1.981          apply (rule exI[where x="0\<^sub>p"])
   1.982          apply simp
   1.983          done }
   1.984 -    moreover 
   1.985 -    {assume dn': "\<not> degree s < n" hence dn: "degree s \<ge> n" by arith
   1.986 -      have degsp': "degree s = degree ?p'" 
   1.987 +    moreover
   1.988 +    { assume dn': "\<not> degree s < n" hence dn: "degree s \<ge> n" by arith
   1.989 +      have degsp': "degree s = degree ?p'"
   1.990          using dn ndp funpow_shift1_degree[where k = "degree s - n" and p="p"] by simp
   1.991 -      {assume ba: "?b = a"
   1.992 -        hence headsp': "head s = head ?p'" using ap headp' by simp
   1.993 -        have nr: "isnpolyh (s -\<^sub>p ?p') 0" using polysub_normh[OF ns np'] by simp
   1.994 +      { assume ba: "?b = a"
   1.995 +        hence headsp': "head s = head ?p'"
   1.996 +          using ap headp' by simp
   1.997 +        have nr: "isnpolyh (s -\<^sub>p ?p') 0"
   1.998 +          using polysub_normh[OF ns np'] by simp
   1.999          from degree_polysub_samehead[OF ns np' headsp' degsp']
  1.1000          have "degree (s -\<^sub>p ?p') < degree s \<or> s -\<^sub>p ?p' = 0\<^sub>p" by simp
  1.1001 -        moreover 
  1.1002 -        {assume deglt:"degree (s -\<^sub>p ?p') < degree s"
  1.1003 +        moreover
  1.1004 +        { assume deglt:"degree (s -\<^sub>p ?p') < degree s"
  1.1005            from polydivide_aux.simps sz dn' ba
  1.1006            have eq: "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  1.1007              by (simp add: Let_def)
  1.1008 -          {assume h1: "polydivide_aux a n p k s = (k', r)"
  1.1009 -            from less(1)[OF deglt nr, of k k' r]
  1.1010 -              trans[OF eq[symmetric] h1]
  1.1011 -            have kk': "k \<le> k'" and nr:"\<exists>nr. isnpolyh r nr" and dr: "degree r = 0 \<or> degree r < degree p"
  1.1012 -              and q1:"\<exists>q nq. isnpolyh q nq \<and> (a ^\<^sub>p k' - k *\<^sub>p (s -\<^sub>p ?p') = p *\<^sub>p q +\<^sub>p r)" by auto
  1.1013 -            from q1 obtain q n1 where nq: "isnpolyh q n1" 
  1.1014 -              and asp:"a^\<^sub>p (k' - k) *\<^sub>p (s -\<^sub>p ?p') = p *\<^sub>p q +\<^sub>p r"  by blast
  1.1015 +          { assume h1: "polydivide_aux a n p k s = (k', r)"
  1.1016 +            from less(1)[OF deglt nr, of k k' r] trans[OF eq[symmetric] h1]
  1.1017 +            have kk': "k \<le> k'"
  1.1018 +              and nr:"\<exists>nr. isnpolyh r nr"
  1.1019 +              and dr: "degree r = 0 \<or> degree r < degree p"
  1.1020 +              and q1: "\<exists>q nq. isnpolyh q nq \<and> (a ^\<^sub>p k' - k *\<^sub>p (s -\<^sub>p ?p') = p *\<^sub>p q +\<^sub>p r)"
  1.1021 +              by auto
  1.1022 +            from q1 obtain q n1 where nq: "isnpolyh q n1"
  1.1023 +              and asp:"a^\<^sub>p (k' - k) *\<^sub>p (s -\<^sub>p ?p') = p *\<^sub>p q +\<^sub>p r" by blast
  1.1024              from nr obtain nr where nr': "isnpolyh r nr" by blast
  1.1025 -            from polymul_normh[OF nakk' ns] have nakks': "isnpolyh (a ^\<^sub>p (k' - k) *\<^sub>p s) 0" by simp
  1.1026 +            from polymul_normh[OF nakk' ns] have nakks': "isnpolyh (a ^\<^sub>p (k' - k) *\<^sub>p s) 0"
  1.1027 +              by simp
  1.1028              from polyadd_normh[OF polymul_normh[OF nakk' nxdn] nq]
  1.1029              have nq': "isnpolyh (?akk' *\<^sub>p ?xdn +\<^sub>p q) 0" by simp
  1.1030 -            from polyadd_normh[OF polymul_normh[OF np 
  1.1031 +            from polyadd_normh[OF polymul_normh[OF np
  1.1032                polyadd_normh[OF polymul_normh[OF nakk' nxdn] nq]] nr']
  1.1033 -            have nqr': "isnpolyh (p *\<^sub>p (?akk' *\<^sub>p ?xdn +\<^sub>p q) +\<^sub>p r) 0" by simp 
  1.1034 -            from asp have "\<forall> (bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a^\<^sub>p (k' - k) *\<^sub>p (s -\<^sub>p ?p')) = 
  1.1035 +            have nqr': "isnpolyh (p *\<^sub>p (?akk' *\<^sub>p ?xdn +\<^sub>p q) +\<^sub>p r) 0"
  1.1036 +              by simp
  1.1037 +            from asp have "\<forall> (bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a^\<^sub>p (k' - k) *\<^sub>p (s -\<^sub>p ?p')) =
  1.1038                Ipoly bs (p *\<^sub>p q +\<^sub>p r)" by simp
  1.1039 -            hence " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a^\<^sub>p (k' - k)*\<^sub>p s) = 
  1.1040 -              Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs ?p' + Ipoly bs p * Ipoly bs q + Ipoly bs r" 
  1.1041 +            hence " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a^\<^sub>p (k' - k)*\<^sub>p s) =
  1.1042 +              Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs ?p' + Ipoly bs p * Ipoly bs q + Ipoly bs r"
  1.1043                by (simp add: field_simps)
  1.1044 -            hence " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) = 
  1.1045 -              Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs (funpow (degree s - n) shift1 (1)\<^sub>p *\<^sub>p p) 
  1.1046 -              + Ipoly bs p * Ipoly bs q + Ipoly bs r"
  1.1047 -              by (auto simp only: funpow_shift1_1) 
  1.1048 -            hence "\<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) = 
  1.1049 -              Ipoly bs p * (Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs (funpow (degree s - n) shift1 (1)\<^sub>p) 
  1.1050 -              + Ipoly bs q) + Ipoly bs r" by (simp add: field_simps)
  1.1051 -            hence "\<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) = 
  1.1052 -              Ipoly bs (p *\<^sub>p ((a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q) +\<^sub>p r)" by simp
  1.1053 +            hence " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1054 +              Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs (funpow (degree s - n) shift1 (1)\<^sub>p *\<^sub>p p) +
  1.1055 +              Ipoly bs p * Ipoly bs q + Ipoly bs r"
  1.1056 +              by (auto simp only: funpow_shift1_1)
  1.1057 +            hence "\<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1058 +              Ipoly bs p * (Ipoly bs (a^\<^sub>p (k' - k)) * Ipoly bs (funpow (degree s - n) shift1 (1)\<^sub>p) +
  1.1059 +              Ipoly bs q) + Ipoly bs r"
  1.1060 +              by (simp add: field_simps)
  1.1061 +            hence "\<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1062 +              Ipoly bs (p *\<^sub>p ((a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q) +\<^sub>p r)"
  1.1063 +              by simp
  1.1064              with isnpolyh_unique[OF nakks' nqr']
  1.1065 -            have "a ^\<^sub>p (k' - k) *\<^sub>p s = 
  1.1066 -              p *\<^sub>p ((a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q) +\<^sub>p r" by blast
  1.1067 +            have "a ^\<^sub>p (k' - k) *\<^sub>p s =
  1.1068 +              p *\<^sub>p ((a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q) +\<^sub>p r"
  1.1069 +              by blast
  1.1070              hence ?qths using nq'
  1.1071                apply (rule_tac x="(a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q" in exI)
  1.1072 -              apply (rule_tac x="0" in exI) by simp
  1.1073 +              apply (rule_tac x="0" in exI)
  1.1074 +              apply simp
  1.1075 +              done
  1.1076              with kk' nr dr have "k \<le> k' \<and> (degree r = 0 \<or> degree r < degree p) \<and> (\<exists>nr. isnpolyh r nr) \<and> ?qths"
  1.1077 -              by blast } hence ?ths by blast }
  1.1078 -        moreover 
  1.1079 -        {assume spz:"s -\<^sub>p ?p' = 0\<^sub>p"
  1.1080 +              by blast
  1.1081 +          }
  1.1082 +          hence ?ths by blast
  1.1083 +        }
  1.1084 +        moreover
  1.1085 +        { assume spz:"s -\<^sub>p ?p' = 0\<^sub>p"
  1.1086            from spz isnpolyh_unique[OF polysub_normh[OF ns np'], where q="0\<^sub>p", symmetric, where ?'a = "'a::{field_char_0, field_inverse_zero}"]
  1.1087 -          have " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs s = Ipoly bs ?p'" by simp
  1.1088 +          have " \<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs s = Ipoly bs ?p'"
  1.1089 +            by simp
  1.1090            hence "\<forall>(bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs s = Ipoly bs (?xdn *\<^sub>p p)"
  1.1091              using np nxdn
  1.1092              apply simp
  1.1093 @@ -1455,134 +1483,162 @@
  1.1094              done
  1.1095            hence sp': "s = ?xdn *\<^sub>p p" using isnpolyh_unique[OF ns polymul_normh[OF nxdn np]]
  1.1096              by blast
  1.1097 -          {assume h1: "polydivide_aux a n p k s = (k',r)"
  1.1098 +          { assume h1: "polydivide_aux a n p k s = (k',r)"
  1.1099              from polydivide_aux.simps sz dn' ba
  1.1100              have eq: "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  1.1101                by (simp add: Let_def)
  1.1102 -            also have "\<dots> = (k,0\<^sub>p)" using polydivide_aux.simps spz by simp
  1.1103 +            also have "\<dots> = (k,0\<^sub>p)"
  1.1104 +              using polydivide_aux.simps spz by simp
  1.1105              finally have "(k',r) = (k,0\<^sub>p)" using h1 by simp
  1.1106              with sp'[symmetric] ns np nxdn polyadd_0(1)[OF polymul_normh[OF np nxdn]]
  1.1107                polyadd_0(2)[OF polymul_normh[OF np nxdn]] have ?ths
  1.1108                apply auto
  1.1109 -              apply (rule exI[where x="?xdn"])        
  1.1110 +              apply (rule exI[where x="?xdn"])
  1.1111                apply (auto simp add: polymul_commute[of p])
  1.1112 -              done} }
  1.1113 -        ultimately have ?ths by blast }
  1.1114 +              done
  1.1115 +          }
  1.1116 +        }
  1.1117 +        ultimately have ?ths by blast
  1.1118 +      }
  1.1119        moreover
  1.1120 -      {assume ba: "?b \<noteq> a"
  1.1121 -        from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np0, simplified ap] ns] 
  1.1122 +      { assume ba: "?b \<noteq> a"
  1.1123 +        from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np0, simplified ap] ns]
  1.1124            polymul_normh[OF head_isnpolyh[OF ns] np']]
  1.1125 -        have nth: "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0" by(simp add: min_def)
  1.1126 +        have nth: "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0"
  1.1127 +          by (simp add: min_def)
  1.1128          have nzths: "a *\<^sub>p s \<noteq> 0\<^sub>p" "?b *\<^sub>p ?p' \<noteq> 0\<^sub>p"
  1.1129 -          using polymul_eq0_iff[OF head_isnpolyh[OF np0, simplified ap] ns] 
  1.1130 +          using polymul_eq0_iff[OF head_isnpolyh[OF np0, simplified ap] ns]
  1.1131              polymul_eq0_iff[OF head_isnpolyh[OF ns] np']head_nz[OF np0] ap pnz sz head_nz[OF ns]
  1.1132 -            funpow_shift1_nz[OF pnz] by simp_all
  1.1133 +            funpow_shift1_nz[OF pnz]
  1.1134 +          by simp_all
  1.1135          from polymul_head_polyeq[OF head_isnpolyh[OF np] ns] head_nz[OF np] sz ap head_head[OF np] pnz
  1.1136            polymul_head_polyeq[OF head_isnpolyh[OF ns] np'] head_nz [OF ns] sz funpow_shift1_nz[OF pnz, where n="degree s - n"]
  1.1137 -        have hdth: "head (a *\<^sub>p s) = head (?b *\<^sub>p ?p')" 
  1.1138 +        have hdth: "head (a *\<^sub>p s) = head (?b *\<^sub>p ?p')"
  1.1139            using head_head[OF ns] funpow_shift1_head[OF np pnz]
  1.1140              polymul_commute[OF head_isnpolyh[OF np] head_isnpolyh[OF ns]]
  1.1141            by (simp add: ap)
  1.1142          from polymul_degreen[OF head_isnpolyh[OF np] ns, where m="0"]
  1.1143            head_nz[OF np] pnz sz ap[symmetric]
  1.1144            funpow_shift1_nz[OF pnz, where n="degree s - n"]
  1.1145 -          polymul_degreen[OF head_isnpolyh[OF ns] np', where m="0"]  head_nz[OF ns]
  1.1146 +          polymul_degreen[OF head_isnpolyh[OF ns] np', where m="0"] head_nz[OF ns]
  1.1147            ndp dn
  1.1148 -        have degth: "degree (a *\<^sub>p s) = degree (?b *\<^sub>p ?p') "
  1.1149 +        have degth: "degree (a *\<^sub>p s) = degree (?b *\<^sub>p ?p')"
  1.1150            by (simp add: degree_eq_degreen0[symmetric] funpow_shift1_degree)
  1.1151 -        {assume dth: "degree ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) < degree s"
  1.1152 -          from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np] ns] polymul_normh[OF head_isnpolyh[OF ns]np']]
  1.1153 -          ap have nasbp': "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0" by simp
  1.1154 -          {assume h1:"polydivide_aux a n p k s = (k', r)"
  1.1155 +        { assume dth: "degree ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) < degree s"
  1.1156 +          from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np] ns]
  1.1157 +            polymul_normh[OF head_isnpolyh[OF ns]np']] ap
  1.1158 +          have nasbp': "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0"
  1.1159 +            by simp
  1.1160 +          { assume h1:"polydivide_aux a n p k s = (k', r)"
  1.1161              from h1 polydivide_aux.simps sz dn' ba
  1.1162              have eq:"polydivide_aux a n p (Suc k) ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) = (k',r)"
  1.1163                by (simp add: Let_def)
  1.1164              with less(1)[OF dth nasbp', of "Suc k" k' r]
  1.1165 -            obtain q nq nr where kk': "Suc k \<le> k'" and nr: "isnpolyh r nr" and nq: "isnpolyh q nq" 
  1.1166 +            obtain q nq nr where kk': "Suc k \<le> k'"
  1.1167 +              and nr: "isnpolyh r nr"
  1.1168 +              and nq: "isnpolyh q nq"
  1.1169                and dr: "degree r = 0 \<or> degree r < degree p"
  1.1170 -              and qr: "a ^\<^sub>p (k' - Suc k) *\<^sub>p ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) = p *\<^sub>p q +\<^sub>p r" by auto
  1.1171 +              and qr: "a ^\<^sub>p (k' - Suc k) *\<^sub>p ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) = p *\<^sub>p q +\<^sub>p r"
  1.1172 +              by auto
  1.1173              from kk' have kk'':"Suc (k' - Suc k) = k' - k" by arith
  1.1174 -            {fix bs:: "'a::{field_char_0, field_inverse_zero} list"
  1.1175 -              
  1.1176 -            from qr isnpolyh_unique[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k", simplified ap] nasbp', symmetric]
  1.1177 -            have "Ipoly bs (a ^\<^sub>p (k' - Suc k) *\<^sub>p ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p'))) = Ipoly bs (p *\<^sub>p q +\<^sub>p r)"
  1.1178 -              by simp
  1.1179 -            hence "Ipoly bs a ^ (Suc (k' - Suc k)) * Ipoly bs s =
  1.1180 -              Ipoly bs p * Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?p' + Ipoly bs r"
  1.1181 -              by (simp add: field_simps)
  1.1182 -            hence "Ipoly bs a ^ (k' - k)  * Ipoly bs s =
  1.1183 -              Ipoly bs p * Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn * Ipoly bs p + Ipoly bs r"
  1.1184 -              by (simp add: kk'' funpow_shift1_1[where n="degree s - n" and p="p"])
  1.1185 -            hence "Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1186 -              Ipoly bs p * (Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn) + Ipoly bs r"
  1.1187 -              by (simp add: field_simps)}
  1.1188 -            hence ieq:"\<forall>(bs :: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) = 
  1.1189 -              Ipoly bs (p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r)" by auto 
  1.1190 +            {
  1.1191 +              fix bs:: "'a::{field_char_0, field_inverse_zero} list"
  1.1192 +              from qr isnpolyh_unique[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k", simplified ap] nasbp', symmetric]
  1.1193 +              have "Ipoly bs (a ^\<^sub>p (k' - Suc k) *\<^sub>p ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p'))) = Ipoly bs (p *\<^sub>p q +\<^sub>p r)"
  1.1194 +                by simp
  1.1195 +              hence "Ipoly bs a ^ (Suc (k' - Suc k)) * Ipoly bs s =
  1.1196 +                Ipoly bs p * Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?p' + Ipoly bs r"
  1.1197 +                by (simp add: field_simps)
  1.1198 +              hence "Ipoly bs a ^ (k' - k)  * Ipoly bs s =
  1.1199 +                Ipoly bs p * Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn * Ipoly bs p + Ipoly bs r"
  1.1200 +                by (simp add: kk'' funpow_shift1_1[where n="degree s - n" and p="p"])
  1.1201 +              hence "Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1202 +                Ipoly bs p * (Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn) + Ipoly bs r"
  1.1203 +                by (simp add: field_simps)
  1.1204 +            }
  1.1205 +            hence ieq:"\<forall>(bs :: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  1.1206 +              Ipoly bs (p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r)"
  1.1207 +              by auto
  1.1208              let ?q = "q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)"
  1.1209              from polyadd_normh[OF nq polymul_normh[OF polymul_normh[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k"] head_isnpolyh[OF ns], simplified ap ] nxdn]]
  1.1210 -            have nqw: "isnpolyh ?q 0" by simp
  1.1211 +            have nqw: "isnpolyh ?q 0"
  1.1212 +              by simp
  1.1213              from ieq isnpolyh_unique[OF polymul_normh[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - k"] ns, simplified ap] polyadd_normh[OF polymul_normh[OF np nqw] nr]]
  1.1214 -            have asth: "(a ^\<^sub>p (k' - k) *\<^sub>p s) = p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r" by blast
  1.1215 -            from dr kk' nr h1 asth nqw have ?ths apply simp
  1.1216 +            have asth: "(a ^\<^sub>p (k' - k) *\<^sub>p s) = p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r"
  1.1217 +              by blast
  1.1218 +            from dr kk' nr h1 asth nqw have ?ths
  1.1219 +              apply simp
  1.1220                apply (rule conjI)
  1.1221                apply (rule exI[where x="nr"], simp)
  1.1222                apply (rule exI[where x="(q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn))"], simp)
  1.1223                apply (rule exI[where x="0"], simp)
  1.1224 -              done}
  1.1225 -          hence ?ths by blast }
  1.1226 -        moreover 
  1.1227 -        {assume spz: "a *\<^sub>p s -\<^sub>p (?b *\<^sub>p ?p') = 0\<^sub>p"
  1.1228 -          {fix bs :: "'a::{field_char_0, field_inverse_zero} list"
  1.1229 +              done
  1.1230 +          }
  1.1231 +          hence ?ths by blast
  1.1232 +        }
  1.1233 +        moreover
  1.1234 +        { assume spz: "a *\<^sub>p s -\<^sub>p (?b *\<^sub>p ?p') = 0\<^sub>p"
  1.1235 +          {
  1.1236 +            fix bs :: "'a::{field_char_0, field_inverse_zero} list"
  1.1237              from isnpolyh_unique[OF nth, where ?'a="'a" and q="0\<^sub>p",simplified,symmetric] spz
  1.1238 -          have "Ipoly bs (a*\<^sub>p s) = Ipoly bs ?b * Ipoly bs ?p'" by simp
  1.1239 -          hence "Ipoly bs (a*\<^sub>p s) = Ipoly bs (?b *\<^sub>p ?xdn) * Ipoly bs p" 
  1.1240 -            by (simp add: funpow_shift1_1[where n="degree s - n" and p="p"])
  1.1241 -          hence "Ipoly bs (a*\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))" by simp
  1.1242 -        }
  1.1243 -        hence hth: "\<forall> (bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a*\<^sub>p s) =
  1.1244 +            have "Ipoly bs (a*\<^sub>p s) = Ipoly bs ?b * Ipoly bs ?p'"
  1.1245 +              by simp
  1.1246 +            hence "Ipoly bs (a*\<^sub>p s) = Ipoly bs (?b *\<^sub>p ?xdn) * Ipoly bs p"
  1.1247 +              by (simp add: funpow_shift1_1[where n="degree s - n" and p="p"])
  1.1248 +            hence "Ipoly bs (a*\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))"
  1.1249 +              by simp
  1.1250 +          }
  1.1251 +          hence hth: "\<forall> (bs:: 'a::{field_char_0, field_inverse_zero} list). Ipoly bs (a*\<^sub>p s) =
  1.1252              Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))" ..
  1.1253 -          from hth
  1.1254 -          have asq: "a *\<^sub>p s = p *\<^sub>p (?b *\<^sub>p ?xdn)" 
  1.1255 -            using isnpolyh_unique[where ?'a = "'a::{field_char_0, field_inverse_zero}", OF polymul_normh[OF head_isnpolyh[OF np] ns] 
  1.1256 +          from hth have asq: "a *\<^sub>p s = p *\<^sub>p (?b *\<^sub>p ?xdn)"
  1.1257 +            using isnpolyh_unique[where ?'a = "'a::{field_char_0, field_inverse_zero}", OF polymul_normh[OF head_isnpolyh[OF np] ns]
  1.1258                      polymul_normh[OF np polymul_normh[OF head_isnpolyh[OF ns] nxdn]],
  1.1259                simplified ap] by simp
  1.1260 -          {assume h1: "polydivide_aux a n p k s = (k', r)"
  1.1261 -          from h1 sz ba dn' spz polydivide_aux.simps polydivide_aux.simps
  1.1262 -          have "(k',r) = (Suc k, 0\<^sub>p)" by (simp add: Let_def)
  1.1263 -          with h1 np head_isnpolyh[OF np, simplified ap] ns polymul_normh[OF head_isnpolyh[OF ns] nxdn]
  1.1264 -            polymul_normh[OF np polymul_normh[OF head_isnpolyh[OF ns] nxdn]] asq
  1.1265 -          have ?ths
  1.1266 -            apply (clarsimp simp add: Let_def)
  1.1267 -            apply (rule exI[where x="?b *\<^sub>p ?xdn"])
  1.1268 -            apply simp
  1.1269 -            apply (rule exI[where x="0"], simp)
  1.1270 -            done }
  1.1271 -        hence ?ths by blast }
  1.1272 +          { assume h1: "polydivide_aux a n p k s = (k', r)"
  1.1273 +            from h1 sz ba dn' spz polydivide_aux.simps polydivide_aux.simps
  1.1274 +            have "(k',r) = (Suc k, 0\<^sub>p)" by (simp add: Let_def)
  1.1275 +            with h1 np head_isnpolyh[OF np, simplified ap] ns polymul_normh[OF head_isnpolyh[OF ns] nxdn]
  1.1276 +              polymul_normh[OF np polymul_normh[OF head_isnpolyh[OF ns] nxdn]] asq
  1.1277 +            have ?ths
  1.1278 +              apply (clarsimp simp add: Let_def)
  1.1279 +              apply (rule exI[where x="?b *\<^sub>p ?xdn"])
  1.1280 +              apply simp
  1.1281 +              apply (rule exI[where x="0"], simp)
  1.1282 +              done
  1.1283 +          }
  1.1284 +          hence ?ths by blast
  1.1285 +        }
  1.1286          ultimately have ?ths
  1.1287            using  degree_polysub_samehead[OF polymul_normh[OF head_isnpolyh[OF np0, simplified ap] ns] polymul_normh[OF head_isnpolyh[OF ns] np'] hdth degth] polymul_degreen[OF head_isnpolyh[OF np] ns, where m="0"]
  1.1288              head_nz[OF np] pnz sz ap[symmetric]
  1.1289 -          by (simp add: degree_eq_degreen0[symmetric]) blast }
  1.1290 +          by (simp add: degree_eq_degreen0[symmetric]) blast
  1.1291 +      }
  1.1292        ultimately have ?ths by blast
  1.1293      }
  1.1294 -    ultimately have ?ths by blast }
  1.1295 +    ultimately have ?ths by blast
  1.1296 +  }
  1.1297    ultimately show ?ths by blast
  1.1298  qed
  1.1299  
  1.1300 -lemma polydivide_properties: 
  1.1301 +lemma polydivide_properties:
  1.1302    assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
  1.1303 -  and np: "isnpolyh p n0" and ns: "isnpolyh s n1" and pnz: "p \<noteq> 0\<^sub>p"
  1.1304 -  shows "(\<exists> k r. polydivide s p = (k,r) \<and> (\<exists>nr. isnpolyh r nr) \<and> (degree r = 0 \<or> degree r < degree p) 
  1.1305 -  \<and> (\<exists>q n1. isnpolyh q n1 \<and> ((polypow k (head p)) *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)))"
  1.1306 -proof-
  1.1307 -  have trv: "head p = head p" "degree p = degree p" by simp_all
  1.1308 -  from polydivide_def[where s="s" and p="p"] 
  1.1309 -  have ex: "\<exists> k r. polydivide s p = (k,r)" by auto
  1.1310 -  then obtain k r where kr: "polydivide s p = (k,r)" by blast
  1.1311 +    and np: "isnpolyh p n0" and ns: "isnpolyh s n1" and pnz: "p \<noteq> 0\<^sub>p"
  1.1312 +  shows "\<exists>k r. polydivide s p = (k,r) \<and>
  1.1313 +    (\<exists>nr. isnpolyh r nr) \<and> (degree r = 0 \<or> degree r < degree p) \<and>
  1.1314 +    (\<exists>q n1. isnpolyh q n1 \<and> ((polypow k (head p)) *\<^sub>p s = p *\<^sub>p q +\<^sub>p r))"
  1.1315 +proof -
  1.1316 +  have trv: "head p = head p" "degree p = degree p"
  1.1317 +    by simp_all
  1.1318 +  from polydivide_def[where s="s" and p="p"] have ex: "\<exists> k r. polydivide s p = (k,r)"
  1.1319 +    by auto
  1.1320 +  then obtain k r where kr: "polydivide s p = (k,r)"
  1.1321 +    by blast
  1.1322    from trans[OF meta_eq_to_obj_eq[OF polydivide_def[where s="s"and p="p"], symmetric] kr]
  1.1323      polydivide_aux_properties[OF np ns trv pnz, where k="0" and k'="k" and r="r"]
  1.1324    have "(degree r = 0 \<or> degree r < degree p) \<and>
  1.1325 -   (\<exists>nr. isnpolyh r nr) \<and> (\<exists>q n1. isnpolyh q n1 \<and> head p ^\<^sub>p k - 0 *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)" by blast
  1.1326 -  with kr show ?thesis 
  1.1327 +    (\<exists>nr. isnpolyh r nr) \<and> (\<exists>q n1. isnpolyh q n1 \<and> head p ^\<^sub>p k - 0 *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)"
  1.1328 +    by blast
  1.1329 +  with kr show ?thesis
  1.1330      apply -
  1.1331      apply (rule exI[where x="k"])
  1.1332      apply (rule exI[where x="r"])
  1.1333 @@ -1596,23 +1652,23 @@
  1.1334  definition "isnonconstant p = (\<not> isconstant p)"
  1.1335  
  1.1336  lemma isnonconstant_pnormal_iff:
  1.1337 -  assumes nc: "isnonconstant p" 
  1.1338 -  shows "pnormal (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0" 
  1.1339 +  assumes nc: "isnonconstant p"
  1.1340 +  shows "pnormal (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0"
  1.1341  proof
  1.1342 -  let ?p = "polypoly bs p"  
  1.1343 +  let ?p = "polypoly bs p"
  1.1344    assume H: "pnormal ?p"
  1.1345    have csz: "coefficients p \<noteq> []" using nc by (cases p) auto
  1.1346 -  
  1.1347 -  from coefficients_head[of p] last_map[OF csz, of "Ipoly bs"]  
  1.1348 +
  1.1349 +  from coefficients_head[of p] last_map[OF csz, of "Ipoly bs"]
  1.1350      pnormal_last_nonzero[OF H]
  1.1351    show "Ipoly bs (head p) \<noteq> 0" by (simp add: polypoly_def)
  1.1352  next
  1.1353    assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  1.1354    let ?p = "polypoly bs p"
  1.1355    have csz: "coefficients p \<noteq> []" using nc by (cases p) auto
  1.1356 -  hence pz: "?p \<noteq> []" by (simp add: polypoly_def) 
  1.1357 +  hence pz: "?p \<noteq> []" by (simp add: polypoly_def)
  1.1358    hence lg: "length ?p > 0" by simp
  1.1359 -  from h coefficients_head[of p] last_map[OF csz, of "Ipoly bs"] 
  1.1360 +  from h coefficients_head[of p] last_map[OF csz, of "Ipoly bs"]
  1.1361    have lz: "last ?p \<noteq> 0" by (simp add: polypoly_def)
  1.1362    from pnormal_last_length[OF lg lz] show "pnormal ?p" .
  1.1363  qed
  1.1364 @@ -1638,10 +1694,10 @@
  1.1365    assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  1.1366    from isnonconstant_pnormal_iff[OF inc, of bs] h
  1.1367    have pn: "pnormal ?p" by blast
  1.1368 -  {fix x assume H: "?p = [x]" 
  1.1369 +  { fix x assume H: "?p = [x]"
  1.1370      from H have "length (coefficients p) = 1" unfolding polypoly_def by auto
  1.1371 -    with isnonconstant_coefficients_length[OF inc] have False by arith}
  1.1372 -  thus "nonconstant ?p" using pn unfolding nonconstant_def by blast  
  1.1373 +    with isnonconstant_coefficients_length[OF inc] have False by arith }
  1.1374 +  thus "nonconstant ?p" using pn unfolding nonconstant_def by blast
  1.1375  qed
  1.1376  
  1.1377  lemma pnormal_length: "p\<noteq>[] \<Longrightarrow> pnormal p \<longleftrightarrow> length (pnormalize p) = length p"
  1.1378 @@ -1655,29 +1711,29 @@
  1.1379    assumes inc: "isnonconstant p"
  1.1380    shows "degree p = Polynomial_List.degree (polypoly bs p) \<longleftrightarrow> \<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  1.1381  proof
  1.1382 -  let  ?p = "polypoly bs p"
  1.1383 +  let ?p = "polypoly bs p"
  1.1384    assume H: "degree p = Polynomial_List.degree ?p"
  1.1385    from isnonconstant_coefficients_length[OF inc] have pz: "?p \<noteq> []"
  1.1386      unfolding polypoly_def by auto
  1.1387    from H degree_coefficients[of p] isnonconstant_coefficients_length[OF inc]
  1.1388    have lg:"length (pnormalize ?p) = length ?p"
  1.1389      unfolding Polynomial_List.degree_def polypoly_def by simp
  1.1390 -  hence "pnormal ?p" using pnormal_length[OF pz] by blast 
  1.1391 -  with isnonconstant_pnormal_iff[OF inc]  
  1.1392 +  hence "pnormal ?p" using pnormal_length[OF pz] by blast
  1.1393 +  with isnonconstant_pnormal_iff[OF inc]
  1.1394    show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0" by blast
  1.1395  next
  1.1396 -  let  ?p = "polypoly bs p"  
  1.1397 +  let  ?p = "polypoly bs p"
  1.1398    assume H: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  1.1399    with isnonconstant_pnormal_iff[OF inc] have "pnormal ?p" by blast
  1.1400    with degree_coefficients[of p] isnonconstant_coefficients_length[OF inc]
  1.1401 -  show "degree p = Polynomial_List.degree ?p" 
  1.1402 +  show "degree p = Polynomial_List.degree ?p"
  1.1403      unfolding polypoly_def pnormal_def Polynomial_List.degree_def by auto
  1.1404  qed
  1.1405  
  1.1406  
  1.1407 -section{* Swaps ; Division by a certain variable *}
  1.1408 +section {* Swaps ; Division by a certain variable *}
  1.1409  
  1.1410 -primrec swap:: "nat \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> poly" where
  1.1411 +primrec swap :: "nat \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> poly" where
  1.1412    "swap n m (C x) = C x"
  1.1413  | "swap n m (Bound k) = Bound (if k = n then m else if k=m then n else k)"
  1.1414  | "swap n m (Neg t) = Neg (swap n m t)"
  1.1415 @@ -1685,8 +1741,8 @@
  1.1416  | "swap n m (Sub s t) = Sub (swap n m s) (swap n m t)"
  1.1417  | "swap n m (Mul s t) = Mul (swap n m s) (swap n m t)"
  1.1418  | "swap n m (Pw t k) = Pw (swap n m t) k"
  1.1419 -| "swap n m (CN c k p) = CN (swap n m c) (if k = n then m else if k=m then n else k)
  1.1420 -  (swap n m p)"
  1.1421 +| "swap n m (CN c k p) =
  1.1422 +    CN (swap n m c) (if k = n then m else if k=m then n else k) (swap n m p)"
  1.1423  
  1.1424  lemma swap:
  1.1425    assumes nbs: "n < length bs"
  1.1426 @@ -1694,10 +1750,10 @@
  1.1427    shows "Ipoly bs (swap n m t) = Ipoly ((bs[n:= bs!m])[m:= bs!n]) t"
  1.1428  proof (induct t)
  1.1429    case (Bound k)
  1.1430 -  thus ?case using nbs mbs by simp 
  1.1431 +  thus ?case using nbs mbs by simp
  1.1432  next
  1.1433    case (CN c k p)
  1.1434 -  thus ?case using nbs mbs by simp 
  1.1435 +  thus ?case using nbs mbs by simp
  1.1436  qed simp_all
  1.1437  
  1.1438  lemma swap_swap_id [simp]: "swap n m (swap m n t) = t"
  1.1439 @@ -1723,9 +1779,9 @@
  1.1440    shows "isnpoly (swapnorm n m p)"
  1.1441    unfolding swapnorm_def by simp
  1.1442  
  1.1443 -definition "polydivideby n s p = 
  1.1444 +definition "polydivideby n s p =
  1.1445    (let ss = swapnorm 0 n s ; sp = swapnorm 0 n p ; h = head sp; (k,r) = polydivide ss sp
  1.1446 -   in (k,swapnorm 0 n h,swapnorm 0 n r))"
  1.1447 +   in (k, swapnorm 0 n h,swapnorm 0 n r))"
  1.1448  
  1.1449  lemma swap_nz [simp]: " (swap n m p = 0\<^sub>p) = (p = 0\<^sub>p)"
  1.1450    by (induct p) simp_all
  1.1451 @@ -1736,10 +1792,10 @@
  1.1452  | "isweaknpoly (CN c n p) \<longleftrightarrow> isweaknpoly c \<and> isweaknpoly p"
  1.1453  | "isweaknpoly p = False"
  1.1454  
  1.1455 -lemma isnpolyh_isweaknpoly: "isnpolyh p n0 \<Longrightarrow> isweaknpoly p" 
  1.1456 +lemma isnpolyh_isweaknpoly: "isnpolyh p n0 \<Longrightarrow> isweaknpoly p"
  1.1457    by (induct p arbitrary: n0) auto
  1.1458  
  1.1459 -lemma swap_isweanpoly: "isweaknpoly p \<Longrightarrow> isweaknpoly (swap n m p)" 
  1.1460 +lemma swap_isweanpoly: "isweaknpoly p \<Longrightarrow> isweaknpoly (swap n m p)"
  1.1461    by (induct p) auto
  1.1462  
  1.1463  end
  1.1464 \ No newline at end of file