author | berghofe |
Tue, 25 Mar 2003 09:48:38 +0100 | |
changeset 13877 | a6b825ee48d9 |
parent 13480 | bb72bd43c6c3 |
child 14123 | b300efca4ae0 |
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)"; |
13462 | 159 |
by Auto_tac; |
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)"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
163 |
by (simp_tac (simpset() addsimps [real_mult_assoc RS sym]) 1); |
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); |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
174 |
by Auto_tac; |
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 |
(** Combining of literal coefficients in sums of products **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
196 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
197 |
Goal "(x < y) = (x-y < (0::real))"; |
13462 | 198 |
by (simp_tac (simpset() addsimps [real_diff_less_eq]) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
199 |
qed "real_less_iff_diff_less_0"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
200 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
201 |
Goal "(x = y) = (x-y = (0::real))"; |
13462 | 202 |
by (simp_tac (simpset() addsimps [real_diff_eq_eq]) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
203 |
qed "real_eq_iff_diff_eq_0"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
204 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
205 |
Goal "(x <= y) = (x-y <= (0::real))"; |
13462 | 206 |
by (simp_tac (simpset() addsimps [real_diff_le_eq]) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
207 |
qed "real_le_iff_diff_le_0"; |
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 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
210 |
(** For combine_numerals **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
211 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
212 |
Goal "i*u + (j*u + k) = (i+j)*u + (k::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
213 |
by (asm_simp_tac (simpset() addsimps [real_add_mult_distrib]) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
214 |
qed "left_real_add_mult_distrib"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
215 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
216 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
217 |
(** For cancel_numerals **) |
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 |
val rel_iff_rel_0_rls = map (inst "y" "?u+?v") |
13462 | 220 |
[real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, |
221 |
real_le_iff_diff_le_0] @ |
|
222 |
map (inst "y" "n") |
|
223 |
[real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, |
|
224 |
real_le_iff_diff_le_0]; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
225 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
226 |
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
|
227 |
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@ |
13462 | 228 |
real_add_ac@rel_iff_rel_0_rls) 1); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
229 |
qed "real_eq_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
230 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
234 |
qed "real_eq_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
235 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
239 |
qed "real_less_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
240 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
244 |
qed "real_less_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
245 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
246 |
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
|
247 |
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
|
248 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
249 |
qed "real_le_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
250 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
@real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
254 |
qed "real_le_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
255 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
256 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
257 |
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
|
258 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
259 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
260 |
structure Real_Numeral_Simprocs = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
261 |
struct |
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 |
(*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
|
264 |
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
|
265 |
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
|
266 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
267 |
(*Utilities*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
268 |
|
10693 | 269 |
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
|
270 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
271 |
(*Decodes a binary real constant, or 0, 1*) |
12819 | 272 |
val dest_numeral = Int_Numeral_Simprocs.dest_numeral; |
273 |
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
|
274 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
275 |
val zero = mk_numeral 0; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
276 |
val mk_plus = HOLogic.mk_binop "op +"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
277 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
278 |
val uminus_const = Const ("uminus", HOLogic.realT --> HOLogic.realT); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
279 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
280 |
(*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
|
281 |
fun mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
282 |
| mk_sum [t,u] = mk_plus (t, u) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
283 |
| mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
284 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
285 |
(*this version ALWAYS includes a trailing zero*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
286 |
fun long_mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
287 |
| 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
|
288 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
289 |
val dest_plus = HOLogic.dest_bin "op +" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
290 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
291 |
(*decompose additions AND subtractions as a sum*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
292 |
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
293 |
dest_summing (pos, t, dest_summing (pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
294 |
| dest_summing (pos, Const ("op -", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
295 |
dest_summing (pos, t, dest_summing (not pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
296 |
| dest_summing (pos, t, ts) = |
13462 | 297 |
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
|
298 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
299 |
fun dest_sum t = dest_summing (true, t, []); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
300 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
301 |
val mk_diff = HOLogic.mk_binop "op -"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
302 |
val dest_diff = HOLogic.dest_bin "op -" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
303 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
304 |
val one = mk_numeral 1; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
305 |
val mk_times = HOLogic.mk_binop "op *"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
306 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
307 |
fun mk_prod [] = one |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
308 |
| mk_prod [t] = t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
309 |
| 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
|
310 |
else mk_times (t, mk_prod ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
311 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
312 |
val dest_times = HOLogic.dest_bin "op *" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
313 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
314 |
fun dest_prod t = |
13462 | 315 |
let val (t,u) = dest_times t |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
316 |
in dest_prod t @ dest_prod u end |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
317 |
handle TERM _ => [t]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
318 |
|
13462 | 319 |
(*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
|
320 |
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
|
321 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
322 |
(*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
|
323 |
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
|
324 |
| dest_coeff sign t = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
325 |
let val ts = sort Term.term_ord (dest_prod t) |
13462 | 326 |
val (n, ts') = find_first_numeral [] ts |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
327 |
handle TERM _ => (1, ts) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
328 |
in (sign*n, mk_prod ts') end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
329 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
330 |
(*Find first coefficient-term THAT MATCHES u*) |
13462 | 331 |
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
|
332 |
| find_first_coeff past u (t::terms) = |
13462 | 333 |
let val (n,u') = dest_coeff 1 t |
334 |
in if u aconv u' then (n, rev past @ terms) |
|
335 |
else find_first_coeff (t::past) u terms |
|
336 |
end |
|
337 |
handle TERM _ => find_first_coeff (t::past) u terms; |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
338 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
339 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
340 |
(*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
|
341 |
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
|
342 |
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
|
343 |
[real_mult_minus1, real_mult_minus1_right]; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
344 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
345 |
(*To perform binary arithmetic*) |
9108 | 346 |
val bin_simps = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
347 |
[real_numeral_0_eq_0 RS sym, real_numeral_1_eq_1 RS sym, |
13462 | 348 |
add_real_number_of, real_add_number_of_left, minus_real_number_of, |
349 |
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
|
350 |
bin_arith_simps @ bin_rel_simps; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
351 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
352 |
(*To evaluate binary negations of coefficients*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
353 |
val real_minus_simps = NCons_simps @ |
13462 | 354 |
[real_minus_1_eq_m1, minus_real_number_of, |
355 |
bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min, |
|
356 |
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
|
357 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
358 |
(*To let us treat subtraction as addition*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
359 |
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
|
360 |
|
12483
0a01efff43e9
new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents:
12338
diff
changeset
|
361 |
(*push the unary minus down: - x * y = x * - y |
13462 | 362 |
val real_minus_mult_eq_1_to_2 = |
10699 | 363 |
[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
|
364 |
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
|
365 |
*) |
10699 | 366 |
|
367 |
(*to extract again any uncancelled minuses*) |
|
13462 | 368 |
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
|
369 |
[real_minus_minus, real_mult_minus_eq1, real_mult_minus_eq2]; |
10699 | 370 |
|
371 |
(*combine unary minus with numeric literals, however nested within a product*) |
|
372 |
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
|
373 |
[real_mult_assoc, real_minus_mult_eq1, real_minus_mult_commute]; |
10699 | 374 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
375 |
(*Apply the given rewrite (if present) just once*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
376 |
fun trans_tac None = all_tac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
377 |
| trans_tac (Some th) = ALLGOALS (rtac (th RS trans)); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
378 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
379 |
(*Final simplification: cancel + and * *) |
13462 | 380 |
val simplify_meta_eq = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
381 |
Int_Numeral_Simprocs.simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
382 |
[real_add_zero_left, real_add_zero_right, |
13462 | 383 |
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
|
384 |
|
13462 | 385 |
fun prep_simproc (name, pats, proc) = |
386 |
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
|
387 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
388 |
structure CancelNumeralsCommon = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
389 |
struct |
13462 | 390 |
val mk_sum = mk_sum |
391 |
val dest_sum = dest_sum |
|
392 |
val mk_coeff = mk_coeff |
|
393 |
val dest_coeff = dest_coeff 1 |
|
394 |
val find_first_coeff = find_first_coeff [] |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
395 |
val trans_tac = trans_tac |
13462 | 396 |
val norm_tac = |
10699 | 397 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
398 |
real_minus_simps@real_add_ac)) |
|
399 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
|
400 |
THEN ALLGOALS |
|
401 |
(simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
|
402 |
real_add_ac@real_mult_ac)) |
|
13462 | 403 |
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
|
404 |
val simplify_meta_eq = simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
405 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
406 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
407 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
408 |
structure EqCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
409 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
410 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
411 |
val mk_bal = HOLogic.mk_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
412 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
413 |
val bal_add1 = real_eq_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
414 |
val bal_add2 = real_eq_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
415 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
416 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
417 |
structure LessCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
418 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
419 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
420 |
val mk_bal = HOLogic.mk_binrel "op <" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
421 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
422 |
val bal_add1 = real_less_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
423 |
val bal_add2 = real_less_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
424 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
425 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
426 |
structure LeCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
427 |
(open CancelNumeralsCommon |
13480
bb72bd43c6c3
use Tactic.prove instead of prove_goalw_cterm in internal proofs!
wenzelm
parents:
13462
diff
changeset
|
428 |
val prove_conv = Bin_Simprocs.prove_conv |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
429 |
val mk_bal = HOLogic.mk_binrel "op <=" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
430 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
431 |
val bal_add1 = real_le_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
432 |
val bal_add2 = real_le_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
433 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
434 |
|
13462 | 435 |
val cancel_numerals = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
436 |
map prep_simproc |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
437 |
[("realeq_cancel_numerals", |
13462 | 438 |
["(l::real) + m = n", "(l::real) = m + n", |
439 |
"(l::real) - m = n", "(l::real) = m - n", |
|
440 |
"(l::real) * m = n", "(l::real) = m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
441 |
EqCancelNumerals.proc), |
13462 | 442 |
("realless_cancel_numerals", |
443 |
["(l::real) + m < n", "(l::real) < m + n", |
|
444 |
"(l::real) - m < n", "(l::real) < m - n", |
|
445 |
"(l::real) * m < n", "(l::real) < m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
446 |
LessCancelNumerals.proc), |
13462 | 447 |
("realle_cancel_numerals", |
448 |
["(l::real) + m <= n", "(l::real) <= m + n", |
|
449 |
"(l::real) - m <= n", "(l::real) <= m - n", |
|
450 |
"(l::real) * m <= n", "(l::real) <= m * n"], |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
451 |
LeCancelNumerals.proc)]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
452 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
453 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
454 |
structure CombineNumeralsData = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
455 |
struct |
13462 | 456 |
val add = op + : int*int -> int |
457 |
val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *) |
|
458 |
val dest_sum = dest_sum |
|
459 |
val mk_coeff = mk_coeff |
|
460 |
val dest_coeff = dest_coeff 1 |
|
461 |
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
|
462 |
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
|
463 |
val trans_tac = trans_tac |
13462 | 464 |
val norm_tac = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
465 |
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
|
466 |
diff_simps@real_minus_simps@real_add_ac)) |
10699 | 467 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
468 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
|
469 |
real_add_ac@real_mult_ac)) |
|
13462 | 470 |
val numeral_simp_tac = ALLGOALS |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
471 |
(simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
13462 | 472 |
val simplify_meta_eq = |
473 |
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
|
474 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
475 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
476 |
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); |
13462 | 477 |
|
478 |
val combine_numerals = |
|
479 |
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
|
480 |
|
10689 | 481 |
|
482 |
(** Declarations for ExtractCommonTerm **) |
|
483 |
||
484 |
(*this version ALWAYS includes a trailing one*) |
|
485 |
fun long_mk_prod [] = one |
|
486 |
| long_mk_prod (t :: ts) = mk_times (t, mk_prod ts); |
|
487 |
||
488 |
(*Find first term that matches u*) |
|
13462 | 489 |
fun find_first past u [] = raise TERM("find_first", []) |
10689 | 490 |
| find_first past u (t::terms) = |
13462 | 491 |
if u aconv t then (rev past @ terms) |
10689 | 492 |
else find_first (t::past) u terms |
13462 | 493 |
handle TERM _ => find_first (t::past) u terms; |
10689 | 494 |
|
495 |
(*Final simplification: cancel + and * *) |
|
13462 | 496 |
fun cancel_simplify_meta_eq cancel_th th = |
497 |
Int_Numeral_Simprocs.simplify_meta_eq |
|
498 |
[real_mult_1, real_mult_1_right] |
|
10689 | 499 |
(([th, cancel_th]) MRS trans); |
500 |
||
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
501 |
(*** 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
|
502 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
503 |
structure RealAbstractNumeralsData = |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
504 |
struct |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
505 |
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
|
506 |
val is_numeral = Bin_Simprocs.is_numeral |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
507 |
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
|
508 |
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
|
509 |
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
|
510 |
fun norm_tac simps = ALLGOALS (simp_tac (HOL_ss addsimps simps)) |
13462 | 511 |
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
|
512 |
end |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
513 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
514 |
structure RealAbstractNumerals = AbstractNumeralsFun (RealAbstractNumeralsData) |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
515 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
516 |
(*For addition, we already have rules for the operand 0. |
13462 | 517 |
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
|
518 |
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
|
519 |
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
|
520 |
one (many spurious calls) and having nine (just too many!) *) |
13462 | 521 |
val eval_numerals = |
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
522 |
map prep_simproc |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
523 |
[("real_add_eval_numerals", |
13462 | 524 |
["(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 add_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
526 |
("real_diff_eval_numerals", |
13462 | 527 |
["(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
|
528 |
RealAbstractNumerals.proc diff_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
529 |
("real_eq_eval_numerals", |
13462 | 530 |
["(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
|
531 |
RealAbstractNumerals.proc eq_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
532 |
("real_less_eval_numerals", |
13462 | 533 |
["(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
|
534 |
RealAbstractNumerals.proc less_real_number_of), |
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
535 |
("real_le_eval_numerals", |
13462 | 536 |
["(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
|
537 |
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
|
538 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
539 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
540 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
541 |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
542 |
Addsimprocs Real_Numeral_Simprocs.eval_numerals; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
543 |
Addsimprocs Real_Numeral_Simprocs.cancel_numerals; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
544 |
Addsimprocs [Real_Numeral_Simprocs.combine_numerals]; |
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 |
(*The Abel_Cancel simprocs are now obsolete*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
547 |
Delsimprocs [Real_Cancel.sum_conv, Real_Cancel.rel_conv]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
548 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
549 |
(*examples: |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
550 |
print_depth 22; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
551 |
set timing; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
552 |
set trace_simp; |
13462 | 553 |
fun test s = (Goal s; by (Simp_tac 1)); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
554 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
555 |
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
|
556 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
557 |
test "2*u = (u::real)"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
558 |
test "(i + j + 12 + (k::real)) - 15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
559 |
test "(i + j + 12 + (k::real)) - 5 = y"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
560 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
561 |
test "y - b < (b::real)"; |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
562 |
test "y - (3*b + c) < (b::real) - 2*c"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
563 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
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
|
568 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
569 |
test "(i + j + 12 + (k::real)) = u + 15 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
570 |
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
|
571 |
|
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
572 |
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
|
573 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
574 |
test "a + -(b+c) + b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
575 |
test "a + -(b+c) - b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
576 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
577 |
(*negative numerals*) |
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
578 |
test "(i + j + -2 + (k::real)) - (u + 5 + y) = zz"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
579 |
test "(i + j + -3 + (k::real)) < u + 5 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
580 |
test "(i + j + 3 + (k::real)) < u + -6 + y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
581 |
test "(i + j + -12 + (k::real)) - 15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
582 |
test "(i + j + 12 + (k::real)) - -15 = y"; |
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
583 |
test "(i + j + -12 + (k::real)) - -15 = y"; |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
584 |
*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
585 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
586 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
587 |
(** Constant folding for real plus and times **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
588 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
589 |
(*We do not need |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
590 |
structure Real_Plus_Assoc = Assoc_Fold (Real_Plus_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
591 |
because combine_numerals does the same thing*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
592 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
593 |
structure Real_Times_Assoc_Data : ASSOC_FOLD_DATA = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
594 |
struct |
13462 | 595 |
val ss = HOL_ss |
596 |
val eq_reflection = eq_reflection |
|
9433 | 597 |
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ())) |
13462 | 598 |
val T = HOLogic.realT |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
599 |
val plus = Const ("op *", [HOLogic.realT,HOLogic.realT] ---> HOLogic.realT) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
600 |
val add_ac = real_mult_ac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
601 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
602 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
603 |
structure Real_Times_Assoc = Assoc_Fold (Real_Times_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
604 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
605 |
Addsimprocs [Real_Times_Assoc.conv]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
606 |
|
10699 | 607 |
(*Simplification of x-y < 0, etc.*) |
608 |
AddIffs [real_less_iff_diff_less_0 RS sym]; |
|
609 |
AddIffs [real_eq_iff_diff_eq_0 RS sym]; |
|
610 |
AddIffs [real_le_iff_diff_le_0 RS sym]; |
|
10784 | 611 |
|
612 |
(** <= monotonicity results: needed for arithmetic **) |
|
613 |
||
614 |
Goal "[| i <= j; (0::real) <= k |] ==> i*k <= j*k"; |
|
13462 | 615 |
by (auto_tac (claset(), |
616 |
simpset() addsimps [order_le_less, real_mult_less_mono1])); |
|
10784 | 617 |
qed "real_mult_le_mono1"; |
618 |
||
619 |
Goal "[| i <= j; (0::real) <= k |] ==> k*i <= k*j"; |
|
620 |
by (dtac real_mult_le_mono1 1); |
|
621 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute]))); |
|
622 |
qed "real_mult_le_mono2"; |
|
623 |
||
624 |
Goal "[| (i::real) <= j; k <= l; 0 <= j; 0 <= k |] ==> i*k <= j*l"; |
|
625 |
by (etac (real_mult_le_mono1 RS order_trans) 1); |
|
626 |
by (assume_tac 1); |
|
627 |
by (etac real_mult_le_mono2 1); |
|
628 |
by (assume_tac 1); |
|
629 |
qed "real_mult_le_mono"; |
|
12018
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
630 |
|
ec054019c910
Numerals and simprocs for types real and hypreal. The abstract
paulson
parents:
11713
diff
changeset
|
631 |
Addsimps [real_minus_1_eq_m1]; |