# HG changeset patch # User haftmann # Date 1665063719 0 # Node ID 63bcec915790d4c4df505e0a76198151f7330534 # Parent 4a064fad28b2b7c4a7a969334fdf22fc4165afc8 tuned proof diff -r 4a064fad28b2 -r 63bcec915790 src/HOL/Examples/Gauss_Numbers.thy --- a/src/HOL/Examples/Gauss_Numbers.thy Tue Oct 04 09:12:42 2022 +0000 +++ b/src/HOL/Examples/Gauss_Numbers.thy Thu Oct 06 13:41:59 2022 +0000 @@ -311,18 +311,29 @@ \Re (x div y) = (Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\ | \Im (x div y) = (Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\ -definition modulo_gauss :: \gauss \ gauss \ gauss\ +primcorec modulo_gauss :: \gauss \ gauss \ gauss\ where - \x mod y = x - x div y * y\ for x y :: gauss + \Re (x mod y) = Re x - + ((Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y - + (Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y)\ + | \Im (x mod y) = Im x - + ((Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y + + (Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y)\ -instance - apply standard - apply (simp_all add: modulo_gauss_def) - apply (auto simp add: gauss_eq_iff algebra_simps power2_eq_square) - apply (simp_all only: flip: mult.assoc distrib_right) - apply (simp_all only: mult.assoc [of \Im k\ \Re l\ \Re r\ for k l r]) - apply (simp_all add: sum_squares_eq_zero_iff mult.commute nonzero_mult_rdiv_cancel_right flip: distrib_left) - done +instance proof + fix x y :: gauss + show \x div 0 = 0\ + by (simp add: gauss_eq_iff) + show \x * y div y = x\ if \y \ 0\ + using that + apply (auto simp add: gauss_eq_iff algebra_simps power2_eq_square) + apply (simp_all only: flip: mult.assoc distrib_right) + apply (simp_all add: mult.assoc [of _ \Re y\ \Re y\] mult.assoc [of _ \Im y\ \Im y\] mult.commute [of _ \Re x\] flip: distrib_left) + apply (simp_all add: sum_squares_eq_zero_iff mult.commute nonzero_mult_rdiv_cancel_right flip: distrib_left) + done + show \x div y * y + x mod y = x\ + by (simp add: gauss_eq_iff) +qed end