author | fleuriot |
Thu, 01 Jun 2000 11:22:27 +0200 | |
changeset 9013 | 9dd0274f76af |
parent 8838 | 4eaa99f0d223 |
child 9043 | ca761fe227d8 |
permissions | -rw-r--r-- |
7292 | 1 |
(* Title: HOL/RealBin.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
6 |
Binary arithmetic for the reals (integer literals only) |
|
7 |
*) |
|
8 |
||
9 |
(** real_of_int (coercion from int to real) **) |
|
10 |
||
11 |
Goal "real_of_int (number_of w) = number_of w"; |
|
12 |
by (simp_tac (simpset() addsimps [real_number_of_def]) 1); |
|
13 |
qed "real_number_of"; |
|
14 |
Addsimps [real_number_of]; |
|
15 |
||
16 |
Goalw [real_number_of_def] "0r = #0"; |
|
17 |
by (simp_tac (simpset() addsimps [real_of_int_zero RS sym]) 1); |
|
18 |
qed "zero_eq_numeral_0"; |
|
19 |
||
20 |
Goalw [real_number_of_def] "1r = #1"; |
|
21 |
by (simp_tac (simpset() addsimps [real_of_int_one RS sym]) 1); |
|
22 |
qed "one_eq_numeral_1"; |
|
23 |
||
24 |
(** Addition **) |
|
25 |
||
26 |
Goal "(number_of v :: real) + number_of v' = number_of (bin_add v v')"; |
|
27 |
by (simp_tac |
|
28 |
(simpset_of Int.thy addsimps [real_number_of_def, |
|
29 |
real_of_int_add, number_of_add]) 1); |
|
30 |
qed "add_real_number_of"; |
|
31 |
||
32 |
Addsimps [add_real_number_of]; |
|
33 |
||
34 |
||
35 |
(** Subtraction **) |
|
36 |
||
37 |
Goalw [real_number_of_def] "- (number_of w :: real) = number_of (bin_minus w)"; |
|
38 |
by (simp_tac |
|
39 |
(simpset_of Int.thy addsimps [number_of_minus, real_of_int_minus]) 1); |
|
40 |
qed "minus_real_number_of"; |
|
41 |
||
42 |
Goalw [real_number_of_def] |
|
43 |
"(number_of v :: real) - number_of w = number_of (bin_add v (bin_minus w))"; |
|
44 |
by (simp_tac |
|
45 |
(simpset_of Int.thy addsimps [diff_number_of_eq, real_of_int_diff]) 1); |
|
46 |
qed "diff_real_number_of"; |
|
47 |
||
48 |
Addsimps [minus_real_number_of, diff_real_number_of]; |
|
49 |
||
50 |
||
51 |
(** Multiplication **) |
|
52 |
||
53 |
Goal "(number_of v :: real) * number_of v' = number_of (bin_mult v v')"; |
|
54 |
by (simp_tac |
|
55 |
(simpset_of Int.thy addsimps [real_number_of_def, |
|
56 |
real_of_int_mult, number_of_mult]) 1); |
|
57 |
qed "mult_real_number_of"; |
|
58 |
||
59 |
Addsimps [mult_real_number_of]; |
|
60 |
||
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
61 |
Goal "(#2::real) = #1 + #1"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
62 |
by (Simp_tac 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
63 |
val lemma = result(); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
64 |
|
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
65 |
(*For specialist use: NOT as default simprules*) |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
66 |
Goal "#2 * z = (z+z::real)"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
67 |
by (simp_tac (simpset_of RealDef.thy |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
68 |
addsimps [lemma, real_add_mult_distrib, |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
69 |
one_eq_numeral_1 RS sym]) 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
70 |
qed "real_mult_2"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
71 |
|
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
72 |
Goal "z * #2 = (z+z::real)"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
73 |
by (stac real_mult_commute 1 THEN rtac real_mult_2 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
74 |
qed "real_mult_2_right"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
75 |
|
7292 | 76 |
|
77 |
(*** Comparisons ***) |
|
78 |
||
79 |
(** Equals (=) **) |
|
80 |
||
81 |
Goal "((number_of v :: real) = number_of v') = \ |
|
82 |
\ iszero (number_of (bin_add v (bin_minus v')))"; |
|
83 |
by (simp_tac |
|
84 |
(simpset_of Int.thy addsimps [real_number_of_def, |
|
85 |
real_of_int_eq_iff, eq_number_of_eq]) 1); |
|
86 |
qed "eq_real_number_of"; |
|
87 |
||
88 |
Addsimps [eq_real_number_of]; |
|
89 |
||
90 |
(** Less-than (<) **) |
|
91 |
||
92 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
93 |
Goal "((number_of v :: real) < number_of v') = \ |
|
94 |
\ neg (number_of (bin_add v (bin_minus v')))"; |
|
95 |
by (simp_tac |
|
96 |
(simpset_of Int.thy addsimps [real_number_of_def, real_of_int_less_iff, |
|
97 |
less_number_of_eq_neg]) 1); |
|
98 |
qed "less_real_number_of"; |
|
99 |
||
100 |
Addsimps [less_real_number_of]; |
|
101 |
||
102 |
||
103 |
(** Less-than-or-equals (<=) **) |
|
104 |
||
105 |
Goal "(number_of x <= (number_of y::real)) = \ |
|
106 |
\ (~ number_of y < (number_of x::real))"; |
|
107 |
by (rtac (linorder_not_less RS sym) 1); |
|
108 |
qed "le_real_number_of_eq_not_less"; |
|
109 |
||
110 |
Addsimps [le_real_number_of_eq_not_less]; |
|
111 |
||
112 |
(*** New versions of existing theorems involving 0r, 1r ***) |
|
113 |
||
114 |
Goal "- #1 = (#-1::real)"; |
|
115 |
by (Simp_tac 1); |
|
116 |
qed "minus_numeral_one"; |
|
117 |
||
118 |
||
119 |
(*Maps 0r to #0 and 1r to #1 and -1r to #-1*) |
|
120 |
val real_numeral_ss = |
|
121 |
HOL_ss addsimps [zero_eq_numeral_0, one_eq_numeral_1, |
|
122 |
minus_numeral_one]; |
|
123 |
||
124 |
fun rename_numerals thy th = simplify real_numeral_ss (change_theory thy th); |
|
125 |
||
126 |
||
127 |
(*Now insert some identities previously stated for 0r and 1r*) |
|
128 |
||
129 |
(** RealDef & Real **) |
|
130 |
||
131 |
Addsimps (map (rename_numerals thy) |
|
132 |
[real_minus_zero, real_minus_zero_iff, |
|
133 |
real_add_zero_left, real_add_zero_right, |
|
134 |
real_diff_0, real_diff_0_right, |
|
135 |
real_mult_0_right, real_mult_0, real_mult_1_right, real_mult_1, |
|
136 |
real_mult_minus_1_right, real_mult_minus_1, real_rinv_1, |
|
137 |
real_minus_zero_less_iff]); |
|
138 |
||
139 |
||
140 |
(*Perhaps add some theorems that aren't in the default simpset, as |
|
141 |
done in Integ/NatBin.ML*) |
|
142 |
||
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
143 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
144 |
(* Author: Tobias Nipkow, TU Muenchen |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
145 |
Copyright 1999 TU Muenchen |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
146 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
147 |
Instantiate linear arithmetic decision procedure for the reals. |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
148 |
FIXME: multiplication with constants (eg #2 * x) does not work yet. |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
149 |
Solution: there should be a simproc for combining coefficients. |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
150 |
*) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
151 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
152 |
let |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
153 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
154 |
(* reduce contradictory <= to False *) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
155 |
val simps = [order_less_irrefl,zero_eq_numeral_0,one_eq_numeral_1, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
156 |
add_real_number_of,minus_real_number_of,diff_real_number_of, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
157 |
mult_real_number_of,eq_real_number_of,less_real_number_of, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
158 |
le_real_number_of_eq_not_less]; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
159 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
160 |
val simprocs = [Real_Cancel.sum_conv, Real_Cancel.rel_conv]; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
161 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
162 |
val add_mono_thms = |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
163 |
map (fn s => prove_goal thy s |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
164 |
(fn prems => [cut_facts_tac prems 1, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
165 |
asm_simp_tac (simpset() addsimps |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
166 |
[real_add_le_mono,real_add_less_mono, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
167 |
real_add_less_le_mono,real_add_le_less_mono]) 1])) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
168 |
["(i <= j) & (k <= l) ==> i + k <= j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
169 |
"(i = j) & (k <= l) ==> i + k <= j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
170 |
"(i <= j) & (k = l) ==> i + k <= j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
171 |
"(i = j) & (k = l) ==> i + k = j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
172 |
"(i < j) & (k = l) ==> i + k < j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
173 |
"(i = j) & (k < l) ==> i + k < j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
174 |
"(i < j) & (k <= l) ==> i + k < j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
175 |
"(i <= j) & (k < l) ==> i + k < j + (l::real)", |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
176 |
"(i < j) & (k < l) ==> i + k < j + (l::real)"]; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
177 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
178 |
in |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
179 |
LA_Data_Ref.add_mono_thms := !LA_Data_Ref.add_mono_thms @ add_mono_thms; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
180 |
LA_Data_Ref.ss_ref := !LA_Data_Ref.ss_ref addsimps simps |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
181 |
addsimprocs simprocs; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
182 |
LA_Data_Ref.discrete := !LA_Data_Ref.discrete @ [("RealDef.real",false)] |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
183 |
end; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
184 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
185 |
let |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
186 |
val real_arith_simproc_pats = |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
187 |
map (fn s => Thm.read_cterm (Theory.sign_of thy) (s, HOLogic.boolT)) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
188 |
["(m::real) < n","(m::real) <= n", "(m::real) = n"]; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
189 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
190 |
val fast_real_arith_simproc = mk_simproc |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
191 |
"fast_real_arith" real_arith_simproc_pats Fast_Arith.lin_arith_prover; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
192 |
in |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
193 |
Addsimprocs [fast_real_arith_simproc] |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
194 |
end; |
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
195 |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
196 |
|
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
197 |
Addsimps [zero_eq_numeral_0,one_eq_numeral_1]; |
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
198 |
|
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
199 |
(* added by jdf *) |
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
200 |
fun full_rename_numerals thy th = |
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
201 |
asm_full_simplify real_numeral_ss (change_theory thy th); |
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
202 |
|
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
203 |