13 uses ("real_arith.ML") |
13 uses ("real_arith.ML") |
14 begin |
14 begin |
15 |
15 |
16 definition |
16 definition |
17 realrel :: "((preal * preal) * (preal * preal)) set" where |
17 realrel :: "((preal * preal) * (preal * preal)) set" where |
18 [code func del]: "realrel = {p. \<exists>x1 y1 x2 y2. p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1}" |
18 [code del]: "realrel = {p. \<exists>x1 y1 x2 y2. p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1}" |
19 |
19 |
20 typedef (Real) real = "UNIV//realrel" |
20 typedef (Real) real = "UNIV//realrel" |
21 by (auto simp add: quotient_def) |
21 by (auto simp add: quotient_def) |
22 |
22 |
23 definition |
23 definition |
24 (** these don't use the overloaded "real" function: users don't see them **) |
24 (** these don't use the overloaded "real" function: users don't see them **) |
25 real_of_preal :: "preal => real" where |
25 real_of_preal :: "preal => real" where |
26 [code func del]: "real_of_preal m = Abs_Real (realrel `` {(m + 1, 1)})" |
26 [code del]: "real_of_preal m = Abs_Real (realrel `` {(m + 1, 1)})" |
27 |
27 |
28 instantiation real :: "{zero, one, plus, minus, uminus, times, inverse, ord, abs, sgn}" |
28 instantiation real :: "{zero, one, plus, minus, uminus, times, inverse, ord, abs, sgn}" |
29 begin |
29 begin |
30 |
30 |
31 definition |
31 definition |
32 real_zero_def [code func del]: "0 = Abs_Real(realrel``{(1, 1)})" |
32 real_zero_def [code del]: "0 = Abs_Real(realrel``{(1, 1)})" |
33 |
33 |
34 definition |
34 definition |
35 real_one_def [code func del]: "1 = Abs_Real(realrel``{(1 + 1, 1)})" |
35 real_one_def [code del]: "1 = Abs_Real(realrel``{(1 + 1, 1)})" |
36 |
36 |
37 definition |
37 definition |
38 real_add_def [code func del]: "z + w = |
38 real_add_def [code del]: "z + w = |
39 contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w). |
39 contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w). |
40 { Abs_Real(realrel``{(x+u, y+v)}) })" |
40 { Abs_Real(realrel``{(x+u, y+v)}) })" |
41 |
41 |
42 definition |
42 definition |
43 real_minus_def [code func del]: "- r = contents (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })" |
43 real_minus_def [code del]: "- r = contents (\<Union>(x,y) \<in> Rep_Real(r). { Abs_Real(realrel``{(y,x)}) })" |
44 |
44 |
45 definition |
45 definition |
46 real_diff_def [code func del]: "r - (s::real) = r + - s" |
46 real_diff_def [code del]: "r - (s::real) = r + - s" |
47 |
47 |
48 definition |
48 definition |
49 real_mult_def [code func del]: |
49 real_mult_def [code del]: |
50 "z * w = |
50 "z * w = |
51 contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w). |
51 contents (\<Union>(x,y) \<in> Rep_Real(z). \<Union>(u,v) \<in> Rep_Real(w). |
52 { Abs_Real(realrel``{(x*u + y*v, x*v + y*u)}) })" |
52 { Abs_Real(realrel``{(x*u + y*v, x*v + y*u)}) })" |
53 |
53 |
54 definition |
54 definition |
55 real_inverse_def [code func del]: "inverse (R::real) = (THE S. (R = 0 & S = 0) | S * R = 1)" |
55 real_inverse_def [code del]: "inverse (R::real) = (THE S. (R = 0 & S = 0) | S * R = 1)" |
56 |
56 |
57 definition |
57 definition |
58 real_divide_def [code func del]: "R / (S::real) = R * inverse S" |
58 real_divide_def [code del]: "R / (S::real) = R * inverse S" |
59 |
59 |
60 definition |
60 definition |
61 real_le_def [code func del]: "z \<le> (w::real) \<longleftrightarrow> |
61 real_le_def [code del]: "z \<le> (w::real) \<longleftrightarrow> |
62 (\<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Real z & (u,v) \<in> Rep_Real w)" |
62 (\<exists>x y u v. x+v \<le> u+y & (x,y) \<in> Rep_Real z & (u,v) \<in> Rep_Real w)" |
63 |
63 |
64 definition |
64 definition |
65 real_less_def [code func del]: "x < (y\<Colon>real) \<longleftrightarrow> x \<le> y \<and> x \<noteq> y" |
65 real_less_def [code del]: "x < (y\<Colon>real) \<longleftrightarrow> x \<le> y \<and> x \<noteq> y" |
66 |
66 |
67 definition |
67 definition |
68 real_abs_def: "abs (r::real) = (if r < 0 then - r else r)" |
68 real_abs_def: "abs (r::real) = (if r < 0 then - r else r)" |
69 |
69 |
70 definition |
70 definition |