misc tuning and modernization;
authorwenzelm
Sun Dec 03 22:28:19 2017 +0100 (10 months ago)
changeset 671233fe40ff1b921
parent 67122 85b40f300fab
child 67124 335ed2834ebc
child 67125 361b3ef643a7
misc tuning and modernization;
src/HOL/Decision_Procs/Algebra_Aux.thy
src/HOL/Decision_Procs/Commutative_Ring.thy
src/HOL/Decision_Procs/Commutative_Ring_Complete.thy
src/HOL/Decision_Procs/Cooper.thy
src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy
src/HOL/Decision_Procs/Rat_Pair.thy
src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy
src/HOL/Decision_Procs/Reflective_Field.thy
src/HOL/Decision_Procs/ex/Commutative_Ring_Ex.thy
     1.1 --- a/src/HOL/Decision_Procs/Algebra_Aux.thy	Sun Dec 03 19:09:42 2017 +0100
     1.2 +++ b/src/HOL/Decision_Procs/Algebra_Aux.thy	Sun Dec 03 22:28:19 2017 +0100
     1.3 @@ -5,16 +5,17 @@
     1.4  section \<open>Things that can be added to the Algebra library\<close>
     1.5  
     1.6  theory Algebra_Aux
     1.7 -imports "HOL-Algebra.Ring"
     1.8 +  imports "HOL-Algebra.Ring"
     1.9  begin
    1.10  
    1.11 -definition of_natural :: "('a, 'm) ring_scheme \<Rightarrow> nat \<Rightarrow> 'a" ("\<guillemotleft>_\<guillemotright>\<^sub>\<nat>\<index>") where
    1.12 -  "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub> = (op \<oplus>\<^bsub>R\<^esub> \<one>\<^bsub>R\<^esub> ^^ n) \<zero>\<^bsub>R\<^esub>"
    1.13 +definition of_natural :: "('a, 'm) ring_scheme \<Rightarrow> nat \<Rightarrow> 'a" ("\<guillemotleft>_\<guillemotright>\<^sub>\<nat>\<index>")
    1.14 +  where "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub> = (op \<oplus>\<^bsub>R\<^esub> \<one>\<^bsub>R\<^esub> ^^ n) \<zero>\<^bsub>R\<^esub>"
    1.15  
    1.16 -definition of_integer :: "('a, 'm) ring_scheme \<Rightarrow> int \<Rightarrow> 'a" ("\<guillemotleft>_\<guillemotright>\<index>") where
    1.17 -  "\<guillemotleft>i\<guillemotright>\<^bsub>R\<^esub> = (if 0 \<le> i then \<guillemotleft>nat i\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub> else \<ominus>\<^bsub>R\<^esub> \<guillemotleft>nat (- i)\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub>)"
    1.18 +definition of_integer :: "('a, 'm) ring_scheme \<Rightarrow> int \<Rightarrow> 'a" ("\<guillemotleft>_\<guillemotright>\<index>")
    1.19 +  where "\<guillemotleft>i\<guillemotright>\<^bsub>R\<^esub> = (if 0 \<le> i then \<guillemotleft>nat i\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub> else \<ominus>\<^bsub>R\<^esub> \<guillemotleft>nat (- i)\<guillemotright>\<^sub>\<nat>\<^bsub>R\<^esub>)"
    1.20  
    1.21 -context ring begin
    1.22 +context ring
    1.23 +begin
    1.24  
    1.25  lemma of_nat_0 [simp]: "\<guillemotleft>0\<guillemotright>\<^sub>\<nat> = \<zero>"
    1.26    by (simp add: of_natural_def)
    1.27 @@ -39,10 +40,16 @@
    1.28  
    1.29  lemma of_nat_diff [simp]: "n \<le> m \<Longrightarrow> \<guillemotleft>m - n\<guillemotright>\<^sub>\<nat> = \<guillemotleft>m\<guillemotright>\<^sub>\<nat> \<ominus> \<guillemotleft>n\<guillemotright>\<^sub>\<nat>"
    1.30  proof (induct m arbitrary: n)
    1.31 -  case (Suc m)
    1.32 -  note Suc' = this
    1.33 +  case 0
    1.34 +  then show ?case by (simp add: minus_eq)
    1.35 +next
    1.36 +  case Suc': (Suc m)
    1.37    show ?case
    1.38    proof (cases n)
    1.39 +    case 0
    1.40 +    then show ?thesis
    1.41 +      by (simp add: minus_eq)
    1.42 +  next
    1.43      case (Suc k)
    1.44      with Suc' have "\<guillemotleft>Suc m - Suc k\<guillemotright>\<^sub>\<nat> = \<guillemotleft>m\<guillemotright>\<^sub>\<nat> \<ominus> \<guillemotleft>k\<guillemotright>\<^sub>\<nat>" by simp
    1.45      also have "\<dots> = \<one> \<oplus> \<ominus> \<one> \<oplus> (\<guillemotleft>m\<guillemotright>\<^sub>\<nat> \<ominus> \<guillemotleft>k\<guillemotright>\<^sub>\<nat>)"
    1.46 @@ -50,8 +57,8 @@
    1.47      also have "\<dots> = \<guillemotleft>Suc m\<guillemotright>\<^sub>\<nat> \<ominus> \<guillemotleft>Suc k\<guillemotright>\<^sub>\<nat>"
    1.48        by (simp add: minus_eq minus_add a_ac)
    1.49      finally show ?thesis using Suc by simp
    1.50 -  qed (simp add: minus_eq)
    1.51 -qed (simp add: minus_eq)
    1.52 +  qed
    1.53 +qed
    1.54  
    1.55  lemma of_int_add [simp]: "\<guillemotleft>i + j\<guillemotright> = \<guillemotleft>i\<guillemotright> \<oplus> \<guillemotleft>j\<guillemotright>"
    1.56  proof (cases "0 \<le> i")
    1.57 @@ -59,7 +66,8 @@
    1.58    show ?thesis
    1.59    proof (cases "0 \<le> j")
    1.60      case True
    1.61 -    with \<open>0 \<le> i\<close> show ?thesis by (simp add: of_integer_def nat_add_distrib)
    1.62 +    with \<open>0 \<le> i\<close> show ?thesis
    1.63 +      by (simp add: of_integer_def nat_add_distrib)
    1.64    next
    1.65      case False
    1.66      show ?thesis
    1.67 @@ -112,7 +120,7 @@
    1.68      case False
    1.69      with \<open>\<not> 0 \<le> i\<close> show ?thesis
    1.70        by (simp add: of_integer_def nat_add_distrib minus_add diff_conv_add_uminus
    1.71 -        del: add_uminus_conv_diff uminus_add_conv_diff)
    1.72 +          del: add_uminus_conv_diff uminus_add_conv_diff)
    1.73    qed
    1.74  qed
    1.75  
    1.76 @@ -171,7 +179,7 @@
    1.77  
    1.78  lemma eq_diff0:
    1.79    assumes "x \<in> carrier R" "y \<in> carrier R"
    1.80 -  shows "(x \<ominus> y = \<zero>) = (x = y)"
    1.81 +  shows "x \<ominus> y = \<zero> \<longleftrightarrow> x = y"
    1.82  proof
    1.83    assume "x \<ominus> y = \<zero>"
    1.84    with assms have "x \<oplus> (\<ominus> y \<oplus> y) = y"
    1.85 @@ -187,7 +195,7 @@
    1.86  
    1.87  lemma eq_neg_iff_add_eq_0:
    1.88    assumes "x \<in> carrier R" "y \<in> carrier R"
    1.89 -  shows "(x = \<ominus> y) = (x \<oplus> y = \<zero>)"
    1.90 +  shows "x = \<ominus> y \<longleftrightarrow> x \<oplus> y = \<zero>"
    1.91  proof
    1.92    assume "x = \<ominus> y"
    1.93    with assms show "x \<oplus> y = \<zero>" by (simp add: l_neg)
    1.94 @@ -201,7 +209,7 @@
    1.95  
    1.96  lemma neg_equal_iff_equal:
    1.97    assumes x: "x \<in> carrier R" and y: "y \<in> carrier R"
    1.98 -  shows "(\<ominus> x = \<ominus> y) = (x = y)"
    1.99 +  shows "\<ominus> x = \<ominus> y \<longleftrightarrow> x = y"
   1.100  proof
   1.101    assume "\<ominus> x = \<ominus> y"
   1.102    then have "\<ominus> (\<ominus> x) = \<ominus> (\<ominus> y)" by simp
   1.103 @@ -225,8 +233,8 @@
   1.104  lemma (in cring) of_int_power [simp]: "\<guillemotleft>i ^ n\<guillemotright> = \<guillemotleft>i\<guillemotright> (^) n"
   1.105    by (induct n) (simp_all add: m_ac)
   1.106  
   1.107 -definition cring_class_ops :: "'a::comm_ring_1 ring" where
   1.108 -  "cring_class_ops \<equiv> \<lparr>carrier = UNIV, mult = op *, one = 1, zero = 0, add = op +\<rparr>"
   1.109 +definition cring_class_ops :: "'a::comm_ring_1 ring"
   1.110 +  where "cring_class_ops \<equiv> \<lparr>carrier = UNIV, mult = op *, one = 1, zero = 0, add = op +\<rparr>"
   1.111  
   1.112  lemma cring_class: "cring cring_class_ops"
   1.113    apply unfold_locales
   1.114 @@ -274,17 +282,16 @@
   1.115    times_class power_class of_nat_class of_int_class carrier_class
   1.116  
   1.117  interpretation cring_class: cring "cring_class_ops::'a::comm_ring_1 ring"
   1.118 -  rewrites
   1.119 -    "(\<zero>\<^bsub>cring_class_ops\<^esub>::'a) = 0" and
   1.120 -    "(\<one>\<^bsub>cring_class_ops\<^esub>::'a) = 1" and
   1.121 -    "(x::'a) \<oplus>\<^bsub>cring_class_ops\<^esub> y = x + y" and
   1.122 -    "(x::'a) \<otimes>\<^bsub>cring_class_ops\<^esub> y = x * y" and
   1.123 -    "\<ominus>\<^bsub>cring_class_ops\<^esub> (x::'a) = - x" and
   1.124 -    "(x::'a) \<ominus>\<^bsub>cring_class_ops\<^esub> y = x - y" and
   1.125 -    "(x::'a) (^)\<^bsub>cring_class_ops\<^esub> n = x ^ n" and
   1.126 -    "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>cring_class_ops\<^esub> = of_nat n" and
   1.127 -    "((\<guillemotleft>i\<guillemotright>\<^bsub>cring_class_ops\<^esub>)::'a) = of_int i" and
   1.128 -    "(Int.of_int (numeral m)::'a) = numeral m"
   1.129 +  rewrites "(\<zero>\<^bsub>cring_class_ops\<^esub>::'a) = 0"
   1.130 +    and "(\<one>\<^bsub>cring_class_ops\<^esub>::'a) = 1"
   1.131 +    and "(x::'a) \<oplus>\<^bsub>cring_class_ops\<^esub> y = x + y"
   1.132 +    and "(x::'a) \<otimes>\<^bsub>cring_class_ops\<^esub> y = x * y"
   1.133 +    and "\<ominus>\<^bsub>cring_class_ops\<^esub> (x::'a) = - x"
   1.134 +    and "(x::'a) \<ominus>\<^bsub>cring_class_ops\<^esub> y = x - y"
   1.135 +    and "(x::'a) (^)\<^bsub>cring_class_ops\<^esub> n = x ^ n"
   1.136 +    and "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>cring_class_ops\<^esub> = of_nat n"
   1.137 +    and "((\<guillemotleft>i\<guillemotright>\<^bsub>cring_class_ops\<^esub>)::'a) = of_int i"
   1.138 +    and "(Int.of_int (numeral m)::'a) = numeral m"
   1.139    by (simp_all add: cring_class class_simps)
   1.140  
   1.141  lemma (in domain) nat_pow_eq_0_iff [simp]:
   1.142 @@ -302,12 +309,12 @@
   1.143      by (simp add: integral_iff eq_neg_iff_add_eq_0 eq_diff0 r_neg)
   1.144  next
   1.145    assume "x = y \<or> x = \<ominus> y"
   1.146 -  with assms show "x \<otimes> x = y \<otimes> y" by (auto simp add: l_minus r_minus)
   1.147 +  with assms show "x \<otimes> x = y \<otimes> y"
   1.148 +    by (auto simp add: l_minus r_minus)
   1.149  qed
   1.150  
   1.151 -definition
   1.152 -  m_div :: "('a, 'b) ring_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<oslash>\<index>" 70) where
   1.153 -  "x \<oslash>\<^bsub>G\<^esub> y = (if y = \<zero>\<^bsub>G\<^esub> then \<zero>\<^bsub>G\<^esub> else x \<otimes>\<^bsub>G\<^esub> inv\<^bsub>G\<^esub> y)"
   1.154 +definition m_div :: "('a, 'b) ring_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<oslash>\<index>" 70)
   1.155 +  where "x \<oslash>\<^bsub>G\<^esub> y = (if y = \<zero>\<^bsub>G\<^esub> then \<zero>\<^bsub>G\<^esub> else x \<otimes>\<^bsub>G\<^esub> inv\<^bsub>G\<^esub> y)"
   1.156  
   1.157  context field
   1.158  begin
   1.159 @@ -323,58 +330,62 @@
   1.160  
   1.161  lemma inverse_unique:
   1.162    assumes a: "a \<in> carrier R"
   1.163 -  and b: "b \<in> carrier R"
   1.164 -  and ab: "a \<otimes> b = \<one>"
   1.165 +    and b: "b \<in> carrier R"
   1.166 +    and ab: "a \<otimes> b = \<one>"
   1.167    shows "inv a = b"
   1.168  proof -
   1.169 -  have "a \<noteq> \<zero>" using ab b by (cases "a = \<zero>") simp_all
   1.170 -  moreover with a have "inv a \<otimes> (a \<otimes> b) = inv a" by (simp add: ab)
   1.171 -  ultimately show ?thesis using a b by (simp add: m_assoc [symmetric])
   1.172 +  from ab b have *: "a \<noteq> \<zero>"
   1.173 +    by (cases "a = \<zero>") simp_all
   1.174 +  with a have "inv a \<otimes> (a \<otimes> b) = inv a"
   1.175 +    by (simp add: ab)
   1.176 +  with a b * show ?thesis
   1.177 +    by (simp add: m_assoc [symmetric])
   1.178  qed
   1.179  
   1.180 -lemma nonzero_inverse_inverse_eq:
   1.181 -  "a \<in> carrier R \<Longrightarrow> a \<noteq> \<zero> \<Longrightarrow> inv (inv a) = a"
   1.182 +lemma nonzero_inverse_inverse_eq: "a \<in> carrier R \<Longrightarrow> a \<noteq> \<zero> \<Longrightarrow> inv (inv a) = a"
   1.183    by (rule inverse_unique) simp_all
   1.184  
   1.185  lemma inv_1 [simp]: "inv \<one> = \<one>"
   1.186    by (rule inverse_unique) simp_all
   1.187  
   1.188  lemma nonzero_inverse_mult_distrib:
   1.189 -  assumes "a \<in> carrier R" and "b \<in> carrier R" and "a \<noteq> \<zero>" and "b \<noteq> \<zero>"
   1.190 +  assumes "a \<in> carrier R" "b \<in> carrier R"
   1.191 +    and "a \<noteq> \<zero>" "b \<noteq> \<zero>"
   1.192    shows "inv (a \<otimes> b) = inv b \<otimes> inv a"
   1.193  proof -
   1.194 -  have "a \<otimes> (b \<otimes> inv b) \<otimes> inv a = \<one>" using assms by simp
   1.195 -  hence eq: "a \<otimes> b \<otimes> (inv b \<otimes> inv a) = \<one>" using assms
   1.196 +  from assms have "a \<otimes> (b \<otimes> inv b) \<otimes> inv a = \<one>"
   1.197 +    by simp
   1.198 +  with assms have eq: "a \<otimes> b \<otimes> (inv b \<otimes> inv a) = \<one>"
   1.199      by (simp only: m_assoc m_closed inv_closed assms)
   1.200 -  from inverse_unique [OF _ _ eq] assms
   1.201 -  show ?thesis by simp
   1.202 +  from assms show ?thesis
   1.203 +    using inverse_unique [OF _ _ eq] by simp
   1.204  qed
   1.205  
   1.206  lemma nonzero_imp_inverse_nonzero:
   1.207    assumes "a \<in> carrier R" and "a \<noteq> \<zero>"
   1.208    shows "inv a \<noteq> \<zero>"
   1.209  proof
   1.210 -  assume ianz: "inv a = \<zero>"
   1.211 -  from assms
   1.212 -  have "\<one> = a \<otimes> inv a" by simp
   1.213 -  also with assms have "... = \<zero>" by (simp add: ianz)
   1.214 +  assume *: "inv a = \<zero>"
   1.215 +  from assms have **: "\<one> = a \<otimes> inv a"
   1.216 +    by simp
   1.217 +  also from assms have "\<dots> = \<zero>" by (simp add: *)
   1.218    finally have "\<one> = \<zero>" .
   1.219 -  thus False by (simp add: eq_commute)
   1.220 +  then show False by (simp add: eq_commute)
   1.221  qed
   1.222  
   1.223  lemma nonzero_divide_divide_eq_left:
   1.224    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> c \<in> carrier R \<Longrightarrow> b \<noteq> \<zero> \<Longrightarrow> c \<noteq> \<zero> \<Longrightarrow>
   1.225 -   a \<oslash> b \<oslash> c = a \<oslash> (b \<otimes> c)"
   1.226 +    a \<oslash> b \<oslash> c = a \<oslash> (b \<otimes> c)"
   1.227    by (simp add: m_div_def nonzero_inverse_mult_distrib m_ac integral_iff)
   1.228  
   1.229  lemma nonzero_times_divide_eq:
   1.230    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> c \<in> carrier R \<Longrightarrow> d \<in> carrier R \<Longrightarrow>
   1.231 -   b \<noteq> \<zero> \<Longrightarrow> d \<noteq> \<zero> \<Longrightarrow> (a \<oslash> b) \<otimes> (c \<oslash> d) = (a \<otimes> c) \<oslash> (b \<otimes> d)"
   1.232 +    b \<noteq> \<zero> \<Longrightarrow> d \<noteq> \<zero> \<Longrightarrow> (a \<oslash> b) \<otimes> (c \<oslash> d) = (a \<otimes> c) \<oslash> (b \<otimes> d)"
   1.233    by (simp add: m_div_def nonzero_inverse_mult_distrib m_ac integral_iff)
   1.234  
   1.235  lemma nonzero_divide_divide_eq:
   1.236    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> c \<in> carrier R \<Longrightarrow> d \<in> carrier R \<Longrightarrow>
   1.237 -   b \<noteq> \<zero> \<Longrightarrow> c \<noteq> \<zero> \<Longrightarrow> d \<noteq> \<zero> \<Longrightarrow> (a \<oslash> b) \<oslash> (c \<oslash> d) = (a \<otimes> d) \<oslash> (b \<otimes> c)"
   1.238 +    b \<noteq> \<zero> \<Longrightarrow> c \<noteq> \<zero> \<Longrightarrow> d \<noteq> \<zero> \<Longrightarrow> (a \<oslash> b) \<oslash> (c \<oslash> d) = (a \<otimes> d) \<oslash> (b \<otimes> c)"
   1.239    by (simp add: m_div_def nonzero_inverse_mult_distrib
   1.240      nonzero_imp_inverse_nonzero nonzero_inverse_inverse_eq m_ac integral_iff)
   1.241  
   1.242 @@ -382,8 +393,8 @@
   1.243    by (simp add: m_div_def)
   1.244  
   1.245  lemma add_frac_eq:
   1.246 -  assumes "x \<in> carrier R" and "y \<in> carrier R" and "z \<in> carrier R" and "w \<in> carrier R"
   1.247 -  and "y \<noteq> \<zero>" and "z \<noteq> \<zero>"
   1.248 +  assumes "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R" "w \<in> carrier R"
   1.249 +    and "y \<noteq> \<zero>" "z \<noteq> \<zero>"
   1.250    shows "x \<oslash> y \<oplus> w \<oslash> z = (x \<otimes> z \<oplus> w \<otimes> y) \<oslash> (y \<otimes> z)"
   1.251  proof -
   1.252    from assms
   1.253 @@ -403,57 +414,56 @@
   1.254    by (simp add: m_div_def l_minus)
   1.255  
   1.256  lemma diff_frac_eq:
   1.257 -  assumes "x \<in> carrier R" and "y \<in> carrier R" and "z \<in> carrier R" and "w \<in> carrier R"
   1.258 -  and "y \<noteq> \<zero>" and "z \<noteq> \<zero>"
   1.259 +  assumes "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R" "w \<in> carrier R"
   1.260 +    and "y \<noteq> \<zero>" "z \<noteq> \<zero>"
   1.261    shows "x \<oslash> y \<ominus> w \<oslash> z = (x \<otimes> z \<ominus> w \<otimes> y) \<oslash> (y \<otimes> z)"
   1.262 -  using assms
   1.263 -  by (simp add: minus_eq l_minus add_frac_eq)
   1.264 +  using assms by (simp add: minus_eq l_minus add_frac_eq)
   1.265  
   1.266  lemma nonzero_mult_divide_mult_cancel_left [simp]:
   1.267 -  assumes "a \<in> carrier R" and "b \<in> carrier R" and "c \<in> carrier R"
   1.268 -  and "b \<noteq> \<zero>" and "c \<noteq> \<zero>"
   1.269 +  assumes "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
   1.270 +    and "b \<noteq> \<zero>" "c \<noteq> \<zero>"
   1.271    shows "(c \<otimes> a) \<oslash> (c \<otimes> b) = a \<oslash> b"
   1.272  proof -
   1.273    from assms have "(c \<otimes> a) \<oslash> (c \<otimes> b) = c \<otimes> a \<otimes> (inv b \<otimes> inv c)"
   1.274      by (simp add: m_div_def nonzero_inverse_mult_distrib integral_iff)
   1.275    also from assms have "\<dots> =  a \<otimes> inv b \<otimes> (inv c \<otimes> c)"
   1.276      by (simp add: m_ac)
   1.277 -  also from assms have "\<dots> =  a \<otimes> inv b" by simp
   1.278 -  finally show ?thesis using assms by (simp add: m_div_def)
   1.279 +  also from assms have "\<dots> =  a \<otimes> inv b"
   1.280 +    by simp
   1.281 +  finally show ?thesis
   1.282 +    using assms by (simp add: m_div_def)
   1.283  qed
   1.284  
   1.285  lemma times_divide_eq_left [simp]:
   1.286    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> c \<in> carrier R \<Longrightarrow> c \<noteq> \<zero> \<Longrightarrow>
   1.287 -   (b \<oslash> c) \<otimes> a = b \<otimes> a \<oslash> c"
   1.288 +    (b \<oslash> c) \<otimes> a = b \<otimes> a \<oslash> c"
   1.289    by (simp add: m_div_def m_ac)
   1.290  
   1.291  lemma times_divide_eq_right [simp]:
   1.292    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> c \<in> carrier R \<Longrightarrow> c \<noteq> \<zero> \<Longrightarrow>
   1.293 -   a \<otimes> (b \<oslash> c) = a \<otimes> b \<oslash> c"
   1.294 +    a \<otimes> (b \<oslash> c) = a \<otimes> b \<oslash> c"
   1.295    by (simp add: m_div_def m_ac)
   1.296  
   1.297  lemma nonzero_power_divide:
   1.298    "a \<in> carrier R \<Longrightarrow> b \<in> carrier R \<Longrightarrow> b \<noteq> \<zero> \<Longrightarrow>
   1.299 -   (a \<oslash> b) (^) (n::nat) = a (^) n \<oslash> b (^) n"
   1.300 +    (a \<oslash> b) (^) (n::nat) = a (^) n \<oslash> b (^) n"
   1.301    by (induct n) (simp_all add: nonzero_divide_divide_eq_left)
   1.302  
   1.303  lemma r_diff_distr:
   1.304    "x \<in> carrier R \<Longrightarrow> y \<in> carrier R \<Longrightarrow> z \<in> carrier R \<Longrightarrow>
   1.305 -   z \<otimes> (x \<ominus> y) = z \<otimes> x \<ominus> z \<otimes> y"
   1.306 +    z \<otimes> (x \<ominus> y) = z \<otimes> x \<ominus> z \<otimes> y"
   1.307    by (simp add: minus_eq r_distr r_minus)
   1.308  
   1.309 -lemma divide_zero_left [simp]:
   1.310 -  "a \<in> carrier R \<Longrightarrow> a \<noteq> \<zero> \<Longrightarrow> \<zero> \<oslash> a = \<zero>"
   1.311 +lemma divide_zero_left [simp]: "a \<in> carrier R \<Longrightarrow> a \<noteq> \<zero> \<Longrightarrow> \<zero> \<oslash> a = \<zero>"
   1.312    by (simp add: m_div_def)
   1.313  
   1.314  lemma divide_self: "a \<in> carrier R \<Longrightarrow> a \<noteq> \<zero> \<Longrightarrow> a \<oslash> a = \<one>"
   1.315    by (simp add: m_div_def)
   1.316  
   1.317  lemma divide_eq_0_iff:
   1.318 -  assumes "a \<in> carrier R"
   1.319 -  and "b \<in> carrier R"
   1.320 -  and "b \<noteq> \<zero>"
   1.321 -  shows "(a \<oslash> b = \<zero>) = (a = \<zero>)"
   1.322 +  assumes "a \<in> carrier R" "b \<in> carrier R"
   1.323 +    and "b \<noteq> \<zero>"
   1.324 +  shows "a \<oslash> b = \<zero> \<longleftrightarrow> a = \<zero>"
   1.325  proof
   1.326    assume "a = \<zero>"
   1.327    with assms show "a \<oslash> b = \<zero>" by simp
   1.328 @@ -471,7 +481,7 @@
   1.329  
   1.330  lemma field_class: "field (cring_class_ops::'a::field ring)"
   1.331    apply unfold_locales
   1.332 -  apply (simp_all add: cring_class_ops_def)
   1.333 +    apply (simp_all add: cring_class_ops_def)
   1.334    apply (auto simp add: Units_def)
   1.335    apply (rule_tac x="1 / x" in exI)
   1.336    apply simp
   1.337 @@ -481,25 +491,24 @@
   1.338    apply (simp add: m_div_def m_inv_def class_simps)
   1.339    apply (rule impI)
   1.340    apply (rule ssubst [OF the_equality, of _ "1 / y"])
   1.341 -  apply simp_all
   1.342 +    apply simp_all
   1.343    apply (drule conjunct2)
   1.344    apply (drule_tac f="\<lambda>x. x / y" in arg_cong)
   1.345    apply simp
   1.346    done
   1.347  
   1.348  interpretation field_class: field "cring_class_ops::'a::field ring"
   1.349 -  rewrites
   1.350 -    "(\<zero>\<^bsub>cring_class_ops\<^esub>::'a) = 0" and
   1.351 -    "(\<one>\<^bsub>cring_class_ops\<^esub>::'a) = 1" and
   1.352 -    "(x::'a) \<oplus>\<^bsub>cring_class_ops\<^esub> y = x + y" and
   1.353 -    "(x::'a) \<otimes>\<^bsub>cring_class_ops\<^esub> y = x * y" and
   1.354 -    "\<ominus>\<^bsub>cring_class_ops\<^esub> (x::'a) = - x" and
   1.355 -    "(x::'a) \<ominus>\<^bsub>cring_class_ops\<^esub> y = x - y" and
   1.356 -    "(x::'a) (^)\<^bsub>cring_class_ops\<^esub> n = x ^ n" and
   1.357 -    "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>cring_class_ops\<^esub> = of_nat n" and
   1.358 -    "((\<guillemotleft>i\<guillemotright>\<^bsub>cring_class_ops\<^esub>)::'a) = of_int i" and
   1.359 -    "(x::'a) \<oslash>\<^bsub>cring_class_ops\<^esub> y = x / y" and
   1.360 -    "(Int.of_int (numeral m)::'a) = numeral m"
   1.361 +  rewrites "(\<zero>\<^bsub>cring_class_ops\<^esub>::'a) = 0"
   1.362 +    and "(\<one>\<^bsub>cring_class_ops\<^esub>::'a) = 1"
   1.363 +    and "(x::'a) \<oplus>\<^bsub>cring_class_ops\<^esub> y = x + y"
   1.364 +    and "(x::'a) \<otimes>\<^bsub>cring_class_ops\<^esub> y = x * y"
   1.365 +    and "\<ominus>\<^bsub>cring_class_ops\<^esub> (x::'a) = - x"
   1.366 +    and "(x::'a) \<ominus>\<^bsub>cring_class_ops\<^esub> y = x - y"
   1.367 +    and "(x::'a) (^)\<^bsub>cring_class_ops\<^esub> n = x ^ n"
   1.368 +    and "\<guillemotleft>n\<guillemotright>\<^sub>\<nat>\<^bsub>cring_class_ops\<^esub> = of_nat n"
   1.369 +    and "((\<guillemotleft>i\<guillemotright>\<^bsub>cring_class_ops\<^esub>)::'a) = of_int i"
   1.370 +    and "(x::'a) \<oslash>\<^bsub>cring_class_ops\<^esub> y = x / y"
   1.371 +    and "(Int.of_int (numeral m)::'a) = numeral m"
   1.372    by (simp_all add: field_class class_simps div_class)
   1.373  
   1.374  end
     2.1 --- a/src/HOL/Decision_Procs/Commutative_Ring.thy	Sun Dec 03 19:09:42 2017 +0100
     2.2 +++ b/src/HOL/Decision_Procs/Commutative_Ring.thy	Sun Dec 03 22:28:19 2017 +0100
     2.3 @@ -7,10 +7,10 @@
     2.4  section \<open>Proving equalities in commutative rings\<close>
     2.5  
     2.6  theory Commutative_Ring
     2.7 -imports
     2.8 -  Conversions
     2.9 -  Algebra_Aux
    2.10 -  "HOL-Library.Code_Target_Numeral"
    2.11 +  imports
    2.12 +    Conversions
    2.13 +    Algebra_Aux
    2.14 +    "HOL-Library.Code_Target_Numeral"
    2.15  begin
    2.16  
    2.17  text \<open>Syntax of multivariate polynomials (pol) and polynomial expressions.\<close>
    2.18 @@ -31,10 +31,11 @@
    2.19  
    2.20  text \<open>Interpretation functions for the shadow syntax.\<close>
    2.21  
    2.22 -context cring begin
    2.23 +context cring
    2.24 +begin
    2.25  
    2.26 -definition in_carrier :: "'a list \<Rightarrow> bool" where
    2.27 -  "in_carrier xs = (\<forall>x\<in>set xs. x \<in> carrier R)"
    2.28 +definition in_carrier :: "'a list \<Rightarrow> bool"
    2.29 +  where "in_carrier xs \<longleftrightarrow> (\<forall>x\<in>set xs. x \<in> carrier R)"
    2.30  
    2.31  lemma in_carrier_Nil: "in_carrier []"
    2.32    by (simp add: in_carrier_def)
    2.33 @@ -43,11 +44,10 @@
    2.34    by (simp add: in_carrier_def)
    2.35  
    2.36  lemma drop_in_carrier [simp]: "in_carrier xs \<Longrightarrow> in_carrier (drop n xs)"
    2.37 -  using set_drop_subset [of n xs]
    2.38 -  by (auto simp add: in_carrier_def)
    2.39 +  using set_drop_subset [of n xs] by (auto simp add: in_carrier_def)
    2.40  
    2.41  primrec head :: "'a list \<Rightarrow> 'a"
    2.42 -where
    2.43 +  where
    2.44      "head [] = \<zero>"
    2.45    | "head (x # xs) = x"
    2.46  
    2.47 @@ -55,7 +55,7 @@
    2.48    by (cases xs) (simp_all add: in_carrier_def)
    2.49  
    2.50  primrec Ipol :: "'a list \<Rightarrow> pol \<Rightarrow> 'a"
    2.51 -where
    2.52 +  where
    2.53      "Ipol l (Pc c) = \<guillemotleft>c\<guillemotright>"
    2.54    | "Ipol l (Pinj i P) = Ipol (drop i l) P"
    2.55    | "Ipol l (PX P x Q) = Ipol l P \<otimes> head l (^) x \<oplus> Ipol (drop 1 l) Q"
    2.56 @@ -67,12 +67,11 @@
    2.57    "Ipol l (Pc (- numeral n)) = \<ominus> \<guillemotleft>numeral n\<guillemotright>"
    2.58    by simp_all
    2.59  
    2.60 -lemma Ipol_closed [simp]:
    2.61 -  "in_carrier l \<Longrightarrow> Ipol l p \<in> carrier R"
    2.62 +lemma Ipol_closed [simp]: "in_carrier l \<Longrightarrow> Ipol l p \<in> carrier R"
    2.63    by (induct p arbitrary: l) simp_all
    2.64  
    2.65  primrec Ipolex :: "'a list \<Rightarrow> polex \<Rightarrow> 'a"
    2.66 -where
    2.67 +  where
    2.68      "Ipolex l (Var n) = head (drop n l)"
    2.69    | "Ipolex l (Const i) = \<guillemotleft>i\<guillemotright>"
    2.70    | "Ipolex l (Add P Q) = Ipolex l P \<oplus> Ipolex l Q"
    2.71 @@ -92,16 +91,14 @@
    2.72  text \<open>Create polynomial normalized polynomials given normalized inputs.\<close>
    2.73  
    2.74  definition mkPinj :: "nat \<Rightarrow> pol \<Rightarrow> pol"
    2.75 -where
    2.76 -  "mkPinj x P =
    2.77 +  where "mkPinj x P =
    2.78      (case P of
    2.79        Pc c \<Rightarrow> Pc c
    2.80      | Pinj y P \<Rightarrow> Pinj (x + y) P
    2.81      | PX p1 y p2 \<Rightarrow> Pinj x P)"
    2.82  
    2.83  definition mkPX :: "pol \<Rightarrow> nat \<Rightarrow> pol \<Rightarrow> pol"
    2.84 -where
    2.85 -  "mkPX P i Q =
    2.86 +  where "mkPX P i Q =
    2.87      (case P of
    2.88        Pc c \<Rightarrow> if c = 0 then mkPinj 1 Q else PX P i Q
    2.89      | Pinj j R \<Rightarrow> PX P i Q
    2.90 @@ -110,7 +107,7 @@
    2.91  text \<open>Defining the basic ring operations on normalized polynomials\<close>
    2.92  
    2.93  function add :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>+\<rangle>" 65)
    2.94 -where
    2.95 +  where
    2.96      "Pc a \<langle>+\<rangle> Pc b = Pc (a + b)"
    2.97    | "Pc c \<langle>+\<rangle> Pinj i P = Pinj i (P \<langle>+\<rangle> Pc c)"
    2.98    | "Pinj i P \<langle>+\<rangle> Pc c = Pinj i (P \<langle>+\<rangle> Pc c)"
    2.99 @@ -132,11 +129,11 @@
   2.100        (if x = y then mkPX (P1 \<langle>+\<rangle> Q1) x (P2 \<langle>+\<rangle> Q2)
   2.101         else (if x > y then mkPX (PX P1 (x - y) (Pc 0) \<langle>+\<rangle> Q1) y (P2 \<langle>+\<rangle> Q2)
   2.102           else mkPX (PX Q1 (y - x) (Pc 0) \<langle>+\<rangle> P1) x (P2 \<langle>+\<rangle> Q2)))"
   2.103 -by pat_completeness auto
   2.104 +  by pat_completeness auto
   2.105  termination by (relation "measure (\<lambda>(x, y). size x + size y)") auto
   2.106  
   2.107  function mul :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>*\<rangle>" 70)
   2.108 -where
   2.109 +  where
   2.110      "Pc a \<langle>*\<rangle> Pc b = Pc (a * b)"
   2.111    | "Pc c \<langle>*\<rangle> Pinj i P =
   2.112        (if c = 0 then Pc 0 else mkPinj i (P \<langle>*\<rangle> Pc c))"
   2.113 @@ -165,35 +162,32 @@
   2.114        mkPX (P1 \<langle>*\<rangle> Q1) (x + y) (P2 \<langle>*\<rangle> Q2) \<langle>+\<rangle>
   2.115          (mkPX (P1 \<langle>*\<rangle> mkPinj 1 Q2) x (Pc 0) \<langle>+\<rangle>
   2.116            (mkPX (Q1 \<langle>*\<rangle> mkPinj 1 P2) y (Pc 0)))"
   2.117 -by pat_completeness auto
   2.118 +  by pat_completeness auto
   2.119  termination by (relation "measure (\<lambda>(x, y). size x + size y)")
   2.120    (auto simp add: mkPinj_def split: pol.split)
   2.121  
   2.122  text \<open>Negation\<close>
   2.123  primrec neg :: "pol \<Rightarrow> pol"
   2.124 -where
   2.125 +  where
   2.126      "neg (Pc c) = Pc (- c)"
   2.127    | "neg (Pinj i P) = Pinj i (neg P)"
   2.128    | "neg (PX P x Q) = PX (neg P) x (neg Q)"
   2.129  
   2.130  text \<open>Subtraction\<close>
   2.131  definition sub :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>-\<rangle>" 65)
   2.132 -where
   2.133 -  "sub P Q = P \<langle>+\<rangle> neg Q"
   2.134 +  where "sub P Q = P \<langle>+\<rangle> neg Q"
   2.135  
   2.136  text \<open>Square for Fast Exponentiation\<close>
   2.137  primrec sqr :: "pol \<Rightarrow> pol"
   2.138 -where
   2.139 +  where
   2.140      "sqr (Pc c) = Pc (c * c)"
   2.141    | "sqr (Pinj i P) = mkPinj i (sqr P)"
   2.142 -  | "sqr (PX A x B) = mkPX (sqr A) (x + x) (sqr B) \<langle>+\<rangle>
   2.143 -      mkPX (Pc 2 \<langle>*\<rangle> A \<langle>*\<rangle> mkPinj 1 B) x (Pc 0)"
   2.144 +  | "sqr (PX A x B) = mkPX (sqr A) (x + x) (sqr B) \<langle>+\<rangle> mkPX (Pc 2 \<langle>*\<rangle> A \<langle>*\<rangle> mkPinj 1 B) x (Pc 0)"
   2.145  
   2.146  text \<open>Fast Exponentiation\<close>
   2.147  
   2.148  fun pow :: "nat \<Rightarrow> pol \<Rightarrow> pol"
   2.149 -where
   2.150 -  pow_if [simp del]: "pow n P =
   2.151 +  where pow_if [simp del]: "pow n P =
   2.152     (if n = 0 then Pc 1
   2.153      else if even n then pow (n div 2) (sqr P)
   2.154      else P \<langle>*\<rangle> pow (n div 2) (sqr P))"
   2.155 @@ -214,7 +208,7 @@
   2.156  text \<open>Normalization of polynomial expressions\<close>
   2.157  
   2.158  primrec norm :: "polex \<Rightarrow> pol"
   2.159 -where
   2.160 +  where
   2.161      "norm (Var n) =
   2.162         (if n = 0 then PX (Pc 1) 1 (Pc 0)
   2.163          else Pinj n (PX (Pc 1) 1 (Pc 0)))"
   2.164 @@ -360,57 +354,52 @@
   2.165    | Minj nat mon
   2.166    | MX nat mon
   2.167  
   2.168 -primrec (in cring)
   2.169 -  Imon :: "'a list \<Rightarrow> mon \<Rightarrow> 'a"
   2.170 -where
   2.171 +primrec (in cring) Imon :: "'a list \<Rightarrow> mon \<Rightarrow> 'a"
   2.172 +  where
   2.173      "Imon l (Mc c) = \<guillemotleft>c\<guillemotright>"
   2.174    | "Imon l (Minj i M) = Imon (drop i l) M"
   2.175    | "Imon l (MX x M) = Imon (drop 1 l) M \<otimes> head l (^) x"
   2.176  
   2.177 -lemma (in cring) Imon_closed [simp]:
   2.178 -  "in_carrier l \<Longrightarrow> Imon l m \<in> carrier R"
   2.179 +lemma (in cring) Imon_closed [simp]: "in_carrier l \<Longrightarrow> Imon l m \<in> carrier R"
   2.180    by (induct m arbitrary: l) simp_all
   2.181  
   2.182 -definition
   2.183 -  mkMinj :: "nat \<Rightarrow> mon \<Rightarrow> mon" where
   2.184 -  "mkMinj i M = (case M of
   2.185 -       Mc c \<Rightarrow> Mc c
   2.186 -     | Minj j M \<Rightarrow> Minj (i + j) M
   2.187 -     | _ \<Rightarrow> Minj i M)"
   2.188 +definition mkMinj :: "nat \<Rightarrow> mon \<Rightarrow> mon"
   2.189 +  where "mkMinj i M =
   2.190 +    (case M of
   2.191 +      Mc c \<Rightarrow> Mc c
   2.192 +    | Minj j M \<Rightarrow> Minj (i + j) M
   2.193 +    | _ \<Rightarrow> Minj i M)"
   2.194  
   2.195 -definition
   2.196 -  Minj_pred :: "nat \<Rightarrow> mon \<Rightarrow> mon" where
   2.197 -  "Minj_pred i M = (if i = 1 then M else mkMinj (i - 1) M)"
   2.198 +definition Minj_pred :: "nat \<Rightarrow> mon \<Rightarrow> mon"
   2.199 +  where "Minj_pred i M = (if i = 1 then M else mkMinj (i - 1) M)"
   2.200  
   2.201  primrec mkMX :: "nat \<Rightarrow> mon \<Rightarrow> mon"
   2.202 -where
   2.203 -  "mkMX i (Mc c) = MX i (Mc c)"
   2.204 -| "mkMX i (Minj j M) = (if j = 0 then mkMX i M else MX i (Minj_pred j M))"
   2.205 -| "mkMX i (MX j M) = MX (i + j) M"
   2.206 +  where
   2.207 +    "mkMX i (Mc c) = MX i (Mc c)"
   2.208 +  | "mkMX i (Minj j M) = (if j = 0 then mkMX i M else MX i (Minj_pred j M))"
   2.209 +  | "mkMX i (MX j M) = MX (i + j) M"
   2.210  
   2.211 -lemma (in cring) mkMinj_correct:
   2.212 -  "Imon l (mkMinj i M) = Imon l (Minj i M)"
   2.213 +lemma (in cring) mkMinj_correct: "Imon l (mkMinj i M) = Imon l (Minj i M)"
   2.214    by (simp add: mkMinj_def add.commute split: mon.split)
   2.215  
   2.216 -lemma (in cring) Minj_pred_correct:
   2.217 -  "0 < i \<Longrightarrow> Imon (drop 1 l) (Minj_pred i M) = Imon l (Minj i M)"
   2.218 +lemma (in cring) Minj_pred_correct: "0 < i \<Longrightarrow> Imon (drop 1 l) (Minj_pred i M) = Imon l (Minj i M)"
   2.219    by (simp add: Minj_pred_def mkMinj_correct)
   2.220  
   2.221 -lemma (in cring) mkMX_correct:
   2.222 -  "in_carrier l \<Longrightarrow> Imon l (mkMX i M) = Imon l M \<otimes> head l (^) i"
   2.223 -  by (induct M) (simp_all add: Minj_pred_correct [simplified] nat_pow_mult [symmetric] m_ac split: mon.split)
   2.224 +lemma (in cring) mkMX_correct: "in_carrier l \<Longrightarrow> Imon l (mkMX i M) = Imon l M \<otimes> head l (^) i"
   2.225 +  by (induct M)
   2.226 +    (simp_all add: Minj_pred_correct [simplified] nat_pow_mult [symmetric] m_ac split: mon.split)
   2.227  
   2.228  fun cfactor :: "pol \<Rightarrow> int \<Rightarrow> pol \<times> pol"
   2.229 -where
   2.230 -  "cfactor (Pc c') c = (Pc (c' mod c), Pc (c' div c))"
   2.231 -| "cfactor (Pinj i P) c =
   2.232 -     (let (R, S) = cfactor P c
   2.233 -      in (mkPinj i R, mkPinj i S))"
   2.234 -| "cfactor (PX P i Q) c =
   2.235 -     (let
   2.236 -        (R1, S1) = cfactor P c;
   2.237 -        (R2, S2) = cfactor Q c
   2.238 -      in (mkPX R1 i R2, mkPX S1 i S2))"
   2.239 +  where
   2.240 +    "cfactor (Pc c') c = (Pc (c' mod c), Pc (c' div c))"
   2.241 +  | "cfactor (Pinj i P) c =
   2.242 +       (let (R, S) = cfactor P c
   2.243 +        in (mkPinj i R, mkPinj i S))"
   2.244 +  | "cfactor (PX P i Q) c =
   2.245 +       (let
   2.246 +          (R1, S1) = cfactor P c;
   2.247 +          (R2, S2) = cfactor Q c
   2.248 +        in (mkPX R1 i R2, mkPX S1 i S2))"
   2.249  
   2.250  lemma (in cring) cfactor_correct:
   2.251    "in_carrier l \<Longrightarrow> Ipol l P = Ipol l (fst (cfactor P c)) \<oplus> \<guillemotleft>c\<guillemotright> \<otimes> Ipol l (snd (cfactor P c))"
   2.252 @@ -430,35 +419,35 @@
   2.253  qed
   2.254  
   2.255  fun mfactor :: "pol \<Rightarrow> mon \<Rightarrow> pol \<times> pol"
   2.256 -where
   2.257 -  "mfactor P (Mc c) = (if c = 1 then (Pc 0, P) else cfactor P c)"
   2.258 -| "mfactor (Pc d) M = (Pc d, Pc 0)"
   2.259 -| "mfactor (Pinj i P) (Minj j M) =
   2.260 -     (if i = j then
   2.261 -        let (R, S) = mfactor P M
   2.262 -        in (mkPinj i R, mkPinj i S)
   2.263 -      else if i < j then
   2.264 -        let (R, S) = mfactor P (Minj (j - i) M)
   2.265 -        in (mkPinj i R, mkPinj i S)
   2.266 -      else (Pinj i P, Pc 0))"
   2.267 -| "mfactor (Pinj i P) (MX j M) = (Pinj i P, Pc 0)"
   2.268 -| "mfactor (PX P i Q) (Minj j M) =
   2.269 -     (if j = 0 then mfactor (PX P i Q) M
   2.270 -      else
   2.271 -        let
   2.272 -          (R1, S1) = mfactor P (Minj j M);
   2.273 -          (R2, S2) = mfactor Q (Minj_pred j M)
   2.274 -        in (mkPX R1 i R2, mkPX S1 i S2))"
   2.275 -| "mfactor (PX P i Q) (MX j M) =
   2.276 -     (if i = j then
   2.277 -        let (R, S) = mfactor P (mkMinj 1 M)
   2.278 -        in (mkPX R i Q, S)
   2.279 -      else if i < j then
   2.280 -        let (R, S) = mfactor P (MX (j - i) M)
   2.281 -        in (mkPX R i Q, S)
   2.282 -      else
   2.283 -        let (R, S) = mfactor P (mkMinj 1 M)
   2.284 -        in (mkPX R i Q, mkPX S (i - j) (Pc 0)))"
   2.285 +  where
   2.286 +    "mfactor P (Mc c) = (if c = 1 then (Pc 0, P) else cfactor P c)"
   2.287 +  | "mfactor (Pc d) M = (Pc d, Pc 0)"
   2.288 +  | "mfactor (Pinj i P) (Minj j M) =
   2.289 +       (if i = j then
   2.290 +          let (R, S) = mfactor P M
   2.291 +          in (mkPinj i R, mkPinj i S)
   2.292 +        else if i < j then
   2.293 +          let (R, S) = mfactor P (Minj (j - i) M)
   2.294 +          in (mkPinj i R, mkPinj i S)
   2.295 +        else (Pinj i P, Pc 0))"
   2.296 +  | "mfactor (Pinj i P) (MX j M) = (Pinj i P, Pc 0)"
   2.297 +  | "mfactor (PX P i Q) (Minj j M) =
   2.298 +       (if j = 0 then mfactor (PX P i Q) M
   2.299 +        else
   2.300 +          let
   2.301 +            (R1, S1) = mfactor P (Minj j M);
   2.302 +            (R2, S2) = mfactor Q (Minj_pred j M)
   2.303 +          in (mkPX R1 i R2, mkPX S1 i S2))"
   2.304 +  | "mfactor (PX P i Q) (MX j M) =
   2.305 +       (if i = j then
   2.306 +          let (R, S) = mfactor P (mkMinj 1 M)
   2.307 +          in (mkPX R i Q, S)
   2.308 +        else if i < j then
   2.309 +          let (R, S) = mfactor P (MX (j - i) M)
   2.310 +          in (mkPX R i Q, S)
   2.311 +        else
   2.312 +          let (R, S) = mfactor P (mkMinj 1 M)
   2.313 +          in (mkPX R i Q, mkPX S (i - j) (Pc 0)))"
   2.314  
   2.315  lemmas mfactor_induct = mfactor.induct
   2.316    [case_names Mc Pc_Minj Pc_MX Pinj_Minj Pinj_MX PX_Minj PX_MX]
   2.317 @@ -515,20 +504,20 @@
   2.318  qed
   2.319  
   2.320  primrec mon_of_pol :: "pol \<Rightarrow> mon option"
   2.321 -where
   2.322 -  "mon_of_pol (Pc c) = Some (Mc c)"
   2.323 -| "mon_of_pol (Pinj i P) = (case mon_of_pol P of
   2.324 -       None \<Rightarrow> None
   2.325 -     | Some M \<Rightarrow> Some (mkMinj i M))"
   2.326 -| "mon_of_pol (PX P i Q) =
   2.327 -     (if Q = Pc 0 then (case mon_of_pol P of
   2.328 -          None \<Rightarrow> None
   2.329 -        | Some M \<Rightarrow> Some (mkMX i M))
   2.330 -      else None)"
   2.331 +  where
   2.332 +    "mon_of_pol (Pc c) = Some (Mc c)"
   2.333 +  | "mon_of_pol (Pinj i P) = (case mon_of_pol P of
   2.334 +         None \<Rightarrow> None
   2.335 +       | Some M \<Rightarrow> Some (mkMinj i M))"
   2.336 +  | "mon_of_pol (PX P i Q) =
   2.337 +       (if Q = Pc 0 then (case mon_of_pol P of
   2.338 +            None \<Rightarrow> None
   2.339 +          | Some M \<Rightarrow> Some (mkMX i M))
   2.340 +        else None)"
   2.341  
   2.342  lemma (in cring) mon_of_pol_correct:
   2.343    assumes "in_carrier l"
   2.344 -  and "mon_of_pol P = Some M"
   2.345 +    and "mon_of_pol P = Some M"
   2.346    shows "Ipol l P = Imon l M"
   2.347    using assms
   2.348  proof (induct P arbitrary: M l)
   2.349 @@ -539,81 +528,85 @@
   2.350  qed (auto simp add: mkMinj_correct split: option.split_asm)
   2.351  
   2.352  fun (in cring) Ipolex_polex_list :: "'a list \<Rightarrow> (polex \<times> polex) list \<Rightarrow> bool"
   2.353 -where
   2.354 -  "Ipolex_polex_list l [] = True"
   2.355 -| "Ipolex_polex_list l ((P, Q) # pps) = ((Ipolex l P = Ipolex l Q) \<and> Ipolex_polex_list l pps)"
   2.356 +  where
   2.357 +    "Ipolex_polex_list l [] = True"
   2.358 +  | "Ipolex_polex_list l ((P, Q) # pps) = ((Ipolex l P = Ipolex l Q) \<and> Ipolex_polex_list l pps)"
   2.359  
   2.360  fun (in cring) Imon_pol_list :: "'a list \<Rightarrow> (mon \<times> pol) list \<Rightarrow> bool"
   2.361 -where
   2.362 -  "Imon_pol_list l [] = True"
   2.363 -| "Imon_pol_list l ((M, P) # mps) = ((Imon l M = Ipol l P) \<and> Imon_pol_list l mps)"
   2.364 +  where
   2.365 +    "Imon_pol_list l [] = True"
   2.366 +  | "Imon_pol_list l ((M, P) # mps) = ((Imon l M = Ipol l P) \<and> Imon_pol_list l mps)"
   2.367  
   2.368  fun mk_monpol_list :: "(polex \<times> polex) list \<Rightarrow> (mon \<times> pol) list"
   2.369 -where
   2.370 -  "mk_monpol_list [] = []"
   2.371 -| "mk_monpol_list ((P, Q) # pps) =
   2.372 -     (case mon_of_pol (norm P) of
   2.373 -        None \<Rightarrow> mk_monpol_list pps
   2.374 -      | Some M \<Rightarrow> (M, norm Q) # mk_monpol_list pps)"
   2.375 +  where
   2.376 +    "mk_monpol_list [] = []"
   2.377 +  | "mk_monpol_list ((P, Q) # pps) =
   2.378 +       (case mon_of_pol (norm P) of
   2.379 +          None \<Rightarrow> mk_monpol_list pps
   2.380 +        | Some M \<Rightarrow> (M, norm Q) # mk_monpol_list pps)"
   2.381  
   2.382  lemma (in cring) mk_monpol_list_correct:
   2.383    "in_carrier l \<Longrightarrow> Ipolex_polex_list l pps \<Longrightarrow> Imon_pol_list l (mk_monpol_list pps)"
   2.384    by (induct pps rule: mk_monpol_list.induct)
   2.385 -    (auto split: option.split
   2.386 -       simp add: norm_ci [symmetric] mon_of_pol_correct [symmetric])
   2.387 +    (auto split: option.split simp add: norm_ci [symmetric] mon_of_pol_correct [symmetric])
   2.388  
   2.389 -definition ponesubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> pol option" where
   2.390 -  "ponesubst P1 M P2 =
   2.391 -     (let (Q, R) = mfactor P1 M
   2.392 -      in case R of
   2.393 -          Pc c \<Rightarrow> if c = 0 then None else Some (add Q (mul P2 R))
   2.394 -        | _ \<Rightarrow> Some (add Q (mul P2 R)))"
   2.395 +definition ponesubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> pol option"
   2.396 +  where "ponesubst P1 M P2 =
   2.397 +   (let (Q, R) = mfactor P1 M in
   2.398 +    (case R of
   2.399 +      Pc c \<Rightarrow> if c = 0 then None else Some (add Q (mul P2 R))
   2.400 +    | _ \<Rightarrow> Some (add Q (mul P2 R))))"
   2.401  
   2.402  fun pnsubst1 :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> nat \<Rightarrow> pol"
   2.403 -where
   2.404 -  "pnsubst1 P1 M P2 n = (case ponesubst P1 M P2 of
   2.405 -       None \<Rightarrow> P1
   2.406 -     | Some P3 \<Rightarrow> if n = 0 then P3 else pnsubst1 P3 M P2 (n - 1))"
   2.407 +  where "pnsubst1 P1 M P2 n =
   2.408 +    (case ponesubst P1 M P2 of
   2.409 +      None \<Rightarrow> P1
   2.410 +    | Some P3 \<Rightarrow> if n = 0 then P3 else pnsubst1 P3 M P2 (n - 1))"
   2.411  
   2.412  lemma pnsubst1_0 [simp]: "pnsubst1 P1 M P2 0 = (case ponesubst P1 M P2 of
   2.413    None \<Rightarrow> P1 | Some P3 \<Rightarrow> P3)"
   2.414    by (simp split: option.split)
   2.415  
   2.416 -lemma pnsubst1_Suc [simp]: "pnsubst1 P1 M P2 (Suc n) = (case ponesubst P1 M P2 of
   2.417 -  None \<Rightarrow> P1 | Some P3 \<Rightarrow> pnsubst1 P3 M P2 n)"
   2.418 +lemma pnsubst1_Suc [simp]:
   2.419 +  "pnsubst1 P1 M P2 (Suc n) =
   2.420 +    (case ponesubst P1 M P2 of
   2.421 +      None \<Rightarrow> P1
   2.422 +    | Some P3 \<Rightarrow> pnsubst1 P3 M P2 n)"
   2.423    by (simp split: option.split)
   2.424  
   2.425  declare pnsubst1.simps [simp del]
   2.426  
   2.427 -definition pnsubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> nat \<Rightarrow> pol option" where
   2.428 -  "pnsubst P1 M P2 n = (case ponesubst P1 M P2 of
   2.429 -       None \<Rightarrow> None
   2.430 -     | Some P3 \<Rightarrow> Some (pnsubst1 P3 M P2 n))"
   2.431 +definition pnsubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> nat \<Rightarrow> pol option"
   2.432 +  where "pnsubst P1 M P2 n =
   2.433 +    (case ponesubst P1 M P2 of
   2.434 +      None \<Rightarrow> None
   2.435 +    | Some P3 \<Rightarrow> Some (pnsubst1 P3 M P2 n))"
   2.436  
   2.437  fun psubstl1 :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> pol"
   2.438 -where
   2.439 -  "psubstl1 P1 [] n = P1"
   2.440 -| "psubstl1 P1 ((M, P2) # mps) n = psubstl1 (pnsubst1 P1 M P2 n) mps n"
   2.441 +  where
   2.442 +    "psubstl1 P1 [] n = P1"
   2.443 +  | "psubstl1 P1 ((M, P2) # mps) n = psubstl1 (pnsubst1 P1 M P2 n) mps n"
   2.444  
   2.445  fun psubstl :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> pol option"
   2.446 -where
   2.447 -  "psubstl P1 [] n = None"
   2.448 -| "psubstl P1 ((M, P2) # mps) n = (case pnsubst P1 M P2 n of
   2.449 -       None \<Rightarrow> psubstl P1 mps n
   2.450 -     | Some P3 \<Rightarrow> Some (psubstl1 P3 mps n))"
   2.451 +  where
   2.452 +    "psubstl P1 [] n = None"
   2.453 +  | "psubstl P1 ((M, P2) # mps) n =
   2.454 +      (case pnsubst P1 M P2 n of
   2.455 +        None \<Rightarrow> psubstl P1 mps n
   2.456 +      | Some P3 \<Rightarrow> Some (psubstl1 P3 mps n))"
   2.457  
   2.458  fun pnsubstl :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> pol"
   2.459 -where
   2.460 -  "pnsubstl P1 mps m n = (case psubstl P1 mps n of
   2.461 -       None \<Rightarrow> P1
   2.462 -     | Some P3 \<Rightarrow> if m = 0 then P3 else pnsubstl P3 mps (m - 1) n)"
   2.463 +  where "pnsubstl P1 mps m n =
   2.464 +    (case psubstl P1 mps n of
   2.465 +      None \<Rightarrow> P1
   2.466 +    | Some P3 \<Rightarrow> if m = 0 then P3 else pnsubstl P3 mps (m - 1) n)"
   2.467  
   2.468 -lemma pnsubstl_0 [simp]: "pnsubstl P1 mps 0 n = (case psubstl P1 mps n of
   2.469 -  None \<Rightarrow> P1 | Some P3 \<Rightarrow> P3)"
   2.470 +lemma pnsubstl_0 [simp]:
   2.471 +  "pnsubstl P1 mps 0 n = (case psubstl P1 mps n of None \<Rightarrow> P1 | Some P3 \<Rightarrow> P3)"
   2.472    by (simp split: option.split)
   2.473  
   2.474 -lemma pnsubstl_Suc [simp]: "pnsubstl P1 mps (Suc m) n = (case psubstl P1 mps n of
   2.475 -  None \<Rightarrow> P1 | Some P3 \<Rightarrow> pnsubstl P3 mps m n)"
   2.476 +lemma pnsubstl_Suc [simp]:
   2.477 +  "pnsubstl P1 mps (Suc m) n = (case psubstl P1 mps n of None \<Rightarrow> P1 | Some P3 \<Rightarrow> pnsubstl P3 mps m n)"
   2.478    by (simp split: option.split)
   2.479  
   2.480  declare pnsubstl.simps [simp del]
   2.481 @@ -961,7 +954,8 @@
   2.482  end
   2.483  \<close>
   2.484  
   2.485 -context cring begin
   2.486 +context cring
   2.487 +begin
   2.488  
   2.489  local_setup \<open>
   2.490  Local_Theory.declaration {syntax = false, pervasive = false}
     3.1 --- a/src/HOL/Decision_Procs/Commutative_Ring_Complete.thy	Sun Dec 03 19:09:42 2017 +0100
     3.2 +++ b/src/HOL/Decision_Procs/Commutative_Ring_Complete.thy	Sun Dec 03 22:28:19 2017 +0100
     3.3 @@ -8,23 +8,25 @@
     3.4  section \<open>Proof of the relative completeness of method comm-ring\<close>
     3.5  
     3.6  theory Commutative_Ring_Complete
     3.7 -imports Commutative_Ring
     3.8 +  imports Commutative_Ring
     3.9  begin
    3.10  
    3.11  text \<open>Formalization of normal form\<close>
    3.12  fun isnorm :: "pol \<Rightarrow> bool"
    3.13 -where
    3.14 -  "isnorm (Pc c) \<longleftrightarrow> True"
    3.15 -| "isnorm (Pinj i (Pc c)) \<longleftrightarrow> False"
    3.16 -| "isnorm (Pinj i (Pinj j Q)) \<longleftrightarrow> False"
    3.17 -| "isnorm (Pinj 0 P) \<longleftrightarrow> False"
    3.18 -| "isnorm (Pinj i (PX Q1 j Q2)) \<longleftrightarrow> isnorm (PX Q1 j Q2)"
    3.19 -| "isnorm (PX P 0 Q) \<longleftrightarrow> False"
    3.20 -| "isnorm (PX (Pc c) i Q) \<longleftrightarrow> c \<noteq> 0 \<and> isnorm Q"
    3.21 -| "isnorm (PX (PX P1 j (Pc c)) i Q) \<longleftrightarrow> c \<noteq> 0 \<and> isnorm (PX P1 j (Pc c)) \<and> isnorm Q"
    3.22 -| "isnorm (PX P i Q) \<longleftrightarrow> isnorm P \<and> isnorm Q"
    3.23 +  where
    3.24 +    "isnorm (Pc c) \<longleftrightarrow> True"
    3.25 +  | "isnorm (Pinj i (Pc c)) \<longleftrightarrow> False"
    3.26 +  | "isnorm (Pinj i (Pinj j Q)) \<longleftrightarrow> False"
    3.27 +  | "isnorm (Pinj 0 P) \<longleftrightarrow> False"
    3.28 +  | "isnorm (Pinj i (PX Q1 j Q2)) \<longleftrightarrow> isnorm (PX Q1 j Q2)"
    3.29 +  | "isnorm (PX P 0 Q) \<longleftrightarrow> False"
    3.30 +  | "isnorm (PX (Pc c) i Q) \<longleftrightarrow> c \<noteq> 0 \<and> isnorm Q"
    3.31 +  | "isnorm (PX (PX P1 j (Pc c)) i Q) \<longleftrightarrow> c \<noteq> 0 \<and> isnorm (PX P1 j (Pc c)) \<and> isnorm Q"
    3.32 +  | "isnorm (PX P i Q) \<longleftrightarrow> isnorm P \<and> isnorm Q"
    3.33  
    3.34 -(* Some helpful lemmas *)
    3.35 +
    3.36 +subsection \<open>Some helpful lemmas\<close>
    3.37 +
    3.38  lemma norm_Pinj_0_False: "isnorm (Pinj 0 P) = False"
    3.39    by (cases P) auto
    3.40  
    3.41 @@ -36,24 +38,24 @@
    3.42  
    3.43  lemma norm_PX2: "isnorm (PX P i Q) \<Longrightarrow> isnorm Q"
    3.44    apply (cases i)
    3.45 -  apply auto
    3.46 +   apply auto
    3.47    apply (cases P)
    3.48 -  apply auto
    3.49 +    apply auto
    3.50    subgoal for \<dots> pol2 by (cases pol2) auto
    3.51    done
    3.52  
    3.53  lemma norm_PX1: "isnorm (PX P i Q) \<Longrightarrow> isnorm P"
    3.54    apply (cases i)
    3.55 -  apply auto
    3.56 +   apply auto
    3.57    apply (cases P)
    3.58 -  apply auto
    3.59 +    apply auto
    3.60    subgoal for \<dots> pol2 by (cases pol2) auto
    3.61    done
    3.62  
    3.63  lemma mkPinj_cn: "y \<noteq> 0 \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (mkPinj y Q)"
    3.64    apply (auto simp add: mkPinj_def norm_Pinj_0_False split: pol.split)
    3.65 -  apply (rename_tac nat a, case_tac nat, auto simp add: norm_Pinj_0_False)
    3.66 -  apply (rename_tac pol a, case_tac pol, auto)
    3.67 +   apply (rename_tac nat a, case_tac nat, auto simp add: norm_Pinj_0_False)
    3.68 +   apply (rename_tac pol a, case_tac pol, auto)
    3.69    apply (case_tac y, auto)
    3.70    done
    3.71  
    3.72 @@ -65,9 +67,9 @@
    3.73    case (PX p1 y p2)
    3.74    with assms show ?thesis
    3.75      apply (cases x)
    3.76 -    apply auto
    3.77 +     apply auto
    3.78      apply (cases p2)
    3.79 -    apply auto
    3.80 +      apply auto
    3.81      done
    3.82  next
    3.83    case Pc
    3.84 @@ -87,9 +89,9 @@
    3.85    case (PX p1 y p2)
    3.86    with assms show ?thesis
    3.87      apply (cases x)
    3.88 -    apply auto
    3.89 +     apply auto
    3.90      apply (cases p2)
    3.91 -    apply auto
    3.92 +      apply auto
    3.93      done
    3.94  next
    3.95    case Pc
    3.96 @@ -101,7 +103,7 @@
    3.97      by (cases x) auto
    3.98  qed
    3.99  
   3.100 -text \<open>mkPX conserves normalizedness (\<open>_cn\<close>)\<close>
   3.101 +text \<open>\<open>mkPX\<close> conserves normalizedness (\<open>_cn\<close>)\<close>
   3.102  lemma mkPX_cn:
   3.103    assumes "x \<noteq> 0"
   3.104      and "isnorm P"
   3.105 @@ -123,13 +125,13 @@
   3.106      by (auto simp add: norm_PX1[of P1 y P2] norm_PX2[of P1 y P2])
   3.107    from assms PX Y0 show ?thesis
   3.108      apply (cases x)
   3.109 -    apply (auto simp add: mkPX_def norm_PXtrans2[of P1 y _ Q _])
   3.110 +     apply (auto simp add: mkPX_def norm_PXtrans2[of P1 y _ Q _])
   3.111      apply (cases P2)
   3.112 -    apply auto
   3.113 +      apply auto
   3.114      done
   3.115  qed
   3.116  
   3.117 -text \<open>add conserves normalizedness\<close>
   3.118 +text \<open>\<open>add\<close> conserves normalizedness\<close>
   3.119  lemma add_cn: "isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<langle>+\<rangle> Q)"
   3.120  proof (induct P Q rule: add.induct)
   3.121    case 1
   3.122 @@ -138,17 +140,17 @@
   3.123    case (2 c i P2)
   3.124    then show ?case
   3.125      apply (cases P2)
   3.126 -    apply simp_all
   3.127 +      apply simp_all
   3.128      apply (cases i)
   3.129 -    apply simp_all
   3.130 +     apply simp_all
   3.131      done
   3.132  next
   3.133    case (3 i P2 c)
   3.134    then show ?case
   3.135      apply (cases P2)
   3.136 -    apply simp_all
   3.137 +      apply simp_all
   3.138      apply (cases i)
   3.139 -    apply simp_all
   3.140 +     apply simp_all
   3.141      done
   3.142  next
   3.143    case (4 c P2 i Q2)
   3.144 @@ -156,9 +158,9 @@
   3.145      by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
   3.146    with 4 show ?case
   3.147      apply (cases i)
   3.148 -    apply simp
   3.149 +     apply simp
   3.150      apply (cases P2)
   3.151 -    apply auto
   3.152 +      apply auto
   3.153      subgoal for \<dots> pol2 by (cases pol2) auto
   3.154      done
   3.155  next
   3.156 @@ -167,9 +169,9 @@
   3.157      by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
   3.158    with 5 show ?case
   3.159      apply (cases i)
   3.160 -    apply simp
   3.161 +     apply simp
   3.162      apply (cases P2)
   3.163 -    apply auto
   3.164 +      apply auto
   3.165      subgoal for \<dots> pol2 by (cases pol2) auto
   3.166      done
   3.167  next
   3.168 @@ -326,7 +328,7 @@
   3.169    qed
   3.170  qed
   3.171  
   3.172 -text \<open>mul concerves normalizedness\<close>
   3.173 +text \<open>\<open>mul\<close> concerves normalizedness\<close>
   3.174  lemma mul_cn: "isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<langle>*\<rangle> Q)"
   3.175  proof (induct P Q rule: mul.induct)
   3.176    case 1
   3.177 @@ -335,17 +337,17 @@
   3.178    case (2 c i P2)
   3.179    then show ?case
   3.180      apply (cases P2)
   3.181 -    apply simp_all
   3.182 +      apply simp_all
   3.183      apply (cases i)
   3.184 -    apply (simp_all add: mkPinj_cn)
   3.185 +     apply (simp_all add: mkPinj_cn)
   3.186      done
   3.187  next
   3.188    case (3 i P2 c)
   3.189    then show ?case
   3.190      apply (cases P2)
   3.191 -    apply simp_all
   3.192 +      apply simp_all
   3.193      apply (cases i)
   3.194 -    apply (simp_all add: mkPinj_cn)
   3.195 +     apply (simp_all add: mkPinj_cn)
   3.196      done
   3.197  next
   3.198    case (4 c P2 i Q2)
   3.199 @@ -353,9 +355,9 @@
   3.200      by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
   3.201    with 4 show ?case
   3.202      apply (cases "c = 0")
   3.203 -    apply simp_all
   3.204 +     apply simp_all
   3.205      apply (cases "i = 0")
   3.206 -    apply (simp_all add: mkPX_cn)
   3.207 +     apply (simp_all add: mkPX_cn)
   3.208      done
   3.209  next
   3.210    case (5 P2 i Q2 c)
   3.211 @@ -363,9 +365,9 @@
   3.212      by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
   3.213    with 5 show ?case
   3.214      apply (cases "c = 0")
   3.215 -    apply simp_all
   3.216 +     apply simp_all
   3.217      apply (cases "i = 0")
   3.218 -    apply (simp_all add: mkPX_cn)
   3.219 +     apply (simp_all add: mkPX_cn)
   3.220      done
   3.221  next
   3.222    case (6 x P2 y Q2)
   3.223 @@ -381,9 +383,9 @@
   3.224        by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
   3.225      from 6 xy y have "isnorm (Pinj d Q2)"
   3.226        apply (cases d)
   3.227 -      apply simp
   3.228 +       apply simp
   3.229        apply (cases Q2)
   3.230 -      apply auto
   3.231 +        apply auto
   3.232        done
   3.233      with 6 * ** y show ?thesis
   3.234        by (simp add: mkPinj_cn)
   3.235 @@ -531,17 +533,14 @@
   3.236    case (Pinj i Q)
   3.237    then show ?case
   3.238      apply (cases Q)
   3.239 -    apply (auto simp add: mkPX_cn mkPinj_cn)
   3.240 +      apply (auto simp add: mkPX_cn mkPinj_cn)
   3.241      apply (cases i)
   3.242 -    apply (auto simp add: mkPX_cn mkPinj_cn)
   3.243 +     apply (auto simp add: mkPX_cn mkPinj_cn)
   3.244      done
   3.245  next
   3.246    case (PX P1 x P2)
   3.247    then have "x + x \<noteq> 0" "isnorm P2" "isnorm P1"
   3.248 -    apply (cases x)
   3.249 -    using PX
   3.250 -    apply (auto simp add: norm_PX1[of P1 x P2] norm_PX2[of P1 x P2])
   3.251 -    done
   3.252 +    by (cases x) (use PX in \<open>auto simp add: norm_PX1[of P1 x P2] norm_PX2[of P1 x P2]\<close>)
   3.253    with PX have "isnorm (mkPX (Pc (1 + 1) \<langle>*\<rangle> P1 \<langle>*\<rangle> mkPinj (Suc 0) P2) x (Pc 0))"
   3.254      and "isnorm (mkPX (sqr P1) (x + x) (sqr P2))"
   3.255      by (auto simp add: add_cn mkPX_cn mkPinj_cn mul_cn)
   3.256 @@ -549,7 +548,7 @@
   3.257      by (auto simp add: add_cn mkPX_cn mkPinj_cn mul_cn)
   3.258  qed
   3.259  
   3.260 -text \<open>pow conserves normalizedness\<close>
   3.261 +text \<open>\<open>pow\<close> conserves normalizedness\<close>
   3.262  lemma pow_cn: "isnorm P \<Longrightarrow> isnorm (pow n P)"
   3.263  proof (induct n arbitrary: P rule: less_induct)
   3.264    case (less k)
     4.1 --- a/src/HOL/Decision_Procs/Cooper.thy	Sun Dec 03 19:09:42 2017 +0100
     4.2 +++ b/src/HOL/Decision_Procs/Cooper.thy	Sun Dec 03 22:28:19 2017 +0100
     4.3 @@ -8,11 +8,9 @@
     4.4    "HOL-Library.Code_Target_Numeral"
     4.5  begin
     4.6  
     4.7 -(* Periodicity of dvd *)
     4.8 +section \<open>Periodicity of \<open>dvd\<close>\<close>
     4.9  
    4.10 -(*********************************************************************************)
    4.11 -(****                            SHADOW SYNTAX AND SEMANTICS                  ****)
    4.12 -(*********************************************************************************)
    4.13 +subsection \<open>Shadow syntax and semantics\<close>
    4.14  
    4.15  datatype (plugins del: size) num = C int | Bound nat | CN nat int num
    4.16    | Neg num | Add num num | Sub num num
    4.17 @@ -22,28 +20,28 @@
    4.18  begin
    4.19  
    4.20  primrec size_num :: "num \<Rightarrow> nat"
    4.21 -where
    4.22 -  "size_num (C c) = 1"
    4.23 -| "size_num (Bound n) = 1"
    4.24 -| "size_num (Neg a) = 1 + size_num a"
    4.25 -| "size_num (Add a b) = 1 + size_num a + size_num b"
    4.26 -| "size_num (Sub a b) = 3 + size_num a + size_num b"
    4.27 -| "size_num (CN n c a) = 4 + size_num a"
    4.28 -| "size_num (Mul c a) = 1 + size_num a"
    4.29 +  where
    4.30 +    "size_num (C c) = 1"
    4.31 +  | "size_num (Bound n) = 1"
    4.32 +  | "size_num (Neg a) = 1 + size_num a"
    4.33 +  | "size_num (Add a b) = 1 + size_num a + size_num b"
    4.34 +  | "size_num (Sub a b) = 3 + size_num a + size_num b"
    4.35 +  | "size_num (CN n c a) = 4 + size_num a"
    4.36 +  | "size_num (Mul c a) = 1 + size_num a"
    4.37  
    4.38  instance ..
    4.39  
    4.40  end
    4.41  
    4.42  primrec Inum :: "int list \<Rightarrow> num \<Rightarrow> int"
    4.43 -where
    4.44 -  "Inum bs (C c) = c"
    4.45 -| "Inum bs (Bound n) = bs ! n"
    4.46 -| "Inum bs (CN n c a) = c * (bs ! n) + Inum bs a"
    4.47 -| "Inum bs (Neg a) = - Inum bs a"
    4.48 -| "Inum bs (Add a b) = Inum bs a + Inum bs b"
    4.49 -| "Inum bs (Sub a b) = Inum bs a - Inum bs b"
    4.50 -| "Inum bs (Mul c a) = c * Inum bs a"
    4.51 +  where
    4.52 +    "Inum bs (C c) = c"
    4.53 +  | "Inum bs (Bound n) = bs ! n"
    4.54 +  | "Inum bs (CN n c a) = c * (bs ! n) + Inum bs a"
    4.55 +  | "Inum bs (Neg a) = - Inum bs a"
    4.56 +  | "Inum bs (Add a b) = Inum bs a + Inum bs b"
    4.57 +  | "Inum bs (Sub a b) = Inum bs a - Inum bs b"
    4.58 +  | "Inum bs (Mul c a) = c * Inum bs a"
    4.59  
    4.60  datatype (plugins del: size) fm = T | F
    4.61    | Lt num | Le num | Gt num | Ge num | Eq num | NEq num
    4.62 @@ -55,180 +53,180 @@
    4.63  begin
    4.64  
    4.65  primrec size_fm :: "fm \<Rightarrow> nat"
    4.66 -where
    4.67 -  "size_fm (NOT p) = 1 + size_fm p"
    4.68 -| "size_fm (And p q) = 1 + size_fm p + size_fm q"
    4.69 -| "size_fm (Or p q) = 1 + size_fm p + size_fm q"
    4.70 -| "size_fm (Imp p q) = 3 + size_fm p + size_fm q"
    4.71 -| "size_fm (Iff p q) = 3 + 2 * (size_fm p + size_fm q)"
    4.72 -| "size_fm (E p) = 1 + size_fm p"
    4.73 -| "size_fm (A p) = 4 + size_fm p"
    4.74 -| "size_fm (Dvd i t) = 2"
    4.75 -| "size_fm (NDvd i t) = 2"
    4.76 -| "size_fm T = 1" 
    4.77 -| "size_fm F = 1"
    4.78 -| "size_fm (Lt _) = 1" 
    4.79 -| "size_fm (Le _) = 1" 
    4.80 -| "size_fm (Gt _) = 1" 
    4.81 -| "size_fm (Ge _) = 1" 
    4.82 -| "size_fm (Eq _) = 1" 
    4.83 -| "size_fm (NEq _) = 1" 
    4.84 -| "size_fm (Closed _) = 1" 
    4.85 -| "size_fm (NClosed _) = 1"
    4.86 +  where
    4.87 +    "size_fm (NOT p) = 1 + size_fm p"
    4.88 +  | "size_fm (And p q) = 1 + size_fm p + size_fm q"
    4.89 +  | "size_fm (Or p q) = 1 + size_fm p + size_fm q"
    4.90 +  | "size_fm (Imp p q) = 3 + size_fm p + size_fm q"
    4.91 +  | "size_fm (Iff p q) = 3 + 2 * (size_fm p + size_fm q)"
    4.92 +  | "size_fm (E p) = 1 + size_fm p"
    4.93 +  | "size_fm (A p) = 4 + size_fm p"
    4.94 +  | "size_fm (Dvd i t) = 2"
    4.95 +  | "size_fm (NDvd i t) = 2"
    4.96 +  | "size_fm T = 1"
    4.97 +  | "size_fm F = 1"
    4.98 +  | "size_fm (Lt _) = 1"
    4.99 +  | "size_fm (Le _) = 1"
   4.100 +  | "size_fm (Gt _) = 1"
   4.101 +  | "size_fm (Ge _) = 1"
   4.102 +  | "size_fm (Eq _) = 1"
   4.103 +  | "size_fm (NEq _) = 1"
   4.104 +  | "size_fm (Closed _) = 1"
   4.105 +  | "size_fm (NClosed _) = 1"
   4.106  
   4.107  instance ..
   4.108  
   4.109  end
   4.110  
   4.111 -lemma fmsize_pos [simp]: "size p > 0" for p :: fm
   4.112 +lemma fmsize_pos [simp]: "size p > 0"
   4.113 +  for p :: fm
   4.114    by (induct p) simp_all
   4.115  
   4.116 -primrec Ifm :: "bool list \<Rightarrow> int list \<Rightarrow> fm \<Rightarrow> bool"  \<comment> \<open>Semantics of formulae (fm)\<close>
   4.117 -where
   4.118 -  "Ifm bbs bs T \<longleftrightarrow> True"
   4.119 -| "Ifm bbs bs F \<longleftrightarrow> False"
   4.120 -| "Ifm bbs bs (Lt a) \<longleftrightarrow> Inum bs a < 0"
   4.121 -| "Ifm bbs bs (Gt a) \<longleftrightarrow> Inum bs a > 0"
   4.122 -| "Ifm bbs bs (Le a) \<longleftrightarrow> Inum bs a \<le> 0"
   4.123 -| "Ifm bbs bs (Ge a) \<longleftrightarrow> Inum bs a \<ge> 0"
   4.124 -| "Ifm bbs bs (Eq a) \<longleftrightarrow> Inum bs a = 0"
   4.125 -| "Ifm bbs bs (NEq a) \<longleftrightarrow> Inum bs a \<noteq> 0"
   4.126 -| "Ifm bbs bs (Dvd i b) \<longleftrightarrow> i dvd Inum bs b"
   4.127 -| "Ifm bbs bs (NDvd i b) \<longleftrightarrow> \<not> i dvd Inum bs b"
   4.128 -| "Ifm bbs bs (NOT p) \<longleftrightarrow> \<not> Ifm bbs bs p"
   4.129 -| "Ifm bbs bs (And p q) \<longleftrightarrow> Ifm bbs bs p \<and> Ifm bbs bs q"
   4.130 -| "Ifm bbs bs (Or p q) \<longleftrightarrow> Ifm bbs bs p \<or> Ifm bbs bs q"
   4.131 -| "Ifm bbs bs (Imp p q) \<longleftrightarrow> (Ifm bbs bs p \<longrightarrow> Ifm bbs bs q)"
   4.132 -| "Ifm bbs bs (Iff p q) \<longleftrightarrow> Ifm bbs bs p = Ifm bbs bs q"
   4.133 -| "Ifm bbs bs (E p) \<longleftrightarrow> (\<exists>x. Ifm bbs (x # bs) p)"
   4.134 -| "Ifm bbs bs (A p) \<longleftrightarrow> (\<forall>x. Ifm bbs (x # bs) p)"
   4.135 -| "Ifm bbs bs (Closed n) \<longleftrightarrow> bbs ! n"
   4.136 -| "Ifm bbs bs (NClosed n) \<longleftrightarrow> \<not> bbs ! n"
   4.137 +primrec Ifm :: "bool list \<Rightarrow> int list \<Rightarrow> fm \<Rightarrow> bool"  \<comment> \<open>Semantics of formulae (\<open>fm\<close>)\<close>
   4.138 +  where
   4.139 +    "Ifm bbs bs T \<longleftrightarrow> True"
   4.140 +  | "Ifm bbs bs F \<longleftrightarrow> False"
   4.141 +  | "Ifm bbs bs (Lt a) \<longleftrightarrow> Inum bs a < 0"
   4.142 +  | "Ifm bbs bs (Gt a) \<longleftrightarrow> Inum bs a > 0"
   4.143 +  | "Ifm bbs bs (Le a) \<longleftrightarrow> Inum bs a \<le> 0"
   4.144 +  | "Ifm bbs bs (Ge a) \<longleftrightarrow> Inum bs a \<ge> 0"
   4.145 +  | "Ifm bbs bs (Eq a) \<longleftrightarrow> Inum bs a = 0"
   4.146 +  | "Ifm bbs bs (NEq a) \<longleftrightarrow> Inum bs a \<noteq> 0"
   4.147 +  | "Ifm bbs bs (Dvd i b) \<longleftrightarrow> i dvd Inum bs b"
   4.148 +  | "Ifm bbs bs (NDvd i b) \<longleftrightarrow> \<not> i dvd Inum bs b"
   4.149 +  | "Ifm bbs bs (NOT p) \<longleftrightarrow> \<not> Ifm bbs bs p"
   4.150 +  | "Ifm bbs bs (And p q) \<longleftrightarrow> Ifm bbs bs p \<and> Ifm bbs bs q"
   4.151 +  | "Ifm bbs bs (Or p q) \<longleftrightarrow> Ifm bbs bs p \<or> Ifm bbs bs q"
   4.152 +  | "Ifm bbs bs (Imp p q) \<longleftrightarrow> (Ifm bbs bs p \<longrightarrow> Ifm bbs bs q)"
   4.153 +  | "Ifm bbs bs (Iff p q) \<longleftrightarrow> Ifm bbs bs p = Ifm bbs bs q"
   4.154 +  | "Ifm bbs bs (E p) \<longleftrightarrow> (\<exists>x. Ifm bbs (x # bs) p)"
   4.155 +  | "Ifm bbs bs (A p) \<longleftrightarrow> (\<forall>x. Ifm bbs (x # bs) p)"
   4.156 +  | "Ifm bbs bs (Closed n) \<longleftrightarrow> bbs ! n"
   4.157 +  | "Ifm bbs bs (NClosed n) \<longleftrightarrow> \<not> bbs ! n"
   4.158  
   4.159  fun prep :: "fm \<Rightarrow> fm"
   4.160 -where
   4.161 -  "prep (E T) = T"
   4.162 -| "prep (E F) = F"
   4.163 -| "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))"
   4.164 -| "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))"
   4.165 -| "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
   4.166 -| "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))"
   4.167 -| "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
   4.168 -| "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
   4.169 -| "prep (E p) = E (prep p)"
   4.170 -| "prep (A (And p q)) = And (prep (A p)) (prep (A q))"
   4.171 -| "prep (A p) = prep (NOT (E (NOT p)))"
   4.172 -| "prep (NOT (NOT p)) = prep p"
   4.173 -| "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))"
   4.174 -| "prep (NOT (A p)) = prep (E (NOT p))"
   4.175 -| "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))"
   4.176 -| "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))"
   4.177 -| "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))"
   4.178 -| "prep (NOT p) = NOT (prep p)"
   4.179 -| "prep (Or p q) = Or (prep p) (prep q)"
   4.180 -| "prep (And p q) = And (prep p) (prep q)"
   4.181 -| "prep (Imp p q) = prep (Or (NOT p) q)"
   4.182 -| "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))"
   4.183 -| "prep p = p"
   4.184 +  where
   4.185 +    "prep (E T) = T"
   4.186 +  | "prep (E F) = F"
   4.187 +  | "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))"
   4.188 +  | "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))"
   4.189 +  | "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
   4.190 +  | "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))"
   4.191 +  | "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
   4.192 +  | "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
   4.193 +  | "prep (E p) = E (prep p)"
   4.194 +  | "prep (A (And p q)) = And (prep (A p)) (prep (A q))"
   4.195 +  | "prep (A p) = prep (NOT (E (NOT p)))"
   4.196 +  | "prep (NOT (NOT p)) = prep p"
   4.197 +  | "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))"
   4.198 +  | "prep (NOT (A p)) = prep (E (NOT p))"
   4.199 +  | "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))"
   4.200 +  | "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))"
   4.201 +  | "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))"
   4.202 +  | "prep (NOT p) = NOT (prep p)"
   4.203 +  | "prep (Or p q) = Or (prep p) (prep q)"
   4.204 +  | "prep (And p q) = And (prep p) (prep q)"
   4.205 +  | "prep (Imp p q) = prep (Or (NOT p) q)"
   4.206 +  | "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))"
   4.207 +  | "prep p = p"
   4.208  
   4.209  lemma prep: "Ifm bbs bs (prep p) = Ifm bbs bs p"
   4.210    by (induct p arbitrary: bs rule: prep.induct) auto
   4.211  
   4.212  
   4.213  fun qfree :: "fm \<Rightarrow> bool"  \<comment> \<open>Quantifier freeness\<close>
   4.214 -where
   4.215 -  "qfree (E p) \<longleftrightarrow> False"
   4.216 -| "qfree (A p) \<longleftrightarrow> False"
   4.217 -| "qfree (NOT p) \<longleftrightarrow> qfree p"
   4.218 -| "qfree (And p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.219 -| "qfree (Or  p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.220 -| "qfree (Imp p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.221 -| "qfree (Iff p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.222 -| "qfree p \<longleftrightarrow> True"
   4.223 +  where
   4.224 +    "qfree (E p) \<longleftrightarrow> False"
   4.225 +  | "qfree (A p) \<longleftrightarrow> False"
   4.226 +  | "qfree (NOT p) \<longleftrightarrow> qfree p"
   4.227 +  | "qfree (And p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.228 +  | "qfree (Or  p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.229 +  | "qfree (Imp p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.230 +  | "qfree (Iff p q) \<longleftrightarrow> qfree p \<and> qfree q"
   4.231 +  | "qfree p \<longleftrightarrow> True"
   4.232  
   4.233  
   4.234  text \<open>Boundedness and substitution\<close>
   4.235  
   4.236 -primrec numbound0 :: "num \<Rightarrow> bool"  \<comment> \<open>a num is INDEPENDENT of Bound 0\<close>
   4.237 -where
   4.238 -  "numbound0 (C c) \<longleftrightarrow> True"
   4.239 -| "numbound0 (Bound n) \<longleftrightarrow> n > 0"
   4.240 -| "numbound0 (CN n i a) \<longleftrightarrow> n > 0 \<and> numbound0 a"
   4.241 -| "numbound0 (Neg a) \<longleftrightarrow> numbound0 a"
   4.242 -| "numbound0 (Add a b) \<longleftrightarrow> numbound0 a \<and> numbound0 b"
   4.243 -| "numbound0 (Sub a b) \<longleftrightarrow> numbound0 a \<and> numbound0 b"
   4.244 -| "numbound0 (Mul i a) \<longleftrightarrow> numbound0 a"
   4.245 +primrec numbound0 :: "num \<Rightarrow> bool"  \<comment> \<open>a \<open>num\<close> is \<^emph>\<open>independent\<close> of Bound 0\<close>
   4.246 +  where
   4.247 +    "numbound0 (C c) \<longleftrightarrow> True"
   4.248 +  | "numbound0 (Bound n) \<longleftrightarrow> n > 0"
   4.249 +  | "numbound0 (CN n i a) \<longleftrightarrow> n > 0 \<and> numbound0 a"
   4.250 +  | "numbound0 (Neg a) \<longleftrightarrow> numbound0 a"
   4.251 +  | "numbound0 (Add a b) \<longleftrightarrow> numbound0 a \<and> numbound0 b"
   4.252 +  | "numbound0 (Sub a b) \<longleftrightarrow> numbound0 a \<and> numbound0 b"
   4.253 +  | "numbound0 (Mul i a) \<longleftrightarrow> numbound0 a"
   4.254  
   4.255  lemma numbound0_I:
   4.256 -  assumes nb: "numbound0 a"
   4.257 +  assumes "numbound0 a"
   4.258    shows "Inum (b # bs) a = Inum (b' # bs) a"
   4.259 -  using nb by (induct a rule: num.induct) (auto simp add: gr0_conv_Suc)
   4.260 +  using assms by (induct a rule: num.induct) (auto simp add: gr0_conv_Suc)
   4.261  
   4.262 -primrec bound0 :: "fm \<Rightarrow> bool" \<comment> \<open>A Formula is independent of Bound 0\<close>
   4.263 -where
   4.264 -  "bound0 T \<longleftrightarrow> True"
   4.265 -| "bound0 F \<longleftrightarrow> True"
   4.266 -| "bound0 (Lt a) \<longleftrightarrow> numbound0 a"
   4.267 -| "bound0 (Le a) \<longleftrightarrow> numbound0 a"
   4.268 -| "bound0 (Gt a) \<longleftrightarrow> numbound0 a"
   4.269 -| "bound0 (Ge a) \<longleftrightarrow> numbound0 a"
   4.270 -| "bound0 (Eq a) \<longleftrightarrow> numbound0 a"
   4.271 -| "bound0 (NEq a) \<longleftrightarrow> numbound0 a"
   4.272 -| "bound0 (Dvd i a) \<longleftrightarrow> numbound0 a"
   4.273 -| "bound0 (NDvd i a) \<longleftrightarrow> numbound0 a"
   4.274 -| "bound0 (NOT p) \<longleftrightarrow> bound0 p"
   4.275 -| "bound0 (And p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.276 -| "bound0 (Or p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.277 -| "bound0 (Imp p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.278 -| "bound0 (Iff p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.279 -| "bound0 (E p) \<longleftrightarrow> False"
   4.280 -| "bound0 (A p) \<longleftrightarrow> False"
   4.281 -| "bound0 (Closed P) \<longleftrightarrow> True"
   4.282 -| "bound0 (NClosed P) \<longleftrightarrow> True"
   4.283 +primrec bound0 :: "fm \<Rightarrow> bool" \<comment> \<open>a formula is independent of Bound 0\<close>
   4.284 +  where
   4.285 +    "bound0 T \<longleftrightarrow> True"
   4.286 +  | "bound0 F \<longleftrightarrow> True"
   4.287 +  | "bound0 (Lt a) \<longleftrightarrow> numbound0 a"
   4.288 +  | "bound0 (Le a) \<longleftrightarrow> numbound0 a"
   4.289 +  | "bound0 (Gt a) \<longleftrightarrow> numbound0 a"
   4.290 +  | "bound0 (Ge a) \<longleftrightarrow> numbound0 a"
   4.291 +  | "bound0 (Eq a) \<longleftrightarrow> numbound0 a"
   4.292 +  | "bound0 (NEq a) \<longleftrightarrow> numbound0 a"
   4.293 +  | "bound0 (Dvd i a) \<longleftrightarrow> numbound0 a"
   4.294 +  | "bound0 (NDvd i a) \<longleftrightarrow> numbound0 a"
   4.295 +  | "bound0 (NOT p) \<longleftrightarrow> bound0 p"
   4.296 +  | "bound0 (And p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.297 +  | "bound0 (Or p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.298 +  | "bound0 (Imp p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.299 +  | "bound0 (Iff p q) \<longleftrightarrow> bound0 p \<and> bound0 q"
   4.300 +  | "bound0 (E p) \<longleftrightarrow> False"
   4.301 +  | "bound0 (A p) \<longleftrightarrow> False"
   4.302 +  | "bound0 (Closed P) \<longleftrightarrow> True"
   4.303 +  | "bound0 (NClosed P) \<longleftrightarrow> True"
   4.304  
   4.305  lemma bound0_I:
   4.306 -  assumes bp: "bound0 p"
   4.307 +  assumes "bound0 p"
   4.308    shows "Ifm bbs (b # bs) p = Ifm bbs (b' # bs) p"
   4.309 -  using bp numbound0_I[where b="b" and bs="bs" and b'="b'"]
   4.310 +  using assms numbound0_I[where b="b" and bs="bs" and b'="b'"]
   4.311    by (induct p rule: fm.induct) (auto simp add: gr0_conv_Suc)
   4.312  
   4.313  fun numsubst0 :: "num \<Rightarrow> num \<Rightarrow> num"
   4.314 -where
   4.315 -  "numsubst0 t (C c) = (C c)"
   4.316 -| "numsubst0 t (Bound n) = (if n=0 then t else Bound n)"
   4.317 -| "numsubst0 t (CN 0 i a) = Add (Mul i t) (numsubst0 t a)"
   4.318 -| "numsubst0 t (CN n i a) = CN n i (numsubst0 t a)"
   4.319 -| "numsubst0 t (Neg a) = Neg (numsubst0 t a)"
   4.320 -| "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)"
   4.321 -| "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)"
   4.322 -| "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)"
   4.323 +  where
   4.324 +    "numsubst0 t (C c) = (C c)"
   4.325 +  | "numsubst0 t (Bound n) = (if n = 0 then t else Bound n)"
   4.326 +  | "numsubst0 t (CN 0 i a) = Add (Mul i t) (numsubst0 t a)"
   4.327 +  | "numsubst0 t (CN n i a) = CN n i (numsubst0 t a)"
   4.328 +  | "numsubst0 t (Neg a) = Neg (numsubst0 t a)"
   4.329 +  | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)"
   4.330 +  | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)"
   4.331 +  | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)"
   4.332  
   4.333 -lemma numsubst0_I: "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t"
   4.334 +lemma numsubst0_I: "Inum (b # bs) (numsubst0 a t) = Inum ((Inum (b # bs) a) # bs) t"
   4.335    by (induct t rule: numsubst0.induct) (auto simp: nth_Cons')
   4.336  
   4.337 -lemma numsubst0_I':
   4.338 -  "numbound0 a \<Longrightarrow> Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t"
   4.339 +lemma numsubst0_I': "numbound0 a \<Longrightarrow> Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t"
   4.340    by (induct t rule: numsubst0.induct) (auto simp: nth_Cons' numbound0_I[where b="b" and b'="b'"])
   4.341  
   4.342 -primrec subst0:: "num \<Rightarrow> fm \<Rightarrow> fm"  \<comment> \<open>substitue a num into a formula for Bound 0\<close>
   4.343 -where
   4.344 -  "subst0 t T = T"
   4.345 -| "subst0 t F = F"
   4.346 -| "subst0 t (Lt a) = Lt (numsubst0 t a)"
   4.347 -| "subst0 t (Le a) = Le (numsubst0 t a)"
   4.348 -| "subst0 t (Gt a) = Gt (numsubst0 t a)"
   4.349 -| "subst0 t (Ge a) = Ge (numsubst0 t a)"
   4.350 -| "subst0 t (Eq a) = Eq (numsubst0 t a)"
   4.351 -| "subst0 t (NEq a) = NEq (numsubst0 t a)"
   4.352 -| "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)"
   4.353 -| "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)"
   4.354 -| "subst0 t (NOT p) = NOT (subst0 t p)"
   4.355 -| "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
   4.356 -| "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
   4.357 -| "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)"
   4.358 -| "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
   4.359 -| "subst0 t (Closed P) = (Closed P)"
   4.360 -| "subst0 t (NClosed P) = (NClosed P)"
   4.361 +primrec subst0:: "num \<Rightarrow> fm \<Rightarrow> fm"  \<comment> \<open>substitute a \<open>num\<close> into a formula for Bound 0\<close>
   4.362 +  where
   4.363 +    "subst0 t T = T"
   4.364 +  | "subst0 t F = F"
   4.365 +  | "subst0 t (Lt a) = Lt (numsubst0 t a)"
   4.366 +  | "subst0 t (Le a) = Le (numsubst0 t a)"
   4.367 +  | "subst0 t (Gt a) = Gt (numsubst0 t a)"
   4.368 +  | "subst0 t (Ge a) = Ge (numsubst0 t a)"
   4.369 +  | "subst0 t (Eq a) = Eq (numsubst0 t a)"
   4.370 +  | "subst0 t (NEq a) = NEq (numsubst0 t a)"
   4.371 +  | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)"
   4.372 +  | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)"
   4.373 +  | "subst0 t (NOT p) = NOT (subst0 t p)"
   4.374 +  | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
   4.375 +  | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
   4.376 +  | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)"
   4.377 +  | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
   4.378 +  | "subst0 t (Closed P) = (Closed P)"
   4.379 +  | "subst0 t (NClosed P) = (NClosed P)"
   4.380  
   4.381  lemma subst0_I:
   4.382    assumes "qfree p"
   4.383 @@ -237,67 +235,67 @@
   4.384    by (induct p) (simp_all add: gr0_conv_Suc)
   4.385  
   4.386  fun decrnum:: "num \<Rightarrow> num"
   4.387 -where
   4.388 -  "decrnum (Bound n) = Bound (n - 1)"
   4.389 -| "decrnum (Neg a) = Neg (decrnum a)"
   4.390 -| "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
   4.391 -| "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
   4.392 -| "decrnum (Mul c a) = Mul c (decrnum a)"
   4.393 -| "decrnum (CN n i a) = (CN (n - 1) i (decrnum a))"
   4.394 -| "decrnum a = a"
   4.395 +  where
   4.396 +    "decrnum (Bound n) = Bound (n - 1)"
   4.397 +  | "decrnum (Neg a) = Neg (decrnum a)"
   4.398 +  | "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
   4.399 +  | "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
   4.400 +  | "decrnum (Mul c a) = Mul c (decrnum a)"
   4.401 +  | "decrnum (CN n i a) = (CN (n - 1) i (decrnum a))"
   4.402 +  | "decrnum a = a"
   4.403  
   4.404  fun decr :: "fm \<Rightarrow> fm"
   4.405 -where
   4.406 -  "decr (Lt a) = Lt (decrnum a)"
   4.407 -| "decr (Le a) = Le (decrnum a)"
   4.408 -| "decr (Gt a) = Gt (decrnum a)"
   4.409 -| "decr (Ge a) = Ge (decrnum a)"
   4.410 -| "decr (Eq a) = Eq (decrnum a)"
   4.411 -| "decr (NEq a) = NEq (decrnum a)"
   4.412 -| "decr (Dvd i a) = Dvd i (decrnum a)"
   4.413 -| "decr (NDvd i a) = NDvd i (decrnum a)"
   4.414 -| "decr (NOT p) = NOT (decr p)"
   4.415 -| "decr (And p q) = And (decr p) (decr q)"
   4.416 -| "decr (Or p q) = Or (decr p) (decr q)"
   4.417 -| "decr (Imp p q) = Imp (decr p) (decr q)"
   4.418 -| "decr (Iff p q) = Iff (decr p) (decr q)"
   4.419 -| "decr p = p"
   4.420 +  where
   4.421 +    "decr (Lt a) = Lt (decrnum a)"
   4.422 +  | "decr (Le a) = Le (decrnum a)"
   4.423 +  | "decr (Gt a) = Gt (decrnum a)"
   4.424 +  | "decr (Ge a) = Ge (decrnum a)"
   4.425 +  | "decr (Eq a) = Eq (decrnum a)"
   4.426 +  | "decr (NEq a) = NEq (decrnum a)"
   4.427 +  | "decr (Dvd i a) = Dvd i (decrnum a)"
   4.428 +  | "decr (NDvd i a) = NDvd i (decrnum a)"
   4.429 +  | "decr (NOT p) = NOT (decr p)"
   4.430 +  | "decr (And p q) = And (decr p) (decr q)"
   4.431 +  | "decr (Or p q) = Or (decr p) (decr q)"
   4.432 +  | "decr (Imp p q) = Imp (decr p) (decr q)"
   4.433 +  | "decr (Iff p q) = Iff (decr p) (decr q)"
   4.434 +  | "decr p = p"
   4.435  
   4.436  lemma decrnum:
   4.437 -  assumes nb: "numbound0 t"
   4.438 +  assumes "numbound0 t"
   4.439    shows "Inum (x # bs) t = Inum bs (decrnum t)"
   4.440 -  using nb by (induct t rule: decrnum.induct) (auto simp add: gr0_conv_Suc)
   4.441 +  using assms by (induct t rule: decrnum.induct) (auto simp add: gr0_conv_Suc)
   4.442  
   4.443  lemma decr:
   4.444 -  assumes nb: "bound0 p"
   4.445 +  assumes assms: "bound0 p"
   4.446    shows "Ifm bbs (x # bs) p = Ifm bbs bs (decr p)"
   4.447 -  using nb by (induct p rule: decr.induct) (simp_all add: gr0_conv_Suc decrnum)
   4.448 +  using assms by (induct p rule: decr.induct) (simp_all add: gr0_conv_Suc decrnum)
   4.449  
   4.450  lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
   4.451    by (induct p) simp_all
   4.452  
   4.453  fun isatom :: "fm \<Rightarrow> bool"  \<comment> \<open>test for atomicity\<close>
   4.454 -where
   4.455 -  "isatom T \<longleftrightarrow> True"
   4.456 -| "isatom F \<longleftrightarrow> True"
   4.457 -| "isatom (Lt a) \<longleftrightarrow> True"
   4.458 -| "isatom (Le a) \<longleftrightarrow> True"
   4.459 -| "isatom (Gt a) \<longleftrightarrow> True"
   4.460 -| "isatom (Ge a) \<longleftrightarrow> True"
   4.461 -| "isatom (Eq a) \<longleftrightarrow> True"
   4.462 -| "isatom (NEq a) \<longleftrightarrow> True"
   4.463 -| "isatom (Dvd i b) \<longleftrightarrow> True"
   4.464 -| "isatom (NDvd i b) \<longleftrightarrow> True"
   4.465 -| "isatom (Closed P) \<longleftrightarrow> True"
   4.466 -| "isatom (NClosed P) \<longleftrightarrow> True"
   4.467 -| "isatom p \<longleftrightarrow> False"
   4.468 +  where
   4.469 +    "isatom T \<longleftrightarrow> True"
   4.470 +  | "isatom F \<longleftrightarrow> True"
   4.471 +  | "isatom (Lt a) \<longleftrightarrow> True"
   4.472 +  | "isatom (Le a) \<longleftrightarrow> True"
   4.473 +  | "isatom (Gt a) \<longleftrightarrow> True"
   4.474 +  | "isatom (Ge a) \<longleftrightarrow> True"
   4.475 +  | "isatom (Eq a) \<longleftrightarrow> True"
   4.476 +  | "isatom (NEq a) \<longleftrightarrow> True"
   4.477 +  | "isatom (Dvd i b) \<longleftrightarrow> True"
   4.478 +  | "isatom (NDvd i b) \<longleftrightarrow> True"
   4.479 +  | "isatom (Closed P) \<longleftrightarrow> True"
   4.480 +  | "isatom (NClosed P) \<longleftrightarrow> True"
   4.481 +  | "isatom p \<longleftrightarrow> False"
   4.482  
   4.483  lemma numsubst0_numbound0:
   4.484    assumes "numbound0 t"
   4.485    shows "numbound0 (numsubst0 t a)"
   4.486    using assms
   4.487  proof (induct a)
   4.488 -  case (CN n _ _)
   4.489 +  case (CN n)
   4.490    then show ?case by (cases n) simp_all
   4.491  qed simp_all
   4.492  
   4.493 @@ -341,10 +339,10 @@
   4.494    using nb by (induct xs) (auto simp add: evaldjf_def djf_def Let_def, case_tac "f a", auto)
   4.495  
   4.496  fun disjuncts :: "fm \<Rightarrow> fm list"
   4.497 -where
   4.498 -  "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   4.499 -| "disjuncts F = []"
   4.500 -| "disjuncts p = [p]"
   4.501 +  where
   4.502 +    "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   4.503 +  | "disjuncts F = []"
   4.504 +  | "disjuncts p = [p]"
   4.505  
   4.506  lemma disjuncts: "(\<exists>q \<in> set (disjuncts p). Ifm bbs bs q) \<longleftrightarrow> Ifm bbs bs p"
   4.507    by (induct p rule: disjuncts.induct) auto
   4.508 @@ -425,36 +423,36 @@
   4.509  text \<open>Algebraic simplifications for nums\<close>
   4.510  
   4.511  fun bnds :: "num \<Rightarrow> nat list"
   4.512 -where
   4.513 -  "bnds (Bound n) = [n]"
   4.514 -| "bnds (CN n c a) = n # bnds a"
   4.515 -| "bnds (Neg a) = bnds a"
   4.516 -| "bnds (Add a b) = bnds a @ bnds b"
   4.517 -| "bnds (Sub a b) = bnds a @ bnds b"
   4.518 -| "bnds (Mul i a) = bnds a"
   4.519 -| "bnds a = []"
   4.520 +  where
   4.521 +    "bnds (Bound n) = [n]"
   4.522 +  | "bnds (CN n c a) = n # bnds a"
   4.523 +  | "bnds (Neg a) = bnds a"
   4.524 +  | "bnds (Add a b) = bnds a @ bnds b"
   4.525 +  | "bnds (Sub a b) = bnds a @ bnds b"
   4.526 +  | "bnds (Mul i a) = bnds a"
   4.527 +  | "bnds a = []"
   4.528  
   4.529  fun lex_ns:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
   4.530 -where
   4.531 -  "lex_ns [] ms \<longleftrightarrow> True"
   4.532 -| "lex_ns ns [] \<longleftrightarrow> False"
   4.533 -| "lex_ns (n # ns) (m # ms) \<longleftrightarrow> n < m \<or> (n = m \<and> lex_ns ns ms)"
   4.534 +  where
   4.535 +    "lex_ns [] ms \<longleftrightarrow> True"
   4.536 +  | "lex_ns ns [] \<longleftrightarrow> False"
   4.537 +  | "lex_ns (n # ns) (m # ms) \<longleftrightarrow> n < m \<or> (n = m \<and> lex_ns ns ms)"
   4.538  
   4.539  definition lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool"
   4.540    where "lex_bnd t s = lex_ns (bnds t) (bnds s)"
   4.541  
   4.542  fun numadd:: "num \<Rightarrow> num \<Rightarrow> num"
   4.543 -where
   4.544 -  "numadd (CN n1 c1 r1) (CN n2 c2 r2) =
   4.545 -    (if n1 = n2 then
   4.546 -       let c = c1 + c2
   4.547 -       in if c = 0 then numadd r1 r2 else CN n1 c (numadd r1 r2)
   4.548 -     else if n1 \<le> n2 then CN n1 c1 (numadd r1 (Add (Mul c2 (Bound n2)) r2))
   4.549 -     else CN n2 c2 (numadd (Add (Mul c1 (Bound n1)) r1) r2))"
   4.550 -| "numadd (CN n1 c1 r1) t = CN n1 c1 (numadd r1 t)"
   4.551 -| "numadd t (CN n2 c2 r2) = CN n2 c2 (numadd t r2)"
   4.552 -| "numadd (C b1) (C b2) = C (b1 + b2)"
   4.553 -| "numadd a b = Add a b"
   4.554 +  where
   4.555 +    "numadd (CN n1 c1 r1) (CN n2 c2 r2) =
   4.556 +      (if n1 = n2 then
   4.557 +         let c = c1 + c2
   4.558 +         in if c = 0 then numadd r1 r2 else CN n1 c (numadd r1 r2)
   4.559 +       else if n1 \<le> n2 then CN n1 c1 (numadd r1 (Add (Mul c2 (Bound n2)) r2))
   4.560 +       else CN n2 c2 (numadd (Add (Mul c1 (Bound n1)) r1) r2))"
   4.561 +  | "numadd (CN n1 c1 r1) t = CN n1 c1 (numadd r1 t)"
   4.562 +  | "numadd t (CN n2 c2 r2) = CN n2 c2 (numadd t r2)"
   4.563 +  | "numadd (C b1) (C b2) = C (b1 + b2)"
   4.564 +  | "numadd a b = Add a b"
   4.565  
   4.566  lemma numadd: "Inum bs (numadd t s) = Inum bs (Add t s)"
   4.567    by (induct t s rule: numadd.induct) (simp_all add: Let_def algebra_simps add_eq_0_iff)
   4.568 @@ -463,10 +461,10 @@
   4.569    by (induct t s rule: numadd.induct) (simp_all add: Let_def)
   4.570  
   4.571  fun nummul :: "int \<Rightarrow> num \<Rightarrow> num"
   4.572 -where
   4.573 -  "nummul i (C j) = C (i * j)"
   4.574 -| "nummul i (CN n c t) = CN n (c * i) (nummul i t)"
   4.575 -| "nummul i t = Mul i t"
   4.576 +  where
   4.577 +    "nummul i (C j) = C (i * j)"
   4.578 +  | "nummul i (CN n c t) = CN n (c * i) (nummul i t)"
   4.579 +  | "nummul i t = Mul i t"
   4.580  
   4.581  lemma nummul: "Inum bs (nummul i t) = Inum bs (Mul i t)"
   4.582    by (induct t arbitrary: i rule: nummul.induct) (simp_all add: algebra_simps)
   4.583 @@ -493,14 +491,14 @@
   4.584    using numsub_def numadd_nb numneg_nb by simp
   4.585  
   4.586  fun simpnum :: "num \<Rightarrow> num"
   4.587 -where
   4.588 -  "simpnum (C j) = C j"
   4.589 -| "simpnum (Bound n) = CN n 1 (C 0)"
   4.590 -| "simpnum (Neg t) = numneg (simpnum t)"
   4.591 -| "simpnum (Add t s) = numadd (simpnum t) (simpnum s)"
   4.592 -| "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
   4.593 -| "simpnum (Mul i t) = (if i = 0 then C 0 else nummul i (simpnum t))"
   4.594 -| "simpnum t = t"
   4.595 +  where
   4.596 +    "simpnum (C j) = C j"
   4.597 +  | "simpnum (Bound n) = CN n 1 (C 0)"
   4.598 +  | "simpnum (Neg t) = numneg (simpnum t)"
   4.599 +  | "simpnum (Add t s) = numadd (simpnum t) (simpnum s)"
   4.600 +  | "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
   4.601 +  | "simpnum (Mul i t) = (if i = 0 then C 0 else nummul i (simpnum t))"
   4.602 +  | "simpnum t = t"
   4.603  
   4.604  lemma simpnum_ci: "Inum bs (simpnum t) = Inum bs t"
   4.605    by (induct t rule: simpnum.induct) (auto simp add: numneg numadd numsub nummul)
   4.606 @@ -509,11 +507,11 @@
   4.607    by (induct t rule: simpnum.induct) (auto simp add: numadd_nb numsub_nb nummul_nb numneg_nb)
   4.608  
   4.609  fun not :: "fm \<Rightarrow> fm"
   4.610 -where
   4.611 -  "not (NOT p) = p"
   4.612 -| "not T = F"
   4.613 -| "not F = T"
   4.614 -| "not p = NOT p"
   4.615 +  where
   4.616 +    "not (NOT p) = p"
   4.617 +  | "not T = F"
   4.618 +  | "not F = T"
   4.619 +  | "not p = NOT p"
   4.620  
   4.621  lemma not: "Ifm bbs bs (not p) = Ifm bbs bs (NOT p)"
   4.622    by (cases p) auto
   4.623 @@ -525,8 +523,7 @@
   4.624    by (cases p) auto
   4.625  
   4.626  definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   4.627 -where
   4.628 -  "conj p q =
   4.629 +  where "conj p q =
   4.630      (if p = F \<or> q = F then F
   4.631       else if p = T then q
   4.632       else if q = T then p
   4.633 @@ -542,8 +539,7 @@
   4.634    using conj_def by auto
   4.635  
   4.636  definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   4.637 -where
   4.638 -  "disj p q =
   4.639 +  where "disj p q =
   4.640      (if p = T \<or> q = T then T
   4.641       else if p = F then q
   4.642       else if q = F then p
   4.643 @@ -559,8 +555,7 @@
   4.644    using disj_def by auto
   4.645  
   4.646  definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   4.647 -where
   4.648 -  "imp p q =
   4.649 +  where "imp p q =
   4.650      (if p = F \<or> q = T then T
   4.651       else if p = T then q
   4.652       else if q = F then not p
   4.653 @@ -576,8 +571,7 @@
   4.654    using imp_def by (cases "p = F \<or> q = T", simp_all add: imp_def, cases p) simp_all
   4.655  
   4.656  definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   4.657 -where
   4.658 -  "iff p q =
   4.659 +  where "iff p q =
   4.660      (if p = q then T
   4.661       else if p = not q \<or> not p = q then F
   4.662       else if p = F then not q
   4.663 @@ -597,27 +591,27 @@
   4.664    using iff_def by (unfold iff_def, cases "p = q", auto simp add: not_bn)
   4.665  
   4.666  fun simpfm :: "fm \<Rightarrow> fm"
   4.667 -where
   4.668 -  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
   4.669 -| "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
   4.670 -| "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
   4.671 -| "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
   4.672 -| "simpfm (NOT p) = not (simpfm p)"
   4.673 -| "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v < 0 then T else F | _ \<Rightarrow> Lt a')"
   4.674 -| "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<le> 0 then T else F | _ \<Rightarrow> Le a')"
   4.675 -| "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v > 0 then T else F | _ \<Rightarrow> Gt a')"
   4.676 -| "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<ge> 0 then T else F | _ \<Rightarrow> Ge a')"
   4.677 -| "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v = 0 then T else F | _ \<Rightarrow> Eq a')"
   4.678 -| "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<noteq> 0 then T else F | _ \<Rightarrow> NEq a')"
   4.679 -| "simpfm (Dvd i a) =
   4.680 -    (if i = 0 then simpfm (Eq a)
   4.681 -     else if \<bar>i\<bar> = 1 then T
   4.682 -     else let a' = simpnum a in case a' of C v \<Rightarrow> if i dvd v then T else F | _ \<Rightarrow> Dvd i a')"
   4.683 -| "simpfm (NDvd i a) =
   4.684 -    (if i = 0 then simpfm (NEq a)
   4.685 -     else if \<bar>i\<bar> = 1 then F
   4.686 -     else let a' = simpnum a in case a' of C v \<Rightarrow> if \<not>( i dvd v) then T else F | _ \<Rightarrow> NDvd i a')"
   4.687 -| "simpfm p = p"
   4.688 +  where
   4.689 +    "simpfm (And p q) = conj (simpfm p) (simpfm q)"
   4.690 +  | "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
   4.691 +  | "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
   4.692 +  | "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
   4.693 +  | "simpfm (NOT p) = not (simpfm p)"
   4.694 +  | "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v < 0 then T else F | _ \<Rightarrow> Lt a')"
   4.695 +  | "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<le> 0 then T else F | _ \<Rightarrow> Le a')"
   4.696 +  | "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v > 0 then T else F | _ \<Rightarrow> Gt a')"
   4.697 +  | "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<ge> 0 then T else F | _ \<Rightarrow> Ge a')"
   4.698 +  | "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v = 0 then T else F | _ \<Rightarrow> Eq a')"
   4.699 +  | "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if v \<noteq> 0 then T else F | _ \<Rightarrow> NEq a')"
   4.700 +  | "simpfm (Dvd i a) =
   4.701 +      (if i = 0 then simpfm (Eq a)
   4.702 +       else if \<bar>i\<bar> = 1 then T
   4.703 +       else let a' = simpnum a in case a' of C v \<Rightarrow> if i dvd v then T else F | _ \<Rightarrow> Dvd i a')"
   4.704 +  | "simpfm (NDvd i a) =
   4.705 +      (if i = 0 then simpfm (NEq a)
   4.706 +       else if \<bar>i\<bar> = 1 then F
   4.707 +       else let a' = simpnum a in case a' of C v \<Rightarrow> if \<not>( i dvd v) then T else F | _ \<Rightarrow> NDvd i a')"
   4.708 +  | "simpfm p = p"
   4.709  
   4.710  lemma simpfm: "Ifm bbs bs (simpfm p) = Ifm bbs bs p"
   4.711  proof (induct p rule: simpfm.induct)
   4.712 @@ -827,15 +821,15 @@
   4.713  
   4.714  text \<open>Generic quantifier elimination\<close>
   4.715  fun qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
   4.716 -where
   4.717 -  "qelim (E p) = (\<lambda>qe. DJ qe (qelim p qe))"
   4.718 -| "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
   4.719 -| "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
   4.720 -| "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
   4.721 -| "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
   4.722 -| "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
   4.723 -| "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
   4.724 -| "qelim p = (\<lambda>y. simpfm p)"
   4.725 +  where
   4.726 +    "qelim (E p) = (\<lambda>qe. DJ qe (qelim p qe))"
   4.727 +  | "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
   4.728 +  | "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
   4.729 +  | "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
   4.730 +  | "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
   4.731 +  | "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
   4.732 +  | "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
   4.733 +  | "qelim p = (\<lambda>y. simpfm p)"
   4.734  
   4.735  lemma qelim_ci:
   4.736    assumes qe_inv: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> Ifm bbs bs (qe p) = Ifm bbs bs (E p)"
   4.737 @@ -848,24 +842,24 @@
   4.738  text \<open>Linearity for fm where Bound 0 ranges over \<open>\<int>\<close>\<close>
   4.739  
   4.740  fun zsplit0 :: "num \<Rightarrow> int \<times> num"  \<comment> \<open>splits the bounded from the unbounded part\<close>
   4.741 -where
   4.742 -  "zsplit0 (C c) = (0, C c)"
   4.743 -| "zsplit0 (Bound n) = (if n = 0 then (1, C 0) else (0, Bound n))"
   4.744 -| "zsplit0 (CN n i a) =
   4.745 -    (let (i', a') =  zsplit0 a
   4.746 -     in if n = 0 then (i + i', a') else (i', CN n i a'))"
   4.747 -| "zsplit0 (Neg a) = (let (i', a') = zsplit0 a in (-i', Neg a'))"
   4.748 -| "zsplit0 (Add a b) =
   4.749 -    (let
   4.750 -      (ia, a') = zsplit0 a;
   4.751 -      (ib, b') = zsplit0 b
   4.752 -     in (ia + ib, Add a' b'))"
   4.753 -| "zsplit0 (Sub a b) =
   4.754 -    (let
   4.755 -      (ia, a') = zsplit0 a;
   4.756 -      (ib, b') = zsplit0 b
   4.757 -     in (ia - ib, Sub a' b'))"
   4.758 -| "zsplit0 (Mul i a) = (let (i', a') = zsplit0 a in (i*i', Mul i a'))"
   4.759 +  where
   4.760 +    "zsplit0 (C c) = (0, C c)"
   4.761 +  | "zsplit0 (Bound n) = (if n = 0 then (1, C 0) else (0, Bound n))"
   4.762 +  | "zsplit0 (CN n i a) =
   4.763 +      (let (i', a') =  zsplit0 a
   4.764 +       in if n = 0 then (i + i', a') else (i', CN n i a'))"
   4.765 +  | "zsplit0 (Neg a) = (let (i', a') = zsplit0 a in (-i', Neg a'))"
   4.766 +  | "zsplit0 (Add a b) =
   4.767 +      (let
   4.768 +        (ia, a') = zsplit0 a;
   4.769 +        (ib, b') = zsplit0 b
   4.770 +       in (ia + ib, Add a' b'))"
   4.771 +  | "zsplit0 (Sub a b) =
   4.772 +      (let
   4.773 +        (ia, a') = zsplit0 a;
   4.774 +        (ib, b') = zsplit0 b
   4.775 +       in (ia - ib, Sub a' b'))"
   4.776 +  | "zsplit0 (Mul i a) = (let (i', a') = zsplit0 a in (i*i', Mul i a'))"
   4.777  
   4.778  lemma zsplit0_I:
   4.779    "\<And>n a. zsplit0 t = (n, a) \<Longrightarrow>
   4.780 @@ -978,91 +972,91 @@
   4.781      by simp
   4.782  qed
   4.783  
   4.784 -fun iszlfm :: "fm \<Rightarrow> bool"  \<comment> \<open>Linearity test for fm\<close>
   4.785 -where
   4.786 -  "iszlfm (And p q) \<longleftrightarrow> iszlfm p \<and> iszlfm q"
   4.787 -| "iszlfm (Or p q) \<longleftrightarrow> iszlfm p \<and> iszlfm q"
   4.788 -| "iszlfm (Eq  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.789 -| "iszlfm (NEq (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.790 -| "iszlfm (Lt  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.791 -| "iszlfm (Le  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.792 -| "iszlfm (Gt  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.793 -| "iszlfm (Ge  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.794 -| "iszlfm (Dvd i (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> i > 0 \<and> numbound0 e"
   4.795 -| "iszlfm (NDvd i (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> i > 0 \<and> numbound0 e"
   4.796 -| "iszlfm p \<longleftrightarrow> isatom p \<and> bound0 p"
   4.797 +fun iszlfm :: "fm \<Rightarrow> bool"  \<comment> \<open>linearity test for fm\<close>
   4.798 +  where
   4.799 +    "iszlfm (And p q) \<longleftrightarrow> iszlfm p \<and> iszlfm q"
   4.800 +  | "iszlfm (Or p q) \<longleftrightarrow> iszlfm p \<and> iszlfm q"
   4.801 +  | "iszlfm (Eq  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.802 +  | "iszlfm (NEq (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.803 +  | "iszlfm (Lt  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.804 +  | "iszlfm (Le  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.805 +  | "iszlfm (Gt  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.806 +  | "iszlfm (Ge  (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> numbound0 e"
   4.807 +  | "iszlfm (Dvd i (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> i > 0 \<and> numbound0 e"
   4.808 +  | "iszlfm (NDvd i (CN 0 c e)) \<longleftrightarrow> c > 0 \<and> i > 0 \<and> numbound0 e"
   4.809 +  | "iszlfm p \<longleftrightarrow> isatom p \<and> bound0 p"
   4.810  
   4.811  lemma zlin_qfree: "iszlfm p \<Longrightarrow> qfree p"
   4.812    by (induct p rule: iszlfm.induct) auto
   4.813  
   4.814 -fun zlfm :: "fm \<Rightarrow> fm"  \<comment> \<open>Linearity transformation for fm\<close>
   4.815 -where
   4.816 -  "zlfm (And p q) = And (zlfm p) (zlfm q)"
   4.817 -| "zlfm (Or p q) = Or (zlfm p) (zlfm q)"
   4.818 -| "zlfm (Imp p q) = Or (zlfm (NOT p)) (zlfm q)"
   4.819 -| "zlfm (Iff p q) = Or (And (zlfm p) (zlfm q)) (And (zlfm (NOT p)) (zlfm (NOT q)))"
   4.820 -| "zlfm (Lt a) =
   4.821 -    (let (c, r) = zsplit0 a in
   4.822 -      if c = 0 then Lt r else
   4.823 -      if c > 0 then (Lt (CN 0 c r))
   4.824 -      else Gt (CN 0 (- c) (Neg r)))"
   4.825 -| "zlfm (Le a) =
   4.826 -    (let (c, r) = zsplit0 a in
   4.827 -      if c = 0 then Le r
   4.828 -      else if c > 0 then Le (CN 0 c r)
   4.829 -      else Ge (CN 0 (- c) (Neg r)))"
   4.830 -| "zlfm (Gt a) =
   4.831 -    (let (c, r) = zsplit0 a in
   4.832 -      if c = 0 then Gt r else
   4.833 -      if c > 0 then Gt (CN 0 c r)
   4.834 -      else Lt (CN 0 (- c) (Neg r)))"
   4.835 -| "zlfm (Ge a) =
   4.836 -    (let (c, r) = zsplit0 a in
   4.837 -      if c = 0 then Ge r
   4.838 -      else if c > 0 then Ge (CN 0 c r)
   4.839 -      else Le (CN 0 (- c) (Neg r)))"
   4.840 -| "zlfm (Eq a) =
   4.841 -    (let (c, r) = zsplit0 a in
   4.842 -      if c = 0 then Eq r
   4.843 -      else if c > 0 then Eq (CN 0 c r)
   4.844 -      else Eq (CN 0 (- c) (Neg r)))"
   4.845 -| "zlfm (NEq a) =
   4.846 -    (let (c, r) = zsplit0 a in
   4.847 -      if c = 0 then NEq r
   4.848 -      else if c > 0 then NEq (CN 0 c r)
   4.849 -      else NEq (CN 0 (- c) (Neg r)))"
   4.850 -| "zlfm (Dvd i a) =
   4.851 -    (if i = 0 then zlfm (Eq a)
   4.852 -     else
   4.853 -      let (c, r) = zsplit0 a in
   4.854 -        if c = 0 then Dvd \<bar>i\<bar> r
   4.855 -        else if c > 0 then Dvd \<bar>i\<bar> (CN 0 c r)
   4.856 -        else Dvd \<bar>i\<bar> (CN 0 (- c) (Neg r)))"
   4.857 -| "zlfm (NDvd i a) =
   4.858 -    (if i = 0 then zlfm (NEq a)
   4.859 -     else
   4.860 -      let (c, r) = zsplit0 a in
   4.861 -        if c = 0 then NDvd \<bar>i\<bar> r
   4.862 -        else if c > 0 then NDvd \<bar>i\<bar> (CN 0 c r)
   4.863 -        else NDvd \<bar>i\<bar> (CN 0 (- c) (Neg r)))"
   4.864 -| "zlfm (NOT (And p q)) = Or (zlfm (NOT p)) (zlfm (NOT q))"
   4.865 -| "zlfm (NOT (Or p q)) = And (zlfm (NOT p)) (zlfm (NOT q))"
   4.866 -| "zlfm (NOT (Imp p q)) = And (zlfm p) (zlfm (NOT q))"
   4.867 -| "zlfm (NOT (Iff p q)) = Or (And(zlfm p) (zlfm(NOT q))) (And (zlfm(NOT p)) (zlfm q))"
   4.868 -| "zlfm (NOT (NOT p)) = zlfm p"
   4.869 -| "zlfm (NOT T) = F"
   4.870 -| "zlfm (NOT F) = T"
   4.871 -| "zlfm (NOT (Lt a)) = zlfm (Ge a)"
   4.872 -| "zlfm (NOT (Le a)) = zlfm (Gt a)"
   4.873 -| "zlfm (NOT (Gt a)) = zlfm (Le a)"
   4.874 -| "zlfm (NOT (Ge a)) = zlfm (Lt a)"
   4.875 -| "zlfm (NOT (Eq a)) = zlfm (NEq a)"
   4.876 -| "zlfm (NOT (NEq a)) = zlfm (Eq a)"
   4.877 -| "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)"
   4.878 -| "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)"
   4.879 -| "zlfm (NOT (Closed P)) = NClosed P"
   4.880 -| "zlfm (NOT (NClosed P)) = Closed P"
   4.881 -| "zlfm p = p"
   4.882 +fun zlfm :: "fm \<Rightarrow> fm"  \<comment> \<open>linearity transformation for fm\<close>
   4.883 +  where
   4.884 +    "zlfm (And p q) = And (zlfm p) (zlfm q)"
   4.885 +  | "zlfm (Or p q) = Or (zlfm p) (zlfm q)"
   4.886 +  | "zlfm (Imp p q) = Or (zlfm (NOT p)) (zlfm q)"
   4.887 +  | "zlfm (Iff p q) = Or (And (zlfm p) (zlfm q)) (And (zlfm (NOT p)) (zlfm (NOT q)))"
   4.888 +  | "zlfm (Lt a) =
   4.889 +      (let (c, r) = zsplit0 a in
   4.890 +        if c = 0 then Lt r else
   4.891 +        if c > 0 then (Lt (CN 0 c r))
   4.892 +        else Gt (CN 0 (- c) (Neg r)))"
   4.893 +  | "zlfm (Le a) =
   4.894 +      (let (c, r) = zsplit0 a in
   4.895 +        if c = 0 then Le r
   4.896 +        else if c > 0 then Le (CN 0 c r)
   4.897 +        else Ge (CN 0 (- c) (Neg r)))"
   4.898 +  | "zlfm (Gt a) =
   4.899 +      (let (c, r) = zsplit0 a in
   4.900 +        if c = 0 then Gt r else
   4.901 +        if c > 0 then Gt (CN 0 c r)
   4.902 +        else Lt (CN 0 (- c) (Neg r)))"
   4.903 +  | "zlfm (Ge a) =
   4.904 +      (let (c, r) = zsplit0 a in
   4.905 +        if c = 0 then Ge r
   4.906 +        else if c > 0 then Ge (CN 0 c r)
   4.907 +        else Le (CN 0 (- c) (Neg r)))"
   4.908 +  | "zlfm (Eq a) =
   4.909 +      (let (c, r) = zsplit0 a in
   4.910 +        if c = 0 then Eq r
   4.911 +        else if c > 0 then Eq (CN 0 c r)
   4.912 +        else Eq (CN 0 (- c) (Neg r)))"
   4.913 +  | "zlfm (NEq a) =
   4.914 +      (let (c, r) = zsplit0 a in
   4.915 +        if c = 0 then NEq r
   4.916 +        else if c > 0 then NEq (CN 0 c r)
   4.917 +        else NEq (CN 0 (- c) (Neg r)))"
   4.918 +  | "zlfm (Dvd i a) =
   4.919 +      (if i = 0 then zlfm (Eq a)
   4.920 +       else
   4.921 +        let (c, r) = zsplit0 a in
   4.922 +          if c = 0 then Dvd \<bar>i\<bar> r
   4.923 +          else if c > 0 then Dvd \<bar>i\<bar> (CN 0 c r)
   4.924 +          else Dvd \<bar>i\<bar> (CN 0 (- c) (Neg r)))"
   4.925 +  | "zlfm (NDvd i a) =
   4.926 +      (if i = 0 then zlfm (NEq a)
   4.927 +       else
   4.928 +        let (c, r) = zsplit0 a in
   4.929 +          if c = 0 then NDvd \<bar>i\<bar> r
   4.930 +          else if c > 0 then NDvd \<bar>i\<bar> (CN 0 c r)
   4.931 +          else NDvd \<bar>i\<bar> (CN 0 (- c) (Neg r)))"
   4.932 +  | "zlfm (NOT (And p q)) = Or (zlfm (NOT p)) (zlfm (NOT q))"
   4.933 +  | "zlfm (NOT (Or p q)) = And (zlfm (NOT p)) (zlfm (NOT q))"
   4.934 +  | "zlfm (NOT (Imp p q)) = And (zlfm p) (zlfm (NOT q))"
   4.935 +  | "zlfm (NOT (Iff p q)) = Or (And(zlfm p) (zlfm(NOT q))) (And (zlfm(NOT p)) (zlfm q))"
   4.936 +  | "zlfm (NOT (NOT p)) = zlfm p"
   4.937 +  | "zlfm (NOT T) = F"
   4.938 +  | "zlfm (NOT F) = T"
   4.939 +  | "zlfm (NOT (Lt a)) = zlfm (Ge a)"
   4.940 +  | "zlfm (NOT (Le a)) = zlfm (Gt a)"
   4.941 +  | "zlfm (NOT (Gt a)) = zlfm (Le a)"
   4.942 +  | "zlfm (NOT (Ge a)) = zlfm (Lt a)"
   4.943 +  | "zlfm (NOT (Eq a)) = zlfm (NEq a)"
   4.944 +  | "zlfm (NOT (NEq a)) = zlfm (Eq a)"
   4.945 +  | "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)"
   4.946 +  | "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)"
   4.947 +  | "zlfm (NOT (Closed P)) = NClosed P"
   4.948 +  | "zlfm (NOT (NClosed P)) = Closed P"
   4.949 +  | "zlfm p = p"
   4.950  
   4.951  lemma zlfm_I:
   4.952    assumes qfp: "qfree p"
   4.953 @@ -1212,7 +1206,7 @@
   4.954    have spl: "zsplit0 a = (?c, ?r)"
   4.955      by simp
   4.956    from zsplit0_I[OF spl, where x="i" and bs="bs"]
   4.957 -  have Ia:"Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
   4.958 +  have Ia: "Inum (i # bs) a = Inum (i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r"
   4.959      by auto
   4.960    let ?N = "\<lambda>t. Inum (i # bs) t"
   4.961    consider "j = 0" | "j \<noteq> 0" "?c = 0" | "j \<noteq> 0" "?c > 0" | "j \<noteq> 0" "?c < 0"
   4.962 @@ -1247,48 +1241,48 @@
   4.963    qed
   4.964  qed auto
   4.965  
   4.966 -fun minusinf :: "fm \<Rightarrow> fm" \<comment> \<open>Virtual substitution of \<open>-\<infinity>\<close>\<close>
   4.967 -where
   4.968 -  "minusinf (And p q) = And (minusinf p) (minusinf q)"
   4.969 -| "minusinf (Or p q) = Or (minusinf p) (minusinf q)"
   4.970 -| "minusinf (Eq  (CN 0 c e)) = F"
   4.971 -| "minusinf (NEq (CN 0 c e)) = T"
   4.972 -| "minusinf (Lt  (CN 0 c e)) = T"
   4.973 -| "minusinf (Le  (CN 0 c e)) = T"
   4.974 -| "minusinf (Gt  (CN 0 c e)) = F"
   4.975 -| "minusinf (Ge  (CN 0 c e)) = F"
   4.976 -| "minusinf p = p"
   4.977 +fun minusinf :: "fm \<Rightarrow> fm" \<comment> \<open>virtual substitution of \<open>-\<infinity>\<close>\<close>
   4.978 +  where
   4.979 +    "minusinf (And p q) = And (minusinf p) (minusinf q)"
   4.980 +  | "minusinf (Or p q) = Or (minusinf p) (minusinf q)"
   4.981 +  | "minusinf (Eq  (CN 0 c e)) = F"
   4.982 +  | "minusinf (NEq (CN 0 c e)) = T"
   4.983 +  | "minusinf (Lt  (CN 0 c e)) = T"
   4.984 +  | "minusinf (Le  (CN 0 c e)) = T"
   4.985 +  | "minusinf (Gt  (CN 0 c e)) = F"
   4.986 +  | "minusinf (Ge  (CN 0 c e)) = F"
   4.987 +  | "minusinf p = p"
   4.988  
   4.989  lemma minusinf_qfree: "qfree p \<Longrightarrow> qfree (minusinf p)"
   4.990    by (induct p rule: minusinf.induct) auto
   4.991  
   4.992 -fun plusinf :: "fm \<Rightarrow> fm"  \<comment> \<open>Virtual substitution of \<open>+\<infinity>\<close>\<close>
   4.993 -where
   4.994 -  "plusinf (And p q) = And (plusinf p) (plusinf q)"
   4.995 -| "plusinf (Or p q) = Or (plusinf p) (plusinf q)"
   4.996 -| "plusinf (Eq  (CN 0 c e)) = F"
   4.997 -| "plusinf (NEq (CN 0 c e)) = T"
   4.998 -| "plusinf (Lt  (CN 0 c e)) = F"
   4.999 -| "plusinf (Le  (CN 0 c e)) = F"
  4.1000 -| "plusinf (Gt  (CN 0 c e)) = T"
  4.1001 -| "plusinf (Ge  (CN 0 c e)) = T"
  4.1002 -| "plusinf p = p"
  4.1003 +fun plusinf :: "fm \<Rightarrow> fm"  \<comment> \<open>virtual substitution of \<open>+\<infinity>\<close>\<close>
  4.1004 +  where
  4.1005 +    "plusinf (And p q) = And (plusinf p) (plusinf q)"
  4.1006 +  | "plusinf (Or p q) = Or (plusinf p) (plusinf q)"
  4.1007 +  | "plusinf (Eq  (CN 0 c e)) = F"
  4.1008 +  | "plusinf (NEq (CN 0 c e)) = T"
  4.1009 +  | "plusinf (Lt  (CN 0 c e)) = F"
  4.1010 +  | "plusinf (Le  (CN 0 c e)) = F"
  4.1011 +  | "plusinf (Gt  (CN 0 c e)) = T"
  4.1012 +  | "plusinf (Ge  (CN 0 c e)) = T"
  4.1013 +  | "plusinf p = p"
  4.1014  
  4.1015 -fun \<delta> :: "fm \<Rightarrow> int"  \<comment> \<open>Compute \<open>lcm {d| N\<^sup>? Dvd c*x+t \<in> p}\<close>\<close>
  4.1016 -where
  4.1017 -  "\<delta> (And p q) = lcm (\<delta> p) (\<delta> q)"
  4.1018 -| "\<delta> (Or p q) = lcm (\<delta> p) (\<delta> q)"
  4.1019 -| "\<delta> (Dvd i (CN 0 c e)) = i"
  4.1020 -| "\<delta> (NDvd i (CN 0 c e)) = i"
  4.1021 -| "\<delta> p = 1"
  4.1022 +fun \<delta> :: "fm \<Rightarrow> int"  \<comment> \<open>compute \<open>lcm {d| N\<^sup>? Dvd c*x+t \<in> p}\<close>\<close>
  4.1023 +  where
  4.1024 +    "\<delta> (And p q) = lcm (\<delta> p) (\<delta> q)"
  4.1025 +  | "\<delta> (Or p q) = lcm (\<delta> p) (\<delta> q)"
  4.1026 +  | "\<delta> (Dvd i (CN 0 c e)) = i"
  4.1027 +  | "\<delta> (NDvd i (CN 0 c e)) = i"
  4.1028 +  | "\<delta> p = 1"
  4.1029  
  4.1030 -fun d_\<delta> :: "fm \<Rightarrow> int \<Rightarrow> bool"  \<comment> \<open>check if a given l divides all the ds above\<close>
  4.1031 -where
  4.1032 -  "d_\<delta> (And p q) d \<longleftrightarrow> d_\<delta> p d \<and> d_\<delta> q d"
  4.1033 -| "d_\<delta> (Or p q) d \<longleftrightarrow> d_\<delta> p d \<and> d_\<delta> q d"
  4.1034 -| "d_\<delta> (Dvd i (CN 0 c e)) d \<longleftrightarrow> i dvd d"
  4.1035 -| "d_\<delta> (NDvd i (CN 0 c e)) d \<longleftrightarrow> i dvd d"
  4.1036 -| "d_\<delta> p d \<longleftrightarrow> True"
  4.1037 +fun d_\<delta> :: "fm \<Rightarrow> int \<Rightarrow> bool"  \<comment> \<open>check if a given \<open>l\<close> divides all the \<open>ds\<close> above\<close>
  4.1038 +  where
  4.1039 +    "d_\<delta> (And p q) d \<longleftrightarrow> d_\<delta> p d \<and> d_\<delta> q d"
  4.1040 +  | "d_\<delta> (Or p q) d \<longleftrightarrow> d_\<delta> p d \<and> d_\<delta> q d"
  4.1041 +  | "d_\<delta> (Dvd i (CN 0 c e)) d \<longleftrightarrow> i dvd d"
  4.1042 +  | "d_\<delta> (NDvd i (CN 0 c e)) d \<longleftrightarrow> i dvd d"
  4.1043 +  | "d_\<delta> p d \<longleftrightarrow> True"
  4.1044  
  4.1045  lemma delta_mono:
  4.1046    assumes lin: "iszlfm p"
  4.1047 @@ -1310,93 +1304,92 @@
  4.1048    assumes lin: "iszlfm p"
  4.1049    shows "d_\<delta> p (\<delta> p) \<and> \<delta> p >0"
  4.1050    using lin
  4.1051 -  by (induct p rule: iszlfm.induct)  (auto intro: delta_mono simp add: lcm_pos_int)
  4.1052 +  by (induct p rule: iszlfm.induct) (auto intro: delta_mono simp add: lcm_pos_int)
  4.1053  
  4.1054  fun a_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm"  \<comment> \<open>adjust the coefficients of a formula\<close>
  4.1055 -where
  4.1056 -  "a_\<beta> (And p q) k = And (a_\<beta> p k) (a_\<beta> q k)"
  4.1057 -| "a_\<beta> (Or p q) k = Or (a_\<beta> p k) (a_\<beta> q k)"
  4.1058 -| "a_\<beta> (Eq  (CN 0 c e)) k = Eq (CN 0 1 (Mul (k div c) e))"
  4.1059 -| "a_\<beta> (NEq (CN 0 c e)) k = NEq (CN 0 1 (Mul (k div c) e))"
  4.1060 -| "a_\<beta> (Lt  (CN 0 c e)) k = Lt (CN 0 1 (Mul (k div c) e))"
  4.1061 -| "a_\<beta> (Le  (CN 0 c e)) k = Le (CN 0 1 (Mul (k div c) e))"
  4.1062 -| "a_\<beta> (Gt  (CN 0 c e)) k = Gt (CN 0 1 (Mul (k div c) e))"
  4.1063 -| "a_\<beta> (Ge  (CN 0 c e)) k = Ge (CN 0 1 (Mul (k div c) e))"
  4.1064 -| "a_\<beta> (Dvd i (CN 0 c e)) k = Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e))"
  4.1065 -| "a_\<beta> (NDvd i (CN 0 c e)) k = NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e))"
  4.1066 -| "a_\<beta> p k = p"
  4.1067 +  where
  4.1068 +    "a_\<beta> (And p q) k = And (a_\<beta> p k) (a_\<beta> q k)"
  4.1069 +  | "a_\<beta> (Or p q) k = Or (a_\<beta> p k) (a_\<beta> q k)"
  4.1070 +  | "a_\<beta> (Eq  (CN 0 c e)) k = Eq (CN 0 1 (Mul (k div c) e))"
  4.1071 +  | "a_\<beta> (NEq (CN 0 c e)) k = NEq (CN 0 1 (Mul (k div c) e))"
  4.1072 +  | "a_\<beta> (Lt  (CN 0 c e)) k = Lt (CN 0 1 (Mul (k div c) e))"
  4.1073 +  | "a_\<beta> (Le  (CN 0 c e)) k = Le (CN 0 1 (Mul (k div c) e))"
  4.1074 +  | "a_\<beta> (Gt  (CN 0 c e)) k = Gt (CN 0 1 (Mul (k div c) e))"
  4.1075 +  | "a_\<beta> (Ge  (CN 0 c e)) k = Ge (CN 0 1 (Mul (k div c) e))"
  4.1076 +  | "a_\<beta> (Dvd i (CN 0 c e)) k = Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e))"
  4.1077 +  | "a_\<beta> (NDvd i (CN 0 c e)) k = NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e))"
  4.1078 +  | "a_\<beta> p k = p"
  4.1079  
  4.1080 -fun d_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> bool"  \<comment> \<open>test if all coeffs c of c divide a given l\<close>
  4.1081 -where
  4.1082 -  "d_\<beta> (And p q) k \<longleftrightarrow> d_\<beta> p k \<and> d_\<beta> q k"
  4.1083 -| "d_\<beta> (Or p q) k \<longleftrightarrow> d_\<beta> p k \<and> d_\<beta> q k"
  4.1084 -| "d_\<beta> (Eq  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1085 -| "d_\<beta> (NEq (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1086 -| "d_\<beta> (Lt  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1087 -| "d_\<beta> (Le  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1088 -| "d_\<beta> (Gt  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1089 -| "d_\<beta> (Ge  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1090 -| "d_\<beta> (Dvd i (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1091 -| "d_\<beta> (NDvd i (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1092 -| "d_\<beta> p k \<longleftrightarrow> True"
  4.1093 +fun d_\<beta> :: "fm \<Rightarrow> int \<Rightarrow> bool"  \<comment> \<open>test if all coeffs of \<open>c\<close> divide a given \<open>l\<close>\<close>
  4.1094 +  where
  4.1095 +    "d_\<beta> (And p q) k \<longleftrightarrow> d_\<beta> p k \<and> d_\<beta> q k"
  4.1096 +  | "d_\<beta> (Or p q) k \<longleftrightarrow> d_\<beta> p k \<and> d_\<beta> q k"
  4.1097 +  | "d_\<beta> (Eq  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1098 +  | "d_\<beta> (NEq (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1099 +  | "d_\<beta> (Lt  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1100 +  | "d_\<beta> (Le  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1101 +  | "d_\<beta> (Gt  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1102 +  | "d_\<beta> (Ge  (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1103 +  | "d_\<beta> (Dvd i (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1104 +  | "d_\<beta> (NDvd i (CN 0 c e)) k \<longleftrightarrow> c dvd k"
  4.1105 +  | "d_\<beta> p k \<longleftrightarrow> True"
  4.1106  
  4.1107 -fun \<zeta> :: "fm \<Rightarrow> int"  \<comment> \<open>computes the lcm of all coefficients of x\<close>
  4.1108 -where
  4.1109 -  "\<zeta> (And p q) = lcm (\<zeta> p) (\<zeta> q)"
  4.1110 -| "\<zeta> (Or p q) = lcm (\<zeta> p) (\<zeta> q)"
  4.1111 -| "\<zeta> (Eq  (CN 0 c e)) = c"
  4.1112 -| "\<zeta> (NEq (CN 0 c e)) = c"
  4.1113 -| "\<zeta> (Lt  (CN 0 c e)) = c"
  4.1114 -| "\<zeta> (Le  (CN 0 c e)) = c"
  4.1115 -| "\<zeta> (Gt  (CN 0 c e)) = c"
  4.1116 -| "\<zeta> (Ge  (CN 0 c e)) = c"
  4.1117 -| "\<zeta> (Dvd i (CN 0 c e)) = c"
  4.1118 -| "\<zeta> (NDvd i (CN 0 c e))= c"
  4.1119 -| "\<zeta> p = 1"
  4.1120 +fun \<zeta> :: "fm \<Rightarrow> int"  \<comment> \<open>computes the lcm of all coefficients of \<open>x\<close>\<close>
  4.1121 +  where
  4.1122 +    "\<zeta> (And p q) = lcm (\<zeta> p) (\<zeta> q)"
  4.1123 +  | "\<zeta> (Or p q) = lcm (\<zeta> p) (\<zeta> q)"
  4.1124 +  | "\<zeta> (Eq  (CN 0 c e)) = c"
  4.1125 +  | "\<zeta> (NEq (CN 0 c e)) = c"
  4.1126 +  | "\<zeta> (Lt  (CN 0 c e)) = c"
  4.1127 +  | "\<zeta> (Le  (CN 0 c e)) = c"
  4.1128 +  | "\<zeta> (Gt  (CN 0 c e)) = c"
  4.1129 +  | "\<zeta> (Ge  (CN 0 c e)) = c"
  4.1130 +  | "\<zeta> (Dvd i (CN 0 c e)) = c"
  4.1131 +  | "\<zeta> (NDvd i (CN 0 c e))= c"
  4.1132 +  | "\<zeta> p = 1"
  4.1133  
  4.1134  fun \<beta> :: "fm \<Rightarrow> num list"
  4.1135 -where
  4.1136 -  "\<beta> (And p q) = (\<beta> p @ \<beta> q)"
  4.1137 -| "\<beta> (Or p q) = (\<beta> p @ \<beta> q)"
  4.1138 -| "\<beta> (Eq  (CN 0 c e)) = [Sub (C (- 1)) e]"
  4.1139 -| "\<beta> (NEq (CN 0 c e)) = [Neg e]"
  4.1140 -| "\<beta> (Lt  (CN 0 c e)) = []"
  4.1141 -| "\<beta> (Le  (CN 0 c e)) = []"
  4.1142 -| "\<beta> (Gt  (CN 0 c e)) = [Neg e]"
  4.1143 -| "\<beta> (Ge  (CN 0 c e)) = [Sub (C (- 1)) e]"
  4.1144 -| "\<beta> p = []"
  4.1145 +  where
  4.1146 +    "\<beta> (And p q) = (\<beta> p @ \<beta> q)"
  4.1147 +  | "\<beta> (Or p q) = (\<beta> p @ \<beta> q)"
  4.1148 +  | "\<beta> (Eq  (CN 0 c e)) = [Sub (C (- 1)) e]"
  4.1149 +  | "\<beta> (NEq (CN 0 c e)) = [Neg e]"
  4.1150 +  | "\<beta> (Lt  (CN 0 c e)) = []"
  4.1151 +  | "\<beta> (Le  (CN 0 c e)) = []"
  4.1152 +  | "\<beta> (Gt  (CN 0 c e)) = [Neg e]"
  4.1153 +  | "\<beta> (Ge  (CN 0 c e)) = [Sub (C (- 1)) e]"
  4.1154 +  | "\<beta> p = []"
  4.1155  
  4.1156  fun \<alpha> :: "fm \<Rightarrow> num list"
  4.1157 -where
  4.1158 -  "\<alpha> (And p q) = \<alpha> p @ \<alpha> q"
  4.1159 -| "\<alpha> (Or p q) = \<alpha> p @ \<alpha> q"
  4.1160 -| "\<alpha> (Eq  (CN 0 c e)) = [Add (C (- 1)) e]"
  4.1161 -| "\<alpha> (NEq (CN 0 c e)) = [e]"
  4.1162 -| "\<alpha> (Lt  (CN 0 c e)) = [e]"
  4.1163 -| "\<alpha> (Le  (CN 0 c e)) = [Add (C (- 1)) e]"
  4.1164 -| "\<alpha> (Gt  (CN 0 c e)) = []"
  4.1165 -| "\<alpha> (Ge  (CN 0 c e)) = []"
  4.1166 -| "\<alpha> p = []"
  4.1167 +  where
  4.1168 +    "\<alpha> (And p q) = \<alpha> p @ \<alpha> q"
  4.1169 +  | "\<alpha> (Or p q) = \<alpha> p @ \<alpha> q"
  4.1170 +  | "\<alpha> (Eq  (CN 0 c e)) = [Add (C (- 1)) e]"
  4.1171 +  | "\<alpha> (NEq (CN 0 c e)) = [e]"
  4.1172 +  | "\<alpha> (Lt  (CN 0 c e)) = [e]"
  4.1173 +  | "\<alpha> (Le  (CN 0 c e)) = [Add (C (- 1)) e]"
  4.1174 +  | "\<alpha> (Gt  (CN 0 c e)) = []"
  4.1175 +  | "\<alpha> (Ge  (CN 0 c e)) = []"
  4.1176 +  | "\<alpha> p = []"
  4.1177  
  4.1178  fun mirror :: "fm \<Rightarrow> fm"
  4.1179 -where
  4.1180 -  "mirror (And p q) = And (mirror p) (mirror q)"
  4.1181 -| "mirror (Or p q) = Or (mirror p) (mirror q)"
  4.1182 -| "mirror (Eq  (CN 0 c e)) = Eq (CN 0 c (Neg e))"
  4.1183 -| "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))"
  4.1184 -| "mirror (Lt  (CN 0 c e)) = Gt (CN 0 c (Neg e))"
  4.1185 -| "mirror (Le  (CN 0 c e)) = Ge (CN 0 c (Neg e))"
  4.1186 -| "mirror (Gt  (CN 0 c e)) = Lt (CN 0 c (Neg e))"
  4.1187 -| "mirror (Ge  (CN 0 c e)) = Le (CN 0 c (Neg e))"
  4.1188 -| "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))"
  4.1189 -| "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
  4.1190 -| "mirror p = p"
  4.1191 +  where
  4.1192 +    "mirror (And p q) = And (mirror p) (mirror q)"
  4.1193 +  | "mirror (Or p q) = Or (mirror p) (mirror q)"
  4.1194 +  | "mirror (Eq  (CN 0 c e)) = Eq (CN 0 c (Neg e))"
  4.1195 +  | "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))"
  4.1196 +  | "mirror (Lt  (CN 0 c e)) = Gt (CN 0 c (Neg e))"
  4.1197 +  | "mirror (Le  (CN 0 c e)) = Ge (CN 0 c (Neg e))"
  4.1198 +  | "mirror (Gt  (CN 0 c e)) = Lt (CN 0 c (Neg e))"
  4.1199 +  | "mirror (Ge  (CN 0 c e)) = Le (CN 0 c (Neg e))"
  4.1200 +  | "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))"
  4.1201 +  | "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
  4.1202 +  | "mirror p = p"
  4.1203  
  4.1204  text \<open>Lemmas for the correctness of \<open>\<sigma>_\<rho>\<close>\<close>
  4.1205  
  4.1206 -lemma dvd1_eq1:
  4.1207 -  fixes x :: int
  4.1208 -  shows "x > 0 \<Longrightarrow> x dvd 1 \<longleftrightarrow> x = 1"
  4.1209 +lemma dvd1_eq1: "x > 0 \<Longrightarrow> x dvd 1 \<longleftrightarrow> x = 1"
  4.1210 +  for x :: int
  4.1211    by simp
  4.1212  
  4.1213  lemma minusinf_inf:
  4.1214 @@ -2141,7 +2134,8 @@
  4.1215      by blast
  4.1216  qed
  4.1217  
  4.1218 -(* Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff. *)
  4.1219 +text \<open>Implement the right hand sides of Cooper's theorem and Ferrante and Rackoff.\<close>
  4.1220 +
  4.1221  lemma mirror_ex:
  4.1222    assumes "iszlfm p"
  4.1223    shows "(\<exists>x. Ifm bbs (x#bs) (mirror p)) \<longleftrightarrow> (\<exists>x. Ifm bbs (x#bs) p)"
  4.1224 @@ -2378,10 +2372,9 @@
  4.1225    using qelim_ci cooper prep by (auto simp add: pa_def)
  4.1226  
  4.1227  definition cooper_test :: "unit \<Rightarrow> fm"
  4.1228 -  where
  4.1229 -    "cooper_test u =
  4.1230 -      pa (E (A (Imp (Ge (Sub (Bound 0) (Bound 1)))
  4.1231 -        (E (E (Eq (Sub (Add (Mul 3 (Bound 1)) (Mul 5 (Bound 0))) (Bound 2))))))))"
  4.1232 +  where "cooper_test u =
  4.1233 +    pa (E (A (Imp (Ge (Sub (Bound 0) (Bound 1)))
  4.1234 +      (E (E (Eq (Sub (Add (Mul 3 (Bound 1)) (Mul 5 (Bound 0))) (Bound 2))))))))"
  4.1235  
  4.1236  ML_val \<open>@{code cooper_test} ()\<close>
  4.1237  
  4.1238 @@ -2505,10 +2498,10 @@
  4.1239    let
  4.1240      val is_op =
  4.1241        member (op =) [@{term HOL.conj}, @{term HOL.disj}, @{term HOL.implies},
  4.1242 -      @{term "op = :: bool => _"},
  4.1243 -      @{term "op = :: int => _"}, @{term "op < :: int => _"},
  4.1244 -      @{term "op <= :: int => _"}, @{term "Not"}, @{term "All :: (int => _) => _"},
  4.1245 -      @{term "Ex :: (int => _) => _"}, @{term "True"}, @{term "False"}]
  4.1246 +      @{term "op = :: bool \<Rightarrow> _"},
  4.1247 +      @{term "op = :: int \<Rightarrow> _"}, @{term "op < :: int \<Rightarrow> _"},
  4.1248 +      @{term "op \<le> :: int \<Rightarrow> _"}, @{term "Not"}, @{term "All :: (int \<Rightarrow> _) \<Rightarrow> _"},
  4.1249 +      @{term "Ex :: (int \<Rightarrow> _) \<Rightarrow> _"}, @{term "True"}, @{term "False"}]
  4.1250      fun is_ty t = not (fastype_of t = HOLogic.boolT)
  4.1251    in
  4.1252      (case t of
  4.1253 @@ -2629,7 +2622,7 @@
  4.1254  theorem "\<forall>(x::int) y. 2 * x + 1 \<noteq> 2 * y"
  4.1255    by cooper
  4.1256  
  4.1257 -theorem "\<exists>(x::int) y. 0 < x  & 0 \<le> y  & 3 * x - 5 * y = 1"
  4.1258 +theorem "\<exists>(x::int) y. 0 < x  \<and> 0 \<le> y \<and> 3 * x - 5 * y = 1"
  4.1259    by cooper
  4.1260  
  4.1261  theorem "\<not> (\<exists>(x::int) (y::int) (z::int). 4*x + (-6::int)*y = 1)"
     5.1 --- a/src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy	Sun Dec 03 19:09:42 2017 +0100
     5.2 +++ b/src/HOL/Decision_Procs/Parametric_Ferrante_Rackoff.thy	Sun Dec 03 22:28:19 2017 +0100
     5.3 @@ -21,14 +21,14 @@
     5.4  begin
     5.5  
     5.6  primrec size_tm :: "tm \<Rightarrow> nat"
     5.7 -where
     5.8 -  "size_tm (CP c) = polysize c"
     5.9 -| "size_tm (Bound n) = 1"
    5.10 -| "size_tm (Neg a) = 1 + size_tm a"
    5.11 -| "size_tm (Add a b) = 1 + size_tm a + size_tm b"
    5.12 -| "size_tm (Sub a b) = 3 + size_tm a + size_tm b"
    5.13 -| "size_tm (Mul c a) = 1 + polysize c + size_tm a"
    5.14 -| "size_tm (CNP n c a) = 3 + polysize c + size_tm a "
    5.15 +  where
    5.16 +    "size_tm (CP c) = polysize c"
    5.17 +  | "size_tm (Bound n) = 1"
    5.18 +  | "size_tm (Neg a) = 1 + size_tm a"
    5.19 +  | "size_tm (Add a b) = 1 + size_tm a + size_tm b"
    5.20 +  | "size_tm (Sub a b) = 3 + size_tm a + size_tm b"
    5.21 +  | "size_tm (Mul c a) = 1 + polysize c + size_tm a"
    5.22 +  | "size_tm (CNP n c a) = 3 + polysize c + size_tm a "
    5.23  
    5.24  instance ..
    5.25  
    5.26 @@ -36,60 +36,59 @@
    5.27  
    5.28  text \<open>Semantics of terms tm.\<close>
    5.29  primrec Itm :: "'a::{field_char_0,field} list \<Rightarrow> 'a list \<Rightarrow> tm \<Rightarrow> 'a"
    5.30 -where
    5.31 -  "Itm vs bs (CP c) = (Ipoly vs c)"
    5.32 -| "Itm vs bs (Bound n) = bs!n"
    5.33 -| "Itm vs bs (Neg a) = -(Itm vs bs a)"
    5.34 -| "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    5.35 -| "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
    5.36 -| "Itm vs bs (Mul c a) = (Ipoly vs c) * Itm vs bs a"
    5.37 -| "Itm vs bs (CNP n c t) = (Ipoly vs c)*(bs!n) + Itm vs bs t"
    5.38 +  where
    5.39 +    "Itm vs bs (CP c) = (Ipoly vs c)"
    5.40 +  | "Itm vs bs (Bound n) = bs!n"
    5.41 +  | "Itm vs bs (Neg a) = -(Itm vs bs a)"
    5.42 +  | "Itm vs bs (Add a b) = Itm vs bs a + Itm vs bs b"
    5.43 +  | "Itm vs bs (Sub a b) = Itm vs bs a - Itm vs bs b"
    5.44 +  | "Itm vs bs (Mul c a) = (Ipoly vs c) * Itm vs bs a"
    5.45 +  | "Itm vs bs (CNP n c t) = (Ipoly vs c)*(bs!n) + Itm vs bs t"
    5.46  
    5.47  fun allpolys :: "(poly \<Rightarrow> bool) \<Rightarrow> tm \<Rightarrow> bool"
    5.48 -where
    5.49 -  "allpolys P (CP c) = P c"
    5.50 -| "allpolys P (CNP n c p) = (P c \<and> allpolys P p)"
    5.51 -| "allpolys P (Mul c p) = (P c \<and> allpolys P p)"
    5.52 -| "allpolys P (Neg p) = allpolys P p"
    5.53 -| "allpolys P (Add p q) = (allpolys P p \<and> allpolys P q)"
    5.54 -| "allpolys P (Sub p q) = (allpolys P p \<and> allpolys P q)"
    5.55 -| "allpolys P p = True"
    5.56 +  where
    5.57 +    "allpolys P (CP c) = P c"
    5.58 +  | "allpolys P (CNP n c p) = (P c \<and> allpolys P p)"
    5.59 +  | "allpolys P (Mul c p) = (P c \<and> allpolys P p)"
    5.60 +  | "allpolys P (Neg p) = allpolys P p"
    5.61 +  | "allpolys P (Add p q) = (allpolys P p \<and> allpolys P q)"
    5.62 +  | "allpolys P (Sub p q) = (allpolys P p \<and> allpolys P q)"
    5.63 +  | "allpolys P p = True"
    5.64  
    5.65  primrec tmboundslt :: "nat \<Rightarrow> tm \<Rightarrow> bool"
    5.66 -where
    5.67 -  "tmboundslt n (CP c) = True"
    5.68 -| "tmboundslt n (Bound m) = (m < n)"
    5.69 -| "tmboundslt n (CNP m c a) = (m < n \<and> tmboundslt n a)"
    5.70 -| "tmboundslt n (Neg a) = tmboundslt n a"
    5.71 -| "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
    5.72 -| "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)"
    5.73 -| "tmboundslt n (Mul i a) = tmboundslt n a"
    5.74 -
    5.75 -primrec tmbound0 :: "tm \<Rightarrow> bool"  \<comment> \<open>a tm is INDEPENDENT of Bound 0\<close>
    5.76 -where
    5.77 -  "tmbound0 (CP c) = True"
    5.78 -| "tmbound0 (Bound n) = (n>0)"
    5.79 -| "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
    5.80 -| "tmbound0 (Neg a) = tmbound0 a"
    5.81 -| "tmbound0 (Add a b) = (tmbound0 a \<and> tmbound0 b)"
    5.82 -| "tmbound0 (Sub a b) = (tmbound0 a \<and> tmbound0 b)"
    5.83 -| "tmbound0 (Mul i a) = tmbound0 a"
    5.84 +  where
    5.85 +    "tmboundslt n (CP c) = True"
    5.86 +  | "tmboundslt n (Bound m) = (m < n)"
    5.87 +  | "tmboundslt n (CNP m c a) = (m < n \<and> tmboundslt n a)"
    5.88 +  | "tmboundslt n (Neg a) = tmboundslt n a"
    5.89 +  | "tmboundslt n (Add a b) = (tmboundslt n a \<and> tmboundslt n b)"
    5.90 +  | "tmboundslt n (Sub a b) = (tmboundslt n a \<and> tmboundslt n b)"
    5.91 +  | "tmboundslt n (Mul i a) = tmboundslt n a"
    5.92 +
    5.93 +primrec tmbound0 :: "tm \<Rightarrow> bool"  \<comment> \<open>a \<open>tm\<close> is \<^emph>\<open>independent\<close> of Bound 0\<close>
    5.94 +  where
    5.95 +    "tmbound0 (CP c) = True"
    5.96 +  | "tmbound0 (Bound n) = (n>0)"
    5.97 +  | "tmbound0 (CNP n c a) = (n\<noteq>0 \<and> tmbound0 a)"
    5.98 +  | "tmbound0 (Neg a) = tmbound0 a"
    5.99 +  | "tmbound0 (Add a b) = (tmbound0 a \<and> tmbound0 b)"
   5.100 +  | "tmbound0 (Sub a b) = (tmbound0 a \<and> tmbound0 b)"
   5.101 +  | "tmbound0 (Mul i a) = tmbound0 a"
   5.102  
   5.103  lemma tmbound0_I:
   5.104 -  assumes nb: "tmbound0 a"
   5.105 +  assumes "tmbound0 a"
   5.106    shows "Itm vs (b#bs) a = Itm vs (b'#bs) a"
   5.107 -  using nb
   5.108 -  by (induct a rule: tm.induct) auto
   5.109 -
   5.110 -primrec tmbound :: "nat \<Rightarrow> tm \<Rightarrow> bool"  \<comment> \<open>a tm is INDEPENDENT of Bound n\<close>
   5.111 -where
   5.112 -  "tmbound n (CP c) = True"
   5.113 -| "tmbound n (Bound m) = (n \<noteq> m)"
   5.114 -| "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
   5.115 -| "tmbound n (Neg a) = tmbound n a"
   5.116 -| "tmbound n (Add a b) = (tmbound n a \<and> tmbound n b)"
   5.117 -| "tmbound n (Sub a b) = (tmbound n a \<and> tmbound n b)"
   5.118 -| "tmbound n (Mul i a) = tmbound n a"
   5.119 +  using assms by (induct a rule: tm.induct) auto
   5.120 +
   5.121 +primrec tmbound :: "nat \<Rightarrow> tm \<Rightarrow> bool"  \<comment> \<open>a \<open>tm\<close> is \<^emph>\<open>independent\<close> of Bound n\<close>
   5.122 +  where
   5.123 +    "tmbound n (CP c) = True"
   5.124 +  | "tmbound n (Bound m) = (n \<noteq> m)"
   5.125 +  | "tmbound n (CNP m c a) = (n\<noteq>m \<and> tmbound n a)"
   5.126 +  | "tmbound n (Neg a) = tmbound n a"
   5.127 +  | "tmbound n (Add a b) = (tmbound n a \<and> tmbound n b)"
   5.128 +  | "tmbound n (Sub a b) = (tmbound n a \<and> tmbound n b)"
   5.129 +  | "tmbound n (Mul i a) = tmbound n a"
   5.130  
   5.131  lemma tmbound0_tmbound_iff: "tmbound 0 t = tmbound0 t"
   5.132    by (induct t) auto
   5.133 @@ -103,24 +102,24 @@
   5.134    by (induct t rule: tm.induct) auto
   5.135  
   5.136  fun decrtm0 :: "tm \<Rightarrow> tm"
   5.137 -where
   5.138 -  "decrtm0 (Bound n) = Bound (n - 1)"
   5.139 -| "decrtm0 (Neg a) = Neg (decrtm0 a)"
   5.140 -| "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)"
   5.141 -| "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)"
   5.142 -| "decrtm0 (Mul c a) = Mul c (decrtm0 a)"
   5.143 -| "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)"
   5.144 -| "decrtm0 a = a"
   5.145 +  where
   5.146 +    "decrtm0 (Bound n) = Bound (n - 1)"
   5.147 +  | "decrtm0 (Neg a) = Neg (decrtm0 a)"
   5.148 +  | "decrtm0 (Add a b) = Add (decrtm0 a) (decrtm0 b)"
   5.149 +  | "decrtm0 (Sub a b) = Sub (decrtm0 a) (decrtm0 b)"
   5.150 +  | "decrtm0 (Mul c a) = Mul c (decrtm0 a)"
   5.151 +  | "decrtm0 (CNP n c a) = CNP (n - 1) c (decrtm0 a)"
   5.152 +  | "decrtm0 a = a"
   5.153  
   5.154  fun incrtm0 :: "tm \<Rightarrow> tm"
   5.155 -where
   5.156 -  "incrtm0 (Bound n) = Bound (n + 1)"
   5.157 -| "incrtm0 (Neg a) = Neg (incrtm0 a)"
   5.158 -| "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)"
   5.159 -| "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)"
   5.160 -| "incrtm0 (Mul c a) = Mul c (incrtm0 a)"
   5.161 -| "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)"
   5.162 -| "incrtm0 a = a"
   5.163 +  where
   5.164 +    "incrtm0 (Bound n) = Bound (n + 1)"
   5.165 +  | "incrtm0 (Neg a) = Neg (incrtm0 a)"
   5.166 +  | "incrtm0 (Add a b) = Add (incrtm0 a) (incrtm0 b)"
   5.167 +  | "incrtm0 (Sub a b) = Sub (incrtm0 a) (incrtm0 b)"
   5.168 +  | "incrtm0 (Mul c a) = Mul c (incrtm0 a)"
   5.169 +  | "incrtm0 (CNP n c a) = CNP (n + 1) c (incrtm0 a)"
   5.170 +  | "incrtm0 a = a"
   5.171  
   5.172  lemma decrtm0:
   5.173    assumes nb: "tmbound0 t"
   5.174 @@ -131,19 +130,19 @@
   5.175    by (induct t rule: decrtm0.induct) simp_all
   5.176  
   5.177  primrec decrtm :: "nat \<Rightarrow> tm \<Rightarrow> tm"
   5.178 -where
   5.179 -  "decrtm m (CP c) = (CP c)"
   5.180 -| "decrtm m (Bound n) = (if n < m then Bound n else Bound (n - 1))"
   5.181 -| "decrtm m (Neg a) = Neg (decrtm m a)"
   5.182 -| "decrtm m (Add a b) = Add (decrtm m a) (decrtm m b)"
   5.183 -| "decrtm m (Sub a b) = Sub (decrtm m a) (decrtm m b)"
   5.184 -| "decrtm m (Mul c a) = Mul c (decrtm m a)"
   5.185 -| "decrtm m (CNP n c a) = (if n < m then CNP n c (decrtm m a) else CNP (n - 1) c (decrtm m a))"
   5.186 +  where
   5.187 +    "decrtm m (CP c) = (CP c)"
   5.188 +  | "decrtm m (Bound n) = (if n < m then Bound n else Bound (n - 1))"
   5.189 +  | "decrtm m (Neg a) = Neg (decrtm m a)"
   5.190 +  | "decrtm m (Add a b) = Add (decrtm m a) (decrtm m b)"
   5.191 +  | "decrtm m (Sub a b) = Sub (decrtm m a) (decrtm m b)"
   5.192 +  | "decrtm m (Mul c a) = Mul c (decrtm m a)"
   5.193 +  | "decrtm m (CNP n c a) = (if n < m then CNP n c (decrtm m a) else CNP (n - 1) c (decrtm m a))"
   5.194  
   5.195  primrec removen :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
   5.196 -where
   5.197 -  "removen n [] = []"
   5.198 -| "removen n (x#xs) = (if n=0 then xs else (x#(removen (n - 1) xs)))"
   5.199 +  where
   5.200 +    "removen n [] = []"
   5.201 +  | "removen n (x#xs) = (if n=0 then xs else (x#(removen (n - 1) xs)))"
   5.202  
   5.203  lemma removen_same: "n \<ge> length xs \<Longrightarrow> removen n xs = xs"
   5.204    by (induct xs arbitrary: n) auto
   5.205 @@ -152,7 +151,7 @@
   5.206    by (induct xs arbitrary: n) auto
   5.207  
   5.208  lemma removen_length: "length (removen n xs) = (if n \<ge> length xs then length xs else length xs - 1)"
   5.209 -  by (induct xs arbitrary: n, auto)
   5.210 +  by (induct xs arbitrary: n) auto
   5.211  
   5.212  lemma removen_nth:
   5.213    "(removen n xs)!m =
   5.214 @@ -212,14 +211,14 @@
   5.215    using bnd nb nle by (induct t rule: tm.induct) (auto simp add: removen_nth)
   5.216  
   5.217  primrec tmsubst0:: "tm \<Rightarrow> tm \<Rightarrow> tm"
   5.218 -where
   5.219 -  "tmsubst0 t (CP c) = CP c"
   5.220 -| "tmsubst0 t (Bound n) = (if n=0 then t else Bound n)"
   5.221 -| "tmsubst0 t (CNP n c a) = (if n=0 then Add (Mul c t) (tmsubst0 t a) else CNP n c (tmsubst0 t a))"
   5.222 -| "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
   5.223 -| "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
   5.224 -| "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)"
   5.225 -| "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
   5.226 +  where
   5.227 +    "tmsubst0 t (CP c) = CP c"
   5.228 +  | "tmsubst0 t (Bound n) = (if n=0 then t else Bound n)"
   5.229 +  | "tmsubst0 t (CNP n c a) = (if n=0 then Add (Mul c t) (tmsubst0 t a) else CNP n c (tmsubst0 t a))"
   5.230 +  | "tmsubst0 t (Neg a) = Neg (tmsubst0 t a)"
   5.231 +  | "tmsubst0 t (Add a b) = Add (tmsubst0 t a) (tmsubst0 t b)"
   5.232 +  | "tmsubst0 t (Sub a b) = Sub (tmsubst0 t a) (tmsubst0 t b)"
   5.233 +  | "tmsubst0 t (Mul i a) = Mul i (tmsubst0 t a)"
   5.234  
   5.235  lemma tmsubst0: "Itm vs (x # bs) (tmsubst0 t a) = Itm vs (Itm vs (x # bs) t # bs) a"
   5.236    by (induct a rule: tm.induct) auto
   5.237 @@ -228,15 +227,15 @@
   5.238    by (induct a rule: tm.induct) auto
   5.239  
   5.240  primrec tmsubst:: "nat \<Rightarrow> tm \<Rightarrow> tm \<Rightarrow> tm"
   5.241 -where
   5.242 -  "tmsubst n t (CP c) = CP c"
   5.243 -| "tmsubst n t (Bound m) = (if n=m then t else Bound m)"
   5.244 -| "tmsubst n t (CNP m c a) =
   5.245 -    (if n = m then Add (Mul c t) (tmsubst n t a) else CNP m c (tmsubst n t a))"
   5.246 -| "tmsubst n t (Neg a) = Neg (tmsubst n t a)"
   5.247 -| "tmsubst n t (Add a b) = Add (tmsubst n t a) (tmsubst n t b)"
   5.248 -| "tmsubst n t (Sub a b) = Sub (tmsubst n t a) (tmsubst n t b)"
   5.249 -| "tmsubst n t (Mul i a) = Mul i (tmsubst n t a)"
   5.250 +  where
   5.251 +    "tmsubst n t (CP c) = CP c"
   5.252 +  | "tmsubst n t (Bound m) = (if n=m then t else Bound m)"
   5.253 +  | "tmsubst n t (CNP m c a) =
   5.254 +      (if n = m then Add (Mul c t) (tmsubst n t a) else CNP m c (tmsubst n t a))"
   5.255 +  | "tmsubst n t (Neg a) = Neg (tmsubst n t a)"
   5.256 +  | "tmsubst n t (Add a b) = Add (tmsubst n t a) (tmsubst n t b)"
   5.257 +  | "tmsubst n t (Sub a b) = Sub (tmsubst n t a) (tmsubst n t b)"
   5.258 +  | "tmsubst n t (Mul i a) = Mul i (tmsubst n t a)"
   5.259  
   5.260  lemma tmsubst:
   5.261    assumes nb: "tmboundslt (length bs) a"
   5.262 @@ -264,26 +263,26 @@
   5.263  text \<open>Simplification.\<close>
   5.264  
   5.265  fun tmadd:: "tm \<Rightarrow> tm \<Rightarrow> tm"
   5.266 -where
   5.267 -  "tmadd (CNP n1 c1 r1) (CNP n2 c2 r2) =
   5.268 -    (if n1 = n2 then
   5.269 -      let c = c1 +\<^sub>p c2
   5.270 -      in if c = 0\<^sub>p then tmadd r1 r2 else CNP n1 c (tmadd r1 r2)
   5.271 -    else if n1 \<le> n2 then (CNP n1 c1 (tmadd r1 (CNP n2 c2 r2)))
   5.272 -    else (CNP n2 c2 (tmadd (CNP n1 c1 r1) r2)))"
   5.273 -| "tmadd (CNP n1 c1 r1) t = CNP n1 c1 (tmadd r1 t)"
   5.274 -| "tmadd t (CNP n2 c2 r2) = CNP n2 c2 (tmadd t r2)"
   5.275 -| "tmadd (CP b1) (CP b2) = CP (b1 +\<^sub>p b2)"
   5.276 -| "tmadd a b = Add a b"
   5.277 +  where
   5.278 +    "tmadd (CNP n1 c1 r1) (CNP n2 c2 r2) =
   5.279 +      (if n1 = n2 then
   5.280 +        let c = c1 +\<^sub>p c2
   5.281 +        in if c = 0\<^sub>p then tmadd r1 r2 else CNP n1 c (tmadd r1 r2)
   5.282 +      else if n1 \<le> n2 then (CNP n1 c1 (tmadd r1 (CNP n2 c2 r2)))
   5.283 +      else (CNP n2 c2 (tmadd (CNP n1 c1 r1) r2)))"
   5.284 +  | "tmadd (CNP n1 c1 r1) t = CNP n1 c1 (tmadd r1 t)"
   5.285 +  | "tmadd t (CNP n2 c2 r2) = CNP n2 c2 (tmadd t r2)"
   5.286 +  | "tmadd (CP b1) (CP b2) = CP (b1 +\<^sub>p b2)"
   5.287 +  | "tmadd a b = Add a b"
   5.288  
   5.289  lemma tmadd [simp]: "Itm vs bs (tmadd t s) = Itm vs bs (Add t s)"
   5.290    apply (induct t s rule: tmadd.induct)
   5.291 -  apply (simp_all add: Let_def)
   5.292 +                      apply (simp_all add: Let_def)
   5.293    apply (case_tac "c1 +\<^sub>p c2 = 0\<^sub>p")
   5.294 -  apply (case_tac "n1 \<le> n2")
   5.295 -  apply simp_all
   5.296 -  apply (case_tac "n1 = n2")
   5.297 -  apply (simp_all add: algebra_simps)
   5.298 +   apply (case_tac "n1 \<le> n2")
   5.299 +    apply simp_all
   5.300 +   apply (case_tac "n1 = n2")
   5.301 +    apply (simp_all add: algebra_simps)
   5.302    apply (simp only: distrib_left [symmetric] polyadd [symmetric])
   5.303    apply simp
   5.304    done
   5.305 @@ -302,10 +301,10 @@
   5.306    by (induct t s rule: tmadd.induct) (simp_all add: Let_def polyadd_norm)
   5.307  
   5.308  fun tmmul:: "tm \<Rightarrow> poly \<Rightarrow> tm"
   5.309 -where
   5.310 -  "tmmul (CP j) = (\<lambda>i. CP (i *\<^sub>p j))"
   5.311 -| "tmmul (CNP n c a) = (\<lambda>i. CNP n (i *\<^sub>p c) (tmmul a i))"
   5.312 -| "tmmul t = (\<lambda>i. Mul i t)"
   5.313 +  where
   5.314 +    "tmmul (CP j) = (\<lambda>i. CP (i *\<^sub>p j))"
   5.315 +  | "tmmul (CNP n c a) = (\<lambda>i. CNP n (i *\<^sub>p c) (tmmul a i))"
   5.316 +  | "tmmul t = (\<lambda>i. Mul i t)"
   5.317  
   5.318  lemma tmmul[simp]: "Itm vs bs (tmmul t i) = Itm vs bs (Mul i t)"
   5.319    by (induct t arbitrary: i rule: tmmul.induct) (simp_all add: field_simps)
   5.320 @@ -343,12 +342,12 @@
   5.321    using tmneg_def by simp
   5.322  
   5.323  lemma [simp]: "isnpoly (C (-1, 1))"
   5.324 -  unfolding isnpoly_def by simp
   5.325 +  by (simp add: isnpoly_def)
   5.326  
   5.327  lemma tmneg_allpolys_npoly[simp]:
   5.328    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   5.329    shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly (tmneg t)"
   5.330 -  unfolding tmneg_def by auto
   5.331 +  by (auto simp: tmneg_def)
   5.332  
   5.333  lemma tmsub[simp]: "Itm vs bs (tmsub a b) = Itm vs bs (Sub a b)"
   5.334    using tmsub_def by simp
   5.335 @@ -365,19 +364,19 @@
   5.336  lemma tmsub_allpolys_npoly[simp]:
   5.337    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   5.338    shows "allpolys isnpoly t \<Longrightarrow> allpolys isnpoly s \<Longrightarrow> allpolys isnpoly (tmsub t s)"
   5.339 -  unfolding tmsub_def by (simp add: isnpoly_def)
   5.340 +  by (simp add: tmsub_def isnpoly_def)
   5.341  
   5.342  fun simptm :: "tm \<Rightarrow> tm"
   5.343 -where
   5.344 -  "simptm (CP j) = CP (polynate j)"
   5.345 -| "simptm (Bound n) = CNP n (1)\<^sub>p (CP 0\<^sub>p)"
   5.346 -| "simptm (Neg t) = tmneg (simptm t)"
   5.347 -| "simptm (Add t s) = tmadd (simptm t) (simptm s)"
   5.348 -| "simptm (Sub t s) = tmsub (simptm t) (simptm s)"
   5.349 -| "simptm (Mul i t) =
   5.350 -    (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   5.351 -| "simptm (CNP n c t) =
   5.352 -    (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p)) (simptm t))"
   5.353 +  where
   5.354 +    "simptm (CP j) = CP (polynate j)"
   5.355 +  | "simptm (Bound n) = CNP n (1)\<^sub>p (CP 0\<^sub>p)"
   5.356 +  | "simptm (Neg t) = tmneg (simptm t)"
   5.357 +  | "simptm (Add t s) = tmadd (simptm t) (simptm s)"
   5.358 +  | "simptm (Sub t s) = tmsub (simptm t) (simptm s)"
   5.359 +  | "simptm (Mul i t) =
   5.360 +      (let i' = polynate i in if i' = 0\<^sub>p then CP 0\<^sub>p else tmmul (simptm t) i')"
   5.361 +  | "simptm (CNP n c t) =
   5.362 +      (let c' = polynate c in if c' = 0\<^sub>p then simptm t else tmadd (CNP n c' (CP 0\<^sub>p)) (simptm t))"
   5.363  
   5.364  lemma polynate_stupid:
   5.365    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   5.366 @@ -410,15 +409,15 @@
   5.367  declare let_cong[fundef_cong del]
   5.368  
   5.369  fun split0 :: "tm \<Rightarrow> poly \<times> tm"
   5.370 -where
   5.371 -  "split0 (Bound 0) = ((1)\<^sub>p, CP 0\<^sub>p)"
   5.372 -| "split0 (CNP 0 c t) = (let (c', t') = split0 t in (c +\<^sub>p c', t'))"
   5.373 -| "split0 (Neg t) = (let (c, t') = split0 t in (~\<^sub>p c, Neg t'))"
   5.374 -| "split0 (CNP n c t) = (let (c', t') = split0 t in (c', CNP n c t'))"
   5.375 -| "split0 (Add s t) = (let (c1, s') = split0 s; (c2, t') = split0 t in (c1 +\<^sub>p c2, Add s' t'))"
   5.376 -| "split0 (Sub s t) = (let (c1, s') = split0 s; (c2, t') = split0 t in (c1 -\<^sub>p c2, Sub s' t'))"
   5.377 -| "split0 (Mul c t) = (let (c', t') = split0 t in (c *\<^sub>p c', Mul c t'))"
   5.378 -| "split0 t = (0\<^sub>p, t)"
   5.379 +  where
   5.380 +    "split0 (Bound 0) = ((1)\<^sub>p, CP 0\<^sub>p)"
   5.381 +  | "split0 (CNP 0 c t) = (let (c', t') = split0 t in (c +\<^sub>p c', t'))"
   5.382 +  | "split0 (Neg t) = (let (c, t') = split0 t in (~\<^sub>p c, Neg t'))"
   5.383 +  | "split0 (CNP n c t) = (let (c', t') = split0 t in (c', CNP n c t'))"
   5.384 +  | "split0 (Add s t) = (let (c1, s') = split0 s; (c2, t') = split0 t in (c1 +\<^sub>p c2, Add s' t'))"
   5.385 +  | "split0 (Sub s t) = (let (c1, s') = split0 s; (c2, t') = split0 t in (c1 -\<^sub>p c2, Sub s' t'))"
   5.386 +  | "split0 (Mul c t) = (let (c', t') = split0 t in (c *\<^sub>p c', Mul c t'))"
   5.387 +  | "split0 t = (0\<^sub>p, t)"
   5.388  
   5.389  declare let_cong[fundef_cong]
   5.390  
   5.391 @@ -431,14 +430,14 @@
   5.392  lemma split0:
   5.393    "tmbound 0 (snd (split0 t)) \<and> Itm vs bs (CNP 0 (fst (split0 t)) (snd (split0 t))) = Itm vs bs t"
   5.394    apply (induct t rule: split0.induct)
   5.395 -  apply simp
   5.396 -  apply (simp add: Let_def split_def field_simps)
   5.397 -  apply (simp add: Let_def split_def field_simps)
   5.398 -  apply (simp add: Let_def split_def field_simps)
   5.399 -  apply (simp add: Let_def split_def field_simps)
   5.400 -  apply (simp add: Let_def split_def field_simps)
   5.401 -  apply (simp add: Let_def split_def mult.assoc distrib_left[symmetric])
   5.402 -  apply (simp add: Let_def split_def field_simps)
   5.403 +          apply simp
   5.404 +         apply (simp add: Let_def split_def field_simps)
   5.405 +        apply (simp add: Let_def split_def field_simps)
   5.406 +       apply (simp add: Let_def split_def field_simps)
   5.407 +      apply (simp add: Let_def split_def field_simps)
   5.408 +     apply (simp add: Let_def split_def field_simps)
   5.409 +    apply (simp add: Let_def split_def mult.assoc distrib_left[symmetric])
   5.410 +   apply (simp add: Let_def split_def field_simps)
   5.411    apply (simp add: Let_def split_def field_simps)
   5.412    done
   5.413  
   5.414 @@ -446,10 +445,9 @@
   5.415  proof -
   5.416    fix c' t'
   5.417    assume "split0 t = (c', t')"
   5.418 -  then have "c' = fst (split0 t)" and "t' = snd (split0 t)"
   5.419 +  then have "c' = fst (split0 t)" "t' = snd (split0 t)"
   5.420      by auto
   5.421 -  with split0[where t="t" and bs="bs"]
   5.422 -  show "Itm vs bs t = Itm vs bs (CNP 0 c' t')"
   5.423 +  with split0[where t="t" and bs="bs"] show "Itm vs bs t = Itm vs bs (CNP 0 c' t')"
   5.424      by simp
   5.425  qed
   5.426  
   5.427 @@ -459,7 +457,7 @@
   5.428  proof -
   5.429    fix c' t'
   5.430    assume "split0 t = (c', t')"
   5.431 -  then have "c' = fst (split0 t)" and "t' = snd (split0 t)"
   5.432 +  then have "c' = fst (split0 t)" "t' = snd (split0 t)"
   5.433      by auto
   5.434    with conjunct1[OF split0[where t="t"]] show "tmbound 0 t'"
   5.435      by simp
   5.436 @@ -509,20 +507,20 @@
   5.437  begin
   5.438  
   5.439  primrec size_fm :: "fm \<Rightarrow> nat"
   5.440 -where
   5.441 -  "size_fm (NOT p) = 1 + size_fm p"
   5.442 -| "size_fm (And p q) = 1 + size_fm p + size_fm q"
   5.443 -| "size_fm (Or p q) = 1 + size_fm p + size_fm q"
   5.444 -| "size_fm (Imp p q) = 3 + size_fm p + size_fm q"
   5.445 -| "size_fm (Iff p q) = 3 + 2 * (size_fm p + size_fm q)"
   5.446 -| "size_fm (E p) = 1 + size_fm p"
   5.447 -| "size_fm (A p) = 4 + size_fm p"
   5.448 -| "size_fm T = 1"
   5.449 -| "size_fm F = 1"
   5.450 -| "size_fm (Le _) = 1"
   5.451 -| "size_fm (Lt _) = 1"
   5.452 -| "size_fm (Eq _) = 1"
   5.453 -| "size_fm (NEq _) = 1"
   5.454 +  where
   5.455 +    "size_fm (NOT p) = 1 + size_fm p"
   5.456 +  | "size_fm (And p q) = 1 + size_fm p + size_fm q"
   5.457 +  | "size_fm (Or p q) = 1 + size_fm p + size_fm q"
   5.458 +  | "size_fm (Imp p q) = 3 + size_fm p + size_fm q"
   5.459 +  | "size_fm (Iff p q) = 3 + 2 * (size_fm p + size_fm q)"
   5.460 +  | "size_fm (E p) = 1 + size_fm p"
   5.461 +  | "size_fm (A p) = 4 + size_fm p"
   5.462 +  | "size_fm T = 1"
   5.463 +  | "size_fm F = 1"
   5.464 +  | "size_fm (Le _) = 1"
   5.465 +  | "size_fm (Lt _) = 1"
   5.466 +  | "size_fm (Eq _) = 1"
   5.467 +  | "size_fm (NEq _) = 1"
   5.468  
   5.469  instance ..
   5.470  
   5.471 @@ -533,39 +531,38 @@
   5.472  
   5.473  text \<open>Semantics of formulae (fm).\<close>
   5.474  primrec Ifm ::"'a::linordered_field list \<Rightarrow> 'a list \<Rightarrow> fm \<Rightarrow> bool"
   5.475 -where
   5.476 -  "Ifm vs bs T = True"
   5.477 -| "Ifm vs bs F = False"
   5.478 -| "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   5.479 -| "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   5.480 -| "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
   5.481 -| "Ifm vs bs (NEq a) = (Itm vs bs a \<noteq> 0)"
   5.482 -| "Ifm vs bs (NOT p) = (\<not> (Ifm vs bs p))"
   5.483 -| "Ifm vs bs (And p q) = (Ifm vs bs p \<and> Ifm vs bs q)"
   5.484 -| "Ifm vs bs (Or p q) = (Ifm vs bs p \<or> Ifm vs bs q)"
   5.485 -| "Ifm vs bs (Imp p q) = ((Ifm vs bs p) \<longrightarrow> (Ifm vs bs q))"
   5.486 -| "Ifm vs bs (Iff p q) = (Ifm vs bs p = Ifm vs bs q)"
   5.487 -| "Ifm vs bs (E p) = (\<exists>x. Ifm vs (x#bs) p)"
   5.488 -| "Ifm vs bs (A p) = (\<forall>x. Ifm vs (x#bs) p)"
   5.489 +  where
   5.490 +    "Ifm vs bs T = True"
   5.491 +  | "Ifm vs bs F = False"
   5.492 +  | "Ifm vs bs (Lt a) = (Itm vs bs a < 0)"
   5.493 +  | "Ifm vs bs (Le a) = (Itm vs bs a \<le> 0)"
   5.494 +  | "Ifm vs bs (Eq a) = (Itm vs bs a = 0)"
   5.495 +  | "Ifm vs bs (NEq a) = (Itm vs bs a \<noteq> 0)"
   5.496 +  | "Ifm vs bs (NOT p) = (\<not> (Ifm vs bs p))"
   5.497 +  | "Ifm vs bs (And p q) = (Ifm vs bs p \<and> Ifm vs bs q)"
   5.498 +  | "Ifm vs bs (Or p q) = (Ifm vs bs p \<or> Ifm vs bs q)"
   5.499 +  | "Ifm vs bs (Imp p q) = ((Ifm vs bs p) \<longrightarrow> (Ifm vs bs q))"
   5.500 +  | "Ifm vs bs (Iff p q) = (Ifm vs bs p = Ifm vs bs q)"
   5.501 +  | "Ifm vs bs (E p) = (\<exists>x. Ifm vs (x#bs) p)"
   5.502 +  | "Ifm vs bs (A p) = (\<forall>x. Ifm vs (x#bs) p)"
   5.503  
   5.504  fun not:: "fm \<Rightarrow> fm"
   5.505 -where
   5.506 -  "not (NOT (NOT p)) = not p"
   5.507 -| "not (NOT p) = p"
   5.508 -| "not T = F"
   5.509 -| "not F = T"
   5.510 -| "not (Lt t) = Le (tmneg t)"
   5.511 -| "not (Le t) = Lt (tmneg t)"
   5.512 -| "not (Eq t) = NEq t"
   5.513 -| "not (NEq t) = Eq t"
   5.514 -| "not p = NOT p"
   5.515 +  where
   5.516 +    "not (NOT (NOT p)) = not p"
   5.517 +  | "not (NOT p) = p"
   5.518 +  | "not T = F"
   5.519 +  | "not F = T"
   5.520 +  | "not (Lt t) = Le (tmneg t)"
   5.521 +  | "not (Le t) = Lt (tmneg t)"
   5.522 +  | "not (Eq t) = NEq t"
   5.523 +  | "not (NEq t) = Eq t"
   5.524 +  | "not p = NOT p"
   5.525  
   5.526  lemma not[simp]: "Ifm vs bs (not p) = Ifm vs bs (NOT p)"
   5.527    by (induct p rule: not.induct) auto
   5.528  
   5.529  definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   5.530 -where
   5.531 -  "conj p q \<equiv>
   5.532 +  where "conj p q \<equiv>
   5.533      (if p = F \<or> q = F then F
   5.534       else if p = T then q
   5.535       else if q = T then p
   5.536 @@ -576,8 +573,7 @@
   5.537    by (cases "p=F \<or> q=F", simp_all add: conj_def) (cases p, simp_all)
   5.538  
   5.539  definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   5.540 -where
   5.541 -  "disj p q \<equiv>
   5.542 +  where "disj p q \<equiv>
   5.543      (if (p = T \<or> q = T) then T
   5.544       else if p = F then q
   5.545       else if q = F then p
   5.546 @@ -588,8 +584,7 @@
   5.547    by (cases "p = T \<or> q = T", simp_all add: disj_def) (cases p, simp_all)
   5.548  
   5.549  definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   5.550 -where
   5.551 -  "imp p q \<equiv>
   5.552 +  where "imp p q \<equiv>
   5.553      (if p = F \<or> q = T \<or> p = q then T
   5.554       else if p = T then q
   5.555       else if q = F then not p
   5.556 @@ -599,8 +594,7 @@
   5.557    by (cases "p = F \<or> q = T") (simp_all add: imp_def)
   5.558  
   5.559  definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
   5.560 -where
   5.561 -  "iff p q \<equiv>
   5.562 +  where "iff p q \<equiv>
   5.563     (if p = q then T
   5.564      else if p = NOT q \<or> NOT p = q then F
   5.565      else if p = F then not q
   5.566 @@ -614,47 +608,47 @@
   5.567  
   5.568  text \<open>Quantifier freeness.\<close>
   5.569  fun qfree:: "fm \<Rightarrow> bool"
   5.570 -where
   5.571 -  "qfree (E p) = False"
   5.572 -| "qfree (A p) = False"
   5.573 -| "qfree (NOT p) = qfree p"
   5.574 -| "qfree (And p q) = (qfree p \<and> qfree q)"
   5.575 -| "qfree (Or  p q) = (qfree p \<and> qfree q)"
   5.576 -| "qfree (Imp p q) = (qfree p \<and> qfree q)"
   5.577 -| "qfree (Iff p q) = (qfree p \<and> qfree q)"
   5.578 -| "qfree p = True"
   5.579 +  where
   5.580 +    "qfree (E p) = False"
   5.581 +  | "qfree (A p) = False"
   5.582 +  | "qfree (NOT p) = qfree p"
   5.583 +  | "qfree (And p q) = (qfree p \<and> qfree q)"
   5.584 +  | "qfree (Or  p q) = (qfree p \<and> qfree q)"
   5.585 +  | "qfree (Imp p q) = (qfree p \<and> qfree q)"
   5.586 +  | "qfree (Iff p q) = (qfree p \<and> qfree q)"
   5.587 +  | "qfree p = True"
   5.588  
   5.589  text \<open>Boundedness and substitution.\<close>
   5.590  primrec boundslt :: "nat \<Rightarrow> fm \<Rightarrow> bool"
   5.591 -where
   5.592 -  "boundslt n T = True"
   5.593 -| "boundslt n F = True"
   5.594 -| "boundslt n (Lt t) = tmboundslt n t"
   5.595 -| "boundslt n (Le t) = tmboundslt n t"
   5.596 -| "boundslt n (Eq t) = tmboundslt n t"
   5.597 -| "boundslt n (NEq t) = tmboundslt n t"
   5.598 -| "boundslt n (NOT p) = boundslt n p"
   5.599 -| "boundslt n (And p q) = (boundslt n p \<and> boundslt n q)"
   5.600 -| "boundslt n (Or p q) = (boundslt n p \<and> boundslt n q)"
   5.601 -| "boundslt n (Imp p q) = ((boundslt n p) \<and> (boundslt n q))"
   5.602 -| "boundslt n (Iff p q) = (boundslt n p \<and> boundslt n q)"
   5.603 -| "boundslt n (E p) = boundslt (Suc n) p"
   5.604 -| "boundslt n (A p) = boundslt (Suc n) p"
   5.605 -
   5.606 -fun bound0:: "fm \<Rightarrow> bool"  \<comment> \<open>a Formula is independent of Bound 0\<close>
   5.607 -where
   5.608 -  "bound0 T = True"
   5.609 -| "bound0 F = True"
   5.610 -| "bound0 (Lt a) = tmbound0 a"
   5.611 -| "bound0 (Le a) = tmbound0 a"
   5.612 -| "bound0 (Eq a) = tmbound0 a"
   5.613 -| "bound0 (NEq a) = tmbound0 a"
   5.614 -| "bound0 (NOT p) = bound0 p"
   5.615 -| "bound0 (And p q) = (bound0 p \<and> bound0 q)"
   5.616 -| "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
   5.617 -| "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
   5.618 -| "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
   5.619 -| "bound0 p = False"
   5.620 +  where
   5.621 +    "boundslt n T = True"
   5.622 +  | "boundslt n F = True"
   5.623 +  | "boundslt n (Lt t) = tmboundslt n t"
   5.624 +  | "boundslt n (Le t) = tmboundslt n t"
   5.625 +  | "boundslt n (Eq t) = tmboundslt n t"
   5.626 +  | "boundslt n (NEq t) = tmboundslt n t"
   5.627 +  | "boundslt n (NOT p) = boundslt n p"
   5.628 +  | "boundslt n (And p q) = (boundslt n p \<and> boundslt n q)"
   5.629 +  | "boundslt n (Or p q) = (boundslt n p \<and> boundslt n q)"
   5.630 +  | "boundslt n (Imp p q) = ((boundslt n p) \<and> (boundslt n q))"
   5.631 +  | "boundslt n (Iff p q) = (boundslt n p \<and> boundslt n q)"
   5.632 +  | "boundslt n (E p) = boundslt (Suc n) p"
   5.633 +  | "boundslt n (A p) = boundslt (Suc n) p"
   5.634 +
   5.635 +fun bound0:: "fm \<Rightarrow> bool"  \<comment> \<open>a formula is independent of Bound 0\<close>
   5.636 +  where
   5.637 +    "bound0 T = True"
   5.638 +  | "bound0 F = True"
   5.639 +  | "bound0 (Lt a) = tmbound0 a"
   5.640 +  | "bound0 (Le a) = tmbound0 a"
   5.641 +  | "bound0 (Eq a) = tmbound0 a"
   5.642 +  | "bound0 (NEq a) = tmbound0 a"
   5.643 +  | "bound0 (NOT p) = bound0 p"
   5.644 +  | "bound0 (And p q) = (bound0 p \<and> bound0 q)"
   5.645 +  | "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
   5.646 +  | "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
   5.647 +  | "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
   5.648 +  | "bound0 p = False"
   5.649  
   5.650  lemma bound0_I:
   5.651    assumes bp: "bound0 p"
   5.652 @@ -662,21 +656,21 @@
   5.653    using bp tmbound0_I[where b="b" and bs="bs" and b'="b'"]
   5.654    by (induct p rule: bound0.induct) auto
   5.655  
   5.656 -primrec bound:: "nat \<Rightarrow> fm \<Rightarrow> bool"  \<comment> \<open>a Formula is independent of Bound n\<close>
   5.657 -where
   5.658 -  "bound m T = True"
   5.659 -| "bound m F = True"
   5.660 -| "bound m (Lt t) = tmbound m t"
   5.661 -| "bound m (Le t) = tmbound m t"
   5.662 -| "bound m (Eq t) = tmbound m t"
   5.663 -| "bound m (NEq t) = tmbound m t"
   5.664 -| "bound m (NOT p) = bound m p"
   5.665 -| "bound m (And p q) = (bound m p \<and> bound m q)"
   5.666 -| "bound m (Or p q) = (bound m p \<and> bound m q)"
   5.667 -| "bound m (Imp p q) = ((bound m p) \<and> (bound m q))"
   5.668 -| "bound m (Iff p q) = (bound m p \<and> bound m q)"
   5.669 -| "bound m (E p) = bound (Suc m) p"
   5.670 -| "bound m (A p) = bound (Suc m) p"
   5.671 +primrec bound:: "nat \<Rightarrow> fm \<Rightarrow> bool"  \<comment> \<open>a formula is independent of Bound n\<close>
   5.672 +  where
   5.673 +    "bound m T = True"
   5.674 +  | "bound m F = True"
   5.675 +  | "bound m (Lt t) = tmbound m t"
   5.676 +  | "bound m (Le t) = tmbound m t"
   5.677 +  | "bound m (Eq t) = tmbound m t"
   5.678 +  | "bound m (NEq t) = tmbound m t"
   5.679 +  | "bound m (NOT p) = bound m p"
   5.680 +  | "bound m (And p q) = (bound m p \<and> bound m q)"
   5.681 +  | "bound m (Or p q) = (bound m p \<and> bound m q)"
   5.682 +  | "bound m (Imp p q) = ((bound m p) \<and> (bound m q))"
   5.683 +  | "bound m (Iff p q) = (bound m p \<and> bound m q)"
   5.684 +  | "bound m (E p) = bound (Suc m) p"
   5.685 +  | "bound m (A p) = bound (Suc m) p"
   5.686  
   5.687  lemma bound_I:
   5.688    assumes bnd: "boundslt (length bs) p"
   5.689 @@ -707,39 +701,38 @@
   5.690  qed auto
   5.691  
   5.692  fun decr0 :: "fm \<Rightarrow> fm"
   5.693 -where
   5.694 -  "decr0 (Lt a) = Lt (decrtm0 a)"
   5.695 -| "decr0 (Le a) = Le (decrtm0 a)"
   5.696 -| "decr0 (Eq a) = Eq (decrtm0 a)"
   5.697 -| "decr0 (NEq a) = NEq (decrtm0 a)"
   5.698 -| "decr0 (NOT p) = NOT (decr0 p)"
   5.699 -| "decr0 (And p q) = conj (decr0 p) (decr0 q)"
   5.700 -| "decr0 (Or p q) = disj (decr0 p) (decr0 q)"
   5.701 -| "decr0 (Imp p q) = imp (decr0 p) (decr0 q)"
   5.702 -| "decr0 (Iff p q) = iff (decr0 p) (decr0 q)"
   5.703 -| "decr0 p = p"
   5.704 +  where
   5.705 +    "decr0 (Lt a) = Lt (decrtm0 a)"
   5.706 +  | "decr0 (Le a) = Le (decrtm0 a)"
   5.707 +  | "decr0 (Eq a) = Eq (decrtm0 a)"
   5.708 +  | "decr0 (NEq a) = NEq (decrtm0 a)"
   5.709 +  | "decr0 (NOT p) = NOT (decr0 p)"
   5.710 +  | "decr0 (And p q) = conj (decr0 p) (decr0 q)"
   5.711 +  | "decr0 (Or p q) = disj (decr0 p) (decr0 q)"
   5.712 +  | "decr0 (Imp p q) = imp (decr0 p) (decr0 q)"
   5.713 +  | "decr0 (Iff p q) = iff (decr0 p) (decr0 q)"
   5.714 +  | "decr0 p = p"
   5.715  
   5.716  lemma decr0:
   5.717 -  assumes nb: "bound0 p"
   5.718 +  assumes "bound0 p"
   5.719    shows "Ifm vs (x#bs) p = Ifm vs bs (decr0 p)"
   5.720 -  using nb
   5.721 -  by (induct p rule: decr0.induct) (simp_all add: decrtm0)
   5.722 +  using assms by (induct p rule: decr0.induct) (simp_all add: decrtm0)
   5.723  
   5.724  primrec decr :: "nat \<Rightarrow> fm \<Rightarrow> fm"
   5.725 -where
   5.726 -  "decr m T = T"
   5.727 -| "decr m F = F"
   5.728 -| "decr m (Lt t) = (Lt (decrtm m t))"
   5.729 -| "decr m (Le t) = (Le (decrtm m t))"
   5.730 -| "decr m (Eq t) = (Eq (decrtm m t))"
   5.731 -| "decr m (NEq t) = (NEq (decrtm m t))"
   5.732 -| "decr m (NOT p) = NOT (decr m p)"
   5.733 -| "decr m (And p q) = conj (decr m p) (decr m q)"
   5.734 -| "decr m (Or p q) = disj (decr m p) (decr m q)"
   5.735 -| "decr m (Imp p q) = imp (decr m p) (decr m q)"
   5.736 -| "decr m (Iff p q) = iff (decr m p) (decr m q)"
   5.737 -| "decr m (E p) = E (decr (Suc m) p)"
   5.738 -| "decr m (A p) = A (decr (Suc m) p)"
   5.739 +  where
   5.740 +    "decr m T = T"
   5.741 +  | "decr m F = F"
   5.742 +  | "decr m (Lt t) = (Lt (decrtm m t))"
   5.743 +  | "decr m (Le t) = (Le (decrtm m t))"
   5.744 +  | "decr m (Eq t) = (Eq (decrtm m t))"
   5.745 +  | "decr m (NEq t) = (NEq (decrtm m t))"
   5.746 +  | "decr m (NOT p) = NOT (decr m p)"
   5.747 +  | "decr m (And p q) = conj (decr m p) (decr m q)"
   5.748 +  | "decr m (Or p q) = disj (decr m p) (decr m q)"
   5.749 +  | "decr m (Imp p q) = imp (decr m p) (decr m q)"
   5.750 +  | "decr m (Iff p q) = iff (decr m p) (decr m q)"
   5.751 +  | "decr m (E p) = E (decr (Suc m) p)"
   5.752 +  | "decr m (A p) = A (decr (Suc m) p)"
   5.753  
   5.754  lemma decr:
   5.755    assumes bnd: "boundslt (length bs) p"
   5.756 @@ -774,20 +767,20 @@
   5.757  qed (auto simp add: decrtm removen_nth)
   5.758  
   5.759  primrec subst0 :: "tm \<Rightarrow> fm \<Rightarrow> fm"
   5.760 -where
   5.761 -  "subst0 t T = T"
   5.762 -| "subst0 t F = F"
   5.763 -| "subst0 t (Lt a) = Lt (tmsubst0 t a)"
   5.764 -| "subst0 t (Le a) = Le (tmsubst0 t a)"
   5.765 -| "subst0 t (Eq a) = Eq (tmsubst0 t a)"
   5.766 -| "subst0 t (NEq a) = NEq (tmsubst0 t a)"
   5.767 -| "subst0 t (NOT p) = NOT (subst0 t p)"
   5.768 -| "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
   5.769 -| "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
   5.770 -| "subst0 t (Imp p q) = Imp (subst0 t p)  (subst0 t q)"
   5.771 -| "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
   5.772 -| "subst0 t (E p) = E p"
   5.773 -| "subst0 t (A p) = A p"
   5.774 +  where
   5.775 +    "subst0 t T = T"
   5.776 +  | "subst0 t F = F"
   5.777 +  | "subst0 t (Lt a) = Lt (tmsubst0 t a)"
   5.778 +  | "subst0 t (Le a) = Le (tmsubst0 t a)"
   5.779 +  | "subst0 t (Eq a) = Eq (tmsubst0 t a)"
   5.780 +  | "subst0 t (NEq a) = NEq (tmsubst0 t a)"
   5.781 +  | "subst0 t (NOT p) = NOT (subst0 t p)"
   5.782 +  | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
   5.783 +  | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
   5.784 +  | "subst0 t (Imp p q) = Imp (subst0 t p)  (subst0 t q)"
   5.785 +  | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
   5.786 +  | "subst0 t (E p) = E p"
   5.787 +  | "subst0 t (A p) = A p"
   5.788  
   5.789  lemma subst0:
   5.790    assumes qf: "qfree p"
   5.791 @@ -799,24 +792,23 @@
   5.792    assumes bp: "tmbound0 t"
   5.793      and qf: "qfree p"
   5.794    shows "bound0 (subst0 t p)"
   5.795 -  using qf tmsubst0_nb[OF bp] bp
   5.796 -  by (induct p rule: fm.induct) auto
   5.797 +  using qf tmsubst0_nb[OF bp] bp by (induct p rule: fm.induct) auto
   5.798  
   5.799  primrec subst:: "nat \<Rightarrow> tm \<Rightarrow> fm \<Rightarrow> fm"
   5.800 -where
   5.801 -  "subst n t T = T"
   5.802 -| "subst n t F = F"
   5.803 -| "subst n t (Lt a) = Lt (tmsubst n t a)"
   5.804 -| "subst n t (Le a) = Le (tmsubst n t a)"
   5.805 -| "subst n t (Eq a) = Eq (tmsubst n t a)"
   5.806 -| "subst n t (NEq a) = NEq (tmsubst n t a)"
   5.807 -| "subst n t (NOT p) = NOT (subst n t p)"
   5.808 -| "subst n t (And p q) = And (subst n t p) (subst n t q)"
   5.809 -| "subst n t (Or p q) = Or (subst n t p) (subst n t q)"
   5.810 -| "subst n t (Imp p q) = Imp (subst n t p)  (subst n t q)"
   5.811 -| "subst n t (Iff p q) = Iff (subst n t p) (subst n t q)"
   5.812 -| "subst n t (E p) = E (subst (Suc n) (incrtm0 t) p)"
   5.813 -| "subst n t (A p) = A (subst (Suc n) (incrtm0 t) p)"
   5.814 +  where
   5.815 +    "subst n t T = T"
   5.816 +  | "subst n t F = F"
   5.817 +  | "subst n t (Lt a) = Lt (tmsubst n t a)"
   5.818 +  | "subst n t (Le a) = Le (tmsubst n t a)"
   5.819 +  | "subst n t (Eq a) = Eq (tmsubst n t a)"
   5.820 +  | "subst n t (NEq a) = NEq (tmsubst n t a)"
   5.821 +  | "subst n t (NOT p) = NOT (subst n t p)"
   5.822 +  | "subst n t (And p q) = And (subst n t p) (subst n t q)"
   5.823 +  | "subst n t (Or p q) = Or (subst n t p) (subst n t q)"
   5.824 +  | "subst n t (Imp p q) = Imp (subst n t p)  (subst n t q)"
   5.825 +  | "subst n t (Iff p q) = Iff (subst n t p) (subst n t q)"
   5.826 +  | "subst n t (E p) = E (subst (Suc n) (incrtm0 t) p)"
   5.827 +  | "subst n t (A p) = A (subst (Suc n) (incrtm0 t) p)"
   5.828  
   5.829  lemma subst:
   5.830    assumes nb: "boundslt (length bs) p"
   5.831 @@ -860,10 +852,9 @@
   5.832  qed (auto simp add: tmsubst)
   5.833  
   5.834  lemma subst_nb:
   5.835 -  assumes tnb: "tmbound m t"
   5.836 +  assumes "tmbound m t"
   5.837    shows "bound m (subst m t p)"
   5.838 -  using tnb tmsubst_nb incrtm0_tmbound
   5.839 -  by (induct p arbitrary: m t rule: fm.induct) auto
   5.840 +  using assms tmsubst_nb incrtm0_tmbound by (induct p arbitrary: m t rule: fm.induct) auto
   5.841  
   5.842  lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
   5.843    by (induct p rule: not.induct) auto
   5.844 @@ -913,21 +904,20 @@
   5.845    by (induct p) simp_all
   5.846  
   5.847  fun isatom :: "fm \<Rightarrow> bool"  \<comment> \<open>test for atomicity\<close>
   5.848 -where
   5.849 -  "isatom T = True"
   5.850 -| "isatom F = True"
   5.851 -| "isatom (Lt a) = True"
   5.852 -| "isatom (Le a) = True"
   5.853 -| "isatom (Eq a) = True"
   5.854 -| "isatom (NEq a) = True"
   5.855 -| "isatom p = False"
   5.856 +  where
   5.857 +    "isatom T = True"
   5.858 +  | "isatom F = True"
   5.859 +  | "isatom (Lt a) = True"
   5.860 +  | "isatom (Le a) = True"
   5.861 +  | "isatom (Eq a) = True"
   5.862 +  | "isatom (NEq a) = True"
   5.863 +  | "isatom p = False"
   5.864  
   5.865  lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
   5.866    by (induct p) simp_all
   5.867  
   5.868  definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm"
   5.869 -where
   5.870 -  "djf f p q \<equiv>
   5.871 +  where "djf f p q \<equiv>
   5.872      (if q = T then T
   5.873       else if q = F then f p
   5.874       else (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
   5.875 @@ -937,60 +927,63 @@
   5.876  
   5.877  lemma djf_Or: "Ifm vs bs (djf f p q) = Ifm vs bs (Or (f p) q)"
   5.878    apply (cases "q = T")
   5.879 -  apply (simp add: djf_def)
   5.880 +   apply (simp add: djf_def)
   5.881    apply (cases "q = F")
   5.882 -  apply (simp add: djf_def)
   5.883 +   apply (simp add: djf_def)
   5.884    apply (cases "f p")
   5.885 -  apply (simp_all add: Let_def djf_def)
   5.886 +              apply (simp_all add: Let_def djf_def)
   5.887    done
   5.888  
   5.889  lemma evaldjf_ex: "Ifm vs bs (evaldjf f ps) \<longleftrightarrow> (\<exists>p \<in> set ps. Ifm vs bs (f p))"
   5.890    by (induct ps) (simp_all add: evaldjf_def djf_Or)
   5.891  
   5.892  lemma evaldjf_bound0:
   5.893 -  assumes nb: "\<forall>x\<in> set xs. bound0 (f x)"
   5.894 +  assumes "\<forall>x\<in> set xs. bound0 (f x)"
   5.895    shows "bound0 (evaldjf f xs)"
   5.896 -  using nb
   5.897 +  using assms
   5.898    apply (induct xs)
   5.899 -  apply (auto simp add: evaldjf_def djf_def Let_def)
   5.900 +   apply (auto simp add: evaldjf_def djf_def Let_def)
   5.901    apply (case_tac "f a")
   5.902 -  apply auto
   5.903 +              apply auto
   5.904    done
   5.905  
   5.906  lemma evaldjf_qf:
   5.907 -  assumes nb: "\<forall>x\<in> set xs. qfree (f x)"
   5.908 +  assumes "\<forall>x\<in> set xs. qfree (f x)"
   5.909    shows "qfree (evaldjf f xs)"
   5.910 -  using nb
   5.911 +  using assms
   5.912    apply (induct xs)
   5.913 -  apply (auto simp add: evaldjf_def djf_def Let_def)
   5.914 +   apply (auto simp add: evaldjf_def djf_def Let_def)
   5.915    apply (case_tac "f a")
   5.916 -  apply auto
   5.917 +              apply auto
   5.918    done
   5.919  
   5.920  fun disjuncts :: "fm \<Rightarrow> fm list"
   5.921 -where
   5.922 -  "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   5.923 -| "disjuncts F = []"
   5.924 -| "disjuncts p = [p]"
   5.925 +  where
   5.926 +    "disjuncts (Or p q) = disjuncts p @ disjuncts q"
   5.927 +  | "disjuncts F = []"
   5.928 +  | "disjuncts p = [p]"
   5.929  
   5.930  lemma disjuncts: "(\<exists>q \<in> set (disjuncts p). Ifm vs bs q) = Ifm vs bs p"
   5.931    by (induct p rule: disjuncts.induct) auto
   5.932  
   5.933 -lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall>q \<in> set (disjuncts p). bound0 q"
   5.934 +lemma disjuncts_nb:
   5.935 +  assumes "bound0 p"
   5.936 +  shows "\<forall>q \<in> set (disjuncts p). bound0 q"
   5.937  proof -
   5.938 -  assume nb: "bound0 p"
   5.939 -  then have "list_all bound0 (disjuncts p)"
   5.940 -    by (induct p rule:disjuncts.induct) auto
   5.941 +  from assms have "list_all bound0 (disjuncts p)"
   5.942 +    by (induct p rule: disjuncts.induct) auto
   5.943    then show ?thesis
   5.944      by (simp only: list_all_iff)
   5.945  qed
   5.946  
   5.947 -lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall>q \<in> set (disjuncts p). qfree q"
   5.948 +lemma disjuncts_qf:
   5.949 +  assumes "qfree p"
   5.950 +  shows "\<forall>q \<in> set (disjuncts p). qfree q"
   5.951  proof -
   5.952 -  assume qf: "qfree p"
   5.953 -  then have "list_all qfree (disjuncts p)"
   5.954 +  from assms have "list_all qfree (disjuncts p)"
   5.955      by (induct p rule: disjuncts.induct) auto
   5.956 -  then show ?thesis by (simp only: list_all_iff)
   5.957 +  then show ?thesis
   5.958 +    by (simp only: list_all_iff)
   5.959  qed
   5.960  
   5.961  definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
   5.962 @@ -1044,17 +1037,16 @@
   5.963  qed
   5.964  
   5.965  fun conjuncts :: "fm \<Rightarrow> fm list"
   5.966 -where
   5.967 -  "conjuncts (And p q) = conjuncts p @ conjuncts q"
   5.968 -| "conjuncts T = []"
   5.969 -| "conjuncts p = [p]"
   5.970 +  where
   5.971 +    "conjuncts (And p q) = conjuncts p @ conjuncts q"
   5.972 +  | "conjuncts T = []"
   5.973 +  | "conjuncts p = [p]"
   5.974  
   5.975  definition list_conj :: "fm list \<Rightarrow> fm"
   5.976    where "list_conj ps \<equiv> foldr conj ps T"
   5.977  
   5.978  definition CJNB :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
   5.979 -where
   5.980 -  "CJNB f p \<equiv>
   5.981 +  where "CJNB f p \<equiv>
   5.982      (let cjs = conjuncts p;
   5.983        (yes, no) = partition bound0 cjs
   5.984       in conj (decr0 (list_conj yes)) (f (list_conj no)))"
   5.985 @@ -1071,27 +1063,28 @@
   5.986  lemma conjuncts: "(\<forall>q\<in> set (conjuncts p). Ifm vs bs q) = Ifm vs bs p"
   5.987    by (induct p rule: conjuncts.induct) auto
   5.988  
   5.989 -lemma conjuncts_nb: "bound0 p \<Longrightarrow> \<forall>q\<in> set (conjuncts p). bound0 q"
   5.990 +lemma conjuncts_nb:
   5.991 +  assumes "bound0 p"
   5.992 +  shows "\<forall>q \<in> set (conjuncts p). bound0 q"
   5.993  proof -
   5.994 -  assume nb: "bound0 p"
   5.995 -  then have "list_all bound0 (conjuncts p)"
   5.996 +  from assms have "list_all bound0 (conjuncts p)"
   5.997      by (induct p rule:conjuncts.induct) auto
   5.998    then show ?thesis
   5.999      by (simp only: list_all_iff)
  5.1000  qed
  5.1001  
  5.1002  fun islin :: "fm \<Rightarrow> bool"
  5.1003 -where
  5.1004 -  "islin (And p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
  5.1005 -| "islin (Or p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
  5.1006 -| "islin (Eq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1007 -| "islin (NEq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1008 -| "islin (Lt (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1009 -| "islin (Le (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1010 -| "islin (NOT p) = False"
  5.1011 -| "islin (Imp p q) = False"
  5.1012 -| "islin (Iff p q) = False"
  5.1013 -| "islin p = bound0 p"
  5.1014 +  where
  5.1015 +    "islin (And p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
  5.1016 +  | "islin (Or p q) = (islin p \<and> islin q \<and> p \<noteq> T \<and> p \<noteq> F \<and> q \<noteq> T \<and> q \<noteq> F)"
  5.1017 +  | "islin (Eq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1018 +  | "islin (NEq (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1019 +  | "islin (Lt (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1020 +  | "islin (Le (CNP 0 c s)) = (isnpoly c \<and> c \<noteq> 0\<^sub>p \<and> tmbound0 s \<and> allpolys isnpoly s)"
  5.1021 +  | "islin (NOT p) = False"
  5.1022 +  | "islin (Imp p q) = False"
  5.1023 +  | "islin (Iff p q) = False"
  5.1024 +  | "islin p = bound0 p"
  5.1025  
  5.1026  lemma islin_stupid:
  5.1027    assumes nb: "tmbound0 p"
  5.1028 @@ -1109,25 +1102,25 @@
  5.1029  lemma lt: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (lt p) = Ifm vs bs (Lt p)"
  5.1030    apply (simp add: lt_def)
  5.1031    apply (cases p)
  5.1032 -  apply simp_all
  5.1033 +        apply simp_all
  5.1034    apply (rename_tac poly, case_tac poly)
  5.1035 -  apply (simp_all add: isnpoly_def)
  5.1036 +         apply (simp_all add: isnpoly_def)
  5.1037    done
  5.1038  
  5.1039  lemma le: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (le p) = Ifm vs bs (Le p)"
  5.1040    apply (simp add: le_def)
  5.1041    apply (cases p)
  5.1042 -  apply simp_all
  5.1043 +        apply simp_all
  5.1044    apply (rename_tac poly, case_tac poly)
  5.1045 -  apply (simp_all add: isnpoly_def)
  5.1046 +         apply (simp_all add: isnpoly_def)
  5.1047    done
  5.1048  
  5.1049  lemma eq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (eq p) = Ifm vs bs (Eq p)"
  5.1050    apply (simp add: eq_def)
  5.1051    apply (cases p)
  5.1052 -  apply simp_all
  5.1053 +        apply simp_all
  5.1054    apply (rename_tac poly, case_tac poly)
  5.1055 -  apply (simp_all add: isnpoly_def)
  5.1056 +         apply (simp_all add: isnpoly_def)
  5.1057    done
  5.1058  
  5.1059  lemma neq: "allpolys isnpoly p \<Longrightarrow> Ifm vs bs (neq p) = Ifm vs bs (NEq p)"
  5.1060 @@ -1136,41 +1129,41 @@
  5.1061  lemma lt_lin: "tmbound0 p \<Longrightarrow> islin (lt p)"
  5.1062    apply (simp add: lt_def)
  5.1063    apply (cases p)
  5.1064 -  apply simp_all
  5.1065 -  apply (rename_tac poly, case_tac poly)
  5.1066 -  apply simp_all
  5.1067 +        apply simp_all
  5.1068 +   apply (rename_tac poly, case_tac poly)
  5.1069 +          apply simp_all
  5.1070    apply (rename_tac nat a b, case_tac nat)
  5.1071 -  apply simp_all
  5.1072 +   apply simp_all
  5.1073    done
  5.1074  
  5.1075  lemma le_lin: "tmbound0 p \<Longrightarrow> islin (le p)"
  5.1076    apply (simp add: le_def)
  5.1077    apply (cases p)
  5.1078 -  apply simp_all
  5.1079 -  apply (rename_tac poly, case_tac poly)
  5.1080 -  apply simp_all
  5.1081 +        apply simp_all
  5.1082 +   apply (rename_tac poly, case_tac poly)
  5.1083 +          apply simp_all
  5.1084    apply (rename_tac nat a b, case_tac nat)
  5.1085 -  apply simp_all
  5.1086 +   apply simp_all
  5.1087    done
  5.1088  
  5.1089  lemma eq_lin: "tmbound0 p \<Longrightarrow> islin (eq p)"
  5.1090    apply (simp add: eq_def)
  5.1091    apply (cases p)
  5.1092 -  apply simp_all
  5.1093 -  apply (rename_tac poly, case_tac poly)
  5.1094 -  apply simp_all
  5.1095 +        apply simp_all
  5.1096 +   apply (rename_tac poly, case_tac poly)
  5.1097 +          apply simp_all
  5.1098    apply (rename_tac nat a b, case_tac nat)
  5.1099 -  apply simp_all
  5.1100 +   apply simp_all
  5.1101    done
  5.1102  
  5.1103  lemma neq_lin: "tmbound0 p \<Longrightarrow> islin (neq p)"
  5.1104    apply (simp add: neq_def eq_def)
  5.1105    apply (cases p)
  5.1106 -  apply simp_all
  5.1107 -  apply (rename_tac poly, case_tac poly)
  5.1108 -  apply simp_all
  5.1109 +        apply simp_all
  5.1110 +   apply (rename_tac poly, case_tac poly)
  5.1111 +          apply simp_all
  5.1112    apply (rename_tac nat a b, case_tac nat)
  5.1113 -  apply simp_all
  5.1114 +   apply simp_all
  5.1115    done
  5.1116  
  5.1117  definition "simplt t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then lt s else Lt (CNP 0 c s))"
  5.1118 @@ -1178,7 +1171,7 @@
  5.1119  definition "simpeq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then eq s else Eq (CNP 0 c s))"
  5.1120  definition "simpneq t = (let (c,s) = split0 (simptm t) in if c= 0\<^sub>p then neq s else NEq (CNP 0 c s))"
  5.1121  
  5.1122 -lemma simplt_islin[simp]:
  5.1123 +lemma simplt_islin [simp]:
  5.1124    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1125    shows "islin (simplt t)"
  5.1126    unfolding simplt_def
  5.1127 @@ -1186,7 +1179,7 @@
  5.1128    by (auto simp add: lt_lin Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  5.1129        islin_stupid allpolys_split0[OF simptm_allpolys_npoly])
  5.1130  
  5.1131 -lemma simple_islin[simp]:
  5.1132 +lemma simple_islin [simp]:
  5.1133    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1134    shows "islin (simple t)"
  5.1135    unfolding simple_def
  5.1136 @@ -1194,7 +1187,7 @@
  5.1137    by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  5.1138        islin_stupid allpolys_split0[OF simptm_allpolys_npoly] le_lin)
  5.1139  
  5.1140 -lemma simpeq_islin[simp]:
  5.1141 +lemma simpeq_islin [simp]:
  5.1142    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1143    shows "islin (simpeq t)"
  5.1144    unfolding simpeq_def
  5.1145 @@ -1202,7 +1195,7 @@
  5.1146    by (auto simp add: Let_def split_def isnpoly_fst_split0[OF simptm_allpolys_npoly]
  5.1147        islin_stupid allpolys_split0[OF simptm_allpolys_npoly] eq_lin)
  5.1148  
  5.1149 -lemma simpneq_islin[simp]:
  5.1150 +lemma simpneq_islin [simp]:
  5.1151    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1152    shows "islin (simpneq t)"
  5.1153    unfolding simpneq_def
  5.1154 @@ -1215,24 +1208,24 @@
  5.1155  
  5.1156  lemma split0_npoly:
  5.1157    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1158 -    and n: "allpolys isnpoly t"
  5.1159 +    and *: "allpolys isnpoly t"
  5.1160    shows "isnpoly (fst (split0 t))"
  5.1161      and "allpolys isnpoly (snd (split0 t))"
  5.1162 -  using n
  5.1163 +  using *
  5.1164    by (induct t rule: split0.induct)
  5.1165      (auto simp add: Let_def split_def polyadd_norm polymul_norm polyneg_norm
  5.1166        polysub_norm really_stupid)
  5.1167  
  5.1168  lemma simplt[simp]: "Ifm vs bs (simplt t) = Ifm vs bs (Lt t)"
  5.1169  proof -
  5.1170 -  have n: "allpolys isnpoly (simptm t)"
  5.1171 +  have *: "allpolys isnpoly (simptm t)"
  5.1172      by simp
  5.1173    let ?t = "simptm t"
  5.1174    show ?thesis
  5.1175    proof (cases "fst (split0 ?t) = 0\<^sub>p")
  5.1176      case True
  5.1177      then show ?thesis
  5.1178 -      using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF n], of vs bs]
  5.1179 +      using split0[of "simptm t" vs bs] lt[OF split0_npoly(2)[OF *], of vs bs]
  5.1180        by (simp add: simplt_def Let_def split_def lt)
  5.1181    next
  5.1182      case False
  5.1183 @@ -1244,14 +1237,14 @@
  5.1184  
  5.1185  lemma simple[simp]: "Ifm vs bs (simple t) = Ifm vs bs (Le t)"
  5.1186  proof -
  5.1187 -  have n: "allpolys isnpoly (simptm t)"
  5.1188 +  have *: "allpolys isnpoly (simptm t)"
  5.1189      by simp
  5.1190    let ?t = "simptm t"
  5.1191    show ?thesis
  5.1192    proof (cases "fst (split0 ?t) = 0\<^sub>p")
  5.1193      case True
  5.1194      then show ?thesis
  5.1195 -      using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF n], of vs bs]
  5.1196 +      using split0[of "simptm t" vs bs] le[OF split0_npoly(2)[OF *], of vs bs]
  5.1197        by (simp add: simple_def Let_def split_def le)
  5.1198    next
  5.1199      case False
  5.1200 @@ -1300,44 +1293,44 @@
  5.1201  lemma lt_nb: "tmbound0 t \<Longrightarrow> bound0 (lt t)"
  5.1202    apply (simp add: lt_def)
  5.1203    apply (cases t)
  5.1204 -  apply auto
  5.1205 +        apply auto
  5.1206    apply (rename_tac poly, case_tac poly)
  5.1207 -  apply auto
  5.1208 +         apply auto
  5.1209    done
  5.1210  
  5.1211  lemma le_nb: "tmbound0 t \<Longrightarrow> bound0 (le t)"
  5.1212    apply (simp add: le_def)
  5.1213    apply (cases t)
  5.1214 -  apply auto
  5.1215 +        apply auto
  5.1216    apply (rename_tac poly, case_tac poly)
  5.1217 -  apply auto
  5.1218 +         apply auto
  5.1219    done
  5.1220  
  5.1221  lemma eq_nb: "tmbound0 t \<Longrightarrow> bound0 (eq t)"
  5.1222    apply (simp add: eq_def)
  5.1223    apply (cases t)
  5.1224 -  apply auto
  5.1225 +        apply auto
  5.1226    apply (rename_tac poly, case_tac poly)
  5.1227 -  apply auto
  5.1228 +         apply auto
  5.1229    done
  5.1230  
  5.1231  lemma neq_nb: "tmbound0 t \<Longrightarrow> bound0 (neq t)"
  5.1232    apply (simp add: neq_def eq_def)
  5.1233    apply (cases t)
  5.1234 -  apply auto
  5.1235 +        apply auto
  5.1236    apply (rename_tac poly, case_tac poly)
  5.1237 -  apply auto
  5.1238 +         apply auto
  5.1239    done
  5.1240  
  5.1241  lemma simplt_nb[simp]:
  5.1242    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1243    shows "tmbound0 t \<Longrightarrow> bound0 (simplt t)"
  5.1244  proof (simp add: simplt_def Let_def split_def)
  5.1245 -  assume nb: "tmbound0 t"
  5.1246 -  then have nb': "tmbound0 (simptm t)"
  5.1247 +  assume "tmbound0 t"
  5.1248 +  then have *: "tmbound0 (simptm t)"
  5.1249      by simp
  5.1250    let ?c = "fst (split0 (simptm t))"
  5.1251 -  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1252 +  from tmbound_split0[OF *[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1253    have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p"
  5.1254      by auto
  5.1255    from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
  5.1256 @@ -1354,11 +1347,11 @@
  5.1257    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1258    shows "tmbound0 t \<Longrightarrow> bound0 (simple t)"
  5.1259  proof(simp add: simple_def Let_def split_def)
  5.1260 -  assume nb: "tmbound0 t"
  5.1261 -  then have nb': "tmbound0 (simptm t)"
  5.1262 +  assume "tmbound0 t"
  5.1263 +  then have *: "tmbound0 (simptm t)"
  5.1264      by simp
  5.1265    let ?c = "fst (split0 (simptm t))"
  5.1266 -  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1267 +  from tmbound_split0[OF *[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1268    have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p"
  5.1269      by auto
  5.1270    from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
  5.1271 @@ -1375,11 +1368,11 @@
  5.1272    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1273    shows "tmbound0 t \<Longrightarrow> bound0 (simpeq t)"
  5.1274  proof (simp add: simpeq_def Let_def split_def)
  5.1275 -  assume nb: "tmbound0 t"
  5.1276 -  then have nb': "tmbound0 (simptm t)"
  5.1277 +  assume "tmbound0 t"
  5.1278 +  then have *: "tmbound0 (simptm t)"
  5.1279      by simp
  5.1280    let ?c = "fst (split0 (simptm t))"
  5.1281 -  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1282 +  from tmbound_split0[OF *[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1283    have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p"
  5.1284      by auto
  5.1285    from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
  5.1286 @@ -1396,11 +1389,11 @@
  5.1287    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
  5.1288    shows "tmbound0 t \<Longrightarrow> bound0 (simpneq t)"
  5.1289  proof (simp add: simpneq_def Let_def split_def)
  5.1290 -  assume nb: "tmbound0 t"
  5.1291 -  then have nb': "tmbound0 (simptm t)"
  5.1292 +  assume "tmbound0 t"
  5.1293 +  then have *: "tmbound0 (simptm t)"
  5.1294      by simp
  5.1295    let ?c = "fst (split0 (simptm t))"
  5.1296 -  from tmbound_split0[OF nb'[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1297 +  from tmbound_split0[OF *[unfolded tmbound0_tmbound_iff[symmetric]]]
  5.1298    have th: "\<forall>bs. Ipoly bs ?c = Ipoly bs 0\<^sub>p"
  5.1299      by auto
  5.1300    from isnpoly_fst_split0[OF simptm_allpolys_npoly[of t]]
  5.1301 @@ -1414,10 +1407,10 @@
  5.1302  qed
  5.1303  
  5.1304  fun conjs :: "fm \<Rightarrow> fm list"
  5.1305 -where
  5.1306 -  "conjs (And p q) = conjs p @ conjs q"
  5.1307 -| "conjs T = []"
  5.1308 -| "conjs p = [p]"
  5.1309 +  where
  5.1310 +    "conjs (And p q) = conjs p @ conjs q"
  5.1311 +  | "conjs T = []"
  5.1312 +  | "conjs p = [p]"
  5.1313  
  5.1314  lemma conjs_ci: "(\<forall>q \<in> set (conjs p). Ifm vs bs q) = Ifm vs bs p"
  5.1315    by (induct p rule: conjs.induct) auto
  5.1316 @@ -1439,36 +1432,33 @@
  5.1317  
  5.1318  lemma conjs_nb: "bound n p \<Longrightarrow> \<forall>q\<in> set (conjs p). bound n q"
  5.1319    apply (induct p rule: conjs.induct)
  5.1320 -  apply (unfold conjs.simps)
  5.1321 -  apply (unfold set_append)
  5.1322 -  apply (unfold ball_Un)
  5.1323 -  apply (unfold bound.simps)
  5.1324 -  apply auto
  5.1325 +              apply (unfold conjs.simps)
  5.1326 +              apply (unfold set_append)
  5.1327 +              apply (unfold ball_Un)
  5.1328 +              apply (unfold bound.simps)
  5.1329 +              apply auto
  5.1330    done
  5.1331  
  5.1332  lemma conjs_boundslt: "boundslt n p \<Longrightarrow> \<forall>q\<in> set (conjs p). boundslt n q"
  5.1333    apply (induct p rule: conjs.induct)
  5.1334 -  apply (unfold conjs.simps)
  5.1335 -  apply (unfold set_append)
  5.1336 -  apply (unfold ball_Un)
  5.1337 -  apply (unfold boundslt.simps)
  5.1338 -  apply blast
  5.1339 -  apply simp_all
  5.1340 +              apply (unfold conjs.simps)
  5.1341 +              apply (unfold set_append)
  5.1342 +              apply (unfold ball_Un)
  5.1343 +              apply (unfold boundslt.simps)
  5.1344 +              apply blast
  5.1345 +             apply simp_all
  5.1346    done
  5.1347  
  5.1348  lemma list_conj_boundslt: " \<forall>p\<in> set ps. boundslt n p \<Longrightarrow> boundslt n (list_conj ps)"
  5.1349 -  unfolding list_conj_def
  5.1350 -  by (induct ps) auto
  5.1351 +  by (induct ps) (auto simp: list_conj_def)
  5.1352  
  5.1353  lemma list_conj_nb:
  5.1354 -  assumes bnd: "\<forall>p\<in> set ps. bound n p"
  5.1355 +  assumes "\<forall>p\<in> set ps. bound n p"
  5.1356    shows "bound n (list_conj ps)"
  5.1357 -  using bnd
  5.1358 -  unfolding list_conj_def
  5.1359 -  by (induct ps) auto
  5.1360 +  using assms by (induct ps) (auto simp: list_conj_def)
  5.1361  
  5.1362  lemma list_conj_nb': "\<forall>p\<in>set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
  5.1363 -  unfolding list_conj_def by (induct ps) auto
  5.1364 +  by (induct ps) (auto simp: list_conj_def)
  5.1365  
  5.1366  lemma CJNB_qe:
  5.1367    assumes qe: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
  5.1368 @@ -1523,29 +1513,29 @@
  5.1369  qed
  5.1370  
  5.1371  fun simpfm :: "fm \<Rightarrow> fm"
  5.1372 -where
  5.1373 -  "simpfm (Lt t) = simplt (simptm t)"
  5.1374 -| "simpfm (Le t) = simple (simptm t)"
  5.1375 -| "simpfm (Eq t) = simpeq(simptm t)"
  5.1376 -| "simpfm (NEq t) = simpneq(simptm t)"
  5.1377 -| "simpfm (And p q) = conj (simpfm p) (simpfm q)"
  5.1378 -| "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
  5.1379 -| "simpfm (Imp p q) = disj (simpfm (NOT p)) (simpfm q)"
  5.1380 -| "simpfm (Iff p q) =
  5.1381 -    disj (conj (simpfm p) (simpfm q)) (conj (simpfm (NOT p)) (simpfm (NOT q)))"
  5.1382 -| "simpfm (NOT (And p q)) = disj (simpfm (NOT p)) (simpfm (NOT q))"
  5.1383 -| "simpfm (NOT (Or p q)) = conj (simpfm (NOT p)) (simpfm (NOT q))"
  5.1384 -| "simpfm (NOT (Imp p q)) = conj (simpfm p) (simpfm (NOT q))"
  5.1385 -| "simpfm (NOT (Iff p q)) =
  5.1386 -    disj (conj (simpfm p) (simpfm (NOT q))) (conj (simpfm (NOT p)) (simpfm q))"
  5.1387 -| "simpfm (NOT (Eq t)) = simpneq t"
  5.1388 -| "simpfm (NOT (NEq t)) = simpeq t"
  5.1389 -| "simpfm (NOT (Le t)) = simplt (Neg t)"
  5.1390 -| "simpfm (NOT (Lt t)) = simple (Neg t)"
  5.1391 -| "simpfm (NOT (NOT p)) = simpfm p"
  5.1392 -| "simpfm (NOT T) = F"
  5.1393 -| "simpfm (NOT F) = T"
  5.1394 -| "simpfm p = p"
  5.1395 +  where
  5.1396 +    "simpfm (Lt t) = simplt (simptm t)"
  5.1397 +  | "simpfm (Le t) = simple (simptm t)"
  5.1398 +  | "simpfm (Eq t) = simpeq(simptm t)"
  5.1399 +  | "simpfm (NEq t) = simpneq(simptm t)"
  5.1400 +  | "simpfm (And p q) = conj (simpfm p) (simpfm q)"
  5.1401 +  | "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
  5.1402 +  | "simpfm (Imp p q) = disj (simpfm (NOT p)) (simpfm q)"
  5.1403 +  | "simpfm (Iff p q) =
  5.1404 +      disj (conj (simpfm p) (simpfm q)) (conj (simpfm (NOT p)) (simpfm (NOT q)))"
  5.1405 +  | "simpfm (NOT (And p q)) = disj (simpfm (NOT p)) (simpfm (NOT q))"
  5.1406 +  | "simpfm (NOT (Or p q)) = conj (simpfm (NOT p)) (simpfm (NOT q))"
  5.1407 +  | "simpfm (NOT (Imp p q)) = conj (simpfm p) (simpfm (NOT q))"
  5.1408 +  | "simpfm (NOT (Iff p q)) =
  5.1409 +      disj (conj (simpfm p) (simpfm (NOT q))) (conj (simpfm (NOT p)) (simpfm q))"
  5.1410 +  | "simpfm (NOT (Eq t)) = simpneq t"
  5.1411 +  | "simpfm (NOT (NEq t)) = simpeq t"
  5.1412 +  | "simpfm (NOT (Le t)) = simplt (Neg t)"
  5.1413 +  | "simpfm (NOT (Lt t)) = simple (Neg t)"
  5.1414 +  | "simpfm (NOT (NOT p)) = simpfm p"
  5.1415 +  | "simpfm (NOT T) = F"
  5.1416 +  | "simpfm (NOT F) = T"
  5.1417 +  | "simpfm p = p"
  5.1418  
  5.1419  lemma simpfm[simp]: "Ifm vs bs (simpfm p) = Ifm vs bs p"
  5.1420    by (induct p arbitrary: bs rule: simpfm.induct) auto
  5.1421 @@ -1557,23 +1547,23 @@
  5.1422  
  5.1423  lemma lt_qf[simp]: "qfree (lt t)"
  5.1424    apply (cases t)
  5.1425 -  apply (auto simp add: lt_def)
  5.1426 +        apply (auto simp add: lt_def)
  5.1427    apply (rename_tac poly, case_tac poly)
  5.1428 -  apply auto
  5.1429 +         apply auto
  5.1430    done
  5.1431  
  5.1432  lemma le_qf[simp]: "qfree (le t)"
  5.1433    apply (cases t)
  5.1434 -  apply (auto simp add: le_def)
  5.1435 +        apply (auto simp add: le_def)
  5.1436    apply (rename_tac poly, case_tac poly)
  5.1437 -  apply auto
  5.1438 +         apply auto
  5.1439    done
  5.1440  
  5.1441  lemma eq_qf[simp]: "qfree (eq t)"
  5.1442    apply (cases t)
  5.1443 -  apply (auto simp add: eq_def)
  5.1444 +        apply (auto simp add: eq_def)
  5.1445    apply (rename_tac poly, case_tac poly)
  5.1446 -  apply auto
  5.1447 +         apply auto
  5.1448    done
  5.1449  
  5.1450  lemma neq_qf[simp]: "qfree (neq t)"
  5.1451 @@ -1596,6 +1586,7 @@
  5.1452  
  5.1453  lemma disj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (disj p q)"
  5.1454    by (simp add: disj_def)
  5.1455 +
  5.1456  lemma conj_lin: "islin p \<Longrightarrow> islin q \<Longrightarrow> islin (conj p q)"
  5.1457    by (simp add: conj_def)
  5.1458  
  5.1459 @@ -1605,30 +1596,30 @@
  5.1460    by (induct p rule: simpfm.induct) (simp_all add: conj_lin disj_lin)
  5.1461  
  5.1462  fun prep :: "fm \<Rightarrow> fm"
  5.1463 -where
  5.1464 -  "prep (E T) = T"
  5.1465 -| "prep (E F) = F"
  5.1466 -| "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
  5.1467 -| "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
  5.1468 -| "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
  5.1469 -| "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
  5.1470 -| "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
  5.1471 -| "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
  5.1472 -| "prep (E p) = E (prep p)"
  5.1473 -| "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
  5.1474 -| "prep (A p) = prep (NOT (E (NOT p)))"
  5.1475 -| "prep (NOT (NOT p)) = prep p"
  5.1476 -| "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
  5.1477 -| "prep (NOT (A p)) = prep (E (NOT p))"
  5.1478 -| "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
  5.1479 -| "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
  5.1480 -| "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
  5.1481 -| "prep (NOT p) = not (prep p)"
  5.1482 -| "prep (Or p q) = disj (prep p) (prep q)"
  5.1483 -| "prep (And p q) = conj (prep p) (prep q)"
  5.1484 -| "prep (Imp p q) = prep (Or (NOT p) q)"
  5.1485 -| "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  5.1486 -| "prep p = p"
  5.1487 +  where
  5.1488 +    "prep (E T) = T"
  5.1489 +  | "prep (E F) = F"
  5.1490 +  | "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
  5.1491 +  | "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
  5.1492 +  | "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))"
  5.1493 +  | "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
  5.1494 +  | "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
  5.1495 +  | "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
  5.1496 +  | "prep (E p) = E (prep p)"
  5.1497 +  | "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
  5.1498 +  | "prep (A p) = prep (NOT (E (NOT p)))"
  5.1499 +  | "prep (NOT (NOT p)) = prep p"
  5.1500 +  | "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
  5.1501 +  | "prep (NOT (A p)) = prep (E (NOT p))"
  5.1502 +  | "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
  5.1503 +  | "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
  5.1504 +  | "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
  5.1505 +  | "prep (NOT p) = not (prep p)"
  5.1506 +  | "prep (Or p q) = disj (prep p) (prep q)"
  5.1507 +  | "prep (And p q) = conj (prep p) (prep q)"
  5.1508 +  | "prep (Imp p q) = prep (Or (NOT p) q)"
  5.1509 +  | "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  5.1510 +  | "prep p = p"
  5.1511  
  5.1512  lemma prep: "Ifm vs bs (prep p) = Ifm vs bs p"
  5.1513    by (induct p arbitrary: bs rule: prep.induct) auto
  5.1514 @@ -1636,15 +1627,15 @@
  5.1515  
  5.1516  text \<open>Generic quantifier elimination.\<close>
  5.1517  fun qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
  5.1518 -where
  5.1519 -  "qelim (E p) = (\<lambda>qe. DJ (CJNB qe) (qelim p qe))"
  5.1520 -| "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
  5.1521 -| "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
  5.1522 -| "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
  5.1523 -| "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
  5.1524 -| "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
  5.1525 -| "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
  5.1526 -| "qelim p = (\<lambda>y. simpfm p)"
  5.1527 +  where
  5.1528 +    "qelim (E p) = (\<lambda>qe. DJ (CJNB qe) (qelim p qe))"
  5.1529 +  | "qelim (A p) = (\<lambda>qe. not (qe ((qelim (NOT p) qe))))"
  5.1530 +  | "qelim (NOT p) = (\<lambda>qe. not (qelim p qe))"
  5.1531 +  | "qelim (And p q) = (\<lambda>qe. conj (qelim p qe) (qelim q qe))"
  5.1532 +  | "qelim (Or  p q) = (\<lambda>qe. disj (qelim p qe) (qelim q qe))"
  5.1533 +  | "qelim (Imp p q) = (\<lambda>qe. imp (qelim p qe) (qelim q qe))"
  5.1534 +  | "qelim (Iff p q) = (\<lambda>qe. iff (qelim p qe) (qelim q qe))"
  5.1535 +  | "qelim p = (\<lambda>y. simpfm p)"
  5.1536  
  5.1537  lemma qelim:
  5.1538    assumes qe_inv: "\<forall>bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm vs bs (qe p) = Ifm vs bs (E p))"
  5.1539 @@ -1655,30 +1646,30 @@
  5.1540  
  5.1541  subsection \<open>Core Procedure\<close>
  5.1542  
  5.1543 -fun minusinf:: "fm \<Rightarrow> fm"  \<comment> \<open>Virtual substitution of -\<infinity>\<close>
  5.1544 -where
  5.1545 -  "minusinf (And p q) = conj (minusinf p) (minusinf q)"
  5.1546 -| "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
  5.1547 -| "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  5.1548 -| "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  5.1549 -| "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
  5.1550 -| "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
  5.1551 -| "minusinf p = p"
  5.1552 -
  5.1553 -fun plusinf:: "fm \<Rightarrow> fm"  \<comment> \<open>Virtual substitution of +\<infinity>\<close>
  5.1554 -where
  5.1555 -  "plusinf (And p q) = conj (plusinf p) (plusinf q)"
  5.1556 -| "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
  5.1557 -| "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  5.1558 -| "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  5.1559 -| "plusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP c))"
  5.1560 -| "plusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP c))"
  5.1561 -| "plusinf p = p"
  5.1562 +fun minusinf:: "fm \<Rightarrow> fm"  \<comment> \<open>virtual substitution of \<open>-\<infinity>\<close>\<close>
  5.1563 +  where
  5.1564 +    "minusinf (And p q) = conj (minusinf p) (minusinf q)"
  5.1565 +  | "minusinf (Or p q) = disj (minusinf p) (minusinf q)"
  5.1566 +  | "minusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  5.1567 +  | "minusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  5.1568 +  | "minusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP (~\<^sub>p c)))"
  5.1569 +  | "minusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP (~\<^sub>p c)))"
  5.1570 +  | "minusinf p = p"
  5.1571 +
  5.1572 +fun plusinf:: "fm \<Rightarrow> fm"  \<comment> \<open>virtual substitution of \<open>+\<infinity>\<close>\<close>
  5.1573 +  where
  5.1574 +    "plusinf (And p q) = conj (plusinf p) (plusinf q)"
  5.1575 +  | "plusinf (Or p q) = disj (plusinf p) (plusinf q)"
  5.1576 +  | "plusinf (Eq  (CNP 0 c e)) = conj (eq (CP c)) (eq e)"
  5.1577 +  | "plusinf (NEq (CNP 0 c e)) = disj (not (eq e)) (not (eq (CP c)))"
  5.1578 +  | "plusinf (Lt  (CNP 0 c e)) = disj (conj (eq (CP c)) (lt e)) (lt (CP c))"
  5.1579 +  | "plusinf (Le  (CNP 0 c e)) = disj (conj (eq (CP c)) (le e)) (lt (CP c))"
  5.1580 +  | "plusinf p = p"
  5.1581  
  5.1582  lemma minusinf_inf:
  5.1583 -  assumes lp: "islin p"
  5.1584 +  assumes "islin p"
  5.1585    shows "\<exists>z. \<forall>x < z. Ifm vs (x#bs) (minusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
  5.1586 -  using lp
  5.1587 +  using assms
  5.1588  proof (induct p rule: minusinf.induct)
  5.1589    case 1
  5.1590    then show ?case
  5.1591 @@ -1881,9 +1872,9 @@
  5.1592  qed auto
  5.1593  
  5.1594  lemma plusinf_inf:
  5.1595 -  assumes lp: "islin p"
  5.1596 +  assumes "islin p"
  5.1597    shows "\<exists>z. \<forall>x > z. Ifm vs (x#bs) (plusinf p) \<longleftrightarrow> Ifm vs (x#bs) p"
  5.1598 -  using lp
  5.1599 +  using assms
  5.1600  proof (induct p rule: plusinf.induct)
  5.1601    case 1
  5.1602    then show ?case
  5.1603 @@ -2125,14 +2116,14 @@
  5.1604  qed
  5.1605  
  5.1606  fun uset :: "fm \<Rightarrow> (poly \<times> tm) list"
  5.1607 -where
  5.1608 -  "uset (And p q) = uset p @ uset q"
  5.1609 -| "uset (Or p q) = uset p @ uset q"
  5.1610 -| "uset (Eq (CNP 0 a e)) = [(a, e)]"
  5.1611 -| "uset (Le (CNP 0 a e)) = [(a, e)]"
  5.1612 -| "uset (Lt (CNP 0 a e)) = [(a, e)]"
  5.1613 -| "uset (NEq (CNP 0 a e)) = [(a, e)]"
  5.1614 -| "uset p = []"
  5.1615 +  where
  5.1616 +    "uset (And p q) = uset p @ uset q"
  5.1617 +  | "uset (Or p q) = uset p @ uset q"
  5.1618 +  | "uset (Eq (CNP 0 a e)) = [(a, e)]"
  5.1619 +  | "uset (Le (CNP 0 a e)) = [(a, e)]"
  5.1620 +  | "uset (Lt (CNP 0 a e)) = [(a, e)]"
  5.1621 +  | "uset (NEq (CNP 0 a e)) = [(a, e)]"
  5.1622 +  | "uset p = []"
  5.1623  
  5.1624  lemma uset_l:
  5.1625    assumes lp: "islin p"
  5.1626 @@ -2150,8 +2141,8 @@
  5.1627        Ipoly vs c > 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s"
  5.1628      using lp nmi ex
  5.1629      apply (induct p rule: minusinf.induct)
  5.1630 -    apply (auto simp add: eq le lt polyneg_norm)
  5.1631 -    apply (auto simp add: linorder_not_less order_le_less)
  5.1632 +                        apply (auto simp add: eq le lt polyneg_norm)
  5.1633 +      apply (auto simp add: linorder_not_less order_le_less)
  5.1634      done
  5.1635    then obtain c s where csU: "(c, s) \<in> set (uset p)"
  5.1636      and x: "(Ipoly vs c < 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s) \<or>
  5.1637 @@ -2193,18 +2184,19 @@
  5.1638        Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s"
  5.1639      using lp nmi ex
  5.1640      apply (induct p rule: minusinf.induct)
  5.1641 -    apply (auto simp add: eq le lt polyneg_norm)
  5.1642 -    apply (auto simp add: linorder_not_less order_le_less)
  5.1643 +                        apply (auto simp add: eq le lt polyneg_norm)
  5.1644 +      apply (auto simp add: linorder_not_less order_le_less)
  5.1645      done
  5.1646 -  then obtain c s where csU: "(c, s) \<in> set (uset p)"
  5.1647 -    and x: "Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s \<or>
  5.1648 -      Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s"
  5.1649 +  then obtain c s
  5.1650 +    where c_s: "(c, s) \<in> set (uset p)"
  5.1651 +      and "Ipoly vs c < 0 \<and> Ipoly vs c * x \<ge> - Itm vs (x#bs) s \<or>
  5.1652 +        Ipoly vs c > 0 \<and> Ipoly vs c * x \<le> - Itm vs (x#bs) s"
  5.1653      by blast
  5.1654    then have "x \<le> (- Itm vs (x#bs) s) / Ipoly vs c"
  5.1655      using le_divide_eq[of x "- Itm vs (x#bs) s" "Ipoly vs c"]
  5.1656      by (auto simp add: mult.commute)
  5.1657    then show ?thesis
  5.1658 -    using csU by auto
  5.1659 +    using c_s by auto
  5.1660  qed
  5.1661  
  5.1662  lemma plusinf_uset:
  5.1663 @@ -2216,12 +2208,13 @@
  5.1664    from nmi have nmi': "\<not> (Ifm vs (x#bs) (plusinf p))"
  5.1665      by (simp add: bound0_I[OF plusinf_nb[OF lp], where b=x and b'=a])
  5.1666    from plusinf_uset0[OF lp nmi' ex]
  5.1667 -  obtain c s where csU: "(c,s) \<in> set (uset p)"
  5.1668 -    and th: "x \<le> - Itm vs (x#bs) s / Ipoly vs c"
  5.1669 +  obtain c s
  5.1670 +    where c_s: "(c,s) \<in> set (uset p)"
  5.1671 +      and x: "x \<le> - Itm vs (x#bs) s / Ipoly vs c"
  5.1672      by blast
  5.1673 -  from uset_l[OF lp, rule_format, OF csU] have nb: "tmbound0 s"
  5.1674 +  from uset_l[OF lp, rule_format, OF c_s] have nb: "tmbound0 s"
  5.1675      by simp
  5.1676 -  from th tmbound0_I[OF nb, of vs x bs a] csU show ?thesis
  5.1677 +  from x tmbound0_I[OF nb, of vs x bs a] c_s show ?thesis
  5.1678      by auto
  5.1679  qed
  5.1680  
  5.1681 @@ -2345,7 +2338,7 @@
  5.1682    next
  5.1683      case N: 3
  5.1684      from px neg_divide_le_eq[OF N, where a="x" and b="-?Nt x s"]
  5.1685 -    have px': "x >= - ?Nt x s / ?N c"
  5.1686 +    have px': "x \<ge> - ?Nt x s / ?N c"
  5.1687        by (simp add: field_simps)
  5.1688      from ycs show ?thesis
  5.1689      proof
  5.1690 @@ -2487,9 +2480,9 @@
  5.1691      have "\<exists>(c, t) \<in> set (uset p). \<exists>(d, s) \<in> set (uset p).
  5.1692          a \<le> - ?Nt x t / ?N c \<and> a \<ge> - ?Nt x s / ?N d"
  5.1693        by blast
  5.1694 -    then obtain "c" "t" "d" "s"
  5.1695 -      where ctU: "(c,t) \<in> ?U"
  5.1696 -        and dsU: "(d,s) \<in> ?U"
  5.1697 +    then obtain c t d s
  5.1698 +      where ctU: "(c, t) \<in> ?U"
  5.1699 +        and dsU: "(d, s) \<in> ?U"
  5.1700          and xs1: "a \<le> - ?Nt x s / ?N d"
  5.1701          and tx1: "a \<ge> - ?Nt x t / ?N c"
  5.1702        by blast
  5.1703 @@ -3090,18 +3083,18 @@
  5.1704    from lp have lin:"isnpoly a" "a \<noteq> 0\<^sub>p" "tmbound0 r" "allpolys isnpoly r"
  5.1705      by simp_all
  5.1706    note r = tmbound0_I[OF lin(3), of vs _ bs x]
  5.1707 -  have cd_cs: "?c * ?d < 0 \<or> ?c * ?d > 0 \<or> (?c = 0 \<and> ?d = 0) \<or> (?c = 0 \<and> ?d < 0) \<or> (?c = 0 \<and> ?d > 0) \<or> (?c < 0 \<and> ?d = 0) \<or> (?c > 0 \<and> ?d = 0)"
  5.1708 +  have "?c * ?d < 0 \<or> ?c * ?d > 0 \<or> (?c = 0 \<and> ?d = 0) \<or> (?c = 0 \<and> ?d < 0) \<or> (?c = 0 \<and> ?d > 0) \<or> (?c < 0 \<and> ?d = 0) \<or> (?c > 0 \<and> ?d = 0)"
  5.1709      by auto
  5.1710 -  moreover
  5.1711 -  {
  5.1712 -    assume c: "?c = 0" and d: "?d = 0"
  5.1713 -    then have ?thesis
  5.1714 -      using nc nd
  5.1715 +  then consider "?c = 0" "?d = 0" | "?c * ?d > 0" | "?c * ?d < 0"
  5.1716 +    | "?c > 0" "?d = 0" | "?c < 0" "?d = 0" | "?c = 0" "?d > 0" | "?c = 0" "?d < 0"
  5.1717 +    by blast
  5.1718 +  then show ?thesis
  5.1719 +  proof cases
  5.1720 +    case 1
  5.1721 +    with nc nd show ?thesis
  5.1722        by (simp add: polyneg_norm polymul_norm lt r[of 0] msubstle_def Let_def evaldjf_ex)
  5.1723 -  }
  5.1724 -  moreover
  5.1725 -  {
  5.1726 -    assume dc: "?c * ?d > 0"
  5.1727 +  next
  5.1728 +    case dc: 2
  5.1729      from dc have dc': "2 * ?c * ?d > 0"
  5.1730        by simp
  5.1731      then have c: "?c \<noteq> 0" and d: "?d \<noteq> 0"
  5.1732 @@ -3122,13 +3115,12 @@
  5.1733      also have "\<dots> \<longleftrightarrow> ?a * (- (?d * ?t + ?c* ?s )) + 2*?c*?d*?r \<le> 0"
  5.1734        using nonzero_mult_div_cancel_left[of "2*?c*?d"] c d
  5.1735        by (simp add: algebra_simps diff_divide_distrib del: distrib_right)
  5.1736 -    finally  have ?thesis using dc c d  nc nd dc'
  5.1737 +    finally show ?thesis
  5.1738 +      using dc c d  nc nd dc'
  5.1739        by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstle_def
  5.1740            Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1741 -  }
  5.1742 -  moreover
  5.1743 -  {
  5.1744 -    assume dc: "?c * ?d < 0"
  5.1745 +  next
  5.1746 +    case dc: 3
  5.1747      from dc have dc': "2 * ?c * ?d < 0"
  5.1748        by (simp add: mult_less_0_iff field_simps add_neg_neg add_pos_pos)
  5.1749      then have c: "?c \<noteq> 0" and d: "?d \<noteq> 0"
  5.1750 @@ -3147,13 +3139,13 @@
  5.1751      also have "\<dots> \<longleftrightarrow> ?a * ((?d * ?t + ?c* ?s )) - 2 * ?c * ?d * ?r \<le> 0"
  5.1752        using nonzero_mult_div_cancel_left[of "2 * ?c * ?d"] c d
  5.1753        by (simp add: algebra_simps diff_divide_distrib del: distrib_right)
  5.1754 -    finally  have ?thesis using dc c d  nc nd
  5.1755 +    finally show ?thesis
  5.1756 +      using dc c d  nc nd
  5.1757        by (simp add: r[of "(- (?d * ?t) + - (?c *?s)) / (2 * ?c * ?d)"] msubstle_def
  5.1758            Let_def evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1759 -  }
  5.1760 -  moreover
  5.1761 -  {
  5.1762 -    assume c: "?c > 0" and d: "?d = 0"
  5.1763 +  next
  5.1764 +    case 4
  5.1765 +    have c: "?c > 0" and d: "?d = 0" by fact+
  5.1766      from c have c'': "2 * ?c > 0"
  5.1767        by (simp add: zero_less_mult_iff)
  5.1768      from c have c': "2 * ?c \<noteq> 0"
  5.1769 @@ -3171,13 +3163,13 @@
  5.1770      also have "\<dots> \<longleftrightarrow> - ?a*?t+  2*?c *?r \<le> 0"
  5.1771        using nonzero_mult_div_cancel_left[OF c'] c
  5.1772        by (simp add: algebra_simps diff_divide_distrib less_le del: distrib_right)
  5.1773 -    finally have ?thesis using c d nc nd
  5.1774 +    finally show ?thesis
  5.1775 +      using c d nc nd
  5.1776        by (simp add: r[of "- (?t / (2*?c))"] msubstle_def Let_def
  5.1777            evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1778 -  }
  5.1779 -  moreover
  5.1780 -  {
  5.1781 -    assume c: "?c < 0" and d: "?d = 0"
  5.1782 +  next
  5.1783 +    case 5
  5.1784 +    have c: "?c < 0" and d: "?d = 0" by fact+
  5.1785      then have c': "2 * ?c \<noteq> 0"
  5.1786        by simp
  5.1787      from c have c'': "2 * ?c < 0"
  5.1788 @@ -3196,13 +3188,12 @@
  5.1789        using nonzero_mult_div_cancel_left[OF c'] c order_less_not_sym[OF c'']
  5.1790            less_imp_neq[OF c''] c''
  5.1791          by (simp add: algebra_simps diff_divide_distrib del: distrib_right)
  5.1792 -    finally have ?thesis using c d nc nd
  5.1793 +    finally show ?thesis using c d nc nd
  5.1794        by (simp add: r[of "- (?t / (2*?c))"] msubstle_def Let_def
  5.1795            evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1796 -  }
  5.1797 -  moreover
  5.1798 -  {
  5.1799 -    assume c: "?c = 0" and d: "?d > 0"
  5.1800 +  next
  5.1801 +    case 6
  5.1802 +    have c: "?c = 0" and d: "?d > 0" by fact+
  5.1803      from d have d'': "2 * ?d > 0"
  5.1804        by (simp add: zero_less_mult_iff)
  5.1805      from d have d': "2 * ?d \<noteq> 0"
  5.1806 @@ -3220,13 +3211,13 @@
  5.1807      also have "\<dots> \<longleftrightarrow> - ?a * ?s + 2 * ?d * ?r \<le> 0"
  5.1808        using nonzero_mult_div_cancel_left[OF d'] d
  5.1809        by (simp add: algebra_simps diff_divide_distrib less_le del: distrib_right)
  5.1810 -    finally have ?thesis using c d nc nd
  5.1811 +    finally show ?thesis
  5.1812 +      using c d nc nd
  5.1813        by (simp add: r[of "- (?s / (2*?d))"] msubstle_def Let_def
  5.1814            evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1815 -  }
  5.1816 -  moreover
  5.1817 -  {
  5.1818 -    assume c: "?c = 0" and d: "?d < 0"
  5.1819 +  next
  5.1820 +    case 7
  5.1821 +    have c: "?c = 0" and d: "?d < 0" by fact+
  5.1822      then have d': "2 * ?d \<noteq> 0"
  5.1823        by simp
  5.1824      from d have d'': "2 * ?d < 0"
  5.1825 @@ -3243,24 +3234,24 @@
  5.1826        by simp
  5.1827      also have "\<dots> \<longleftrightarrow> ?a * ?s -  2 * ?d * ?r \<le> 0"
  5.1828        using nonzero_mult_div_cancel_left[OF d'] d order_less_not_sym[OF d'']
  5.1829 -          less_imp_neq[OF d''] d''
  5.1830 -        by (simp add: algebra_simps diff_divide_distrib del: distrib_right)
  5.1831 -    finally have ?thesis using c d nc nd
  5.1832 +        less_imp_neq[OF d''] d''
  5.1833 +      by (simp add: algebra_simps diff_divide_distrib del: distrib_right)
  5.1834 +    finally show ?thesis
  5.1835 +      using c d nc nd
  5.1836        by (simp add: r[of "- (?s / (2*?d))"] msubstle_def Let_def
  5.1837            evaldjf_ex field_simps lt polyneg_norm polymul_norm)
  5.1838 -  }
  5.1839 -  ultimately show ?thesis by blast
  5.1840 +  qed
  5.1841  qed
  5.1842  
  5.1843  fun msubst :: "fm \<Rightarrow> (poly \<times> tm) \<times> (poly \<times> tm) \<Rightarrow> fm"
  5.1844 -where
  5.1845 -  "msubst (And p q) ((c, t), (d, s)) = conj (msubst p ((c,t),(d,s))) (msubst q ((c, t), (d, s)))"
  5.1846 -| "msubst (Or p q) ((c, t), (d, s)) = disj (msubst p ((c,t),(d,s))) (msubst q ((c, t), (d, s)))"
  5.1847 -| "msubst (Eq (CNP 0 a r)) ((c, t), (d, s)) = msubsteq c t d s a r"
  5.1848 -| "msubst (NEq (CNP 0 a r)) ((c, t), (d, s)) = msubstneq c t d s a r"
  5.1849 -| "msubst (Lt (CNP 0 a r)) ((c, t), (d, s)) = msubstlt c t d s a r"
  5.1850 -| "msubst (Le (CNP 0 a r)) ((c, t), (d, s)) = msubstle c t d s a r"
  5.1851 -| "msubst p ((c, t), (d, s)) = p"
  5.1852 +  where
  5.1853 +    "msubst (And p q) ((c, t), (d, s)) = conj (msubst p ((c,t),(d,s))) (msubst q ((c, t), (d, s)))"
  5.1854 +  | "msubst (Or p q) ((c, t), (d, s)) = disj (msubst p ((c,t),(d,s))) (msubst q ((c, t), (d, s)))"
  5.1855 +  | "msubst (Eq (CNP 0 a r)) ((c, t), (d, s)) = msubsteq c t d s a r"
  5.1856 +  | "msubst (NEq (CNP 0 a r)) ((c, t), (d, s)) = msubstneq c t d s a r"
  5.1857 +  | "msubst (Lt (CNP 0 a r)) ((c, t), (d, s)) = msubstlt c t d s a r"
  5.1858 +  | "msubst (Le (CNP 0 a r)) ((c, t), (d, s)) = msubstle c t d s a r"
  5.1859 +  | "msubst p ((c, t), (d, s)) = p"
  5.1860  
  5.1861  lemma msubst_I:
  5.1862    assumes lp: "islin p"
  5.1863 @@ -3276,12 +3267,12 @@
  5.1864        msubsteq msubstneq msubstlt [OF nc nd] msubstle [OF nc nd])
  5.1865  
  5.1866  lemma msubst_nb:
  5.1867 -  assumes lp: "islin p"
  5.1868 -    and t: "tmbound0 t"
  5.1869 -    and s: "tmbound0 s"
  5.1870 +  assumes "islin p"
  5.1871 +    and "tmbound0 t"
  5.1872 +    and "tmbound0 s"
  5.1873    shows "bound0 (msubst p ((c,t),(d,s)))"
  5.1874 -  using lp t s
  5.1875 -  by (induct p rule: islin.induct, auto simp add: msubsteq_nb msubstneq_nb msubstlt_nb msubstle_nb)
  5.1876 +  using assms
  5.1877 +  by (induct p rule: islin.induct) (auto simp add: msubsteq_nb msubstneq_nb msubstlt_nb msubstle_nb)
  5.1878  
  5.1879  lemma fr_eq_msubst:
  5.1880    assumes lp: "islin p"
  5.1881 @@ -3292,15 +3283,14 @@
  5.1882        Ifm vs (x#bs) (msubst p ((c, t), (d, s)))))"
  5.1883    (is "(\<exists>x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
  5.1884  proof -
  5.1885 -  from uset_l[OF lp]
  5.1886 -  have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s"
  5.1887 +  from uset_l[OF lp] have *: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s"
  5.1888      by blast
  5.1889    {
  5.1890      fix c t d s
  5.1891      assume ctU: "(c, t) \<in>set (uset p)"
  5.1892        and dsU: "(d,s) \<in>set (uset p)"
  5.1893        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"
  5.1894 -    from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d"
  5.1895 +    from *[rule_format, OF ctU] *[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d"
  5.1896        by simp_all
  5.1897      from msubst_I[OF lp norm, of vs x bs t s] pts
  5.1898      have "Ifm vs (x # bs) (msubst p ((c, t), d, s))" ..
  5.1899 @@ -3311,15 +3301,15 @@
  5.1900      assume ctU: "(c, t) \<in> set (uset p)"
  5.1901        and dsU: "(d,s) \<in>set (uset p)"
  5.1902        and pts: "Ifm vs (x # bs) (msubst p ((c, t), d, s))"
  5.1903 -    from th[rule_format, OF ctU] th[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d"
  5.1904 +    from *[rule_format, OF ctU] *[rule_format, OF dsU] have norm:"isnpoly c" "isnpoly d"
  5.1905        by simp_all
  5.1906      from msubst_I[OF lp norm, of vs x bs t s] pts
  5.1907      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" ..
  5.1908    }
  5.1909 -  ultimately have th': "(\<exists>(c, t) \<in> set (uset p). \<exists>(d, s) \<in> set (uset p).
  5.1910 +  ultimately have **: "(\<exists>(c, t) \<in> set (uset p). \<exists>(d, s) \<in> set (uset p).
  5.1911        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"
  5.1912      by blast
  5.1913 -  from fr_eq[OF lp, of vs bs x, simplified th'] show ?thesis .
  5.1914 +  from fr_eq[OF lp, of vs bs x, simplified **] show ?thesis .
  5.1915  qed
  5.1916  
  5.1917  lemma simpfm_lin:
  5.1918 @@ -3407,7 +3397,7 @@
  5.1919      using decr0[OF th1, of vs x bs]
  5.1920      apply (simp add: ferrack_def Let_def)
  5.1921      apply (cases "?mp = T \<or> ?pp = T")
  5.1922 -    apply auto
  5.1923 +     apply auto
  5.1924      done
  5.1925    finally show ?thesis
  5.1926      using thqf by blast
  5.1927 @@ -3425,7 +3415,7 @@
  5.1928  qed
  5.1929  
  5.1930  
  5.1931 -section \<open>Second implemenation: Case splits not local\<close>
  5.1932 +section \<open>Second implementation: case splits not local\<close>
  5.1933  
  5.1934  lemma fr_eq2:
  5.1935    assumes lp: "islin p"
  5.1936 @@ -3442,14 +3432,14 @@
  5.1937    (is "(\<exists>x. ?I x p) = (?M \<or> ?P \<or> ?Z \<or> ?U \<or> ?F)" is "?E = ?D")
  5.1938  proof
  5.1939    assume px: "\<exists>x. ?I x p"
  5.1940 -  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
  5.1941 -  moreover {
  5.1942 -    assume "?M \<or> ?P"
  5.1943 -    then have "?D" by blast
  5.1944 -  }
  5.1945 -  moreover {
  5.1946 -    assume nmi: "\<not> ?M"
  5.1947 -      and npi: "\<not> ?P"
  5.1948 +  consider "?M \<or> ?P" | "\<not> ?M" "\<not> ?P" by blast
  5.1949 +  then show ?D
  5.1950 +  proof cases
  5.1951 +    case 1
  5.1952 +    then show ?thesis by blast
  5.1953 +  next
  5.1954 +    case 2
  5.1955 +    have nmi: "\<not> ?M" and npi: "\<not> ?P" by fact+
  5.1956      from inf_uset[OF lp nmi npi, OF px]
  5.1957      obtain c t d s where ct:
  5.1958        "(c, t) \<in> set (uset p)"
  5.1959 @@ -3462,50 +3452,42 @@
  5.1960      let ?t = "Itm vs (x # bs) t"
  5.1961      have eq2: "\<And>(x::'a). x + x = 2 * x"
  5.1962        by (simp add: field_simps)
  5.1963 -    {
  5.1964 -      assume "?c = 0 \<and> ?d = 0"
  5.1965 -      with ct have ?D by simp
  5.1966 -    }
  5.1967 -    moreover
  5.1968 -    {
  5.1969 -      assume z: "?c = 0" "?d \<noteq> 0"
  5.1970 -      from z have ?D using ct by auto
  5.1971 -    }
  5.1972 -    moreover
  5.1973 -    {
  5.1974 -      assume z: "?c \<noteq> 0" "?d = 0"
  5.1975 -      with ct have ?D by auto
  5.1976 -    }
  5.1977 -    moreover
  5.1978 -    {
  5.1979 -      assume z: "?c \<noteq> 0" "?d \<noteq> 0"
  5.1980 -      from z have ?F using ct
  5.1981 +    consider "?c = 0" "?d = 0" | "?c = 0" "?d \<noteq> 0" | "?c \<noteq> 0" "?d = 0" | "?c \<noteq> 0" "?d \<noteq> 0"
  5.1982 +      by auto
  5.1983 +    then show ?thesis
  5.1984 +    proof cases
  5.1985 +      case 1
  5.1986 +      with ct show ?thesis by simp
  5.1987 +    next
  5.1988 +      case 2
  5.1989 +      with ct show ?thesis by auto
  5.1990 +    next
  5.1991 +      case 3
  5.1992 +      with ct show ?thesis by auto
  5.1993 +    next
  5.1994 +      case z: 4
  5.1995 +      from z have ?F
  5.1996 +        using ct
  5.1997          apply -
  5.1998          apply (rule bexI[where x = "(c,t)"])
  5.1999 -        apply simp_all
  5.2000 +         apply simp_all
  5.2001          apply (rule bexI[where x = "(d,s)"])
  5.2002 -        apply simp_all
  5.2003 +         apply simp_all
  5.2004          done
  5.2005 -      then have ?D by blast
  5.2006 -    }
  5.2007 -    ultimately have ?D by auto
  5.2008 -  }
  5.2009 -  ultimately show "?D" by blast
  5.2010 +      then show ?thesis by blast
  5.2011 +    qed
  5.2012 +  qed
  5.2013  next
  5.2014 -  assume "?D"
  5.2015 -  moreover {
  5.2016 -    assume m: "?M"
  5.2017 -    from minusinf_ex[OF lp m] have "?E" .
  5.2018 -  }
  5.2019 -  moreover {
  5.2020 -    assume p: "?P"
  5.2021 -    from plusinf_ex[OF lp p] have "?E" .
  5.2022 -  }
  5.2023 -  moreover {
  5.2024 -    assume f:"?F"
  5.2025 -    then have "?E" by blast
  5.2026 -  }
  5.2027 -  ultimately show "?E" by blast
  5.2028 +  assume ?D
  5.2029 +  then consider ?M | ?P | ?Z | ?U | ?F by blast
  5.2030 +  then show ?E
  5.2031 +  proof cases
  5.2032 +    case 1
  5.2033 +    show ?thesis by (rule minusinf_ex[OF lp \<open>?M\<close>])
  5.2034 +  next
  5.2035 +    case 2
  5.2036 +    show ?thesis by (rule plusinf_ex[OF lp \<open>?P\<close>])
  5.2037 +  qed blast+
  5.2038  qed
  5.2039  
  5.2040  definition "msubsteq2 c t a b = Eq (Add (Mul a t) (Mul c b))"
  5.2041 @@ -3555,14 +3537,14 @@
  5.2042    by (simp add: msubstleneg_def field_simps del: minus_add_distrib)
  5.2043  
  5.2044  fun msubstpos :: "fm \<Rightarrow> poly \<Rightarrow> tm \<Rightarrow> fm"
  5.2045 -where
  5.2046 -  "msubstpos (And p q) c t = And (msubstpos p c t) (msubstpos q c t)"
  5.2047 -| "msubstpos (Or p q) c t = Or (msubstpos p c t) (msubstpos q c t)"
  5.2048 -| "msubstpos (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
  5.2049 -| "msubstpos (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
  5.2050 -| "msubstpos (Lt (CNP 0 a r)) c t = msubstltpos c t a r"
  5.2051 -| "msubstpos (Le (CNP 0 a r)) c t = msubstlepos c t a r"
  5.2052 -| "msubstpos p c t = p"
  5.2053 +  where
  5.2054 +    "msubstpos (And p q) c t = And (msubstpos p c t) (msubstpos q c t)"
  5.2055 +  | "msubstpos (Or p q) c t = Or (msubstpos p c t) (msubstpos q c t)"
  5.2056 +  | "msubstpos (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
  5.2057 +  | "msubstpos (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
  5.2058 +  | "msubstpos (Lt (CNP 0 a r)) c t = msubstltpos c t a r"
  5.2059 +  | "msubstpos (Le (CNP 0 a r)) c t = msubstlepos c t a r"
  5.2060 +  | "msubstpos p c t = p"
  5.2061  
  5.2062  lemma msubstpos_I:
  5.2063    assumes lp: "islin p"
  5.2064 @@ -3576,14 +3558,14 @@
  5.2065        bound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] field_simps)
  5.2066  
  5.2067  fun msubstneg :: "fm \<Rightarrow> poly \<Rightarrow> tm \<Rightarrow> fm"
  5.2068 -where
  5.2069 -  "msubstneg (And p q) c t = And (msubstneg p c t) (msubstneg q c t)"
  5.2070 -| "msubstneg (Or p q) c t = Or (msubstneg p c t) (msubstneg q c t)"
  5.2071 -| "msubstneg (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
  5.2072 -| "msubstneg (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
  5.2073 -| "msubstneg (Lt (CNP 0 a r)) c t = msubstltneg c t a r"
  5.2074 -| "msubstneg (Le (CNP 0 a r)) c t = msubstleneg c t a r"
  5.2075 -| "msubstneg p c t = p"
  5.2076 +  where
  5.2077 +    "msubstneg (And p q) c t = And (msubstneg p c t) (msubstneg q c t)"
  5.2078 +  | "msubstneg (Or p q) c t = Or (msubstneg p c t) (msubstneg q c t)"
  5.2079 +  | "msubstneg (Eq (CNP 0 a r)) c t = msubsteq2 c t a r"
  5.2080 +  | "msubstneg (NEq (CNP 0 a r)) c t = NOT (msubsteq2 c t a r)"
  5.2081 +  | "msubstneg (Lt (CNP 0 a r)) c t = msubstltneg c t a r"
  5.2082 +  | "msubstneg (Le (CNP 0 a r)) c t = msubstleneg c t a r"
  5.2083 +  | "msubstneg p c t = p"
  5.2084  
  5.2085  lemma msubstneg_I:
  5.2086    assumes lp: "islin p"
  5.2087 @@ -3595,11 +3577,9 @@
  5.2088        tmbound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x]
  5.2089        bound0_I[of _ vs "Itm vs (x # bs) t / \<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup>" bs x] field_simps)
  5.2090  
  5.2091 -definition
  5.2092 -  "msubst2 p c t =
  5.2093 -    disj
  5.2094 -      (conj (lt (CP (polyneg c))) (simpfm (msubstpos p c t)))
  5.2095 -      (conj (lt (CP c)) (simpfm (msubstneg p c t)))"
  5.2096 +definition "msubst2 p c t =
  5.2097 +  disj (conj (lt (CP (polyneg c))) (simpfm (msubstpos p c t)))
  5.2098 +    (conj (lt (CP c)) (simpfm (msubstneg p c t)))"
  5.2099  
  5.2100  lemma msubst2:
  5.2101    assumes lp: "islin p"
  5.2102 @@ -3610,20 +3590,19 @@
  5.2103    let ?c = "Ipoly vs c"
  5.2104    from nc have anc: "allpolys isnpoly (CP c)" "allpolys isnpoly (CP (~\<^sub>p c))"
  5.2105      by (simp_all add: polyneg_norm)
  5.2106 -  from nz have "?c > 0 \<or> ?c < 0" by arith
  5.2107 -  moreover
  5.2108 -  {
  5.2109 -    assume c: "?c < 0"
  5.2110 +  from nz consider "?c < 0" | "?c > 0" by arith
  5.2111 +  then show ?thesis
  5.2112 +  proof cases
  5.2113 +    case c: 1
  5.2114      from c msubstneg_I[OF lp c, of x bs t] lt[OF anc(1), of vs "x#bs"] lt[OF anc(2), of vs "x#bs"]
  5.2115 -    have ?thesis by (auto simp add: msubst2_def)
  5.2116 -  }
  5.2117 -  moreover
  5.2118 -  {
  5.2119 -    assume c: "?c > 0"
  5.2120 +    show ?thesis
  5.2121 +      by (auto simp add: msubst2_def)
  5.2122 +  next
  5.2123 +    case c: 2
  5.2124      from c msubstpos_I[OF lp c, of x bs t] lt[OF anc(1), of vs "x#bs"] lt[OF anc(2), of vs "x#bs"]
  5.2125 -    have ?thesis by (auto simp add: msubst2_def)
  5.2126 -  }
  5.2127 -  ultimately show ?thesis by blast
  5.2128 +    show ?thesis
  5.2129 +      by (auto simp add: msubst2_def)
  5.2130 +  qed
  5.2131  qed
  5.2132  
  5.2133  lemma msubsteq2_nb: "tmbound0 t \<Longrightarrow> islin (Eq (CNP 0 a r)) \<Longrightarrow> bound0 (msubsteq2 c t a r)"
  5.2134 @@ -3664,10 +3643,12 @@
  5.2135    using lp tnb
  5.2136    by (simp add: msubst2_def msubstneg_nb msubstpos_nb lt_nb simpfm_bound0)
  5.2137  
  5.2138 -lemma mult_minus2_left: "-2 * (x::'a::comm_ring_1) = - (2 * x)"
  5.2139 +lemma mult_minus2_left: "-2 * x = - (2 * x)"
  5.2140 +  for x :: "'a::comm_ring_1"
  5.2141    by simp
  5.2142  
  5.2143 -lemma mult_minus2_right: "(x::'a::comm_ring_1) * -2 = - (x * 2)"
  5.2144 +lemma mult_minus2_right: "x * -2 = - (x * 2)"
  5.2145 +  for x :: "'a::comm_ring_1"
  5.2146    by simp
  5.2147  
  5.2148  lemma islin_qf: "islin p \<Longrightarrow> qfree p"
  5.2149 @@ -3685,7 +3666,7 @@
  5.2150          Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))))"
  5.2151    (is "(\<exists>x. ?I x p) = (?M \<or> ?P \<or> ?Pz \<or> ?PU \<or> ?F)" is "?E = ?D")
  5.2152  proof -
  5.2153 -  from uset_l[OF lp] have th: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s"
  5.2154 +  from uset_l[OF lp] have *: "\<forall>(c, s)\<in>set (uset p). isnpoly c \<and> tmbound0 s"
  5.2155      by blast
  5.2156    let ?I = "\<lambda>p. Ifm vs (x#bs) p"
  5.2157    have n2: "isnpoly (C (-2,1))"
  5.2158 @@ -3700,7 +3681,7 @@
  5.2159      {
  5.2160        fix n t
  5.2161        assume H: "(n, t) \<in> set (uset p)" "?I(msubst2 p (n *\<^sub>p C (-2, 1)) t)"
  5.2162 -      from H(1) th have "isnpoly n"
  5.2163 +      from H(1) * have "isnpoly n"
  5.2164          by blast
  5.2165        then have nn: "isnpoly (n *\<^sub>p (C (-2,1)))"
  5.2166          by (simp_all add: polymul_norm n2)
  5.2167 @@ -3719,7 +3700,7 @@
  5.2168        assume H:
  5.2169          "(n, t) \<in> set (uset p)" "\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  5.2170          "Ifm vs (- Itm vs (x # bs) t / (\<lparr>n\<rparr>\<^sub>p\<^bsup>vs\<^esup> * 2) # bs) p"
  5.2171 -      from H(1) th have "isnpoly n"
  5.2172 +      from H(1) * have "isnpoly n"
  5.2173          by blast
  5.2174        then have nn: "isnpoly (n *\<^sub>p (C (-2,1)))" "\<lparr>n *\<^sub>p(C (-2,1)) \<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  5.2175          using H(2) by (simp_all add: polymul_norm n2)
  5.2176 @@ -3740,7 +3721,7 @@
  5.2177        assume H:
  5.2178          "(c,t) \<in> set (uset p)" "(d,s) \<in> set (uset p)"
  5.2179          "Ifm vs (x#bs) (msubst2 p (C (-2, 1) *\<^sub>p c*\<^sub>p d) (Add (Mul d t) (Mul c s)))"
  5.2180 -      from H(1,2) th have "isnpoly c" "isnpoly d"
  5.2181 +      from H(1,2) * have "isnpoly c" "isnpoly d"
  5.2182          by blast+
  5.2183        then have nn: "isnpoly (C (-2, 1) *\<^sub>p c*\<^sub>p d)"
  5.2184          by (simp_all add: polymul_norm n2)
  5.2185 @@ -3766,7 +3747,7 @@
  5.2186          "\<lparr>c\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  5.2187          "\<lparr>d\<rparr>\<^sub>p\<^bsup>vs\<^esup> \<noteq> 0"
  5.2188          "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"
  5.2189 -      from H(1,2) th have "isnpoly c" "isnpoly d"
  5.2190 +      from H(1,2) * have "isnpoly c" "isnpoly d"
  5.2191          by blast+
  5.2192        then have 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"
  5.2193          using H(3,4) by (simp_all add: polymul_norm n2)
  5.2194 @@ -3780,32 +3761,31 @@
  5.2195      unfolding eq0 eq1 eq2 by blast
  5.2196  qed
  5.2197  
  5.2198 -definition
  5.2199 -  "ferrack2 p \<equiv>
  5.2200 -    let
  5.2201 -      q = simpfm p;
  5.2202 -      mp = minusinf q;
  5.2203 -      pp = plusinf q
  5.2204 -    in
  5.2205 -      if (mp = T \<or> pp = T) then T
  5.2206 -      else
  5.2207 -       (let U = remdups (uset  q)
  5.2208 -        in
  5.2209 -          decr0
  5.2210 -            (list_disj
  5.2211 -              [mp,
  5.2212 -               pp,
  5.2213 -               simpfm (subst0 (CP 0\<^sub>p) q),
  5.2214 -               evaldjf (\<lambda>(c, t). msubst2 q (c *\<^sub>p C (-2, 1)) t) U,
  5.2215 -               evaldjf (\<lambda>((b, a),(d, c)).
  5.2216 -                msubst2 q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) (alluopairs U)]))"
  5.2217 +definition "ferrack2 p \<equiv>
  5.2218 +  let
  5.2219 +    q = simpfm p;
  5.2220 +    mp = minusinf q;
  5.2221 +    pp = plusinf q
  5.2222 +  in
  5.2223 +    if (mp = T \<or> pp = T) then T
  5.2224 +    else
  5.2225 +     (let U = remdups (uset  q)
  5.2226 +      in
  5.2227 +        decr0
  5.2228 +          (list_disj
  5.2229 +            [mp,
  5.2230 +             pp,
  5.2231 +             simpfm (subst0 (CP 0\<^sub>p) q),
  5.2232 +             evaldjf (\<lambda>(c, t). msubst2 q (c *\<^sub>p C (-2, 1)) t) U,
  5.2233 +             evaldjf (\<lambda>((b, a),(d, c)).
  5.2234 +              msubst2 q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) (alluopairs U)]))"
  5.2235  
  5.2236  definition "frpar2 p = simpfm (qelim (prep p) ferrack2)"
  5.2237  
  5.2238  lemma ferrack2:
  5.2239    assumes qf: "qfree p"
  5.2240    shows "qfree (ferrack2 p) \<and> Ifm vs bs (ferrack2 p) = Ifm vs bs (E p)"
  5.2241 -  (is "_ \<and> (?rhs = ?lhs)")
  5.2242 +    (is "_ \<and> (?rhs = ?lhs)")
  5.2243  proof -
  5.2244    let ?J = "\<lambda>x p. Ifm vs (x#bs) p"
  5.2245    let ?N = "\<lambda>t. Ipoly vs t"
  5.2246 @@ -3826,34 +3806,29 @@
  5.2247      by simp
  5.2248    have bnd0: "\<forall>x \<in> set ?U. bound0 ((\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) x)"
  5.2249    proof -
  5.2250 -    {
  5.2251 -      fix c t
  5.2252 -      assume ct: "(c, t) \<in> set ?U"
  5.2253 -      then have tnb: "tmbound0 t"
  5.2254 -        using U_l by blast
  5.2255 -      from msubst2_nb[OF lq tnb]
  5.2256 -      have "bound0 ((\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) (c,t))" by simp
  5.2257 -    }
  5.2258 +    have "bound0 ((\<lambda>(c,t). msubst2 ?q (c *\<^sub>p C (-2, 1)) t) (c,t))"
  5.2259 +      if "(c, t) \<in> set ?U" for c t
  5.2260 +    proof -
  5.2261 +      from U_l that have "tmbound0 t" by blast
  5.2262 +      from msubst2_nb[OF lq this] show ?thesis by simp
  5.2263 +    qed
  5.2264      then show ?thesis by auto
  5.2265    qed
  5.2266    have bnd1: "\<forall>x \<in> set ?Up. bound0 ((\<lambda>((b, a), (d, c)).
  5.2267      msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) x)"
  5.2268    proof -
  5.2269 -    {
  5.2270 -      fix b a d c
  5.2271 -      assume badc: "((b,a),(d,c)) \<in> set ?Up"
  5.2272 -      from badc U_l alluopairs_set1[of ?U]
  5.2273 -      have nb: "tmbound0 (Add (Mul d a) (Mul b c))"
  5.2274 +    have "bound0 ((\<lambda>((b, a),(d, c)).
  5.2275 +      msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) ((b,a),(d,c)))"
  5.2276 +      if  "((b,a),(d,c)) \<in> set ?Up" for b a d c
  5.2277 +    proof -
  5.2278 +      from U_l alluopairs_set1[of ?U] that have this: "tmbound0 (Add (Mul d a) (Mul b c))"
  5.2279          by auto
  5.2280 -      from msubst2_nb[OF lq nb]
  5.2281 -      have "bound0 ((\<lambda>((b, a),(d, c)).
  5.2282 -          msubst2 ?q (C (-2, 1) *\<^sub>p b*\<^sub>p d) (Add (Mul d a) (Mul b c))) ((b,a),(d,c)))"
  5.2283 +      from msubst2_nb[OF lq this] show ?thesis
  5.2284          by simp
  5.2285 -    }
  5.2286 +    qed
  5.2287      then show ?thesis by auto
  5.2288    qed
  5.2289 -  have stupid: "bound0 F"
  5.2290 -    by simp
  5.2291 +  have stupid: "bound0 F" by simp
  5.2292    let ?R =
  5.2293      "list_disj
  5.2294       [?mp,
  5.2295 @@ -3925,9 +3900,9 @@
  5.2296    also have "\<dots> \<longleftrightarrow> ?rhs"
  5.2297      unfolding ferrack2_def
  5.2298      apply (cases "?mp = T")
  5.2299 -    apply (simp add: list_disj_def)
  5.2300 +     apply (simp add: list_disj_def)
  5.2301      apply (cases "?pp = T")
  5.2302 -    apply (simp add: list_disj_def)
  5.2303 +     apply (simp add: list_disj_def)
  5.2304      apply (simp_all add: Let_def decr0[OF nb])
  5.2305      done
  5.2306    finally show ?thesis using decr0_qf[OF nb]
  5.2307 @@ -3937,14 +3912,14 @@
  5.2308  lemma frpar2: "qfree (frpar2 p) \<and> (Ifm vs bs (frpar2 p) \<longleftrightarrow> Ifm vs bs p)"
  5.2309  proof -
  5.2310    from ferrack2
  5.2311 -  have th: "\<forall>bs p. qfree p \<longrightarrow> qfree (ferrack2 p) \<and> Ifm vs bs (ferrack2 p) = Ifm vs bs (E p)"
  5.2312 +  have this: "\<forall>bs p. qfree p \<longrightarrow> qfree (ferrack2 p) \<and> Ifm vs bs (ferrack2 p) = Ifm vs bs (E p)"
  5.2313      by blast
  5.2314 -  from qelim[OF th, of "prep p" bs]
  5.2315 -  show ?thesis
  5.2316 +  from qelim[OF this, of "prep p" bs] show ?thesis
  5.2317      unfolding frpar2_def by (auto simp add: prep)
  5.2318  qed
  5.2319  
  5.2320 -oracle frpar_oracle = \<open>
  5.2321 +oracle frpar_oracle =
  5.2322 +\<open>
  5.2323  let
  5.2324  
  5.2325  fun binopT T = T --> T --> T;
     6.1 --- a/src/HOL/Decision_Procs/Rat_Pair.thy	Sun Dec 03 19:09:42 2017 +0100
     6.2 +++ b/src/HOL/Decision_Procs/Rat_Pair.thy	Sun Dec 03 22:28:19 2017 +0100
     6.3 @@ -5,7 +5,7 @@
     6.4  section \<open>Rational numbers as pairs\<close>
     6.5  
     6.6  theory Rat_Pair
     6.7 -imports Complex_Main
     6.8 +  imports Complex_Main
     6.9  begin
    6.10  
    6.11  type_synonym Num = "int \<times> int"
    6.12 @@ -20,8 +20,7 @@
    6.13    where "isnormNum = (\<lambda>(a, b). if a = 0 then b = 0 else b > 0 \<and> gcd a b = 1)"
    6.14  
    6.15  definition normNum :: "Num \<Rightarrow> Num"
    6.16 -where
    6.17 -  "normNum = (\<lambda>(a,b).
    6.18 +  where "normNum = (\<lambda>(a,b).
    6.19      (if a = 0 \<or> b = 0 then (0, 0)
    6.20       else
    6.21        (let g = gcd a b
     7.1 --- a/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Sun Dec 03 19:09:42 2017 +0100
     7.2 +++ b/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Sun Dec 03 22:28:19 2017 +0100
     7.3 @@ -5,7 +5,7 @@
     7.4  section \<open>Implementation and verification of multivariate polynomials\<close>
     7.5  
     7.6  theory Reflected_Multivariate_Polynomial
     7.7 -imports Complex_Main Rat_Pair Polynomial_List
     7.8 +  imports Complex_Main Rat_Pair Polynomial_List
     7.9  begin
    7.10  
    7.11  subsection \<open>Datatype of polynomial expressions\<close>
    7.12 @@ -20,95 +20,95 @@
    7.13  subsection\<open>Boundedness, substitution and all that\<close>
    7.14  
    7.15  primrec polysize:: "poly \<Rightarrow> nat"
    7.16 -where
    7.17 -  "polysize (C c) = 1"
    7.18 -| "polysize (Bound n) = 1"
    7.19 -| "polysize (Neg p) = 1 + polysize p"
    7.20 -| "polysize (Add p q) = 1 + polysize p + polysize q"
    7.21 -| "polysize (Sub p q) = 1 + polysize p + polysize q"
    7.22 -| "polysize (Mul p q) = 1 + polysize p + polysize q"
    7.23 -| "polysize (Pw p n) = 1 + polysize p"
    7.24 -| "polysize (CN c n p) = 4 + polysize c + polysize p"
    7.25 +  where
    7.26 +    "polysize (C c) = 1"
    7.27 +  | "polysize (Bound n) = 1"
    7.28 +  | "polysize (Neg p) = 1 + polysize p"
    7.29 +  | "polysize (Add p q) = 1 + polysize p + polysize q"
    7.30 +  | "polysize (Sub p q) = 1 + polysize p + polysize q"
    7.31 +  | "polysize (Mul p q) = 1 + polysize p + polysize q"
    7.32 +  | "polysize (Pw p n) = 1 + polysize p"
    7.33 +  | "polysize (CN c n p) = 4 + polysize c + polysize p"
    7.34  
    7.35  primrec polybound0:: "poly \<Rightarrow> bool" \<comment> \<open>a poly is INDEPENDENT of Bound 0\<close>
    7.36 -where
    7.37 -  "polybound0 (C c) \<longleftrightarrow> True"
    7.38 -| "polybound0 (Bound n) \<longleftrightarrow> n > 0"
    7.39 -| "polybound0 (Neg a) \<longleftrightarrow> polybound0 a"
    7.40 -| "polybound0 (Add a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.41 -| "polybound0 (Sub a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.42 -| "polybound0 (Mul a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.43 -| "polybound0 (Pw p n) \<longleftrightarrow> polybound0 p"
    7.44 -| "polybound0 (CN c n p) \<longleftrightarrow> n \<noteq> 0 \<and> polybound0 c \<and> polybound0 p"
    7.45 +  where
    7.46 +    "polybound0 (C c) \<longleftrightarrow> True"
    7.47 +  | "polybound0 (Bound n) \<longleftrightarrow> n > 0"
    7.48 +  | "polybound0 (Neg a) \<longleftrightarrow> polybound0 a"
    7.49 +  | "polybound0 (Add a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.50 +  | "polybound0 (Sub a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.51 +  | "polybound0 (Mul a b) \<longleftrightarrow> polybound0 a \<and> polybound0 b"
    7.52 +  | "polybound0 (Pw p n) \<longleftrightarrow> polybound0 p"
    7.53 +  | "polybound0 (CN c n p) \<longleftrightarrow> n \<noteq> 0 \<and> polybound0 c \<and> polybound0 p"
    7.54  
    7.55  primrec polysubst0:: "poly \<Rightarrow> poly \<Rightarrow> poly" \<comment> \<open>substitute a poly into a poly for Bound 0\<close>
    7.56 -where
    7.57 -  "polysubst0 t (C c) = C c"
    7.58 -| "polysubst0 t (Bound n) = (if n = 0 then t else Bound n)"
    7.59 -| "polysubst0 t (Neg a) = Neg (polysubst0 t a)"
    7.60 -| "polysubst0 t (Add a b) = Add (polysubst0 t a) (polysubst0 t b)"
    7.61 -| "polysubst0 t (Sub a b) = Sub (polysubst0 t a) (polysubst0 t b)"
    7.62 -| "polysubst0 t (Mul a b) = Mul (polysubst0 t a) (polysubst0 t b)"
    7.63 -| "polysubst0 t (Pw p n) = Pw (polysubst0 t p) n"
    7.64 -| "polysubst0 t (CN c n p) =
    7.65 -    (if n = 0 then Add (polysubst0 t c) (Mul t (polysubst0 t p))
    7.66 -     else CN (polysubst0 t c) n (polysubst0 t p))"
    7.67 +  where
    7.68 +    "polysubst0 t (C c) = C c"
    7.69 +  | "polysubst0 t (Bound n) = (if n = 0 then t else Bound n)"
    7.70 +  | "polysubst0 t (Neg a) = Neg (polysubst0 t a)"
    7.71 +  | "polysubst0 t (Add a b) = Add (polysubst0 t a) (polysubst0 t b)"
    7.72 +  | "polysubst0 t (Sub a b) = Sub (polysubst0 t a) (polysubst0 t b)"
    7.73 +  | "polysubst0 t (Mul a b) = Mul (polysubst0 t a) (polysubst0 t b)"
    7.74 +  | "polysubst0 t (Pw p n) = Pw (polysubst0 t p) n"
    7.75 +  | "polysubst0 t (CN c n p) =
    7.76 +      (if n = 0 then Add (polysubst0 t c) (Mul t (polysubst0 t p))
    7.77 +       else CN (polysubst0 t c) n (polysubst0 t p))"
    7.78  
    7.79  fun decrpoly:: "poly \<Rightarrow> poly"
    7.80 -where
    7.81 -  "decrpoly (Bound n) = Bound (n - 1)"
    7.82 -| "decrpoly (Neg a) = Neg (decrpoly a)"
    7.83 -| "decrpoly (Add a b) = Add (decrpoly a) (decrpoly b)"
    7.84 -| "decrpoly (Sub a b) = Sub (decrpoly a) (decrpoly b)"
    7.85 -| "decrpoly (Mul a b) = Mul (decrpoly a) (decrpoly b)"
    7.86 -| "decrpoly (Pw p n) = Pw (decrpoly p) n"
    7.87 -| "decrpoly (CN c n p) = CN (decrpoly c) (n - 1) (decrpoly p)"
    7.88 -| "decrpoly a = a"
    7.89 +  where
    7.90 +    "decrpoly (Bound n) = Bound (n - 1)"
    7.91 +  | "decrpoly (Neg a) = Neg (decrpoly a)"
    7.92 +  | "decrpoly (Add a b) = Add (decrpoly a) (decrpoly b)"
    7.93 +  | "decrpoly (Sub a b) = Sub (decrpoly a) (decrpoly b)"
    7.94 +  | "decrpoly (Mul a b) = Mul (decrpoly a) (decrpoly b)"
    7.95 +  | "decrpoly (Pw p n) = Pw (decrpoly p) n"
    7.96 +  | "decrpoly (CN c n p) = CN (decrpoly c) (n - 1) (decrpoly p)"
    7.97 +  | "decrpoly a = a"
    7.98  
    7.99  
   7.100  subsection \<open>Degrees and heads and coefficients\<close>
   7.101  
   7.102  fun degree :: "poly \<Rightarrow> nat"
   7.103 -where
   7.104 -  "degree (CN c 0 p) = 1 + degree p"
   7.105 -| "degree p = 0"
   7.106 +  where
   7.107 +    "degree (CN c 0 p) = 1 + degree p"
   7.108 +  | "degree p = 0"
   7.109  
   7.110  fun head :: "poly \<Rightarrow> poly"
   7.111 -where
   7.112 -  "head (CN c 0 p) = head p"
   7.113 -| "head p = p"
   7.114 +  where
   7.115 +    "head (CN c 0 p) = head p"
   7.116 +  | "head p = p"
   7.117  
   7.118  text \<open>More general notions of degree and head.\<close>
   7.119  
   7.120  fun degreen :: "poly \<Rightarrow> nat \<Rightarrow> nat"
   7.121 -where
   7.122 -  "degreen (CN c n p) = (\<lambda>m. if n = m then 1 + degreen p n else 0)"
   7.123 -| "degreen p = (\<lambda>m. 0)"
   7.124 +  where
   7.125 +    "degreen (CN c n p) = (\<lambda>m. if n = m then 1 + degreen p n else 0)"
   7.126 +  | "degreen p = (\<lambda>m. 0)"
   7.127  
   7.128  fun headn :: "poly \<Rightarrow> nat \<Rightarrow> poly"
   7.129 -where
   7.130 -  "headn (CN c n p) = (\<lambda>m. if n \<le> m then headn p m else CN c n p)"
   7.131 -| "headn p = (\<lambda>m. p)"
   7.132 +  where
   7.133 +    "headn (CN c n p) = (\<lambda>m. if n \<le> m then headn p m else CN c n p)"
   7.134 +  | "headn p = (\<lambda>m. p)"
   7.135  
   7.136  fun coefficients :: "poly \<Rightarrow> poly list"
   7.137 -where
   7.138 -  "coefficients (CN c 0 p) = c # coefficients p"
   7.139 -| "coefficients p = [p]"
   7.140 +  where
   7.141 +    "coefficients (CN c 0 p) = c # coefficients p"
   7.142 +  | "coefficients p = [p]"
   7.143  
   7.144  fun isconstant :: "poly \<Rightarrow> bool"
   7.145 -where
   7.146 -  "isconstant (CN c 0 p) = False"
   7.147 -| "isconstant p = True"
   7.148 +  where
   7.149 +    "isconstant (CN c 0 p) = False"
   7.150 +  | "isconstant p = True"
   7.151  
   7.152  fun behead :: "poly \<Rightarrow> poly"
   7.153 -where
   7.154 -  "behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')"
   7.155 -| "behead p = 0\<^sub>p"
   7.156 +  where
   7.157 +    "behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')"
   7.158 +  | "behead p = 0\<^sub>p"
   7.159  
   7.160  fun headconst :: "poly \<Rightarrow> Num"
   7.161 -where
   7.162 -  "headconst (CN c n p) = headconst p"
   7.163 -| "headconst (C n) = n"
   7.164 +  where
   7.165 +    "headconst (CN c n p) = headconst p"
   7.166 +  | "headconst (C n) = n"
   7.167  
   7.168  
   7.169  subsection \<open>Operations for normalization\<close>
   7.170 @@ -116,70 +116,69 @@
   7.171  declare if_cong[fundef_cong del]
   7.172  declare let_cong[fundef_cong del]
   7.173  
   7.174 -fun polyadd :: "poly \<Rightarrow> poly \<Rightarrow> poly" (infixl "+\<^sub>p" 60)
   7.175 -where
   7.176 -  "polyadd (C c) (C c') = C (c +\<^sub>N c')"
   7.177 -| "polyadd (C c) (CN c' n' p') = CN (polyadd (C c) c') n' p'"
   7.178 -| "polyadd (CN c n p) (C c') = CN (polyadd c (C c')) n p"
   7.179 -| "polyadd (CN c n p) (CN c' n' p') =
   7.180 -    (if n < n' then CN (polyadd c (CN c' n' p')) n p
   7.181 -     else if n' < n then CN (polyadd (CN c n p) c') n' p'
   7.182 -     else
   7.183 -      let
   7.184 -        cc' = polyadd c c';
   7.185 -        pp' = polyadd p p'
   7.186 -      in if pp' = 0\<^sub>p then cc' else CN cc' n pp')"
   7.187 -| "polyadd a b = Add a b"
   7.188 -
   7.189 +fun polyadd :: "poly \<Rightarrow> poly \<Rightarrow> poly"  (infixl "+\<^sub>p" 60)
   7.190 +  where
   7.191 +    "polyadd (C c) (C c') = C (c +\<^sub>N c')"
   7.192 +  | "polyadd (C c) (CN c' n' p') = CN (polyadd (C c) c') n' p'"
   7.193 +  | "polyadd (CN c n p) (C c') = CN (polyadd c (C c')) n p"
   7.194 +  | "polyadd (CN c n p) (CN c' n' p') =
   7.195 +      (if n < n' then CN (polyadd c (CN c' n' p')) n p
   7.196 +       else if n' < n then CN (polyadd (CN c n p) c') n' p'
   7.197 +       else
   7.198 +        let
   7.199 +          cc' = polyadd c c';
   7.200 +          pp' = polyadd p p'
   7.201 +        in if pp' = 0\<^sub>p then cc' else CN cc' n pp')"
   7.202 +  | "polyadd a b = Add a b"
   7.203  
   7.204  fun polyneg :: "poly \<Rightarrow> poly" ("~\<^sub>p")
   7.205 -where
   7.206 -  "polyneg (C c) = C (~\<^sub>N c)"
   7.207 -| "polyneg (CN c n p) = CN (polyneg c) n (polyneg p)"
   7.208 -| "polyneg a = Neg a"
   7.209 +  where
   7.210 +    "polyneg (C c) = C (~\<^sub>N c)"
   7.211 +  | "polyneg (CN c n p) = CN (polyneg c) n (polyneg p)"
   7.212 +  | "polyneg a = Neg a"
   7.213  
   7.214 -definition polysub :: "poly \<Rightarrow> poly \<Rightarrow> poly" (infixl "-\<^sub>p" 60)
   7.215 +definition polysub :: "poly \<Rightarrow> poly \<Rightarrow> poly"  (infixl "-\<^sub>p" 60)
   7.216    where "p -\<^sub>p q = polyadd p (polyneg q)"
   7.217  
   7.218 -fun polymul :: "poly \<Rightarrow> poly \<Rightarrow> poly" (infixl "*\<^sub>p" 60)
   7.219 -where
   7.220 -  "polymul (C c) (C c') = C (c *\<^sub>N c')"
   7.221 -| "polymul (C c) (CN c' n' p') =
   7.222 -    (if c = 0\<^sub>N then 0\<^sub>p else CN (polymul (C c) c') n' (polymul (C c) p'))"
   7.223 -| "polymul (CN c n p) (C c') =
   7.224 -    (if c' = 0\<^sub>N  then 0\<^sub>p else CN (polymul c (C c')) n (polymul p (C c')))"
   7.225 -| "polymul (CN c n p) (CN c' n' p') =
   7.226 -    (if n < n' then CN (polymul c (CN c' n' p')) n (polymul p (CN c' n' p'))
   7.227 -     else if n' < n then CN (polymul (CN c n p) c') n' (polymul (CN c n p) p')
   7.228 -     else polyadd (polymul (CN c n p) c') (CN 0\<^sub>p n' (polymul (CN c n p) p')))"
   7.229 -| "polymul a b = Mul a b"
   7.230 +fun polymul :: "poly \<Rightarrow> poly \<Rightarrow> poly"  (infixl "*\<^sub>p" 60)
   7.231 +  where
   7.232 +    "polymul (C c) (C c') = C (c *\<^sub>N c')"
   7.233 +  | "polymul (C c) (CN c' n' p') =
   7.234 +      (if c = 0\<^sub>N then 0\<^sub>p else CN (polymul (C c) c') n' (polymul (C c) p'))"
   7.235 +  | "polymul (CN c n p) (C c') =
   7.236 +      (if c' = 0\<^sub>N  then 0\<^sub>p else CN (polymul c (C c')) n (polymul p (C c')))"
   7.237 +  | "polymul (CN c n p) (CN c' n' p') =
   7.238 +      (if n < n' then CN (polymul c (CN c' n' p')) n (polymul p (CN c' n' p'))
   7.239 +       else if n' < n then CN (polymul (CN c n p) c') n' (polymul (CN c n p) p')
   7.240 +       else polyadd (polymul (CN c n p) c') (CN 0\<^sub>p n' (polymul (CN c n p) p')))"
   7.241 +  | "polymul a b = Mul a b"
   7.242  
   7.243  declare if_cong[fundef_cong]
   7.244  declare let_cong[fundef_cong]
   7.245  
   7.246  fun polypow :: "nat \<Rightarrow> poly \<Rightarrow> poly"
   7.247 -where
   7.248 -  "polypow 0 = (\<lambda>p. (1)\<^sub>p)"
   7.249 -| "polypow n =
   7.250 -    (\<lambda>p.
   7.251 -      let
   7.252 -        q = polypow (n div 2) p;
   7.253 -        d = polymul q q
   7.254 -      in if even n then d else polymul p d)"
   7.255 +  where
   7.256 +    "polypow 0 = (\<lambda>p. (1)\<^sub>p)"
   7.257 +  | "polypow n =
   7.258 +      (\<lambda>p.
   7.259 +        let
   7.260 +          q = polypow (n div 2) p;
   7.261 +          d = polymul q q
   7.262 +        in if even n then d else polymul p d)"
   7.263  
   7.264 -abbreviation poly_pow :: "poly \<Rightarrow> nat \<Rightarrow> poly" (infixl "^\<^sub>p" 60)
   7.265 +abbreviation poly_pow :: "poly \<Rightarrow> nat \<Rightarrow> poly"  (infixl "^\<^sub>p" 60)
   7.266    where "a ^\<^sub>p k \<equiv> polypow k a"
   7.267  
   7.268  function polynate :: "poly \<Rightarrow> poly"
   7.269 -where
   7.270 -  "polynate (Bound n) = CN 0\<^sub>p n (1)\<^sub>p"
   7.271 -| "polynate (Add p q) = polynate p +\<^sub>p polynate q"
   7.272 -| "polynate (Sub p q) = polynate p -\<^sub>p polynate q"
   7.273 -| "polynate (Mul p q) = polynate p *\<^sub>p polynate q"
   7.274 -| "polynate (Neg p) = ~\<^sub>p (polynate p)"
   7.275 -| "polynate (Pw p n) = polynate p ^\<^sub>p n"
   7.276 -| "polynate (CN c n p) = polynate (Add c (Mul (Bound n) p))"
   7.277 -| "polynate (C c) = C (normNum c)"
   7.278 +  where
   7.279 +    "polynate (Bound n) = CN 0\<^sub>p n (1)\<^sub>p"
   7.280 +  | "polynate (Add p q) = polynate p +\<^sub>p polynate q"
   7.281 +  | "polynate (Sub p q) = polynate p -\<^sub>p polynate q"
   7.282 +  | "polynate (Mul p q) = polynate p *\<^sub>p polynate q"
   7.283 +  | "polynate (Neg p) = ~\<^sub>p (polynate p)"
   7.284 +  | "polynate (Pw p n) = polynate p ^\<^sub>p n"
   7.285 +  | "polynate (CN c n p) = polynate (Add c (Mul (Bound n) p))"
   7.286 +  | "polynate (C c) = C (normNum c)"
   7.287    by pat_completeness auto
   7.288  termination by (relation "measure polysize") auto
   7.289  
   7.290 @@ -190,8 +189,7 @@
   7.291  | "poly_cmul y p = C y *\<^sub>p p"
   7.292  
   7.293  definition monic :: "poly \<Rightarrow> poly \<times> bool"
   7.294 -where
   7.295 -  "monic p =
   7.296 +  where "monic p =
   7.297      (let h = headconst p
   7.298       in if h = 0\<^sub>N then (p, False) else (C (Ninv h) *\<^sub>p p, 0>\<^sub>N h))"
   7.299  
   7.300 @@ -224,28 +222,28 @@
   7.301    where "polydivide s p = polydivide_aux (head p) (degree p) p 0 s"
   7.302  
   7.303  fun poly_deriv_aux :: "nat \<Rightarrow> poly \<Rightarrow> poly"
   7.304 -where
   7.305 -  "poly_deriv_aux n (CN c 0 p) = CN (poly_cmul ((int n)\<^sub>N) c) 0 (poly_deriv_aux (n + 1) p)"
   7.306 -| "poly_deriv_aux n p = poly_cmul ((int n)\<^sub>N) p"
   7.307 +  where
   7.308 +    "poly_deriv_aux n (CN c 0 p) = CN (poly_cmul ((int n)\<^sub>N) c) 0 (poly_deriv_aux (n + 1) p)"
   7.309 +  | "poly_deriv_aux n p = poly_cmul ((int n)\<^sub>N) p"
   7.310  
   7.311  fun poly_deriv :: "poly \<Rightarrow> poly"
   7.312 -where
   7.313 -  "poly_deriv (CN c 0 p) = poly_deriv_aux 1 p"
   7.314 -| "poly_deriv p = 0\<^sub>p"
   7.315 +  where
   7.316 +    "poly_deriv (CN c 0 p) = poly_deriv_aux 1 p"
   7.317 +  | "poly_deriv p = 0\<^sub>p"
   7.318  
   7.319  
   7.320  subsection \<open>Semantics of the polynomial representation\<close>
   7.321  
   7.322  primrec Ipoly :: "'a list \<Rightarrow> poly \<Rightarrow> 'a::{field_char_0,field,power}"
   7.323 -where
   7.324 -  "Ipoly bs (C c) = INum c"
   7.325 -| "Ipoly bs (Bound n) = bs!n"
   7.326 -| "Ipoly bs (Neg a) = - Ipoly bs a"
   7.327 -| "Ipoly bs (Add a b) = Ipoly bs a + Ipoly bs b"
   7.328 -| "Ipoly bs (Sub a b) = Ipoly bs a - Ipoly bs b"
   7.329 -| "Ipoly bs (Mul a b) = Ipoly bs a * Ipoly bs b"
   7.330 -| "Ipoly bs (Pw t n) = Ipoly bs t ^ n"
   7.331 -| "Ipoly bs (CN c n p) = Ipoly bs c + (bs!n) * Ipoly bs p"
   7.332 +  where
   7.333 +    "Ipoly bs (C c) = INum c"
   7.334 +  | "Ipoly bs (Bound n) = bs!n"
   7.335 +  | "Ipoly bs (Neg a) = - Ipoly bs a"
   7.336 +  | "Ipoly bs (Add a b) = Ipoly bs a + Ipoly bs b"
   7.337 +  | "Ipoly bs (Sub a b) = Ipoly bs a - Ipoly bs b"
   7.338 +  | "Ipoly bs (Mul a b) = Ipoly bs a * Ipoly bs b"
   7.339 +  | "Ipoly bs (Pw t n) = Ipoly bs t ^ n"
   7.340 +  | "Ipoly bs (CN c n p) = Ipoly bs c + (bs!n) * Ipoly bs p"
   7.341  
   7.342  abbreviation Ipoly_syntax :: "poly \<Rightarrow> 'a list \<Rightarrow>'a::{field_char_0,field,power}"  ("\<lparr>_\<rparr>\<^sub>p\<^bsup>_\<^esup>")
   7.343    where "\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<equiv> Ipoly bs p"
   7.344 @@ -262,10 +260,10 @@
   7.345  subsection \<open>Normal form and normalization\<close>
   7.346  
   7.347  fun isnpolyh:: "poly \<Rightarrow> nat \<Rightarrow> bool"
   7.348 -where
   7.349 -  "isnpolyh (C c) = (\<lambda>k. isnormNum c)"
   7.350 -| "isnpolyh (CN c n p) = (\<lambda>k. n \<ge> k \<and> isnpolyh c (Suc n) \<and> isnpolyh p n \<and> p \<noteq> 0\<^sub>p)"
   7.351 -| "isnpolyh p = (\<lambda>k. False)"
   7.352 +  where
   7.353 +    "isnpolyh (C c) = (\<lambda>k. isnormNum c)"
   7.354 +  | "isnpolyh (CN c n p) = (\<lambda>k. n \<ge> k \<and> isnpolyh c (Suc n) \<and> isnpolyh p n \<and> p \<noteq> 0\<^sub>p)"
   7.355 +  | "isnpolyh p = (\<lambda>k. False)"
   7.356  
   7.357  lemma isnpolyh_mono: "n' \<le> n \<Longrightarrow> isnpolyh p n \<Longrightarrow> isnpolyh p n'"
   7.358    by (induct p rule: isnpolyh.induct) auto
   7.359 @@ -512,23 +510,22 @@
   7.360        and nn0: "n \<ge> n0"
   7.361        and nn1: "n' \<ge> n1"
   7.362        by simp_all
   7.363 -    {
   7.364 -      assume "n < n'"
   7.365 +    consider "n < n'" | "n' < n" | "n' = n" by arith
   7.366 +    then show ?case
   7.367 +    proof cases
   7.368 +      case 1
   7.369        with "4.hyps"(4-5)[OF np cnp', of n] and "4.hyps"(1)[OF nc cnp', of n] nn0 cnp
   7.370 -      have ?case by (simp add: min_def)
   7.371 -    } moreover {
   7.372 -      assume "n' < n"
   7.373 +      show ?thesis by (simp add: min_def)
   7.374 +    next
   7.375 +      case 2
   7.376        with "4.hyps"(16-17)[OF cnp np', of "n'"] and "4.hyps"(13)[OF cnp nc', of "Suc n'"] nn1 cnp'
   7.377 -      have ?case by (cases "Suc n' = n") (simp_all add: min_def)
   7.378 -    } moreover {
   7.379 -      assume "n' = n"
   7.380 +      show ?thesis by (cases "Suc n' = n") (simp_all add: min_def)
   7.381 +    next
   7.382 +      case 3
   7.383        with "4.hyps"(16-17)[OF cnp np', of n] and "4.hyps"(13)[OF cnp nc', of n] cnp cnp' nn1 nn0
   7.384 -      have ?case
   7.385 -        apply (auto intro!: polyadd_normh)
   7.386 -        apply (simp_all add: min_def isnpolyh_mono[OF nn0])
   7.387 -        done
   7.388 -    }
   7.389 -    ultimately show ?case by arith
   7.390 +      show ?thesis
   7.391 +        by (auto intro!: polyadd_normh) (simp_all add: min_def isnpolyh_mono[OF nn0])
   7.392 +    qed
   7.393    next
   7.394      fix n0 n1 m
   7.395      assume np: "isnpolyh ?cnp n0"
   7.396 @@ -538,16 +535,14 @@
   7.397      let ?d1 = "degreen ?cnp m"
   7.398      let ?d2 = "degreen ?cnp' m"
   7.399      let ?eq = "?d = (if ?cnp = 0\<^sub>p \<or> ?cnp' = 0\<^sub>p then 0  else ?d1 + ?d2)"
   7.400 -    have "n' < n \<or> n < n' \<or> n' = n" by auto
   7.401 -    moreover
   7.402 -    {
   7.403 -      assume "n' < n \<or> n < n'"
   7.404 -      with "4.hyps"(3,6,18) np np' m have ?eq
   7.405 -        by auto
   7.406 -    }
   7.407 -    moreover
   7.408 -    {
   7.409 -      assume nn': "n' = n"
   7.410 +    consider "n' < n \<or> n < n'" | "n' = n" by linarith
   7.411 +    then show ?eq
   7.412 +    proof cases
   7.413 +      case 1
   7.414 +      with "4.hyps"(3,6,18) np np' m show ?thesis by auto
   7.415 +    next
   7.416 +      case 2
   7.417 +      have nn': "n' = n" by fact
   7.418        then have nn: "\<not> n' < n \<and> \<not> n < n'" by arith
   7.419        from "4.hyps"(16,18)[of n n' n]
   7.420          "4.hyps"(13,14)[of n "Suc n'" n]
   7.421 @@ -562,8 +557,9 @@
   7.422          "?cnp *\<^sub>p c' = 0\<^sub>p \<longleftrightarrow> c' = 0\<^sub>p"
   7.423          "?cnp *\<^sub>p p' \<noteq> 0\<^sub>p"
   7.424          by (auto simp add: min_def)
   7.425 -      {
   7.426 -        assume mn: "m = n"
   7.427 +      show ?thesis
   7.428 +      proof (cases "m = n")
   7.429 +        case mn: True
   7.430          from "4.hyps"(17,18)[OF norm(1,4), of n]
   7.431            "4.hyps"(13,15)[OF norm(1,2), of n] norm nn' mn
   7.432          have degs:
   7.433 @@ -583,11 +579,9 @@
   7.434          from "4.hyps"(16-18)[OF norm(1,4), of n]
   7.435            "4.hyps"(13-15)[OF norm(1,2), of n]
   7.436            mn norm m nn' deg
   7.437 -        have ?eq by simp
   7.438 -      }
   7.439 -      moreover
   7.440 -      {
   7.441 -        assume mn: "m \<noteq> n"
   7.442 +        show ?thesis by simp
   7.443 +      next
   7.444 +        case mn: False
   7.445          then have mn': "m < n"
   7.446            using m np by auto
   7.447          from nn' m np have max1: "m \<le> max n n"
   7.448 @@ -605,11 +599,10 @@
   7.449          with "4.hyps"(16-18)[OF norm(1,4) min1]
   7.450            "4.hyps"(13-15)[OF norm(1,2) min2]
   7.451            degreen_0[OF norm(3) mn']
   7.452 -        have ?eq using nn' mn np np' by clarsimp
   7.453 -      }
   7.454 -      ultimately have ?eq by blast
   7.455 -    }
   7.456 -    ultimately show ?eq by blast
   7.457 +          nn' mn np np'
   7.458 +        show ?thesis by clarsimp
   7.459 +      qed
   7.460 +    qed
   7.461    }
   7.462    {
   7.463      case (2 n0 n1)
   7.464 @@ -619,9 +612,9 @@
   7.465        by simp_all
   7.466      then have mn: "m \<le> n" by simp
   7.467      let ?c0p = "CN 0\<^sub>p n (?cnp *\<^sub>p p')"
   7.468 -    {
   7.469 -      assume C: "?cnp *\<^sub>p c' +\<^sub>p ?c0p = 0\<^sub>p" "n' = n"
   7.470 -      then have nn: "\<not> n' < n \<and> \<not> n < n'"
   7.471 +    have False if C: "?cnp *\<^sub>p c' +\<^sub>p ?c0p = 0\<^sub>p" "n' = n"
   7.472 +    proof -
   7.473 +      from C have nn: "\<not> n' < n \<and> \<not> n < n'"
   7.474          by simp
   7.475        from "4.hyps"(16-18) [of n n n]
   7.476          "4.hyps"(13-15)[of n "Suc n" n]
   7.477 @@ -643,8 +636,8 @@
   7.478        have degneq: "degreen (?cnp *\<^sub>p c') n < degreen (CN 0\<^sub>p n (?cnp *\<^sub>p p')) n"
   7.479          using norm by simp
   7.480        from polyadd_eq_const_degreen[OF norm(3) cn C(1), where m="n"] degneq
   7.481 -      have False by simp
   7.482 -    }
   7.483 +      show ?thesis by simp
   7.484 +    qed
   7.485      then show ?case using "4.hyps" by clarsimp
   7.486    }
   7.487  qed auto
   7.488 @@ -747,22 +740,19 @@
   7.489  
   7.490  text \<open>polypow is a power function and preserves normal forms\<close>
   7.491  
   7.492 -lemma polypow[simp]:
   7.493 -  "Ipoly bs (polypow n p) = (Ipoly bs p :: 'a::{field_char_0,field}) ^ n"
   7.494 +lemma polypow[simp]: "Ipoly bs (polypow n p) = (Ipoly bs p :: 'a::{field_char_0,field}) ^ n"
   7.495  proof (induct n rule: polypow.induct)
   7.496    case 1
   7.497 -  then show ?case
   7.498 -    by simp
   7.499 +  then show ?case by simp
   7.500  next
   7.501    case (2 n)
   7.502    let ?q = "polypow ((Suc n) div 2) p"
   7.503    let ?d = "polymul ?q ?q"
   7.504 -  have "odd (Suc n) \<or> even (Suc n)"
   7.505 -    by simp
   7.506 -  moreover
   7.507 -  {
   7.508 -    assume odd: "odd (Suc n)"
   7.509 -    have th: "(Suc (Suc (Suc 0) * (Suc n div Suc (Suc 0)))) = Suc n div 2 + Suc n div 2 + 1"
   7.510 +  consider "odd (Suc n)" | "even (Suc n)" by auto
   7.511 +  then show ?case
   7.512 +  proof cases
   7.513 +    case odd: 1
   7.514 +    have *: "(Suc (Suc (Suc 0) * (Suc n div Suc (Suc 0)))) = Suc n div 2 + Suc n div 2 + 1"
   7.515        by arith
   7.516      from odd have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs (polymul p ?d)"
   7.517        by (simp add: Let_def)
   7.518 @@ -771,21 +761,19 @@
   7.519      also have "\<dots> = (Ipoly bs p) ^ (Suc n div 2 + Suc n div 2 + 1)"
   7.520        by (simp only: power_add power_one_right) simp
   7.521      also have "\<dots> = (Ipoly bs p) ^ (Suc (Suc (Suc 0) * (Suc n div Suc (Suc 0))))"
   7.522 -      by (simp only: th)
   7.523 -    finally have ?case unfolding numeral_2_eq_2 [symmetric]
   7.524 -    using odd_two_times_div_two_nat [OF odd] by simp
   7.525 -  }
   7.526 -  moreover
   7.527 -  {
   7.528 -    assume even: "even (Suc n)"
   7.529 +      by (simp only: *)
   7.530 +    finally show ?thesis
   7.531 +      unfolding numeral_2_eq_2 [symmetric]
   7.532 +      using odd_two_times_div_two_nat [OF odd] by simp
   7.533 +  next
   7.534 +    case even: 2
   7.535      from even have "Ipoly bs (p ^\<^sub>p Suc n) = Ipoly bs ?d"
   7.536        by (simp add: Let_def)
   7.537      also have "\<dots> = (Ipoly bs p) ^ (2 * (Suc n div 2))"
   7.538        using "2.hyps" by (simp only: mult_2 power_add) simp
   7.539 -    finally have ?case using even_two_times_div_two [OF even]
   7.540 -      by simp
   7.541 -  }
   7.542 -  ultimately show ?case by blast
   7.543 +    finally show ?thesis
   7.544 +      using even_two_times_div_two [OF even] by simp
   7.545 +  qed
   7.546  qed
   7.547  
   7.548  lemma polypow_normh:
   7.549 @@ -798,14 +786,13 @@
   7.550    case (2 k n)
   7.551    let ?q = "polypow (Suc k div 2) p"
   7.552    let ?d = "polymul ?q ?q"
   7.553 -  from 2 have th1: "isnpolyh ?q n" and th2: "isnpolyh p n"
   7.554 +  from 2 have *: "isnpolyh ?q n" and **: "isnpolyh p n"
   7.555      by blast+
   7.556 -  from polymul_normh[OF th1 th1] have dn: "isnpolyh ?d n"
   7.557 +  from polymul_normh[OF * *] have dn: "isnpolyh ?d n"
   7.558      by simp
   7.559 -  from polymul_normh[OF th2 dn] have on: "isnpolyh (polymul p ?d) n"
   7.560 +  from polymul_normh[OF ** dn] have on: "isnpolyh (polymul p ?d) n"
   7.561      by simp
   7.562    from dn on show ?case by (simp, unfold Let_def) auto
   7.563 -    
   7.564  qed
   7.565  
   7.566  lemma polypow_norm:
   7.567 @@ -815,8 +802,7 @@
   7.568  
   7.569  text \<open>Finally the whole normalization\<close>
   7.570  
   7.571 -lemma polynate [simp]:
   7.572 -  "Ipoly bs (polynate p) = (Ipoly bs p :: 'a ::{field_char_0,field})"
   7.573 +lemma polynate [simp]: "Ipoly bs (polynate p) = (Ipoly bs p :: 'a ::{field_char_0,field})"
   7.574    by (induct p rule:polynate.induct) auto
   7.575  
   7.576  lemma polynate_norm[simp]:
   7.577 @@ -828,7 +814,6 @@
   7.578  
   7.579  text \<open>shift1\<close>
   7.580  
   7.581 -
   7.582  lemma shift1: "Ipoly bs (shift1 p) = Ipoly bs (Mul (Bound 0) p)"
   7.583    by (simp add: shift1_def)
   7.584  
   7.585 @@ -909,7 +894,7 @@
   7.586  
   7.587  lemma decrpoly_normh: "isnpolyh p n0 \<Longrightarrow> polybound0 p \<Longrightarrow> isnpolyh (decrpoly p) (n0 - 1)"
   7.588    apply (induct p arbitrary: n0)
   7.589 -  apply auto
   7.590 +         apply auto
   7.591    apply atomize
   7.592    apply (rename_tac nat a b, erule_tac x = "Suc nat" in allE)
   7.593    apply auto
   7.594 @@ -945,15 +930,15 @@
   7.595    by (induct p arbitrary: n rule: degree.induct) (auto simp add: isnpolyh_polybound0)
   7.596  
   7.597  primrec maxindex :: "poly \<Rightarrow> nat"
   7.598 -where
   7.599 -  "maxindex (Bound n) = n + 1"
   7.600 -| "maxindex (CN c n p) = max  (n + 1) (max (maxindex c) (maxindex p))"
   7.601 -| "maxindex (Add p q) = max (maxindex p) (maxindex q)"
   7.602 -| "maxindex (Sub p q) = max (maxindex p) (maxindex q)"
   7.603 -| "maxindex (Mul p q) = max (maxindex p) (maxindex q)"
   7.604 -| "maxindex (Neg p) = maxindex p"
   7.605 -| "maxindex (Pw p n) = maxindex p"
   7.606 -| "maxindex (C x) = 0"
   7.607 +  where
   7.608 +    "maxindex (Bound n) = n + 1"
   7.609 +  | "maxindex (CN c n p) = max  (n + 1) (max (maxindex c) (maxindex p))"
   7.610 +  | "maxindex (Add p q) = max (maxindex p) (maxindex q)"
   7.611 +  | "maxindex (Sub p q) = max (maxindex p) (maxindex q)"
   7.612 +  | "maxindex (Mul p q) = max (maxindex p) (maxindex q)"
   7.613 +  | "maxindex (Neg p) = maxindex p"
   7.614 +  | "maxindex (Pw p n) = maxindex p"
   7.615 +  | "maxindex (C x) = 0"
   7.616  
   7.617  definition wf_bs :: "'a list \<Rightarrow> poly \<Rightarrow> bool"
   7.618    where "wf_bs bs p \<longleftrightarrow> length bs \<ge> maxindex p"
   7.619 @@ -964,25 +949,21 @@
   7.620    show ?case
   7.621    proof
   7.622      fix x
   7.623 -    assume xc: "x \<in> set (coefficients (CN c 0 p))"
   7.624 -    then have "x = c \<or> x \<in> set (coefficients p)"
   7.625 -      by simp
   7.626 -    moreover
   7.627 -    {
   7.628 -      assume "x = c"
   7.629 -      then have "wf_bs bs x"
   7.630 -        using "1.prems" unfolding wf_bs_def by simp
   7.631 -    }
   7.632 -    moreover
   7.633 -    {
   7.634 -      assume H: "x \<in> set (coefficients p)"
   7.635 +    assume "x \<in> set (coefficients (CN c 0 p))"
   7.636 +    then consider "x = c" | "x \<in> set (coefficients p)"
   7.637 +      by auto
   7.638 +    then show "wf_bs bs x"
   7.639 +    proof cases
   7.640 +      case prems: 1
   7.641 +      then show ?thesis
   7.642 +        using "1.prems" by (simp add: wf_bs_def)
   7.643 +    next
   7.644 +      case prems: 2
   7.645        from "1.prems" have "wf_bs bs p"
   7.646 -        unfolding wf_bs_def by simp
   7.647 -      with "1.hyps" H have "wf_bs bs x"
   7.648 +        by (simp add: wf_bs_def)
   7.649 +      with "1.hyps" prems show ?thesis
   7.650          by blast
   7.651 -    }
   7.652 -    ultimately show "wf_bs bs x"
   7.653 -      by blast
   7.654 +    qed
   7.655    qed
   7.656  qed simp_all
   7.657  
   7.658 @@ -990,7 +971,7 @@
   7.659    by (induct p rule: coefficients.induct) auto
   7.660  
   7.661  lemma wf_bs_I: "wf_bs bs p \<Longrightarrow> Ipoly (bs @ bs') p = Ipoly bs p"
   7.662 -  unfolding wf_bs_def by (induct p) (auto simp add: nth_append)
   7.663 +  by (induct p) (auto simp add: nth_append wf_bs_def)
   7.664  
   7.665  lemma take_maxindex_wf:
   7.666    assumes wf: "wf_bs bs p"
   7.667 @@ -1012,10 +993,10 @@
   7.668    by (induct p) auto
   7.669  
   7.670  lemma wf_bs_insensitive: "length bs = length bs' \<Longrightarrow> wf_bs bs p = wf_bs bs' p"
   7.671 -  unfolding wf_bs_def by simp
   7.672 +  by (simp add: wf_bs_def)
   7.673  
   7.674  lemma wf_bs_insensitive': "wf_bs (x # bs) p = wf_bs (y # bs) p"
   7.675 -  unfolding wf_bs_def by simp
   7.676 +  by (simp add: wf_bs_def)
   7.677  
   7.678  lemma wf_bs_coefficients': "\<forall>c \<in> set (coefficients p). wf_bs bs c \<Longrightarrow> wf_bs (x # bs) p"
   7.679    by (induct p rule: coefficients.induct) (auto simp add: wf_bs_def)
   7.680 @@ -1030,31 +1011,28 @@
   7.681    unfolding wf_bs_def by (induct p rule: decrpoly.induct) auto
   7.682  
   7.683  lemma length_le_list_ex: "length xs \<le> n \<Longrightarrow> \<exists>ys. length (xs @ ys) = n"
   7.684 -  apply (rule exI[where x="replicate (n - length xs) z" for z])
   7.685 -  apply simp
   7.686 -  done
   7.687 +  by (rule exI[where x="replicate (n - length xs) z" for z]) simp
   7.688  
   7.689  lemma isnpolyh_Suc_const: "isnpolyh p (Suc n) \<Longrightarrow> isconstant p"
   7.690    apply (cases p)
   7.691 -  apply auto
   7.692 +         apply auto
   7.693    apply (rename_tac nat a, case_tac "nat")
   7.694 -  apply simp_all
   7.695 +   apply simp_all
   7.696    done
   7.697  
   7.698  lemma wf_bs_polyadd: "wf_bs bs p \<and> wf_bs bs q \<longrightarrow> wf_bs bs (p +\<^sub>p q)"
   7.699 -  unfolding wf_bs_def by (induct p q rule: polyadd.induct) (auto simp add: Let_def)
   7.700 +  by (induct p q rule: polyadd.induct) (auto simp add: Let_def wf_bs_def)
   7.701  
   7.702  lemma wf_bs_polyul: "wf_bs bs p \<Longrightarrow> wf_bs bs q \<Longrightarrow> wf_bs bs (p *\<^sub>p q)"
   7.703 -  unfolding wf_bs_def
   7.704    apply (induct p q arbitrary: bs rule: polymul.induct)
   7.705 -  apply (simp_all add: wf_bs_polyadd)
   7.706 +                      apply (simp_all add: wf_bs_polyadd wf_bs_def)
   7.707    apply clarsimp
   7.708    apply (rule wf_bs_polyadd[unfolded wf_bs_def, rule_format])
   7.709    apply auto
   7.710    done
   7.711  
   7.712  lemma wf_bs_polyneg: "wf_bs bs p \<Longrightarrow> wf_bs bs (~\<^sub>p p)"
   7.713 -  unfolding wf_bs_def by (induct p rule: polyneg.induct) auto
   7.714 +  by (induct p rule: polyneg.induct) (auto simp: wf_bs_def)
   7.715  
   7.716  lemma wf_bs_polysub: "wf_bs bs p \<Longrightarrow> wf_bs bs q \<Longrightarrow> wf_bs bs (p -\<^sub>p q)"
   7.717    unfolding polysub_def split_def fst_conv snd_conv
   7.718 @@ -1087,16 +1065,15 @@
   7.719  proof -
   7.720    let ?cf = "set (coefficients p)"
   7.721    from coefficients_normh[OF np] have cn_norm: "\<forall> q\<in> ?cf. isnpolyh q n0" .
   7.722 -  {
   7.723 -    fix q
   7.724 -    assume q: "q \<in> ?cf"
   7.725 -    from q cn_norm have th: "isnpolyh q n0"
   7.726 +  have "polybound0 q" if "q \<in> ?cf" for q
   7.727 +  proof -
   7.728 +    from that cn_norm have *: "isnpolyh q n0"
   7.729        by blast
   7.730 -    from coefficients_isconst[OF np] q have "isconstant q"
   7.731 +    from coefficients_isconst[OF np] that have "isconstant q"
   7.732        by blast
   7.733 -    with isconstant_polybound0[OF th] have "polybound0 q"
   7.734 +    with isconstant_polybound0[OF *] show ?thesis
   7.735        by blast
   7.736 -  }
   7.737 +  qed
   7.738    then have "\<forall>q \<in> ?cf. polybound0 q" ..
   7.739    then have "\<forall>q \<in> ?cf. Ipoly (x # bs) q = Ipoly bs (decrpoly q)"
   7.740      using polybound0_I[where b=x and bs=bs and b'=y] decrpoly[where x=x and bs=bs]
   7.741 @@ -1124,9 +1101,9 @@
   7.742    using assms
   7.743    unfolding polypoly_def
   7.744    apply (cases p)
   7.745 -  apply auto
   7.746 +         apply auto
   7.747    apply (rename_tac nat a, case_tac nat)
   7.748 -  apply auto
   7.749 +   apply auto
   7.750    done
   7.751  
   7.752  lemma head_isnpolyh: "isnpolyh p n0 \<Longrightarrow> isnpolyh (head p) n0"
   7.753 @@ -1149,16 +1126,13 @@
   7.754  proof (induct "maxindex p" arbitrary: p n0 rule: less_induct)
   7.755    case less
   7.756    note np = \<open>isnpolyh p n0\<close> and zp = \<open>\<forall>bs. wf_bs bs p \<longrightarrow> \<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)\<close>
   7.757 -  {
   7.758 -    assume nz: "maxindex p = 0"
   7.759 -    then obtain c where "p = C c"
   7.760 -      using np by (cases p) auto
   7.761 -    with zp np have "p = 0\<^sub>p"
   7.762 -      unfolding wf_bs_def by simp
   7.763 -  }
   7.764 -  moreover
   7.765 -  {
   7.766 -    assume nz: "maxindex p \<noteq> 0"
   7.767 +  show "p = 0\<^sub>p"
   7.768 +  proof (cases "maxindex p = 0")
   7.769 +    case True
   7.770 +    with np obtain c where "p = C c" by (cases p) auto
   7.771 +    with zp np show ?thesis by (simp add: wf_bs_def)
   7.772 +  next
   7.773 +    case nz: False
   7.774      let ?h = "head p"
   7.775      let ?hd = "decrpoly ?h"
   7.776      let ?ihd = "maxindex ?hd"
   7.777 @@ -1173,13 +1147,13 @@
   7.778        by auto
   7.779      with decr_maxindex[OF h(2)] nz have ihd_lt_n: "?ihd < maxindex p"
   7.780        by auto
   7.781 -    {
   7.782 -      fix bs :: "'a list"
   7.783 -      assume bs: "wf_bs bs ?hd"
   7.784 +
   7.785 +    have "\<lparr>?hd\<rparr>\<^sub>p\<^bsup>bs\<^esup> = 0" if bs: "wf_bs bs ?hd" for bs :: "'a list"
   7.786 +    proof -
   7.787        let ?ts = "take ?ihd bs"
   7.788        let ?rs = "drop ?ihd bs"
   7.789 -      have ts: "wf_bs ?ts ?hd"
   7.790 -        using bs unfolding wf_bs_def by simp
   7.791 +      from bs have ts: "wf_bs ?ts ?hd"
   7.792 +        by (simp add: wf_bs_def)
   7.793        have bs_ts_eq: "?ts @ ?rs = bs"
   7.794          by simp
   7.795        from wf_bs_decrpoly[OF ts] have tsh: " \<forall>x. wf_bs (x # ?ts) ?h"
   7.796 @@ -1189,7 +1163,7 @@
   7.797        with length_le_list_ex obtain xs where xs: "length ((x # ?ts) @ xs) = maxindex p"
   7.798          by blast
   7.799        then have "\<forall>x. wf_bs ((x # ?ts) @ xs) p"
   7.800 -        unfolding wf_bs_def by simp
   7.801 +        by (simp add: wf_bs_def)
   7.802        with zp have "\<forall>x. Ipoly ((x # ?ts) @ xs) p = 0"
   7.803          by blast
   7.804        then have "\<forall>x. Ipoly (x # (?ts @ xs)) p = 0"
   7.805 @@ -1202,24 +1176,22 @@
   7.806        then have "\<forall>c \<in> set (coefficients p). Ipoly (?ts @ xs) (decrpoly c) = 0"
   7.807          using poly_zero[where ?'a='a] by (simp add: polypoly'_def)
   7.808        with coefficients_head[of p, symmetric]
   7.809 -      have th0: "Ipoly (?ts @ xs) ?hd = 0"
   7.810 +      have *: "Ipoly (?ts @ xs) ?hd = 0"
   7.811          by simp
   7.812        from bs have wf'': "wf_bs ?ts ?hd"
   7.813 -        unfolding wf_bs_def by simp
   7.814 -      with th0 wf_bs_I[of ?ts ?hd xs] have "Ipoly ?ts ?hd = 0"
   7.815 +        by (simp add: wf_bs_def)
   7.816 +      with * wf_bs_I[of ?ts ?hd xs] have "Ipoly ?ts ?hd = 0"
   7.817          by simp
   7.818 -      with wf'' wf_bs_I[of ?ts ?hd ?rs] bs_ts_eq have "\<lparr>?hd\<rparr>\<^sub>p\<^bsup>bs\<^esup> = 0"
   7.819 +      with wf'' wf_bs_I[of ?ts ?hd ?rs] bs_ts_eq show ?thesis
   7.820          by simp
   7.821 -    }
   7.822 +    qed
   7.823      then have hdz: "\<forall>bs. wf_bs bs ?hd \<longrightarrow> \<lparr>?hd\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)"
   7.824        by blast
   7.825      from less(1)[OF ihd_lt_n nhd] hdz have "?hd = 0\<^sub>p"
   7.826        by blast
   7.827      then have "?h = 0\<^sub>p" by simp
   7.828 -    with head_nz[OF np] have "p = 0\<^sub>p" by simp
   7.829 -  }
   7.830 -  ultimately show "p = 0\<^sub>p"
   7.831 -    by blast
   7.832 +    with head_nz[OF np] show ?thesis by simp
   7.833 +  qed
   7.834  qed
   7.835  
   7.836  lemma isnpolyh_unique:
   7.837 @@ -1227,7 +1199,7 @@
   7.838      and nq: "isnpolyh q n1"
   7.839    shows "(\<forall>bs. \<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (\<lparr>q\<rparr>\<^sub>p\<^bsup>bs\<^esup> :: 'a::{field_char_0,field,power})) \<longleftrightarrow> p = q"
   7.840  proof auto
   7.841 -  assume H: "\<forall>bs. (\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> ::'a) = \<lparr>q\<rparr>\<^sub>p\<^bsup>bs\<^esup>"
   7.842 +  assume "\<forall>bs. (\<lparr>p\<rparr>\<^sub>p\<^bsup>bs\<^esup> ::'a) = \<lparr>q\<rparr>\<^sub>p\<^bsup>bs\<^esup>"
   7.843    then have "\<forall>bs.\<lparr>p -\<^sub>p q\<rparr>\<^sub>p\<^bsup>bs\<^esup>= (0::'a)"
   7.844      by simp
   7.845    then have "\<forall>bs. wf_bs bs (p -\<^sub>p q) \<longrightarrow> \<lparr>p -\<^sub>p q\<rparr>\<^sub>p\<^bsup>bs\<^esup> = (0::'a)"
   7.846 @@ -1237,7 +1209,7 @@
   7.847  qed
   7.848  
   7.849  
   7.850 -text \<open>consequences of unicity on the algorithms for polynomial normalization\<close>
   7.851 +text \<open>Consequences of unicity on the algorithms for polynomial normalization.\<close>
   7.852  
   7.853  lemma polyadd_commute:
   7.854    assumes "SORT_CONSTRAINT('a::{field_char_0,field})"
   7.855 @@ -1311,7 +1283,7 @@
   7.856    unfolding poly_nate_polypoly' by auto
   7.857  
   7.858  
   7.859 -subsection \<open>heads, degrees and all that\<close>
   7.860 +subsection \<open>Heads, degrees and all that\<close>
   7.861  
   7.862  lemma degree_eq_degreen0: "degree p = degreen p 0"
   7.863    by (induct p rule: degree.induct) simp_all
   7.864 @@ -1321,9 +1293,9 @@
   7.865    shows "degree (polyneg p) = degree p"
   7.866    apply (induct p rule: polyneg.induct)
   7.867    using assms
   7.868 -  apply simp_all
   7.869 +         apply simp_all
   7.870    apply (case_tac na)
   7.871 -  apply auto
   7.872 +   apply auto
   7.873    done
   7.874  
   7.875  lemma degree_polyadd:
   7.876 @@ -1395,50 +1367,43 @@
   7.877      by simp
   7.878    from H have pnh: "isnpolyh p n" and p'nh: "isnpolyh p' n'"
   7.879      by auto
   7.880 -  have "n = n' \<or> n < n' \<or> n > n'"
   7.881 +  consider "n = n'" | "n < n'" | "n > n'"
   7.882      by arith
   7.883 -  moreover
   7.884 -  {
   7.885 -    assume nn': "n = n'"
   7.886 -    have "n = 0 \<or> n > 0" by arith
   7.887 -    moreover
   7.888 -    {
   7.889 -      assume nz: "n = 0"
   7.890 -      then have ?case using 4 nn'
   7.891 +  then show ?case
   7.892 +  proof cases
   7.893 +    case nn': 1
   7.894 +    consider "n = 0" | "n > 0" by arith
   7.895 +    then show ?thesis
   7.896 +    proof cases
   7.897 +      case 1
   7.898 +      with 4 nn' show ?thesis
   7.899          by (auto simp add: Let_def degcmc')
   7.900 -    }
   7.901 -    moreover
   7.902 -    {
   7.903 -      assume nz: "n > 0"
   7.904 -      with nn' H(3) have  cc': "c = c'" and pp': "p = p'"
   7.905 -        by (cases n, auto)+
   7.906 -      then have ?case
   7.907 +    next
   7.908 +      case 2
   7.909 +      with nn' H(3) have "c = c'" and "p = p'"
   7.910 +        by (cases n; auto)+
   7.911 +      with nn' 4 show ?thesis
   7.912          using polysub_same_0[OF p'nh, simplified polysub_def split_def fst_conv snd_conv]
   7.913          using polysub_same_0[OF c'nh, simplified polysub_def]
   7.914 -        using nn' 4 by (simp add: Let_def)
   7.915 -    }
   7.916 -    ultimately have ?case by blast
   7.917 -  }
   7.918 -  moreover
   7.919 -  {
   7.920 -    assume nn': "n < n'"
   7.921 +        by (simp add: Let_def)
   7.922 +    qed
   7.923 +  next
   7.924 +    case nn': 2
   7.925      then have n'p: "n' > 0"
   7.926        by simp
   7.927      then have headcnp':"head (CN c' n' p') = CN c' n' p'"
   7.928        by (cases n') simp_all
   7.929 -    have degcnp': "degree (CN c' n' p') = 0"
   7.930 +    with 4 nn' have degcnp': "degree (CN c' n' p') = 0"
   7.931        and degcnpeq: "degree (CN c n p) = degree (CN c' n' p')"
   7.932 -      using 4 nn' by (cases n', simp_all)
   7.933 +      by (cases n', simp_all)
   7.934      then have "n > 0"
   7.935        by (cases n) simp_all
   7.936      then have headcnp: "head (CN c n p) = CN c n p"
   7.937        by (cases n) auto
   7.938 -    from H(3) headcnp headcnp' nn' have ?case
   7.939 +    from H(3) headcnp headcnp' nn' show ?thesis
   7.940        by auto
   7.941 -  }
   7.942 -  moreover
   7.943 -  {
   7.944 -    assume nn': "n > n'"
   7.945 +  next
   7.946 +    case nn': 3
   7.947      then have np: "n > 0" by simp
   7.948      then have headcnp:"head (CN c n p) = CN c n p"
   7.949        by (cases n) simp_all
   7.950 @@ -1450,15 +1415,14 @@
   7.951        by (cases n') simp_all
   7.952      then have headcnp': "head (CN c' n' p') = CN c' n' p'"
   7.953        by (cases n') auto
   7.954 -    from H(3) headcnp headcnp' nn' have ?case by auto
   7.955 -  }
   7.956 -  ultimately show ?case by blast
   7.957 +    from H(3) headcnp headcnp' nn' show ?thesis by auto
   7.958 +  qed
   7.959  qed auto
   7.960  
   7.961  lemma shift1_head : "isnpolyh p n0 \<Longrightarrow> head (shift1 p) = head p"
   7.962    by (induct p arbitrary: n0 rule: head.induct) (simp_all add: shift1_def)
   7.963  
   7.964 -lemma funpow_shift1_head: "isnpolyh p n0 \<Longrightarrow> p\<noteq> 0\<^sub>p \<Longrightarrow> head (funpow k shift1 p) = head p"
   7.965 +lemma funpow_shift1_head: "isnpolyh p n0 \<Longrightarrow> p \<noteq> 0\<^sub>p \<Longrightarrow> head (funpow k shift1 p) = head p"
   7.966  proof (induct k arbitrary: n0 p)
   7.967    case 0
   7.968    then show ?case
   7.969 @@ -1503,13 +1467,13 @@
   7.970    shows "head (p +\<^sub>p q) = (if degree p < degree q then head q else head p)"
   7.971    using np nq deg
   7.972    apply (induct p q arbitrary: n0 n1 rule: polyadd.induct)
   7.973 -  apply simp_all
   7.974 -  apply (case_tac n', simp, simp)
   7.975 -  apply (case_tac n, simp, simp)
   7.976 +                      apply simp_all
   7.977 +    apply (case_tac n', simp, simp)
   7.978 +   apply (case_tac n, simp, simp)
   7.979    apply (case_tac n, case_tac n', simp add: Let_def)
   7.980 -  apply (auto simp add: polyadd_eq_const_degree)[2]
   7.981 -  apply (metis head_nz)
   7.982 -  apply (metis head_nz)
   7.983 +    apply (auto simp add: polyadd_eq_const_degree)[2]
   7.984 +    apply (metis head_nz)
   7.985 +   apply (metis head_nz)
   7.986    apply (metis degree.simps(9) gr0_conv_Suc head.simps(1) less_Suc0 not_less_eq)
   7.987    done
   7.988  
   7.989 @@ -1533,67 +1497,61 @@
   7.990    then have norm: "isnpolyh p n" "isnpolyh c (Suc n)" "isnpolyh p' n'" "isnpolyh c' (Suc n')"
   7.991      "isnpolyh (CN c n p) n" "isnpolyh (CN c' n' p') n'"
   7.992      by simp_all
   7.993 -  have "n < n' \<or> n' < n \<or> n = n'" by arith
   7.994 -  moreover
   7.995 -  {
   7.996 -    assume nn': "n < n'"
   7.997 -    then have ?case
   7.998 +  consider "n < n'" | "n' < n" | "n' = n" by arith
   7.999 +  then show ?case
  7.1000 +  proof cases
  7.1001 +    case nn': 1
  7.1002 +    then show ?thesis
  7.1003        using norm "4.hyps"(2)[OF norm(1,6)] "4.hyps"(1)[OF norm(2,6)]
  7.1004        apply simp
  7.1005        apply (cases n)
  7.1006 -      apply simp
  7.1007 +       apply simp
  7.1008        apply (cases n')
  7.1009 -      apply simp_all
  7.1010 +       apply simp_all
  7.1011        done
  7.1012 -  }
  7.1013 -  moreover {
  7.1014 -    assume nn': "n'< n"
  7.1015 -    then have ?case
  7.1016 +  next
  7.1017 +    case nn': 2
  7.1018 +    then show ?thesis
  7.1019        using norm "4.hyps"(6) [OF norm(5,3)] "4.hyps"(5)[OF norm(5,4)]
  7.1020        apply simp
  7.1021        apply (cases n')
  7.1022 -      apply simp
  7.1023 +       apply simp
  7.1024        apply (cases n)
  7.1025 -      apply auto
  7.1026 +       apply auto
  7.1027        done
  7.1028 -  }
  7.1029 -  moreover
  7.1030 -  {
  7.1031 -    assume nn': "n' = n"
  7.1032 +  next
  7.1033 +    case nn': 3
  7.1034      from nn' polymul_normh[OF norm(5,4)]
  7.1035 -    have ncnpc':"isnpolyh (CN c n p *\<^sub>p c') n" by (simp add: min_def)
  7.1036 +    have ncnpc': "isnpolyh (CN c n p *\<^sub>p c') n" by (simp add: min_def)
  7.1037      from nn' polymul_normh[OF norm(5,3)] norm
  7.1038 -    have ncnpp':"isnpolyh (CN c n p *\<^sub>p p') n" by simp
  7.1039 +    have ncnpp': "isnpolyh (CN c n p *\<^sub>p p') n" by simp
  7.1040      from nn' ncnpp' polymul_eq0_iff[OF norm(5,3)] norm(6)
  7.1041 -    have ncnpp0':"isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp
  7.1042 +    have ncnpp0': "isnpolyh (CN 0\<^sub>p n (CN c n p *\<^sub>p p')) n" by simp
  7.1043      from polyadd_normh[OF ncnpc' ncnpp0']
  7.1044      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"
  7.1045        by (simp add: min_def)
  7.1046 -    {
  7.1047 -      assume np: "n > 0"
  7.1048 +    consider "n > 0" | "n = 0" by auto
  7.1049 +    then show ?thesis
  7.1050 +    proof cases
  7.1051 +      case np: 1
  7.1052        with nn' head_isnpolyh_Suc'[OF np nth]
  7.1053          head_isnpolyh_Suc'[OF np norm(5)] head_isnpolyh_Suc'[OF np norm(6)[simplified nn']]
  7.1054 -      have ?case by simp
  7.1055 -    }
  7.1056 -    moreover
  7.1057 -    {
  7.1058 -      assume nz: "n = 0"
  7.1059 +      show ?thesis by simp
  7.1060 +    next
  7.1061 +      case nz: 2
  7.1062        from polymul_degreen[OF norm(5,4), where m="0"]
  7.1063          polymul_degreen[OF norm(5,3), where m="0"] nn' nz degree_eq_degreen0
  7.1064 -      norm(5,6) degree_npolyhCN[OF norm(6)]
  7.1065 -    have dth: "degree (CN c 0 p *\<^sub>p c') < degree (CN 0\<^sub>p 0 (CN c 0 p *\<^sub>p p'))"
  7.1066 -      by simp
  7.1067 -    then have dth': "degree (CN c 0 p *\<^sub>p c') \<noteq> degree (CN 0\<^sub>p 0 (CN c 0 p *\<^sub>p p'))"
  7.1068 -      by simp
  7.1069 -    from polyadd_head[OF ncnpc'[simplified nz] ncnpp0'[simplified nz] dth'] dth
  7.1070 -    have ?case
  7.1071 -      using norm "4.hyps"(6)[OF norm(5,3)] "4.hyps"(5)[OF norm(5,4)] nn' nz
  7.1072 -      by simp
  7.1073 -    }
  7.1074 -    ultimately have ?case
  7.1075 -      by (cases n) auto
  7.1076 -  }
  7.1077 -  ultimately show ?case by blast
  7.1078 +        norm(5,6) degree_npolyhCN[OF norm(6)]
  7.1079 +      have dth: "degree (CN c 0 p *\<^sub>p c') < degree (CN 0\<^sub>p 0 (CN c 0 p *\<^sub>p p'))"
  7.1080 +        by simp
  7.1081 +      then have dth': "degree (CN c 0 p *\<^sub>p c') \<noteq> degree (CN 0\<^sub>p 0 (CN c 0 p *\<^sub>p p'))"
  7.1082 +        by simp
  7.1083 +      from polyadd_head[OF ncnpc'[simplified nz] ncnpp0'[simplified nz] dth'] dth
  7.1084 +      show ?thesis
  7.1085 +        using norm "4.hyps"(6)[OF norm(5,3)] "4.hyps"(5)[OF norm(5,4)] nn' nz
  7.1086 +        by simp
  7.1087 +    qed
  7.1088 +  qed
  7.1089  qed simp_all
  7.1090  
  7.1091  lemma degree_coefficients: "degree p = length (coefficients p) - 1"
  7.1092 @@ -1663,52 +1621,50 @@
  7.1093      by (simp add: isnpoly_def)
  7.1094    from polypow_normh [OF head_isnpolyh[OF np0], where k="k' - k"] ap
  7.1095    have nakk':"isnpolyh ?akk' 0" by blast
  7.1096 -  {
  7.1097 -    assume sz: "s = 0\<^sub>p"
  7.1098 -    then have ?ths
  7.1099 -      using np polydivide_aux.simps
  7.1100 -      apply clarsimp
  7.1101 +  show ?ths
  7.1102 +  proof (cases "s = 0\<^sub>p")
  7.1103 +    case True
  7.1104 +    with np show ?thesis
  7.1105 +      apply (clarsimp simp: polydivide_aux.simps)
  7.1106        apply (rule exI[where x="0\<^sub>p"])
  7.1107        apply simp
  7.1108        done
  7.1109 -  }
  7.1110 -  moreover
  7.1111 -  {
  7.1112 -    assume sz: "s \<noteq> 0\<^sub>p"
  7.1113 -    {
  7.1114 -      assume dn: "degree s < n"
  7.1115 -      then have "?ths"
  7.1116 +  next
  7.1117 +    case sz: False
  7.1118 +    show ?thesis
  7.1119 +    proof (cases "degree s < n")
  7.1120 +      case True
  7.1121 +      then show ?thesis
  7.1122          using ns ndp np polydivide_aux.simps
  7.1123          apply auto
  7.1124          apply (rule exI[where x="0\<^sub>p"])
  7.1125          apply simp
  7.1126          done
  7.1127 -    }
  7.1128 -    moreover
  7.1129 -    {
  7.1130 -      assume dn': "\<not> degree s < n"
  7.1131 +    next
  7.1132 +      case dn': False
  7.1133        then have dn: "degree s \<ge> n"
  7.1134          by arith
  7.1135        have degsp': "degree s = degree ?p'"
  7.1136          using dn ndp funpow_shift1_degree[where k = "degree s - n" and p="p"]
  7.1137          by simp
  7.1138 -      {
  7.1139 -        assume ba: "?b = a"
  7.1140 +      show ?thesis
  7.1141 +      proof (cases "?b = a")
  7.1142 +        case ba: True
  7.1143          then have headsp': "head s = head ?p'"
  7.1144            using ap headp' by simp
  7.1145          have nr: "isnpolyh (s -\<^sub>p ?p') 0"
  7.1146            using polysub_normh[OF ns np'] by simp
  7.1147          from degree_polysub_samehead[OF ns np' headsp' degsp']
  7.1148 -        have "degree (s -\<^sub>p ?p') < degree s \<or> s -\<^sub>p ?p' = 0\<^sub>p"
  7.1149 -          by simp
  7.1150 -        moreover
  7.1151 -        {
  7.1152 -          assume deglt:"degree (s -\<^sub>p ?p') < degree s"
  7.1153 +        consider "degree (s -\<^sub>p ?p') < degree s" | "s -\<^sub>p ?p' = 0\<^sub>p" by auto
  7.1154 +        then show ?thesis
  7.1155 +        proof cases
  7.1156 +          case deglt: 1
  7.1157            from polydivide_aux.simps sz dn' ba
  7.1158            have eq: "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  7.1159              by (simp add: Let_def)
  7.1160 -          {
  7.1161 -            assume h1: "polydivide_aux a n p k s = (k', r)"
  7.1162 +          have "k \<le> k' \<and> (degree r = 0 \<or> degree r < degree p) \<and> (\<exists>nr. isnpolyh r nr) \<and> ?qths"
  7.1163 +            if h1: "polydivide_aux a n p k s = (k', r)"
  7.1164 +          proof -
  7.1165              from less(1)[OF deglt nr, of k k' r] trans[OF eq[symmetric] h1]
  7.1166              have kk': "k \<le> k'"
  7.1167                and nr: "\<exists>nr. isnpolyh r nr"
  7.1168 @@ -1753,54 +1709,45 @@
  7.1169              have "a ^\<^sub>p (k' - k) *\<^sub>p s =
  7.1170                p *\<^sub>p ((a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q) +\<^sub>p r"
  7.1171                by blast
  7.1172 -            then have ?qths using nq'
  7.1173 +            with nq' have ?qths
  7.1174                apply (rule_tac x="(a^\<^sub>p (k' - k)) *\<^sub>p (funpow (degree s - n) shift1 (1)\<^sub>p) +\<^sub>p q" in exI)
  7.1175                apply (rule_tac x="0" in exI)
  7.1176                apply simp
  7.1177                done
  7.1178 -            with kk' nr dr have "k \<le> k' \<and> (degree r = 0 \<or> degree r < degree p) \<and>
  7.1179 -              (\<exists>nr. isnpolyh r nr) \<and> ?qths"
  7.1180 +            with kk' nr dr show ?thesis
  7.1181                by blast
  7.1182 -          }
  7.1183 -          then have ?ths by blast
  7.1184 -        }
  7.1185 -        moreover
  7.1186 -        {
  7.1187 -          assume spz:"s -\<^sub>p ?p' = 0\<^sub>p"
  7.1188 +          qed
  7.1189 +          then show ?thesis by blast
  7.1190 +        next
  7.1191 +          case spz: 2
  7.1192            from spz isnpolyh_unique[OF polysub_normh[OF ns np'], where q="0\<^sub>p", symmetric, where ?'a = "'a::{field_char_0,field}"]
  7.1193            have "\<forall>bs:: 'a::{field_char_0,field} list. Ipoly bs s = Ipoly bs ?p'"
  7.1194              by simp
  7.1195 -          then have "\<forall>bs:: 'a::{field_char_0,field} list. Ipoly bs s = Ipoly bs (?xdn *\<^sub>p p)"
  7.1196 -            using np nxdn
  7.1197 -            apply simp
  7.1198 -            apply (simp only: funpow_shift1_1)
  7.1199 -            apply simp
  7.1200 -            done
  7.1201 +          with np nxdn have "\<forall>bs:: 'a::{field_char_0,field} list. Ipoly bs s = Ipoly bs (?xdn *\<^sub>p p)"
  7.1202 +            by (simp only: funpow_shift1_1) simp
  7.1203            then have sp': "s = ?xdn *\<^sub>p p"
  7.1204              using isnpolyh_unique[OF ns polymul_normh[OF nxdn np]]
  7.1205              by blast
  7.1206 -          {
  7.1207 -            assume h1: "polydivide_aux a n p k s = (k', r)"
  7.1208 -            from polydivide_aux.simps sz dn' ba
  7.1209 -            have eq: "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  7.1210 -              by (simp add: Let_def)
  7.1211 +          have ?thesis if h1: "polydivide_aux a n p k s = (k', r)"
  7.1212 +          proof -
  7.1213 +            from sz dn' ba
  7.1214 +            have "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  7.1215 +              by (simp add: Let_def polydivide_aux.simps)
  7.1216              also have "\<dots> = (k,0\<^sub>p)"
  7.1217 -              using polydivide_aux.simps spz by simp
  7.1218 +              using spz by (simp add: polydivide_aux.simps)
  7.1219              finally have "(k', r) = (k, 0\<^sub>p)"
  7.1220 -              using h1 by simp
  7.1221 +              by (simp add: h1)
  7.1222              with sp'[symmetric] ns np nxdn polyadd_0(1)[OF polymul_normh[OF np nxdn]]
  7.1223 -              polyadd_0(2)[OF polymul_normh[OF np nxdn]] have ?ths
  7.1224 +              polyadd_0(2)[OF polymul_normh[OF np nxdn]] show ?thesis
  7.1225                apply auto
  7.1226                apply (rule exI[where x="?xdn"])
  7.1227                apply (auto simp add: polymul_commute[of p])
  7.1228                done
  7.1229 -          }
  7.1230 -        }
  7.1231 -        ultimately have ?ths by blast
  7.1232 -      }
  7.1233 -      moreover
  7.1234 -      {
  7.1235 -        assume ba: "?b \<noteq> a"
  7.1236 +          qed
  7.1237 +          then show ?thesis by blast
  7.1238 +        qed
  7.1239 +      next
  7.1240 +        case ba: False
  7.1241          from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np0, simplified ap] ns]
  7.1242            polymul_normh[OF head_isnpolyh[OF ns] np']]
  7.1243          have nth: "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0"
  7.1244 @@ -1811,7 +1758,8 @@
  7.1245              funpow_shift1_nz[OF pnz]
  7.1246            by simp_all
  7.1247          from polymul_head_polyeq[OF head_isnpolyh[OF np] ns] head_nz[OF np] sz ap head_head[OF np] pnz
  7.1248 -          polymul_head_polyeq[OF head_isnpolyh[OF ns] np'] head_nz [OF ns] sz funpow_shift1_nz[OF pnz, where n="degree s - n"]
  7.1249 +          polymul_head_polyeq[OF head_isnpolyh[OF ns] np'] head_nz [OF ns] sz
  7.1250 +          funpow_shift1_nz[OF pnz, where n="degree s - n"]
  7.1251          have hdth: "head (a *\<^sub>p s) = head (?b *\<^sub>p ?p')"
  7.1252            using head_head[OF ns] funpow_shift1_head[OF np pnz]
  7.1253              polymul_commute[OF head_isnpolyh[OF np] head_isnpolyh[OF ns]]
  7.1254 @@ -1823,14 +1771,22 @@
  7.1255            ndp dn
  7.1256          have degth: "degree (a *\<^sub>p s) = degree (?b *\<^sub>p ?p')"
  7.1257            by (simp add: degree_eq_degreen0[symmetric] funpow_shift1_degree)
  7.1258 -        {
  7.1259 -          assume dth: "degree ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) < degree s"
  7.1260 +
  7.1261 +        consider "degree ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) < degree s" | "a *\<^sub>p s -\<^sub>p (?b *\<^sub>p ?p') = 0\<^sub>p"
  7.1262 +          using degree_polysub_samehead[OF polymul_normh[OF head_isnpolyh[OF np0, simplified ap] ns]
  7.1263 +            polymul_normh[OF head_isnpolyh[OF ns] np'] hdth degth]
  7.1264 +            polymul_degreen[OF head_isnpolyh[OF np] ns, where m="0"]
  7.1265 +            head_nz[OF np] pnz sz ap[symmetric]
  7.1266 +          by (auto simp add: degree_eq_degreen0[symmetric])
  7.1267 +        then show ?thesis
  7.1268 +        proof cases
  7.1269 +          case dth: 1
  7.1270            from polysub_normh[OF polymul_normh[OF head_isnpolyh[OF np] ns]
  7.1271              polymul_normh[OF head_isnpolyh[OF ns]np']] ap
  7.1272            have nasbp': "isnpolyh ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) 0"
  7.1273              by simp
  7.1274 -          {
  7.1275 -            assume h1:"polydivide_aux a n p k s = (k', r)"
  7.1276 +          have ?thesis if h1: "polydivide_aux a n p k s = (k', r)"
  7.1277 +          proof -
  7.1278              from h1 polydivide_aux.simps sz dn' ba
  7.1279              have eq:"polydivide_aux a n p (Suc k) ((a *\<^sub>p s) -\<^sub>p (?b *\<^sub>p ?p')) = (k',r)"
  7.1280                by (simp add: Let_def)
  7.1281 @@ -1843,8 +1799,10 @@
  7.1282                by auto
  7.1283              from kk' have kk'': "Suc (k' - Suc k) = k' - k"
  7.1284                by arith
  7.1285 -            {
  7.1286 -              fix bs :: "'a::{field_char_0,field} list"
  7.1287 +            have "Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  7.1288 +                Ipoly bs p * (Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn) + Ipoly bs r"
  7.1289 +              for bs :: "'a::{field_char_0,field} list"
  7.1290 +            proof -
  7.1291                from qr isnpolyh_unique[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k", simplified ap] nasbp', symmetric]
  7.1292                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)"
  7.1293                  by simp
  7.1294 @@ -1854,11 +1812,10 @@
  7.1295                then have "Ipoly bs a ^ (k' - k)  * Ipoly bs s =
  7.1296                  Ipoly bs p * Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn * Ipoly bs p + Ipoly bs r"
  7.1297                  by (simp add: kk'' funpow_shift1_1[where n="degree s - n" and p="p"])
  7.1298 -              then have "Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  7.1299 -                Ipoly bs p * (Ipoly bs q + Ipoly bs a ^ (k' - Suc k) * Ipoly bs ?b * Ipoly bs ?xdn) + Ipoly bs r"
  7.1300 +              then show ?thesis
  7.1301                  by (simp add: field_simps)
  7.1302 -            }
  7.1303 -            then have ieq:"\<forall>bs :: 'a::{field_char_0,field} list.
  7.1304 +            qed
  7.1305 +            then have ieq: "\<forall>bs :: 'a::{field_char_0,field} list.
  7.1306                  Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  7.1307                  Ipoly bs (p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r)"
  7.1308                by auto
  7.1309 @@ -1869,62 +1826,53 @@
  7.1310              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]]
  7.1311              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"
  7.1312                by blast
  7.1313 -            from dr kk' nr h1 asth nqw have ?ths
  7.1314 +            from dr kk' nr h1 asth nqw show ?thesis
  7.1315                apply simp
  7.1316                apply (rule conjI)
  7.1317                apply (rule exI[where x="nr"], simp)
  7.1318                apply (rule exI[where x="(q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn))"], simp)
  7.1319                apply (rule exI[where x="0"], simp)
  7.1320                done
  7.1321 -          }
  7.1322 -          then have ?ths by blast
  7.1323 -        }
  7.1324 -        moreover
  7.1325 -        {
  7.1326 -          assume spz: "a *\<^sub>p s -\<^sub>p (?b *\<^sub>p ?p') = 0\<^sub>p"
  7.1327 -          {
  7.1328 +          qed
  7.1329 +          then show ?thesis by blast
  7.1330 +        next
  7.1331 +          case spz: 2
  7.1332 +          have hth: "\<forall>bs :: 'a::{field_char_0,field} list.
  7.1333 +            Ipoly bs (a *\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))"
  7.1334 +          proof
  7.1335              fix bs :: "'a::{field_char_0,field} list"
  7.1336              from isnpolyh_unique[OF nth, where ?'a="'a" and q="0\<^sub>p",simplified,symmetric] spz
  7.1337              have "Ipoly bs (a*\<^sub>p s) = Ipoly bs ?b * Ipoly bs ?p'"
  7.1338                by simp
  7.1339              then have "Ipoly bs (a*\<^sub>p s) = Ipoly bs (?b *\<^sub>p ?xdn) * Ipoly bs p"
  7.1340                by (simp add: funpow_shift1_1[where n="degree s - n" and p="p"])
  7.1341 -            then have "Ipoly bs (a*\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))"
  7.1342 +            then show "Ipoly bs (a*\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))"
  7.1343                by simp
  7.1344 -          }
  7.1345 -          then have hth: "\<forall>bs :: 'a::{field_char_0,field} list.
  7.1346 -            Ipoly bs (a *\<^sub>p s) = Ipoly bs (p *\<^sub>p (?b *\<^sub>p ?xdn))" ..
  7.1347 +          qed
  7.1348            from hth have asq: "a *\<^sub>p s = p *\<^sub>p (?b *\<^sub>p ?xdn)"
  7.1349              using isnpolyh_unique[where ?'a = "'a::{field_char_0,field}", OF polymul_normh[OF head_isnpolyh[OF np] ns]
  7.1350                      polymul_normh[OF np polymul_normh[OF head_isnpolyh[OF ns] nxdn]],
  7.1351                simplified ap]
  7.1352              by simp
  7.1353 -          {
  7.1354 -            assume h1: "polydivide_aux a n p k s = (k', r)"
  7.1355 +          have ?ths if h1: "polydivide_aux a n p k s = (k', r)"
  7.1356 +          proof -
  7.1357              from h1 sz ba dn' spz polydivide_aux.simps polydivide_aux.simps
  7.1358              have "(k', r) = (Suc k, 0\<^sub>p)"
  7.1359                by (simp add: Let_def)
  7.1360              with h1 np head_isnpolyh[OF np, simplified ap] ns polymul_normh[OF head_isnpolyh[OF ns] nxdn]
  7.1361                polymul_normh[OF np polymul_normh[OF head_isnpolyh[OF ns] nxdn]] asq
  7.1362 -            have ?ths
  7.1363 +            show ?thesis
  7.1364                apply (clarsimp simp add: Let_def)
  7.1365                apply (rule exI[where x="?b *\<^sub>p ?xdn"])
  7.1366                apply simp
  7.1367                apply (rule exI[where x="0"], simp)
  7.1368                done
  7.1369 -          }
  7.1370 -          then have ?ths by blast
  7.1371 -        }
  7.1372 -        ultimately have ?ths
  7.1373 -          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"]
  7.1374 -            head_nz[OF np] pnz sz ap[symmetric]
  7.1375 -          by (auto simp add: degree_eq_degreen0[symmetric])
  7.1376 -      }
  7.1377 -      ultimately have ?ths by blast
  7.1378 -    }
  7.1379 -    ultimately have ?ths by blast
  7.1380 -  }
  7.1381 -  ultimately show ?ths by blast
  7.1382 +          qed
  7.1383 +          then show ?thesis by blast
  7.1384 +        qed
  7.1385 +      qed
  7.1386 +    qed
  7.1387 +  qed
  7.1388  qed
  7.1389  
  7.1390  lemma polydivide_properties:
  7.1391 @@ -1965,14 +1913,14 @@
  7.1392    shows "pnormal (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0"
  7.1393  proof
  7.1394    let ?p = "polypoly bs p"
  7.1395 -  assume H: "pnormal ?p"
  7.1396 -  have csz: "coefficients p \<noteq> []"
  7.1397 +  assume *: "pnormal ?p"
  7.1398 +  have "coefficients p \<noteq> []"
  7.1399      using assms by (cases p) auto
  7.1400 -  from coefficients_head[of p] last_map[OF csz, of "Ipoly bs"] pnormal_last_nonzero[OF H]
  7.1401 +  from coefficients_head[of p] last_map[OF this, of "Ipoly bs"] pnormal_last_nonzero[OF *]
  7.1402    show "Ipoly bs (head p) \<noteq> 0"
  7.1403      by (simp add: polypoly_def)
  7.1404  next
  7.1405 -  assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1406 +  assume *: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1407    let ?p = "polypoly bs p"
  7.1408    have csz: "coefficients p \<noteq> []"
  7.1409      using assms by (cases p) auto
  7.1410 @@ -1980,7 +1928,7 @@
  7.1411      by (simp add: polypoly_def)
  7.1412    then have lg: "length ?p > 0"
  7.1413      by simp
  7.1414 -  from h coefficients_head[of p] last_map[OF csz, of "Ipoly bs"]
  7.1415 +  from * coefficients_head[of p] last_map[OF csz, of "Ipoly bs"]
  7.1416    have lz: "last ?p \<noteq> 0"
  7.1417      by (simp add: polypoly_def)
  7.1418    from pnormal_last_length[OF lg lz] show "pnormal ?p" .
  7.1419 @@ -1999,73 +1947,71 @@
  7.1420    shows "nonconstant (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0"
  7.1421  proof
  7.1422    let ?p = "polypoly bs p"
  7.1423 -  assume nc: "nonconstant ?p"
  7.1424 -  from isnonconstant_pnormal_iff[OF assms, of bs] nc
  7.1425 -  show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1426 +  assume "nonconstant ?p"
  7.1427 +  with isnonconstant_pnormal_iff[OF assms, of bs] show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1428      unfolding nonconstant_def by blast
  7.1429  next
  7.1430    let ?p = "polypoly bs p"
  7.1431 -  assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1432 -  from isnonconstant_pnormal_iff[OF assms, of bs] h
  7.1433 -  have pn: "pnormal ?p"
  7.1434 +  assume "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1435 +  with isnonconstant_pnormal_iff[OF assms, of bs] have pn: "pnormal ?p"
  7.1436      by blast
  7.1437 -  {
  7.1438 -    fix x
  7.1439 -    assume H: "?p = [x]"
  7.1440 +  have False if H: "?p = [x]" for x
  7.1441 +  proof -
  7.1442      from H have "length (coefficients p) = 1"
  7.1443 -      unfolding polypoly_def by auto
  7.1444 +      by (auto simp: polypoly_def)
  7.1445      with isnonconstant_coefficients_length[OF assms]
  7.1446 -    have False by arith
  7.1447 -  }
  7.1448 +    show ?thesis by arith
  7.1449 +  qed
  7.1450    then show "nonconstant ?p"
  7.1451      using pn unfolding nonconstant_def by blast
  7.1452  qed
  7.1453  
  7.1454  lemma pnormal_length: "p \<noteq> [] \<Longrightarrow> pnormal p \<longleftrightarrow> length (pnormalize p) = length p"
  7.1455    apply (induct p)
  7.1456 -  apply (simp_all add: pnormal_def)
  7.1457 +   apply (simp_all add: pnormal_def)
  7.1458    apply (case_tac "p = []")
  7.1459 -  apply simp_all
  7.1460 +   apply simp_all
  7.1461    done
  7.1462  
  7.1463  lemma degree_degree:
  7.1464    assumes "isnonconstant p"
  7.1465    shows "degree p = Polynomial_List.degree (polypoly bs p) \<longleftrightarrow> \<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1466 +    (is "?lhs \<longleftrightarrow> ?rhs")
  7.1467  proof
  7.1468    let ?p = "polypoly bs p"
  7.1469 -  assume H: "degree p = Polynomial_List.degree ?p"
  7.1470 -  from isnonconstant_coefficients_length[OF assms] have pz: "?p \<noteq> []"
  7.1471 -    unfolding polypoly_def by auto
  7.1472 -  from H degree_coefficients[of p] isnonconstant_coefficients_length[OF assms]
  7.1473 -  have lg: "length (pnormalize ?p) = length ?p"
  7.1474 -    unfolding Polynomial_List.degree_def polypoly_def by simp
  7.1475 -  then have "pnormal ?p"
  7.1476 -    using pnormal_length[OF pz] by blast
  7.1477 -  with isnonconstant_pnormal_iff[OF assms] show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1478 -    by blast
  7.1479 -next
  7.1480 -  let ?p = "polypoly bs p"
  7.1481 -  assume H: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  7.1482 -  with isnonconstant_pnormal_iff[OF assms] have "pnormal ?p"
  7.1483 -    by blast
  7.1484 -  with degree_coefficients[of p] isnonconstant_coefficients_length[OF assms]
  7.1485 -  show "degree p = Polynomial_List.degree ?p"
  7.1486 -    unfolding polypoly_def pnormal_def Polynomial_List.degree_def by auto
  7.1487 +  {
  7.1488 +    assume ?lhs
  7.1489 +    from isnonconstant_coefficients_length[OF assms] have "?p \<noteq> []"
  7.1490 +      by (auto simp: polypoly_def)
  7.1491 +    from \<open>?lhs\<close> degree_coefficients[of p] isnonconstant_coefficients_length[OF assms]
  7.1492 +    have "length (pnormalize ?p) = length ?p"
  7.1493 +      by (simp add: Polynomial_List.degree_def polypoly_def)
  7.1494 +    with pnormal_length[OF \<open>?p \<noteq> []\<close>] have "pnormal ?p"
  7.1495 +      by blast
  7.1496 +    with isnonconstant_pnormal_iff[OF assms] show ?rhs
  7.1497 +      by blast
  7.1498 +  next
  7.1499 +    assume ?rhs
  7.1500 +    with isnonconstant_pnormal_iff[OF assms] have "pnormal ?p"
  7.1501 +      by blast
  7.1502 +    with degree_coefficients[of p] isnonconstant_coefficients_length[OF assms] show ?lhs
  7.1503 +      by (auto simp: polypoly_def pnormal_def Polynomial_List.degree_def)
  7.1504 +  }
  7.1505  qed
  7.1506  
  7.1507  
  7.1508 -section \<open>Swaps ; Division by a certain variable\<close>
  7.1509 +section \<open>Swaps -- division by a certain variable\<close>
  7.1510  
  7.1511  primrec swap :: "nat \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> poly"
  7.1512 -where
  7.1513 -  "swap n m (C x) = C x"
  7.1514 -| "swap n m (Bound k) = Bound (if k = n then m else if k = m then n else k)"
  7.1515 -| "swap n m (Neg t) = Neg (swap n m t)"
  7.1516 -| "swap n m (Add s t) = Add (swap n m s) (swap n m t)"
  7.1517 -| "swap n m (Sub s t) = Sub (swap n m s) (swap n m t)"
  7.1518 -| "swap n m (Mul s t) = Mul (swap n m s) (swap n m t)"
  7.1519 -| "swap n m (Pw t k) = Pw (swap n m t) k"
  7.1520 -| "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) (swap n m p)"
  7.1521 +  where
  7.1522 +    "swap n m (C x) = C x"
  7.1523 +  | "swap n m (Bound k) = Bound (if k = n then m else if k = m then n else k)"
  7.1524 +  | "swap n m (Neg t) = Neg (swap n m t)"
  7.1525 +  | "swap n m (Add s t) = Add (swap n m s) (swap n m t)"
  7.1526 +  | "swap n m (Sub s t) = Sub (swap n m s) (swap n m t)"
  7.1527 +  | "swap n m (Mul s t) = Mul (swap n m s) (swap n m t)"
  7.1528 +  | "swap n m (Pw t k) = Pw (swap n m t) k"
  7.1529 +  | "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) (swap n m p)"
  7.1530  
  7.1531  lemma swap:
  7.1532    assumes "n < length bs"
  7.1533 @@ -2116,10 +2062,10 @@
  7.1534    by (induct p) simp_all
  7.1535  
  7.1536  fun isweaknpoly :: "poly \<Rightarrow> bool"
  7.1537 -where
  7.1538 -  "isweaknpoly (C c) = True"
  7.1539 -| "isweaknpoly (CN c n p) \<longleftrightarrow> isweaknpoly c \<and> isweaknpoly p"
  7.1540 -| "isweaknpoly p = False"
  7.1541 +  where
  7.1542 +    "isweaknpoly (C c) = True"
  7.1543 +  | "isweaknpoly (CN c n p) \<longleftrightarrow> isweaknpoly c \<and> isweaknpoly p"
  7.1544 +  | "isweaknpoly p = False"
  7.1545  
  7.1546  lemma isnpolyh_isweaknpoly: "isnpolyh p n0 \<Longrightarrow> isweaknpoly p"
  7.1547    by (induct p arbitrary: n0) auto
     8.1 --- a/src/HOL/Decision_Procs/Reflective_Field.thy	Sun Dec 03 19:09:42 2017 +0100
     8.2 +++ b/src/HOL/Decision_Procs/Reflective_Field.thy	Sun Dec 03 22:28:19 2017 +0100
     8.3 @@ -5,7 +5,7 @@
     8.4  *)
     8.5  
     8.6  theory Reflective_Field
     8.7 -imports "~~/src/HOL/Decision_Procs/Commutative_Ring"
     8.8 +  imports Commutative_Ring
     8.9  begin
    8.10  
    8.11  datatype fexpr =
    8.12 @@ -18,29 +18,28 @@
    8.13    | FDiv fexpr fexpr
    8.14    | FPow fexpr nat
    8.15  
    8.16 -fun (in field) nth_el :: "'a list \<Rightarrow> nat \<Rightarrow> 'a" where
    8.17 -  "nth_el [] n = \<zero>"
    8.18 -| "nth_el (x # xs) 0 = x"
    8.19 -| "nth_el (x # xs) (Suc n) = nth_el xs n"
    8.20 +fun (in field) nth_el :: "'a list \<Rightarrow> nat \<Rightarrow> 'a"
    8.21 +  where
    8.22 +    "nth_el [] n = \<zero>"
    8.23 +  | "nth_el (x # xs) 0 = x"
    8.24 +  | "nth_el (x # xs) (Suc n) = nth_el xs n"
    8.25  
    8.26 -lemma (in field) nth_el_Cons:
    8.27 -  "nth_el (x # xs) n = (if n = 0 then x else nth_el xs (n - 1))"
    8.28 +lemma (in field) nth_el_Cons: "nth_el (x # xs) n = (if n = 0 then x else nth_el xs (n - 1))"
    8.29    by (cases n) simp_all
    8.30  
    8.31 -lemma (in field) nth_el_closed [simp]:
    8.32 -  "in_carrier xs \<Longrightarrow> nth_el xs n \<in> carrier R"
    8.33 +lemma (in field) nth_el_closed [simp]: "in_carrier xs \<Longrightarrow> nth_el xs n \<in> carrier R"
    8.34    by (induct xs n rule: nth_el.induct) (simp_all add: in_carrier_def)
    8.35  
    8.36  primrec (in field) feval :: "'a list \<Rightarrow> fexpr \<Rightarrow> 'a"
    8.37 -where
    8.38 -  "feval xs (FCnst c) = \<guillemotleft>c\<guillemotright>"
    8.39 -| "feval xs (FVar n) = nth_el xs n"
    8.40 -| "feval xs (FAdd a b) = feval xs a \<oplus> feval xs b"
    8.41 -| "feval xs (FSub a b) = feval xs a \<ominus> feval xs b"
    8.42 -| "feval xs (FMul a b) = feval xs a \<otimes> feval xs b"
    8.43 -| "feval xs (FNeg a) = \<ominus> feval xs a"
    8.44 -| "feval xs (FDiv a b) = feval xs a \<oslash> feval xs b"
    8.45 -| "feval xs (FPow a n) = feval xs a (^) n"
    8.46 +  where
    8.47 +    "feval xs (FCnst c) = \<guillemotleft>c\<guillemotright>"
    8.48 +  | "feval xs (FVar n) = nth_el xs n"
    8.49 +  | "feval xs (FAdd a b) = feval xs a \<oplus> feval xs b"
    8.50 +  | "feval xs (FSub a b) = feval xs a \<ominus> feval xs b"
    8.51 +  | "feval xs (FMul a b) = feval xs a \<otimes> feval xs b"
    8.52 +  | "feval xs (FNeg a) = \<ominus> feval xs a"
    8.53 +  | "feval xs (FDiv a b) = feval xs a \<oslash> feval xs b"
    8.54 +  | "feval xs (FPow a n) = feval xs a (^) n"
    8.55  
    8.56  lemma (in field) feval_Cnst:
    8.57    "feval xs (FCnst 0) = \<zero>"
    8.58 @@ -75,29 +74,29 @@
    8.59    case (PExpr1 e')
    8.60    then show ?thesis
    8.61      apply (cases e')
    8.62 -    apply simp_all
    8.63 -    apply (erule assms)+
    8.64 +        apply simp_all
    8.65 +        apply (erule assms)+
    8.66      done
    8.67  next
    8.68    case (PExpr2 e')
    8.69    then show ?thesis
    8.70      apply (cases e')
    8.71 -    apply simp_all
    8.72 -    apply (erule assms)+
    8.73 +     apply simp_all
    8.74 +     apply (erule assms)+
    8.75      done
    8.76  qed
    8.77  
    8.78  lemmas pexpr_cases2 = pexpr_cases [case_product pexpr_cases]
    8.79  
    8.80  fun (in field) peval :: "'a list \<Rightarrow> pexpr \<Rightarrow> 'a"
    8.81 -where
    8.82 -  "peval xs (PExpr1 (PCnst c)) = \<guillemotleft>c\<guillemotright>"
    8.83 -| "peval xs (PExpr1 (PVar n)) = nth_el xs n"
    8.84 -| "peval xs (PExpr1 (PAdd a b)) = peval xs a \<oplus> peval xs b"
    8.85 -| "peval xs (PExpr1 (PSub a b)) = peval xs a \<ominus> peval xs b"
    8.86 -| "peval xs (PExpr1 (PNeg a)) = \<ominus> peval xs a"
    8.87 -| "peval xs (PExpr2 (PMul a b)) = peval xs a \<otimes> peval xs b"
    8.88 -| "peval xs (PExpr2 (PPow a n)) = peval xs a (^) n"
    8.89 +  where
    8.90 +    "peval xs (PExpr1 (PCnst c)) = \<guillemotleft>c\<guillemotright>"
    8.91 +  | "peval xs (PExpr1 (PVar n)) = nth_el xs n"
    8.92 +  | "peval xs (PExpr1 (PAdd a b)) = peval xs a \<oplus> peval xs b"
    8.93 +  | "peval xs (PExpr1 (PSub a b)) = peval xs a \<ominus> peval xs b"
    8.94 +  | "peval xs (PExpr1 (PNeg a)) = \<ominus> peval xs a"
    8.95 +  | "peval xs (PExpr2 (PMul a b)) = peval xs a \<otimes> peval xs b"
    8.96 +  | "peval xs (PExpr2 (PPow a n)) = peval xs a (^) n"
    8.97  
    8.98  lemma (in field) peval_Cnst:
    8.99    "peval xs (PExpr1 (PCnst 0)) = \<zero>"
   8.100 @@ -113,44 +112,44 @@
   8.101    by (induct e and e1 and e2) simp_all
   8.102  
   8.103  definition npepow :: "pexpr \<Rightarrow> nat \<Rightarrow> pexpr"
   8.104 -where
   8.105 -  "npepow e n =
   8.106 -     (if n = 0 then PExpr1 (PCnst 1)
   8.107 -      else if n = 1 then e
   8.108 -      else (case e of
   8.109 -          PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (c ^ n))
   8.110 -        | _ \<Rightarrow> PExpr2 (PPow e n)))"
   8.111 +  where "npepow e n =
   8.112 +   (if n = 0 then PExpr1 (PCnst 1)
   8.113 +    else if n = 1 then e
   8.114 +    else
   8.115 +      (case e of
   8.116 +        PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (c ^ n))
   8.117 +      | _ \<Rightarrow> PExpr2 (PPow e n)))"
   8.118  
   8.119  lemma (in field) npepow_correct:
   8.120    "in_carrier xs \<Longrightarrow> peval xs (npepow e n) = peval xs (PExpr2 (PPow e n))"
   8.121 -  by (cases e rule: pexpr_cases)
   8.122 -    (simp_all add: npepow_def)
   8.123 +  by (cases e rule: pexpr_cases) (simp_all add: npepow_def)
   8.124  
   8.125  fun npemul :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.126 -where
   8.127 -  "npemul x y = (case x of
   8.128 -       PExpr1 (PCnst c) \<Rightarrow>
   8.129 -         if c = 0 then x
   8.130 -         else if c = 1 then y else
   8.131 -           (case y of
   8.132 -              PExpr1 (PCnst d) \<Rightarrow> PExpr1 (PCnst (c * d))
   8.133 -            | _ \<Rightarrow> PExpr2 (PMul x y))
   8.134 -     | PExpr2 (PPow e1 n) \<Rightarrow>
   8.135 -         (case y of
   8.136 -            PExpr2 (PPow e2 m) \<Rightarrow>
   8.137 -              if n = m then npepow (npemul e1 e2) n
   8.138 -              else PExpr2 (PMul x y)
   8.139 -          | PExpr1 (PCnst d) \<Rightarrow>
   8.140 -              if d = 0 then y
   8.141 -              else if d = 1 then x
   8.142 -              else PExpr2 (PMul x y)
   8.143 +  where "npemul x y =
   8.144 +    (case x of
   8.145 +      PExpr1 (PCnst c) \<Rightarrow>
   8.146 +        if c = 0 then x
   8.147 +        else if c = 1 then y else
   8.148 +          (case y of
   8.149 +            PExpr1 (PCnst d) \<Rightarrow> PExpr1 (PCnst (c * d))
   8.150            | _ \<Rightarrow> PExpr2 (PMul x y))
   8.151 -     | _ \<Rightarrow> (case y of
   8.152 -         PExpr1 (PCnst d) \<Rightarrow>
   8.153 -           if d = 0 then y
   8.154 -           else if d = 1 then x
   8.155 -           else PExpr2 (PMul x y)
   8.156 -       | _ \<Rightarrow> PExpr2 (PMul x y)))"
   8.157 +    | PExpr2 (PPow e1 n) \<Rightarrow>
   8.158 +        (case y of
   8.159 +          PExpr2 (PPow e2 m) \<Rightarrow>
   8.160 +            if n = m then npepow (npemul e1 e2) n
   8.161 +            else PExpr2 (PMul x y)
   8.162 +        | PExpr1 (PCnst d) \<Rightarrow>
   8.163 +            if d = 0 then y
   8.164 +            else if d = 1 then x
   8.165 +            else PExpr2 (PMul x y)
   8.166 +        | _ \<Rightarrow> PExpr2 (PMul x y))
   8.167 +    | _ \<Rightarrow>
   8.168 +      (case y of
   8.169 +        PExpr1 (PCnst d) \<Rightarrow>
   8.170 +          if d = 0 then y
   8.171 +          else if d = 1 then x
   8.172 +          else PExpr2 (PMul x y)
   8.173 +      | _ \<Rightarrow> PExpr2 (PMul x y)))"
   8.174  
   8.175  lemma (in field) npemul_correct:
   8.176    "in_carrier xs \<Longrightarrow> peval xs (npemul e1 e2) = peval xs (PExpr2 (PMul e1 e2))"
   8.177 @@ -160,104 +159,101 @@
   8.178    proof (cases x y rule: pexpr_cases2)
   8.179      case (PPow_PPow e n e' m)
   8.180      then show ?thesis
   8.181 -    by (simp add: 1 npepow_correct nat_pow_distr
   8.182 -      npemul.simps [of "PExpr2 (PPow e n)" "PExpr2 (PPow e' m)"]
   8.183 -      del: npemul.simps)
   8.184 +      by (simp del: npemul.simps add: 1 npepow_correct nat_pow_distr
   8.185 +          npemul.simps [of "PExpr2 (PPow e n)" "PExpr2 (PPow e' m)"])
   8.186    qed simp_all
   8.187  qed
   8.188  
   8.189  declare npemul.simps [simp del]
   8.190  
   8.191  definition npeadd :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.192 -where
   8.193 -  "npeadd x y = (case x of
   8.194 -       PExpr1 (PCnst c) \<Rightarrow>
   8.195 -         if c = 0 then y else
   8.196 -           (case y of
   8.197 -              PExpr1 (PCnst d) \<Rightarrow> PExpr1 (PCnst (c + d))
   8.198 -            | _ \<Rightarrow> PExpr1 (PAdd x y))
   8.199 -     | _ \<Rightarrow> (case y of
   8.200 -         PExpr1 (PCnst d) \<Rightarrow>
   8.201 -           if d = 0 then x
   8.202 -           else PExpr1 (PAdd x y)
   8.203 -       | _ \<Rightarrow> PExpr1 (PAdd x y)))"
   8.204 +  where "npeadd x y =
   8.205 +    (case x of
   8.206 +      PExpr1 (PCnst c) \<Rightarrow>
   8.207 +        if c = 0 then y
   8.208 +        else
   8.209 +          (case y of
   8.210 +            PExpr1 (PCnst d) \<Rightarrow> PExpr1 (PCnst (c + d))
   8.211 +          | _ \<Rightarrow> PExpr1 (PAdd x y))
   8.212 +    | _ \<Rightarrow>
   8.213 +      (case y of
   8.214 +        PExpr1 (PCnst d) \<Rightarrow>
   8.215 +          if d = 0 then x
   8.216 +          else PExpr1 (PAdd x y)
   8.217 +      | _ \<Rightarrow> PExpr1 (PAdd x y)))"
   8.218  
   8.219  lemma (in field) npeadd_correct:
   8.220    "in_carrier xs \<Longrightarrow> peval xs (npeadd e1 e2) = peval xs (PExpr1 (PAdd e1 e2))"
   8.221    by (cases e1 e2 rule: pexpr_cases2) (simp_all add: npeadd_def)
   8.222  
   8.223  definition npesub :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.224 -where
   8.225 -  "npesub x y = (case y of
   8.226 -       PExpr1 (PCnst d) \<Rightarrow>
   8.227 -         if d = 0 then x else
   8.228 -           (case x of
   8.229 -              PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (c - d))
   8.230 -            | _ \<Rightarrow> PExpr1 (PSub x y))
   8.231 -     | _ \<Rightarrow> (case x of
   8.232 -         PExpr1 (PCnst c) \<Rightarrow>
   8.233 -           if c = 0 then PExpr1 (PNeg y)
   8.234 -           else PExpr1 (PSub x y)
   8.235 -       | _ \<Rightarrow> PExpr1 (PSub x y)))"
   8.236 +  where "npesub x y =
   8.237 +    (case y of
   8.238 +      PExpr1 (PCnst d) \<Rightarrow>
   8.239 +        if d = 0 then x
   8.240 +        else
   8.241 +          (case x of
   8.242 +            PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (c - d))
   8.243 +          | _ \<Rightarrow> PExpr1 (PSub x y))
   8.244 +    | _ \<Rightarrow>
   8.245 +      (case x of
   8.246 +        PExpr1 (PCnst c) \<Rightarrow>
   8.247 +          if c = 0 then PExpr1 (PNeg y)
   8.248 +          else PExpr1 (PSub x y)
   8.249 +      | _ \<Rightarrow> PExpr1 (PSub x y)))"
   8.250  
   8.251  lemma (in field) npesub_correct:
   8.252    "in_carrier xs \<Longrightarrow> peval xs (npesub e1 e2) = peval xs (PExpr1 (PSub e1 e2))"
   8.253    by (cases e1 e2 rule: pexpr_cases2) (simp_all add: npesub_def)
   8.254  
   8.255  definition npeneg :: "pexpr \<Rightarrow> pexpr"
   8.256 -where
   8.257 -  "npeneg e = (case e of
   8.258 -       PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (- c))
   8.259 -     | _ \<Rightarrow> PExpr1 (PNeg e))"
   8.260 +  where "npeneg e =
   8.261 +    (case e of
   8.262 +      PExpr1 (PCnst c) \<Rightarrow> PExpr1 (PCnst (- c))
   8.263 +    | _ \<Rightarrow> PExpr1 (PNeg e))"
   8.264  
   8.265 -lemma (in field) npeneg_correct:
   8.266 -  "peval xs (npeneg e) = peval xs (PExpr1 (PNeg e))"
   8.267 +lemma (in field) npeneg_correct: "peval xs (npeneg e) = peval xs (PExpr1 (PNeg e))"
   8.268    by (cases e rule: pexpr_cases) (simp_all add: npeneg_def)
   8.269  
   8.270  lemma option_pair_cases [case_names None Some]:
   8.271 -  assumes
   8.272 -    "x = None \<Longrightarrow> P"
   8.273 -    "\<And>p q. x = Some (p, q) \<Longrightarrow> P"
   8.274 -  shows P
   8.275 +  obtains (None) "x = None" | (Some) p q where "x = Some (p, q)"
   8.276  proof (cases x)
   8.277    case None
   8.278 -  then show ?thesis by (rule assms)
   8.279 +  then show ?thesis by (rule that)
   8.280  next
   8.281    case (Some r)
   8.282    then show ?thesis
   8.283 -    apply (cases r)
   8.284 -    apply simp
   8.285 -    by (rule assms)
   8.286 +    by (cases r, simp) (rule that)
   8.287  qed
   8.288  
   8.289 -fun isin :: "pexpr \<Rightarrow> nat \<Rightarrow> pexpr \<Rightarrow> nat \<Rightarrow> (nat * pexpr) option"
   8.290 -where
   8.291 -  "isin e n (PExpr2 (PMul e1 e2)) m =
   8.292 -     (case isin e n e1 m of
   8.293 +fun isin :: "pexpr \<Rightarrow> nat \<Rightarrow> pexpr \<Rightarrow> nat \<Rightarrow> (nat \<times> pexpr) option"
   8.294 +  where
   8.295 +    "isin e n (PExpr2 (PMul e1 e2)) m =
   8.296 +      (case isin e n e1 m of
   8.297          Some (k, e3) \<Rightarrow>
   8.298            if k = 0 then Some (0, npemul e3 (npepow e2 m))
   8.299 -          else (case isin e k e2 m of
   8.300 +          else
   8.301 +            (case isin e k e2 m of
   8.302                Some (l, e4) \<Rightarrow> Some (l, npemul e3 e4)
   8.303              | None \<Rightarrow> Some (k, npemul e3 (npepow e2 m)))
   8.304 -      | None \<Rightarrow> (case isin e n e2 m of
   8.305 -          Some (k, e3) \<Rightarrow> Some (k, npemul (npepow e1 m) e3)
   8.306 -        | None \<Rightarrow> None))"
   8.307 -| "isin e n (PExpr2 (PPow e' k)) m =
   8.308 -     (if k = 0 then None else isin e n e' (k * m))"
   8.309 -| "isin (PExpr1 e) n (PExpr1 e') m =
   8.310 -     (if e = e' then
   8.311 -        if n >= m then Some (n - m, PExpr1 (PCnst 1))
   8.312 +      | None \<Rightarrow>
   8.313 +          (case isin e n e2 m of
   8.314 +            Some (k, e3) \<Rightarrow> Some (k, npemul (npepow e1 m) e3)
   8.315 +          | None \<Rightarrow> None))"
   8.316 +  | "isin e n (PExpr2 (PPow e' k)) m =
   8.317 +      (if k = 0 then None else isin e n e' (k * m))"
   8.318 +  | "isin (PExpr1 e) n (PExpr1 e') m =
   8.319 +      (if e = e' then
   8.320 +        if n \<ge> m then Some (n - m, PExpr1 (PCnst 1))
   8.321          else Some (0, npepow (PExpr1 e) (m - n))
   8.322 -      else None)"
   8.323 -| "isin (PExpr2 e) n (PExpr1 e') m = None"
   8.324 +       else None)"
   8.325 +  | "isin (PExpr2 e) n (PExpr1 e') m = None"
   8.326  
   8.327  lemma (in field) isin_correct:
   8.328    assumes "in_carrier xs"
   8.329 -  and "isin e n e' m = Some (p, e'')"
   8.330 -  shows
   8.331 -    "peval xs (PExpr2 (PPow e' m)) =
   8.332 -     peval xs (PExpr2 (PMul (PExpr2 (PPow e (n - p))) e''))"
   8.333 -    "p \<le> n"
   8.334 +    and "isin e n e' m = Some (p, e'')"
   8.335 +  shows "peval xs (PExpr2 (PPow e' m)) = peval xs (PExpr2 (PMul (PExpr2 (PPow e (n - p))) e''))"
   8.336 +    and "p \<le> n"
   8.337    using assms
   8.338    by (induct e n e' m arbitrary: p e'' rule: isin.induct)
   8.339      (force
   8.340 @@ -268,38 +264,37 @@
   8.341  
   8.342  lemma (in field) isin_correct':
   8.343    "in_carrier xs \<Longrightarrow> isin e n e' 1 = Some (p, e'') \<Longrightarrow>
   8.344 -   peval xs e' = peval xs e (^) (n - p) \<otimes> peval xs e''"
   8.345 +    peval xs e' = peval xs e (^) (n - p) \<otimes> peval xs e''"
   8.346    "in_carrier xs \<Longrightarrow> isin e n e' 1 = Some (p, e'') \<Longrightarrow> p \<le> n"
   8.347 -  using isin_correct [where m=1]
   8.348 -  by simp_all
   8.349 +  using isin_correct [where m = 1] by simp_all
   8.350  
   8.351  fun split_aux :: "pexpr \<Rightarrow> nat \<Rightarrow> pexpr \<Rightarrow> pexpr \<times> pexpr \<times> pexpr"
   8.352 -where
   8.353 -  "split_aux (PExpr2 (PMul e1 e2)) n e =
   8.354 -     (let
   8.355 -        (left1, common1, right1) = split_aux e1 n e;
   8.356 -        (left2, common2, right2) = split_aux e2 n right1
   8.357 -      in (npemul left1 left2, npemul common1 common2, right2))"
   8.358 -| "split_aux (PExpr2 (PPow e' m)) n e =
   8.359 -     (if m = 0 then (PExpr1 (PCnst 1), PExpr1 (PCnst 1), e)
   8.360 -      else split_aux e' (m * n) e)"
   8.361 -| "split_aux (PExpr1 e') n e =
   8.362 -     (case isin (PExpr1 e') n e 1 of
   8.363 -        Some (m, e'') \<Rightarrow>
   8.364 -          (if m = 0 then (PExpr1 (PCnst 1), npepow (PExpr1 e') n, e'')
   8.365 -           else (npepow (PExpr1 e') m, npepow (PExpr1 e') (n - m), e''))
   8.366 -      | None \<Rightarrow> (npepow (PExpr1 e') n, PExpr1 (PCnst 1), e))"
   8.367 +  where
   8.368 +    "split_aux (PExpr2 (PMul e1 e2)) n e =
   8.369 +       (let
   8.370 +          (left1, common1, right1) = split_aux e1 n e;
   8.371 +          (left2, common2, right2) = split_aux e2 n right1
   8.372 +        in (npemul left1 left2, npemul common1 common2, right2))"
   8.373 +  | "split_aux (PExpr2 (PPow e' m)) n e =
   8.374 +       (if m = 0 then (PExpr1 (PCnst 1), PExpr1 (PCnst 1), e)
   8.375 +        else split_aux e' (m * n) e)"
   8.376 +  | "split_aux (PExpr1 e') n e =
   8.377 +       (case isin (PExpr1 e') n e 1 of
   8.378 +          Some (m, e'') \<Rightarrow>
   8.379 +            (if m = 0 then (PExpr1 (PCnst 1), npepow (PExpr1 e') n, e'')
   8.380 +             else (npepow (PExpr1 e') m, npepow (PExpr1 e') (n - m), e''))
   8.381 +        | None \<Rightarrow> (npepow (PExpr1 e') n, PExpr1 (PCnst 1), e))"
   8.382  
   8.383 -hide_const Left Right
   8.384 +hide_const Left Right  (* FIXME !? *)
   8.385  
   8.386 -abbreviation Left :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr" where
   8.387 -  "Left e1 e2 \<equiv> fst (split_aux e1 (Suc 0) e2)"
   8.388 +abbreviation Left :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.389 +  where "Left e1 e2 \<equiv> fst (split_aux e1 (Suc 0) e2)"
   8.390  
   8.391 -abbreviation Common :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr" where
   8.392 -  "Common e1 e2 \<equiv> fst (snd (split_aux e1 (Suc 0) e2))"
   8.393 +abbreviation Common :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.394 +  where "Common e1 e2 \<equiv> fst (snd (split_aux e1 (Suc 0) e2))"
   8.395  
   8.396 -abbreviation Right :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr" where
   8.397 -  "Right e1 e2 \<equiv> snd (snd (split_aux e1 (Suc 0) e2))"
   8.398 +abbreviation Right :: "pexpr \<Rightarrow> pexpr \<Rightarrow> pexpr"
   8.399 +  where "Right e1 e2 \<equiv> snd (snd (split_aux e1 (Suc 0) e2))"
   8.400  
   8.401  lemma split_aux_induct [case_names 1 2 3]:
   8.402    assumes I1: "\<And>e1 e2 n e. P e1 n e \<Longrightarrow> P e2 n (snd (snd (split_aux e1 n e))) \<Longrightarrow>
   8.403 @@ -321,11 +316,11 @@
   8.404  
   8.405  lemma (in field) split_aux_correct:
   8.406    "in_carrier xs \<Longrightarrow>
   8.407 -   peval xs (PExpr2 (PPow e\<^sub>1 n)) =
   8.408 -   peval xs (PExpr2 (PMul (fst (split_aux e\<^sub>1 n e\<^sub>2)) (fst (snd (split_aux e\<^sub>1 n e\<^sub>2)))))"
   8.409 +    peval xs (PExpr2 (PPow e\<^sub>1 n)) =
   8.410 +    peval xs (PExpr2 (PMul (fst (split_aux e\<^sub>1 n e\<^sub>2)) (fst (snd (split_aux e\<^sub>1 n e\<^sub>2)))))"
   8.411    "in_carrier xs \<Longrightarrow>
   8.412 -   peval xs e\<^sub>2 =
   8.413 -   peval xs (PExpr2 (PMul (snd (snd (split_aux e\<^sub>1 n e\<^sub>2))) (fst (snd (split_aux e\<^sub>1 n e\<^sub>2)))))"
   8.414 +    peval xs e\<^sub>2 =
   8.415 +    peval xs (PExpr2 (PMul (snd (snd (split_aux e\<^sub>1 n e\<^sub>2))) (fst (snd (split_aux e\<^sub>1 n e\<^sub>2)))))"
   8.416    by (induct e\<^sub>1 n e\<^sub>2 rule: split_aux_induct)
   8.417      (auto simp add: split_beta
   8.418         nat_pow_distr nat_pow_pow nat_pow_mult m_ac
   8.419 @@ -334,81 +329,78 @@
   8.420  
   8.421  lemma (in field) split_aux_correct':
   8.422    "in_carrier xs \<Longrightarrow>
   8.423 -   peval xs e\<^sub>1 = peval xs (Left e\<^sub>1 e\<^sub>2) \<otimes> peval xs (Common e\<^sub>1 e\<^sub>2)"
   8.424 +    peval xs e\<^sub>1 = peval xs (Left e\<^sub>1 e\<^sub>2) \<otimes> peval xs (Common e\<^sub>1 e\<^sub>2)"
   8.425    "in_carrier xs \<Longrightarrow>
   8.426 -   peval xs e\<^sub>2 = peval xs (Right e\<^sub>1 e\<^sub>2) \<otimes> peval xs (Common e\<^sub>1 e\<^sub>2)"
   8.427 -  using split_aux_correct [where n=1]
   8.428 -  by simp_all
   8.429 +    peval xs e\<^sub>2 = peval xs (Right e\<^sub>1 e\<^sub>2) \<otimes> peval xs (Common e\<^sub>1 e\<^sub>2)"
   8.430 +  using split_aux_correct [where n = 1] by simp_all
   8.431  
   8.432  fun fnorm :: "fexpr \<Rightarrow> pexpr \<times> pexpr \<times> pexpr list"
   8.433 -where
   8.434 -  "fnorm (FCnst c) = (PExpr1 (PCnst c), PExpr1 (PCnst 1), [])"
   8.435 -| "fnorm (FVar n) = (PExpr1 (PVar n), PExpr1 (PCnst 1), [])"
   8.436 -| "fnorm (FAdd e1 e2) =
   8.437 -     (let
   8.438 -        (xn, xd, xc) = fnorm e1;
   8.439 -        (yn, yd, yc) = fnorm e2;
   8.440 -        (left, common, right) = split_aux xd 1 yd
   8.441 -      in
   8.442 -        (npeadd (npemul xn right) (npemul yn left),
   8.443 -         npemul left (npemul right common),
   8.444 -         List.union xc yc))"
   8.445 -| "fnorm (FSub e1 e2) =
   8.446 -     (let
   8.447 -        (xn, xd, xc) = fnorm e1;
   8.448 -        (yn, yd, yc) = fnorm e2;
   8.449 -        (left, common, right) = split_aux xd 1 yd
   8.450 -      in
   8.451 -        (npesub (npemul xn right) (npemul yn left),
   8.452 -         npemul left (npemul right common),
   8.453 -         List.union xc yc))"
   8.454 -| "fnorm (FMul e1 e2) =
   8.455 -     (let
   8.456 -        (xn, xd, xc) = fnorm e1;
   8.457 -        (yn, yd, yc) = fnorm e2;
   8.458 -        (left1, common1, right1) = split_aux xn 1 yd;
   8.459 -        (left2, common2, right2) = split_aux yn 1 xd
   8.460 -      in
   8.461 -        (npemul left1 left2,
   8.462 -         npemul right2 right1,
   8.463 -         List.union xc yc))"
   8.464 -| "fnorm (FNeg e) =
   8.465 -     (let (n, d, c) = fnorm e
   8.466 -      in (npeneg n, d, c))"
   8.467 -| "fnorm (FDiv e1 e2) =
   8.468 -     (let
   8.469 -        (xn, xd, xc) = fnorm e1;
   8.470 -        (yn, yd, yc) = fnorm e2;
   8.471 -        (left1, common1, right1) = split_aux xn 1 yn;
   8.472 -        (left2, common2, right2) = split_aux xd 1 yd
   8.473 -      in
   8.474 -        (npemul left1 right2,
   8.475 -         npemul left2 right1,
   8.476 -         List.insert yn (List.union xc yc)))"
   8.477 -| "fnorm (FPow e m) =
   8.478 -     (let (n, d, c) = fnorm e
   8.479 -      in (npepow n m, npepow d m, c))"
   8.480 +  where
   8.481 +    "fnorm (FCnst c) = (PExpr1 (PCnst c), PExpr1 (PCnst 1), [])"
   8.482 +  | "fnorm (FVar n) = (PExpr1 (PVar n), PExpr1 (PCnst 1), [])"
   8.483 +  | "fnorm (FAdd e1 e2) =
   8.484 +       (let
   8.485 +          (xn, xd, xc) = fnorm e1;
   8.486 +          (yn, yd, yc) = fnorm e2;
   8.487 +          (left, common, right) = split_aux xd 1 yd
   8.488 +        in
   8.489 +          (npeadd (npemul xn right) (npemul yn left),
   8.490 +           npemul left (npemul right common),
   8.491 +           List.union xc yc))"
   8.492 +  | "fnorm (FSub e1 e2) =
   8.493 +       (let
   8.494 +          (xn, xd, xc) = fnorm e1;
   8.495 +          (yn, yd, yc) = fnorm e2;
   8.496 +          (left, common, right) = split_aux xd 1 yd
   8.497 +        in
   8.498 +          (npesub (npemul xn right) (npemul yn left),
   8.499 +           npemul left (npemul right common),
   8.500 +           List.union xc yc))"
   8.501 +  | "fnorm (FMul e1 e2) =
   8.502 +       (let
   8.503 +          (xn, xd, xc) = fnorm e1;
   8.504 +          (yn, yd, yc) = fnorm e2;
   8.505 +          (left1, common1, right1) = split_aux xn 1 yd;
   8.506 +          (left2, common2, right2) = split_aux yn 1 xd
   8.507 +        in
   8.508 +          (npemul left1 left2,
   8.509 +           npemul right2 right1,
   8.510 +           List.union xc yc))"
   8.511 +  | "fnorm (FNeg e) =
   8.512 +       (let (n, d, c) = fnorm e
   8.513 +        in (npeneg n, d, c))"
   8.514 +  | "fnorm (FDiv e1 e2) =
   8.515 +       (let
   8.516 +          (xn, xd, xc) = fnorm e1;
   8.517 +          (yn, yd, yc) = fnorm e2;
   8.518 +          (left1, common1, right1) = split_aux xn 1 yn;
   8.519 +          (left2, common2, right2) = split_aux xd 1 yd
   8.520 +        in
   8.521 +          (npemul left1 right2,
   8.522 +           npemul left2 right1,
   8.523 +           List.insert yn (List.union xc yc)))"
   8.524 +  | "fnorm (FPow e m) =
   8.525 +       (let (n, d, c) = fnorm e
   8.526 +        in (npepow n m, npepow d m, c))"
   8.527  
   8.528 -abbreviation Num :: "fexpr \<Rightarrow> pexpr" where
   8.529 -  "Num e \<equiv> fst (fnorm e)"
   8.530 +abbreviation Num :: "fexpr \<Rightarrow> pexpr"
   8.531 +  where "Num e \<equiv> fst (fnorm e)"
   8.532  
   8.533 -abbreviation Denom :: "fexpr \<Rightarrow> pexpr" where
   8.534 -  "Denom e \<equiv> fst (snd (fnorm e))"
   8.535 +abbreviation Denom :: "fexpr \<Rightarrow> pexpr"
   8.536 +  where "Denom e \<equiv> fst (snd (fnorm e))"
   8.537  
   8.538 -abbreviation Cond :: "fexpr \<Rightarrow> pexpr list" where
   8.539 -  "Cond e \<equiv> snd (snd (fnorm e))"
   8.540 +abbreviation Cond :: "fexpr \<Rightarrow> pexpr list"
   8.541 +  where "Cond e \<equiv> snd (snd (fnorm e))"
   8.542  
   8.543  primrec (in field) nonzero :: "'a list \<Rightarrow> pexpr list \<Rightarrow> bool"
   8.544 -where
   8.545 -  "nonzero xs [] = True"
   8.546 -| "nonzero xs (p # ps) = (peval xs p \<noteq> \<zero> \<and> nonzero xs ps)"
   8.547 +  where
   8.548 +    "nonzero xs [] \<longleftrightarrow> True"
   8.549 +  | "nonzero xs (p # ps) \<longleftrightarrow> peval xs p \<noteq> \<zero> \<and> nonzero xs ps"
   8.550  
   8.551 -lemma (in field) nonzero_singleton:
   8.552 -  "nonzero xs [p] = (peval xs p \<noteq> \<zero>)"
   8.553 +lemma (in field) nonzero_singleton: "nonzero xs [p] = (peval xs p \<noteq> \<zero>)"
   8.554    by simp
   8.555  
   8.556 -lemma (in field) nonzero_append:
   8.557 -  "nonzero xs (ps @ qs) = (nonzero xs ps \<and> nonzero xs qs)"
   8.558 +lemma (in field) nonzero_append: "nonzero xs (ps @ qs) = (nonzero xs ps \<and> nonzero xs qs)"
   8.559    by (induct ps) simp_all
   8.560  
   8.561  lemma (in field) nonzero_idempotent:
   8.562 @@ -426,12 +418,13 @@
   8.563  
   8.564  lemma (in field) fnorm_correct:
   8.565    assumes "in_carrier xs"
   8.566 -  and "nonzero xs (Cond e)"
   8.567 +    and "nonzero xs (Cond e)"
   8.568    shows "feval xs e = peval xs (Num e) \<oslash> peval xs (Denom e)"
   8.569 -  and "peval xs (Denom e) \<noteq> \<zero>"
   8.570 +    and "peval xs (Denom e) \<noteq> \<zero>"
   8.571    using assms
   8.572  proof (induct e)
   8.573 -  case (FCnst c) {
   8.574 +  case (FCnst c)
   8.575 +  {
   8.576      case 1
   8.577      show ?case by simp
   8.578    next
   8.579 @@ -439,7 +432,8 @@
   8.580      show ?case by simp
   8.581    }
   8.582  next
   8.583 -  case (FVar n) {
   8.584 +  case (FVar n)
   8.585 +  {
   8.586      case 1
   8.587      then show ?case by simp
   8.588    next
   8.589 @@ -448,21 +442,17 @@
   8.590    }
   8.591  next
   8.592    case (FAdd e1 e2)
   8.593 -  note split = split_aux_correct' [where xs=xs and
   8.594 -    e\<^sub>1="Denom e1" and e\<^sub>2="Denom e2"]
   8.595 +  note split = split_aux_correct' [where xs=xs and e\<^sub>1 = "Denom e1" and e\<^sub>2 = "Denom e2"]
   8.596    {
   8.597      case 1
   8.598      let ?left = "peval xs (Left (Denom e1) (Denom e2))"
   8.599      let ?common = "peval xs (Common (Denom e1) (Denom e2))"
   8.600      let ?right = "peval xs (Right (Denom e1) (Denom e2))"
   8.601 -    from 1 FAdd
   8.602 -    have "feval xs (FAdd e1 e2) =
   8.603 +    from 1 FAdd have "feval xs (FAdd e1 e2) =
   8.604        (?common \<otimes> (peval xs (Num e1) \<otimes> ?right \<oplus> peval xs (Num e2) \<otimes> ?left)) \<oslash>
   8.605        (?common \<otimes> (?left \<otimes> (?right \<otimes> ?common)))"
   8.606 -      by (simp add: split_beta split nonzero_union
   8.607 -        add_frac_eq r_distr m_ac)
   8.608 -    also from 1 FAdd have "\<dots> =
   8.609 -      peval xs (Num (FAdd e1 e2)) \<oslash> peval xs (Denom (FAdd e1 e2))"
   8.610 +      by (simp add: split_beta split nonzero_union add_frac_eq r_distr m_ac)
   8.611 +    also from 1 FAdd have "\<dots> = peval xs (Num (FAdd e1 e2)) \<oslash> peval xs (Denom (FAdd e1 e2))"
   8.612        by (simp add: split_beta split nonzero_union npeadd_correct npemul_correct integral_iff)
   8.613      finally show ?case .
   8.614    next
   8.615 @@ -472,8 +462,7 @@
   8.616    }
   8.617  next
   8.618    case (FSub e1 e2)
   8.619 -  note split = split_aux_correct' [where xs=xs and
   8.620 -    e\<^sub>1="Denom e1" and e\<^sub>2="Denom e2"]
   8.621 +  note split = split_aux_correct' [where xs=xs and e\<^sub>1 = "Denom e1" and e\<^sub>2 = "Denom e2"]
   8.622    {
   8.623      case 1
   8.624      let ?left = "peval xs (Left (Denom e1) (Denom e2))"
   8.625 @@ -483,10 +472,8 @@
   8.626      have "feval xs (FSub e1 e2) =
   8.627        (?common \<otimes> (peval xs (Num e1) \<otimes> ?right \<ominus> peval xs (Num e2) \<otimes> ?left)) \<oslash>
   8.628        (?common \<otimes> (?left \<otimes> (?right \<otimes> ?common)))"
   8.629 -      by (simp add: split_beta split nonzero_union
   8.630 -        diff_frac_eq r_diff_distr m_ac)
   8.631 -    also from 1 FSub have "\<dots> =
   8.632 -      peval xs (Num (FSub e1 e2)) \<oslash> peval xs (Denom (FSub e1 e2))"
   8.633 +      by (simp add: split_beta split nonzero_union diff_frac_eq r_diff_distr m_ac)
   8.634 +    also from 1 FSub have "\<dots> = peval xs (Num (FSub e1 e2)) \<oslash> peval xs (Denom (FSub e1 e2))"
   8.635        by (simp add: split_beta split nonzero_union npesub_correct npemul_correct integral_iff)
   8.636      finally show ?case .
   8.637    next
   8.638 @@ -497,10 +484,8 @@
   8.639  next
   8.640    case (FMul e1 e2)
   8.641    note split =
   8.642 -    split_aux_correct' [where xs=xs and
   8.643 -      e\<^sub>1="Num e1" and e\<^sub>2="Denom e2"]
   8.644 -    split_aux_correct' [where xs=xs and
   8.645 -      e\<^sub>1="Num e2" and e\<^sub>2="Denom e1"]
   8.646 +    split_aux_correct' [where xs=xs and e\<^sub>1 = "Num e1" and e\<^sub>2 = "Denom e2"]
   8.647 +    split_aux_correct' [where xs=xs and e\<^sub>1 = "Num e2" and e\<^sub>2 = "Denom e1"]
   8.648    {
   8.649      case 1
   8.650      let ?left\<^sub>1 = "peval xs (Left (Num e1) (Denom e2))"
   8.651 @@ -509,14 +494,12 @@
   8.652      let ?left\<^sub>2 = "peval xs (Left (Num e2) (Denom e1))"
   8.653      let ?common\<^sub>2 = "peval xs (Common (Num e2) (Denom e1))"
   8.654      let ?right\<^sub>2 = "peval xs (Right (Num e2) (Denom e1))"
   8.655 -    from 1 FMul
   8.656 -    have "feval xs (FMul e1 e2) =
   8.657 +    from 1 FMul have "feval xs (FMul e1 e2) =
   8.658        ((?common\<^sub>1 \<otimes> ?common\<^sub>2) \<otimes> (?left\<^sub>1 \<otimes> ?left\<^sub>2)) \<oslash>
   8.659        ((?common\<^sub>1 \<otimes> ?common\<^sub>2) \<otimes> (?right\<^sub>2 \<otimes> ?right\<^sub>1))"
   8.660        by (simp add: split_beta split nonzero_union
   8.661          nonzero_divide_divide_eq_left m_ac)
   8.662 -    also from 1 FMul have "\<dots> =
   8.663 -      peval xs (Num (FMul e1 e2)) \<oslash> peval xs (Denom (FMul e1 e2))"
   8.664 +    also from 1 FMul have "\<dots> = peval xs (Num (FMul e1 e2)) \<oslash> peval xs (Denom (FMul e1 e2))"
   8.665        by (simp add: split_beta split nonzero_union npemul_correct integral_iff)
   8.666      finally show ?case .
   8.667    next
   8.668 @@ -538,10 +521,8 @@
   8.669  next
   8.670    case (FDiv e1 e2)
   8.671    note split =
   8.672 -    split_aux_correct' [where xs=xs and
   8.673 -      e\<^sub>1="Num e1" and e\<^sub>2="Num e2"]
   8.674 -    split_aux_correct' [where xs=xs and
   8.675 -      e\<^sub>1="Denom e1" and e\<^sub>2="Denom e2"]
   8.676 +    split_aux_correct' [where xs=xs and e\<^sub>1 = "Num e1" and e\<^sub>2 = "Num e2"]
   8.677 +    split_aux_correct' [where xs=xs and e\<^sub>1 = "Denom e1" and e\<^sub>2 = "Denom e2"]
   8.678    {
   8.679      case 1
   8.680      let ?left\<^sub>1 = "peval xs (Left (Num e1) (Num e2))"
   8.681 @@ -556,8 +537,7 @@
   8.682        ((?common\<^sub>1 \<otimes> ?common\<^sub>2) \<otimes> (?left\<^sub>2 \<otimes> ?right\<^sub>1))"
   8.683        by (simp add: split_beta split nonzero_union nonzero_insert
   8.684          nonzero_divide_divide_eq m_ac)
   8.685 -    also from 1 FDiv have "\<dots> =
   8.686 -      peval xs (Num (FDiv e1 e2)) \<oslash> peval xs (Denom (FDiv e1 e2))"
   8.687 +    also from 1 FDiv have "\<dots> = peval xs (Num (FDiv e1 e2)) \<oslash> peval xs (Denom (FDiv e1 e2))"
   8.688        by (simp add: split_beta split nonzero_union nonzero_insert npemul_correct integral_iff)
   8.689      finally show ?case .
   8.690    next
   8.691 @@ -580,16 +560,15 @@
   8.692  
   8.693  lemma (in field) feval_eq0:
   8.694    assumes "in_carrier xs"
   8.695 -  and "fnorm e = (n, d, c)"
   8.696 -  and "nonzero xs c"
   8.697 -  and "peval xs n = \<zero>"
   8.698 +    and "fnorm e = (n, d, c)"
   8.699 +    and "nonzero xs c"
   8.700 +    and "peval xs n = \<zero>"
   8.701    shows "feval xs e = \<zero>"
   8.702 -  using assms fnorm_correct [of xs e]
   8.703 -  by simp
   8.704 +  using assms fnorm_correct [of xs e] by simp
   8.705  
   8.706  lemma (in field) fexpr_in_carrier:
   8.707    assumes "in_carrier xs"
   8.708 -  and "nonzero xs (Cond e)"
   8.709 +    and "nonzero xs (Cond e)"
   8.710    shows "feval xs e \<in> carrier R"
   8.711    using assms
   8.712  proof (induct e)
   8.713 @@ -610,8 +589,8 @@
   8.714  
   8.715  lemma (in field) feval_eq:
   8.716    assumes "in_carrier xs"
   8.717 -  and "fnorm (FSub e e') = (n, d, c)"
   8.718 -  and "nonzero xs c"
   8.719 +    and "fnorm (FSub e e') = (n, d, c)"
   8.720 +    and "nonzero xs c"
   8.721    shows "(feval xs e = feval xs e') = (peval xs n = \<zero>)"
   8.722  proof -
   8.723    from assms have "nonzero xs (Cond e)" "nonzero xs (Cond e')"
   8.724 @@ -940,7 +919,8 @@
   8.725  end
   8.726  \<close>
   8.727  
   8.728 -context field begin
   8.729 +context field
   8.730 +begin
   8.731  
   8.732  local_setup \<open>
   8.733  Local_Theory.declaration {syntax = false, pervasive = false}
     9.1 --- a/src/HOL/Decision_Procs/ex/Commutative_Ring_Ex.thy	Sun Dec 03 19:09:42 2017 +0100
     9.2 +++ b/src/HOL/Decision_Procs/ex/Commutative_Ring_Ex.thy	Sun Dec 03 22:28:19 2017 +0100
     9.3 @@ -5,7 +5,7 @@
     9.4  section \<open>Some examples demonstrating the ring and field methods\<close>
     9.5  
     9.6  theory Commutative_Ring_Ex
     9.7 -imports "../Reflective_Field"
     9.8 +  imports "../Reflective_Field"
     9.9  begin
    9.10  
    9.11  lemma "4 * (x::int) ^ 5 * y ^ 3 * x ^ 2 * 3 + x * z + 3 ^ 5 = 12 * x ^ 7 * y ^ 3 + z * x + 243"