author | wenzelm |
Sat, 03 Feb 2001 17:43:34 +0100 | |
changeset 11048 | 2f4976370b7a |
parent 9907 | 473a6604da94 |
child 11386 | cf8d81cf8034 |
permissions | -rw-r--r-- |
1793 | 1 |
(* Title: ZF/Arith.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
1609 | 6 |
Arithmetic operators and their definitions |
0 | 7 |
|
8 |
Proofs about elementary arithmetic: addition, multiplication, etc. |
|
9 |
*) |
|
10 |
||
11 |
(*"Difference" is subtraction of natural numbers. |
|
12 |
There are no negative numbers; we have |
|
13 |
m #- n = 0 iff m<=n and m #- n = succ(k) iff m>n. |
|
14 |
Also, rec(m, 0, %z w.z) is pred(m). |
|
15 |
*) |
|
16 |
||
8127
68c6159440f1
new lemmas for Ntree recursor example; more simprules; more lemmas borrowed
paulson
parents:
7499
diff
changeset
|
17 |
Addsimps [rec_type, nat_0_le]; |
9907 | 18 |
bind_thms ("nat_typechecks", [rec_type, nat_0I, nat_1I, nat_succI, Ord_nat]); |
0 | 19 |
|
5137 | 20 |
Goal "[| 0<k; k: nat |] ==> EX j: nat. k = succ(j)"; |
1708 | 21 |
by (etac rev_mp 1); |
6070 | 22 |
by (induct_tac "k" 1); |
2469 | 23 |
by (Simp_tac 1); |
3016 | 24 |
by (Blast_tac 1); |
1708 | 25 |
val lemma = result(); |
26 |
||
27 |
(* [| 0 < k; k: nat; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *) |
|
28 |
bind_thm ("zero_lt_natE", lemma RS bexE); |
|
29 |
||
30 |
||
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
31 |
(** natify: coercion to "nat" **) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
32 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
33 |
Goalw [pred_def] "pred(succ(y)) = y"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
34 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
35 |
qed "pred_succ_eq"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
36 |
Addsimps [pred_succ_eq]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
37 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
38 |
Goal "natify(succ(x)) = succ(natify(x))"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
39 |
by (rtac (natify_def RS def_Vrecursor RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
40 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
41 |
qed "natify_succ"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
42 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
43 |
Goal "natify(0) = 0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
44 |
by (rtac (natify_def RS def_Vrecursor RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
45 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
46 |
qed "natify_0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
47 |
Addsimps [natify_0]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
48 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
49 |
Goal "ALL z. x ~= succ(z) ==> natify(x) = 0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
50 |
by (rtac (natify_def RS def_Vrecursor RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
51 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
52 |
qed "natify_non_succ"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
53 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
54 |
Goal "natify(x) : nat"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
55 |
by (eps_ind_tac "x" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
56 |
by (case_tac "EX z. x1 = succ(z)" 1); |
9548 | 57 |
by (auto_tac (claset(), simpset() addsimps [natify_succ, natify_non_succ])); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
58 |
qed "natify_in_nat"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
59 |
AddIffs [natify_in_nat]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
60 |
AddTCs [natify_in_nat]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
61 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
62 |
Goal "n : nat ==> natify(n) = n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
63 |
by (induct_tac "n" 1); |
9548 | 64 |
by (auto_tac (claset(), simpset() addsimps [natify_succ])); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
65 |
qed "natify_ident"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
66 |
Addsimps [natify_ident]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
67 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
68 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
69 |
(*** Collapsing rules: to remove natify from arithmetic expressions ***) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
70 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
71 |
Goal "natify(natify(x)) = natify(x)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
72 |
by (Simp_tac 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
73 |
qed "natify_idem"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
74 |
Addsimps [natify_idem]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
75 |
|
0 | 76 |
(** Addition **) |
77 |
||
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
78 |
Goal "natify(m) #+ n = m #+ n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
79 |
by (simp_tac (simpset() addsimps [add_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
80 |
qed "add_natify1"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
81 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
82 |
Goal "m #+ natify(n) = m #+ n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
83 |
by (simp_tac (simpset() addsimps [add_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
84 |
qed "add_natify2"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
85 |
Addsimps [add_natify1, add_natify2]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
86 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
87 |
(** Multiplication **) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
88 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
89 |
Goal "natify(m) #* n = m #* n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
90 |
by (simp_tac (simpset() addsimps [mult_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
91 |
qed "mult_natify1"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
92 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
93 |
Goal "m #* natify(n) = m #* n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
94 |
by (simp_tac (simpset() addsimps [mult_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
95 |
qed "mult_natify2"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
96 |
Addsimps [mult_natify1, mult_natify2]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
97 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
98 |
(** Difference **) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
99 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
100 |
Goal "natify(m) #- n = m #- n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
101 |
by (simp_tac (simpset() addsimps [diff_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
102 |
qed "diff_natify1"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
103 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
104 |
Goal "m #- natify(n) = m #- n"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
105 |
by (simp_tac (simpset() addsimps [diff_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
106 |
qed "diff_natify2"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
107 |
Addsimps [diff_natify1, diff_natify2]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
108 |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
109 |
(** Remainder **) |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
110 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
111 |
Goal "natify(m) mod n = m mod n"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
112 |
by (simp_tac (simpset() addsimps [mod_def]) 1); |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
113 |
qed "mod_natify1"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
114 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
115 |
Goal "m mod natify(n) = m mod n"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
116 |
by (simp_tac (simpset() addsimps [mod_def]) 1); |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
117 |
qed "mod_natify2"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
118 |
Addsimps [mod_natify1, mod_natify2]; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
119 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
120 |
(** Quotient **) |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
121 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
122 |
Goal "natify(m) div n = m div n"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
123 |
by (simp_tac (simpset() addsimps [div_def]) 1); |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
124 |
qed "div_natify1"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
125 |
|
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
126 |
Goal "m div natify(n) = m div n"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
127 |
by (simp_tac (simpset() addsimps [div_def]) 1); |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
128 |
qed "div_natify2"; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
129 |
Addsimps [div_natify1, div_natify2]; |
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
130 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
131 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
132 |
(*** Typing rules ***) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
133 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
134 |
(** Addition **) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
135 |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
136 |
Goal "[| m:nat; n:nat |] ==> raw_add (m, n) : nat"; |
6070 | 137 |
by (induct_tac "m" 1); |
138 |
by Auto_tac; |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
139 |
qed "raw_add_type"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
140 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
141 |
Goal "m #+ n : nat"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
142 |
by (simp_tac (simpset() addsimps [add_def, raw_add_type]) 1); |
6070 | 143 |
qed "add_type"; |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
144 |
AddIffs [add_type]; |
6153 | 145 |
AddTCs [add_type]; |
2469 | 146 |
|
0 | 147 |
(** Multiplication **) |
148 |
||
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
149 |
Goal "[| m:nat; n:nat |] ==> raw_mult (m, n) : nat"; |
6070 | 150 |
by (induct_tac "m" 1); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
151 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [raw_add_type]))); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
152 |
qed "raw_mult_type"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
153 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
154 |
Goal "m #* n : nat"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
155 |
by (simp_tac (simpset() addsimps [mult_def, raw_mult_type]) 1); |
6070 | 156 |
qed "mult_type"; |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
157 |
AddIffs [mult_type]; |
6153 | 158 |
AddTCs [mult_type]; |
0 | 159 |
|
2469 | 160 |
|
0 | 161 |
(** Difference **) |
162 |
||
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
163 |
Goal "[| m:nat; n:nat |] ==> raw_diff (m, n) : nat"; |
6070 | 164 |
by (induct_tac "n" 1); |
165 |
by Auto_tac; |
|
166 |
by (fast_tac (claset() addIs [nat_case_type]) 1); |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
167 |
qed "raw_diff_type"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
168 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
169 |
Goal "m #- n : nat"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
170 |
by (simp_tac (simpset() addsimps [diff_def, raw_diff_type]) 1); |
6070 | 171 |
qed "diff_type"; |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
172 |
AddIffs [diff_type]; |
6153 | 173 |
AddTCs [diff_type]; |
0 | 174 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
175 |
Goalw [diff_def] "0 #- n = 0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
176 |
by (rtac (natify_in_nat RS nat_induct) 1); |
6070 | 177 |
by Auto_tac; |
178 |
qed "diff_0_eq_0"; |
|
0 | 179 |
|
6070 | 180 |
(*Must simplify BEFORE the induction: else we get a critical pair*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
181 |
Goal "succ(m) #- succ(n) = m #- n"; |
9548 | 182 |
by (simp_tac (simpset() addsimps [natify_succ, diff_def]) 1); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
183 |
by (res_inst_tac [("x1","n")] (natify_in_nat RS nat_induct) 1); |
6070 | 184 |
by Auto_tac; |
185 |
qed "diff_succ_succ"; |
|
0 | 186 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
187 |
(*This defining property is no longer wanted*) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
188 |
Delsimps [raw_diff_succ]; |
2469 | 189 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
190 |
(*Natify has weakened this law, compared with the older approach*) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
191 |
Goal "m #- 0 = natify(m)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
192 |
by (asm_simp_tac (simpset() addsimps [diff_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
193 |
qed "diff_0"; |
0 | 194 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
195 |
Addsimps [diff_0, diff_0_eq_0, diff_succ_succ]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
196 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
197 |
Goal "m:nat ==> (m #- n) le m"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
198 |
by (subgoal_tac "(m #- natify(n)) le m" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
199 |
by (res_inst_tac [("m","m"), ("n","natify(n)")] diff_induct 2); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
200 |
by (etac leE 6); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
201 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [le_iff]))); |
760 | 202 |
qed "diff_le_self"; |
0 | 203 |
|
204 |
||
205 |
(*** Addition ***) |
|
206 |
||
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
207 |
(*Natify has weakened this law, compared with the older approach*) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
208 |
Goal "0 #+ m = natify(m)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
209 |
by (asm_simp_tac (simpset() addsimps [add_def]) 1); |
9548 | 210 |
qed "add_0_natify"; |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
211 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
212 |
Goal "succ(m) #+ n = succ(m #+ n)"; |
9548 | 213 |
by (asm_simp_tac (simpset() addsimps [natify_succ, add_def]) 1); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
214 |
qed "add_succ"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
215 |
|
9548 | 216 |
Addsimps [add_0_natify, add_succ]; |
217 |
||
218 |
Goal "m: nat ==> 0 #+ m = m"; |
|
219 |
by (Asm_simp_tac 1); |
|
220 |
qed "add_0"; |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
221 |
|
0 | 222 |
(*Associative law for addition*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
223 |
Goal "(m #+ n) #+ k = m #+ (n #+ k)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
224 |
by (subgoal_tac "(natify(m) #+ natify(n)) #+ natify(k) = \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
225 |
\ natify(m) #+ (natify(n) #+ natify(k))" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
226 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
6070 | 227 |
by Auto_tac; |
228 |
qed "add_assoc"; |
|
0 | 229 |
|
230 |
(*The following two lemmas are used for add_commute and sometimes |
|
231 |
elsewhere, since they are safe for rewriting.*) |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
232 |
Goal "m #+ 0 = natify(m)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
233 |
by (subgoal_tac "natify(m) #+ 0 = natify(m)" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
234 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
235 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
236 |
qed "add_0_right_natify"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
237 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
238 |
Goalw [add_def] "m #+ succ(n) = succ(m #+ n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
239 |
by (res_inst_tac [("n","natify(m)")] nat_induct 1); |
9548 | 240 |
by (auto_tac (claset(), simpset() addsimps [natify_succ])); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
241 |
qed "add_succ_right"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
242 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
243 |
Addsimps [add_0_right_natify, add_succ_right]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
244 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
245 |
Goal "m: nat ==> m #+ 0 = m"; |
6070 | 246 |
by Auto_tac; |
247 |
qed "add_0_right"; |
|
0 | 248 |
|
249 |
(*Commutative law for addition*) |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
250 |
Goal "m #+ n = n #+ m"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
251 |
by (subgoal_tac "natify(m) #+ natify(n) = natify(n) #+ natify(m)" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
252 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
6070 | 253 |
by Auto_tac; |
254 |
qed "add_commute"; |
|
435 | 255 |
|
437 | 256 |
(*for a/c rewriting*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
257 |
Goal "m#+(n#+k)=n#+(m#+k)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
258 |
by (rtac (add_commute RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
259 |
by (rtac (add_assoc RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
260 |
by (rtac (add_commute RS subst_context) 1); |
6070 | 261 |
qed "add_left_commute"; |
435 | 262 |
|
263 |
(*Addition is an AC-operator*) |
|
9907 | 264 |
bind_thms ("add_ac", [add_assoc, add_commute, add_left_commute]); |
0 | 265 |
|
266 |
(*Cancellation law on the left*) |
|
9492
72e429c66608
used natify with div and mod; also put in the divide-by-zero trick
paulson
parents:
9491
diff
changeset
|
267 |
Goal "[| raw_add(k, m) = raw_add(k, n); k:nat |] ==> m=n"; |
6070 | 268 |
by (etac rev_mp 1); |
269 |
by (induct_tac "k" 1); |
|
270 |
by Auto_tac; |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
271 |
qed "raw_add_left_cancel"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
272 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
273 |
Goalw [add_def] "k #+ m = k #+ n ==> natify(m) = natify(n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
274 |
by (dtac raw_add_left_cancel 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
275 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
276 |
qed "add_left_cancel_natify"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
277 |
|
9548 | 278 |
Goal "[| i = j; i #+ m = j #+ n; m:nat; n:nat |] ==> m = n"; |
279 |
by (force_tac (claset() addSDs [add_left_cancel_natify], simpset()) 1); |
|
760 | 280 |
qed "add_left_cancel"; |
0 | 281 |
|
9548 | 282 |
(*Thanks to Sten Agerholm*) |
283 |
Goal "k#+m le k#+n ==> natify(m) le natify(n)"; |
|
284 |
by (res_inst_tac [("P", "natify(k)#+m le natify(k)#+n")] rev_mp 1); |
|
285 |
by (res_inst_tac [("n","natify(k)")] nat_induct 2); |
|
286 |
by Auto_tac; |
|
287 |
qed "add_le_elim1_natify"; |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
288 |
|
9548 | 289 |
Goal "[| k#+m le k#+n; m: nat; n: nat |] ==> m le n"; |
290 |
by (dtac add_le_elim1_natify 1); |
|
291 |
by Auto_tac; |
|
292 |
qed "add_le_elim1"; |
|
293 |
||
294 |
Goal "k#+m < k#+n ==> natify(m) < natify(n)"; |
|
295 |
by (res_inst_tac [("P", "natify(k)#+m < natify(k)#+n")] rev_mp 1); |
|
296 |
by (res_inst_tac [("n","natify(k)")] nat_induct 2); |
|
297 |
by Auto_tac; |
|
298 |
qed "add_lt_elim1_natify"; |
|
299 |
||
300 |
Goal "[| k#+m < k#+n; m: nat; n: nat |] ==> m < n"; |
|
301 |
by (dtac add_lt_elim1_natify 1); |
|
302 |
by Auto_tac; |
|
303 |
qed "add_lt_elim1"; |
|
304 |
||
305 |
||
306 |
(*** Monotonicity of Addition ***) |
|
307 |
||
308 |
(*strict, in 1st argument; proof is by rule induction on 'less than'. |
|
309 |
Still need j:nat, for consider j = omega. Then we can have i<omega, |
|
310 |
which is the same as i:nat, but natify(j)=0, so the conclusion fails.*) |
|
311 |
Goal "[| i<j; j:nat |] ==> i#+k < j#+k"; |
|
312 |
by (ftac lt_nat_in_nat 1); |
|
313 |
by (assume_tac 1); |
|
314 |
by (etac succ_lt_induct 1); |
|
315 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [leI]))); |
|
316 |
qed "add_lt_mono1"; |
|
317 |
||
318 |
(*strict, in both arguments*) |
|
319 |
Goal "[| i<j; k<l; j:nat; l:nat |] ==> i#+k < j#+l"; |
|
320 |
by (rtac (add_lt_mono1 RS lt_trans) 1); |
|
321 |
by (REPEAT (assume_tac 1)); |
|
322 |
by (EVERY [stac add_commute 1, |
|
323 |
stac add_commute 1, |
|
324 |
rtac add_lt_mono1 1]); |
|
325 |
by (REPEAT (assume_tac 1)); |
|
326 |
qed "add_lt_mono"; |
|
327 |
||
328 |
(*A [clumsy] way of lifting < monotonicity to le monotonicity *) |
|
329 |
val lt_mono::ford::prems = Goal |
|
330 |
"[| !!i j. [| i<j; j:k |] ==> f(i) < f(j); \ |
|
331 |
\ !!i. i:k ==> Ord(f(i)); \ |
|
332 |
\ i le j; j:k \ |
|
333 |
\ |] ==> f(i) le f(j)"; |
|
334 |
by (cut_facts_tac prems 1); |
|
335 |
by (blast_tac (le_cs addSIs [lt_mono,ford] addSEs [leE]) 1); |
|
336 |
qed "Ord_lt_mono_imp_le_mono"; |
|
337 |
||
338 |
(*le monotonicity, 1st argument*) |
|
339 |
Goal "[| i le j; j:nat |] ==> i#+k le j#+k"; |
|
340 |
by (res_inst_tac [("f", "%j. j#+k")] Ord_lt_mono_imp_le_mono 1); |
|
341 |
by (REPEAT (ares_tac [add_lt_mono1, add_type RS nat_into_Ord] 1)); |
|
342 |
qed "add_le_mono1"; |
|
343 |
||
344 |
(* le monotonicity, BOTH arguments*) |
|
345 |
Goal "[| i le j; k le l; j:nat; l:nat |] ==> i#+k le j#+l"; |
|
346 |
by (rtac (add_le_mono1 RS le_trans) 1); |
|
347 |
by (REPEAT (assume_tac 1)); |
|
348 |
by (EVERY [stac add_commute 1, |
|
349 |
stac add_commute 1, |
|
350 |
rtac add_le_mono1 1]); |
|
351 |
by (REPEAT (assume_tac 1)); |
|
352 |
qed "add_le_mono"; |
|
353 |
||
354 |
(** Subtraction is the inverse of addition. **) |
|
355 |
||
356 |
Goal "(n#+m) #- n = natify(m)"; |
|
357 |
by (subgoal_tac "(natify(n) #+ m) #- natify(n) = natify(m)" 1); |
|
358 |
by (res_inst_tac [("n","natify(n)")] nat_induct 2); |
|
359 |
by Auto_tac; |
|
360 |
qed "diff_add_inverse"; |
|
361 |
||
362 |
Goal "(m#+n) #- n = natify(m)"; |
|
363 |
by (simp_tac (simpset() addsimps [inst "m" "m" add_commute, |
|
364 |
diff_add_inverse]) 1); |
|
365 |
qed "diff_add_inverse2"; |
|
366 |
||
367 |
Goal "(k#+m) #- (k#+n) = m #- n"; |
|
368 |
by (subgoal_tac "(natify(k) #+ natify(m)) #- (natify(k) #+ natify(n)) = \ |
|
369 |
\ natify(m) #- natify(n)" 1); |
|
370 |
by (res_inst_tac [("n","natify(k)")] nat_induct 2); |
|
371 |
by Auto_tac; |
|
372 |
qed "diff_cancel"; |
|
373 |
||
374 |
Goal "(m#+k) #- (n#+k) = m #- n"; |
|
375 |
by (simp_tac (simpset() addsimps [inst "n" "k" add_commute, diff_cancel]) 1); |
|
376 |
qed "diff_cancel2"; |
|
377 |
||
378 |
Goal "n #- (n#+m) = 0"; |
|
379 |
by (subgoal_tac "natify(n) #- (natify(n) #+ natify(m)) = 0" 1); |
|
380 |
by (res_inst_tac [("n","natify(n)")] nat_induct 2); |
|
381 |
by Auto_tac; |
|
382 |
qed "diff_add_0"; |
|
383 |
||
384 |
||
385 |
(** Lemmas for the CancelNumerals simproc **) |
|
386 |
||
387 |
Goal "(u #+ m = u #+ n) <-> (0 #+ m = natify(n))"; |
|
388 |
by Auto_tac; |
|
389 |
by (blast_tac (claset() addDs [add_left_cancel_natify]) 1); |
|
390 |
by (asm_full_simp_tac (simpset() addsimps [add_def]) 1); |
|
391 |
qed "eq_add_iff"; |
|
392 |
||
393 |
Goal "(u #+ m < u #+ n) <-> (0 #+ m < natify(n))"; |
|
394 |
by (auto_tac (claset(), simpset() addsimps [add_lt_elim1_natify])); |
|
395 |
by (dtac add_lt_mono1 1); |
|
396 |
by (auto_tac (claset(), simpset() addsimps [inst "m" "u" add_commute])); |
|
397 |
qed "less_add_iff"; |
|
398 |
||
399 |
Goal "((u #+ m) #- (u #+ n)) = ((0 #+ m) #- n)"; |
|
400 |
by (asm_simp_tac (simpset() addsimps [diff_cancel]) 1); |
|
401 |
qed "diff_add_eq"; |
|
402 |
||
403 |
(*To tidy up the result of a simproc. Only the RHS will be simplified.*) |
|
404 |
Goal "u = u' ==> (t==u) == (t==u')"; |
|
405 |
by Auto_tac; |
|
406 |
qed "eq_cong2"; |
|
407 |
||
408 |
Goal "u <-> u' ==> (t==u) == (t==u')"; |
|
409 |
by Auto_tac; |
|
410 |
qed "iff_cong2"; |
|
411 |
||
412 |
||
413 |
(*** Multiplication [the simprocs need these laws] ***) |
|
0 | 414 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
415 |
Goal "0 #* m = 0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
416 |
by (simp_tac (simpset() addsimps [mult_def]) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
417 |
qed "mult_0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
418 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
419 |
Goal "succ(m) #* n = n #+ (m #* n)"; |
9548 | 420 |
by (simp_tac (simpset() addsimps [add_def, mult_def, natify_succ, |
421 |
raw_mult_type]) 1); |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
422 |
qed "mult_succ"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
423 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
424 |
Addsimps [mult_0, mult_succ]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
425 |
|
0 | 426 |
(*right annihilation in product*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
427 |
Goalw [mult_def] "m #* 0 = 0"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
428 |
by (res_inst_tac [("n","natify(m)")] nat_induct 1); |
6070 | 429 |
by Auto_tac; |
430 |
qed "mult_0_right"; |
|
0 | 431 |
|
432 |
(*right successor law for multiplication*) |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
433 |
Goal "m #* succ(n) = m #+ (m #* n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
434 |
by (subgoal_tac "natify(m) #* succ(natify(n)) = \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
435 |
\ natify(m) #+ (natify(m) #* natify(n))" 1); |
9548 | 436 |
by (full_simp_tac (simpset() addsimps [natify_succ, add_def, mult_def]) 1); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
437 |
by (res_inst_tac [("n","natify(m)")] nat_induct 1); |
6070 | 438 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps add_ac))); |
439 |
qed "mult_succ_right"; |
|
2469 | 440 |
|
441 |
Addsimps [mult_0_right, mult_succ_right]; |
|
0 | 442 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
443 |
Goal "1 #* n = natify(n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
444 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
445 |
qed "mult_1_natify"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
446 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
447 |
Goal "n #* 1 = natify(n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
448 |
by Auto_tac; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
449 |
qed "mult_1_right_natify"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
450 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
451 |
Addsimps [mult_1_natify, mult_1_right_natify]; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
452 |
|
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
453 |
Goal "n : nat ==> 1 #* n = n"; |
2469 | 454 |
by (Asm_simp_tac 1); |
1793 | 455 |
qed "mult_1"; |
456 |
||
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
457 |
Goal "n : nat ==> n #* 1 = n"; |
2469 | 458 |
by (Asm_simp_tac 1); |
1793 | 459 |
qed "mult_1_right"; |
460 |
||
0 | 461 |
(*Commutative law for multiplication*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
462 |
Goal "m #* n = n #* m"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
463 |
by (subgoal_tac "natify(m) #* natify(n) = natify(n) #* natify(m)" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
464 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
6070 | 465 |
by Auto_tac; |
466 |
qed "mult_commute"; |
|
0 | 467 |
|
468 |
(*addition distributes over multiplication*) |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
469 |
Goal "(m #+ n) #* k = (m #* k) #+ (n #* k)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
470 |
by (subgoal_tac "(natify(m) #+ natify(n)) #* natify(k) = \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
471 |
\ (natify(m) #* natify(k)) #+ (natify(n) #* natify(k))" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
472 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
473 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_assoc RS sym]))); |
6070 | 474 |
qed "add_mult_distrib"; |
0 | 475 |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
476 |
(*Distributive law on the left*) |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
477 |
Goal "k #* (m #+ n) = (k #* m) #+ (k #* n)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
478 |
by (subgoal_tac "natify(k) #* (natify(m) #+ natify(n)) = \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
479 |
\ (natify(k) #* natify(m)) #+ (natify(k) #* natify(n))" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
480 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
481 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps add_ac))); |
6070 | 482 |
qed "add_mult_distrib_left"; |
0 | 483 |
|
484 |
(*Associative law for multiplication*) |
|
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
485 |
Goal "(m #* n) #* k = m #* (n #* k)"; |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
486 |
by (subgoal_tac "(natify(m) #* natify(n)) #* natify(k) = \ |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
487 |
\ natify(m) #* (natify(n) #* natify(k))" 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
488 |
by (res_inst_tac [("n","natify(m)")] nat_induct 2); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
489 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_mult_distrib]))); |
6070 | 490 |
qed "mult_assoc"; |
0 | 491 |
|
437 | 492 |
(*for a/c rewriting*) |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
493 |
Goal "m #* (n #* k) = n #* (m #* k)"; |
6070 | 494 |
by (rtac (mult_commute RS trans) 1); |
9491
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
495 |
by (rtac (mult_assoc RS trans) 1); |
1a36151ee2fc
natify, a coercion to reduce the number of type constraints in arithmetic
paulson
parents:
9301
diff
changeset
|
496 |
by (rtac (mult_commute RS subst_context) 1); |
6070 | 497 |
qed "mult_left_commute"; |
437 | 498 |
|
9907 | 499 |
bind_thms ("mult_ac", [mult_assoc,mult_commute,mult_left_commute]); |