author | blanchet |
Fri, 27 Aug 2010 15:37:03 +0200 | |
changeset 38826 | f42f425edf24 |
parent 37765 | 26bdfb7b680b |
child 39910 | 10097e0a9dbd |
permissions | -rw-r--r-- |
35372 | 1 |
(* Title: HOL/Library/Fraction_Field.thy |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
2 |
Author: Amine Chaieb, University of Cambridge |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
3 |
*) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
4 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
5 |
header{* A formalization of the fraction field of any integral domain |
35372 | 6 |
A generalization of Rat.thy from int to any integral domain *} |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
7 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
8 |
theory Fraction_Field |
35372 | 9 |
imports Main |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
10 |
begin |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
11 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
12 |
subsection {* General fractions construction *} |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
13 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
14 |
subsubsection {* Construction of the type of fractions *} |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
15 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
16 |
definition fractrel :: "(('a::idom * 'a ) * ('a * 'a)) set" where |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
17 |
"fractrel == {(x, y). snd x \<noteq> 0 \<and> snd y \<noteq> 0 \<and> fst x * snd y = fst y * snd x}" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
18 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
19 |
lemma fractrel_iff [simp]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
20 |
"(x, y) \<in> fractrel \<longleftrightarrow> snd x \<noteq> 0 \<and> snd y \<noteq> 0 \<and> fst x * snd y = fst y * snd x" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
21 |
by (simp add: fractrel_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
22 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
23 |
lemma refl_fractrel: "refl_on {x. snd x \<noteq> 0} fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
24 |
by (auto simp add: refl_on_def fractrel_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
25 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
26 |
lemma sym_fractrel: "sym fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
27 |
by (simp add: fractrel_def sym_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
28 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
29 |
lemma trans_fractrel: "trans fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
30 |
proof (rule transI, unfold split_paired_all) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
31 |
fix a b a' b' a'' b'' :: 'a |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
32 |
assume A: "((a, b), (a', b')) \<in> fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
33 |
assume B: "((a', b'), (a'', b'')) \<in> fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
34 |
have "b' * (a * b'') = b'' * (a * b')" by (simp add: mult_ac) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
35 |
also from A have "a * b' = a' * b" by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
36 |
also have "b'' * (a' * b) = b * (a' * b'')" by (simp add: mult_ac) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
37 |
also from B have "a' * b'' = a'' * b'" by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
38 |
also have "b * (a'' * b') = b' * (a'' * b)" by (simp add: mult_ac) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
39 |
finally have "b' * (a * b'') = b' * (a'' * b)" . |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
40 |
moreover from B have "b' \<noteq> 0" by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
41 |
ultimately have "a * b'' = a'' * b" by simp |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
42 |
with A B show "((a, b), (a'', b'')) \<in> fractrel" by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
43 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
44 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
45 |
lemma equiv_fractrel: "equiv {x. snd x \<noteq> 0} fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
46 |
by (rule equiv.intro [OF refl_fractrel sym_fractrel trans_fractrel]) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
47 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
48 |
lemmas UN_fractrel = UN_equiv_class [OF equiv_fractrel] |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
49 |
lemmas UN_fractrel2 = UN_equiv_class2 [OF equiv_fractrel equiv_fractrel] |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
50 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
51 |
lemma equiv_fractrel_iff [iff]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
52 |
assumes "snd x \<noteq> 0" and "snd y \<noteq> 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
53 |
shows "fractrel `` {x} = fractrel `` {y} \<longleftrightarrow> (x, y) \<in> fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
54 |
by (rule eq_equiv_class_iff, rule equiv_fractrel) (auto simp add: assms) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
55 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
56 |
typedef 'a fract = "{(x::'a\<times>'a). snd x \<noteq> (0::'a::idom)} // fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
57 |
proof |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
58 |
have "(0::'a, 1::'a) \<in> {x. snd x \<noteq> 0}" by simp |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
59 |
then show "fractrel `` {(0::'a, 1)} \<in> {x. snd x \<noteq> 0} // fractrel" by (rule quotientI) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
60 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
61 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
62 |
lemma fractrel_in_fract [simp]: "snd x \<noteq> 0 \<Longrightarrow> fractrel `` {x} \<in> fract" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
63 |
by (simp add: fract_def quotientI) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
64 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
65 |
declare Abs_fract_inject [simp] Abs_fract_inverse [simp] |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
66 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
67 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
68 |
subsubsection {* Representation and basic operations *} |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
69 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
70 |
definition |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
71 |
Fract :: "'a::idom \<Rightarrow> 'a \<Rightarrow> 'a fract" where |
37765 | 72 |
"Fract a b = Abs_fract (fractrel `` {if b = 0 then (0, 1) else (a, b)})" |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
73 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
74 |
code_datatype Fract |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
75 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
76 |
lemma Fract_cases [case_names Fract, cases type: fract]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
77 |
assumes "\<And>a b. q = Fract a b \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> C" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
78 |
shows C |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
79 |
using assms by (cases q) (clarsimp simp add: Fract_def fract_def quotient_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
80 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
81 |
lemma Fract_induct [case_names Fract, induct type: fract]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
82 |
assumes "\<And>a b. b \<noteq> 0 \<Longrightarrow> P (Fract a b)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
83 |
shows "P q" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
84 |
using assms by (cases q) simp |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
85 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
86 |
lemma eq_fract: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
87 |
shows "\<And>a b c d. b \<noteq> 0 \<Longrightarrow> d \<noteq> 0 \<Longrightarrow> Fract a b = Fract c d \<longleftrightarrow> a * d = c * b" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
88 |
and "\<And>a. Fract a 0 = Fract 0 1" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
89 |
and "\<And>a c. Fract 0 a = Fract 0 c" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
90 |
by (simp_all add: Fract_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
91 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
92 |
instantiation fract :: (idom) "{comm_ring_1, power}" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
93 |
begin |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
94 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
95 |
definition |
37765 | 96 |
Zero_fract_def [code_unfold]: "0 = Fract 0 1" |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
97 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
98 |
definition |
37765 | 99 |
One_fract_def [code_unfold]: "1 = Fract 1 1" |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
100 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
101 |
definition |
37765 | 102 |
add_fract_def: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
103 |
"q + r = Abs_fract (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r. |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
104 |
fractrel `` {(fst x * snd y + fst y * snd x, snd x * snd y)})" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
105 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
106 |
lemma add_fract [simp]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
107 |
assumes "b \<noteq> (0::'a::idom)" and "d \<noteq> 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
108 |
shows "Fract a b + Fract c d = Fract (a * d + c * b) (b * d)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
109 |
proof - |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
110 |
have "(\<lambda>x y. fractrel``{(fst x * snd y + fst y * snd x, snd x * snd y :: 'a)}) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
111 |
respects2 fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
112 |
apply (rule equiv_fractrel [THEN congruent2_commuteI]) apply (auto simp add: algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
113 |
unfolding mult_assoc[symmetric] . |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
114 |
with assms show ?thesis by (simp add: Fract_def add_fract_def UN_fractrel2) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
115 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
116 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
117 |
definition |
37765 | 118 |
minus_fract_def: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
119 |
"- q = Abs_fract (\<Union>x \<in> Rep_fract q. fractrel `` {(- fst x, snd x)})" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
120 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
121 |
lemma minus_fract [simp, code]: "- Fract a b = Fract (- a) (b::'a::idom)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
122 |
proof - |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
123 |
have "(\<lambda>x. fractrel `` {(- fst x, snd x :: 'a)}) respects fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
124 |
by (simp add: congruent_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
125 |
then show ?thesis by (simp add: Fract_def minus_fract_def UN_fractrel) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
126 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
127 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
128 |
lemma minus_fract_cancel [simp]: "Fract (- a) (- b) = Fract a b" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
129 |
by (cases "b = 0") (simp_all add: eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
130 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
131 |
definition |
37765 | 132 |
diff_fract_def: "q - r = q + - (r::'a fract)" |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
133 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
134 |
lemma diff_fract [simp]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
135 |
assumes "b \<noteq> 0" and "d \<noteq> 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
136 |
shows "Fract a b - Fract c d = Fract (a * d - c * b) (b * d)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
137 |
using assms by (simp add: diff_fract_def diff_minus) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
138 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
139 |
definition |
37765 | 140 |
mult_fract_def: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
141 |
"q * r = Abs_fract (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r. |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
142 |
fractrel``{(fst x * fst y, snd x * snd y)})" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
143 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
144 |
lemma mult_fract [simp]: "Fract (a::'a::idom) b * Fract c d = Fract (a * c) (b * d)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
145 |
proof - |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
146 |
have "(\<lambda>x y. fractrel `` {(fst x * fst y, snd x * snd y :: 'a)}) respects2 fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
147 |
apply (rule equiv_fractrel [THEN congruent2_commuteI]) apply (auto simp add: algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
148 |
unfolding mult_assoc[symmetric] . |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
149 |
then show ?thesis by (simp add: Fract_def mult_fract_def UN_fractrel2) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
150 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
151 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
152 |
lemma mult_fract_cancel: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
153 |
assumes "c \<noteq> 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
154 |
shows "Fract (c * a) (c * b) = Fract a b" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
155 |
proof - |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
156 |
from assms have "Fract c c = Fract 1 1" by (simp add: Fract_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
157 |
then show ?thesis by (simp add: mult_fract [symmetric]) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
158 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
159 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
160 |
instance proof |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
161 |
fix q r s :: "'a fract" show "(q * r) * s = q * (r * s)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
162 |
by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
163 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
164 |
fix q r :: "'a fract" show "q * r = r * q" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
165 |
by (cases q, cases r) (simp add: eq_fract algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
166 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
167 |
fix q :: "'a fract" show "1 * q = q" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
168 |
by (cases q) (simp add: One_fract_def eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
169 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
170 |
fix q r s :: "'a fract" show "(q + r) + s = q + (r + s)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
171 |
by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
172 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
173 |
fix q r :: "'a fract" show "q + r = r + q" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
174 |
by (cases q, cases r) (simp add: eq_fract algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
175 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
176 |
fix q :: "'a fract" show "0 + q = q" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
177 |
by (cases q) (simp add: Zero_fract_def eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
178 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
179 |
fix q :: "'a fract" show "- q + q = 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
180 |
by (cases q) (simp add: Zero_fract_def eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
181 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
182 |
fix q r :: "'a fract" show "q - r = q + - r" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
183 |
by (cases q, cases r) (simp add: eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
184 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
185 |
fix q r s :: "'a fract" show "(q + r) * s = q * s + r * s" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
186 |
by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
187 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
188 |
show "(0::'a fract) \<noteq> 1" by (simp add: Zero_fract_def One_fract_def eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
189 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
190 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
191 |
end |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
192 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
193 |
lemma of_nat_fract: "of_nat k = Fract (of_nat k) 1" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
194 |
by (induct k) (simp_all add: Zero_fract_def One_fract_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
195 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
196 |
lemma Fract_of_nat_eq: "Fract (of_nat k) 1 = of_nat k" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
197 |
by (rule of_nat_fract [symmetric]) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
198 |
|
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31761
diff
changeset
|
199 |
lemma fract_collapse [code_post]: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
200 |
"Fract 0 k = 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
201 |
"Fract 1 1 = 1" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
202 |
"Fract k 0 = 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
203 |
by (cases "k = 0") |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
204 |
(simp_all add: Zero_fract_def One_fract_def eq_fract Fract_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
205 |
|
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31761
diff
changeset
|
206 |
lemma fract_expand [code_unfold]: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
207 |
"0 = Fract 0 1" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
208 |
"1 = Fract 1 1" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
209 |
by (simp_all add: fract_collapse) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
210 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
211 |
lemma Fract_cases_nonzero [case_names Fract 0]: |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
212 |
assumes Fract: "\<And>a b. q = Fract a b \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> C" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
213 |
assumes 0: "q = 0 \<Longrightarrow> C" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
214 |
shows C |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
215 |
proof (cases "q = 0") |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
216 |
case True then show C using 0 by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
217 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
218 |
case False |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
219 |
then obtain a b where "q = Fract a b" and "b \<noteq> 0" by (cases q) auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
220 |
moreover with False have "0 \<noteq> Fract a b" by simp |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
221 |
with `b \<noteq> 0` have "a \<noteq> 0" by (simp add: Zero_fract_def eq_fract) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
222 |
with Fract `q = Fract a b` `b \<noteq> 0` show C by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
223 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
224 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
225 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
226 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
227 |
subsubsection {* The field of rational numbers *} |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
228 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
229 |
context idom |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
230 |
begin |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
231 |
subclass ring_no_zero_divisors .. |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
232 |
thm mult_eq_0_iff |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
233 |
end |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
234 |
|
36409 | 235 |
instantiation fract :: (idom) field_inverse_zero |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
236 |
begin |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
237 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
238 |
definition |
37765 | 239 |
inverse_fract_def: |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
240 |
"inverse q = Abs_fract (\<Union>x \<in> Rep_fract q. |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
241 |
fractrel `` {if fst x = 0 then (0, 1) else (snd x, fst x)})" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
242 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
243 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
244 |
lemma inverse_fract [simp]: "inverse (Fract a b) = Fract (b::'a::idom) a" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
245 |
proof - |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
246 |
have stupid: "\<And>x. (0::'a) = x \<longleftrightarrow> x = 0" by auto |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
247 |
have "(\<lambda>x. fractrel `` {if fst x = 0 then (0, 1) else (snd x, fst x :: 'a)}) respects fractrel" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
248 |
by (auto simp add: congruent_def stupid algebra_simps) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
249 |
then show ?thesis by (simp add: Fract_def inverse_fract_def UN_fractrel) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
250 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
251 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
252 |
definition |
37765 | 253 |
divide_fract_def: "q / r = q * inverse (r:: 'a fract)" |
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
254 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
255 |
lemma divide_fract [simp]: "Fract a b / Fract c d = Fract (a * d) (b * c)" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
256 |
by (simp add: divide_fract_def) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
257 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
258 |
instance proof |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
259 |
fix q :: "'a fract" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
260 |
assume "q \<noteq> 0" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
261 |
then show "inverse q * q = 1" apply (cases q rule: Fract_cases_nonzero) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
262 |
by (simp_all add: mult_fract inverse_fract fract_expand eq_fract mult_commute) |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
263 |
next |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
264 |
fix q r :: "'a fract" |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
265 |
show "q / r = q * inverse r" by (simp add: divide_fract_def) |
36409 | 266 |
next |
267 |
show "inverse 0 = (0:: 'a fract)" by (simp add: fract_expand) |
|
268 |
(simp add: fract_collapse) |
|
31761
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
269 |
qed |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
270 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
271 |
end |
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
272 |
|
3585bebe49a8
Added Library/Fraction_Field.thy: The fraction field of any integral
chaieb
parents:
diff
changeset
|
273 |
|
36331
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
274 |
subsubsection {* The ordered field of fractions over an ordered idom *} |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
275 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
276 |
lemma le_congruent2: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
277 |
"(\<lambda>x y::'a \<times> 'a::linordered_idom. |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
278 |
{(fst x * snd y)*(snd x * snd y) \<le> (fst y * snd x)*(snd x * snd y)}) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
279 |
respects2 fractrel" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
280 |
proof (clarsimp simp add: congruent2_def) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
281 |
fix a b a' b' c d c' d' :: 'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
282 |
assume neq: "b \<noteq> 0" "b' \<noteq> 0" "d \<noteq> 0" "d' \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
283 |
assume eq1: "a * b' = a' * b" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
284 |
assume eq2: "c * d' = c' * d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
285 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
286 |
let ?le = "\<lambda>a b c d. ((a * d) * (b * d) \<le> (c * b) * (b * d))" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
287 |
{ |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
288 |
fix a b c d x :: 'a assume x: "x \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
289 |
have "?le a b c d = ?le (a * x) (b * x) c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
290 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
291 |
from x have "0 < x * x" by (auto simp add: zero_less_mult_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
292 |
hence "?le a b c d = |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
293 |
((a * d) * (b * d) * (x * x) \<le> (c * b) * (b * d) * (x * x))" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
294 |
by (simp add: mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
295 |
also have "... = ?le (a * x) (b * x) c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
296 |
by (simp add: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
297 |
finally show ?thesis . |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
298 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
299 |
} note le_factor = this |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
300 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
301 |
let ?D = "b * d" and ?D' = "b' * d'" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
302 |
from neq have D: "?D \<noteq> 0" by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
303 |
from neq have "?D' \<noteq> 0" by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
304 |
hence "?le a b c d = ?le (a * ?D') (b * ?D') c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
305 |
by (rule le_factor) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
306 |
also have "... = ((a * b') * ?D * ?D' * d * d' \<le> (c * d') * ?D * ?D' * b * b')" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
307 |
by (simp add: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
308 |
also have "... = ((a' * b) * ?D * ?D' * d * d' \<le> (c' * d) * ?D * ?D' * b * b')" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
309 |
by (simp only: eq1 eq2) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
310 |
also have "... = ?le (a' * ?D) (b' * ?D) c' d'" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
311 |
by (simp add: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
312 |
also from D have "... = ?le a' b' c' d'" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
313 |
by (rule le_factor [symmetric]) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
314 |
finally show "?le a b c d = ?le a' b' c' d'" . |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
315 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
316 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
317 |
instantiation fract :: (linordered_idom) linorder |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
318 |
begin |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
319 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
320 |
definition |
37765 | 321 |
le_fract_def: |
36331
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
322 |
"q \<le> r \<longleftrightarrow> contents (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r. |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
323 |
{(fst x * snd y)*(snd x * snd y) \<le> (fst y * snd x)*(snd x * snd y)})" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
324 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
325 |
definition |
37765 | 326 |
less_fract_def: "z < (w::'a fract) \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z" |
36331
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
327 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
328 |
lemma le_fract [simp]: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
329 |
assumes "b \<noteq> 0" and "d \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
330 |
shows "Fract a b \<le> Fract c d \<longleftrightarrow> (a * d) * (b * d) \<le> (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
331 |
by (simp add: Fract_def le_fract_def le_congruent2 UN_fractrel2 assms) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
332 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
333 |
lemma less_fract [simp]: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
334 |
assumes "b \<noteq> 0" and "d \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
335 |
shows "Fract a b < Fract c d \<longleftrightarrow> (a * d) * (b * d) < (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
336 |
by (simp add: less_fract_def less_le_not_le mult_ac assms) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
337 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
338 |
instance proof |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
339 |
fix q r s :: "'a fract" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
340 |
assume "q \<le> r" and "r \<le> s" thus "q \<le> s" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
341 |
proof (induct q, induct r, induct s) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
342 |
fix a b c d e f :: 'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
343 |
assume neq: "b \<noteq> 0" "d \<noteq> 0" "f \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
344 |
assume 1: "Fract a b \<le> Fract c d" and 2: "Fract c d \<le> Fract e f" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
345 |
show "Fract a b \<le> Fract e f" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
346 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
347 |
from neq obtain bb: "0 < b * b" and dd: "0 < d * d" and ff: "0 < f * f" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
348 |
by (auto simp add: zero_less_mult_iff linorder_neq_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
349 |
have "(a * d) * (b * d) * (f * f) \<le> (c * b) * (b * d) * (f * f)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
350 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
351 |
from neq 1 have "(a * d) * (b * d) \<le> (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
352 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
353 |
with ff show ?thesis by (simp add: mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
354 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
355 |
also have "... = (c * f) * (d * f) * (b * b)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
356 |
by (simp only: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
357 |
also have "... \<le> (e * d) * (d * f) * (b * b)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
358 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
359 |
from neq 2 have "(c * f) * (d * f) \<le> (e * d) * (d * f)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
360 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
361 |
with bb show ?thesis by (simp add: mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
362 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
363 |
finally have "(a * f) * (b * f) * (d * d) \<le> e * b * (b * f) * (d * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
364 |
by (simp only: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
365 |
with dd have "(a * f) * (b * f) \<le> (e * b) * (b * f)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
366 |
by (simp add: mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
367 |
with neq show ?thesis by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
368 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
369 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
370 |
next |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
371 |
fix q r :: "'a fract" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
372 |
assume "q \<le> r" and "r \<le> q" thus "q = r" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
373 |
proof (induct q, induct r) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
374 |
fix a b c d :: 'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
375 |
assume neq: "b \<noteq> 0" "d \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
376 |
assume 1: "Fract a b \<le> Fract c d" and 2: "Fract c d \<le> Fract a b" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
377 |
show "Fract a b = Fract c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
378 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
379 |
from neq 1 have "(a * d) * (b * d) \<le> (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
380 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
381 |
also have "... \<le> (a * d) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
382 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
383 |
from neq 2 have "(c * b) * (d * b) \<le> (a * d) * (d * b)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
384 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
385 |
thus ?thesis by (simp only: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
386 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
387 |
finally have "(a * d) * (b * d) = (c * b) * (b * d)" . |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
388 |
moreover from neq have "b * d \<noteq> 0" by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
389 |
ultimately have "a * d = c * b" by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
390 |
with neq show ?thesis by (simp add: eq_fract) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
391 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
392 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
393 |
next |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
394 |
fix q r :: "'a fract" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
395 |
show "q \<le> q" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
396 |
by (induct q) simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
397 |
show "(q < r) = (q \<le> r \<and> \<not> r \<le> q)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
398 |
by (simp only: less_fract_def) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
399 |
show "q \<le> r \<or> r \<le> q" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
400 |
by (induct q, induct r) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
401 |
(simp add: mult_commute, rule linorder_linear) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
402 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
403 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
404 |
end |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
405 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
406 |
instantiation fract :: (linordered_idom) "{distrib_lattice, abs_if, sgn_if}" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
407 |
begin |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
408 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
409 |
definition |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
410 |
abs_fract_def: "\<bar>q\<bar> = (if q < 0 then -q else (q::'a fract))" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
411 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
412 |
definition |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
413 |
sgn_fract_def: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
414 |
"sgn (q::'a fract) = (if q=0 then 0 else if 0<q then 1 else - 1)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
415 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
416 |
theorem abs_fract [simp]: "\<bar>Fract a b\<bar> = Fract \<bar>a\<bar> \<bar>b\<bar>" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
417 |
by (auto simp add: abs_fract_def Zero_fract_def le_less |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
418 |
eq_fract zero_less_mult_iff mult_less_0_iff split: abs_split) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
419 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
420 |
definition |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
421 |
inf_fract_def: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
422 |
"(inf \<Colon> 'a fract \<Rightarrow> 'a fract \<Rightarrow> 'a fract) = min" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
423 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
424 |
definition |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
425 |
sup_fract_def: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
426 |
"(sup \<Colon> 'a fract \<Rightarrow> 'a fract \<Rightarrow> 'a fract) = max" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
427 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
428 |
instance by intro_classes |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
429 |
(auto simp add: abs_fract_def sgn_fract_def |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
430 |
min_max.sup_inf_distrib1 inf_fract_def sup_fract_def) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
431 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
432 |
end |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
433 |
|
36414 | 434 |
instance fract :: (linordered_idom) linordered_field_inverse_zero |
36331
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
435 |
proof |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
436 |
fix q r s :: "'a fract" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
437 |
show "q \<le> r ==> s + q \<le> s + r" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
438 |
proof (induct q, induct r, induct s) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
439 |
fix a b c d e f :: 'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
440 |
assume neq: "b \<noteq> 0" "d \<noteq> 0" "f \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
441 |
assume le: "Fract a b \<le> Fract c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
442 |
show "Fract e f + Fract a b \<le> Fract e f + Fract c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
443 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
444 |
let ?F = "f * f" from neq have F: "0 < ?F" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
445 |
by (auto simp add: zero_less_mult_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
446 |
from neq le have "(a * d) * (b * d) \<le> (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
447 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
448 |
with F have "(a * d) * (b * d) * ?F * ?F \<le> (c * b) * (b * d) * ?F * ?F" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
449 |
by (simp add: mult_le_cancel_right) |
36348
89c54f51f55a
dropped group_simps, ring_simps, field_eq_simps; classes division_ring_inverse_zero, field_inverse_zero, linordered_field_inverse_zero
haftmann
parents:
36331
diff
changeset
|
450 |
with neq show ?thesis by (simp add: field_simps) |
36331
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
451 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
452 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
453 |
show "q < r ==> 0 < s ==> s * q < s * r" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
454 |
proof (induct q, induct r, induct s) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
455 |
fix a b c d e f :: 'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
456 |
assume neq: "b \<noteq> 0" "d \<noteq> 0" "f \<noteq> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
457 |
assume le: "Fract a b < Fract c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
458 |
assume gt: "0 < Fract e f" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
459 |
show "Fract e f * Fract a b < Fract e f * Fract c d" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
460 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
461 |
let ?E = "e * f" and ?F = "f * f" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
462 |
from neq gt have "0 < ?E" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
463 |
by (auto simp add: Zero_fract_def order_less_le eq_fract) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
464 |
moreover from neq have "0 < ?F" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
465 |
by (auto simp add: zero_less_mult_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
466 |
moreover from neq le have "(a * d) * (b * d) < (c * b) * (b * d)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
467 |
by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
468 |
ultimately have "(a * d) * (b * d) * ?E * ?F < (c * b) * (b * d) * ?E * ?F" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
469 |
by (simp add: mult_less_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
470 |
with neq show ?thesis |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
471 |
by (simp add: mult_ac) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
472 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
473 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
474 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
475 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
476 |
lemma fract_induct_pos [case_names Fract]: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
477 |
fixes P :: "'a::linordered_idom fract \<Rightarrow> bool" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
478 |
assumes step: "\<And>a b. 0 < b \<Longrightarrow> P (Fract a b)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
479 |
shows "P q" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
480 |
proof (cases q) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
481 |
have step': "\<And>a b. b < 0 \<Longrightarrow> P (Fract a b)" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
482 |
proof - |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
483 |
fix a::'a and b::'a |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
484 |
assume b: "b < 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
485 |
hence "0 < -b" by simp |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
486 |
hence "P (Fract (-a) (-b))" by (rule step) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
487 |
thus "P (Fract a b)" by (simp add: order_less_imp_not_eq [OF b]) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
488 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
489 |
case (Fract a b) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
490 |
thus "P q" by (force simp add: linorder_neq_iff step step') |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
491 |
qed |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
492 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
493 |
lemma zero_less_Fract_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
494 |
"0 < b \<Longrightarrow> 0 < Fract a b \<longleftrightarrow> 0 < a" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
495 |
by (auto simp add: Zero_fract_def zero_less_mult_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
496 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
497 |
lemma Fract_less_zero_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
498 |
"0 < b \<Longrightarrow> Fract a b < 0 \<longleftrightarrow> a < 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
499 |
by (auto simp add: Zero_fract_def mult_less_0_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
500 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
501 |
lemma zero_le_Fract_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
502 |
"0 < b \<Longrightarrow> 0 \<le> Fract a b \<longleftrightarrow> 0 \<le> a" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
503 |
by (auto simp add: Zero_fract_def zero_le_mult_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
504 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
505 |
lemma Fract_le_zero_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
506 |
"0 < b \<Longrightarrow> Fract a b \<le> 0 \<longleftrightarrow> a \<le> 0" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
507 |
by (auto simp add: Zero_fract_def mult_le_0_iff) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
508 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
509 |
lemma one_less_Fract_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
510 |
"0 < b \<Longrightarrow> 1 < Fract a b \<longleftrightarrow> b < a" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
511 |
by (auto simp add: One_fract_def mult_less_cancel_right_disj) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
512 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
513 |
lemma Fract_less_one_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
514 |
"0 < b \<Longrightarrow> Fract a b < 1 \<longleftrightarrow> a < b" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
515 |
by (auto simp add: One_fract_def mult_less_cancel_right_disj) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
516 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
517 |
lemma one_le_Fract_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
518 |
"0 < b \<Longrightarrow> 1 \<le> Fract a b \<longleftrightarrow> b \<le> a" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
519 |
by (auto simp add: One_fract_def mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
520 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
521 |
lemma Fract_le_one_iff: |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
522 |
"0 < b \<Longrightarrow> Fract a b \<le> 1 \<longleftrightarrow> a \<le> b" |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
523 |
by (auto simp add: One_fract_def mult_le_cancel_right) |
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
524 |
|
6b9e487450ba
Library/Fraction_Field.thy: ordering relations for fractions
huffman
parents:
36312
diff
changeset
|
525 |
end |