primcorec plus_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> where \<open>Re (x + y) = Re x + Re y\<close>
| \<open>Im (x + y) = Im x + Im y\<close>
primcorec uminus_gauss :: \<open>gauss \<Rightarrow> gauss\<close> where \<open>Re (- x) = - Re x\<close>
| \<open>Im (- x) = - Im x\<close>
primcorec minus_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> where \<open>Re (x - y) = Re x - Re y\<close>
| \<open>Im (x - y) = Im x - Im y\<close>
primcorec times_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> where \<open>Re (x * y) = Re x * Re y - Im x * Im y\<close>
| \<open>Im (x * y) = Re x * Im y + Im x * Re y\<close>
instance by standard (simp_all add: gauss_eq_iff algebra_simps)
end
lemma of_nat_gauss: \<open>of_nat n = Gauss (int n) 0\<close> by (induction n) (simp_all add: gauss_eq_iff)
lemma numeral_gauss: \<open>numeral n = Gauss (numeral n) 0\<close> proof - have\<open>numeral n = (of_nat (numeral n) :: gauss)\<close> by simp alsohave\<open>\<dots> = Gauss (of_nat (numeral n)) 0\<close> by (simp add: of_nat_gauss) finallyshow ?thesis by simp qed
lemma of_int_gauss: \<open>of_int k = Gauss k 0\<close> by (simp add: gauss_eq_iff of_int_of_nat of_nat_gauss)
lemma gauss_add_cnj: \<open>z + cnj z = of_int (2 * Re z)\<close> by (simp add: gauss_eq_iff)
lemma gauss_diff_cnj: \<open>z - cnj z = of_int (2 * Im z) * \<i>\<close> by (simp add: gauss_eq_iff)
lemma gauss_mult_cnj: \<open>z * cnj z = of_int ((Re z)\<^sup>2 + (Im z)\<^sup>2)\<close> by (simp add: gauss_eq_iff power2_eq_square)
lemma cnj_add_mult_eq_Re: \<open>z * cnj w + cnj z * w = of_int (2 * Re (z * cnj w))\<close> by (simp add: gauss_eq_iff)
lemma gauss_In_mult_cnj_zero [simp]: \<open>Im (z * cnj z) = 0\<close> by simp
subsection \<open>Algebraic division\<close>
instantiation gauss :: idom_modulo begin
primcorec divide_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> where \<open>Re (x div y) = (Re x * Re y + Im x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close>
| \<open>Im (x div y) = (Im x * Re y - Re x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close>
primcorec modulo_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close> where \<open>Re (x mod y) = Re x -
((Re x * Re y + Im x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y -
(Im x * Re y - Re x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y)\<close>
| \<open>Im (x mod y) = Im x -
((Re x * Re y + Im x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y +
(Im x * Re y - Re x * Im y) cdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y)\<close>
instanceproof fix x y :: gauss show\<open>x div 0 = 0\<close> by (simp add: gauss_eq_iff) show\<open>x * y div y = x\<close> if \<open>y \<noteq> 0\<close> proof -
define Y where\<open>Y = (Re y)\<^sup>2 + (Im y)\<^sup>2\<close> moreoverhave\<open>Y > 0\<close> using that by (simp add: gauss_eq_0 less_le Y_def) have *: \<open>Im y * (Im y * Re x) + Re x * (Re y * Re y) = Re x * Y\<close> \<open>Im x * (Im y * Im y) + Im x * (Re y * Re y) = Im x * Y\<close> \<open>(Im y)\<^sup>2 + (Re y)\<^sup>2 = Y\<close> by (simp_all add: power2_eq_square algebra_simps Y_def) from\<open>Y > 0\<close> show ?thesis by (simp add: gauss_eq_iff algebra_simps) (simp add: * nonzero_mult_cdiv_cancel_right) qed show\<open>x div y * y + x mod y = x\<close> by (simp add: gauss_eq_iff) qed
instanceproof show\<open>euclidean_size (0::gauss) = 0\<close> by (simp add: euclidean_size_gauss_def) show\<open>euclidean_size (x mod y) < euclidean_size y\<close> if \<open>y \<noteq> 0\<close> for x y :: gauss
proof-
define X and Y and R and I where\<open>X = (Re x)\<^sup>2 + (Im x)\<^sup>2\<close> and \<open>Y = (Re y)\<^sup>2 + (Im y)\<^sup>2\<close> and\<open>R = Re x * Re y + Im x * Im y\<close> and \<open>I = Im x * Re y - Re x * Im y\<close> with that have\<open>0 < Y\<close> and rhs: \<open>int (euclidean_size y) = Y\<close> by (simp_all add: gauss_neq_0 euclidean_size_gauss_def) have\<open>X * Y = R\<^sup>2 + I\<^sup>2\<close> by (simp add: R_def I_def X_def Y_def power2_eq_square algebra_simps) let ?lhs = \<open>X - I * (I cdiv Y) - R * (R cdiv Y)
- I cdiv Y * (I cmod Y) - R cdiv Y * (R cmod Y)\<close> have\<open>?lhs = X + Y * (R cdiv Y) * (R cdiv Y) + Y * (I cdiv Y) * (I cdiv Y)
- 2 * (R cdiv Y * R + I cdiv Y * I)\<close> by (simp flip: minus_cmod_eq_mult_cdiv add: algebra_simps) alsohave\<open>\<dots> = (Re (x mod y))\<^sup>2 + (Im (x mod y))\<^sup>2\<close> by (simp add: X_def Y_def R_def I_def algebra_simps power2_eq_square) finallyhave lhs: \<open>int (euclidean_size (x mod y)) = ?lhs\<close> by (simp add: euclidean_size_gauss_def) have\<open>?lhs * Y = (I cmod Y)\<^sup>2 + (R cmod Y)\<^sup>2\<close> apply (simp add: algebra_simps power2_eq_square \<open>X * Y = R\<^sup>2 + I\<^sup>2\<close>) apply (simp flip: mult.assoc add.assoc minus_cmod_eq_mult_cdiv) apply (simp add: algebra_simps) done alsohave\<open>\<dots> \<le> (Y div 2)\<^sup>2 + (Y div 2)\<^sup>2\<close> by (rule add_mono) (use\<open>Y > 0\<close> abs_cmod_less_equal [of Y] in \<open>simp_all add: power2_le_iff_abs_le\<close>) alsohave\<open>\<dots> < Y\<^sup>2\<close> using\<open>Y > 0\<close> by (cases \<open>Y = 1\<close>) (simp_all add: power2_eq_square mult_le_less_imp_less flip: mult.assoc) finallyhave\<open>?lhs * Y < Y\<^sup>2\<close> . with\<open>Y > 0\<close> have \<open>?lhs < Y\<close> by (simp add: power2_eq_square) thenhave\<open>int (euclidean_size (x mod y)) < int (euclidean_size y)\<close> by (simp only: lhs rhs) thenshow ?thesis by simp qed show\<open>euclidean_size x \<le> euclidean_size (x * y)\<close> if \<open>y \<noteq> 0\<close> for x y :: gauss proof - from that have\<open>euclidean_size y > 0\<close> by (simp add: euclidean_size_gauss_def gauss_neq_0) thenhave\<open>euclidean_size x \<le> euclidean_size x * euclidean_size y\<close> by simp alsohave\<open>\<dots> = nat (((Re x)\<^sup>2 + (Im x)\<^sup>2) * ((Re y)\<^sup>2 + (Im y)\<^sup>2))\<close> by (simp add: euclidean_size_gauss_def nat_mult_distrib) alsohave\<open>\<dots> = euclidean_size (x * y)\<close> by (simp add: euclidean_size_gauss_def eq_nat_nat_iff) (simp add: algebra_simps power2_eq_square) finallyshow ?thesis . qed qed
end
end
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.