76143
|
1 |
(* Author: Florian Haftmann, TU Muenchen; based on existing material on complex numbers\<close>
|
75955
|
2 |
*)
|
|
3 |
|
|
4 |
section \<open>Gauss Numbers: integral gauss numbers\<close>
|
|
5 |
|
|
6 |
theory Gauss_Numbers
|
76143
|
7 |
imports "HOL-Library.Rounded_Division"
|
75955
|
8 |
begin
|
|
9 |
|
|
10 |
codatatype gauss = Gauss (Re: int) (Im: int)
|
|
11 |
|
|
12 |
lemma gauss_eqI [intro?]:
|
|
13 |
\<open>x = y\<close> if \<open>Re x = Re y\<close> \<open>Im x = Im y\<close>
|
|
14 |
by (rule gauss.expand) (use that in simp)
|
|
15 |
|
|
16 |
lemma gauss_eq_iff:
|
|
17 |
\<open>x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y\<close>
|
|
18 |
by (auto intro: gauss_eqI)
|
|
19 |
|
|
20 |
|
|
21 |
subsection \<open>Basic arithmetic\<close>
|
|
22 |
|
|
23 |
instantiation gauss :: comm_ring_1
|
|
24 |
begin
|
|
25 |
|
|
26 |
primcorec zero_gauss :: \<open>gauss\<close>
|
|
27 |
where
|
|
28 |
\<open>Re 0 = 0\<close>
|
|
29 |
| \<open>Im 0 = 0\<close>
|
|
30 |
|
|
31 |
primcorec one_gauss :: \<open>gauss\<close>
|
|
32 |
where
|
|
33 |
\<open>Re 1 = 1\<close>
|
|
34 |
| \<open>Im 1 = 0\<close>
|
|
35 |
|
|
36 |
primcorec plus_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close>
|
|
37 |
where
|
|
38 |
\<open>Re (x + y) = Re x + Re y\<close>
|
|
39 |
| \<open>Im (x + y) = Im x + Im y\<close>
|
|
40 |
|
|
41 |
primcorec uminus_gauss :: \<open>gauss \<Rightarrow> gauss\<close>
|
|
42 |
where
|
|
43 |
\<open>Re (- x) = - Re x\<close>
|
|
44 |
| \<open>Im (- x) = - Im x\<close>
|
|
45 |
|
|
46 |
primcorec minus_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close>
|
|
47 |
where
|
|
48 |
\<open>Re (x - y) = Re x - Re y\<close>
|
|
49 |
| \<open>Im (x - y) = Im x - Im y\<close>
|
|
50 |
|
|
51 |
primcorec times_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close>
|
|
52 |
where
|
|
53 |
\<open>Re (x * y) = Re x * Re y - Im x * Im y\<close>
|
|
54 |
| \<open>Im (x * y) = Re x * Im y + Im x * Re y\<close>
|
|
55 |
|
|
56 |
instance
|
|
57 |
by standard (simp_all add: gauss_eq_iff algebra_simps)
|
|
58 |
|
|
59 |
end
|
|
60 |
|
|
61 |
lemma of_nat_gauss:
|
|
62 |
\<open>of_nat n = Gauss (int n) 0\<close>
|
|
63 |
by (induction n) (simp_all add: gauss_eq_iff)
|
|
64 |
|
|
65 |
lemma numeral_gauss:
|
|
66 |
\<open>numeral n = Gauss (numeral n) 0\<close>
|
|
67 |
proof -
|
|
68 |
have \<open>numeral n = (of_nat (numeral n) :: gauss)\<close>
|
|
69 |
by simp
|
|
70 |
also have \<open>\<dots> = Gauss (of_nat (numeral n)) 0\<close>
|
|
71 |
by (simp add: of_nat_gauss)
|
|
72 |
finally show ?thesis
|
|
73 |
by simp
|
|
74 |
qed
|
|
75 |
|
|
76 |
lemma of_int_gauss:
|
|
77 |
\<open>of_int k = Gauss k 0\<close>
|
|
78 |
by (simp add: gauss_eq_iff of_int_of_nat of_nat_gauss)
|
|
79 |
|
|
80 |
lemma conversion_simps [simp]:
|
|
81 |
\<open>Re (numeral m) = numeral m\<close>
|
|
82 |
\<open>Im (numeral m) = 0\<close>
|
|
83 |
\<open>Re (of_nat n) = int n\<close>
|
|
84 |
\<open>Im (of_nat n) = 0\<close>
|
|
85 |
\<open>Re (of_int k) = k\<close>
|
|
86 |
\<open>Im (of_int k) = 0\<close>
|
|
87 |
by (simp_all add: numeral_gauss of_nat_gauss of_int_gauss)
|
|
88 |
|
|
89 |
lemma gauss_eq_0:
|
|
90 |
\<open>z = 0 \<longleftrightarrow> (Re z)\<^sup>2 + (Im z)\<^sup>2 = 0\<close>
|
|
91 |
by (simp add: gauss_eq_iff sum_power2_eq_zero_iff)
|
|
92 |
|
|
93 |
lemma gauss_neq_0:
|
|
94 |
\<open>z \<noteq> 0 \<longleftrightarrow> (Re z)\<^sup>2 + (Im z)\<^sup>2 > 0\<close>
|
|
95 |
by (simp add: gauss_eq_0 sum_power2_ge_zero less_le)
|
|
96 |
|
|
97 |
lemma Re_sum [simp]:
|
|
98 |
\<open>Re (sum f s) = (\<Sum>x\<in>s. Re (f x))\<close>
|
|
99 |
by (induct s rule: infinite_finite_induct) auto
|
|
100 |
|
|
101 |
lemma Im_sum [simp]:
|
|
102 |
\<open>Im (sum f s) = (\<Sum>x\<in>s. Im (f x))\<close>
|
|
103 |
by (induct s rule: infinite_finite_induct) auto
|
|
104 |
|
|
105 |
instance gauss :: idom
|
|
106 |
proof
|
|
107 |
fix x y :: gauss
|
|
108 |
assume \<open>x \<noteq> 0\<close> \<open>y \<noteq> 0\<close>
|
|
109 |
then show \<open>x * y \<noteq> 0\<close>
|
|
110 |
by (simp_all add: gauss_eq_iff)
|
|
111 |
(smt (verit, best) mult_eq_0_iff mult_neg_neg mult_neg_pos mult_pos_neg mult_pos_pos)
|
|
112 |
qed
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
subsection \<open>The Gauss Number $i$\<close>
|
|
117 |
|
|
118 |
primcorec imaginary_unit :: gauss (\<open>\<i>\<close>)
|
|
119 |
where
|
|
120 |
\<open>Re \<i> = 0\<close>
|
|
121 |
| \<open>Im \<i> = 1\<close>
|
|
122 |
|
|
123 |
lemma Gauss_eq:
|
|
124 |
\<open>Gauss a b = of_int a + \<i> * of_int b\<close>
|
|
125 |
by (simp add: gauss_eq_iff)
|
|
126 |
|
|
127 |
lemma gauss_eq:
|
|
128 |
\<open>a = of_int (Re a) + \<i> * of_int (Im a)\<close>
|
|
129 |
by (simp add: gauss_eq_iff)
|
|
130 |
|
|
131 |
lemma gauss_i_not_zero [simp]:
|
|
132 |
\<open>\<i> \<noteq> 0\<close>
|
|
133 |
by (simp add: gauss_eq_iff)
|
|
134 |
|
|
135 |
lemma gauss_i_not_one [simp]:
|
|
136 |
\<open>\<i> \<noteq> 1\<close>
|
|
137 |
by (simp add: gauss_eq_iff)
|
|
138 |
|
|
139 |
lemma gauss_i_not_numeral [simp]:
|
|
140 |
\<open>\<i> \<noteq> numeral n\<close>
|
|
141 |
by (simp add: gauss_eq_iff)
|
|
142 |
|
|
143 |
lemma gauss_i_not_neg_numeral [simp]:
|
|
144 |
\<open>\<i> \<noteq> - numeral n\<close>
|
|
145 |
by (simp add: gauss_eq_iff)
|
|
146 |
|
|
147 |
lemma i_mult_i_eq [simp]:
|
|
148 |
\<open>\<i> * \<i> = - 1\<close>
|
|
149 |
by (simp add: gauss_eq_iff)
|
|
150 |
|
|
151 |
lemma gauss_i_mult_minus [simp]:
|
|
152 |
\<open>\<i> * (\<i> * x) = - x\<close>
|
|
153 |
by (simp flip: mult.assoc)
|
|
154 |
|
|
155 |
lemma i_squared [simp]:
|
|
156 |
\<open>\<i>\<^sup>2 = - 1\<close>
|
|
157 |
by (simp add: power2_eq_square)
|
|
158 |
|
|
159 |
lemma i_even_power [simp]:
|
|
160 |
\<open>\<i> ^ (n * 2) = (- 1) ^ n\<close>
|
|
161 |
unfolding mult.commute [of n] power_mult by simp
|
|
162 |
|
|
163 |
lemma Re_i_times [simp]:
|
|
164 |
\<open>Re (\<i> * z) = - Im z\<close>
|
|
165 |
by simp
|
|
166 |
|
|
167 |
lemma Im_i_times [simp]:
|
|
168 |
\<open>Im (\<i> * z) = Re z\<close>
|
|
169 |
by simp
|
|
170 |
|
|
171 |
lemma i_times_eq_iff:
|
|
172 |
\<open>\<i> * w = z \<longleftrightarrow> w = - (\<i> * z)\<close>
|
|
173 |
by auto
|
|
174 |
|
|
175 |
lemma is_unit_i [simp]:
|
|
176 |
\<open>\<i> dvd 1\<close>
|
|
177 |
by (rule dvdI [of _ _ \<open>- \<i>\<close>]) simp
|
|
178 |
|
|
179 |
lemma gauss_numeral [code_post]:
|
|
180 |
\<open>Gauss 0 0 = 0\<close>
|
|
181 |
\<open>Gauss 1 0 = 1\<close>
|
|
182 |
\<open>Gauss (- 1) 0 = - 1\<close>
|
|
183 |
\<open>Gauss (numeral n) 0 = numeral n\<close>
|
|
184 |
\<open>Gauss (- numeral n) 0 = - numeral n\<close>
|
|
185 |
\<open>Gauss 0 1 = \<i>\<close>
|
|
186 |
\<open>Gauss 0 (- 1) = - \<i>\<close>
|
|
187 |
\<open>Gauss 0 (numeral n) = numeral n * \<i>\<close>
|
|
188 |
\<open>Gauss 0 (- numeral n) = - numeral n * \<i>\<close>
|
|
189 |
\<open>Gauss 1 1 = 1 + \<i>\<close>
|
|
190 |
\<open>Gauss (- 1) 1 = - 1 + \<i>\<close>
|
|
191 |
\<open>Gauss (numeral n) 1 = numeral n + \<i>\<close>
|
|
192 |
\<open>Gauss (- numeral n) 1 = - numeral n + \<i>\<close>
|
|
193 |
\<open>Gauss 1 (- 1) = 1 - \<i>\<close>
|
|
194 |
\<open>Gauss 1 (numeral n) = 1 + numeral n * \<i>\<close>
|
|
195 |
\<open>Gauss 1 (- numeral n) = 1 - numeral n * \<i>\<close>
|
|
196 |
\<open>Gauss (- 1) (- 1) = - 1 - \<i>\<close>
|
|
197 |
\<open>Gauss (numeral n) (- 1) = numeral n - \<i>\<close>
|
|
198 |
\<open>Gauss (- numeral n) (- 1) = - numeral n - \<i>\<close>
|
|
199 |
\<open>Gauss (- 1) (numeral n) = - 1 + numeral n * \<i>\<close>
|
|
200 |
\<open>Gauss (- 1) (- numeral n) = - 1 - numeral n * \<i>\<close>
|
|
201 |
\<open>Gauss (numeral m) (numeral n) = numeral m + numeral n * \<i>\<close>
|
|
202 |
\<open>Gauss (- numeral m) (numeral n) = - numeral m + numeral n * \<i>\<close>
|
|
203 |
\<open>Gauss (numeral m) (- numeral n) = numeral m - numeral n * \<i>\<close>
|
|
204 |
\<open>Gauss (- numeral m) (- numeral n) = - numeral m - numeral n * \<i>\<close>
|
|
205 |
by (simp_all add: gauss_eq_iff)
|
|
206 |
|
|
207 |
|
|
208 |
subsection \<open>Gauss Conjugation\<close>
|
|
209 |
|
|
210 |
primcorec cnj :: \<open>gauss \<Rightarrow> gauss\<close>
|
|
211 |
where
|
|
212 |
\<open>Re (cnj z) = Re z\<close>
|
|
213 |
| \<open>Im (cnj z) = - Im z\<close>
|
|
214 |
|
|
215 |
lemma gauss_cnj_cancel_iff [simp]:
|
|
216 |
\<open>cnj x = cnj y \<longleftrightarrow> x = y\<close>
|
|
217 |
by (simp add: gauss_eq_iff)
|
|
218 |
|
|
219 |
lemma gauss_cnj_cnj [simp]:
|
|
220 |
\<open>cnj (cnj z) = z\<close>
|
|
221 |
by (simp add: gauss_eq_iff)
|
|
222 |
|
|
223 |
lemma gauss_cnj_zero [simp]:
|
|
224 |
\<open>cnj 0 = 0\<close>
|
|
225 |
by (simp add: gauss_eq_iff)
|
|
226 |
|
|
227 |
lemma gauss_cnj_zero_iff [iff]:
|
|
228 |
\<open>cnj z = 0 \<longleftrightarrow> z = 0\<close>
|
|
229 |
by (simp add: gauss_eq_iff)
|
|
230 |
|
|
231 |
lemma gauss_cnj_one_iff [simp]:
|
|
232 |
\<open>cnj z = 1 \<longleftrightarrow> z = 1\<close>
|
|
233 |
by (simp add: gauss_eq_iff)
|
|
234 |
|
|
235 |
lemma gauss_cnj_add [simp]:
|
|
236 |
\<open>cnj (x + y) = cnj x + cnj y\<close>
|
|
237 |
by (simp add: gauss_eq_iff)
|
|
238 |
|
|
239 |
lemma cnj_sum [simp]:
|
|
240 |
\<open>cnj (sum f s) = (\<Sum>x\<in>s. cnj (f x))\<close>
|
|
241 |
by (induct s rule: infinite_finite_induct) auto
|
|
242 |
|
|
243 |
lemma gauss_cnj_diff [simp]:
|
|
244 |
\<open>cnj (x - y) = cnj x - cnj y\<close>
|
|
245 |
by (simp add: gauss_eq_iff)
|
|
246 |
|
|
247 |
lemma gauss_cnj_minus [simp]:
|
|
248 |
\<open>cnj (- x) = - cnj x\<close>
|
|
249 |
by (simp add: gauss_eq_iff)
|
|
250 |
|
|
251 |
lemma gauss_cnj_one [simp]:
|
|
252 |
\<open>cnj 1 = 1\<close>
|
|
253 |
by (simp add: gauss_eq_iff)
|
|
254 |
|
|
255 |
lemma gauss_cnj_mult [simp]:
|
|
256 |
\<open>cnj (x * y) = cnj x * cnj y\<close>
|
|
257 |
by (simp add: gauss_eq_iff)
|
|
258 |
|
|
259 |
lemma cnj_prod [simp]:
|
|
260 |
\<open>cnj (prod f s) = (\<Prod>x\<in>s. cnj (f x))\<close>
|
|
261 |
by (induct s rule: infinite_finite_induct) auto
|
|
262 |
|
|
263 |
lemma gauss_cnj_power [simp]:
|
|
264 |
\<open>cnj (x ^ n) = cnj x ^ n\<close>
|
|
265 |
by (induct n) simp_all
|
|
266 |
|
|
267 |
lemma gauss_cnj_numeral [simp]:
|
|
268 |
\<open>cnj (numeral w) = numeral w\<close>
|
|
269 |
by (simp add: gauss_eq_iff)
|
|
270 |
|
|
271 |
lemma gauss_cnj_of_nat [simp]:
|
|
272 |
\<open>cnj (of_nat n) = of_nat n\<close>
|
|
273 |
by (simp add: gauss_eq_iff)
|
|
274 |
|
|
275 |
lemma gauss_cnj_of_int [simp]:
|
|
276 |
\<open>cnj (of_int z) = of_int z\<close>
|
|
277 |
by (simp add: gauss_eq_iff)
|
|
278 |
|
|
279 |
lemma gauss_cnj_i [simp]:
|
|
280 |
\<open>cnj \<i> = - \<i>\<close>
|
|
281 |
by (simp add: gauss_eq_iff)
|
|
282 |
|
|
283 |
lemma gauss_add_cnj:
|
|
284 |
\<open>z + cnj z = of_int (2 * Re z)\<close>
|
|
285 |
by (simp add: gauss_eq_iff)
|
|
286 |
|
|
287 |
lemma gauss_diff_cnj:
|
|
288 |
\<open>z - cnj z = of_int (2 * Im z) * \<i>\<close>
|
|
289 |
by (simp add: gauss_eq_iff)
|
|
290 |
|
|
291 |
lemma gauss_mult_cnj:
|
|
292 |
\<open>z * cnj z = of_int ((Re z)\<^sup>2 + (Im z)\<^sup>2)\<close>
|
|
293 |
by (simp add: gauss_eq_iff power2_eq_square)
|
|
294 |
|
|
295 |
lemma cnj_add_mult_eq_Re:
|
|
296 |
\<open>z * cnj w + cnj z * w = of_int (2 * Re (z * cnj w))\<close>
|
|
297 |
by (simp add: gauss_eq_iff)
|
|
298 |
|
|
299 |
lemma gauss_In_mult_cnj_zero [simp]:
|
|
300 |
\<open>Im (z * cnj z) = 0\<close>
|
|
301 |
by simp
|
|
302 |
|
|
303 |
|
|
304 |
subsection \<open>Algebraic division\<close>
|
|
305 |
|
|
306 |
instantiation gauss :: idom_modulo
|
|
307 |
begin
|
|
308 |
|
|
309 |
primcorec divide_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close>
|
|
310 |
where
|
76143
|
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) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2)\<close>
|
75955
|
313 |
|
76250
|
314 |
primcorec modulo_gauss :: \<open>gauss \<Rightarrow> gauss \<Rightarrow> gauss\<close>
|
75955
|
315 |
where
|
76250
|
316 |
\<open>Re (x mod y) = Re x -
|
|
317 |
((Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y -
|
|
318 |
(Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y)\<close>
|
|
319 |
| \<open>Im (x mod y) = Im x -
|
|
320 |
((Re x * Re y + Im x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Im y +
|
|
321 |
(Im x * Re y - Re x * Im y) rdiv ((Re y)\<^sup>2 + (Im y)\<^sup>2) * Re y)\<close>
|
75955
|
322 |
|
76250
|
323 |
instance proof
|
|
324 |
fix x y :: gauss
|
|
325 |
show \<open>x div 0 = 0\<close>
|
|
326 |
by (simp add: gauss_eq_iff)
|
|
327 |
show \<open>x * y div y = x\<close> if \<open>y \<noteq> 0\<close>
|
76251
|
328 |
proof -
|
|
329 |
define Y where \<open>Y = (Re y)\<^sup>2 + (Im y)\<^sup>2\<close>
|
|
330 |
moreover have \<open>Y > 0\<close>
|
|
331 |
using that by (simp add: gauss_eq_0 less_le Y_def)
|
|
332 |
have *: \<open>Im y * (Im y * Re x) + Re x * (Re y * Re y) = Re x * Y\<close>
|
|
333 |
\<open>Im x * (Im y * Im y) + Im x * (Re y * Re y) = Im x * Y\<close>
|
|
334 |
\<open>(Im y)\<^sup>2 + (Re y)\<^sup>2 = Y\<close>
|
|
335 |
by (simp_all add: power2_eq_square algebra_simps Y_def)
|
|
336 |
from \<open>Y > 0\<close> show ?thesis
|
|
337 |
by (simp add: gauss_eq_iff algebra_simps) (simp add: * nonzero_mult_rdiv_cancel_right)
|
|
338 |
qed
|
76250
|
339 |
show \<open>x div y * y + x mod y = x\<close>
|
|
340 |
by (simp add: gauss_eq_iff)
|
|
341 |
qed
|
75955
|
342 |
|
|
343 |
end
|
|
344 |
|
76251
|
345 |
instantiation gauss :: euclidean_ring
|
|
346 |
begin
|
|
347 |
|
|
348 |
definition euclidean_size_gauss :: \<open>gauss \<Rightarrow> nat\<close>
|
|
349 |
where \<open>euclidean_size x = nat ((Re x)\<^sup>2 + (Im x)\<^sup>2)\<close>
|
|
350 |
|
|
351 |
instance proof
|
|
352 |
show \<open>euclidean_size (0::gauss) = 0\<close>
|
|
353 |
by (simp add: euclidean_size_gauss_def)
|
|
354 |
show \<open>euclidean_size (x mod y) < euclidean_size y\<close> if \<open>y \<noteq> 0\<close> for x y :: gauss
|
|
355 |
proof-
|
|
356 |
define X and Y and R and I
|
|
357 |
where \<open>X = (Re x)\<^sup>2 + (Im x)\<^sup>2\<close> and \<open>Y = (Re y)\<^sup>2 + (Im y)\<^sup>2\<close>
|
|
358 |
and \<open>R = Re x * Re y + Im x * Im y\<close> and \<open>I = Im x * Re y - Re x * Im y\<close>
|
|
359 |
with that have \<open>0 < Y\<close> and rhs: \<open>int (euclidean_size y) = Y\<close>
|
|
360 |
by (simp_all add: gauss_neq_0 euclidean_size_gauss_def)
|
|
361 |
have \<open>X * Y = R\<^sup>2 + I\<^sup>2\<close>
|
|
362 |
by (simp add: R_def I_def X_def Y_def power2_eq_square algebra_simps)
|
|
363 |
let ?lhs = \<open>X - I * (I rdiv Y) - R * (R rdiv Y)
|
|
364 |
- I rdiv Y * (I rmod Y) - R rdiv Y * (R rmod Y)\<close>
|
|
365 |
have \<open>?lhs = X + Y * (R rdiv Y) * (R rdiv Y) + Y * (I rdiv Y) * (I rdiv Y)
|
|
366 |
- 2 * (R rdiv Y * R + I rdiv Y * I)\<close>
|
|
367 |
by (simp flip: minus_rmod_eq_mult_rdiv add: algebra_simps)
|
|
368 |
also have \<open>\<dots> = (Re (x mod y))\<^sup>2 + (Im (x mod y))\<^sup>2\<close>
|
|
369 |
by (simp add: X_def Y_def R_def I_def algebra_simps power2_eq_square)
|
|
370 |
finally have lhs: \<open>int (euclidean_size (x mod y)) = ?lhs\<close>
|
|
371 |
by (simp add: euclidean_size_gauss_def)
|
|
372 |
have \<open>?lhs * Y = (I rmod Y)\<^sup>2 + (R rmod Y)\<^sup>2\<close>
|
|
373 |
apply (simp add: algebra_simps power2_eq_square \<open>X * Y = R\<^sup>2 + I\<^sup>2\<close>)
|
|
374 |
apply (simp flip: mult.assoc add.assoc minus_rmod_eq_mult_rdiv)
|
|
375 |
apply (simp add: algebra_simps)
|
|
376 |
done
|
|
377 |
also have \<open>\<dots> \<le> (Y div 2)\<^sup>2 + (Y div 2)\<^sup>2\<close>
|
|
378 |
by (rule add_mono) (use \<open>Y > 0\<close> abs_rmod_less_equal [of Y] in \<open>simp_all add: power2_le_iff_abs_le\<close>)
|
|
379 |
also have \<open>\<dots> < Y\<^sup>2\<close>
|
|
380 |
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)
|
|
381 |
finally have \<open>?lhs * Y < Y\<^sup>2\<close> .
|
|
382 |
with \<open>Y > 0\<close> have \<open>?lhs < Y\<close>
|
|
383 |
by (simp add: power2_eq_square)
|
|
384 |
then have \<open>int (euclidean_size (x mod y)) < int (euclidean_size y)\<close>
|
|
385 |
by (simp only: lhs rhs)
|
|
386 |
then show ?thesis
|
|
387 |
by simp
|
|
388 |
qed
|
|
389 |
show \<open>euclidean_size x \<le> euclidean_size (x * y)\<close> if \<open>y \<noteq> 0\<close> for x y :: gauss
|
|
390 |
proof -
|
|
391 |
from that have \<open>euclidean_size y > 0\<close>
|
|
392 |
by (simp add: euclidean_size_gauss_def gauss_neq_0)
|
|
393 |
then have \<open>euclidean_size x \<le> euclidean_size x * euclidean_size y\<close>
|
|
394 |
by simp
|
|
395 |
also have \<open>\<dots> = nat (((Re x)\<^sup>2 + (Im x)\<^sup>2) * ((Re y)\<^sup>2 + (Im y)\<^sup>2))\<close>
|
|
396 |
by (simp add: euclidean_size_gauss_def nat_mult_distrib)
|
|
397 |
also have \<open>\<dots> = euclidean_size (x * y)\<close>
|
|
398 |
by (simp add: euclidean_size_gauss_def eq_nat_nat_iff) (simp add: algebra_simps power2_eq_square)
|
|
399 |
finally show ?thesis .
|
|
400 |
qed
|
|
401 |
qed
|
|
402 |
|
75955
|
403 |
end
|
76251
|
404 |
|
|
405 |
end
|