| author | paulson |
| Thu, 26 Aug 1999 11:34:17 +0200 | |
| changeset 7360 | 7d3136b9af08 |
| parent 7074 | e0730ffaafcc |
| child 7517 | bad2f36810e1 |
| permissions | -rw-r--r-- |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
1 |
(* Title: HOL/Integ/Bin.ML |
|
7074
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
2 |
ID: $Id$ |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
3 |
Authors: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
4 |
David Spelt, University of Twente |
| 6060 | 5 |
Tobias Nipkow, Technical University Munich |
| 1632 | 6 |
Copyright 1994 University of Cambridge |
| 6060 | 7 |
Copyright 1996 University of Twente |
8 |
Copyright 1999 TU Munich |
|
| 1632 | 9 |
|
| 6060 | 10 |
Arithmetic on binary integers; |
11 |
decision procedure for linear arithmetic. |
|
| 1632 | 12 |
*) |
13 |
||
14 |
(** extra rules for bin_succ, bin_pred, bin_add, bin_mult **) |
|
15 |
||
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
16 |
Goal "NCons Pls False = Pls"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
17 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
18 |
qed "NCons_Pls_0"; |
| 1632 | 19 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
20 |
Goal "NCons Pls True = Pls BIT True"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
21 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
22 |
qed "NCons_Pls_1"; |
| 1632 | 23 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
24 |
Goal "NCons Min False = Min BIT False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
25 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
26 |
qed "NCons_Min_0"; |
| 1632 | 27 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
28 |
Goal "NCons Min True = Min"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
29 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
30 |
qed "NCons_Min_1"; |
| 1632 | 31 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
32 |
Goal "bin_succ(w BIT True) = (bin_succ w) BIT False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
33 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
34 |
qed "bin_succ_1"; |
| 1632 | 35 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
36 |
Goal "bin_succ(w BIT False) = NCons w True"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
37 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
38 |
qed "bin_succ_0"; |
| 1632 | 39 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
40 |
Goal "bin_pred(w BIT True) = NCons w False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
41 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
42 |
qed "bin_pred_1"; |
| 1632 | 43 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
44 |
Goal "bin_pred(w BIT False) = (bin_pred w) BIT True"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
45 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
46 |
qed "bin_pred_0"; |
| 1632 | 47 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
48 |
Goal "bin_minus(w BIT True) = bin_pred (NCons (bin_minus w) False)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
49 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
50 |
qed "bin_minus_1"; |
| 1632 | 51 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
52 |
Goal "bin_minus(w BIT False) = (bin_minus w) BIT False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
53 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
54 |
qed "bin_minus_0"; |
| 1632 | 55 |
|
| 5491 | 56 |
|
| 1632 | 57 |
(*** bin_add: binary addition ***) |
58 |
||
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
59 |
Goal "bin_add (v BIT True) (w BIT True) = \ |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
60 |
\ NCons (bin_add v (bin_succ w)) False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
61 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
62 |
qed "bin_add_BIT_11"; |
| 1632 | 63 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
64 |
Goal "bin_add (v BIT True) (w BIT False) = NCons (bin_add v w) True"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
65 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
66 |
qed "bin_add_BIT_10"; |
| 1632 | 67 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
68 |
Goal "bin_add (v BIT False) (w BIT y) = NCons (bin_add v w) y"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
69 |
by Auto_tac; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
70 |
qed "bin_add_BIT_0"; |
| 1632 | 71 |
|
| 5551 | 72 |
Goal "bin_add w Pls = w"; |
73 |
by (induct_tac "w" 1); |
|
74 |
by Auto_tac; |
|
75 |
qed "bin_add_Pls_right"; |
|
| 1632 | 76 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
77 |
Goal "bin_add (v BIT x) Min = bin_pred (v BIT x)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
78 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
79 |
qed "bin_add_BIT_Min"; |
| 1632 | 80 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
81 |
Goal "bin_add (v BIT x) (w BIT y) = \ |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
82 |
\ NCons(bin_add v (if x & y then (bin_succ w) else w)) (x~= y)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
83 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
84 |
qed "bin_add_BIT_BIT"; |
| 1632 | 85 |
|
86 |
||
| 6036 | 87 |
(*** bin_mult: binary multiplication ***) |
| 1632 | 88 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
89 |
Goal "bin_mult (v BIT True) w = bin_add (NCons (bin_mult v w) False) w"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
90 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
91 |
qed "bin_mult_1"; |
| 1632 | 92 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
93 |
Goal "bin_mult (v BIT False) w = NCons (bin_mult v w) False"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
94 |
by (Simp_tac 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
95 |
qed "bin_mult_0"; |
| 1632 | 96 |
|
97 |
||
98 |
(**** The carry/borrow functions, bin_succ and bin_pred ****) |
|
99 |
||
100 |
||
| 6910 | 101 |
(**** number_of ****) |
| 1632 | 102 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
103 |
Goal "number_of(NCons w b) = (number_of(w BIT b)::int)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
104 |
by (induct_tac "w" 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
105 |
by (ALLGOALS Asm_simp_tac); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
106 |
qed "number_of_NCons"; |
| 1632 | 107 |
|
| 6910 | 108 |
Addsimps [number_of_NCons]; |
| 1632 | 109 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
110 |
Goal "number_of(bin_succ w) = int 1 + number_of w"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
111 |
by (induct_tac "w" 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
112 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac))); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
113 |
qed "number_of_succ"; |
| 5491 | 114 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
115 |
Goal "number_of(bin_pred w) = - (int 1) + number_of w"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
116 |
by (induct_tac "w" 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
117 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac))); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
118 |
qed "number_of_pred"; |
| 1632 | 119 |
|
| 6910 | 120 |
Goal "number_of(bin_minus w) = (- (number_of w)::int)"; |
121 |
by (induct_tac "w" 1); |
|
| 5491 | 122 |
by (Simp_tac 1); |
123 |
by (Simp_tac 1); |
|
124 |
by (asm_simp_tac (simpset() |
|
| 5551 | 125 |
delsimps [bin_pred_Pls, bin_pred_Min, bin_pred_BIT] |
| 6910 | 126 |
addsimps [number_of_succ,number_of_pred, |
| 5491 | 127 |
zadd_assoc]) 1); |
| 6910 | 128 |
qed "number_of_minus"; |
| 1632 | 129 |
|
130 |
||
| 6910 | 131 |
val bin_add_simps = [bin_add_BIT_BIT, number_of_succ, number_of_pred]; |
| 1632 | 132 |
|
| 6036 | 133 |
(*This proof is complicated by the mutual recursion*) |
| 6910 | 134 |
Goal "! w. number_of(bin_add v w) = (number_of v + number_of w::int)"; |
| 5184 | 135 |
by (induct_tac "v" 1); |
| 4686 | 136 |
by (simp_tac (simpset() addsimps bin_add_simps) 1); |
137 |
by (simp_tac (simpset() addsimps bin_add_simps) 1); |
|
| 1632 | 138 |
by (rtac allI 1); |
| 5184 | 139 |
by (induct_tac "w" 1); |
| 5540 | 140 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps bin_add_simps @ zadd_ac))); |
| 6910 | 141 |
qed_spec_mp "number_of_add"; |
| 1632 | 142 |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
143 |
|
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
144 |
(*Subtraction*) |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
145 |
Goalw [zdiff_def] |
| 6910 | 146 |
"number_of v - number_of w = (number_of(bin_add v (bin_minus w))::int)"; |
147 |
by (simp_tac (simpset() addsimps [number_of_add, number_of_minus]) 1); |
|
148 |
qed "diff_number_of_eq"; |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
149 |
|
| 6910 | 150 |
val bin_mult_simps = [zmult_zminus, number_of_minus, number_of_add]; |
| 1632 | 151 |
|
| 6910 | 152 |
Goal "number_of(bin_mult v w) = (number_of v * number_of w::int)"; |
| 5184 | 153 |
by (induct_tac "v" 1); |
| 4686 | 154 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
155 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
|
| 5491 | 156 |
by (asm_simp_tac |
| 5540 | 157 |
(simpset() addsimps bin_mult_simps @ [zadd_zmult_distrib] @ zadd_ac) 1); |
| 6910 | 158 |
qed "number_of_mult"; |
| 5491 | 159 |
|
| 1632 | 160 |
|
| 6941 | 161 |
(*The correctness of shifting. But it doesn't seem to give a measurable |
162 |
speed-up.*) |
|
163 |
Goal "(#2::int) * number_of w = number_of (w BIT False)"; |
|
164 |
by (induct_tac "w" 1); |
|
165 |
by (ALLGOALS (asm_simp_tac |
|
166 |
(simpset() addsimps bin_mult_simps @ [zadd_zmult_distrib] @ zadd_ac))); |
|
167 |
qed "double_number_of_BIT"; |
|
168 |
||
169 |
||
| 5491 | 170 |
(** Simplification rules with integer constants **) |
171 |
||
| 6910 | 172 |
Goal "#0 + z = (z::int)"; |
| 5491 | 173 |
by (Simp_tac 1); |
174 |
qed "zadd_0"; |
|
175 |
||
| 6910 | 176 |
Goal "z + #0 = (z::int)"; |
| 5491 | 177 |
by (Simp_tac 1); |
178 |
qed "zadd_0_right"; |
|
179 |
||
| 5592 | 180 |
Addsimps [zadd_0, zadd_0_right]; |
181 |
||
182 |
||
183 |
(** Converting simple cases of (int n) to numerals **) |
|
| 5491 | 184 |
|
| 5592 | 185 |
(*int 0 = #0 *) |
| 6910 | 186 |
bind_thm ("int_0", number_of_Pls RS sym);
|
| 5491 | 187 |
|
| 5592 | 188 |
Goal "int (Suc n) = #1 + int n"; |
189 |
by (simp_tac (simpset() addsimps [zadd_int]) 1); |
|
190 |
qed "int_Suc"; |
|
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
191 |
|
| 6910 | 192 |
Goal "- (#0) = (#0::int)"; |
| 5491 | 193 |
by (Simp_tac 1); |
194 |
qed "zminus_0"; |
|
195 |
||
196 |
Addsimps [zminus_0]; |
|
197 |
||
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
198 |
|
| 6910 | 199 |
Goal "(#0::int) - x = -x"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
200 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
201 |
qed "zdiff0"; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
202 |
|
| 6910 | 203 |
Goal "x - (#0::int) = x"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
204 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
205 |
qed "zdiff0_right"; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
206 |
|
| 6910 | 207 |
Goal "x - x = (#0::int)"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
208 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
209 |
qed "zdiff_self"; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
210 |
|
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
211 |
Addsimps [zdiff0, zdiff0_right, zdiff_self]; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
212 |
|
| 6917 | 213 |
|
214 |
(** Special simplification, for constants only **) |
|
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
215 |
|
| 6917 | 216 |
fun inst x t = read_instantiate_sg (sign_of Bin.thy) [(x,t)]; |
217 |
||
|
7074
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
218 |
(*Distributive laws for literals*) |
| 6917 | 219 |
Addsimps (map (inst "w" "number_of ?v") |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
220 |
[zadd_zmult_distrib, zadd_zmult_distrib2, |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
221 |
zdiff_zmult_distrib, zdiff_zmult_distrib2]); |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
222 |
|
| 6917 | 223 |
Addsimps (map (inst "x" "number_of ?v") |
224 |
[zless_zminus, zle_zminus, equation_zminus]); |
|
225 |
Addsimps (map (inst "y" "number_of ?v") |
|
226 |
[zminus_zless, zminus_zle, zminus_equation]); |
|
227 |
||
|
7074
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
228 |
(*Moving negation out of products*) |
|
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
229 |
Addsimps [zmult_zminus, zmult_zminus_right]; |
| 6917 | 230 |
|
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
231 |
(** Special-case simplification for small constants **) |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
232 |
|
| 6910 | 233 |
Goal "#0 * z = (#0::int)"; |
| 5491 | 234 |
by (Simp_tac 1); |
235 |
qed "zmult_0"; |
|
236 |
||
| 6910 | 237 |
Goal "z * #0 = (#0::int)"; |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
238 |
by (Simp_tac 1); |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
239 |
qed "zmult_0_right"; |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
240 |
|
| 6910 | 241 |
Goal "#1 * z = (z::int)"; |
| 5491 | 242 |
by (Simp_tac 1); |
243 |
qed "zmult_1"; |
|
244 |
||
| 6910 | 245 |
Goal "z * #1 = (z::int)"; |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
246 |
by (Simp_tac 1); |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
247 |
qed "zmult_1_right"; |
|
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
248 |
|
| 6917 | 249 |
Goal "#-1 * z = -(z::int)"; |
250 |
by (simp_tac (simpset() addsimps zcompare_rls@[zmult_zminus]) 1); |
|
251 |
qed "zmult_minus1"; |
|
252 |
||
253 |
Goal "z * #-1 = -(z::int)"; |
|
254 |
by (simp_tac (simpset() addsimps zcompare_rls@[zmult_zminus_right]) 1); |
|
255 |
qed "zmult_minus1_right"; |
|
256 |
||
257 |
Addsimps [zmult_0, zmult_0_right, |
|
258 |
zmult_1, zmult_1_right, |
|
259 |
zmult_minus1, zmult_minus1_right]; |
|
260 |
||
261 |
(*For specialist use: NOT as default simprules*) |
|
| 6910 | 262 |
Goal "#2 * z = (z+z::int)"; |
| 5491 | 263 |
by (simp_tac (simpset() addsimps [zadd_zmult_distrib]) 1); |
264 |
qed "zmult_2"; |
|
265 |
||
| 6910 | 266 |
Goal "z * #2 = (z+z::int)"; |
| 5491 | 267 |
by (simp_tac (simpset() addsimps [zadd_zmult_distrib2]) 1); |
268 |
qed "zmult_2_right"; |
|
269 |
||
| 6917 | 270 |
|
271 |
(** Inequality reasoning **) |
|
| 5491 | 272 |
|
| 6989 | 273 |
Goal "(m*n = (#0::int)) = (m = #0 | n = #0)"; |
274 |
by (stac (int_0 RS sym) 1 THEN rtac zmult_eq_int0_iff 1); |
|
275 |
qed "zmult_eq_0_iff"; |
|
276 |
||
| 6910 | 277 |
Goal "(w < z + (#1::int)) = (w<z | w=z)"; |
| 5592 | 278 |
by (simp_tac (simpset() addsimps [zless_add_int_Suc_eq]) 1); |
| 5491 | 279 |
qed "zless_add1_eq"; |
280 |
||
| 6910 | 281 |
Goal "(w + (#1::int) <= z) = (w<z)"; |
| 5592 | 282 |
by (simp_tac (simpset() addsimps [add_int_Suc_zle_eq]) 1); |
| 5491 | 283 |
qed "add1_zle_eq"; |
| 6997 | 284 |
|
285 |
Goal "((#1::int) + w <= z) = (w<z)"; |
|
286 |
by (stac zadd_commute 1); |
|
287 |
by (rtac add1_zle_eq 1); |
|
288 |
qed "add1_left_zle_eq"; |
|
| 5491 | 289 |
|
| 5540 | 290 |
Goal "neg x = (x < #0)"; |
| 6917 | 291 |
by (simp_tac (simpset() addsimps [neg_eq_less_int0]) 1); |
| 5540 | 292 |
qed "neg_eq_less_0"; |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
293 |
|
| 6989 | 294 |
Goal "(~neg x) = (#0 <= x)"; |
| 6917 | 295 |
by (simp_tac (simpset() addsimps [not_neg_eq_ge_int0]) 1); |
| 5540 | 296 |
qed "not_neg_eq_ge_0"; |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
297 |
|
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
298 |
Goal "#0 <= int m"; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
299 |
by (Simp_tac 1); |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
300 |
qed "zero_zle_int"; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
301 |
AddIffs [zero_zle_int]; |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
302 |
|
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
303 |
|
| 5747 | 304 |
(** Needed because (int 0) rewrites to #0. |
305 |
Can these be generalized without evaluating large numbers?**) |
|
306 |
||
307 |
Goal "~ (int k < #0)"; |
|
308 |
by (Simp_tac 1); |
|
309 |
qed "int_less_0_conv"; |
|
310 |
||
311 |
Goal "(int k <= #0) = (k=0)"; |
|
312 |
by (Simp_tac 1); |
|
313 |
qed "int_le_0_conv"; |
|
314 |
||
315 |
Goal "(int k = #0) = (k=0)"; |
|
316 |
by (Simp_tac 1); |
|
317 |
qed "int_eq_0_conv"; |
|
318 |
||
319 |
Goal "(#0 = int k) = (k=0)"; |
|
320 |
by Auto_tac; |
|
321 |
qed "int_eq_0_conv'"; |
|
322 |
||
323 |
Addsimps [int_less_0_conv, int_le_0_conv, int_eq_0_conv, int_eq_0_conv']; |
|
324 |
||
325 |
||
| 5491 | 326 |
(** Simplification rules for comparison of binary numbers (Norbert Voelker) **) |
327 |
||
328 |
(** Equals (=) **) |
|
| 1632 | 329 |
|
| 5491 | 330 |
Goalw [iszero_def] |
| 6997 | 331 |
"((number_of x::int) = number_of y) = \ |
332 |
\ iszero (number_of (bin_add x (bin_minus y)))"; |
|
| 5491 | 333 |
by (simp_tac (simpset() addsimps |
| 6910 | 334 |
(zcompare_rls @ [number_of_add, number_of_minus])) 1); |
335 |
qed "eq_number_of_eq"; |
|
| 5491 | 336 |
|
| 6910 | 337 |
Goalw [iszero_def] "iszero ((number_of Pls)::int)"; |
| 5491 | 338 |
by (Simp_tac 1); |
| 6910 | 339 |
qed "iszero_number_of_Pls"; |
| 5491 | 340 |
|
| 6910 | 341 |
Goalw [iszero_def] "~ iszero ((number_of Min)::int)"; |
| 5491 | 342 |
by (Simp_tac 1); |
| 6910 | 343 |
qed "nonzero_number_of_Min"; |
| 5491 | 344 |
|
345 |
Goalw [iszero_def] |
|
| 6910 | 346 |
"iszero (number_of (w BIT x)) = (~x & iszero (number_of w::int))"; |
| 5491 | 347 |
by (Simp_tac 1); |
| 6910 | 348 |
by (int_case_tac "number_of w" 1); |
| 5491 | 349 |
by (ALLGOALS (asm_simp_tac |
| 5540 | 350 |
(simpset() addsimps zcompare_rls @ |
351 |
[zminus_zadd_distrib RS sym, |
|
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
352 |
zadd_int]))); |
| 6910 | 353 |
qed "iszero_number_of_BIT"; |
| 5491 | 354 |
|
| 6910 | 355 |
Goal "iszero (number_of (w BIT False)) = iszero (number_of w::int)"; |
356 |
by (simp_tac (HOL_ss addsimps [iszero_number_of_BIT]) 1); |
|
357 |
qed "iszero_number_of_0"; |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
358 |
|
| 6910 | 359 |
Goal "~ iszero (number_of (w BIT True)::int)"; |
360 |
by (simp_tac (HOL_ss addsimps [iszero_number_of_BIT]) 1); |
|
361 |
qed "iszero_number_of_1"; |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
362 |
|
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
363 |
|
| 5491 | 364 |
|
365 |
(** Less-than (<) **) |
|
366 |
||
367 |
Goalw [zless_def,zdiff_def] |
|
| 6910 | 368 |
"(number_of x::int) < number_of y \ |
369 |
\ = neg (number_of (bin_add x (bin_minus y)))"; |
|
| 5491 | 370 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
| 6910 | 371 |
qed "less_number_of_eq_neg"; |
| 5491 | 372 |
|
| 6910 | 373 |
Goal "~ neg (number_of Pls)"; |
| 5491 | 374 |
by (Simp_tac 1); |
| 6910 | 375 |
qed "not_neg_number_of_Pls"; |
| 5491 | 376 |
|
| 6910 | 377 |
Goal "neg (number_of Min)"; |
| 5491 | 378 |
by (Simp_tac 1); |
| 6910 | 379 |
qed "neg_number_of_Min"; |
| 5491 | 380 |
|
| 6910 | 381 |
Goal "neg (number_of (w BIT x)) = neg (number_of w)"; |
| 5491 | 382 |
by (Asm_simp_tac 1); |
| 6910 | 383 |
by (int_case_tac "number_of w" 1); |
| 5491 | 384 |
by (ALLGOALS (asm_simp_tac |
| 6917 | 385 |
(simpset() addsimps [zadd_int, neg_eq_less_int0, |
| 5540 | 386 |
symmetric zdiff_def] @ zcompare_rls))); |
| 6910 | 387 |
qed "neg_number_of_BIT"; |
| 5491 | 388 |
|
389 |
||
390 |
(** Less-than-or-equals (<=) **) |
|
391 |
||
| 7033 | 392 |
Goal "(number_of x <= (number_of y::int)) = \ |
393 |
\ (~ number_of y < (number_of x::int))"; |
|
394 |
by (rtac (linorder_not_less RS sym) 1); |
|
| 6910 | 395 |
qed "le_number_of_eq_not_less"; |
| 5491 | 396 |
|
| 5540 | 397 |
(*Delete the original rewrites, with their clumsy conditional expressions*) |
| 5551 | 398 |
Delsimps [bin_succ_BIT, bin_pred_BIT, bin_minus_BIT, |
399 |
NCons_Pls, NCons_Min, bin_add_BIT, bin_mult_BIT]; |
|
| 5491 | 400 |
|
401 |
(*Hide the binary representation of integer constants*) |
|
| 6910 | 402 |
Delsimps [number_of_Pls, number_of_Min, number_of_BIT]; |
| 5491 | 403 |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
404 |
(*simplification of arithmetic operations on integer constants*) |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
405 |
val bin_arith_extra_simps = |
| 6910 | 406 |
[number_of_add RS sym, |
407 |
number_of_minus RS sym, |
|
408 |
number_of_mult RS sym, |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
409 |
bin_succ_1, bin_succ_0, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
410 |
bin_pred_1, bin_pred_0, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
411 |
bin_minus_1, bin_minus_0, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
412 |
bin_add_Pls_right, bin_add_BIT_Min, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
413 |
bin_add_BIT_0, bin_add_BIT_10, bin_add_BIT_11, |
| 6910 | 414 |
diff_number_of_eq, |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
415 |
bin_mult_1, bin_mult_0, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
416 |
NCons_Pls_0, NCons_Pls_1, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
417 |
NCons_Min_0, NCons_Min_1, NCons_BIT]; |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
418 |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
419 |
(*For making a minimal simpset, one must include these default simprules |
| 6910 | 420 |
of thy. Also include simp_thms, or at least (~False)=True*) |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
421 |
val bin_arith_simps = |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
422 |
[bin_pred_Pls, bin_pred_Min, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
423 |
bin_succ_Pls, bin_succ_Min, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
424 |
bin_add_Pls, bin_add_Min, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
425 |
bin_minus_Pls, bin_minus_Min, |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
426 |
bin_mult_Pls, bin_mult_Min] @ bin_arith_extra_simps; |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
427 |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
428 |
(*Simplification of relational operations*) |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
429 |
val bin_rel_simps = |
| 6910 | 430 |
[eq_number_of_eq, iszero_number_of_Pls, nonzero_number_of_Min, |
431 |
iszero_number_of_0, iszero_number_of_1, |
|
432 |
less_number_of_eq_neg, |
|
433 |
not_neg_number_of_Pls, neg_number_of_Min, neg_number_of_BIT, |
|
434 |
le_number_of_eq_not_less]; |
|
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
435 |
|
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
436 |
Addsimps bin_arith_extra_simps; |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
437 |
Addsimps bin_rel_simps; |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
438 |
|
| 6997 | 439 |
|
440 |
(** Constant folding inside parentheses **) |
|
441 |
||
442 |
Goal "number_of v + (number_of w + c) = number_of(bin_add v w) + (c::int)"; |
|
443 |
by (stac (zadd_assoc RS sym) 1); |
|
444 |
by (stac number_of_add 1); |
|
445 |
by Auto_tac; |
|
446 |
qed "nested_number_of_add"; |
|
447 |
||
448 |
Goalw [zdiff_def] |
|
449 |
"number_of v + (number_of w - c) = number_of(bin_add v w) - (c::int)"; |
|
450 |
by (rtac nested_number_of_add 1); |
|
451 |
qed "nested_diff1_number_of_add"; |
|
452 |
||
453 |
Goal "number_of v + (c - number_of w) = \ |
|
454 |
\ number_of (bin_add v (bin_minus w)) + (c::int)"; |
|
455 |
by (stac (diff_number_of_eq RS sym) 1); |
|
456 |
by Auto_tac; |
|
457 |
qed "nested_diff2_number_of_add"; |
|
458 |
||
459 |
Goal "number_of v * (number_of w * c) = number_of(bin_mult v w) * (c::int)"; |
|
460 |
by (stac (zmult_assoc RS sym) 1); |
|
461 |
by (stac number_of_mult 1); |
|
462 |
by Auto_tac; |
|
463 |
qed "nested_number_of_mult"; |
|
464 |
Addsimps [nested_number_of_add, nested_diff1_number_of_add, |
|
465 |
nested_diff2_number_of_add, nested_number_of_mult]; |
|
466 |
||
467 |
||
468 |
||
| 6060 | 469 |
(*---------------------------------------------------------------------------*) |
470 |
(* Linear arithmetic *) |
|
471 |
(*---------------------------------------------------------------------------*) |
|
472 |
||
473 |
(* |
|
474 |
Instantiation of the generic linear arithmetic package for int. |
|
475 |
FIXME: multiplication with constants (eg #2 * i) does not work yet. |
|
476 |
Solution: the cancellation simprocs in Int_Cancel should be able to deal with |
|
477 |
it (eg simplify #3 * i <= 2 * i to i <= #0) or `add_rules' below should |
|
478 |
include rules for turning multiplication with constants into addition. |
|
479 |
(The latter option is very inefficient!) |
|
480 |
*) |
|
481 |
||
| 6128 | 482 |
structure Int_LA_Data(*: LIN_ARITH_DATA*) = |
| 6060 | 483 |
struct |
| 6101 | 484 |
|
| 6128 | 485 |
val lessD = Nat_LA_Data.lessD @ [add1_zle_eq RS iffD2]; |
| 6060 | 486 |
|
487 |
fun add_atom(t,m,(p,i)) = (case assoc(p,t) of None => ((t,m)::p,i) |
|
488 |
| Some n => (overwrite(p,(t,n+m:int)), i)); |
|
489 |
||
490 |
(* Turn term into list of summand * multiplicity plus a constant *) |
|
491 |
fun poly(Const("op +",_) $ s $ t, m, pi) = poly(s,m,poly(t,m,pi))
|
|
492 |
| poly(Const("op -",_) $ s $ t, m, pi) = poly(s,m,poly(t,~1*m,pi))
|
|
493 |
| poly(Const("uminus",_) $ t, m, pi) = poly(t,~1*m,pi)
|
|
| 6910 | 494 |
| poly(all as Const("op *",_) $ (Const("Numeral.number_of",_)$c) $ t, m, pi) =
|
495 |
(poly(t,m*NumeralSyntax.dest_bin c,pi) handle Match => add_atom(all,m,pi)) |
|
496 |
| poly(all as Const("Numeral.number_of",_)$t,m,(p,i)) =
|
|
497 |
((p,i + m*NumeralSyntax.dest_bin t) handle Match => add_atom(all,m,(p,i))) |
|
| 6060 | 498 |
| poly x = add_atom x; |
499 |
||
| 6128 | 500 |
fun decomp2(rel,lhs,rhs) = |
| 6060 | 501 |
let val (p,i) = poly(lhs,1,([],0)) and (q,j) = poly(rhs,1,([],0)) |
502 |
in case rel of |
|
503 |
"op <" => Some(p,i,"<",q,j) |
|
504 |
| "op <=" => Some(p,i,"<=",q,j) |
|
505 |
| "op =" => Some(p,i,"=",q,j) |
|
506 |
| _ => None |
|
507 |
end; |
|
508 |
||
| 6128 | 509 |
val intT = Type("IntDef.int",[]);
|
510 |
fun iib T = T = ([intT,intT] ---> HOLogic.boolT); |
|
| 6060 | 511 |
|
| 6128 | 512 |
fun decomp1(T,xxx) = |
513 |
if iib T then decomp2 xxx else Nat_LA_Data.decomp1(T,xxx); |
|
514 |
||
515 |
fun decomp(_$(Const(rel,T)$lhs$rhs)) = decomp1(T,(rel,lhs,rhs)) |
|
| 6060 | 516 |
| decomp(_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
|
| 6128 | 517 |
Nat_LA_Data.negate(decomp1(T,(rel,lhs,rhs))) |
| 6060 | 518 |
| decomp _ = None |
519 |
||
520 |
(* reduce contradictory <= to False *) |
|
521 |
val add_rules = simp_thms@bin_arith_simps@bin_rel_simps@[int_0]; |
|
522 |
||
| 6128 | 523 |
val cancel_sums_ss = Nat_LA_Data.cancel_sums_ss addsimps add_rules |
| 6060 | 524 |
addsimprocs [Int_Cancel.sum_conv, Int_Cancel.rel_conv]; |
525 |
||
526 |
val simp = simplify cancel_sums_ss; |
|
527 |
||
| 6128 | 528 |
val add_mono_thms = Nat_LA_Data.add_mono_thms @ |
529 |
map (fn s => prove_goal Int.thy s |
|
530 |
(fn prems => [cut_facts_tac prems 1, |
|
531 |
asm_simp_tac (simpset() addsimps [zadd_zle_mono]) 1])) |
|
532 |
["(i <= j) & (k <= l) ==> i + k <= j + (l::int)", |
|
533 |
"(i = j) & (k <= l) ==> i + k <= j + (l::int)", |
|
534 |
"(i <= j) & (k = l) ==> i + k <= j + (l::int)", |
|
535 |
"(i = j) & (k = l) ==> i + k = j + (l::int)" |
|
536 |
]; |
|
| 6060 | 537 |
|
538 |
end; |
|
539 |
||
| 6128 | 540 |
(* Update parameters of arithmetic prover *) |
541 |
LA_Data_Ref.add_mono_thms := Int_LA_Data.add_mono_thms; |
|
542 |
LA_Data_Ref.lessD := Int_LA_Data.lessD; |
|
543 |
LA_Data_Ref.decomp := Int_LA_Data.decomp; |
|
544 |
LA_Data_Ref.simp := Int_LA_Data.simp; |
|
545 |
||
| 6060 | 546 |
|
| 6128 | 547 |
val int_arith_simproc_pats = |
| 6394 | 548 |
map (fn s => Thm.read_cterm (Theory.sign_of Int.thy) (s, HOLogic.boolT)) |
| 6128 | 549 |
["(m::int) < n","(m::int) <= n", "(m::int) = n"]; |
| 6060 | 550 |
|
| 6128 | 551 |
val fast_int_arith_simproc = mk_simproc "fast_int_arith" int_arith_simproc_pats |
552 |
Fast_Arith.lin_arith_prover; |
|
553 |
||
554 |
Addsimprocs [fast_int_arith_simproc]; |
|
| 6060 | 555 |
|
556 |
(* FIXME: K true should be replaced by a sensible test to speed things up |
|
557 |
in case there are lots of irrelevant terms involved. |
|
| 6157 | 558 |
|
| 6128 | 559 |
val arith_tac = |
560 |
refute_tac (K true) (REPEAT o split_tac[nat_diff_split]) |
|
561 |
((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac); |
|
| 6157 | 562 |
*) |
| 6060 | 563 |
|
564 |
(* Some test data |
|
565 |
Goal "!!a::int. [| a <= b; c <= d; x+y<z |] ==> a+c <= b+d"; |
|
| 6301 | 566 |
by (fast_arith_tac 1); |
| 6060 | 567 |
Goal "!!a::int. [| a < b; c < d |] ==> a-d+ #2 <= b+(-c)"; |
| 6301 | 568 |
by (fast_arith_tac 1); |
| 6060 | 569 |
Goal "!!a::int. [| a < b; c < d |] ==> a+c+ #1 < b+d"; |
| 6301 | 570 |
by (fast_arith_tac 1); |
| 6060 | 571 |
Goal "!!a::int. [| a <= b; b+b <= c |] ==> a+a <= c"; |
| 6301 | 572 |
by (fast_arith_tac 1); |
| 6060 | 573 |
Goal "!!a::int. [| a+b <= i+j; a<=b; i<=j |] \ |
574 |
\ ==> a+a <= j+j"; |
|
| 6301 | 575 |
by (fast_arith_tac 1); |
| 6060 | 576 |
Goal "!!a::int. [| a+b < i+j; a<b; i<j |] \ |
577 |
\ ==> a+a - - #-1 < j+j - #3"; |
|
| 6301 | 578 |
by (fast_arith_tac 1); |
| 6060 | 579 |
Goal "!!a::int. a+b+c <= i+j+k & a<=b & b<=c & i<=j & j<=k --> a+a+a <= k+k+k"; |
| 6301 | 580 |
by (arith_tac 1); |
| 6060 | 581 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
582 |
\ ==> a <= l"; |
|
| 6301 | 583 |
by (fast_arith_tac 1); |
| 6060 | 584 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
585 |
\ ==> a+a+a+a <= l+l+l+l"; |
|
| 6301 | 586 |
by (fast_arith_tac 1); |
| 6060 | 587 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
588 |
\ ==> a+a+a+a+a <= l+l+l+l+i"; |
|
| 6301 | 589 |
by (fast_arith_tac 1); |
| 6060 | 590 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
591 |
\ ==> a+a+a+a+a+a <= l+l+l+l+i+l"; |
|
| 6301 | 592 |
by (fast_arith_tac 1); |
| 6060 | 593 |
*) |
594 |
||
595 |
(*---------------------------------------------------------------------------*) |
|
596 |
(* End of linear arithmetic *) |
|
597 |
(*---------------------------------------------------------------------------*) |
|
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
598 |
|
| 5592 | 599 |
(** Simplification of arithmetic when nested to the right **) |
600 |
||
| 6910 | 601 |
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::int)"; |
| 5592 | 602 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
| 6910 | 603 |
qed "add_number_of_left"; |
| 5592 | 604 |
|
| 6910 | 605 |
Goal "number_of v * (number_of w * z) = (number_of(bin_mult v w) * z::int)"; |
| 5592 | 606 |
by (simp_tac (simpset() addsimps [zmult_assoc RS sym]) 1); |
| 6910 | 607 |
qed "mult_number_of_left"; |
| 5592 | 608 |
|
| 6910 | 609 |
Addsimps [add_number_of_left, mult_number_of_left]; |
| 5592 | 610 |
|
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
611 |
(** Simplification of inequalities involving numerical constants **) |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
612 |
|
| 6910 | 613 |
Goal "(w <= z + (#1::int)) = (w<=z | w = z + (#1::int))"; |
| 6301 | 614 |
by (arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
615 |
qed "zle_add1_eq"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
616 |
|
| 6910 | 617 |
Goal "(w <= z - (#1::int)) = (w<(z::int))"; |
| 6301 | 618 |
by (arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
619 |
qed "zle_diff1_eq"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
620 |
Addsimps [zle_diff1_eq]; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
621 |
|
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
622 |
(*2nd premise can be proved automatically if v is a literal*) |
| 6910 | 623 |
Goal "[| w <= z; #0 <= v |] ==> w <= z + (v::int)"; |
| 6301 | 624 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
625 |
qed "zle_imp_zle_zadd"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
626 |
|
| 6910 | 627 |
Goal "w <= z ==> w <= z + (#1::int)"; |
| 6301 | 628 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
629 |
qed "zle_imp_zle_zadd1"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
630 |
|
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
631 |
(*2nd premise can be proved automatically if v is a literal*) |
| 6910 | 632 |
Goal "[| w < z; #0 <= v |] ==> w < z + (v::int)"; |
| 6301 | 633 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
634 |
qed "zless_imp_zless_zadd"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
635 |
|
| 6910 | 636 |
Goal "w < z ==> w < z + (#1::int)"; |
| 6301 | 637 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
638 |
qed "zless_imp_zless_zadd1"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
639 |
|
| 6910 | 640 |
Goal "(w < z + #1) = (w<=(z::int))"; |
| 6301 | 641 |
by (arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
642 |
qed "zle_add1_eq_le"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
643 |
Addsimps [zle_add1_eq_le]; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
644 |
|
| 6910 | 645 |
Goal "(z = z + w) = (w = (#0::int))"; |
| 6301 | 646 |
by (arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
647 |
qed "zadd_left_cancel0"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
648 |
Addsimps [zadd_left_cancel0]; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
649 |
|
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
650 |
(*LOOPS as a simprule!*) |
| 6910 | 651 |
Goal "[| w + v < z; #0 <= v |] ==> w < (z::int)"; |
| 6301 | 652 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
653 |
qed "zless_zadd_imp_zless"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
654 |
|
| 5540 | 655 |
(*LOOPS as a simprule! Analogous to Suc_lessD*) |
| 6910 | 656 |
Goal "w + #1 < z ==> w < (z::int)"; |
| 6301 | 657 |
by (fast_arith_tac 1); |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
658 |
qed "zless_zadd1_imp_zless"; |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
659 |
|
| 6910 | 660 |
Goal "w + #-1 = w - (#1::int)"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
661 |
by (Simp_tac 1); |
| 5551 | 662 |
qed "zplus_minus1_conv"; |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
663 |
|
| 5551 | 664 |
|
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
665 |
(*** nat ***) |
| 5551 | 666 |
|
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
667 |
Goal "#0 <= z ==> int (nat z) = z"; |
| 5551 | 668 |
by (asm_full_simp_tac |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
669 |
(simpset() addsimps [neg_eq_less_0, zle_def, not_neg_nat]) 1); |
|
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
670 |
qed "nat_0_le"; |
| 5551 | 671 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
672 |
Goal "z <= #0 ==> nat z = 0"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
673 |
by (case_tac "z = #0" 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
674 |
by (asm_simp_tac (simpset() addsimps [nat_le_int0]) 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
675 |
by (asm_full_simp_tac |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
676 |
(simpset() addsimps [neg_eq_less_0, neg_nat, linorder_neq_iff]) 1); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
677 |
qed "nat_le_0"; |
| 5551 | 678 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
679 |
Addsimps [nat_0_le, nat_le_0]; |
| 5551 | 680 |
|
| 7033 | 681 |
val [major,minor] = Goal "[| #0 <= z; !!m. z = int m ==> P |] ==> P"; |
682 |
by (rtac (major RS nat_0_le RS sym RS minor) 1); |
|
683 |
qed "nonneg_eq_int"; |
|
684 |
||
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
685 |
Goal "#0 <= w ==> (nat w = m) = (w = int m)"; |
| 5551 | 686 |
by Auto_tac; |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
687 |
qed "nat_eq_iff"; |
| 5551 | 688 |
|
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
689 |
Goal "#0 <= w ==> (nat w < m) = (w < int m)"; |
| 5551 | 690 |
by (rtac iffI 1); |
691 |
by (asm_full_simp_tac |
|
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
692 |
(simpset() delsimps [zless_int] addsimps [zless_int RS sym]) 2); |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
693 |
by (etac (nat_0_le RS subst) 1); |
| 5551 | 694 |
by (Simp_tac 1); |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
695 |
qed "nat_less_iff"; |
| 5551 | 696 |
|
| 5747 | 697 |
|
|
6716
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
698 |
(*Users don't want to see (int 0), int(Suc 0) or w + - z*) |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
699 |
Addsimps [int_0, int_Suc, symmetric zdiff_def]; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
700 |
|
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
701 |
Goal "nat #0 = 0"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
702 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
703 |
qed "nat_0"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
704 |
|
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
705 |
Goal "nat #1 = 1"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
706 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
707 |
qed "nat_1"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
708 |
|
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
709 |
Goal "nat #2 = 2"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
710 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
711 |
qed "nat_2"; |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
712 |
|
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
713 |
Goal "#0 <= w ==> (nat w < nat z) = (w<z)"; |
| 5551 | 714 |
by (case_tac "neg z" 1); |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
715 |
by (auto_tac (claset(), simpset() addsimps [nat_less_iff])); |
| 5551 | 716 |
by (auto_tac (claset() addIs [zless_trans], |
| 5747 | 717 |
simpset() addsimps [neg_eq_less_0, zle_def])); |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
718 |
qed "nat_less_eq_zless"; |
| 5747 | 719 |
|
|
7008
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
720 |
Goal "#0 < w | #0 <= z ==> (nat w <= nat z) = (w<=z)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
721 |
by (auto_tac (claset(), |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
722 |
simpset() addsimps [linorder_not_less RS sym, |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
723 |
zless_nat_conj])); |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
724 |
qed "nat_le_eq_zle"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
725 |
|
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
726 |
(*Analogous to zadd_int, but more easily provable using the arithmetic in Bin*) |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
727 |
Goal "n<=m --> int m - int n = int (m-n)"; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
728 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
|
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
729 |
by Auto_tac; |
|
6def5ce146e2
qed_goal -> Goal; new theorems nat_le_0, nat_le_eq_zle and zdiff_int
paulson
parents:
6997
diff
changeset
|
730 |
qed_spec_mp "zdiff_int"; |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
731 |
|
| 6941 | 732 |
|
733 |
(** Products of signs **) |
|
734 |
||
735 |
Goal "(m::int) < #0 ==> (#0 < m*n) = (n < #0)"; |
|
736 |
by Auto_tac; |
|
737 |
by (force_tac (claset() addDs [zmult_zless_mono1_neg], simpset()) 2); |
|
738 |
by (eres_inst_tac [("P", "#0 < m * n")] rev_mp 1);
|
|
739 |
by (simp_tac (simpset() addsimps [linorder_not_le RS sym]) 1); |
|
|
7074
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
740 |
by (force_tac (claset() addDs [inst "k" "m" zmult_zless_mono1_neg], |
|
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
741 |
simpset()addsimps [order_le_less, zmult_commute]) 1); |
| 6941 | 742 |
qed "neg_imp_zmult_pos_iff"; |
743 |
||
744 |
Goal "(m::int) < #0 ==> (m*n < #0) = (#0 < n)"; |
|
745 |
by Auto_tac; |
|
746 |
by (force_tac (claset() addDs [zmult_zless_mono1], simpset()) 2); |
|
747 |
by (eres_inst_tac [("P", "m * n < #0")] rev_mp 1);
|
|
748 |
by (simp_tac (simpset() addsimps [linorder_not_le RS sym]) 1); |
|
749 |
by (force_tac (claset() addDs [zmult_zless_mono1_neg], |
|
750 |
simpset() addsimps [order_le_less]) 1); |
|
751 |
qed "neg_imp_zmult_neg_iff"; |
|
752 |
||
753 |
Goal "#0 < (m::int) ==> (m*n < #0) = (n < #0)"; |
|
754 |
by Auto_tac; |
|
755 |
by (force_tac (claset() addDs [zmult_zless_mono1_neg], simpset()) 2); |
|
756 |
by (eres_inst_tac [("P", "m * n < #0")] rev_mp 1);
|
|
757 |
by (simp_tac (simpset() addsimps [linorder_not_le RS sym]) 1); |
|
758 |
by (force_tac (claset() addDs [zmult_zless_mono1], |
|
759 |
simpset() addsimps [order_le_less]) 1); |
|
760 |
qed "pos_imp_zmult_neg_iff"; |
|
761 |
||
762 |
Goal "#0 < (m::int) ==> (#0 < m*n) = (#0 < n)"; |
|
763 |
by Auto_tac; |
|
764 |
by (force_tac (claset() addDs [zmult_zless_mono1], simpset()) 2); |
|
765 |
by (eres_inst_tac [("P", "#0 < m * n")] rev_mp 1);
|
|
766 |
by (simp_tac (simpset() addsimps [linorder_not_le RS sym]) 1); |
|
|
7074
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
767 |
by (force_tac (claset() addDs [inst "k" "m" zmult_zless_mono1], |
|
e0730ffaafcc
zadd_ac and zmult_ac are no longer included by default
paulson
parents:
7033
diff
changeset
|
768 |
simpset() addsimps [order_le_less, zmult_commute]) 1); |
| 6941 | 769 |
qed "pos_imp_zmult_pos_iff"; |
| 6973 | 770 |
|
771 |
(** <= versions of the theorems above **) |
|
772 |
||
773 |
Goal "(m::int) < #0 ==> (m*n <= #0) = (#0 <= n)"; |
|
774 |
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
775 |
neg_imp_zmult_pos_iff]) 1); |
|
776 |
qed "neg_imp_zmult_nonpos_iff"; |
|
777 |
||
778 |
Goal "(m::int) < #0 ==> (#0 <= m*n) = (n <= #0)"; |
|
779 |
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
780 |
neg_imp_zmult_neg_iff]) 1); |
|
781 |
qed "neg_imp_zmult_nonneg_iff"; |
|
782 |
||
783 |
Goal "#0 < (m::int) ==> (m*n <= #0) = (n <= #0)"; |
|
784 |
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
785 |
pos_imp_zmult_pos_iff]) 1); |
|
786 |
qed "pos_imp_zmult_nonpos_iff"; |
|
787 |
||
788 |
Goal "#0 < (m::int) ==> (#0 <= m*n) = (#0 <= n)"; |
|
789 |
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
790 |
pos_imp_zmult_neg_iff]) 1); |
|
791 |
qed "pos_imp_zmult_nonneg_iff"; |