author | wenzelm |
Mon, 08 May 2000 20:57:02 +0200 | |
changeset 8838 | 4eaa99f0d223 |
parent 8552 | 8c4ff19a7286 |
child 9013 | 9dd0274f76af |
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 |
||
8838 | 113 |
(** abs (absolute value) **) |
7292 | 114 |
|
8838 | 115 |
Goalw [abs_real_def] |
116 |
"abs (number_of v :: real) = \ |
|
7292 | 117 |
\ (if neg (number_of v) then number_of (bin_minus v) \ |
118 |
\ else number_of v)"; |
|
119 |
by (simp_tac |
|
120 |
(simpset_of Int.thy addsimps |
|
121 |
bin_arith_simps@ |
|
122 |
[minus_real_number_of, zero_eq_numeral_0, le_real_number_of_eq_not_less, |
|
123 |
less_real_number_of, real_of_int_le_iff]) 1); |
|
8838 | 124 |
qed "abs_nat_number_of"; |
7292 | 125 |
|
8838 | 126 |
Addsimps [abs_nat_number_of]; |
7292 | 127 |
|
128 |
||
129 |
(*** New versions of existing theorems involving 0r, 1r ***) |
|
130 |
||
131 |
Goal "- #1 = (#-1::real)"; |
|
132 |
by (Simp_tac 1); |
|
133 |
qed "minus_numeral_one"; |
|
134 |
||
135 |
||
136 |
(*Maps 0r to #0 and 1r to #1 and -1r to #-1*) |
|
137 |
val real_numeral_ss = |
|
138 |
HOL_ss addsimps [zero_eq_numeral_0, one_eq_numeral_1, |
|
139 |
minus_numeral_one]; |
|
140 |
||
141 |
fun rename_numerals thy th = simplify real_numeral_ss (change_theory thy th); |
|
142 |
||
143 |
||
144 |
(*Now insert some identities previously stated for 0r and 1r*) |
|
145 |
||
146 |
(** RealDef & Real **) |
|
147 |
||
148 |
Addsimps (map (rename_numerals thy) |
|
149 |
[real_minus_zero, real_minus_zero_iff, |
|
150 |
real_add_zero_left, real_add_zero_right, |
|
151 |
real_diff_0, real_diff_0_right, |
|
152 |
real_mult_0_right, real_mult_0, real_mult_1_right, real_mult_1, |
|
153 |
real_mult_minus_1_right, real_mult_minus_1, real_rinv_1, |
|
154 |
real_minus_zero_less_iff]); |
|
155 |
||
156 |
||
157 |
(*Perhaps add some theorems that aren't in the default simpset, as |
|
158 |
done in Integ/NatBin.ML*) |
|
159 |
||
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
160 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
161 |
(* Author: Tobias Nipkow, TU Muenchen |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
162 |
Copyright 1999 TU Muenchen |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
163 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
164 |
Instantiate linear arithmetic decision procedure for the reals. |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
165 |
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
|
166 |
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
|
167 |
*) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
168 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
169 |
let |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
170 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
171 |
(* reduce contradictory <= to False *) |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
le_real_number_of_eq_not_less]; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
176 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
177 |
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
|
178 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
179 |
val add_mono_thms = |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
180 |
map (fn s => prove_goal thy s |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
181 |
(fn prems => [cut_facts_tac prems 1, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
182 |
asm_simp_tac (simpset() addsimps |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
183 |
[real_add_le_mono,real_add_less_mono, |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
184 |
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
|
185 |
["(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
|
186 |
"(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
|
187 |
"(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
|
188 |
"(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
|
189 |
"(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
|
190 |
"(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
|
191 |
"(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
|
192 |
"(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
|
193 |
"(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
|
194 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
195 |
in |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
addsimprocs simprocs; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
199 |
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
|
200 |
end; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
201 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
202 |
let |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
203 |
val real_arith_simproc_pats = |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
204 |
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
|
205 |
["(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
|
206 |
|
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
207 |
val fast_real_arith_simproc = mk_simproc |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
208 |
"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
|
209 |
in |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
210 |
Addsimprocs [fast_real_arith_simproc] |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
211 |
end; |
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
212 |
|
8838 | 213 |
Goalw [abs_real_def] |
214 |
"P(abs (x::real)) = ((#0 <= x --> P x) & (x < #0 --> P(-x)))"; |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
215 |
by(auto_tac (claset(), simpset() addsimps [zero_eq_numeral_0])); |
8838 | 216 |
qed "abs_split"; |
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
217 |
|
8838 | 218 |
arith_tac_split_thms := !arith_tac_split_thms @ [abs_split]; |
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
219 |