author wenzelm Wed, 07 Sep 2011 16:37:50 +0200 changeset 44779 98d597c4193d parent 44778 18b1ba7cfcfe child 44780 a13cdb1e9e08
tuned proofs;
```--- a/src/HOL/Decision_Procs/Commutative_Ring_Complete.thy	Wed Sep 07 11:36:39 2011 +0200
+++ b/src/HOL/Decision_Procs/Commutative_Ring_Complete.thy	Wed Sep 07 16:37:50 2011 +0200
@@ -12,8 +12,7 @@
begin

text {* Formalization of normal form *}
-fun
-  isnorm :: "('a::{comm_ring}) pol \<Rightarrow> bool"
+fun isnorm :: "'a::comm_ring pol \<Rightarrow> bool"
where
"isnorm (Pc c) \<longleftrightarrow> True"
| "isnorm (Pinj i (Pc c)) \<longleftrightarrow> False"
@@ -26,35 +25,40 @@
| "isnorm (PX P i Q) \<longleftrightarrow> isnorm P \<and> isnorm Q"

-lemma norm_Pinj_0_False:"isnorm (Pinj 0 P) = False"
-by(cases P, auto)
+lemma norm_Pinj_0_False: "isnorm (Pinj 0 P) = False"
+  by (cases P) auto

-lemma norm_PX_0_False:"isnorm (PX (Pc 0) i Q) = False"
-by(cases i, auto)
+lemma norm_PX_0_False: "isnorm (PX (Pc 0) i Q) = False"
+  by (cases i) auto

-lemma norm_Pinj:"isnorm (Pinj i Q) \<Longrightarrow> isnorm Q"
-by(cases i,simp add: norm_Pinj_0_False norm_PX_0_False,cases Q) auto
+lemma norm_Pinj: "isnorm (Pinj i Q) \<Longrightarrow> isnorm Q"
+  by (cases i) (simp add: norm_Pinj_0_False norm_PX_0_False, cases Q, auto)

-lemma norm_PX2:"isnorm (PX P i Q) \<Longrightarrow> isnorm Q"
-by(cases i, auto, cases P, auto, case_tac pol2, auto)
+lemma norm_PX2: "isnorm (PX P i Q) \<Longrightarrow> isnorm Q"
+  by (cases i) (auto, cases P, auto, case_tac pol2, auto)
+
+lemma norm_PX1: "isnorm (PX P i Q) \<Longrightarrow> isnorm P"
+  by (cases i) (auto, cases P, auto, case_tac pol2, auto)

-lemma norm_PX1:"isnorm (PX P i Q) \<Longrightarrow> isnorm P"
-by(cases i, auto, cases P, auto, case_tac pol2, auto)
-
-lemma mkPinj_cn:"\<lbrakk>y~=0; isnorm Q\<rbrakk> \<Longrightarrow> isnorm (mkPinj y Q)"
-apply(auto simp add: mkPinj_def norm_Pinj_0_False split: pol.split)
-apply(case_tac nat, auto simp add: norm_Pinj_0_False)
-by(case_tac pol, auto) (case_tac y, auto)
+lemma mkPinj_cn: "y ~= 0 \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (mkPinj y Q)"
+  apply (auto simp add: mkPinj_def norm_Pinj_0_False split: pol.split)
+  apply (case_tac nat, auto simp add: norm_Pinj_0_False)
+  apply (case_tac pol, auto)
+  apply (case_tac y, auto)
+  done

lemma norm_PXtrans:
-  assumes A:"isnorm (PX P x Q)" and "isnorm Q2"
+  assumes A: "isnorm (PX P x Q)" and "isnorm Q2"
shows "isnorm (PX P x Q2)"
-proof(cases P)
-  case (PX p1 y p2) with assms show ?thesis by(cases x, auto, cases p2, auto)
+proof (cases P)
+  case (PX p1 y p2)
+  with assms show ?thesis by (cases x) (auto, cases p2, auto)
next
-  case Pc with assms show ?thesis by (cases x) auto
+  case Pc
+  with assms show ?thesis by (cases x) auto
next
-  case Pinj with assms show ?thesis by (cases x) auto
+  case Pinj
+  with assms show ?thesis by (cases x) auto
qed

lemma norm_PXtrans2:
@@ -62,7 +66,7 @@
shows "isnorm (PX P (Suc (n+x)) Q2)"
proof (cases P)
case (PX p1 y p2)
-  with assms show ?thesis by (cases x, auto, cases p2, auto)
+  with assms show ?thesis by (cases x) (auto, cases p2, auto)
next
case Pc
with assms show ?thesis by (cases x) auto
@@ -83,27 +87,33 @@
with assms show ?thesis by (cases x) (auto simp add: mkPinj_cn mkPX_def)
next
case (PX P1 y P2)
-  with assms have Y0: "y>0" by (cases y) auto
+  with assms have Y0: "y > 0" by (cases y) auto
from assms PX have "isnorm P1" "isnorm P2"
by (auto simp add: norm_PX1[of P1 y P2] norm_PX2[of P1 y P2])
from assms PX Y0 show ?thesis
-    by (cases x, auto simp add: mkPX_def norm_PXtrans2[of P1 y _ Q _], cases P2, auto)
+    by (cases x) (auto simp add: mkPX_def norm_PXtrans2[of P1 y _ Q _], cases P2, auto)
qed

text {* add conserves normalizedness *}
-lemma add_cn:"isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<oplus> Q)"
-  case (2 c i P2) thus ?case by (cases P2, simp_all, cases i, simp_all)
+lemma add_cn: "isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<oplus> Q)"
+proof (induct P Q rule: add.induct)
+  case (2 c i P2)
+  thus ?case by (cases P2) (simp_all, cases i, simp_all)
next
-  case (3 i P2 c) thus ?case by (cases P2, simp_all, cases i, simp_all)
+  case (3 i P2 c)
+  thus ?case by (cases P2) (simp_all, cases i, simp_all)
next
case (4 c P2 i Q2)
-  then have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
-  with 4 show ?case by(cases i, simp, cases P2, auto, case_tac pol2, auto)
+  then have "isnorm P2" "isnorm Q2"
+    by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
+  with 4 show ?case
+    by (cases i) (simp, cases P2, auto, case_tac pol2, auto)
next
case (5 P2 i Q2 c)
-  then have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
-  with 5 show ?case by(cases i, simp, cases P2, auto, case_tac pol2, auto)
+  then have "isnorm P2" "isnorm Q2"
+    by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
+  with 5 show ?case
+    by (cases i) (simp, cases P2, auto, case_tac pol2, auto)
next
case (6 x P2 y Q2)
then have Y0: "y>0" by (cases y) (auto simp add: norm_Pinj_0_False)
@@ -115,14 +125,17 @@
moreover
note 6 X0
moreover
-    from 6 have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
+    from 6 have "isnorm P2" "isnorm Q2"
+      by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
moreover
-    from 6 `x < y` y have "isnorm (Pinj d Q2)" by (cases d, simp, cases Q2, auto)
+    from 6 `x < y` y have "isnorm (Pinj d Q2)"
+      by (cases d, simp, cases Q2, auto)
ultimately have ?case by (simp add: mkPinj_cn) }
moreover
{ assume "x=y"
moreover
-    from 6 have "isnorm P2" "isnorm Q2" by(auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
+    from 6 have "isnorm P2" "isnorm Q2"
+      by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
moreover
note 6 Y0
moreover
@@ -133,30 +146,35 @@
moreover
note 6 Y0
moreover
-    from 6 have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
+    from 6 have "isnorm P2" "isnorm Q2"
+      by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
moreover
-    from 6 `x > y` x have "isnorm (Pinj d P2)" by (cases d, simp, cases P2, auto)
-    ultimately have ?case by (simp add: mkPinj_cn)}
+    from 6 `x > y` x have "isnorm (Pinj d P2)"
+      by (cases d) (simp, cases P2, auto)
+    ultimately have ?case by (simp add: mkPinj_cn) }
ultimately show ?case by blast
next
case (7 x P2 Q2 y R)
-  have "x=0 \<or> (x = 1) \<or> (x > 1)" by arith
+  have "x = 0 \<or> x = 1 \<or> x > 1" by arith
moreover
{ assume "x = 0"
with 7 have ?case by (auto simp add: norm_Pinj_0_False) }
moreover
{ assume "x = 1"
-    from 7 have "isnorm R" "isnorm P2" by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
+    from 7 have "isnorm R" "isnorm P2"
+      by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
with 7 `x = 1` have "isnorm (R \<oplus> P2)" by simp
-    with 7 `x = 1` have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
+    with 7 `x = 1` have ?case
+      by (simp add: norm_PXtrans[of Q2 y _]) }
moreover
{ assume "x > 1" hence "EX d. x=Suc (Suc d)" by arith
-    then obtain d where X:"x=Suc (Suc d)" ..
+    then obtain d where X: "x=Suc (Suc d)" ..
with 7 have NR: "isnorm R" "isnorm P2"
by (auto simp add: norm_Pinj[of _ P2] norm_PX2[of Q2 y R])
with 7 X have "isnorm (Pinj (x - 1) P2)" by (cases P2) auto
with 7 X NR have "isnorm (R \<oplus> Pinj (x - 1) P2)" by simp
-    with `isnorm (PX Q2 y R)` X have ?case by (simp add: norm_PXtrans[of Q2 y _]) }
+    with `isnorm (PX Q2 y R)` X have ?case
+      by (simp add: norm_PXtrans[of Q2 y _]) }
ultimately show ?case by blast
next
case (8 Q2 y R x P2)
@@ -183,7 +201,7 @@
with 9 have X0: "x>0" by (cases x) auto
with 9 have NP1: "isnorm P1" and NP2: "isnorm P2"
by (auto simp add: norm_PX1[of P1 _ P2] norm_PX2[of P1 _ P2])
-  with 9 have NQ1:"isnorm Q1" and NQ2: "isnorm Q2"
+  with 9 have NQ1: "isnorm Q1" and NQ2: "isnorm Q2"
by (auto simp add: norm_PX1[of Q1 _ Q2] norm_PX2[of Q1 _ Q2])
have "y < x \<or> x = y \<or> x < y" by arith
moreover
@@ -194,7 +212,7 @@
have "isnorm (PX P1 d (Pc 0))"
proof (cases P1)
case (PX p1 y p2)
-      with 9 sm1 sm2 show ?thesis by - (cases d, simp, cases p2, auto)
+      with 9 sm1 sm2 show ?thesis by (cases d) (simp, cases p2, auto)
next
case Pc with 9 sm1 sm2 show ?thesis by (cases d) auto
next
@@ -214,35 +232,37 @@
have "isnorm (PX Q1 d (Pc 0))"
proof (cases Q1)
case (PX p1 y p2)
-      with 9 sm1 sm2 show ?thesis by - (cases d, simp, cases p2, auto)
+      with 9 sm1 sm2 show ?thesis by (cases d) (simp, cases p2, auto)
next
case Pc with 9 sm1 sm2 show ?thesis by (cases d) auto
next
case Pinj with 9 sm1 sm2 show ?thesis by (cases d) auto
qed
ultimately have "isnorm (P2 \<oplus> Q2)" "isnorm (PX Q1 (y - x) (Pc 0) \<oplus> P1)" by auto
-    with X0 sm1 sm2 have ?case by (simp add: mkPX_cn)}
+    with X0 sm1 sm2 have ?case by (simp add: mkPX_cn) }
ultimately show ?case by blast
qed simp

text {* mul concerves normalizedness *}
-lemma mul_cn :"isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<otimes> Q)"
-proof(induct P Q rule: mul.induct)
+lemma mul_cn: "isnorm P \<Longrightarrow> isnorm Q \<Longrightarrow> isnorm (P \<otimes> Q)"
+proof (induct P Q rule: mul.induct)
case (2 c i P2) thus ?case
-    by (cases P2, simp_all) (cases "i",simp_all add: mkPinj_cn)
+    by (cases P2) (simp_all, cases i, simp_all add: mkPinj_cn)
next
case (3 i P2 c) thus ?case
-    by (cases P2, simp_all) (cases "i",simp_all add: mkPinj_cn)
+    by (cases P2) (simp_all, cases i, simp_all add: mkPinj_cn)
next
case (4 c P2 i Q2)
-  then have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
+  then have "isnorm P2" "isnorm Q2"
+    by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
with 4 show ?case
-    by - (cases "c = 0", simp_all, cases "i = 0", simp_all add: mkPX_cn)
+    by (cases "c = 0") (simp_all, cases "i = 0", simp_all add: mkPX_cn)
next
case (5 P2 i Q2 c)
-  then have "isnorm P2" "isnorm Q2" by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
+  then have "isnorm P2" "isnorm Q2"
+    by (auto simp only: norm_PX1[of P2 i Q2] norm_PX2[of P2 i Q2])
with 5 show ?case
-    by - (cases "c = 0", simp_all, cases "i = 0", simp_all add: mkPX_cn)
+    by (cases "c = 0") (simp_all, cases "i = 0", simp_all add: mkPX_cn)
next
case (6 x P2 y Q2)
have "x < y \<or> x = y \<or> x > y" by arith
@@ -256,7 +276,7 @@
moreover
from 6 have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
moreover
-    from 6 `x < y` y have "isnorm (Pinj d Q2)" by - (cases d, simp, cases Q2, auto)
+    from 6 `x < y` y have "isnorm (Pinj d Q2)" by (cases d) (simp, cases Q2, auto)
ultimately have ?case by (simp add: mkPinj_cn) }
moreover
{ assume "x = y"
@@ -278,7 +298,7 @@
moreover
from 6 have "isnorm P2" "isnorm Q2" by (auto simp add: norm_Pinj[of _ P2] norm_Pinj[of _ Q2])
moreover
-    from 6 `x > y` x have "isnorm (Pinj d P2)" by - (cases d, simp, cases P2, auto)
+    from 6 `x > y` x have "isnorm (Pinj d P2)" by (cases d) (simp, cases P2, auto)
ultimately have ?case by (simp add: mkPinj_cn) }
ultimately show ?case by blast
next
@@ -356,7 +376,7 @@
proof (induct P)
case (Pinj i P2)
then have "isnorm P2" by (simp add: norm_Pinj[of i P2])
-  with Pinj show ?case by - (cases P2, auto, cases i, auto)
+  with Pinj show ?case by (cases P2) (auto, cases i, auto)
next
case (PX P1 x P2) note PX1 = this
from PX have "isnorm P2" "isnorm P1"
@@ -364,7 +384,7 @@
with PX show ?case
proof (cases P1)
case (PX p1 y p2)
-    with PX1 show ?thesis by - (cases x, auto, cases p2, auto)
+    with PX1 show ?thesis by (cases x) (auto, cases p2, auto)
next
case Pinj
with PX1 show ?thesis by (cases x) auto
@@ -372,15 +392,18 @@
qed simp

text {* sub conserves normalizedness *}
-lemma sub_cn:"isnorm p \<Longrightarrow> isnorm q \<Longrightarrow> isnorm (p \<ominus> q)"
+lemma sub_cn: "isnorm p \<Longrightarrow> isnorm q \<Longrightarrow> isnorm (p \<ominus> q)"

text {* sqr conserves normalizizedness *}
-lemma sqr_cn:"isnorm P \<Longrightarrow> isnorm (sqr P)"
+lemma sqr_cn: "isnorm P \<Longrightarrow> isnorm (sqr P)"
proof (induct P)
+  case Pc
+  then show ?case by simp
+next
case (Pinj i Q)
then show ?case
-    by - (cases Q, auto simp add: mkPX_cn mkPinj_cn, cases i, auto simp add: mkPX_cn mkPinj_cn)
+    by (cases Q) (auto simp add: mkPX_cn mkPinj_cn, cases i, auto simp add: mkPX_cn mkPinj_cn)
next
case (PX P1 x P2)
then have "x + x ~= 0" "isnorm P2" "isnorm P1"
@@ -389,20 +412,23 @@
and "isnorm (mkPX (sqr P1) (x + x) (sqr P2))"
-qed simp
+qed

text {* pow conserves normalizedness *}
-lemma pow_cn:"isnorm P \<Longrightarrow> isnorm (pow n P)"
-proof (induct n arbitrary: P rule: nat_less_induct)
-  case (1 k)
+lemma pow_cn: "isnorm P \<Longrightarrow> isnorm (pow n P)"
+proof (induct n arbitrary: P rule: less_induct)
+  case (less k)
show ?case
proof (cases "k = 0")
+    case True
+    then show ?thesis by simp
+  next
case False
then have K2: "k div 2 < k" by (cases k) auto
-    from 1 have "isnorm (sqr P)" by (simp add: sqr_cn)
-    with 1 False K2 show ?thesis
-      by - (simp add: allE[of _ "(k div 2)" _] allE[of _ "(sqr P)" _], cases k, auto simp add: mul_cn)
-  qed simp
+    from less have "isnorm (sqr P)" by (simp add: sqr_cn)
+    with less False K2 show ?thesis
+      by (simp add: allE[of _ "(k div 2)" _] allE[of _ "(sqr P)" _], cases k, auto simp add: mul_cn)
+  qed
qed

end```
```--- a/src/HOL/Decision_Procs/Ferrack.thy	Wed Sep 07 11:36:39 2011 +0200
+++ b/src/HOL/Decision_Procs/Ferrack.thy	Wed Sep 07 16:37:50 2011 +0200
@@ -676,13 +676,13 @@
{assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
moreover
{ assume nnz: "n \<noteq> 0"
-    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci) }
+    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def) }
moreover
{assume g1:"?g>1" hence g0: "?g > 0" by simp
from g1 nnz have gp0: "?g' \<noteq> 0" by simp
hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
hence "?g'= 1 \<or> ?g' > 1" by arith
-      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)}
+      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
moreover {assume g'1:"?g'>1"
from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
let ?tt = "reducecoeffh ?t' ?g'"
@@ -800,32 +800,34 @@
proof(induct p rule: simpfm.induct)
case (6 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
next
case (7 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
next
case (8 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
next
case (9 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
next
case (10 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
next
case (11 a) hence nb: "numbound0 a" by simp
hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
-  thus ?case by (cases "simpnum a", auto simp add: Let_def)
+  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
qed(auto simp add: disj_def imp_def iff_def conj_def not_bn)

lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)"
-by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def)
- (case_tac "simpnum a",auto)+
+  apply (induct p rule: simpfm.induct)
+  apply (auto simp add: Let_def)
+  apply (case_tac "simpnum a", auto)+
+  done

consts prep :: "fm \<Rightarrow> fm"
recdef prep "measure fmsize"
@@ -854,7 +856,7 @@
"prep p = p"
lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
-by (induct p rule: prep.induct, auto)
+  by (induct p rule: prep.induct) auto

(* Generic quantifier elimination *)
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where
@@ -1037,7 +1039,7 @@
assumes qfp: "qfree p"
shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)"
using qfp
-by (induct p rule: rlfm.induct, auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin)
+by (induct p rule: rlfm.induct) (auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin)

(* Operations needed for Ferrante and Rackoff *)
lemma rminusinf_inf:
@@ -1045,9 +1047,11 @@
shows "\<exists> z. \<forall> x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p")
using lp
proof (induct p rule: minusinf.induct)
-  case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto
+  case (1 p q)
+  thus ?case apply auto apply (rule_tac x= "min z za" in exI) apply auto done
next
-  case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto
+  case (2 p q)
+  thus ?case apply auto apply (rule_tac x= "min z za" in exI) apply auto done
next
case (3 c e)
from 3 have nb: "numbound0 e" by simp```
```--- a/src/HOL/Library/Abstract_Rat.thy	Wed Sep 07 11:36:39 2011 +0200
+++ b/src/HOL/Library/Abstract_Rat.thy	Wed Sep 07 16:37:50 2011 +0200
@@ -10,64 +10,58 @@

type_synonym Num = "int \<times> int"

-abbreviation
-  Num0_syn :: Num ("0\<^sub>N")
-where "0\<^sub>N \<equiv> (0, 0)"
+abbreviation Num0_syn :: Num ("0\<^sub>N")
+  where "0\<^sub>N \<equiv> (0, 0)"

-abbreviation
-  Numi_syn :: "int \<Rightarrow> Num" ("_\<^sub>N")
-where "i\<^sub>N \<equiv> (i, 1)"
+abbreviation Numi_syn :: "int \<Rightarrow> Num" ("_\<^sub>N")
+  where "i\<^sub>N \<equiv> (i, 1)"

-definition
-  isnormNum :: "Num \<Rightarrow> bool"
-where
+definition isnormNum :: "Num \<Rightarrow> bool" where
"isnormNum = (\<lambda>(a,b). (if a = 0 then b = 0 else b > 0 \<and> gcd a b = 1))"

-definition
-  normNum :: "Num \<Rightarrow> Num"
-where
-  "normNum = (\<lambda>(a,b). (if a=0 \<or> b = 0 then (0,0) else
-  (let g = gcd a b
-   in if b > 0 then (a div g, b div g) else (- (a div g), - (b div g)))))"
+definition normNum :: "Num \<Rightarrow> Num" where
+  "normNum = (\<lambda>(a,b).
+    (if a=0 \<or> b = 0 then (0,0) else
+      (let g = gcd a b
+       in if b > 0 then (a div g, b div g) else (- (a div g), - (b div g)))))"

-declare gcd_dvd1_int[presburger]
-declare gcd_dvd2_int[presburger]
+declare gcd_dvd1_int[presburger] gcd_dvd2_int[presburger]
+
lemma normNum_isnormNum [simp]: "isnormNum (normNum x)"
proof -
have " \<exists> a b. x = (a,b)" by auto
then obtain a b where x[simp]: "x = (a,b)" by blast
-  {assume "a=0 \<or> b = 0" hence ?thesis by (simp add: normNum_def isnormNum_def)}
+  { assume "a=0 \<or> b = 0" hence ?thesis by (simp add: normNum_def isnormNum_def) }
moreover
-  {assume anz: "a \<noteq> 0" and bnz: "b \<noteq> 0"
+  { assume anz: "a \<noteq> 0" and bnz: "b \<noteq> 0"
let ?g = "gcd a b"
let ?a' = "a div ?g"
let ?b' = "b div ?g"
let ?g' = "gcd ?a' ?b'"
-    from anz bnz have "?g \<noteq> 0" by simp  with gcd_ge_0_int[of a b]
+    from anz bnz have "?g \<noteq> 0" by simp  with gcd_ge_0_int[of a b]
have gpos: "?g > 0" by arith
-    have gdvd: "?g dvd a" "?g dvd b" by arith+
-    from zdvd_mult_div_cancel[OF gdvd(1)] zdvd_mult_div_cancel[OF gdvd(2)]
-    anz bnz
-    have nz':"?a' \<noteq> 0" "?b' \<noteq> 0"
-      by - (rule notI, simp)+
-    from anz bnz have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by arith
+    have gdvd: "?g dvd a" "?g dvd b" by arith+
+    from zdvd_mult_div_cancel[OF gdvd(1)] zdvd_mult_div_cancel[OF gdvd(2)] anz bnz
+    have nz':"?a' \<noteq> 0" "?b' \<noteq> 0" by - (rule notI, simp)+
+    from anz bnz have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by arith
from div_gcd_coprime_int[OF stupid] have gp1: "?g' = 1" .
from bnz have "b < 0 \<or> b > 0" by arith
moreover
-    {assume b: "b > 0"
-      from b have "?b' \<ge> 0"
-        by (presburger add: pos_imp_zdiv_nonneg_iff[OF gpos])
+    { assume b: "b > 0"
+      from b have "?b' \<ge> 0"
+        by (presburger add: pos_imp_zdiv_nonneg_iff[OF gpos])
with nz' have b': "?b' > 0" by arith
from b b' anz bnz nz' gp1 have ?thesis
-        by (simp add: isnormNum_def normNum_def Let_def split_def fst_conv snd_conv)}
-    moreover {assume b: "b < 0"
-      {assume b': "?b' \<ge> 0"
+        by (simp add: isnormNum_def normNum_def Let_def split_def)}
+    moreover {
+      assume b: "b < 0"
+      { assume b': "?b' \<ge> 0"
from gpos have th: "?g \<ge> 0" by arith
from mult_nonneg_nonneg[OF th b'] zdvd_mult_div_cancel[OF gdvd(2)]
have False using b by arith }
-      hence b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
+      hence b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
from anz bnz nz' b b' gp1 have ?thesis
-        by (simp add: isnormNum_def normNum_def Let_def split_def)}
+        by (simp add: isnormNum_def normNum_def Let_def split_def) }
ultimately have ?thesis by blast
}
ultimately show ?thesis by blast
@@ -75,50 +69,42 @@

text {* Arithmetic over Num *}

-definition
-  Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "+\<^sub>N" 60)
-where
-  "Nadd = (\<lambda>(a,b) (a',b'). if a = 0 \<or> b = 0 then normNum(a',b')
+definition Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "+\<^sub>N" 60) where
+  "Nadd = (\<lambda>(a,b) (a',b'). if a = 0 \<or> b = 0 then normNum(a',b')
else if a'=0 \<or> b' = 0 then normNum(a,b)
else normNum(a*b' + b*a', b*b'))"

-definition
-  Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "*\<^sub>N" 60)
-where
+definition Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "*\<^sub>N" 60) where
"Nmul = (\<lambda>(a,b) (a',b'). let g = gcd (a*a') (b*b')
in (a*a' div g, b*b' div g))"

-definition
-  Nneg :: "Num \<Rightarrow> Num" ("~\<^sub>N")
-where
-  "Nneg \<equiv> (\<lambda>(a,b). (-a,b))"
+definition Nneg :: "Num \<Rightarrow> Num" ("~\<^sub>N")
+  where "Nneg \<equiv> (\<lambda>(a,b). (-a,b))"

-definition
-  Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "-\<^sub>N" 60)
-where
-  "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"
+definition Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "-\<^sub>N" 60)
+  where "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"

-definition
-  Ninv :: "Num \<Rightarrow> Num"
-where
-  "Ninv \<equiv> \<lambda>(a,b). if a < 0 then (-b, \<bar>a\<bar>) else (b,a)"
+definition Ninv :: "Num \<Rightarrow> Num"
+  where "Ninv = (\<lambda>(a,b). if a < 0 then (-b, \<bar>a\<bar>) else (b,a))"

-definition
-  Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "\<div>\<^sub>N" 60)
-where
-  "Ndiv \<equiv> \<lambda>a b. a *\<^sub>N Ninv b"
+definition Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "\<div>\<^sub>N" 60)
+  where "Ndiv = (\<lambda>a b. a *\<^sub>N Ninv b)"

lemma Nneg_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (~\<^sub>N x)"
-  by(simp add: isnormNum_def Nneg_def split_def)
+  by (simp add: isnormNum_def Nneg_def split_def)
+
lemma Nadd_normN[simp]: "isnormNum (x +\<^sub>N y)"
+
lemma Nsub_normN[simp]: "\<lbrakk> isnormNum y\<rbrakk> \<Longrightarrow> isnormNum (x -\<^sub>N y)"
-lemma Nmul_normN[simp]: assumes xn:"isnormNum x" and yn: "isnormNum y"
+
+lemma Nmul_normN[simp]:
+  assumes xn:"isnormNum x" and yn: "isnormNum y"
shows "isnormNum (x *\<^sub>N y)"
-proof-
+proof -
have "\<exists>a b. x = (a,b)" and "\<exists> a' b'. y = (a',b')" by auto
-  then obtain a b a' b' where ab: "x = (a,b)"  and ab': "y = (a',b')" by blast
+  then obtain a b a' b' where ab: "x = (a,b)"  and ab': "y = (a',b')" by blast
{assume "a = 0"
hence ?thesis using xn ab ab'
by (simp add: isnormNum_def Let_def Nmul_def split_def)}
@@ -146,38 +132,25 @@

text {* Relations over Num *}

-definition
-  Nlt0:: "Num \<Rightarrow> bool" ("0>\<^sub>N")
-where
-  "Nlt0 = (\<lambda>(a,b). a < 0)"
+definition Nlt0:: "Num \<Rightarrow> bool" ("0>\<^sub>N")
+  where "Nlt0 = (\<lambda>(a,b). a < 0)"

-definition
-  Nle0:: "Num \<Rightarrow> bool" ("0\<ge>\<^sub>N")
-where
-  "Nle0 = (\<lambda>(a,b). a \<le> 0)"
+definition Nle0:: "Num \<Rightarrow> bool" ("0\<ge>\<^sub>N")
+  where "Nle0 = (\<lambda>(a,b). a \<le> 0)"

-definition
-  Ngt0:: "Num \<Rightarrow> bool" ("0<\<^sub>N")
-where
-  "Ngt0 = (\<lambda>(a,b). a > 0)"
+definition Ngt0:: "Num \<Rightarrow> bool" ("0<\<^sub>N")
+  where "Ngt0 = (\<lambda>(a,b). a > 0)"

-definition
-  Nge0:: "Num \<Rightarrow> bool" ("0\<le>\<^sub>N")
-where
-  "Nge0 = (\<lambda>(a,b). a \<ge> 0)"
+definition Nge0:: "Num \<Rightarrow> bool" ("0\<le>\<^sub>N")
+  where "Nge0 = (\<lambda>(a,b). a \<ge> 0)"

-definition
-  Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "<\<^sub>N" 55)
-where
-  "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"
+definition Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "<\<^sub>N" 55)
+  where "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"

-definition
-  Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "\<le>\<^sub>N" 55)
-where
-  "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"
+definition Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool"  (infix "\<le>\<^sub>N" 55)
+  where "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"

-definition
-  "INum = (\<lambda>(a,b). of_int a / of_int b)"
+definition "INum = (\<lambda>(a,b). of_int a / of_int b)"

lemma INum_int [simp]: "INum (i\<^sub>N) = ((of_int i) ::'a::field)" "INum 0\<^sub>N = (0::'a::field)"
@@ -189,9 +162,9 @@
have "\<exists> a b a' b'. x = (a,b) \<and> y = (a',b')" by auto
then obtain a b a' b' where xy[simp]: "x = (a,b)" "y=(a',b')" by blast
assume H: ?lhs
-  {assume "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0"
+  { assume "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0"
hence ?rhs using na nb H
-      by (simp add: INum_def split_def isnormNum_def split: split_if_asm)}
+      by (simp add: INum_def split_def isnormNum_def split: split_if_asm) }
moreover
{ assume az: "a \<noteq> 0" and bz: "b \<noteq> 0" and a'z: "a'\<noteq>0" and b'z: "b'\<noteq>0"
from az bz a'z b'z na nb have pos: "b > 0" "b' > 0" by (simp_all add: isnormNum_def)
@@ -217,9 +190,10 @@
qed

-lemma isnormNum0[simp]: "isnormNum x \<Longrightarrow> (INum x = (0::'a::{field_char_0, field_inverse_zero})) = (x = 0\<^sub>N)"
+lemma isnormNum0[simp]:
+    "isnormNum x \<Longrightarrow> (INum x = (0::'a::{field_char_0, field_inverse_zero})) = (x = 0\<^sub>N)"
unfolding INum_int(2)[symmetric]
-  by (rule isnormNum_unique, simp_all)
+  by (rule isnormNum_unique) simp_all

lemma of_int_div_aux: "d ~= 0 ==> ((of_int x)::'a::field_char_0) / (of_int d) =
of_int (x div d) + (of_int (x mod d)) / ((of_int d)::'a)"
@@ -241,25 +215,27 @@
apply (frule of_int_div_aux [of d n, where ?'a = 'a])
apply simp
-done
+  done

lemma normNum[simp]: "INum (normNum x) = (INum x :: 'a::{field_char_0, field_inverse_zero})"
-proof-
+proof -
have "\<exists> a b. x = (a,b)" by auto
-  then obtain a b where x[simp]: "x = (a,b)" by blast
-  {assume "a=0 \<or> b = 0" hence ?thesis
-      by (simp add: INum_def normNum_def split_def Let_def)}
+  then obtain a b where x: "x = (a,b)" by blast
+  { assume "a=0 \<or> b = 0" hence ?thesis
+      by (simp add: x INum_def normNum_def split_def Let_def)}
moreover
-  {assume a: "a\<noteq>0" and b: "b\<noteq>0"
+  { assume a: "a\<noteq>0" and b: "b\<noteq>0"
let ?g = "gcd a b"
from a b have g: "?g \<noteq> 0"by simp
from of_int_div[OF g, where ?'a = 'a]
-    have ?thesis by (auto simp add: INum_def normNum_def split_def Let_def)}
+    have ?thesis by (auto simp add: x INum_def normNum_def split_def Let_def) }
ultimately show ?thesis by blast
qed

-lemma INum_normNum_iff: "(INum x ::'a::{field_char_0, field_inverse_zero}) = INum y \<longleftrightarrow> normNum x = normNum y" (is "?lhs = ?rhs")
+lemma INum_normNum_iff:
+  "(INum x ::'a::{field_char_0, field_inverse_zero}) = INum y \<longleftrightarrow> normNum x = normNum y"
+  (is "?lhs = ?rhs")
proof -
have "normNum x = normNum y \<longleftrightarrow> (INum (normNum x) :: 'a) = INum (normNum y)"
by (simp del: normNum)
@@ -268,139 +244,159 @@
qed

lemma Nadd[simp]: "INum (x +\<^sub>N y) = INum x + (INum y :: 'a :: {field_char_0, field_inverse_zero})"
-proof-
-let ?z = "0:: 'a"
-  have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
-  then obtain a b a' b' where x[simp]: "x = (a,b)"
+proof -
+  let ?z = "0:: 'a"
+  have "\<exists>a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
+  then obtain a b a' b' where x: "x = (a,b)"
and y[simp]: "y = (a',b')" by blast
-  {assume "a=0 \<or> a'= 0 \<or> b =0 \<or> b' = 0" hence ?thesis
-      apply (cases "b= 0",simp_all add: INum_def)
-       apply (cases "a'= 0",simp_all)
-       apply (cases "b'= 0",simp_all)
+  { assume "a=0 \<or> a'= 0 \<or> b =0 \<or> b' = 0"
+    hence ?thesis
+      apply (cases "b= 0", simp_all add: INum_def)
+       apply (cases "a'= 0", simp_all)
+       apply (cases "b'= 0", simp_all)
done }
moreover
-  {assume aa':"a \<noteq> 0" "a'\<noteq> 0" and bb': "b \<noteq> 0" "b' \<noteq> 0"
-    {assume z: "a * b' + b * a' = 0"
+  { assume aa':"a \<noteq> 0" "a'\<noteq> 0" and bb': "b \<noteq> 0" "b' \<noteq> 0"
+    { assume z: "a * b' + b * a' = 0"
hence "of_int (a*b' + b*a') / (of_int b* of_int b') = ?z" by simp
-      hence "of_int b' * of_int a / (of_int b * of_int b') + of_int b * of_int a' / (of_int b * of_int b') = ?z"  by (simp add:add_divide_distrib)
-      hence th: "of_int a / of_int b + of_int a' / of_int b' = ?z" using bb' aa' by simp
+      hence "of_int b' * of_int a / (of_int b * of_int b') + of_int b * of_int a' / (of_int b * of_int b') = ?z"
+      hence th: "of_int a / of_int b + of_int a' / of_int b' = ?z" using bb' aa'
+        by simp
from z aa' bb' have ?thesis
-    moreover {assume z: "a * b' + b * a' \<noteq> 0"
+    moreover {
+      assume z: "a * b' + b * a' \<noteq> 0"
let ?g = "gcd (a * b' + b * a') (b*b')"
have gz: "?g \<noteq> 0" using z by simp
have ?thesis using aa' bb' z gz
-        of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a * b' + b * a'" and y="b*b'"]]  of_int_div[where ?'a = 'a,
-        OF gz gcd_dvd2_int[where x="a * b' + b * a'" and y="b*b'"]]
-    ultimately have ?thesis using aa' bb'
+        of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a * b' + b * a'" and y="b*b'"]]
+        of_int_div[where ?'a = 'a, OF gz gcd_dvd2_int[where x="a * b' + b * a'" and y="b*b'"]]
+    ultimately have ?thesis using aa' bb'
ultimately show ?thesis by blast
qed

-lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a :: {field_char_0, field_inverse_zero}) "
-proof-
+lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a :: {field_char_0, field_inverse_zero})"
+proof -
let ?z = "0::'a"
-  have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
+  have "\<exists>a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
then obtain a b a' b' where x: "x = (a,b)" and y: "y = (a',b')" by blast
-  {assume "a=0 \<or> a'= 0 \<or> b = 0 \<or> b' = 0" hence ?thesis
-      apply (cases "a=0",simp_all add: x y Nmul_def INum_def Let_def)
-      apply (cases "b=0",simp_all)
-      apply (cases "a'=0",simp_all)
+  { assume "a=0 \<or> a'= 0 \<or> b = 0 \<or> b' = 0"
+    hence ?thesis
+      apply (cases "a=0", simp_all add: x y Nmul_def INum_def Let_def)
+      apply (cases "b=0", simp_all)
+      apply (cases "a'=0", simp_all)
done }
moreover
-  {assume z: "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
+  { assume z: "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
let ?g="gcd (a*a') (b*b')"
have gz: "?g \<noteq> 0" using z by simp
-    from z of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a*a'" and y="b*b'"]]
+    from z of_int_div[where ?'a = 'a, OF gz gcd_dvd1_int[where x="a*a'" and y="b*b'"]]
of_int_div[where ?'a = 'a , OF gz gcd_dvd2_int[where x="a*a'" and y="b*b'"]]
-    have ?thesis by (simp add: Nmul_def x y Let_def INum_def)}
+    have ?thesis by (simp add: Nmul_def x y Let_def INum_def) }
ultimately show ?thesis by blast
qed

lemma Nneg[simp]: "INum (~\<^sub>N x) = - (INum x ::'a:: field)"
by (simp add: Nneg_def split_def INum_def)

-lemma Nsub[simp]: shows "INum (x -\<^sub>N y) = INum x - (INum y:: 'a :: {field_char_0, field_inverse_zero})"
+lemma Nsub[simp]: "INum (x -\<^sub>N y) = INum x - (INum y:: 'a :: {field_char_0, field_inverse_zero})"
+  by (simp add: Nsub_def split_def)

lemma Ninv[simp]: "INum (Ninv x) = (1::'a :: field_inverse_zero) / (INum x)"
by (simp add: Ninv_def INum_def split_def)

-lemma Ndiv[simp]: "INum (x \<div>\<^sub>N y) = INum x / (INum y ::'a :: {field_char_0, field_inverse_zero})" by (simp add: Ndiv_def)
+lemma Ndiv[simp]: "INum (x \<div>\<^sub>N y) = INum x / (INum y ::'a :: {field_char_0, field_inverse_zero})"

-lemma Nlt0_iff[simp]: assumes nx: "isnormNum x"
-  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})< 0) = 0>\<^sub>N x "
-proof-
-  have " \<exists> a b. x = (a,b)" by simp
+lemma Nlt0_iff[simp]:
+  assumes nx: "isnormNum x"
+  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})< 0) = 0>\<^sub>N x"
+proof -
+  have "\<exists> a b. x = (a,b)" by simp
then obtain a b where x[simp]:"x = (a,b)" by blast
{assume "a = 0" hence ?thesis by (simp add: Nlt0_def INum_def) }
moreover
-  {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
+  { assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
from pos_divide_less_eq[OF b, where b="of_int a" and a="0::'a"]
-    have ?thesis by (simp add: Nlt0_def INum_def)}
+    have ?thesis by (simp add: Nlt0_def INum_def) }
ultimately show ?thesis by blast
qed

-lemma Nle0_iff[simp]:assumes nx: "isnormNum x"
+lemma Nle0_iff[simp]:
+  assumes nx: "isnormNum x"
shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) \<le> 0) = 0\<ge>\<^sub>N x"
-proof-
-  have " \<exists> a b. x = (a,b)" by simp
+proof -
+  have "\<exists>a b. x = (a,b)" by simp
then obtain a b where x[simp]:"x = (a,b)" by blast
-  {assume "a = 0" hence ?thesis by (simp add: Nle0_def INum_def) }
+  { assume "a = 0" hence ?thesis by (simp add: Nle0_def INum_def) }
moreover
-  {assume a: "a\<noteq>0" hence b: "(of_int b :: 'a) > 0" using nx by (simp add: isnormNum_def)
+  { assume a: "a\<noteq>0" hence b: "(of_int b :: 'a) > 0" using nx by (simp add: isnormNum_def)
from pos_divide_le_eq[OF b, where b="of_int a" and a="0::'a"]
have ?thesis by (simp add: Nle0_def INum_def)}
ultimately show ?thesis by blast
qed

-lemma Ngt0_iff[simp]:assumes nx: "isnormNum x" shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})> 0) = 0<\<^sub>N x"
-proof-
-  have " \<exists> a b. x = (a,b)" by simp
+lemma Ngt0_iff[simp]:
+  assumes nx: "isnormNum x"
+  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})> 0) = 0<\<^sub>N x"
+proof -
+  have "\<exists> a b. x = (a,b)" by simp
then obtain a b where x[simp]:"x = (a,b)" by blast
-  {assume "a = 0" hence ?thesis by (simp add: Ngt0_def INum_def) }
+  { assume "a = 0" hence ?thesis by (simp add: Ngt0_def INum_def) }
moreover
-  {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
+  { assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx
from pos_less_divide_eq[OF b, where b="of_int a" and a="0::'a"]
-    have ?thesis by (simp add: Ngt0_def INum_def)}
-  ultimately show ?thesis by blast
-qed
-lemma Nge0_iff[simp]:assumes nx: "isnormNum x"
-  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) \<ge> 0) = 0\<le>\<^sub>N x"
-proof-
-  have " \<exists> a b. x = (a,b)" by simp
-  then obtain a b where x[simp]:"x = (a,b)" by blast
-  {assume "a = 0" hence ?thesis by (simp add: Nge0_def INum_def) }
-  moreover
-  {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
-    from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
-    have ?thesis by (simp add: Nge0_def INum_def)}
+    have ?thesis by (simp add: Ngt0_def INum_def) }
ultimately show ?thesis by blast
qed

-lemma Nlt_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
+lemma Nge0_iff[simp]:
+  assumes nx: "isnormNum x"
+  shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) \<ge> 0) = 0\<le>\<^sub>N x"
+proof -
+  have "\<exists> a b. x = (a,b)" by simp
+  then obtain a b where x[simp]:"x = (a,b)" by blast
+  { assume "a = 0" hence ?thesis by (simp add: Nge0_def INum_def) }
+  moreover
+  { assume "a \<noteq> 0" hence b: "(of_int b::'a) > 0" using nx
+    from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
+    have ?thesis by (simp add: Nge0_def INum_def) }
+  ultimately show ?thesis by blast
+qed
+
+lemma Nlt_iff[simp]:
+  assumes nx: "isnormNum x" and ny: "isnormNum y"
shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero}) < INum y) = (x <\<^sub>N y)"
-proof-
+proof -
let ?z = "0::'a"
-  have "((INum x ::'a) < INum y) = (INum (x -\<^sub>N y) < ?z)" using nx ny by simp
-  also have "\<dots> = (0>\<^sub>N (x -\<^sub>N y))" using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
+  have "((INum x ::'a) < INum y) = (INum (x -\<^sub>N y) < ?z)"
+    using nx ny by simp
+  also have "\<dots> = (0>\<^sub>N (x -\<^sub>N y))"
+    using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
finally show ?thesis by (simp add: Nlt_def)
qed

-lemma Nle_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
+lemma Nle_iff[simp]:
+  assumes nx: "isnormNum x" and ny: "isnormNum y"
shows "((INum x :: 'a :: {field_char_0, linordered_field_inverse_zero})\<le> INum y) = (x \<le>\<^sub>N y)"
-proof-
-  have "((INum x ::'a) \<le> INum y) = (INum (x -\<^sub>N y) \<le> (0::'a))" using nx ny by simp
-  also have "\<dots> = (0\<ge>\<^sub>N (x -\<^sub>N y))" using Nle0_iff[OF Nsub_normN[OF ny]] by simp
+proof -
+  have "((INum x ::'a) \<le> INum y) = (INum (x -\<^sub>N y) \<le> (0::'a))"
+    using nx ny by simp
+  also have "\<dots> = (0\<ge>\<^sub>N (x -\<^sub>N y))"
+    using Nle0_iff[OF Nsub_normN[OF ny]] by simp
finally show ?thesis by (simp add: Nle_def)
qed

assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
shows "x +\<^sub>N y = y +\<^sub>N x"
-proof-
+proof -
have n: "isnormNum (x +\<^sub>N y)" "isnormNum (y +\<^sub>N x)" by simp_all
have "(INum (x +\<^sub>N y)::'a) = INum (y +\<^sub>N x)" by simp
with isnormNum_unique[OF n] show ?thesis by simp
@@ -422,12 +418,11 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
assumes nx: "isnormNum x"
shows "normNum x = x"
-proof-
+proof -
let ?a = "normNum x"
have n: "isnormNum ?a" by simp
-  have th:"INum ?a = (INum x ::'a)" by simp
-  with isnormNum_unique[OF n nx]
-  show ?thesis by simp
+  have th: "INum ?a = (INum x ::'a)" by simp
+  with isnormNum_unique[OF n nx] show ?thesis by simp
qed

lemma normNum_nilpotent[simp]:
@@ -445,7 +440,7 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
shows "normNum x +\<^sub>N y = x +\<^sub>N y"
-proof-
+proof -
have n: "isnormNum (normNum x +\<^sub>N y)" "isnormNum (x +\<^sub>N y)" by simp_all
have "INum (normNum x +\<^sub>N y) = INum x + (INum y :: 'a)" by simp
also have "\<dots> = INum (x +\<^sub>N y)" by simp
@@ -455,7 +450,7 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
shows "x +\<^sub>N normNum y = x +\<^sub>N y"
-proof-
+proof -
have n: "isnormNum (x +\<^sub>N normNum y)" "isnormNum (x +\<^sub>N y)" by simp_all
have "INum (x +\<^sub>N normNum y) = INum x + (INum y :: 'a)" by simp
also have "\<dots> = INum (x +\<^sub>N y)" by simp
@@ -465,7 +460,7 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
shows "x +\<^sub>N y +\<^sub>N z = x +\<^sub>N (y +\<^sub>N z)"
-proof-
+proof -
have n: "isnormNum (x +\<^sub>N y +\<^sub>N z)" "isnormNum (x +\<^sub>N (y +\<^sub>N z))" by simp_all
have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)" by simp
with isnormNum_unique[OF n] show ?thesis by simp
@@ -478,7 +473,7 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
assumes nx: "isnormNum x" and ny:"isnormNum y" and nz:"isnormNum z"
shows "x *\<^sub>N y *\<^sub>N z = x *\<^sub>N (y *\<^sub>N z)"
-proof-
+proof -
from nx ny nz have n: "isnormNum (x *\<^sub>N y *\<^sub>N z)" "isnormNum (x *\<^sub>N (y *\<^sub>N z))"
by simp_all
have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a)" by simp
@@ -488,13 +483,13 @@
lemma Nsub0:
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
assumes x: "isnormNum x" and y:"isnormNum y" shows "(x -\<^sub>N y = 0\<^sub>N) = (x = y)"
-proof-
-  { fix h :: 'a
-    from isnormNum_unique[where 'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
-    have "(x -\<^sub>N y = 0\<^sub>N) = (INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)) " by simp
-    also have "\<dots> = (INum x = (INum y :: 'a))" by simp
-    also have "\<dots> = (x = y)" using x y by simp
-    finally show ?thesis . }
+proof -
+  fix h :: 'a
+  from isnormNum_unique[where 'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
+  have "(x -\<^sub>N y = 0\<^sub>N) = (INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)) " by simp
+  also have "\<dots> = (INum x = (INum y :: 'a))" by simp
+  also have "\<dots> = (x = y)" using x y by simp
+  finally show ?thesis .
qed

lemma Nmul0[simp]: "c *\<^sub>N 0\<^sub>N = 0\<^sub>N" " 0\<^sub>N *\<^sub>N c = 0\<^sub>N"
@@ -504,16 +499,18 @@
assumes "SORT_CONSTRAINT('a::{field_char_0, field_inverse_zero})"
assumes nx:"isnormNum x" and ny: "isnormNum y"
shows "(x*\<^sub>N y = 0\<^sub>N) = (x = 0\<^sub>N \<or> y = 0\<^sub>N)"
-proof-
-  { fix h :: 'a
-    have " \<exists> a b a' b'. x = (a,b) \<and> y= (a',b')" by auto
-    then obtain a b a' b' where xy[simp]: "x = (a,b)" "y = (a',b')" by blast
-    have n0: "isnormNum 0\<^sub>N" by simp
-    show ?thesis using nx ny
-      apply (simp only: isnormNum_unique[where ?'a = 'a, OF  Nmul_normN[OF nx ny] n0, symmetric] Nmul[where ?'a = 'a])
-      by (simp add: INum_def split_def isnormNum_def split: split_if_asm)
-  }
+proof -
+  fix h :: 'a
+  have " \<exists> a b a' b'. x = (a,b) \<and> y= (a',b')" by auto
+  then obtain a b a' b' where xy[simp]: "x = (a,b)" "y = (a',b')" by blast
+  have n0: "isnormNum 0\<^sub>N" by simp
+  show ?thesis using nx ny
+    apply (simp only: isnormNum_unique[where ?'a = 'a, OF  Nmul_normN[OF nx ny] n0, symmetric]
+      Nmul[where ?'a = 'a])
+    apply (simp add: INum_def split_def isnormNum_def split: split_if_asm)
+    done
qed
+
lemma Nneg_Nneg[simp]: "~\<^sub>N (~\<^sub>N c) = c"