equal
deleted
inserted
replaced
1 (* Author: Florian Haftmann, TU Muenchen; based on existing material on gauss numbers\<close> |
1 (* Author: Florian Haftmann, TU Muenchen; based on existing material on complex numbers\<close> |
2 *) |
2 *) |
3 |
3 |
4 section \<open>Gauss Numbers: integral gauss numbers\<close> |
4 section \<open>Gauss Numbers: integral gauss numbers\<close> |
5 |
5 |
6 theory Gauss_Numbers |
6 theory Gauss_Numbers |
7 imports Main |
7 imports "HOL-Library.Rounded_Division" |
8 begin |
8 begin |
9 |
9 |
10 codatatype gauss = Gauss (Re: int) (Im: int) |
10 codatatype gauss = Gauss (Re: int) (Im: int) |
11 |
11 |
12 lemma gauss_eqI [intro?]: |
12 lemma gauss_eqI [intro?]: |
306 instantiation gauss :: idom_modulo |
306 instantiation gauss :: idom_modulo |
307 begin |
307 begin |
308 |
308 |
309 primcorec divide_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> |
309 primcorec divide_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> |
310 where |
310 where |
311 \<open>Re (x div y) = (Re x * Re y + Im x * Im y) div ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close> |
311 \<open>Re (x div y) = (Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close> |
312 | \<open>Im (x div y) = (Im x * Re y - Re x * Im y) div ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close> |
312 | \<open>Im (x div y) = (Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close> |
313 |
313 |
314 definition modulo_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> |
314 definition modulo_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> |
315 where |
315 where |
316 \<open>x mod y = x - x div y * y\<close> for x y :: gauss |
316 \<open>x mod y = x - x div y * y\<close> for x y :: gauss |
317 |
317 |
319 apply standard |
319 apply standard |
320 apply (simp_all add: modulo_gauss_def) |
320 apply (simp_all add: modulo_gauss_def) |
321 apply (auto simp add: gauss_eq_iff algebra_simps power2_eq_square) |
321 apply (auto simp add: gauss_eq_iff algebra_simps power2_eq_square) |
322 apply (simp_all only: flip: mult.assoc distrib_right) |
322 apply (simp_all only: flip: mult.assoc distrib_right) |
323 apply (simp_all only: mult.assoc [of \<open>Im k\<close> \<open>Re l\<close> \<open>Re r\<close> for k l r]) |
323 apply (simp_all only: mult.assoc [of \<open>Im k\<close> \<open>Re l\<close> \<open>Re r\<close> for k l r]) |
324 apply (simp_all add: sum_squares_eq_zero_iff mult.commute flip: distrib_left) |
324 apply (simp_all add: sum_squares_eq_zero_iff mult.commute nonzero_mult_rdiv_cancel_right flip: distrib_left) |
325 done |
325 done |
326 |
326 |
327 end |
327 end |
328 |
328 |
329 end |
329 end |