author | haftmann |
Thu, 16 Nov 2017 11:30:23 +0100 | |
changeset 67078 | 6a85b8a9c28c |
parent 67051 | e7e54a0b9197 |
child 71398 | e0237f2eb49d |
permissions | -rw-r--r-- |
65435 | 1 |
(* Title: HOL/Computational_Algebra/Normalized_Fraction.thy |
64591
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64240
diff
changeset
|
2 |
Author: Manuel Eberl |
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64240
diff
changeset
|
3 |
*) |
240a39af9ec4
restructured matter on polynomials and normalized fractions
haftmann
parents:
64240
diff
changeset
|
4 |
|
63500 | 5 |
theory Normalized_Fraction |
6 |
imports |
|
7 |
Main |
|
65417 | 8 |
Euclidean_Algorithm |
65366 | 9 |
Fraction_Field |
63500 | 10 |
begin |
11 |
||
12 |
definition quot_to_fract :: "'a :: {idom} \<times> 'a \<Rightarrow> 'a fract" where |
|
13 |
"quot_to_fract = (\<lambda>(a,b). Fraction_Field.Fract a b)" |
|
14 |
||
15 |
definition normalize_quot :: "'a :: {ring_gcd,idom_divide} \<times> 'a \<Rightarrow> 'a \<times> 'a" where |
|
16 |
"normalize_quot = |
|
17 |
(\<lambda>(a,b). if b = 0 then (0,1) else let d = gcd a b * unit_factor b in (a div d, b div d))" |
|
18 |
||
67051 | 19 |
lemma normalize_quot_zero [simp]: |
20 |
"normalize_quot (a, 0) = (0, 1)" |
|
21 |
by (simp add: normalize_quot_def) |
|
22 |
||
67078
6a85b8a9c28c
removed overambitious simp rules from e7e54a0b9197
haftmann
parents:
67051
diff
changeset
|
23 |
lemma normalize_quot_proj: |
67051 | 24 |
"fst (normalize_quot (a, b)) = a div (gcd a b * unit_factor b)" |
25 |
"snd (normalize_quot (a, b)) = normalize b div gcd a b" if "b \<noteq> 0" |
|
26 |
using that by (simp_all add: normalize_quot_def Let_def mult.commute [of _ "unit_factor b"] dvd_div_mult2_eq mult_unit_dvd_iff') |
|
27 |
||
63500 | 28 |
definition normalized_fracts :: "('a :: {ring_gcd,idom_divide} \<times> 'a) set" where |
29 |
"normalized_fracts = {(a,b). coprime a b \<and> unit_factor b = 1}" |
|
30 |
||
31 |
lemma not_normalized_fracts_0_denom [simp]: "(a, 0) \<notin> normalized_fracts" |
|
32 |
by (auto simp: normalized_fracts_def) |
|
33 |
||
34 |
lemma unit_factor_snd_normalize_quot [simp]: |
|
35 |
"unit_factor (snd (normalize_quot x)) = 1" |
|
36 |
by (simp add: normalize_quot_def case_prod_unfold Let_def dvd_unit_factor_div |
|
37 |
mult_unit_dvd_iff unit_factor_mult unit_factor_gcd) |
|
38 |
||
39 |
lemma snd_normalize_quot_nonzero [simp]: "snd (normalize_quot x) \<noteq> 0" |
|
40 |
using unit_factor_snd_normalize_quot[of x] |
|
41 |
by (auto simp del: unit_factor_snd_normalize_quot) |
|
42 |
||
43 |
lemma normalize_quot_aux: |
|
44 |
fixes a b |
|
45 |
assumes "b \<noteq> 0" |
|
46 |
defines "d \<equiv> gcd a b * unit_factor b" |
|
47 |
shows "a = fst (normalize_quot (a,b)) * d" "b = snd (normalize_quot (a,b)) * d" |
|
48 |
"d dvd a" "d dvd b" "d \<noteq> 0" |
|
49 |
proof - |
|
50 |
from assms show "d dvd a" "d dvd b" |
|
51 |
by (simp_all add: d_def mult_unit_dvd_iff) |
|
52 |
thus "a = fst (normalize_quot (a,b)) * d" "b = snd (normalize_quot (a,b)) * d" "d \<noteq> 0" |
|
53 |
by (auto simp: normalize_quot_def Let_def d_def \<open>b \<noteq> 0\<close>) |
|
54 |
qed |
|
55 |
||
56 |
lemma normalize_quotE: |
|
57 |
assumes "b \<noteq> 0" |
|
58 |
obtains d where "a = fst (normalize_quot (a,b)) * d" "b = snd (normalize_quot (a,b)) * d" |
|
59 |
"d dvd a" "d dvd b" "d \<noteq> 0" |
|
60 |
using that[OF normalize_quot_aux[OF assms]] . |
|
61 |
||
62 |
lemma normalize_quotE': |
|
63 |
assumes "snd x \<noteq> 0" |
|
64 |
obtains d where "fst x = fst (normalize_quot x) * d" "snd x = snd (normalize_quot x) * d" |
|
65 |
"d dvd fst x" "d dvd snd x" "d \<noteq> 0" |
|
66 |
proof - |
|
67 |
from normalize_quotE[OF assms, of "fst x"] guess d . |
|
68 |
from this show ?thesis unfolding prod.collapse by (intro that[of d]) |
|
69 |
qed |
|
70 |
||
71 |
lemma coprime_normalize_quot: |
|
72 |
"coprime (fst (normalize_quot x)) (snd (normalize_quot x))" |
|
67051 | 73 |
by (simp add: normalize_quot_def case_prod_unfold div_mult_unit2) |
74 |
(metis coprime_mult_self_right_iff div_gcd_coprime unit_div_mult_self unit_factor_is_unit) |
|
63500 | 75 |
|
76 |
lemma normalize_quot_in_normalized_fracts [simp]: "normalize_quot x \<in> normalized_fracts" |
|
77 |
by (simp add: normalized_fracts_def coprime_normalize_quot case_prod_unfold) |
|
78 |
||
79 |
lemma normalize_quot_eq_iff: |
|
80 |
assumes "b \<noteq> 0" "d \<noteq> 0" |
|
81 |
shows "normalize_quot (a,b) = normalize_quot (c,d) \<longleftrightarrow> a * d = b * c" |
|
82 |
proof - |
|
83 |
define x y where "x = normalize_quot (a,b)" and "y = normalize_quot (c,d)" |
|
84 |
from normalize_quotE[OF assms(1), of a] normalize_quotE[OF assms(2), of c] |
|
85 |
obtain d1 d2 |
|
86 |
where "a = fst x * d1" "b = snd x * d1" "c = fst y * d2" "d = snd y * d2" "d1 \<noteq> 0" "d2 \<noteq> 0" |
|
87 |
unfolding x_def y_def by metis |
|
88 |
hence "a * d = b * c \<longleftrightarrow> fst x * snd y = snd x * fst y" by simp |
|
89 |
also have "\<dots> \<longleftrightarrow> fst x = fst y \<and> snd x = snd y" |
|
90 |
by (intro coprime_crossproduct') (simp_all add: x_def y_def coprime_normalize_quot) |
|
91 |
also have "\<dots> \<longleftrightarrow> x = y" using prod_eqI by blast |
|
92 |
finally show "x = y \<longleftrightarrow> a * d = b * c" .. |
|
93 |
qed |
|
94 |
||
95 |
lemma normalize_quot_eq_iff': |
|
96 |
assumes "snd x \<noteq> 0" "snd y \<noteq> 0" |
|
97 |
shows "normalize_quot x = normalize_quot y \<longleftrightarrow> fst x * snd y = snd x * fst y" |
|
98 |
using assms by (cases x, cases y, hypsubst) (subst normalize_quot_eq_iff, simp_all) |
|
99 |
||
100 |
lemma normalize_quot_id: "x \<in> normalized_fracts \<Longrightarrow> normalize_quot x = x" |
|
101 |
by (auto simp: normalized_fracts_def normalize_quot_def case_prod_unfold) |
|
102 |
||
103 |
lemma normalize_quot_idem [simp]: "normalize_quot (normalize_quot x) = normalize_quot x" |
|
104 |
by (rule normalize_quot_id) simp_all |
|
105 |
||
106 |
lemma fractrel_iff_normalize_quot_eq: |
|
107 |
"fractrel x y \<longleftrightarrow> normalize_quot x = normalize_quot y \<and> snd x \<noteq> 0 \<and> snd y \<noteq> 0" |
|
108 |
by (cases x, cases y) (auto simp: fractrel_def normalize_quot_eq_iff) |
|
109 |
||
110 |
lemma fractrel_normalize_quot_left: |
|
111 |
assumes "snd x \<noteq> 0" |
|
112 |
shows "fractrel (normalize_quot x) y \<longleftrightarrow> fractrel x y" |
|
113 |
using assms by (subst (1 2) fractrel_iff_normalize_quot_eq) auto |
|
114 |
||
115 |
lemma fractrel_normalize_quot_right: |
|
116 |
assumes "snd x \<noteq> 0" |
|
117 |
shows "fractrel y (normalize_quot x) \<longleftrightarrow> fractrel y x" |
|
118 |
using assms by (subst (1 2) fractrel_iff_normalize_quot_eq) auto |
|
119 |
||
120 |
||
121 |
lift_definition quot_of_fract :: "'a :: {ring_gcd,idom_divide} fract \<Rightarrow> 'a \<times> 'a" |
|
122 |
is normalize_quot |
|
123 |
by (subst (asm) fractrel_iff_normalize_quot_eq) simp_all |
|
124 |
||
125 |
lemma quot_to_fract_quot_of_fract [simp]: "quot_to_fract (quot_of_fract x) = x" |
|
126 |
unfolding quot_to_fract_def |
|
127 |
proof transfer |
|
128 |
fix x :: "'a \<times> 'a" assume rel: "fractrel x x" |
|
129 |
define x' where "x' = normalize_quot x" |
|
130 |
obtain a b where [simp]: "x = (a, b)" by (cases x) |
|
131 |
from rel have "b \<noteq> 0" by simp |
|
132 |
from normalize_quotE[OF this, of a] guess d . |
|
133 |
hence "a = fst x' * d" "b = snd x' * d" "d \<noteq> 0" "snd x' \<noteq> 0" by (simp_all add: x'_def) |
|
134 |
thus "fractrel (case x' of (a, b) \<Rightarrow> if b = 0 then (0, 1) else (a, b)) x" |
|
135 |
by (auto simp add: case_prod_unfold) |
|
136 |
qed |
|
137 |
||
138 |
lemma quot_of_fract_quot_to_fract: "quot_of_fract (quot_to_fract x) = normalize_quot x" |
|
139 |
proof (cases "snd x = 0") |
|
140 |
case True |
|
141 |
thus ?thesis unfolding quot_to_fract_def |
|
142 |
by transfer (simp add: case_prod_unfold normalize_quot_def) |
|
143 |
next |
|
144 |
case False |
|
145 |
thus ?thesis unfolding quot_to_fract_def by transfer (simp add: case_prod_unfold) |
|
146 |
qed |
|
147 |
||
148 |
lemma quot_of_fract_quot_to_fract': |
|
149 |
"x \<in> normalized_fracts \<Longrightarrow> quot_of_fract (quot_to_fract x) = x" |
|
150 |
unfolding quot_to_fract_def by transfer (auto simp: normalize_quot_id) |
|
151 |
||
152 |
lemma quot_of_fract_in_normalized_fracts [simp]: "quot_of_fract x \<in> normalized_fracts" |
|
153 |
by transfer simp |
|
154 |
||
155 |
lemma normalize_quotI: |
|
156 |
assumes "a * d = b * c" "b \<noteq> 0" "(c, d) \<in> normalized_fracts" |
|
157 |
shows "normalize_quot (a, b) = (c, d)" |
|
158 |
proof - |
|
159 |
from assms have "normalize_quot (a, b) = normalize_quot (c, d)" |
|
160 |
by (subst normalize_quot_eq_iff) auto |
|
161 |
also have "\<dots> = (c, d)" by (intro normalize_quot_id) fact |
|
162 |
finally show ?thesis . |
|
163 |
qed |
|
164 |
||
165 |
lemma td_normalized_fract: |
|
166 |
"type_definition quot_of_fract quot_to_fract normalized_fracts" |
|
167 |
by standard (simp_all add: quot_of_fract_quot_to_fract') |
|
168 |
||
169 |
lemma quot_of_fract_add_aux: |
|
170 |
assumes "snd x \<noteq> 0" "snd y \<noteq> 0" |
|
171 |
shows "(fst x * snd y + fst y * snd x) * (snd (normalize_quot x) * snd (normalize_quot y)) = |
|
172 |
snd x * snd y * (fst (normalize_quot x) * snd (normalize_quot y) + |
|
173 |
snd (normalize_quot x) * fst (normalize_quot y))" |
|
174 |
proof - |
|
175 |
from normalize_quotE'[OF assms(1)] guess d . note d = this |
|
176 |
from normalize_quotE'[OF assms(2)] guess e . note e = this |
|
177 |
show ?thesis by (simp_all add: d e algebra_simps) |
|
178 |
qed |
|
179 |
||
180 |
||
181 |
locale fract_as_normalized_quot |
|
182 |
begin |
|
183 |
setup_lifting td_normalized_fract |
|
184 |
end |
|
185 |
||
186 |
||
187 |
lemma quot_of_fract_add: |
|
188 |
"quot_of_fract (x + y) = |
|
189 |
(let (a,b) = quot_of_fract x; (c,d) = quot_of_fract y |
|
190 |
in normalize_quot (a * d + b * c, b * d))" |
|
191 |
by transfer (insert quot_of_fract_add_aux, |
|
192 |
simp_all add: Let_def case_prod_unfold normalize_quot_eq_iff) |
|
193 |
||
194 |
lemma quot_of_fract_uminus: |
|
195 |
"quot_of_fract (-x) = (let (a,b) = quot_of_fract x in (-a, b))" |
|
64592
7759f1766189
more fine-grained type class hierarchy for div and mod
haftmann
parents:
64591
diff
changeset
|
196 |
by transfer (auto simp: case_prod_unfold Let_def normalize_quot_def dvd_neg_div mult_unit_dvd_iff) |
63500 | 197 |
|
198 |
lemma quot_of_fract_diff: |
|
199 |
"quot_of_fract (x - y) = |
|
200 |
(let (a,b) = quot_of_fract x; (c,d) = quot_of_fract y |
|
201 |
in normalize_quot (a * d - b * c, b * d))" (is "_ = ?rhs") |
|
202 |
proof - |
|
203 |
have "x - y = x + -y" by simp |
|
204 |
also have "quot_of_fract \<dots> = ?rhs" |
|
205 |
by (simp only: quot_of_fract_add quot_of_fract_uminus Let_def case_prod_unfold) simp_all |
|
206 |
finally show ?thesis . |
|
207 |
qed |
|
208 |
||
209 |
lemma normalize_quot_mult_coprime: |
|
210 |
assumes "coprime a b" "coprime c d" "unit_factor b = 1" "unit_factor d = 1" |
|
211 |
defines "e \<equiv> fst (normalize_quot (a, d))" and "f \<equiv> snd (normalize_quot (a, d))" |
|
212 |
and "g \<equiv> fst (normalize_quot (c, b))" and "h \<equiv> snd (normalize_quot (c, b))" |
|
213 |
shows "normalize_quot (a * c, b * d) = (e * g, f * h)" |
|
214 |
proof (rule normalize_quotI) |
|
67051 | 215 |
from assms have "gcd a b = 1" "gcd c d = 1" |
216 |
by simp_all |
|
63500 | 217 |
from assms have "b \<noteq> 0" "d \<noteq> 0" by auto |
67051 | 218 |
with assms have "normalize b = b" "normalize d = d" |
219 |
by (auto intro: normalize_unit_factor_eqI) |
|
220 |
from normalize_quotE [OF \<open>b \<noteq> 0\<close>, of c] guess k . |
|
221 |
note k = this [folded \<open>gcd a b = 1\<close> \<open>gcd c d = 1\<close> assms(3) assms(4)] |
|
222 |
from normalize_quotE [OF \<open>d \<noteq> 0\<close>, of a] guess l . |
|
223 |
note l = this [folded \<open>gcd a b = 1\<close> \<open>gcd c d = 1\<close> assms(3) assms(4)] |
|
224 |
from k l show "a * c * (f * h) = b * d * (e * g)" |
|
225 |
by (metis e_def f_def g_def h_def mult.commute mult.left_commute) |
|
63500 | 226 |
from assms have [simp]: "unit_factor f = 1" "unit_factor h = 1" |
227 |
by simp_all |
|
228 |
from assms have "coprime e f" "coprime g h" by (simp_all add: coprime_normalize_quot) |
|
67051 | 229 |
with k l assms(1,2) \<open>b \<noteq> 0\<close> \<open>d \<noteq> 0\<close> \<open>unit_factor b = 1\<close> \<open>unit_factor d = 1\<close> |
230 |
\<open>normalize b = b\<close> \<open>normalize d = d\<close> |
|
231 |
show "(e * g, f * h) \<in> normalized_fracts" |
|
232 |
by (simp add: normalized_fracts_def unit_factor_mult e_def f_def g_def h_def |
|
233 |
coprime_normalize_quot dvd_unit_factor_div unit_factor_gcd) |
|
234 |
(metis coprime_mult_left_iff coprime_mult_right_iff) |
|
63500 | 235 |
qed (insert assms(3,4), auto) |
236 |
||
237 |
lemma normalize_quot_mult: |
|
238 |
assumes "snd x \<noteq> 0" "snd y \<noteq> 0" |
|
239 |
shows "normalize_quot (fst x * fst y, snd x * snd y) = normalize_quot |
|
240 |
(fst (normalize_quot x) * fst (normalize_quot y), |
|
241 |
snd (normalize_quot x) * snd (normalize_quot y))" |
|
242 |
proof - |
|
243 |
from normalize_quotE'[OF assms(1)] guess d . note d = this |
|
244 |
from normalize_quotE'[OF assms(2)] guess e . note e = this |
|
245 |
show ?thesis by (simp_all add: d e algebra_simps normalize_quot_eq_iff) |
|
246 |
qed |
|
247 |
||
248 |
lemma quot_of_fract_mult: |
|
249 |
"quot_of_fract (x * y) = |
|
250 |
(let (a,b) = quot_of_fract x; (c,d) = quot_of_fract y; |
|
251 |
(e,f) = normalize_quot (a,d); (g,h) = normalize_quot (c,b) |
|
252 |
in (e*g, f*h))" |
|
67051 | 253 |
by transfer |
254 |
(simp add: split_def Let_def coprime_normalize_quot normalize_quot_mult normalize_quot_mult_coprime) |
|
63500 | 255 |
|
256 |
lemma normalize_quot_0 [simp]: |
|
257 |
"normalize_quot (0, x) = (0, 1)" "normalize_quot (x, 0) = (0, 1)" |
|
258 |
by (simp_all add: normalize_quot_def) |
|
259 |
||
260 |
lemma normalize_quot_eq_0_iff [simp]: "fst (normalize_quot x) = 0 \<longleftrightarrow> fst x = 0 \<or> snd x = 0" |
|
261 |
by (auto simp: normalize_quot_def case_prod_unfold Let_def div_mult_unit2 dvd_div_eq_0_iff) |
|
262 |
||
263 |
lemma fst_quot_of_fract_0_imp: "fst (quot_of_fract x) = 0 \<Longrightarrow> snd (quot_of_fract x) = 1" |
|
264 |
by transfer auto |
|
265 |
||
266 |
lemma normalize_quot_swap: |
|
267 |
assumes "a \<noteq> 0" "b \<noteq> 0" |
|
268 |
defines "a' \<equiv> fst (normalize_quot (a, b))" and "b' \<equiv> snd (normalize_quot (a, b))" |
|
269 |
shows "normalize_quot (b, a) = (b' div unit_factor a', a' div unit_factor a')" |
|
270 |
proof (rule normalize_quotI) |
|
271 |
from normalize_quotE[OF assms(2), of a] guess d . note d = this [folded assms(3,4)] |
|
272 |
show "b * (a' div unit_factor a') = a * (b' div unit_factor a')" |
|
273 |
using assms(1,2) d |
|
274 |
by (simp add: div_unit_factor [symmetric] unit_div_mult_swap mult_ac del: div_unit_factor) |
|
275 |
have "coprime a' b'" by (simp add: a'_def b'_def coprime_normalize_quot) |
|
276 |
thus "(b' div unit_factor a', a' div unit_factor a') \<in> normalized_fracts" |
|
67051 | 277 |
using assms(1,2) d |
67078
6a85b8a9c28c
removed overambitious simp rules from e7e54a0b9197
haftmann
parents:
67051
diff
changeset
|
278 |
by (auto simp add: normalized_fracts_def ac_simps dvd_div_unit_iff elim: coprime_imp_coprime) |
63500 | 279 |
qed fact+ |
280 |
||
281 |
lemma quot_of_fract_inverse: |
|
282 |
"quot_of_fract (inverse x) = |
|
283 |
(let (a,b) = quot_of_fract x; d = unit_factor a |
|
284 |
in if d = 0 then (0, 1) else (b div d, a div d))" |
|
285 |
proof (transfer, goal_cases) |
|
286 |
case (1 x) |
|
287 |
from normalize_quot_swap[of "fst x" "snd x"] show ?case |
|
288 |
by (auto simp: Let_def case_prod_unfold) |
|
289 |
qed |
|
290 |
||
291 |
lemma normalize_quot_div_unit_left: |
|
292 |
fixes x y u |
|
293 |
assumes "is_unit u" |
|
294 |
defines "x' \<equiv> fst (normalize_quot (x, y))" and "y' \<equiv> snd (normalize_quot (x, y))" |
|
295 |
shows "normalize_quot (x div u, y) = (x' div u, y')" |
|
296 |
proof (cases "y = 0") |
|
297 |
case False |
|
67051 | 298 |
define v where "v = 1 div u" |
299 |
with \<open>is_unit u\<close> have "is_unit v" and u: "\<And>a. a div u = a * v" |
|
300 |
by simp_all |
|
301 |
from \<open>is_unit v\<close> have "coprime v = top" |
|
302 |
by (simp add: fun_eq_iff is_unit_left_imp_coprime) |
|
303 |
from normalize_quotE[OF False, of x] guess d . |
|
304 |
note d = this[folded assms(2,3)] |
|
305 |
from assms have "coprime x' y'" "unit_factor y' = 1" |
|
306 |
by (simp_all add: coprime_normalize_quot) |
|
307 |
with d \<open>coprime v = top\<close> have "normalize_quot (x * v, y) = (x' * v, y')" |
|
308 |
by (auto simp: normalized_fracts_def intro: normalize_quotI) |
|
309 |
then show ?thesis |
|
310 |
by (simp add: u) |
|
63500 | 311 |
qed (simp_all add: assms) |
312 |
||
313 |
lemma normalize_quot_div_unit_right: |
|
314 |
fixes x y u |
|
315 |
assumes "is_unit u" |
|
316 |
defines "x' \<equiv> fst (normalize_quot (x, y))" and "y' \<equiv> snd (normalize_quot (x, y))" |
|
317 |
shows "normalize_quot (x, y div u) = (x' * u, y')" |
|
318 |
proof (cases "y = 0") |
|
319 |
case False |
|
320 |
from normalize_quotE[OF this, of x] guess d . note d = this[folded assms(2,3)] |
|
321 |
from assms have "coprime x' y'" "unit_factor y' = 1" by (simp_all add: coprime_normalize_quot) |
|
67051 | 322 |
with d \<open>is_unit u\<close> show ?thesis |
323 |
by (auto simp add: normalized_fracts_def is_unit_left_imp_coprime unit_div_eq_0_iff intro: normalize_quotI) |
|
63500 | 324 |
qed (simp_all add: assms) |
325 |
||
326 |
lemma normalize_quot_normalize_left: |
|
327 |
fixes x y u |
|
328 |
defines "x' \<equiv> fst (normalize_quot (x, y))" and "y' \<equiv> snd (normalize_quot (x, y))" |
|
329 |
shows "normalize_quot (normalize x, y) = (x' div unit_factor x, y')" |
|
330 |
using normalize_quot_div_unit_left[of "unit_factor x" x y] |
|
331 |
by (cases "x = 0") (simp_all add: assms) |
|
332 |
||
333 |
lemma normalize_quot_normalize_right: |
|
334 |
fixes x y u |
|
335 |
defines "x' \<equiv> fst (normalize_quot (x, y))" and "y' \<equiv> snd (normalize_quot (x, y))" |
|
336 |
shows "normalize_quot (x, normalize y) = (x' * unit_factor y, y')" |
|
337 |
using normalize_quot_div_unit_right[of "unit_factor y" x y] |
|
338 |
by (cases "y = 0") (simp_all add: assms) |
|
339 |
||
340 |
lemma quot_of_fract_0 [simp]: "quot_of_fract 0 = (0, 1)" |
|
341 |
by transfer auto |
|
342 |
||
343 |
lemma quot_of_fract_1 [simp]: "quot_of_fract 1 = (1, 1)" |
|
344 |
by transfer (rule normalize_quotI, simp_all add: normalized_fracts_def) |
|
345 |
||
346 |
lemma quot_of_fract_divide: |
|
347 |
"quot_of_fract (x / y) = (if y = 0 then (0, 1) else |
|
348 |
(let (a,b) = quot_of_fract x; (c,d) = quot_of_fract y; |
|
349 |
(e,f) = normalize_quot (a,c); (g,h) = normalize_quot (d,b) |
|
350 |
in (e * g, f * h)))" (is "_ = ?rhs") |
|
351 |
proof (cases "y = 0") |
|
352 |
case False |
|
353 |
hence A: "fst (quot_of_fract y) \<noteq> 0" by transfer auto |
|
354 |
have "x / y = x * inverse y" by (simp add: divide_inverse) |
|
355 |
also from False A have "quot_of_fract \<dots> = ?rhs" |
|
356 |
by (simp only: quot_of_fract_mult quot_of_fract_inverse) |
|
357 |
(simp_all add: Let_def case_prod_unfold fst_quot_of_fract_0_imp |
|
358 |
normalize_quot_div_unit_left normalize_quot_div_unit_right |
|
359 |
normalize_quot_normalize_right normalize_quot_normalize_left) |
|
360 |
finally show ?thesis . |
|
361 |
qed simp_all |
|
362 |
||
363 |
end |