1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/HOL/Library/Abstract_Rat.thy Thu Aug 09 15:52:49 2007 +0200
1.3 @@ -0,0 +1,502 @@
1.4 +(* Title: HOL/Library/Abstract_Rat.thy
1.5 + ID: $Id$
1.6 + Author: Amine Chaieb
1.7 +*)
1.8 +
1.9 +header {* Abstract rational numbers *}
1.10 +
1.11 +theory Abstract_Rat
1.12 +imports GCD
1.13 +begin
1.14 +
1.15 +types Num = "int \<times> int"
1.16 +syntax "_Num0" :: "Num" ("0\<^sub>N")
1.17 +translations "0\<^sub>N" \<rightleftharpoons> "(0, 0)"
1.18 +syntax "_Numi" :: "int \<Rightarrow> Num" ("_\<^sub>N")
1.19 +translations "i\<^sub>N" \<rightleftharpoons> "(i, 1) \<Colon> Num"
1.20 +
1.21 +definition
1.22 + isnormNum :: "Num \<Rightarrow> bool"
1.23 +where
1.24 + "isnormNum = (\<lambda>(a,b). (if a = 0 then b = 0 else b > 0 \<and> igcd a b = 1))"
1.25 +
1.26 +definition
1.27 + normNum :: "Num \<Rightarrow> Num"
1.28 +where
1.29 + "normNum = (\<lambda>(a,b). (if a=0 \<or> b = 0 then (0,0) else
1.30 + (let g = igcd a b
1.31 + in if b > 0 then (a div g, b div g) else (- (a div g), - (b div g)))))"
1.32 +
1.33 +lemma normNum_isnormNum [simp]: "isnormNum (normNum x)"
1.34 +proof -
1.35 + have " \<exists> a b. x = (a,b)" by auto
1.36 + then obtain a b where x[simp]: "x = (a,b)" by blast
1.37 + {assume "a=0 \<or> b = 0" hence ?thesis by (simp add: normNum_def isnormNum_def)}
1.38 + moreover
1.39 + {assume anz: "a \<noteq> 0" and bnz: "b \<noteq> 0"
1.40 + let ?g = "igcd a b"
1.41 + let ?a' = "a div ?g"
1.42 + let ?b' = "b div ?g"
1.43 + let ?g' = "igcd ?a' ?b'"
1.44 + from anz bnz have "?g \<noteq> 0" by simp with igcd_pos[of a b]
1.45 + have gpos: "?g > 0" by arith
1.46 + have gdvd: "?g dvd a" "?g dvd b" by (simp_all add: igcd_dvd1 igcd_dvd2)
1.47 + from zdvd_mult_div_cancel[OF gdvd(1)] zdvd_mult_div_cancel[OF gdvd(2)]
1.48 + anz bnz
1.49 + have nz':"?a' \<noteq> 0" "?b' \<noteq> 0"
1.50 + by - (rule notI,simp add:igcd_def)+
1.51 + from anz bnz have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by blast
1.52 + from div_igcd_relprime[OF stupid] have gp1: "?g' = 1" .
1.53 + from bnz have "b < 0 \<or> b > 0" by arith
1.54 + moreover
1.55 + {assume b: "b > 0"
1.56 + from pos_imp_zdiv_nonneg_iff[OF gpos] b
1.57 + have "?b' \<ge> 0" by simp
1.58 + with nz' have b': "?b' > 0" by simp
1.59 + from b b' anz bnz nz' gp1 have ?thesis
1.60 + by (simp add: isnormNum_def normNum_def Let_def split_def fst_conv snd_conv)}
1.61 + moreover {assume b: "b < 0"
1.62 + {assume b': "?b' \<ge> 0"
1.63 + from gpos have th: "?g \<ge> 0" by arith
1.64 + from mult_nonneg_nonneg[OF th b'] zdvd_mult_div_cancel[OF gdvd(2)]
1.65 + have False using b by simp }
1.66 + hence b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
1.67 + from anz bnz nz' b b' gp1 have ?thesis
1.68 + by (simp add: isnormNum_def normNum_def Let_def split_def fst_conv snd_conv)}
1.69 + ultimately have ?thesis by blast
1.70 + }
1.71 + ultimately show ?thesis by blast
1.72 +qed
1.73 +
1.74 +text {* Arithmetic over Num *}
1.75 +
1.76 +definition
1.77 + Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "+\<^sub>N" 60)
1.78 +where
1.79 + "Nadd = (\<lambda>(a,b) (a',b'). if a = 0 \<or> b = 0 then normNum(a',b')
1.80 + else if a'=0 \<or> b' = 0 then normNum(a,b)
1.81 + else normNum(a*b' + b*a', b*b'))"
1.82 +
1.83 +definition
1.84 + Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "*\<^sub>N" 60)
1.85 +where
1.86 + "Nmul = (\<lambda>(a,b) (a',b'). let g = igcd (a*a') (b*b')
1.87 + in (a*a' div g, b*b' div g))"
1.88 +
1.89 +definition
1.90 + Nneg :: "Num \<Rightarrow> Num" ("~\<^sub>N")
1.91 +where
1.92 + "Nneg \<equiv> (\<lambda>(a,b). (-a,b))"
1.93 +
1.94 +definition
1.95 + Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "-\<^sub>N" 60)
1.96 +where
1.97 + "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"
1.98 +
1.99 +definition
1.100 + Ninv :: "Num \<Rightarrow> Num"
1.101 +where
1.102 + "Ninv \<equiv> \<lambda>(a,b). if a < 0 then (-b, \<bar>a\<bar>) else (b,a)"
1.103 +
1.104 +definition
1.105 + Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "\<div>\<^sub>N" 60)
1.106 +where
1.107 + "Ndiv \<equiv> \<lambda>a b. a *\<^sub>N Ninv b"
1.108 +
1.109 +lemma Nneg_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (~\<^sub>N x)"
1.110 + by(simp add: isnormNum_def Nneg_def split_def)
1.111 +lemma Nadd_normN[simp]: "isnormNum (x +\<^sub>N y)"
1.112 + by (simp add: Nadd_def split_def)
1.113 +lemma Nsub_normN[simp]: "\<lbrakk> isnormNum y\<rbrakk> \<Longrightarrow> isnormNum (x -\<^sub>N y)"
1.114 + by (simp add: Nsub_def split_def)
1.115 +lemma Nmul_normN[simp]: assumes xn:"isnormNum x" and yn: "isnormNum y"
1.116 + shows "isnormNum (x *\<^sub>N y)"
1.117 +proof-
1.118 + have "\<exists>a b. x = (a,b)" and "\<exists> a' b'. y = (a',b')" by auto
1.119 + then obtain a b a' b' where ab: "x = (a,b)" and ab': "y = (a',b')" by blast
1.120 + {assume "a = 0"
1.121 + hence ?thesis using xn ab ab'
1.122 + by (simp add: igcd_def isnormNum_def Let_def Nmul_def split_def)}
1.123 + moreover
1.124 + {assume "a' = 0"
1.125 + hence ?thesis using yn ab ab'
1.126 + by (simp add: igcd_def isnormNum_def Let_def Nmul_def split_def)}
1.127 + moreover
1.128 + {assume a: "a \<noteq>0" and a': "a'\<noteq>0"
1.129 + hence bp: "b > 0" "b' > 0" using xn yn ab ab' by (simp_all add: isnormNum_def)
1.130 + from mult_pos_pos[OF bp] have "x *\<^sub>N y = normNum (a*a', b*b')"
1.131 + using ab ab' a a' bp by (simp add: Nmul_def Let_def split_def normNum_def)
1.132 + hence ?thesis by simp}
1.133 + ultimately show ?thesis by blast
1.134 +qed
1.135 +
1.136 +lemma Ninv_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (Ninv x)"
1.137 +by (simp add: Ninv_def isnormNum_def split_def)
1.138 +(cases "fst x = 0",auto simp add: igcd_commute)
1.139 +
1.140 +lemma isnormNum_int[simp]:
1.141 + "isnormNum 0\<^sub>N" "isnormNum (1::int)\<^sub>N" "i \<noteq> 0 \<Longrightarrow> isnormNum i\<^sub>N"
1.142 + by (simp_all add: isnormNum_def igcd_def)
1.143 +
1.144 +
1.145 +text {* Relations over Num *}
1.146 +
1.147 +definition
1.148 + Nlt0:: "Num \<Rightarrow> bool" ("0>\<^sub>N")
1.149 +where
1.150 + "Nlt0 = (\<lambda>(a,b). a < 0)"
1.151 +
1.152 +definition
1.153 + Nle0:: "Num \<Rightarrow> bool" ("0\<ge>\<^sub>N")
1.154 +where
1.155 + "Nle0 = (\<lambda>(a,b). a \<le> 0)"
1.156 +
1.157 +definition
1.158 + Ngt0:: "Num \<Rightarrow> bool" ("0<\<^sub>N")
1.159 +where
1.160 + "Ngt0 = (\<lambda>(a,b). a > 0)"
1.161 +
1.162 +definition
1.163 + Nge0:: "Num \<Rightarrow> bool" ("0\<le>\<^sub>N")
1.164 +where
1.165 + "Nge0 = (\<lambda>(a,b). a \<ge> 0)"
1.166 +
1.167 +definition
1.168 + Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "<\<^sub>N" 55)
1.169 +where
1.170 + "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"
1.171 +
1.172 +definition
1.173 + Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "\<le>\<^sub>N" 55)
1.174 +where
1.175 + "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"
1.176 +
1.177 +definition
1.178 + "INum = (\<lambda>(a,b). of_int a / of_int b)"
1.179 +
1.180 +lemma INum_int [simp]: "INum i\<^sub>N = ((of_int i) ::'a::field)" "INum 0\<^sub>N = (0::'a::field)"
1.181 + by (simp_all add: INum_def)
1.182 +
1.183 +lemma isnormNum_unique[simp]:
1.184 + assumes na: "isnormNum x" and nb: "isnormNum y"
1.185 + shows "((INum x ::'a::{ring_char_0,field, division_by_zero}) = INum y) = (x = y)" (is "?lhs = ?rhs")
1.186 +proof
1.187 + have "\<exists> a b a' b'. x = (a,b) \<and> y = (a',b')" by auto
1.188 + then obtain a b a' b' where xy[simp]: "x = (a,b)" "y=(a',b')" by blast
1.189 + assume H: ?lhs
1.190 + {assume "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0" hence ?rhs
1.191 + using na nb H
1.192 + apply (simp add: INum_def split_def isnormNum_def)
1.193 + apply (cases "a = 0", simp_all)
1.194 + apply (cases "b = 0", simp_all)
1.195 + apply (cases "a' = 0", simp_all)
1.196 + apply (cases "a' = 0", simp_all add: of_int_eq_0_iff)
1.197 + done}
1.198 + moreover
1.199 + { assume az: "a \<noteq> 0" and bz: "b \<noteq> 0" and a'z: "a'\<noteq>0" and b'z: "b'\<noteq>0"
1.200 + from az bz a'z b'z na nb have pos: "b > 0" "b' > 0" by (simp_all add: isnormNum_def)
1.201 + from prems have eq:"a * b' = a'*b"
1.202 + by (simp add: INum_def eq_divide_eq divide_eq_eq of_int_mult[symmetric] del: of_int_mult)
1.203 + from prems have gcd1: "igcd a b = 1" "igcd b a = 1" "igcd a' b' = 1" "igcd b' a' = 1"
1.204 + by (simp_all add: isnormNum_def add: igcd_commute)
1.205 + from eq have raw_dvd: "a dvd a'*b" "b dvd b'*a" "a' dvd a*b'" "b' dvd b*a'"
1.206 + apply(unfold dvd_def)
1.207 + apply (rule_tac x="b'" in exI, simp add: mult_ac)
1.208 + apply (rule_tac x="a'" in exI, simp add: mult_ac)
1.209 + apply (rule_tac x="b" in exI, simp add: mult_ac)
1.210 + apply (rule_tac x="a" in exI, simp add: mult_ac)
1.211 + done
1.212 + from zdvd_dvd_eq[OF bz zrelprime_dvd_mult[OF gcd1(2) raw_dvd(2)]
1.213 + zrelprime_dvd_mult[OF gcd1(4) raw_dvd(4)]]
1.214 + have eq1: "b = b'" using pos by simp_all
1.215 + with eq have "a = a'" using pos by simp
1.216 + with eq1 have ?rhs by simp}
1.217 + ultimately show ?rhs by blast
1.218 +next
1.219 + assume ?rhs thus ?lhs by simp
1.220 +qed
1.221 +
1.222 +
1.223 +lemma isnormNum0[simp]: "isnormNum x \<Longrightarrow> (INum x = (0::'a::{ring_char_0, field,division_by_zero})) = (x = 0\<^sub>N)"
1.224 + unfolding INum_int(2)[symmetric]
1.225 + by (rule isnormNum_unique, simp_all)
1.226 +
1.227 +lemma of_int_div_aux: "d ~= 0 ==> ((of_int x)::'a::{field, ring_char_0}) / (of_int d) =
1.228 + of_int (x div d) + (of_int (x mod d)) / ((of_int d)::'a)"
1.229 +proof -
1.230 + assume "d ~= 0"
1.231 + hence dz: "of_int d \<noteq> (0::'a)" by (simp add: of_int_eq_0_iff)
1.232 + let ?t = "of_int (x div d) * ((of_int d)::'a) + of_int(x mod d)"
1.233 + let ?f = "\<lambda>x. x / of_int d"
1.234 + have "x = (x div d) * d + x mod d"
1.235 + by auto
1.236 + then have eq: "of_int x = ?t"
1.237 + by (simp only: of_int_mult[symmetric] of_int_add [symmetric])
1.238 + then have "of_int x / of_int d = ?t / of_int d"
1.239 + using cong[OF refl[of ?f] eq] by simp
1.240 + then show ?thesis by (simp add: add_divide_distrib ring_simps prems)
1.241 +qed
1.242 +
1.243 +lemma of_int_div: "(d::int) ~= 0 ==> d dvd n ==>
1.244 + (of_int(n div d)::'a::{field, ring_char_0}) = of_int n / of_int d"
1.245 + apply (frule of_int_div_aux [of d n, where ?'a = 'a])
1.246 + apply simp
1.247 + apply (simp add: zdvd_iff_zmod_eq_0)
1.248 +done
1.249 +
1.250 +
1.251 +lemma normNum[simp]: "INum (normNum x) = (INum x :: 'a::{ring_char_0,field, division_by_zero})"
1.252 +proof-
1.253 + have "\<exists> a b. x = (a,b)" by auto
1.254 + then obtain a b where x[simp]: "x = (a,b)" by blast
1.255 + {assume "a=0 \<or> b = 0" hence ?thesis
1.256 + by (simp add: INum_def normNum_def split_def Let_def)}
1.257 + moreover
1.258 + {assume a: "a\<noteq>0" and b: "b\<noteq>0"
1.259 + let ?g = "igcd a b"
1.260 + from a b have g: "?g \<noteq> 0"by simp
1.261 + from of_int_div[OF g, where ?'a = 'a]
1.262 + have ?thesis by (auto simp add: INum_def normNum_def split_def Let_def)}
1.263 + ultimately show ?thesis by blast
1.264 +qed
1.265 +
1.266 +lemma INum_normNum_iff [code]: "(INum x ::'a::{field, division_by_zero, ring_char_0}) = INum y \<longleftrightarrow> normNum x = normNum y" (is "?lhs = ?rhs")
1.267 +proof -
1.268 + have "normNum x = normNum y \<longleftrightarrow> (INum (normNum x) :: 'a) = INum (normNum y)"
1.269 + by (simp del: normNum)
1.270 + also have "\<dots> = ?lhs" by simp
1.271 + finally show ?thesis by simp
1.272 +qed
1.273 +
1.274 +lemma Nadd[simp]: "INum (x +\<^sub>N y) = INum x + (INum y :: 'a :: {ring_char_0,division_by_zero,field})"
1.275 +proof-
1.276 +let ?z = "0:: 'a"
1.277 + have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
1.278 + then obtain a b a' b' where x[simp]: "x = (a,b)"
1.279 + and y[simp]: "y = (a',b')" by blast
1.280 + {assume "a=0 \<or> a'= 0 \<or> b =0 \<or> b' = 0" hence ?thesis
1.281 + apply (cases "a=0",simp_all add: Nadd_def)
1.282 + apply (cases "b= 0",simp_all add: INum_def)
1.283 + apply (cases "a'= 0",simp_all)
1.284 + apply (cases "b'= 0",simp_all)
1.285 + done }
1.286 + moreover
1.287 + {assume aa':"a \<noteq> 0" "a'\<noteq> 0" and bb': "b \<noteq> 0" "b' \<noteq> 0"
1.288 + {assume z: "a * b' + b * a' = 0"
1.289 + hence "of_int (a*b' + b*a') / (of_int b* of_int b') = ?z" by simp
1.290 + 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)
1.291 + hence th: "of_int a / of_int b + of_int a' / of_int b' = ?z" using bb' aa' by simp
1.292 + from z aa' bb' have ?thesis
1.293 + by (simp add: th Nadd_def normNum_def INum_def split_def)}
1.294 + moreover {assume z: "a * b' + b * a' \<noteq> 0"
1.295 + let ?g = "igcd (a * b' + b * a') (b*b')"
1.296 + have gz: "?g \<noteq> 0" using z by simp
1.297 + have ?thesis using aa' bb' z gz
1.298 + of_int_div[where ?'a = 'a,
1.299 + OF gz igcd_dvd1[where i="a * b' + b * a'" and j="b*b'"]]
1.300 + of_int_div[where ?'a = 'a,
1.301 + OF gz igcd_dvd2[where i="a * b' + b * a'" and j="b*b'"]]
1.302 + by (simp add: x y Nadd_def INum_def normNum_def Let_def add_divide_distrib)}
1.303 + ultimately have ?thesis using aa' bb'
1.304 + by (simp add: Nadd_def INum_def normNum_def x y Let_def) }
1.305 + ultimately show ?thesis by blast
1.306 +qed
1.307 +
1.308 +lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a :: {ring_char_0,division_by_zero,field}) "
1.309 +proof-
1.310 + let ?z = "0::'a"
1.311 + have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
1.312 + then obtain a b a' b' where x: "x = (a,b)" and y: "y = (a',b')" by blast
1.313 + {assume "a=0 \<or> a'= 0 \<or> b = 0 \<or> b' = 0" hence ?thesis
1.314 + apply (cases "a=0",simp_all add: x y Nmul_def INum_def Let_def)
1.315 + apply (cases "b=0",simp_all)
1.316 + apply (cases "a'=0",simp_all)
1.317 + done }
1.318 + moreover
1.319 + {assume z: "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
1.320 + let ?g="igcd (a*a') (b*b')"
1.321 + have gz: "?g \<noteq> 0" using z by simp
1.322 + from z of_int_div[where ?'a = 'a, OF gz igcd_dvd1[where i="a*a'" and j="b*b'"]]
1.323 + of_int_div[where ?'a = 'a , OF gz igcd_dvd2[where i="a*a'" and j="b*b'"]]
1.324 + have ?thesis by (simp add: Nmul_def x y Let_def INum_def)}
1.325 + ultimately show ?thesis by blast
1.326 +qed
1.327 +
1.328 +lemma Nneg[simp]: "INum (~\<^sub>N x) = - (INum x ::'a:: field)"
1.329 + by (simp add: Nneg_def split_def INum_def)
1.330 +
1.331 +lemma Nsub[simp]: shows "INum (x -\<^sub>N y) = INum x - (INum y:: 'a :: {ring_char_0,division_by_zero,field})"
1.332 +by (simp add: Nsub_def split_def)
1.333 +
1.334 +lemma Ninv[simp]: "INum (Ninv x) = (1::'a :: {division_by_zero,field}) / (INum x)"
1.335 + by (simp add: Ninv_def INum_def split_def)
1.336 +
1.337 +lemma Ndiv[simp]: "INum (x \<div>\<^sub>N y) = INum x / (INum y ::'a :: {ring_char_0, division_by_zero,field})" by (simp add: Ndiv_def)
1.338 +
1.339 +lemma Nlt0_iff[simp]: assumes nx: "isnormNum x"
1.340 + shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field})< 0) = 0>\<^sub>N x "
1.341 +proof-
1.342 + have " \<exists> a b. x = (a,b)" by simp
1.343 + then obtain a b where x[simp]:"x = (a,b)" by blast
1.344 + {assume "a = 0" hence ?thesis by (simp add: Nlt0_def INum_def) }
1.345 + moreover
1.346 + {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
1.347 + from pos_divide_less_eq[OF b, where b="of_int a" and a="0::'a"]
1.348 + have ?thesis by (simp add: Nlt0_def INum_def)}
1.349 + ultimately show ?thesis by blast
1.350 +qed
1.351 +
1.352 +lemma Nle0_iff[simp]:assumes nx: "isnormNum x"
1.353 + shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) \<le> 0) = 0\<ge>\<^sub>N x"
1.354 +proof-
1.355 + have " \<exists> a b. x = (a,b)" by simp
1.356 + then obtain a b where x[simp]:"x = (a,b)" by blast
1.357 + {assume "a = 0" hence ?thesis by (simp add: Nle0_def INum_def) }
1.358 + moreover
1.359 + {assume a: "a\<noteq>0" hence b: "(of_int b :: 'a) > 0" using nx by (simp add: isnormNum_def)
1.360 + from pos_divide_le_eq[OF b, where b="of_int a" and a="0::'a"]
1.361 + have ?thesis by (simp add: Nle0_def INum_def)}
1.362 + ultimately show ?thesis by blast
1.363 +qed
1.364 +
1.365 +lemma Ngt0_iff[simp]:assumes nx: "isnormNum x" shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field})> 0) = 0<\<^sub>N x"
1.366 +proof-
1.367 + have " \<exists> a b. x = (a,b)" by simp
1.368 + then obtain a b where x[simp]:"x = (a,b)" by blast
1.369 + {assume "a = 0" hence ?thesis by (simp add: Ngt0_def INum_def) }
1.370 + moreover
1.371 + {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
1.372 + from pos_less_divide_eq[OF b, where b="of_int a" and a="0::'a"]
1.373 + have ?thesis by (simp add: Ngt0_def INum_def)}
1.374 + ultimately show ?thesis by blast
1.375 +qed
1.376 +lemma Nge0_iff[simp]:assumes nx: "isnormNum x"
1.377 + shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) \<ge> 0) = 0\<le>\<^sub>N x"
1.378 +proof-
1.379 + have " \<exists> a b. x = (a,b)" by simp
1.380 + then obtain a b where x[simp]:"x = (a,b)" by blast
1.381 + {assume "a = 0" hence ?thesis by (simp add: Nge0_def INum_def) }
1.382 + moreover
1.383 + {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
1.384 + from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
1.385 + have ?thesis by (simp add: Nge0_def INum_def)}
1.386 + ultimately show ?thesis by blast
1.387 +qed
1.388 +
1.389 +lemma Nlt_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
1.390 + shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) < INum y) = (x <\<^sub>N y)"
1.391 +proof-
1.392 + let ?z = "0::'a"
1.393 + have "((INum x ::'a) < INum y) = (INum (x -\<^sub>N y) < ?z)" using nx ny by simp
1.394 + also have "\<dots> = (0>\<^sub>N (x -\<^sub>N y))" using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
1.395 + finally show ?thesis by (simp add: Nlt_def)
1.396 +qed
1.397 +
1.398 +lemma Nle_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
1.399 + shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field})\<le> INum y) = (x \<le>\<^sub>N y)"
1.400 +proof-
1.401 + have "((INum x ::'a) \<le> INum y) = (INum (x -\<^sub>N y) \<le> (0::'a))" using nx ny by simp
1.402 + also have "\<dots> = (0\<ge>\<^sub>N (x -\<^sub>N y))" using Nle0_iff[OF Nsub_normN[OF ny]] by simp
1.403 + finally show ?thesis by (simp add: Nle_def)
1.404 +qed
1.405 +
1.406 +lemma Nadd_commute: "x +\<^sub>N y = y +\<^sub>N x"
1.407 +proof-
1.408 + have n: "isnormNum (x +\<^sub>N y)" "isnormNum (y +\<^sub>N x)" by simp_all
1.409 + have "(INum (x +\<^sub>N y)::'a :: {ring_char_0,division_by_zero,field}) = INum (y +\<^sub>N x)" by simp
1.410 + with isnormNum_unique[OF n] show ?thesis by simp
1.411 +qed
1.412 +
1.413 +lemma[simp]: "(0, b) +\<^sub>N y = normNum y" "(a, 0) +\<^sub>N y = normNum y"
1.414 + "x +\<^sub>N (0, b) = normNum x" "x +\<^sub>N (a, 0) = normNum x"
1.415 + apply (simp add: Nadd_def split_def, simp add: Nadd_def split_def)
1.416 + apply (subst Nadd_commute,simp add: Nadd_def split_def)
1.417 + apply (subst Nadd_commute,simp add: Nadd_def split_def)
1.418 + done
1.419 +
1.420 +lemma normNum_nilpotent_aux[simp]: assumes nx: "isnormNum x"
1.421 + shows "normNum x = x"
1.422 +proof-
1.423 + let ?a = "normNum x"
1.424 + have n: "isnormNum ?a" by simp
1.425 + have th:"INum ?a = (INum x ::'a :: {ring_char_0, division_by_zero,field})" by simp
1.426 + with isnormNum_unique[OF n nx]
1.427 + show ?thesis by simp
1.428 +qed
1.429 +
1.430 +lemma normNum_nilpotent[simp]: "normNum (normNum x) = normNum x"
1.431 + by simp
1.432 +lemma normNum0[simp]: "normNum (0,b) = 0\<^sub>N" "normNum (a,0) = 0\<^sub>N"
1.433 + by (simp_all add: normNum_def)
1.434 +lemma normNum_Nadd: "normNum (x +\<^sub>N y) = x +\<^sub>N y" by simp
1.435 +lemma Nadd_normNum1[simp]: "normNum x +\<^sub>N y = x +\<^sub>N y"
1.436 +proof-
1.437 + have n: "isnormNum (normNum x +\<^sub>N y)" "isnormNum (x +\<^sub>N y)" by simp_all
1.438 + have "INum (normNum x +\<^sub>N y) = INum x + (INum y :: 'a :: {ring_char_0, division_by_zero,field})" by simp
1.439 + also have "\<dots> = INum (x +\<^sub>N y)" by simp
1.440 + finally show ?thesis using isnormNum_unique[OF n] by simp
1.441 +qed
1.442 +lemma Nadd_normNum2[simp]: "x +\<^sub>N normNum y = x +\<^sub>N y"
1.443 +proof-
1.444 + have n: "isnormNum (x +\<^sub>N normNum y)" "isnormNum (x +\<^sub>N y)" by simp_all
1.445 + have "INum (x +\<^sub>N normNum y) = INum x + (INum y :: 'a :: {ring_char_0, division_by_zero,field})" by simp
1.446 + also have "\<dots> = INum (x +\<^sub>N y)" by simp
1.447 + finally show ?thesis using isnormNum_unique[OF n] by simp
1.448 +qed
1.449 +
1.450 +lemma Nadd_assoc: "x +\<^sub>N y +\<^sub>N z = x +\<^sub>N (y +\<^sub>N z)"
1.451 +proof-
1.452 + have n: "isnormNum (x +\<^sub>N y +\<^sub>N z)" "isnormNum (x +\<^sub>N (y +\<^sub>N z))" by simp_all
1.453 + have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a :: {ring_char_0, division_by_zero,field})" by simp
1.454 + with isnormNum_unique[OF n] show ?thesis by simp
1.455 +qed
1.456 +
1.457 +lemma Nmul_commute: "isnormNum x \<Longrightarrow> isnormNum y \<Longrightarrow> x *\<^sub>N y = y *\<^sub>N x"
1.458 + by (simp add: Nmul_def split_def Let_def igcd_commute mult_commute)
1.459 +
1.460 +lemma Nmul_assoc: assumes nx: "isnormNum x" and ny:"isnormNum y" and nz:"isnormNum z"
1.461 + shows "x *\<^sub>N y *\<^sub>N z = x *\<^sub>N (y *\<^sub>N z)"
1.462 +proof-
1.463 + from nx ny nz have n: "isnormNum (x *\<^sub>N y *\<^sub>N z)" "isnormNum (x *\<^sub>N (y *\<^sub>N z))"
1.464 + by simp_all
1.465 + have "INum (x +\<^sub>N y +\<^sub>N z) = (INum (x +\<^sub>N (y +\<^sub>N z)) :: 'a :: {ring_char_0, division_by_zero,field})" by simp
1.466 + with isnormNum_unique[OF n] show ?thesis by simp
1.467 +qed
1.468 +
1.469 +lemma Nsub0: assumes x: "isnormNum x" and y:"isnormNum y" shows "(x -\<^sub>N y = 0\<^sub>N) = (x = y)"
1.470 +proof-
1.471 + {fix h :: "'a :: {ring_char_0,division_by_zero,ordered_field}"
1.472 + from isnormNum_unique[where ?'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
1.473 + have "(x -\<^sub>N y = 0\<^sub>N) = (INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)) " by simp
1.474 + also have "\<dots> = (INum x = (INum y:: 'a))" by simp
1.475 + also have "\<dots> = (x = y)" using x y by simp
1.476 + finally show ?thesis .}
1.477 +qed
1.478 +
1.479 +lemma Nmul0[simp]: "c *\<^sub>N 0\<^sub>N = 0\<^sub>N" " 0\<^sub>N *\<^sub>N c = 0\<^sub>N"
1.480 + by (simp_all add: Nmul_def Let_def split_def)
1.481 +
1.482 +lemma Nmul_eq0[simp]: assumes nx:"isnormNum x" and ny: "isnormNum y"
1.483 + shows "(x*\<^sub>N y = 0\<^sub>N) = (x = 0\<^sub>N \<or> y = 0\<^sub>N)"
1.484 +proof-
1.485 + {fix h :: "'a :: {ring_char_0,division_by_zero,ordered_field}"
1.486 + have " \<exists> a b a' b'. x = (a,b) \<and> y= (a',b')" by auto
1.487 + then obtain a b a' b' where xy[simp]: "x = (a,b)" "y = (a',b')" by blast
1.488 + have n0: "isnormNum 0\<^sub>N" by simp
1.489 + show ?thesis using nx ny
1.490 + apply (simp only: isnormNum_unique[where ?'a = 'a, OF Nmul_normN[OF nx ny] n0, symmetric] Nmul[where ?'a = 'a])
1.491 + apply (simp add: INum_def split_def isnormNum_def fst_conv snd_conv)
1.492 + apply (cases "a=0",simp_all)
1.493 + apply (cases "a'=0",simp_all)
1.494 + done }
1.495 +qed
1.496 +lemma Nneg_Nneg[simp]: "~\<^sub>N (~\<^sub>N c) = c"
1.497 + by (simp add: Nneg_def split_def)
1.498 +
1.499 +lemma Nmul1[simp]:
1.500 + "isnormNum c \<Longrightarrow> 1\<^sub>N *\<^sub>N c = c"
1.501 + "isnormNum c \<Longrightarrow> c *\<^sub>N 1\<^sub>N = c"
1.502 + apply (simp_all add: Nmul_def Let_def split_def isnormNum_def)
1.503 + by (cases "fst c = 0", simp_all,cases c, simp_all)+
1.504 +
1.505 +end
1.506 \ No newline at end of file