| author | wenzelm |
| Fri, 17 Aug 2007 00:03:50 +0200 | |
| changeset 24300 | e170cee91c66 |
| parent 24197 | c9e3cb5e5681 |
| permissions | -rw-r--r-- |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
1 |
(* Title: HOL/Library/Executable_Real.thy |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
2 |
ID: $Id$ |
| 24197 | 3 |
Author: Florian Haftmann, TU Muenchen |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
4 |
*) |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
5 |
|
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
6 |
header {* Implementation of rational real numbers as pairs of integers *}
|
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
7 |
|
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
8 |
theory Executable_Real |
| 24197 | 9 |
imports Abstract_Rat "~~/src/HOL/Real/Real" |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
10 |
begin |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
11 |
|
| 24197 | 12 |
hide (open) const Real |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
13 |
|
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
14 |
definition |
| 24197 | 15 |
Real :: "int \<times> int \<Rightarrow> real" |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
16 |
where |
| 24197 | 17 |
"Real = INum" |
18 |
||
19 |
code_datatype Real |
|
20 |
||
21 |
lemma Real_simp: |
|
22 |
"Real (k, l) = real_of_int k / real_of_int l" |
|
23 |
unfolding Real_def INum_def by simp |
|
24 |
||
25 |
lemma Real_zero [simp]: "Real 0\<^sub>N = 0" |
|
26 |
by (simp add: Real_simp) |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
27 |
|
| 24197 | 28 |
lemma Real_lit [simp]: "Real i\<^sub>N = real_of_int i" |
29 |
by (simp add: Real_simp) |
|
30 |
||
31 |
lemma zero_real_code [code]: |
|
32 |
"0 = Real 0\<^sub>N" by simp |
|
33 |
||
34 |
lemma zero_real_code [code]: |
|
35 |
"1 = Real 1\<^sub>N" by simp |
|
36 |
||
37 |
lemma [code, code unfold]: |
|
38 |
"number_of k = real_of_int (number_of k)" |
|
39 |
by (simp add: number_of_is_id real_number_of_def) |
|
40 |
||
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
41 |
instance real :: eq .. |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
42 |
|
| 24197 | 43 |
lemma real_eq_code [code]: "Real x = Real y \<longleftrightarrow> normNum x = normNum y" |
44 |
unfolding Real_def INum_normNum_iff .. |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
45 |
|
| 24197 | 46 |
lemma real_less_eq_code [code]: "Real x \<le> Real y \<longleftrightarrow> normNum x \<le>\<^sub>N normNum y" |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
47 |
proof - |
| 24197 | 48 |
have "normNum x \<le>\<^sub>N normNum y \<longleftrightarrow> Real (normNum x) \<le> Real (normNum y)" |
49 |
by (simp add: Real_def del: normNum) |
|
50 |
also have "\<dots> = (Real x \<le> Real y)" by (simp add: Real_def) |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
51 |
finally show ?thesis by simp |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
52 |
qed |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
53 |
|
| 24197 | 54 |
lemma real_less_code [code]: "Real x < Real y \<longleftrightarrow> normNum x <\<^sub>N normNum y" |
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
55 |
proof - |
| 24197 | 56 |
have "normNum x <\<^sub>N normNum y \<longleftrightarrow> Real (normNum x) < Real (normNum y)" |
57 |
by (simp add: Real_def del: normNum) |
|
58 |
also have "\<dots> = (Real x < Real y)" by (simp add: Real_def) |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
59 |
finally show ?thesis by simp |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
60 |
qed |
|
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
61 |
|
| 24197 | 62 |
lemma real_add_code [code]: "Real x + Real y = Real (x +\<^sub>N y)" |
63 |
unfolding Real_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
64 |
|
| 24197 | 65 |
lemma real_mul_code [code]: "Real x * Real y = Real (x *\<^sub>N y)" |
66 |
unfolding Real_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
67 |
|
| 24197 | 68 |
lemma real_neg_code [code]: "- Real x = Real (~\<^sub>N x)" |
69 |
unfolding Real_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
70 |
|
| 24197 | 71 |
lemma real_sub_code [code]: "Real x - Real y = Real (x -\<^sub>N y)" |
72 |
unfolding Real_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
73 |
|
| 24197 | 74 |
lemma real_inv_code [code]: "inverse (Real x) = Real (Ninv x)" |
75 |
unfolding Real_def Ninv real_divide_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
76 |
|
| 24197 | 77 |
lemma real_div_code [code]: "Real x / Real y = Real (x \<div>\<^sub>N y)" |
78 |
unfolding Real_def by simp |
|
|
22981
cf071f3fc4ae
A verified theory for rational numbers representation and simple calculations;
chaieb
parents:
diff
changeset
|
79 |
|
| 23017 | 80 |
code_modulename SML |
81 |
RealDef Real |
|
82 |
Executable_Real Real |
|
83 |
||
84 |
code_modulename OCaml |
|
85 |
RealDef Real |
|
86 |
Executable_Real Real |
|
87 |
||
88 |
code_modulename Haskell |
|
89 |
RealDef Real |
|
90 |
Executable_Real Real |
|
91 |
||
|
23030
c7ff1537c4bf
Disabled Stefancs code generator - already enabled in RealDef.
nipkow
parents:
23017
diff
changeset
|
92 |
end |