author | paulson |
Thu, 25 Dec 2003 22:48:32 +0100 | |
changeset 14329 | ff3210fe968f |
parent 14290 | 84fda1b39947 |
child 14334 | 6137d24eef79 |
permissions | -rw-r--r-- |
9433 | 1 |
(* Title: HOL/Real/RealBin.ML |
7292 | 2 |
ID: $Id$ |
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
9433 | 6 |
Binary arithmetic for the reals (integer literals only). |
7292 | 7 |
*) |
8 |
||
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
9 |
(** real (coercion from int to real) **) |
7292 | 10 |
|
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
11 |
Goal "real (number_of w :: int) = number_of w"; |
7292 | 12 |
by (simp_tac (simpset() addsimps [real_number_of_def]) 1); |
13 |
qed "real_number_of"; |
|
14 |
Addsimps [real_number_of]; |
|
15 |
||
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
16 |
Goalw [real_number_of_def] "Numeral0 = (0::real)"; |
7292 | 17 |
by (simp_tac (simpset() addsimps [real_of_int_zero RS sym]) 1); |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
18 |
qed "real_numeral_0_eq_0"; |
7292 | 19 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
20 |
Goalw [real_number_of_def] "Numeral1 = (1::real)"; |
13462 | 21 |
by (stac (real_of_one RS sym) 1); |
22 |
by (Simp_tac 1); |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
23 |
qed "real_numeral_1_eq_1"; |
7292 | 24 |
|
25 |
(** Addition **) |
|
26 |
||
27 |
Goal "(number_of v :: real) + number_of v' = number_of (bin_add v v')"; |
|
28 |
by (simp_tac |
|
13462 | 29 |
(HOL_ss addsimps [real_number_of_def, |
30 |
real_of_int_add, number_of_add]) 1); |
|
7292 | 31 |
qed "add_real_number_of"; |
32 |
||
33 |
Addsimps [add_real_number_of]; |
|
34 |
||
35 |
||
36 |
(** Subtraction **) |
|
37 |
||
38 |
Goalw [real_number_of_def] "- (number_of w :: real) = number_of (bin_minus w)"; |
|
39 |
by (simp_tac |
|
9433 | 40 |
(HOL_ss addsimps [number_of_minus, real_of_int_minus]) 1); |
7292 | 41 |
qed "minus_real_number_of"; |
42 |
||
43 |
Goalw [real_number_of_def] |
|
44 |
"(number_of v :: real) - number_of w = number_of (bin_add v (bin_minus w))"; |
|
45 |
by (simp_tac |
|
9433 | 46 |
(HOL_ss addsimps [diff_number_of_eq, real_of_int_diff]) 1); |
7292 | 47 |
qed "diff_real_number_of"; |
48 |
||
49 |
Addsimps [minus_real_number_of, diff_real_number_of]; |
|
50 |
||
51 |
||
52 |
(** Multiplication **) |
|
53 |
||
54 |
Goal "(number_of v :: real) * number_of v' = number_of (bin_mult v v')"; |
|
55 |
by (simp_tac |
|
13462 | 56 |
(HOL_ss addsimps [real_number_of_def, real_of_int_mult, |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
57 |
number_of_mult]) 1); |
7292 | 58 |
qed "mult_real_number_of"; |
59 |
||
60 |
Addsimps [mult_real_number_of]; |
|
61 |
||
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
62 |
Goal "(2::real) = 1 + 1"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
63 |
by (simp_tac (simpset() addsimps [real_numeral_1_eq_1 RS sym]) 1); |
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
64 |
val lemma = result(); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
65 |
|
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
66 |
(*For specialist use: NOT as default simprules*) |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
67 |
Goal "2 * z = (z+z::real)"; |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
68 |
by (simp_tac (simpset () addsimps [lemma, real_add_mult_distrib]) 1); |
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
69 |
qed "real_mult_2"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
70 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
71 |
Goal "z * 2 = (z+z::real)"; |
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
72 |
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
|
73 |
qed "real_mult_2_right"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
74 |
|
7292 | 75 |
|
76 |
(*** Comparisons ***) |
|
77 |
||
78 |
(** Equals (=) **) |
|
79 |
||
80 |
Goal "((number_of v :: real) = number_of v') = \ |
|
81 |
\ iszero (number_of (bin_add v (bin_minus v')))"; |
|
82 |
by (simp_tac |
|
13462 | 83 |
(HOL_ss addsimps [real_number_of_def, |
84 |
real_of_int_inject, eq_number_of_eq]) 1); |
|
7292 | 85 |
qed "eq_real_number_of"; |
86 |
||
87 |
Addsimps [eq_real_number_of]; |
|
88 |
||
89 |
(** Less-than (<) **) |
|
90 |
||
91 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
92 |
Goal "((number_of v :: real) < number_of v') = \ |
|
93 |
\ neg (number_of (bin_add v (bin_minus v')))"; |
|
94 |
by (simp_tac |
|
13462 | 95 |
(HOL_ss addsimps [real_number_of_def, real_of_int_less_iff, |
96 |
less_number_of_eq_neg]) 1); |
|
7292 | 97 |
qed "less_real_number_of"; |
98 |
||
99 |
Addsimps [less_real_number_of]; |
|
100 |
||
101 |
||
102 |
(** Less-than-or-equals (<=) **) |
|
103 |
||
104 |
Goal "(number_of x <= (number_of y::real)) = \ |
|
105 |
\ (~ number_of y < (number_of x::real))"; |
|
106 |
by (rtac (linorder_not_less RS sym) 1); |
|
13462 | 107 |
qed "le_real_number_of_eq_not_less"; |
7292 | 108 |
|
109 |
Addsimps [le_real_number_of_eq_not_less]; |
|
110 |
||
11713
883d559b0b8c
sane numerals (stage 3): provide generic "1" on all number types;
wenzelm
parents:
11704
diff
changeset
|
111 |
(*** New versions of existing theorems involving 0, 1 ***) |
7292 | 112 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
113 |
Goal "- 1 = (-1::real)"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
114 |
by (simp_tac (simpset() addsimps [real_numeral_1_eq_1 RS sym]) 1); |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
115 |
qed "real_minus_1_eq_m1"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
116 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
117 |
Goal "-1 * z = -(z::real)"; |
13462 | 118 |
by (simp_tac (simpset() addsimps [real_minus_1_eq_m1 RS sym, |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
119 |
real_mult_minus_1]) 1); |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
120 |
qed "real_mult_minus1"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
121 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
122 |
Goal "z * -1 = -(z::real)"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
123 |
by (stac real_mult_commute 1 THEN rtac real_mult_minus1 1); |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
124 |
qed "real_mult_minus1_right"; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
125 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
126 |
Addsimps [real_mult_minus1, real_mult_minus1_right]; |
7292 | 127 |
|
128 |
||
11713
883d559b0b8c
sane numerals (stage 3): provide generic "1" on all number types;
wenzelm
parents:
11704
diff
changeset
|
129 |
(*Maps 0 to Numeral0 and 1 to Numeral1 and -(Numeral1) to -1*) |
13462 | 130 |
val real_numeral_ss = |
131 |
HOL_ss addsimps [real_numeral_0_eq_0 RS sym, real_numeral_1_eq_1 RS sym, |
|
132 |
real_minus_1_eq_m1]; |
|
7292 | 133 |
|
13462 | 134 |
fun rename_numerals th = |
9433 | 135 |
asm_full_simplify real_numeral_ss (Thm.transfer (the_context ()) th); |
7292 | 136 |
|
137 |
||
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
138 |
(** real from type "nat" **) |
7292 | 139 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
140 |
Goal "(0 < real (n::nat)) = (0<n)"; |
13462 | 141 |
by (simp_tac (HOL_ss addsimps [real_of_nat_less_iff, |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
142 |
real_of_nat_zero RS sym]) 1); |
10784 | 143 |
qed "zero_less_real_of_nat_iff"; |
144 |
AddIffs [zero_less_real_of_nat_iff]; |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
145 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
146 |
Goal "(0 <= real (n::nat)) = (0<=n)"; |
13462 | 147 |
by (simp_tac (HOL_ss addsimps [real_of_nat_le_iff, |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
148 |
real_of_nat_zero RS sym]) 1); |
10784 | 149 |
qed "zero_le_real_of_nat_iff"; |
150 |
AddIffs [zero_le_real_of_nat_iff]; |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
151 |
|
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
152 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
153 |
(*Like the ones above, for "equals"*) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
154 |
AddIffs [real_of_nat_zero_iff]; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
155 |
|
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
156 |
(** Simplification of arithmetic when nested to the right **) |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
157 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
158 |
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::real)"; |
14290 | 159 |
by (asm_full_simp_tac (simpset() addsimps [add_assoc RS sym]) 1); |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
160 |
qed "real_add_number_of_left"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
161 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
162 |
Goal "number_of v * (number_of w * z) = (number_of(bin_mult v w) * z::real)"; |
14290 | 163 |
by (simp_tac (simpset() addsimps [mult_assoc RS sym]) 1); |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
164 |
qed "real_mult_number_of_left"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
165 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
166 |
Goalw [real_diff_def] |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
167 |
"number_of v + (number_of w - c) = number_of(bin_add v w) - (c::real)"; |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
168 |
by (rtac real_add_number_of_left 1); |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
169 |
qed "real_add_number_of_diff1"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
170 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
171 |
Goal "number_of v + (c - number_of w) = \ |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
172 |
\ number_of (bin_add v (bin_minus w)) + (c::real)"; |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
173 |
by (stac (diff_real_number_of RS sym) 1); |
14290 | 174 |
by (asm_full_simp_tac (HOL_ss addsimps [real_diff_def]@add_ac) 1); |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
175 |
qed "real_add_number_of_diff2"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
176 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
177 |
Addsimps [real_add_number_of_left, real_mult_number_of_left, |
13462 | 178 |
real_add_number_of_diff1, real_add_number_of_diff2]; |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
179 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
180 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
181 |
(*"neg" is used in rewrite rules for binary comparisons*) |
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
182 |
Goal "real (number_of v :: nat) = \ |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
183 |
\ (if neg (number_of v) then 0 \ |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
184 |
\ else (number_of v :: real))"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
185 |
by (simp_tac |
9433 | 186 |
(HOL_ss addsimps [nat_number_of_def, real_of_nat_real_of_int, |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
187 |
real_of_nat_neg_int, real_number_of, |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
188 |
real_numeral_0_eq_0 RS sym]) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
189 |
qed "real_of_nat_number_of"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
190 |
Addsimps [real_of_nat_number_of]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
191 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
192 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
193 |
(**** Simprocs for numeric literals ****) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
194 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
195 |
(** For combine_numerals **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
196 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
197 |
Goal "i*u + (j*u + k) = (i+j)*u + (k::real)"; |
14290 | 198 |
by (asm_simp_tac (simpset() addsimps [real_add_mult_distrib] @ add_ac) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
199 |
qed "left_real_add_mult_distrib"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
200 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
201 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
202 |
(** For cancel_numerals **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
203 |
|
14329 | 204 |
val rel_iff_rel_0_rls = map (inst "b" "?u+?v") |
205 |
[less_iff_diff_less_0, eq_iff_diff_eq_0, le_iff_diff_le_0] @ |
|
206 |
map (inst "b" "n") |
|
207 |
[less_iff_diff_less_0, eq_iff_diff_eq_0, le_iff_diff_le_0]; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
208 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
209 |
Goal "!!i::real. (i*u + m = j*u + n) = ((i-j)*u + m = n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
210 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
13462 | 211 |
real_add_ac@rel_iff_rel_0_rls) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
212 |
qed "real_eq_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
213 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
214 |
Goal "!!i::real. (i*u + m = j*u + n) = (m = (j-i)*u + n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
215 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
216 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
217 |
qed "real_eq_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
218 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
219 |
Goal "!!i::real. (i*u + m < j*u + n) = ((i-j)*u + m < n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
220 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
221 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
222 |
qed "real_less_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
223 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
224 |
Goal "!!i::real. (i*u + m < j*u + n) = (m < (j-i)*u + n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
225 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
226 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
227 |
qed "real_less_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
228 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
229 |
Goal "!!i::real. (i*u + m <= j*u + n) = ((i-j)*u + m <= n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
230 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
231 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
232 |
qed "real_le_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
233 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
234 |
Goal "!!i::real. (i*u + m <= j*u + n) = (m <= (j-i)*u + n)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
235 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib] |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
236 |
@real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
237 |
qed "real_le_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
238 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
239 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
240 |
Addsimps [real_numeral_0_eq_0, real_numeral_1_eq_1]; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
241 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
242 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
243 |
structure Real_Numeral_Simprocs = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
244 |
struct |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
245 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
246 |
(*Maps 0 to Numeral0 and 1 to Numeral1 so that arithmetic in simprocs |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
247 |
isn't complicated by the abstract 0 and 1.*) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
248 |
val numeral_syms = [real_numeral_0_eq_0 RS sym, real_numeral_1_eq_1 RS sym]; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
249 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
250 |
(*Utilities*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
251 |
|
10693 | 252 |
fun mk_numeral n = HOLogic.number_of_const HOLogic.realT $ HOLogic.mk_bin n; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
253 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
254 |
(*Decodes a binary real constant, or 0, 1*) |
12819 | 255 |
val dest_numeral = Int_Numeral_Simprocs.dest_numeral; |
256 |
val find_first_numeral = Int_Numeral_Simprocs.find_first_numeral; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
257 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
258 |
val zero = mk_numeral 0; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
259 |
val mk_plus = HOLogic.mk_binop "op +"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
260 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
261 |
val uminus_const = Const ("uminus", HOLogic.realT --> HOLogic.realT); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
262 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
263 |
(*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*) |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
264 |
fun mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
265 |
| mk_sum [t,u] = mk_plus (t, u) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
266 |
| mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
267 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
268 |
(*this version ALWAYS includes a trailing zero*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
269 |
fun long_mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
270 |
| long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
271 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
272 |
val dest_plus = HOLogic.dest_bin "op +" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
273 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
274 |
(*decompose additions AND subtractions as a sum*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
275 |
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
276 |
dest_summing (pos, t, dest_summing (pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
277 |
| dest_summing (pos, Const ("op -", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
278 |
dest_summing (pos, t, dest_summing (not pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
279 |
| dest_summing (pos, t, ts) = |
13462 | 280 |
if pos then t::ts else uminus_const$t :: ts; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
281 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
282 |
fun dest_sum t = dest_summing (true, t, []); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
283 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
284 |
val mk_diff = HOLogic.mk_binop "op -"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
285 |
val dest_diff = HOLogic.dest_bin "op -" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
286 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
287 |
val one = mk_numeral 1; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
288 |
val mk_times = HOLogic.mk_binop "op *"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
289 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
290 |
fun mk_prod [] = one |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
291 |
| mk_prod [t] = t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
292 |
| mk_prod (t :: ts) = if t = one then mk_prod ts |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
293 |
else mk_times (t, mk_prod ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
294 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
295 |
val dest_times = HOLogic.dest_bin "op *" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
296 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
297 |
fun dest_prod t = |
13462 | 298 |
let val (t,u) = dest_times t |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
299 |
in dest_prod t @ dest_prod u end |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
300 |
handle TERM _ => [t]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
301 |
|
13462 | 302 |
(*DON'T do the obvious simplifications; that would create special cases*) |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
303 |
fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
304 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
305 |
(*Express t as a product of (possibly) a numeral with other sorted terms*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
306 |
fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
307 |
| dest_coeff sign t = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
308 |
let val ts = sort Term.term_ord (dest_prod t) |
13462 | 309 |
val (n, ts') = find_first_numeral [] ts |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
310 |
handle TERM _ => (1, ts) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
311 |
in (sign*n, mk_prod ts') end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
312 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
313 |
(*Find first coefficient-term THAT MATCHES u*) |
13462 | 314 |
fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
315 |
| find_first_coeff past u (t::terms) = |
13462 | 316 |
let val (n,u') = dest_coeff 1 t |
317 |
in if u aconv u' then (n, rev past @ terms) |
|
318 |
else find_first_coeff (t::past) u terms |
|
319 |
end |
|
320 |
handle TERM _ => find_first_coeff (t::past) u terms; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
321 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
322 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
323 |
(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1*) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
324 |
val add_0s = map rename_numerals [real_add_zero_left, real_add_zero_right]; |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
325 |
val mult_1s = map rename_numerals [real_mult_1, real_mult_1_right] @ |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
326 |
[real_mult_minus1, real_mult_minus1_right]; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
327 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
328 |
(*To perform binary arithmetic*) |
9108 | 329 |
val bin_simps = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
330 |
[real_numeral_0_eq_0 RS sym, real_numeral_1_eq_1 RS sym, |
13462 | 331 |
add_real_number_of, real_add_number_of_left, minus_real_number_of, |
332 |
diff_real_number_of, mult_real_number_of, real_mult_number_of_left] @ |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
333 |
bin_arith_simps @ bin_rel_simps; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
334 |
|
14123 | 335 |
(*Binary arithmetic BUT NOT ADDITION since it may collapse adjacent terms |
336 |
during re-arrangement*) |
|
337 |
val non_add_bin_simps = |
|
338 |
bin_simps \\ [real_add_number_of_left, add_real_number_of]; |
|
339 |
||
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
340 |
(*To evaluate binary negations of coefficients*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
341 |
val real_minus_simps = NCons_simps @ |
13462 | 342 |
[real_minus_1_eq_m1, minus_real_number_of, |
343 |
bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min, |
|
344 |
bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min]; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
345 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
346 |
(*To let us treat subtraction as addition*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
347 |
val diff_simps = [real_diff_def, real_minus_add_distrib, real_minus_minus]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
348 |
|
12483
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
349 |
(*push the unary minus down: - x * y = x * - y |
13462 | 350 |
val real_minus_mult_eq_1_to_2 = |
10699 | 351 |
[real_minus_mult_eq1 RS sym, real_minus_mult_eq2] MRS trans |> standard; |
12483
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
352 |
same as real_minus_mult_commute |
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
353 |
*) |
10699 | 354 |
|
355 |
(*to extract again any uncancelled minuses*) |
|
13462 | 356 |
val real_minus_from_mult_simps = |
12483
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
357 |
[real_minus_minus, real_mult_minus_eq1, real_mult_minus_eq2]; |
10699 | 358 |
|
359 |
(*combine unary minus with numeric literals, however nested within a product*) |
|
360 |
val real_mult_minus_simps = |
|
12483
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
361 |
[real_mult_assoc, real_minus_mult_eq1, real_minus_mult_commute]; |
10699 | 362 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
363 |
(*Apply the given rewrite (if present) just once*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
364 |
fun trans_tac None = all_tac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
365 |
| trans_tac (Some th) = ALLGOALS (rtac (th RS trans)); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
366 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
367 |
(*Final simplification: cancel + and * *) |
13462 | 368 |
val simplify_meta_eq = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
369 |
Int_Numeral_Simprocs.simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
370 |
[real_add_zero_left, real_add_zero_right, |
13462 | 371 |
real_mult_0, real_mult_0_right, real_mult_1, real_mult_1_right]; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
372 |
|
13462 | 373 |
fun prep_simproc (name, pats, proc) = |
374 |
Simplifier.simproc (Theory.sign_of (the_context ())) name pats proc; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
375 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
376 |
structure CancelNumeralsCommon = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
377 |
struct |
13462 | 378 |
val mk_sum = mk_sum |
379 |
val dest_sum = dest_sum |
|
380 |
val mk_coeff = mk_coeff |
|
381 |
val dest_coeff = dest_coeff 1 |
|
382 |
val find_first_coeff = find_first_coeff [] |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
383 |
val trans_tac = trans_tac |
13462 | 384 |
val norm_tac = |
10699 | 385 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
386 |
real_minus_simps@real_add_ac)) |
|
14123 | 387 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@real_mult_minus_simps)) |
10699 | 388 |
THEN ALLGOALS |
389 |
(simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
|
390 |
real_add_ac@real_mult_ac)) |
|
13462 | 391 |
val numeral_simp_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
392 |
val simplify_meta_eq = simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
393 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
394 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
395 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
396 |
structure EqCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
397 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
398 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
399 |
val mk_bal = HOLogic.mk_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
400 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
401 |
val bal_add1 = real_eq_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
402 |
val bal_add2 = real_eq_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
403 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
404 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
405 |
structure LessCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
406 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
407 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
408 |
val mk_bal = HOLogic.mk_binrel "op <" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
409 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
410 |
val bal_add1 = real_less_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
411 |
val bal_add2 = real_less_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
412 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
413 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
414 |
structure LeCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
415 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
416 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
417 |
val mk_bal = HOLogic.mk_binrel "op <=" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
418 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
419 |
val bal_add1 = real_le_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
420 |
val bal_add2 = real_le_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
421 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
422 |
|
13462 | 423 |
val cancel_numerals = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
424 |
map prep_simproc |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
425 |
[("realeq_cancel_numerals", |
13462 | 426 |
["(l::real) + m = n", "(l::real) = m + n", |
427 |
"(l::real) - m = n", "(l::real) = m - n", |
|
428 |
"(l::real) * m = n", "(l::real) = m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
429 |
EqCancelNumerals.proc), |
13462 | 430 |
("realless_cancel_numerals", |
431 |
["(l::real) + m < n", "(l::real) < m + n", |
|
432 |
"(l::real) - m < n", "(l::real) < m - n", |
|
433 |
"(l::real) * m < n", "(l::real) < m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
434 |
LessCancelNumerals.proc), |
13462 | 435 |
("realle_cancel_numerals", |
436 |
["(l::real) + m <= n", "(l::real) <= m + n", |
|
437 |
"(l::real) - m <= n", "(l::real) <= m - n", |
|
438 |
"(l::real) * m <= n", "(l::real) <= m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
439 |
LeCancelNumerals.proc)]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
440 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
441 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
442 |
structure CombineNumeralsData = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
443 |
struct |
13462 | 444 |
val add = op + : int*int -> int |
445 |
val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *) |
|
446 |
val dest_sum = dest_sum |
|
447 |
val mk_coeff = mk_coeff |
|
448 |
val dest_coeff = dest_coeff 1 |
|
449 |
val left_distrib = left_real_add_mult_distrib RS trans |
|
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
450 |
val prove_conv = Bin_Simprocs.prove_conv_nohyps |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
451 |
val trans_tac = trans_tac |
13462 | 452 |
val norm_tac = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
453 |
ALLGOALS (simp_tac (HOL_ss addsimps numeral_syms@add_0s@mult_1s@ |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
454 |
diff_simps@real_minus_simps@real_add_ac)) |
14123 | 455 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@real_mult_minus_simps)) |
10699 | 456 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
457 |
real_add_ac@real_mult_ac)) |
|
13462 | 458 |
val numeral_simp_tac = ALLGOALS |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
459 |
(simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
13462 | 460 |
val simplify_meta_eq = |
461 |
Int_Numeral_Simprocs.simplify_meta_eq (add_0s@mult_1s) |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
462 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
463 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
464 |
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); |
13462 | 465 |
|
466 |
val combine_numerals = |
|
467 |
prep_simproc ("real_combine_numerals", ["(i::real) + j", "(i::real) - j"], CombineNumerals.proc); |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
468 |
|
10689 | 469 |
|
470 |
(** Declarations for ExtractCommonTerm **) |
|
471 |
||
472 |
(*this version ALWAYS includes a trailing one*) |
|
473 |
fun long_mk_prod [] = one |
|
474 |
| long_mk_prod (t :: ts) = mk_times (t, mk_prod ts); |
|
475 |
||
476 |
(*Find first term that matches u*) |
|
13462 | 477 |
fun find_first past u [] = raise TERM("find_first", []) |
10689 | 478 |
| find_first past u (t::terms) = |
13462 | 479 |
if u aconv t then (rev past @ terms) |
10689 | 480 |
else find_first (t::past) u terms |
13462 | 481 |
handle TERM _ => find_first (t::past) u terms; |
10689 | 482 |
|
483 |
(*Final simplification: cancel + and * *) |
|
13462 | 484 |
fun cancel_simplify_meta_eq cancel_th th = |
485 |
Int_Numeral_Simprocs.simplify_meta_eq |
|
486 |
[real_mult_1, real_mult_1_right] |
|
10689 | 487 |
(([th, cancel_th]) MRS trans); |
488 |
||
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
489 |
(*** Making constant folding work for 0 and 1 too ***) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
490 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
491 |
structure RealAbstractNumeralsData = |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
492 |
struct |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
493 |
val dest_eq = HOLogic.dest_eq o HOLogic.dest_Trueprop o concl_of |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
494 |
val is_numeral = Bin_Simprocs.is_numeral |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
495 |
val numeral_0_eq_0 = real_numeral_0_eq_0 |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
496 |
val numeral_1_eq_1 = real_numeral_1_eq_1 |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
497 |
val prove_conv = Bin_Simprocs.prove_conv_nohyps_novars |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
498 |
fun norm_tac simps = ALLGOALS (simp_tac (HOL_ss addsimps simps)) |
13462 | 499 |
val simplify_meta_eq = Bin_Simprocs.simplify_meta_eq |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
500 |
end |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
501 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
502 |
structure RealAbstractNumerals = AbstractNumeralsFun (RealAbstractNumeralsData) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
503 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
504 |
(*For addition, we already have rules for the operand 0. |
13462 | 505 |
Multiplication is omitted because there are already special rules for |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
506 |
both 0 and 1 as operands. Unary minus is trivial, just have - 1 = -1. |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
507 |
For the others, having three patterns is a compromise between just having |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
508 |
one (many spurious calls) and having nine (just too many!) *) |
13462 | 509 |
val eval_numerals = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
510 |
map prep_simproc |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
511 |
[("real_add_eval_numerals", |
13462 | 512 |
["(m::real) + 1", "(m::real) + number_of v"], |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
513 |
RealAbstractNumerals.proc add_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
514 |
("real_diff_eval_numerals", |
13462 | 515 |
["(m::real) - 1", "(m::real) - number_of v"], |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
516 |
RealAbstractNumerals.proc diff_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
517 |
("real_eq_eval_numerals", |
13462 | 518 |
["(m::real) = 0", "(m::real) = 1", "(m::real) = number_of v"], |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
519 |
RealAbstractNumerals.proc eq_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
520 |
("real_less_eval_numerals", |
13462 | 521 |
["(m::real) < 0", "(m::real) < 1", "(m::real) < number_of v"], |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
522 |
RealAbstractNumerals.proc less_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
523 |
("real_le_eval_numerals", |
13462 | 524 |
["(m::real) <= 0", "(m::real) <= 1", "(m::real) <= number_of v"], |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
525 |
RealAbstractNumerals.proc le_real_number_of_eq_not_less)] |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
526 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
527 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
528 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
529 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
530 |
Addsimprocs Real_Numeral_Simprocs.eval_numerals; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
531 |
Addsimprocs Real_Numeral_Simprocs.cancel_numerals; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
532 |
Addsimprocs [Real_Numeral_Simprocs.combine_numerals]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
533 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
534 |
(*examples: |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
535 |
print_depth 22; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
536 |
set timing; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
537 |
set trace_simp; |
13462 | 538 |
fun test s = (Goal s; by (Simp_tac 1)); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
539 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
540 |
test "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::real)"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
541 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
542 |
test "2*u = (u::real)"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
543 |
test "(i + j + 12 + (k::real)) - 15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
544 |
test "(i + j + 12 + (k::real)) - 5 = y"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
545 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
546 |
test "y - b < (b::real)"; |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
547 |
test "y - (3*b + c) < (b::real) - 2*c"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
548 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
549 |
test "(2*x - (u*v) + y) - v*3*u = (w::real)"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
550 |
test "(2*x*u*v + (u*v)*4 + y) - v*u*4 = (w::real)"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
551 |
test "(2*x*u*v + (u*v)*4 + y) - v*u = (w::real)"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
552 |
test "u*v - (x*u*v + (u*v)*4 + y) = (w::real)"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
553 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
554 |
test "(i + j + 12 + (k::real)) = u + 15 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
555 |
test "(i + j*2 + 12 + (k::real)) = j + 5 + y"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
556 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
557 |
test "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::real)"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
558 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
559 |
test "a + -(b+c) + b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
560 |
test "a + -(b+c) - b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
561 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
562 |
(*negative numerals*) |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
563 |
test "(i + j + -2 + (k::real)) - (u + 5 + y) = zz"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
564 |
test "(i + j + -3 + (k::real)) < u + 5 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
565 |
test "(i + j + 3 + (k::real)) < u + -6 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
566 |
test "(i + j + -12 + (k::real)) - 15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
567 |
test "(i + j + 12 + (k::real)) - -15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
568 |
test "(i + j + -12 + (k::real)) - -15 = y"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
569 |
*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
570 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
571 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
572 |
(** Constant folding for real plus and times **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
573 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
574 |
(*We do not need |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
575 |
structure Real_Plus_Assoc = Assoc_Fold (Real_Plus_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
576 |
because combine_numerals does the same thing*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
577 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
578 |
structure Real_Times_Assoc_Data : ASSOC_FOLD_DATA = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
579 |
struct |
13462 | 580 |
val ss = HOL_ss |
581 |
val eq_reflection = eq_reflection |
|
9433 | 582 |
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ())) |
13462 | 583 |
val T = HOLogic.realT |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
584 |
val plus = Const ("op *", [HOLogic.realT,HOLogic.realT] ---> HOLogic.realT) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
585 |
val add_ac = real_mult_ac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
586 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
587 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
588 |
structure Real_Times_Assoc = Assoc_Fold (Real_Times_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
589 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
590 |
Addsimprocs [Real_Times_Assoc.conv]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
591 |
|
10699 | 592 |
(*Simplification of x-y < 0, etc.*) |
14329 | 593 |
AddIffs [less_iff_diff_less_0 RS sym]; |
594 |
AddIffs [eq_iff_diff_eq_0 RS sym]; |
|
595 |
AddIffs [le_iff_diff_le_0 RS sym]; |
|
10784 | 596 |
|
597 |
(** <= monotonicity results: needed for arithmetic **) |
|
598 |
||
599 |
Goal "[| i <= j; (0::real) <= k |] ==> i*k <= j*k"; |
|
13462 | 600 |
by (auto_tac (claset(), |
601 |
simpset() addsimps [order_le_less, real_mult_less_mono1])); |
|
10784 | 602 |
qed "real_mult_le_mono1"; |
603 |
||
604 |
Goal "[| i <= j; (0::real) <= k |] ==> k*i <= k*j"; |
|
605 |
by (dtac real_mult_le_mono1 1); |
|
606 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute]))); |
|
607 |
qed "real_mult_le_mono2"; |
|
608 |
||
609 |
Goal "[| (i::real) <= j; k <= l; 0 <= j; 0 <= k |] ==> i*k <= j*l"; |
|
610 |
by (etac (real_mult_le_mono1 RS order_trans) 1); |
|
611 |
by (assume_tac 1); |
|
612 |
by (etac real_mult_le_mono2 1); |
|
613 |
by (assume_tac 1); |
|
614 |
qed "real_mult_le_mono"; |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
615 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
616 |
Addsimps [real_minus_1_eq_m1]; |