1 (* Title: HOL/Library/Abstract_Rat.thy
6 header {* Abstract rational numbers *}
12 types Num = "int \<times> int"
15 Num0_syn :: Num ("0\<^sub>N")
16 where "0\<^sub>N \<equiv> (0, 0)"
19 Numi_syn :: "int \<Rightarrow> Num" ("_\<^sub>N")
20 where "i\<^sub>N \<equiv> (i, 1)"
23 isnormNum :: "Num \<Rightarrow> bool"
25 "isnormNum = (\<lambda>(a,b). (if a = 0 then b = 0 else b > 0 \<and> zgcd a b = 1))"
28 normNum :: "Num \<Rightarrow> Num"
30 "normNum = (\<lambda>(a,b). (if a=0 \<or> b = 0 then (0,0) else
32 in if b > 0 then (a div g, b div g) else (- (a div g), - (b div g)))))"
34 lemma normNum_isnormNum [simp]: "isnormNum (normNum x)"
36 have " \<exists> a b. x = (a,b)" by auto
37 then obtain a b where x[simp]: "x = (a,b)" by blast
38 {assume "a=0 \<or> b = 0" hence ?thesis by (simp add: normNum_def isnormNum_def)}
40 {assume anz: "a \<noteq> 0" and bnz: "b \<noteq> 0"
44 let ?g' = "zgcd ?a' ?b'"
45 from anz bnz have "?g \<noteq> 0" by simp with zgcd_pos[of a b]
46 have gpos: "?g > 0" by arith
47 have gdvd: "?g dvd a" "?g dvd b" by (simp_all add: zgcd_dvd1 zgcd_dvd2)
48 from zdvd_mult_div_cancel[OF gdvd(1)] zdvd_mult_div_cancel[OF gdvd(2)]
50 have nz':"?a' \<noteq> 0" "?b' \<noteq> 0"
51 by - (rule notI,simp add:zgcd_def)+
52 from anz bnz have stupid: "a \<noteq> 0 \<or> b \<noteq> 0" by blast
53 from div_zgcd_relprime[OF stupid] have gp1: "?g' = 1" .
54 from bnz have "b < 0 \<or> b > 0" by arith
57 from pos_imp_zdiv_nonneg_iff[OF gpos] b
58 have "?b' \<ge> 0" by simp
59 with nz' have b': "?b' > 0" by simp
60 from b b' anz bnz nz' gp1 have ?thesis
61 by (simp add: isnormNum_def normNum_def Let_def split_def fst_conv snd_conv)}
62 moreover {assume b: "b < 0"
63 {assume b': "?b' \<ge> 0"
64 from gpos have th: "?g \<ge> 0" by arith
65 from mult_nonneg_nonneg[OF th b'] zdvd_mult_div_cancel[OF gdvd(2)]
66 have False using b by simp }
67 hence b': "?b' < 0" by (presburger add: linorder_not_le[symmetric])
68 from anz bnz nz' b b' gp1 have ?thesis
69 by (simp add: isnormNum_def normNum_def Let_def split_def fst_conv snd_conv)}
70 ultimately have ?thesis by blast
72 ultimately show ?thesis by blast
75 text {* Arithmetic over Num *}
78 Nadd :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "+\<^sub>N" 60)
80 "Nadd = (\<lambda>(a,b) (a',b'). if a = 0 \<or> b = 0 then normNum(a',b')
81 else if a'=0 \<or> b' = 0 then normNum(a,b)
82 else normNum(a*b' + b*a', b*b'))"
85 Nmul :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "*\<^sub>N" 60)
87 "Nmul = (\<lambda>(a,b) (a',b'). let g = zgcd (a*a') (b*b')
88 in (a*a' div g, b*b' div g))"
91 Nneg :: "Num \<Rightarrow> Num" ("~\<^sub>N")
93 "Nneg \<equiv> (\<lambda>(a,b). (-a,b))"
96 Nsub :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "-\<^sub>N" 60)
98 "Nsub = (\<lambda>a b. a +\<^sub>N ~\<^sub>N b)"
101 Ninv :: "Num \<Rightarrow> Num"
103 "Ninv \<equiv> \<lambda>(a,b). if a < 0 then (-b, \<bar>a\<bar>) else (b,a)"
106 Ndiv :: "Num \<Rightarrow> Num \<Rightarrow> Num" (infixl "\<div>\<^sub>N" 60)
108 "Ndiv \<equiv> \<lambda>a b. a *\<^sub>N Ninv b"
110 lemma Nneg_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (~\<^sub>N x)"
111 by(simp add: isnormNum_def Nneg_def split_def)
112 lemma Nadd_normN[simp]: "isnormNum (x +\<^sub>N y)"
113 by (simp add: Nadd_def split_def)
114 lemma Nsub_normN[simp]: "\<lbrakk> isnormNum y\<rbrakk> \<Longrightarrow> isnormNum (x -\<^sub>N y)"
115 by (simp add: Nsub_def split_def)
116 lemma Nmul_normN[simp]: assumes xn:"isnormNum x" and yn: "isnormNum y"
117 shows "isnormNum (x *\<^sub>N y)"
119 have "\<exists>a b. x = (a,b)" and "\<exists> a' b'. y = (a',b')" by auto
120 then obtain a b a' b' where ab: "x = (a,b)" and ab': "y = (a',b')" by blast
122 hence ?thesis using xn ab ab'
123 by (simp add: zgcd_def isnormNum_def Let_def Nmul_def split_def)}
126 hence ?thesis using yn ab ab'
127 by (simp add: zgcd_def isnormNum_def Let_def Nmul_def split_def)}
129 {assume a: "a \<noteq>0" and a': "a'\<noteq>0"
130 hence bp: "b > 0" "b' > 0" using xn yn ab ab' by (simp_all add: isnormNum_def)
131 from mult_pos_pos[OF bp] have "x *\<^sub>N y = normNum (a*a', b*b')"
132 using ab ab' a a' bp by (simp add: Nmul_def Let_def split_def normNum_def)
133 hence ?thesis by simp}
134 ultimately show ?thesis by blast
137 lemma Ninv_normN[simp]: "isnormNum x \<Longrightarrow> isnormNum (Ninv x)"
138 by (simp add: Ninv_def isnormNum_def split_def)
139 (cases "fst x = 0", auto simp add: zgcd_commute)
141 lemma isnormNum_int[simp]:
142 "isnormNum 0\<^sub>N" "isnormNum (1::int)\<^sub>N" "i \<noteq> 0 \<Longrightarrow> isnormNum i\<^sub>N"
143 by (simp_all add: isnormNum_def zgcd_def)
146 text {* Relations over Num *}
149 Nlt0:: "Num \<Rightarrow> bool" ("0>\<^sub>N")
151 "Nlt0 = (\<lambda>(a,b). a < 0)"
154 Nle0:: "Num \<Rightarrow> bool" ("0\<ge>\<^sub>N")
156 "Nle0 = (\<lambda>(a,b). a \<le> 0)"
159 Ngt0:: "Num \<Rightarrow> bool" ("0<\<^sub>N")
161 "Ngt0 = (\<lambda>(a,b). a > 0)"
164 Nge0:: "Num \<Rightarrow> bool" ("0\<le>\<^sub>N")
166 "Nge0 = (\<lambda>(a,b). a \<ge> 0)"
169 Nlt :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "<\<^sub>N" 55)
171 "Nlt = (\<lambda>a b. 0>\<^sub>N (a -\<^sub>N b))"
174 Nle :: "Num \<Rightarrow> Num \<Rightarrow> bool" (infix "\<le>\<^sub>N" 55)
176 "Nle = (\<lambda>a b. 0\<ge>\<^sub>N (a -\<^sub>N b))"
179 "INum = (\<lambda>(a,b). of_int a / of_int b)"
181 lemma INum_int [simp]: "INum i\<^sub>N = ((of_int i) ::'a::field)" "INum 0\<^sub>N = (0::'a::field)"
182 by (simp_all add: INum_def)
184 lemma isnormNum_unique[simp]:
185 assumes na: "isnormNum x" and nb: "isnormNum y"
186 shows "((INum x ::'a::{ring_char_0,field, division_by_zero}) = INum y) = (x = y)" (is "?lhs = ?rhs")
188 have "\<exists> a b a' b'. x = (a,b) \<and> y = (a',b')" by auto
189 then obtain a b a' b' where xy[simp]: "x = (a,b)" "y=(a',b')" by blast
191 {assume "a = 0 \<or> b = 0 \<or> a' = 0 \<or> b' = 0" hence ?rhs
193 apply (simp add: INum_def split_def isnormNum_def)
194 apply (cases "a = 0", simp_all)
195 apply (cases "b = 0", simp_all)
196 apply (cases "a' = 0", simp_all)
197 apply (cases "a' = 0", simp_all add: of_int_eq_0_iff)
200 { assume az: "a \<noteq> 0" and bz: "b \<noteq> 0" and a'z: "a'\<noteq>0" and b'z: "b'\<noteq>0"
201 from az bz a'z b'z na nb have pos: "b > 0" "b' > 0" by (simp_all add: isnormNum_def)
202 from prems have eq:"a * b' = a'*b"
203 by (simp add: INum_def eq_divide_eq divide_eq_eq of_int_mult[symmetric] del: of_int_mult)
204 from prems have gcd1: "zgcd a b = 1" "zgcd b a = 1" "zgcd a' b' = 1" "zgcd b' a' = 1"
205 by (simp_all add: isnormNum_def add: zgcd_commute)
206 from eq have raw_dvd: "a dvd a'*b" "b dvd b'*a" "a' dvd a*b'" "b' dvd b*a'"
207 apply(unfold dvd_def)
208 apply (rule_tac x="b'" in exI, simp add: mult_ac)
209 apply (rule_tac x="a'" in exI, simp add: mult_ac)
210 apply (rule_tac x="b" in exI, simp add: mult_ac)
211 apply (rule_tac x="a" in exI, simp add: mult_ac)
213 from zdvd_dvd_eq[OF bz zrelprime_dvd_mult[OF gcd1(2) raw_dvd(2)]
214 zrelprime_dvd_mult[OF gcd1(4) raw_dvd(4)]]
215 have eq1: "b = b'" using pos by simp_all
216 with eq have "a = a'" using pos by simp
217 with eq1 have ?rhs by simp}
218 ultimately show ?rhs by blast
220 assume ?rhs thus ?lhs by simp
224 lemma isnormNum0[simp]: "isnormNum x \<Longrightarrow> (INum x = (0::'a::{ring_char_0, field,division_by_zero})) = (x = 0\<^sub>N)"
225 unfolding INum_int(2)[symmetric]
226 by (rule isnormNum_unique, simp_all)
228 lemma of_int_div_aux: "d ~= 0 ==> ((of_int x)::'a::{field, ring_char_0}) / (of_int d) =
229 of_int (x div d) + (of_int (x mod d)) / ((of_int d)::'a)"
232 hence dz: "of_int d \<noteq> (0::'a)" by (simp add: of_int_eq_0_iff)
233 let ?t = "of_int (x div d) * ((of_int d)::'a) + of_int(x mod d)"
234 let ?f = "\<lambda>x. x / of_int d"
235 have "x = (x div d) * d + x mod d"
237 then have eq: "of_int x = ?t"
238 by (simp only: of_int_mult[symmetric] of_int_add [symmetric])
239 then have "of_int x / of_int d = ?t / of_int d"
240 using cong[OF refl[of ?f] eq] by simp
241 then show ?thesis by (simp add: add_divide_distrib ring_simps prems)
244 lemma of_int_div: "(d::int) ~= 0 ==> d dvd n ==>
245 (of_int(n div d)::'a::{field, ring_char_0}) = of_int n / of_int d"
246 apply (frule of_int_div_aux [of d n, where ?'a = 'a])
248 apply (simp add: zdvd_iff_zmod_eq_0)
252 lemma normNum[simp]: "INum (normNum x) = (INum x :: 'a::{ring_char_0,field, division_by_zero})"
254 have "\<exists> a b. x = (a,b)" by auto
255 then obtain a b where x[simp]: "x = (a,b)" by blast
256 {assume "a=0 \<or> b = 0" hence ?thesis
257 by (simp add: INum_def normNum_def split_def Let_def)}
259 {assume a: "a\<noteq>0" and b: "b\<noteq>0"
261 from a b have g: "?g \<noteq> 0"by simp
262 from of_int_div[OF g, where ?'a = 'a]
263 have ?thesis by (auto simp add: INum_def normNum_def split_def Let_def)}
264 ultimately show ?thesis by blast
267 lemma INum_normNum_iff: "(INum x ::'a::{field, division_by_zero, ring_char_0}) = INum y \<longleftrightarrow> normNum x = normNum y" (is "?lhs = ?rhs")
269 have "normNum x = normNum y \<longleftrightarrow> (INum (normNum x) :: 'a) = INum (normNum y)"
270 by (simp del: normNum)
271 also have "\<dots> = ?lhs" by simp
272 finally show ?thesis by simp
275 lemma Nadd[simp]: "INum (x +\<^sub>N y) = INum x + (INum y :: 'a :: {ring_char_0,division_by_zero,field})"
278 have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
279 then obtain a b a' b' where x[simp]: "x = (a,b)"
280 and y[simp]: "y = (a',b')" by blast
281 {assume "a=0 \<or> a'= 0 \<or> b =0 \<or> b' = 0" hence ?thesis
282 apply (cases "a=0",simp_all add: Nadd_def)
283 apply (cases "b= 0",simp_all add: INum_def)
284 apply (cases "a'= 0",simp_all)
285 apply (cases "b'= 0",simp_all)
288 {assume aa':"a \<noteq> 0" "a'\<noteq> 0" and bb': "b \<noteq> 0" "b' \<noteq> 0"
289 {assume z: "a * b' + b * a' = 0"
290 hence "of_int (a*b' + b*a') / (of_int b* of_int b') = ?z" by simp
291 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)
292 hence th: "of_int a / of_int b + of_int a' / of_int b' = ?z" using bb' aa' by simp
293 from z aa' bb' have ?thesis
294 by (simp add: th Nadd_def normNum_def INum_def split_def)}
295 moreover {assume z: "a * b' + b * a' \<noteq> 0"
296 let ?g = "zgcd (a * b' + b * a') (b*b')"
297 have gz: "?g \<noteq> 0" using z by simp
298 have ?thesis using aa' bb' z gz
299 of_int_div[where ?'a = 'a,
300 OF gz zgcd_dvd1[where i="a * b' + b * a'" and j="b*b'"]]
301 of_int_div[where ?'a = 'a,
302 OF gz zgcd_dvd2[where i="a * b' + b * a'" and j="b*b'"]]
303 by (simp add: x y Nadd_def INum_def normNum_def Let_def add_divide_distrib)}
304 ultimately have ?thesis using aa' bb'
305 by (simp add: Nadd_def INum_def normNum_def x y Let_def) }
306 ultimately show ?thesis by blast
309 lemma Nmul[simp]: "INum (x *\<^sub>N y) = INum x * (INum y:: 'a :: {ring_char_0,division_by_zero,field}) "
312 have " \<exists> a b. x = (a,b)" " \<exists> a' b'. y = (a',b')" by auto
313 then obtain a b a' b' where x: "x = (a,b)" and y: "y = (a',b')" by blast
314 {assume "a=0 \<or> a'= 0 \<or> b = 0 \<or> b' = 0" hence ?thesis
315 apply (cases "a=0",simp_all add: x y Nmul_def INum_def Let_def)
316 apply (cases "b=0",simp_all)
317 apply (cases "a'=0",simp_all)
320 {assume z: "a \<noteq> 0" "a' \<noteq> 0" "b \<noteq> 0" "b' \<noteq> 0"
321 let ?g="zgcd (a*a') (b*b')"
322 have gz: "?g \<noteq> 0" using z by simp
323 from z of_int_div[where ?'a = 'a, OF gz zgcd_dvd1[where i="a*a'" and j="b*b'"]]
324 of_int_div[where ?'a = 'a , OF gz zgcd_dvd2[where i="a*a'" and j="b*b'"]]
325 have ?thesis by (simp add: Nmul_def x y Let_def INum_def)}
326 ultimately show ?thesis by blast
329 lemma Nneg[simp]: "INum (~\<^sub>N x) = - (INum x ::'a:: field)"
330 by (simp add: Nneg_def split_def INum_def)
332 lemma Nsub[simp]: shows "INum (x -\<^sub>N y) = INum x - (INum y:: 'a :: {ring_char_0,division_by_zero,field})"
333 by (simp add: Nsub_def split_def)
335 lemma Ninv[simp]: "INum (Ninv x) = (1::'a :: {division_by_zero,field}) / (INum x)"
336 by (simp add: Ninv_def INum_def split_def)
338 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)
340 lemma Nlt0_iff[simp]: assumes nx: "isnormNum x"
341 shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field})< 0) = 0>\<^sub>N x "
343 have " \<exists> a b. x = (a,b)" by simp
344 then obtain a b where x[simp]:"x = (a,b)" by blast
345 {assume "a = 0" hence ?thesis by (simp add: Nlt0_def INum_def) }
347 {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
348 from pos_divide_less_eq[OF b, where b="of_int a" and a="0::'a"]
349 have ?thesis by (simp add: Nlt0_def INum_def)}
350 ultimately show ?thesis by blast
353 lemma Nle0_iff[simp]:assumes nx: "isnormNum x"
354 shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) \<le> 0) = 0\<ge>\<^sub>N x"
356 have " \<exists> a b. x = (a,b)" by simp
357 then obtain a b where x[simp]:"x = (a,b)" by blast
358 {assume "a = 0" hence ?thesis by (simp add: Nle0_def INum_def) }
360 {assume a: "a\<noteq>0" hence b: "(of_int b :: 'a) > 0" using nx by (simp add: isnormNum_def)
361 from pos_divide_le_eq[OF b, where b="of_int a" and a="0::'a"]
362 have ?thesis by (simp add: Nle0_def INum_def)}
363 ultimately show ?thesis by blast
366 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"
368 have " \<exists> a b. x = (a,b)" by simp
369 then obtain a b where x[simp]:"x = (a,b)" by blast
370 {assume "a = 0" hence ?thesis by (simp add: Ngt0_def INum_def) }
372 {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
373 from pos_less_divide_eq[OF b, where b="of_int a" and a="0::'a"]
374 have ?thesis by (simp add: Ngt0_def INum_def)}
375 ultimately show ?thesis by blast
377 lemma Nge0_iff[simp]:assumes nx: "isnormNum x"
378 shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) \<ge> 0) = 0\<le>\<^sub>N x"
380 have " \<exists> a b. x = (a,b)" by simp
381 then obtain a b where x[simp]:"x = (a,b)" by blast
382 {assume "a = 0" hence ?thesis by (simp add: Nge0_def INum_def) }
384 {assume a: "a\<noteq>0" hence b: "(of_int b::'a) > 0" using nx by (simp add: isnormNum_def)
385 from pos_le_divide_eq[OF b, where b="of_int a" and a="0::'a"]
386 have ?thesis by (simp add: Nge0_def INum_def)}
387 ultimately show ?thesis by blast
390 lemma Nlt_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
391 shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field}) < INum y) = (x <\<^sub>N y)"
394 have "((INum x ::'a) < INum y) = (INum (x -\<^sub>N y) < ?z)" using nx ny by simp
395 also have "\<dots> = (0>\<^sub>N (x -\<^sub>N y))" using Nlt0_iff[OF Nsub_normN[OF ny]] by simp
396 finally show ?thesis by (simp add: Nlt_def)
399 lemma Nle_iff[simp]: assumes nx: "isnormNum x" and ny: "isnormNum y"
400 shows "((INum x :: 'a :: {ring_char_0,division_by_zero,ordered_field})\<le> INum y) = (x \<le>\<^sub>N y)"
402 have "((INum x ::'a) \<le> INum y) = (INum (x -\<^sub>N y) \<le> (0::'a))" using nx ny by simp
403 also have "\<dots> = (0\<ge>\<^sub>N (x -\<^sub>N y))" using Nle0_iff[OF Nsub_normN[OF ny]] by simp
404 finally show ?thesis by (simp add: Nle_def)
407 lemma Nadd_commute: "x +\<^sub>N y = y +\<^sub>N x"
409 have n: "isnormNum (x +\<^sub>N y)" "isnormNum (y +\<^sub>N x)" by simp_all
410 have "(INum (x +\<^sub>N y)::'a :: {ring_char_0,division_by_zero,field}) = INum (y +\<^sub>N x)" by simp
411 with isnormNum_unique[OF n] show ?thesis by simp
414 lemma[simp]: "(0, b) +\<^sub>N y = normNum y" "(a, 0) +\<^sub>N y = normNum y"
415 "x +\<^sub>N (0, b) = normNum x" "x +\<^sub>N (a, 0) = normNum x"
416 apply (simp add: Nadd_def split_def, simp add: Nadd_def split_def)
417 apply (subst Nadd_commute,simp add: Nadd_def split_def)
418 apply (subst Nadd_commute,simp add: Nadd_def split_def)
421 lemma normNum_nilpotent_aux[simp]: assumes nx: "isnormNum x"
422 shows "normNum x = x"
425 have n: "isnormNum ?a" by simp
426 have th:"INum ?a = (INum x ::'a :: {ring_char_0, division_by_zero,field})" by simp
427 with isnormNum_unique[OF n nx]
431 lemma normNum_nilpotent[simp]: "normNum (normNum x) = normNum x"
433 lemma normNum0[simp]: "normNum (0,b) = 0\<^sub>N" "normNum (a,0) = 0\<^sub>N"
434 by (simp_all add: normNum_def)
435 lemma normNum_Nadd: "normNum (x +\<^sub>N y) = x +\<^sub>N y" by simp
436 lemma Nadd_normNum1[simp]: "normNum x +\<^sub>N y = x +\<^sub>N y"
438 have n: "isnormNum (normNum x +\<^sub>N y)" "isnormNum (x +\<^sub>N y)" by simp_all
439 have "INum (normNum x +\<^sub>N y) = INum x + (INum y :: 'a :: {ring_char_0, division_by_zero,field})" by simp
440 also have "\<dots> = INum (x +\<^sub>N y)" by simp
441 finally show ?thesis using isnormNum_unique[OF n] by simp
443 lemma Nadd_normNum2[simp]: "x +\<^sub>N normNum y = x +\<^sub>N y"
445 have n: "isnormNum (x +\<^sub>N normNum y)" "isnormNum (x +\<^sub>N y)" by simp_all
446 have "INum (x +\<^sub>N normNum y) = INum x + (INum y :: 'a :: {ring_char_0, division_by_zero,field})" by simp
447 also have "\<dots> = INum (x +\<^sub>N y)" by simp
448 finally show ?thesis using isnormNum_unique[OF n] by simp
451 lemma Nadd_assoc: "x +\<^sub>N y +\<^sub>N z = x +\<^sub>N (y +\<^sub>N z)"
453 have n: "isnormNum (x +\<^sub>N y +\<^sub>N z)" "isnormNum (x +\<^sub>N (y +\<^sub>N z))" by simp_all
454 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
455 with isnormNum_unique[OF n] show ?thesis by simp
458 lemma Nmul_commute: "isnormNum x \<Longrightarrow> isnormNum y \<Longrightarrow> x *\<^sub>N y = y *\<^sub>N x"
459 by (simp add: Nmul_def split_def Let_def zgcd_commute mult_commute)
461 lemma Nmul_assoc: assumes nx: "isnormNum x" and ny:"isnormNum y" and nz:"isnormNum z"
462 shows "x *\<^sub>N y *\<^sub>N z = x *\<^sub>N (y *\<^sub>N z)"
464 from nx ny nz have n: "isnormNum (x *\<^sub>N y *\<^sub>N z)" "isnormNum (x *\<^sub>N (y *\<^sub>N z))"
466 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
467 with isnormNum_unique[OF n] show ?thesis by simp
470 lemma Nsub0: assumes x: "isnormNum x" and y:"isnormNum y" shows "(x -\<^sub>N y = 0\<^sub>N) = (x = y)"
472 {fix h :: "'a :: {ring_char_0,division_by_zero,ordered_field}"
473 from isnormNum_unique[where ?'a = 'a, OF Nsub_normN[OF y], where y="0\<^sub>N"]
474 have "(x -\<^sub>N y = 0\<^sub>N) = (INum (x -\<^sub>N y) = (INum 0\<^sub>N :: 'a)) " by simp
475 also have "\<dots> = (INum x = (INum y:: 'a))" by simp
476 also have "\<dots> = (x = y)" using x y by simp
477 finally show ?thesis .}
480 lemma Nmul0[simp]: "c *\<^sub>N 0\<^sub>N = 0\<^sub>N" " 0\<^sub>N *\<^sub>N c = 0\<^sub>N"
481 by (simp_all add: Nmul_def Let_def split_def)
483 lemma Nmul_eq0[simp]: assumes nx:"isnormNum x" and ny: "isnormNum y"
484 shows "(x*\<^sub>N y = 0\<^sub>N) = (x = 0\<^sub>N \<or> y = 0\<^sub>N)"
486 {fix h :: "'a :: {ring_char_0,division_by_zero,ordered_field}"
487 have " \<exists> a b a' b'. x = (a,b) \<and> y= (a',b')" by auto
488 then obtain a b a' b' where xy[simp]: "x = (a,b)" "y = (a',b')" by blast
489 have n0: "isnormNum 0\<^sub>N" by simp
490 show ?thesis using nx ny
491 apply (simp only: isnormNum_unique[where ?'a = 'a, OF Nmul_normN[OF nx ny] n0, symmetric] Nmul[where ?'a = 'a])
492 apply (simp add: INum_def split_def isnormNum_def fst_conv snd_conv)
493 apply (cases "a=0",simp_all)
494 apply (cases "a'=0",simp_all)
497 lemma Nneg_Nneg[simp]: "~\<^sub>N (~\<^sub>N c) = c"
498 by (simp add: Nneg_def split_def)
501 "isnormNum c \<Longrightarrow> 1\<^sub>N *\<^sub>N c = c"
502 "isnormNum c \<Longrightarrow> c *\<^sub>N 1\<^sub>N = c"
503 apply (simp_all add: Nmul_def Let_def split_def isnormNum_def)
504 by (cases "fst c = 0", simp_all,cases c, simp_all)+