author | nipkow |
Mon, 06 Aug 2001 13:43:24 +0200 | |
changeset 11464 | ddea204de5bc |
parent 11296 | 38a69e5d79fa |
child 11468 | 02cd5d5bc497 |
permissions | -rw-r--r-- |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
1 |
(* Title: HOL/NatSimprocs.ML |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
2 |
ID: $Id$ |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
4 |
Copyright 2000 University of Cambridge |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
5 |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
6 |
Simprocs for nat numerals (see also nat_simprocs.ML). |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
7 |
*) |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
8 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
9 |
(** For simplifying Suc m - #n **) |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
10 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
11 |
Goal "#0 < n ==> Suc m - n = m - (n - #1)"; |
8865 | 12 |
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1); |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
13 |
qed "Suc_diff_eq_diff_pred"; |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
14 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
15 |
(*Now just instantiating n to (number_of v) does the right simplification, |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
16 |
but with some redundant inequality tests.*) |
11464 | 17 |
(* |
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8877
diff
changeset
|
18 |
Goal "neg (number_of (bin_pred v)) = (number_of v = (0::nat))"; |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
19 |
by (subgoal_tac "neg (number_of (bin_pred v)) = (number_of v < 1)" 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
20 |
by (Asm_simp_tac 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
21 |
by (stac less_number_of_Suc 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
22 |
by (Simp_tac 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
23 |
qed "neg_number_of_bin_pred_iff_0"; |
11464 | 24 |
*) |
25 |
val neg_number_of_bin_pred_iff_0 = thm "neg_number_of_bin_pred_iff_0"; |
|
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
26 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
27 |
Goal "neg (number_of (bin_minus v)) ==> \ |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
28 |
\ Suc m - (number_of v) = m - (number_of (bin_pred v))"; |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
29 |
by (stac Suc_diff_eq_diff_pred 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
30 |
by (Simp_tac 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
31 |
by (Simp_tac 1); |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
32 |
by (asm_full_simp_tac |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
33 |
(simpset_of Int.thy addsimps [diff_nat_number_of, less_0_number_of RS sym, |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
34 |
neg_number_of_bin_pred_iff_0]) 1); |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
35 |
qed "Suc_diff_number_of"; |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
36 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
37 |
(* now redundant because of the inverse_fold simproc |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
38 |
Addsimps [Suc_diff_number_of]; *) |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
39 |
|
8865 | 40 |
Goal "nat_case a f (number_of v) = \ |
41 |
\ (let pv = number_of (bin_pred v) in \ |
|
42 |
\ if neg pv then a else f (nat pv))"; |
|
43 |
by (simp_tac |
|
44 |
(simpset() addsplits [nat.split] |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
45 |
addsimps [Let_def, neg_number_of_bin_pred_iff_0]) 1); |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
46 |
qed "nat_case_number_of"; |
8865 | 47 |
|
48 |
Goal "nat_case a f ((number_of v) + n) = \ |
|
49 |
\ (let pv = number_of (bin_pred v) in \ |
|
50 |
\ if neg pv then nat_case a f n else f (nat pv + n))"; |
|
51 |
by (stac add_eq_if 1); |
|
52 |
by (asm_simp_tac |
|
53 |
(simpset() addsplits [nat.split] |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
54 |
addsimps [Let_def, neg_imp_number_of_eq_0, |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
55 |
neg_number_of_bin_pred_iff_0]) 1); |
8865 | 56 |
qed "nat_case_add_eq_if"; |
57 |
||
58 |
Addsimps [nat_case_number_of, nat_case_add_eq_if]; |
|
59 |
||
60 |
||
61 |
Goal "nat_rec a f (number_of v) = \ |
|
62 |
\ (let pv = number_of (bin_pred v) in \ |
|
63 |
\ if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))"; |
|
64 |
by (case_tac "(number_of v)::nat" 1); |
|
65 |
by (ALLGOALS (asm_simp_tac |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
66 |
(simpset() addsimps [Let_def, neg_number_of_bin_pred_iff_0]))); |
8865 | 67 |
by (asm_full_simp_tac (simpset() addsplits [split_if_asm]) 1); |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
68 |
qed "nat_rec_number_of"; |
8865 | 69 |
|
70 |
Goal "nat_rec a f (number_of v + n) = \ |
|
71 |
\ (let pv = number_of (bin_pred v) in \ |
|
72 |
\ if neg pv then nat_rec a f n \ |
|
73 |
\ else f (nat pv + n) (nat_rec a f (nat pv + n)))"; |
|
74 |
by (stac add_eq_if 1); |
|
75 |
by (asm_simp_tac |
|
76 |
(simpset() addsplits [nat.split] |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
77 |
addsimps [Let_def, neg_imp_number_of_eq_0, |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
78 |
neg_number_of_bin_pred_iff_0]) 1); |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
79 |
qed "nat_rec_add_eq_if"; |
8865 | 80 |
|
81 |
Addsimps [nat_rec_number_of, nat_rec_add_eq_if]; |
|
82 |
||
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
83 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
84 |
(** For simplifying #m - Suc n **) |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
85 |
|
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
86 |
Goal "m - Suc n = (m - #1) - n"; |
8865 | 87 |
by (simp_tac (numeral_ss addsplits [nat_diff_split]) 1); |
8759
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
88 |
qed "diff_Suc_eq_diff_pred"; |
49154c960140
new file containing simproc invocations, from NatBin.ML
paulson
parents:
diff
changeset
|
89 |
|
8877 | 90 |
(*Obsolete because of natdiff_cancel_numerals |
91 |
Addsimps [inst "m" "number_of ?v" diff_Suc_eq_diff_pred]; |
|
92 |
It LOOPS if #1 is being replaced by 1. |
|
93 |
*) |
|
8776 | 94 |
|
95 |
||
96 |
(** Evens and Odds, for Mutilated Chess Board **) |
|
97 |
||
98 |
(*Case analysis on b<#2*) |
|
99 |
Goal "(n::nat) < #2 ==> n = #0 | n = #1"; |
|
100 |
by (arith_tac 1); |
|
101 |
qed "less_2_cases"; |
|
102 |
||
103 |
Goal "Suc(Suc(m)) mod #2 = m mod #2"; |
|
104 |
by (subgoal_tac "m mod #2 < #2" 1); |
|
105 |
by (Asm_simp_tac 2); |
|
106 |
be (less_2_cases RS disjE) 1; |
|
107 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_Suc]))); |
|
108 |
qed "mod2_Suc_Suc"; |
|
109 |
Addsimps [mod2_Suc_Suc]; |
|
110 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8877
diff
changeset
|
111 |
Goal "!!m::nat. (0 < m mod #2) = (m mod #2 = #1)"; |
8776 | 112 |
by (subgoal_tac "m mod #2 < #2" 1); |
113 |
by (Asm_simp_tac 2); |
|
114 |
by (auto_tac (claset(), simpset() delsimps [mod_less_divisor])); |
|
115 |
qed "mod2_gr_0"; |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9000
diff
changeset
|
116 |
Addsimps [mod2_gr_0, rename_numerals mod2_gr_0]; |
8776 | 117 |
|
8877 | 118 |
(** Removal of small numerals: #0, #1 and (in additive positions) #2 **) |
119 |
||
120 |
Goal "#2 + n = Suc (Suc n)"; |
|
121 |
by (Simp_tac 1); |
|
122 |
qed "add_2_eq_Suc"; |
|
123 |
||
124 |
Goal "n + #2 = Suc (Suc n)"; |
|
125 |
by (Simp_tac 1); |
|
126 |
qed "add_2_eq_Suc'"; |
|
127 |
||
128 |
Addsimps [numeral_0_eq_0, numeral_1_eq_1, add_2_eq_Suc, add_2_eq_Suc']; |
|
129 |
||
130 |
(*Can be used to eliminate long strings of Sucs, but not by default*) |
|
131 |
Goal "Suc (Suc (Suc n)) = #3 + n"; |
|
132 |
by (Simp_tac 1); |
|
133 |
qed "Suc3_eq_add_3"; |
|
9583
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
134 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
135 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
136 |
(** To collapse some needless occurrences of Suc |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
137 |
At least three Sucs, since two and fewer are rewritten back to Suc again! |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
138 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
139 |
We already have some rules to simplify operands smaller than 3. |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
140 |
**) |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
141 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
142 |
Goal "m div (Suc (Suc (Suc n))) = m div (#3+n)"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
143 |
by (simp_tac (simpset() addsimps [Suc3_eq_add_3]) 1); |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
144 |
qed "div_Suc_eq_div_add3"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
145 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
146 |
Goal "m mod (Suc (Suc (Suc n))) = m mod (#3+n)"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
147 |
by (simp_tac (simpset() addsimps [Suc3_eq_add_3]) 1); |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
148 |
qed "mod_Suc_eq_mod_add3"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
149 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
150 |
Addsimps [div_Suc_eq_div_add3, mod_Suc_eq_mod_add3]; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
151 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
152 |
Goal "(Suc (Suc (Suc m))) div n = (#3+m) div n"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
153 |
by (simp_tac (simpset() addsimps [Suc3_eq_add_3]) 1); |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
154 |
qed "Suc_div_eq_add3_div"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
155 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
156 |
Goal "(Suc (Suc (Suc m))) mod n = (#3+m) mod n"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
157 |
by (simp_tac (simpset() addsimps [Suc3_eq_add_3]) 1); |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
158 |
qed "Suc_mod_eq_add3_mod"; |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
159 |
|
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
160 |
Addsimps [inst "n" "number_of ?v" Suc_div_eq_add3_div, |
794e26a802c9
some ad-hoc simprules for div and mod to reduce the
paulson
parents:
9436
diff
changeset
|
161 |
inst "n" "number_of ?v" Suc_mod_eq_add3_mod]; |