author | paulson |
Tue, 16 Jan 2001 12:20:52 +0100 | |
changeset 10919 | 144ede948e58 |
parent 10890 | 0b4e916f51ed |
child 11597 | cd6d2eddf75f |
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 |
||
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
16 |
Goalw [real_number_of_def] "(0::real) = #0"; |
7292 | 17 |
by (simp_tac (simpset() addsimps [real_of_int_zero RS sym]) 1); |
18 |
qed "zero_eq_numeral_0"; |
|
19 |
||
20 |
Goalw [real_number_of_def] "1r = #1"; |
|
21 |
by (simp_tac (simpset() addsimps [real_of_int_one RS sym]) 1); |
|
22 |
qed "one_eq_numeral_1"; |
|
23 |
||
24 |
(** Addition **) |
|
25 |
||
26 |
Goal "(number_of v :: real) + number_of v' = number_of (bin_add v v')"; |
|
27 |
by (simp_tac |
|
9433 | 28 |
(HOL_ss addsimps [real_number_of_def, |
7292 | 29 |
real_of_int_add, number_of_add]) 1); |
30 |
qed "add_real_number_of"; |
|
31 |
||
32 |
Addsimps [add_real_number_of]; |
|
33 |
||
34 |
||
35 |
(** Subtraction **) |
|
36 |
||
37 |
Goalw [real_number_of_def] "- (number_of w :: real) = number_of (bin_minus w)"; |
|
38 |
by (simp_tac |
|
9433 | 39 |
(HOL_ss addsimps [number_of_minus, real_of_int_minus]) 1); |
7292 | 40 |
qed "minus_real_number_of"; |
41 |
||
42 |
Goalw [real_number_of_def] |
|
43 |
"(number_of v :: real) - number_of w = number_of (bin_add v (bin_minus w))"; |
|
44 |
by (simp_tac |
|
9433 | 45 |
(HOL_ss addsimps [diff_number_of_eq, real_of_int_diff]) 1); |
7292 | 46 |
qed "diff_real_number_of"; |
47 |
||
48 |
Addsimps [minus_real_number_of, diff_real_number_of]; |
|
49 |
||
50 |
||
51 |
(** Multiplication **) |
|
52 |
||
53 |
Goal "(number_of v :: real) * number_of v' = number_of (bin_mult v v')"; |
|
54 |
by (simp_tac |
|
9433 | 55 |
(HOL_ss addsimps [real_number_of_def, |
7292 | 56 |
real_of_int_mult, number_of_mult]) 1); |
57 |
qed "mult_real_number_of"; |
|
58 |
||
59 |
Addsimps [mult_real_number_of]; |
|
60 |
||
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
61 |
Goal "(#2::real) = #1 + #1"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
62 |
by (Simp_tac 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
63 |
val lemma = result(); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
64 |
|
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
65 |
(*For specialist use: NOT as default simprules*) |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
66 |
Goal "#2 * z = (z+z::real)"; |
9433 | 67 |
by (simp_tac (simpset () |
7588
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
68 |
addsimps [lemma, real_add_mult_distrib, |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
69 |
one_eq_numeral_1 RS sym]) 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
70 |
qed "real_mult_2"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
71 |
|
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
72 |
Goal "z * #2 = (z+z::real)"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
73 |
by (stac real_mult_commute 1 THEN rtac real_mult_2 1); |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
74 |
qed "real_mult_2_right"; |
26384af93359
Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents:
7583
diff
changeset
|
75 |
|
7292 | 76 |
|
77 |
(*** Comparisons ***) |
|
78 |
||
79 |
(** Equals (=) **) |
|
80 |
||
81 |
Goal "((number_of v :: real) = number_of v') = \ |
|
82 |
\ iszero (number_of (bin_add v (bin_minus v')))"; |
|
83 |
by (simp_tac |
|
9433 | 84 |
(HOL_ss addsimps [real_number_of_def, |
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10712
diff
changeset
|
85 |
real_of_int_eq_iff, eq_number_of_eq]) 1); |
7292 | 86 |
qed "eq_real_number_of"; |
87 |
||
88 |
Addsimps [eq_real_number_of]; |
|
89 |
||
90 |
(** Less-than (<) **) |
|
91 |
||
92 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
93 |
Goal "((number_of v :: real) < number_of v') = \ |
|
94 |
\ neg (number_of (bin_add v (bin_minus v')))"; |
|
95 |
by (simp_tac |
|
9433 | 96 |
(HOL_ss addsimps [real_number_of_def, real_of_int_less_iff, |
7292 | 97 |
less_number_of_eq_neg]) 1); |
98 |
qed "less_real_number_of"; |
|
99 |
||
100 |
Addsimps [less_real_number_of]; |
|
101 |
||
102 |
||
103 |
(** Less-than-or-equals (<=) **) |
|
104 |
||
105 |
Goal "(number_of x <= (number_of y::real)) = \ |
|
106 |
\ (~ number_of y < (number_of x::real))"; |
|
107 |
by (rtac (linorder_not_less RS sym) 1); |
|
108 |
qed "le_real_number_of_eq_not_less"; |
|
109 |
||
110 |
Addsimps [le_real_number_of_eq_not_less]; |
|
111 |
||
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
112 |
(*** New versions of existing theorems involving 0, 1r ***) |
7292 | 113 |
|
114 |
Goal "- #1 = (#-1::real)"; |
|
115 |
by (Simp_tac 1); |
|
116 |
qed "minus_numeral_one"; |
|
117 |
||
118 |
||
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
119 |
(*Maps 0 to #0 and 1r to #1 and -1r to #-1*) |
7292 | 120 |
val real_numeral_ss = |
121 |
HOL_ss addsimps [zero_eq_numeral_0, one_eq_numeral_1, |
|
122 |
minus_numeral_one]; |
|
123 |
||
9433 | 124 |
fun rename_numerals th = |
125 |
asm_full_simplify real_numeral_ss (Thm.transfer (the_context ()) th); |
|
7292 | 126 |
|
127 |
||
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
128 |
(*Now insert some identities previously stated for 0 and 1r*) |
7292 | 129 |
|
130 |
(** RealDef & Real **) |
|
131 |
||
9433 | 132 |
Addsimps (map rename_numerals |
7292 | 133 |
[real_minus_zero, real_minus_zero_iff, |
134 |
real_add_zero_left, real_add_zero_right, |
|
135 |
real_diff_0, real_diff_0_right, |
|
136 |
real_mult_0_right, real_mult_0, real_mult_1_right, real_mult_1, |
|
10606 | 137 |
real_mult_minus_1_right, real_mult_minus_1, real_inverse_1, |
7292 | 138 |
real_minus_zero_less_iff]); |
139 |
||
10784 | 140 |
AddIffs |
141 |
(map rename_numerals |
|
142 |
[real_mult_is_0, real_of_nat_zero_iff, real_le_square]); |
|
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
143 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
144 |
bind_thm ("real_0_less_mult_iff", |
9433 | 145 |
rename_numerals real_zero_less_mult_iff); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
146 |
bind_thm ("real_0_le_mult_iff", |
9433 | 147 |
rename_numerals real_zero_le_mult_iff); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
148 |
bind_thm ("real_mult_less_0_iff", |
9433 | 149 |
rename_numerals real_mult_less_zero_iff); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
150 |
bind_thm ("real_mult_le_0_iff", |
9433 | 151 |
rename_numerals real_mult_le_zero_iff); |
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
152 |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10712
diff
changeset
|
153 |
bind_thm ("real_inverse_less_0", rename_numerals real_inverse_less_zero); |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10712
diff
changeset
|
154 |
bind_thm ("real_inverse_gt_0", rename_numerals real_inverse_gt_zero); |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10712
diff
changeset
|
155 |
|
10784 | 156 |
Addsimps [zero_eq_numeral_0,one_eq_numeral_1]; |
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10712
diff
changeset
|
157 |
|
7292 | 158 |
|
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
159 |
(** real from type "nat" **) |
7292 | 160 |
|
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
161 |
Goal "(#0 < real (n::nat)) = (0<n)"; |
10784 | 162 |
by (simp_tac (HOL_ss addsimps [real_of_nat_less_iff, |
163 |
rename_numerals real_of_nat_zero RS sym]) 1); |
|
164 |
qed "zero_less_real_of_nat_iff"; |
|
165 |
AddIffs [zero_less_real_of_nat_iff]; |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
166 |
|
10919
144ede948e58
renamings: real_of_nat, real_of_int -> (overloaded) real
paulson
parents:
10890
diff
changeset
|
167 |
Goal "(#0 <= real (n::nat)) = (0<=n)"; |
10784 | 168 |
by (simp_tac (HOL_ss addsimps [real_of_nat_le_iff, |
169 |
rename_numerals real_of_nat_zero RS sym]) 1); |
|
170 |
qed "zero_le_real_of_nat_iff"; |
|
171 |
AddIffs [zero_le_real_of_nat_iff]; |
|
7583
d1b40e0464b1
Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents:
7292
diff
changeset
|
172 |
|
9013
9dd0274f76af
Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents:
8838
diff
changeset
|
173 |
|
9043
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
174 |
(** Simplification of arithmetic when nested to the right **) |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
175 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
176 |
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::real)"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
177 |
by Auto_tac; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
178 |
qed "real_add_number_of_left"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
179 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
qed "real_mult_number_of_left"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
183 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
184 |
Goalw [real_diff_def] |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
185 |
"number_of v + (number_of w - c) = number_of(bin_add v w) - (c::real)"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
186 |
by (rtac real_add_number_of_left 1); |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
187 |
qed "real_add_number_of_diff1"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
188 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
189 |
Goal "number_of v + (c - number_of w) = \ |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
190 |
\ number_of (bin_add v (bin_minus w)) + (c::real)"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
191 |
by (stac (diff_real_number_of RS sym) 1); |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
192 |
by Auto_tac; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
193 |
qed "real_add_number_of_diff2"; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
194 |
|
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
195 |
Addsimps [real_add_number_of_left, real_mult_number_of_left, |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
196 |
real_add_number_of_diff1, real_add_number_of_diff2]; |
ca761fe227d8
First round of changes, towards installation of simprocs
paulson
parents:
9013
diff
changeset
|
197 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
198 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
199 |
(*"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
|
200 |
Goal "real (number_of v :: nat) = \ |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
201 |
\ (if neg (number_of v) then #0 \ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
202 |
\ else (number_of v :: real))"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
203 |
by (simp_tac |
9433 | 204 |
(HOL_ss addsimps [nat_number_of_def, real_of_nat_real_of_int, |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
205 |
real_of_nat_neg_int, real_number_of, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
206 |
zero_eq_numeral_0]) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
207 |
qed "real_of_nat_number_of"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
208 |
Addsimps [real_of_nat_number_of]; |
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 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
211 |
(**** Simprocs for numeric literals ****) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
212 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
213 |
(** Combining of literal coefficients in sums of products **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
214 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
215 |
Goal "(x < y) = (x-y < (#0::real))"; |
9080
67ca888af420
fixed the installation of linear arithmetic for the reals
paulson
parents:
9068
diff
changeset
|
216 |
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
|
217 |
qed "real_less_iff_diff_less_0"; |
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 "(x = y) = (x-y = (#0::real))"; |
9080
67ca888af420
fixed the installation of linear arithmetic for the reals
paulson
parents:
9068
diff
changeset
|
220 |
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
|
221 |
qed "real_eq_iff_diff_eq_0"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
222 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
223 |
Goal "(x <= y) = (x-y <= (#0::real))"; |
9080
67ca888af420
fixed the installation of linear arithmetic for the reals
paulson
parents:
9068
diff
changeset
|
224 |
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
|
225 |
qed "real_le_iff_diff_le_0"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
226 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
227 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
228 |
(** For combine_numerals **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
229 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
230 |
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
|
231 |
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
|
232 |
qed "left_real_add_mult_distrib"; |
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 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
235 |
(** For cancel_numerals **) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
236 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
237 |
val rel_iff_rel_0_rls = map (inst "y" "?u+?v") |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
238 |
[real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
239 |
real_le_iff_diff_le_0] @ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
240 |
map (inst "y" "n") |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
241 |
[real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
242 |
real_le_iff_diff_le_0]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
243 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
247 |
qed "real_eq_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
248 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
252 |
qed "real_eq_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
253 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
257 |
qed "real_less_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
258 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
262 |
qed "real_less_add_iff2"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
263 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
267 |
qed "real_le_add_iff1"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
268 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
@real_add_ac@rel_iff_rel_0_rls) 1); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
272 |
qed "real_le_add_iff2"; |
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 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
275 |
structure Real_Numeral_Simprocs = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
276 |
struct |
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 |
(*Utilities*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
279 |
|
10693 | 280 |
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
|
281 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
282 |
(*Decodes a binary real constant*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
283 |
fun dest_numeral (Const("Numeral.number_of", _) $ w) = |
10890 | 284 |
(HOLogic.dest_binum w |
285 |
handle TERM _ => raise TERM("Real_Numeral_Simprocs.dest_numeral:1", [w])) |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
286 |
| dest_numeral t = raise TERM("Real_Numeral_Simprocs.dest_numeral:2", [t]); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
287 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
288 |
fun find_first_numeral past (t::terms) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
289 |
((dest_numeral t, rev past @ terms) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
290 |
handle TERM _ => find_first_numeral (t::past) terms) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
291 |
| find_first_numeral past [] = raise TERM("find_first_numeral", []); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
292 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
293 |
val zero = mk_numeral 0; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
294 |
val mk_plus = HOLogic.mk_binop "op +"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
295 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
296 |
val uminus_const = Const ("uminus", HOLogic.realT --> HOLogic.realT); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
297 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
298 |
(*Thus mk_sum[t] yields t+#0; longer sums don't have a trailing zero*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
299 |
fun mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
300 |
| mk_sum [t,u] = mk_plus (t, u) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
301 |
| mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
302 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
303 |
(*this version ALWAYS includes a trailing zero*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
304 |
fun long_mk_sum [] = zero |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
305 |
| 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
|
306 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
307 |
val dest_plus = HOLogic.dest_bin "op +" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
308 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
309 |
(*decompose additions AND subtractions as a sum*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
310 |
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
311 |
dest_summing (pos, t, dest_summing (pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
312 |
| dest_summing (pos, Const ("op -", _) $ t $ u, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
313 |
dest_summing (pos, t, dest_summing (not pos, u, ts)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
314 |
| dest_summing (pos, t, ts) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
315 |
if pos then t::ts else uminus_const$t :: ts; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
316 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
317 |
fun dest_sum t = dest_summing (true, t, []); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
318 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
319 |
val mk_diff = HOLogic.mk_binop "op -"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
320 |
val dest_diff = HOLogic.dest_bin "op -" HOLogic.realT; |
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 |
val one = mk_numeral 1; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
323 |
val mk_times = HOLogic.mk_binop "op *"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
324 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
325 |
fun mk_prod [] = one |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
326 |
| mk_prod [t] = t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
327 |
| 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
|
328 |
else mk_times (t, mk_prod ts); |
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 |
val dest_times = HOLogic.dest_bin "op *" HOLogic.realT; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
331 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
332 |
fun dest_prod t = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
333 |
let val (t,u) = dest_times t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
334 |
in dest_prod t @ dest_prod u end |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
335 |
handle TERM _ => [t]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
336 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
337 |
(*DON'T do the obvious simplifications; that would create special cases*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
338 |
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
|
339 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
340 |
(*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
|
341 |
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
|
342 |
| dest_coeff sign t = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
343 |
let val ts = sort Term.term_ord (dest_prod t) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
344 |
val (n, ts') = find_first_numeral [] ts |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
345 |
handle TERM _ => (1, ts) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
346 |
in (sign*n, mk_prod ts') end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
347 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
348 |
(*Find first coefficient-term THAT MATCHES u*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
349 |
fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
350 |
| find_first_coeff past u (t::terms) = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
351 |
let val (n,u') = dest_coeff 1 t |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
352 |
in if u aconv u' then (n, rev past @ terms) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
353 |
else find_first_coeff (t::past) u terms |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
354 |
end |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
355 |
handle TERM _ => find_first_coeff (t::past) u terms; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
356 |
|
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 |
(*Simplify #1*n and n*#1 to n*) |
9433 | 359 |
val add_0s = map rename_numerals |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
360 |
[real_add_zero_left, real_add_zero_right]; |
10648 | 361 |
val mult_plus_1s = map rename_numerals |
362 |
[real_mult_1, real_mult_1_right]; |
|
363 |
val mult_minus_1s = map rename_numerals |
|
364 |
[real_mult_minus_1, real_mult_minus_1_right]; |
|
365 |
val mult_1s = mult_plus_1s @ mult_minus_1s; |
|
9068
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 |
(*To perform binary arithmetic*) |
9108 | 368 |
val bin_simps = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
369 |
[add_real_number_of, real_add_number_of_left, minus_real_number_of, |
10648 | 370 |
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
|
371 |
bin_arith_simps @ bin_rel_simps; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
372 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
373 |
(*To evaluate binary negations of coefficients*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
374 |
val real_minus_simps = NCons_simps @ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
375 |
[minus_real_number_of, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
376 |
bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
377 |
bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min]; |
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 |
(*To let us treat subtraction as addition*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
380 |
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
|
381 |
|
10699 | 382 |
(*push the unary minus down: - x * y = x * - y *) |
383 |
val real_minus_mult_eq_1_to_2 = |
|
384 |
[real_minus_mult_eq1 RS sym, real_minus_mult_eq2] MRS trans |> standard; |
|
385 |
||
386 |
(*to extract again any uncancelled minuses*) |
|
387 |
val real_minus_from_mult_simps = |
|
388 |
[real_minus_minus, real_minus_mult_eq1 RS sym, real_minus_mult_eq2 RS sym]; |
|
389 |
||
390 |
(*combine unary minus with numeric literals, however nested within a product*) |
|
391 |
val real_mult_minus_simps = |
|
392 |
[real_mult_assoc, real_minus_mult_eq1, real_minus_mult_eq_1_to_2]; |
|
393 |
||
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
394 |
(*Apply the given rewrite (if present) just once*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
395 |
fun trans_tac None = all_tac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
396 |
| trans_tac (Some th) = ALLGOALS (rtac (th RS trans)); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
397 |
|
9544
f9202e219a29
added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents:
9433
diff
changeset
|
398 |
fun prove_conv name tacs sg (hyps: thm list) (t,u) = |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
399 |
if t aconv u then None |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
400 |
else |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
401 |
let val ct = cterm_of sg (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u))) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
402 |
in Some |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
403 |
(prove_goalw_cterm [] ct (K tacs) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
404 |
handle ERROR => error |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
405 |
("The error(s) above occurred while trying to prove " ^ |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
406 |
string_of_cterm ct ^ "\nInternal failure of simproc " ^ name)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
407 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
408 |
|
9544
f9202e219a29
added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents:
9433
diff
changeset
|
409 |
(*version without the hyps argument*) |
f9202e219a29
added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents:
9433
diff
changeset
|
410 |
fun prove_conv_nohyps name tacs sg = prove_conv name tacs sg []; |
f9202e219a29
added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents:
9433
diff
changeset
|
411 |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
412 |
(*Final simplification: cancel + and * *) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
413 |
val simplify_meta_eq = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
414 |
Int_Numeral_Simprocs.simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
415 |
[real_add_zero_left, real_add_zero_right, |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
416 |
real_mult_0, real_mult_0_right, real_mult_1, real_mult_1_right]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
417 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
418 |
fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc; |
9433 | 419 |
fun prep_pat s = Thm.read_cterm (Theory.sign_of (the_context ())) (s, HOLogic.termT); |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
420 |
val prep_pats = map prep_pat; |
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 |
structure CancelNumeralsCommon = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
423 |
struct |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
424 |
val mk_sum = mk_sum |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
425 |
val dest_sum = dest_sum |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
426 |
val mk_coeff = mk_coeff |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
427 |
val dest_coeff = dest_coeff 1 |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
428 |
val find_first_coeff = find_first_coeff [] |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
429 |
val trans_tac = trans_tac |
10699 | 430 |
val norm_tac = |
431 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
|
432 |
real_minus_simps@real_add_ac)) |
|
433 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
|
434 |
THEN ALLGOALS |
|
435 |
(simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
|
436 |
real_add_ac@real_mult_ac)) |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
437 |
val numeral_simp_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
438 |
val simplify_meta_eq = simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
439 |
end; |
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 EqCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
443 |
(open CancelNumeralsCommon |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
444 |
val prove_conv = prove_conv "realeq_cancel_numerals" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
445 |
val mk_bal = HOLogic.mk_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
446 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
447 |
val bal_add1 = real_eq_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
448 |
val bal_add2 = real_eq_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
449 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
450 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
451 |
structure LessCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
452 |
(open CancelNumeralsCommon |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
453 |
val prove_conv = prove_conv "realless_cancel_numerals" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
454 |
val mk_bal = HOLogic.mk_binrel "op <" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
455 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
456 |
val bal_add1 = real_less_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
457 |
val bal_add2 = real_less_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
458 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
459 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
460 |
structure LeCancelNumerals = CancelNumeralsFun |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
461 |
(open CancelNumeralsCommon |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
462 |
val prove_conv = prove_conv "realle_cancel_numerals" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
463 |
val mk_bal = HOLogic.mk_binrel "op <=" |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
464 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
465 |
val bal_add1 = real_le_add_iff1 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
466 |
val bal_add2 = real_le_add_iff2 RS trans |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
467 |
); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
468 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
469 |
val cancel_numerals = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
470 |
map prep_simproc |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
471 |
[("realeq_cancel_numerals", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
472 |
prep_pats ["(l::real) + m = n", "(l::real) = m + n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
473 |
"(l::real) - m = n", "(l::real) = m - n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
474 |
"(l::real) * m = n", "(l::real) = m * n"], |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
475 |
EqCancelNumerals.proc), |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
476 |
("realless_cancel_numerals", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
477 |
prep_pats ["(l::real) + m < n", "(l::real) < m + n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
478 |
"(l::real) - m < n", "(l::real) < m - n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
479 |
"(l::real) * m < n", "(l::real) < m * n"], |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
480 |
LessCancelNumerals.proc), |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
481 |
("realle_cancel_numerals", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
482 |
prep_pats ["(l::real) + m <= n", "(l::real) <= m + n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
483 |
"(l::real) - m <= n", "(l::real) <= m - n", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
484 |
"(l::real) * m <= n", "(l::real) <= m * n"], |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
485 |
LeCancelNumerals.proc)]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
486 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
487 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
488 |
structure CombineNumeralsData = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
489 |
struct |
9574 | 490 |
val add = op + : int*int -> int |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
491 |
val mk_sum = long_mk_sum (*to work for e.g. #2*x + #3*x *) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
492 |
val dest_sum = dest_sum |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
493 |
val mk_coeff = mk_coeff |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
494 |
val dest_coeff = dest_coeff 1 |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
495 |
val left_distrib = left_real_add_mult_distrib RS trans |
9544
f9202e219a29
added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents:
9433
diff
changeset
|
496 |
val prove_conv = prove_conv_nohyps "real_combine_numerals" |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
497 |
val trans_tac = trans_tac |
10699 | 498 |
val norm_tac = |
499 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
|
500 |
real_minus_simps@real_add_ac)) |
|
501 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
|
502 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps@ |
|
503 |
real_add_ac@real_mult_ac)) |
|
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
504 |
val numeral_simp_tac = ALLGOALS |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
505 |
(simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
506 |
val simplify_meta_eq = simplify_meta_eq |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
507 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
508 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
509 |
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
510 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
511 |
val combine_numerals = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
512 |
prep_simproc ("real_combine_numerals", |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
513 |
prep_pats ["(i::real) + j", "(i::real) - j"], |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
514 |
CombineNumerals.proc); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
515 |
|
10689 | 516 |
|
517 |
(** Declarations for ExtractCommonTerm **) |
|
518 |
||
519 |
(*this version ALWAYS includes a trailing one*) |
|
520 |
fun long_mk_prod [] = one |
|
521 |
| long_mk_prod (t :: ts) = mk_times (t, mk_prod ts); |
|
522 |
||
523 |
(*Find first term that matches u*) |
|
524 |
fun find_first past u [] = raise TERM("find_first", []) |
|
525 |
| find_first past u (t::terms) = |
|
526 |
if u aconv t then (rev past @ terms) |
|
527 |
else find_first (t::past) u terms |
|
528 |
handle TERM _ => find_first (t::past) u terms; |
|
529 |
||
530 |
(*Final simplification: cancel + and * *) |
|
531 |
fun cancel_simplify_meta_eq cancel_th th = |
|
532 |
Int_Numeral_Simprocs.simplify_meta_eq |
|
533 |
[real_mult_1, real_mult_1_right] |
|
534 |
(([th, cancel_th]) MRS trans); |
|
535 |
||
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
536 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
537 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
538 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
539 |
Addsimprocs Real_Numeral_Simprocs.cancel_numerals; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
540 |
Addsimprocs [Real_Numeral_Simprocs.combine_numerals]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
541 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
542 |
(*The Abel_Cancel simprocs are now obsolete*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
543 |
Delsimprocs [Real_Cancel.sum_conv, Real_Cancel.rel_conv]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
544 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
545 |
(*examples: |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
546 |
print_depth 22; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
547 |
set timing; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
548 |
set trace_simp; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
549 |
fun test s = (Goal s; by (Simp_tac 1)); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
550 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
551 |
test "l + #2 + #2 + #2 + (l + #2) + (oo + #2) = (uu::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
552 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
553 |
test "#2*u = (u::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
554 |
test "(i + j + #12 + (k::real)) - #15 = y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
555 |
test "(i + j + #12 + (k::real)) - #5 = y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
556 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
557 |
test "y - b < (b::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
558 |
test "y - (#3*b + c) < (b::real) - #2*c"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
559 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
560 |
test "(#2*x - (u*v) + y) - v*#3*u = (w::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
561 |
test "(#2*x*u*v + (u*v)*#4 + y) - v*u*#4 = (w::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
562 |
test "(#2*x*u*v + (u*v)*#4 + y) - v*u = (w::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
563 |
test "u*v - (x*u*v + (u*v)*#4 + y) = (w::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
564 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
565 |
test "(i + j + #12 + (k::real)) = u + #15 + y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
566 |
test "(i + j*#2 + #12 + (k::real)) = j + #5 + y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
567 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
568 |
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)"; |
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 |
test "a + -(b+c) + b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
571 |
test "a + -(b+c) - b = (d::real)"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
572 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
573 |
(*negative numerals*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
574 |
test "(i + j + #-2 + (k::real)) - (u + #5 + y) = zz"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
575 |
test "(i + j + #-3 + (k::real)) < u + #5 + y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
576 |
test "(i + j + #3 + (k::real)) < u + #-6 + y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
577 |
test "(i + j + #-12 + (k::real)) - #15 = y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
578 |
test "(i + j + #12 + (k::real)) - #-15 = y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
579 |
test "(i + j + #-12 + (k::real)) - #-15 = y"; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
580 |
*) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
581 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
582 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
583 |
(** Constant folding for real plus and times **) |
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 |
(*We do not need |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
586 |
structure Real_Plus_Assoc = Assoc_Fold (Real_Plus_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
587 |
because combine_numerals does the same thing*) |
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 |
structure Real_Times_Assoc_Data : ASSOC_FOLD_DATA = |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
590 |
struct |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
591 |
val ss = HOL_ss |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
592 |
val eq_reflection = eq_reflection |
9433 | 593 |
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ())) |
9068
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
594 |
val T = HOLogic.realT |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
595 |
val plus = Const ("op *", [HOLogic.realT,HOLogic.realT] ---> HOLogic.realT) |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
596 |
val add_ac = real_mult_ac |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
597 |
end; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
598 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
599 |
structure Real_Times_Assoc = Assoc_Fold (Real_Times_Assoc_Data); |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
600 |
|
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
601 |
Addsimprocs [Real_Times_Assoc.conv]; |
202fdf72cf23
installing the cancel_numerals and combine_numerals simprocs
paulson
parents:
9043
diff
changeset
|
602 |
|
10699 | 603 |
(*Simplification of x-y < 0, etc.*) |
604 |
AddIffs [real_less_iff_diff_less_0 RS sym]; |
|
605 |
AddIffs [real_eq_iff_diff_eq_0 RS sym]; |
|
606 |
AddIffs [real_le_iff_diff_le_0 RS sym]; |
|
10784 | 607 |
|
608 |
(** <= monotonicity results: needed for arithmetic **) |
|
609 |
||
610 |
Goal "[| i <= j; (0::real) <= k |] ==> i*k <= j*k"; |
|
611 |
by (auto_tac (claset(), |
|
612 |
simpset() addsimps [order_le_less, real_mult_less_mono1])); |
|
613 |
qed "real_mult_le_mono1"; |
|
614 |
||
615 |
Goal "[| i <= j; (0::real) <= k |] ==> k*i <= k*j"; |
|
616 |
by (dtac real_mult_le_mono1 1); |
|
617 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute]))); |
|
618 |
qed "real_mult_le_mono2"; |
|
619 |
||
620 |
Goal "[| (i::real) <= j; k <= l; 0 <= j; 0 <= k |] ==> i*k <= j*l"; |
|
621 |
by (etac (real_mult_le_mono1 RS order_trans) 1); |
|
622 |
by (assume_tac 1); |
|
623 |
by (etac real_mult_le_mono2 1); |
|
624 |
by (assume_tac 1); |
|
625 |
qed "real_mult_le_mono"; |