author | huffman |
Thu, 04 Dec 2008 08:47:45 -0800 | |
changeset 28969 | 4ed63cdda799 |
parent 28968 | a4f3db5d1393 |
child 28984 | 060832a1f087 |
permissions | -rw-r--r-- |
23164 | 1 |
(* Title: HOL/NatBin.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
*) |
|
6 |
||
7 |
header {* Binary arithmetic for the natural numbers *} |
|
8 |
||
9 |
theory NatBin |
|
10 |
imports IntDiv |
|
11 |
begin |
|
12 |
||
13 |
text {* |
|
14 |
Arithmetic for naturals is reduced to that for the non-negative integers. |
|
15 |
*} |
|
16 |
||
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
17 |
instantiation nat :: number |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
18 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
19 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
20 |
definition |
28562 | 21 |
nat_number_of_def [code inline, code del]: "number_of v = nat (number_of v)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
22 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
23 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
24 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
25 |
end |
23164 | 26 |
|
25965 | 27 |
lemma [code post]: |
28 |
"nat (number_of v) = number_of v" |
|
29 |
unfolding nat_number_of_def .. |
|
30 |
||
23164 | 31 |
abbreviation (xsymbols) |
32 |
square :: "'a::power => 'a" ("(_\<twosuperior>)" [1000] 999) where |
|
33 |
"x\<twosuperior> == x^2" |
|
34 |
||
35 |
notation (latex output) |
|
36 |
square ("(_\<twosuperior>)" [1000] 999) |
|
37 |
||
38 |
notation (HTML output) |
|
39 |
square ("(_\<twosuperior>)" [1000] 999) |
|
40 |
||
41 |
||
42 |
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*} |
|
43 |
||
44 |
declare nat_0 [simp] nat_1 [simp] |
|
45 |
||
46 |
lemma nat_number_of [simp]: "nat (number_of w) = number_of w" |
|
47 |
by (simp add: nat_number_of_def) |
|
48 |
||
49 |
lemma nat_numeral_0_eq_0 [simp]: "Numeral0 = (0::nat)" |
|
50 |
by (simp add: nat_number_of_def) |
|
51 |
||
52 |
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)" |
|
53 |
by (simp add: nat_1 nat_number_of_def) |
|
54 |
||
55 |
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0" |
|
56 |
by (simp add: nat_numeral_1_eq_1) |
|
57 |
||
58 |
lemma numeral_2_eq_2: "2 = Suc (Suc 0)" |
|
59 |
apply (unfold nat_number_of_def) |
|
60 |
apply (rule nat_2) |
|
61 |
done |
|
62 |
||
63 |
||
64 |
text{*Distributive laws for type @{text nat}. The others are in theory |
|
65 |
@{text IntArith}, but these require div and mod to be defined for type |
|
66 |
"int". They also need some of the lemmas proved above.*} |
|
67 |
||
68 |
lemma nat_div_distrib: "(0::int) <= z ==> nat (z div z') = nat z div nat z'" |
|
69 |
apply (case_tac "0 <= z'") |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
70 |
apply (auto simp add: div_nonneg_neg_le0) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
71 |
apply (case_tac "z' = 0", simp) |
23365 | 72 |
apply (auto elim!: nonneg_eq_int) |
23164 | 73 |
apply (rename_tac m m') |
23365 | 74 |
apply (subgoal_tac "0 <= int m div int m'") |
23164 | 75 |
prefer 2 apply (simp add: nat_numeral_0_eq_0 pos_imp_zdiv_nonneg_iff) |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
76 |
apply (rule of_nat_eq_iff [where 'a=int, THEN iffD1], simp) |
23365 | 77 |
apply (rule_tac r = "int (m mod m') " in quorem_div) |
23164 | 78 |
prefer 2 apply force |
23365 | 79 |
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
80 |
of_nat_add [symmetric] of_nat_mult [symmetric] |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
81 |
del: of_nat_add of_nat_mult) |
23164 | 82 |
done |
83 |
||
84 |
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*) |
|
85 |
lemma nat_mod_distrib: |
|
86 |
"[| (0::int) <= z; 0 <= z' |] ==> nat (z mod z') = nat z mod nat z'" |
|
87 |
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO) |
|
23365 | 88 |
apply (auto elim!: nonneg_eq_int) |
23164 | 89 |
apply (rename_tac m m') |
23365 | 90 |
apply (subgoal_tac "0 <= int m mod int m'") |
91 |
prefer 2 apply (simp add: nat_less_iff nat_numeral_0_eq_0 pos_mod_sign) |
|
92 |
apply (rule int_int_eq [THEN iffD1], simp) |
|
93 |
apply (rule_tac q = "int (m div m') " in quorem_mod) |
|
23164 | 94 |
prefer 2 apply force |
23365 | 95 |
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
96 |
of_nat_add [symmetric] of_nat_mult [symmetric] |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
97 |
del: of_nat_add of_nat_mult) |
23164 | 98 |
done |
99 |
||
100 |
text{*Suggested by Matthias Daum*} |
|
101 |
lemma int_div_less_self: "\<lbrakk>0 < x; 1 < k\<rbrakk> \<Longrightarrow> x div k < (x::int)" |
|
102 |
apply (subgoal_tac "nat x div nat k < nat x") |
|
103 |
apply (simp (asm_lr) add: nat_div_distrib [symmetric]) |
|
104 |
apply (rule Divides.div_less_dividend, simp_all) |
|
105 |
done |
|
106 |
||
107 |
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*} |
|
108 |
||
109 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
110 |
lemma int_nat_number_of [simp]: |
|
23365 | 111 |
"int (number_of v) = |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
112 |
(if neg (number_of v :: int) then 0 |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
113 |
else (number_of v :: int))" |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
114 |
by (simp del: nat_number_of |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
115 |
add: neg_nat nat_number_of_def not_neg_nat add_assoc) |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
116 |
|
23164 | 117 |
|
118 |
subsubsection{*Successor *} |
|
119 |
||
120 |
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
|
121 |
apply (rule sym) |
|
122 |
apply (simp add: nat_eq_iff int_Suc) |
|
123 |
done |
|
124 |
||
125 |
lemma Suc_nat_number_of_add: |
|
126 |
"Suc (number_of v + n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
127 |
(if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)" |
23164 | 128 |
by (simp del: nat_number_of |
129 |
add: nat_number_of_def neg_nat |
|
130 |
Suc_nat_eq_nat_zadd1 number_of_succ) |
|
131 |
||
132 |
lemma Suc_nat_number_of [simp]: |
|
133 |
"Suc (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
134 |
(if neg (number_of v :: int) then 1 else number_of (Int.succ v))" |
23164 | 135 |
apply (cut_tac n = 0 in Suc_nat_number_of_add) |
136 |
apply (simp cong del: if_weak_cong) |
|
137 |
done |
|
138 |
||
139 |
||
140 |
subsubsection{*Addition *} |
|
141 |
||
142 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
143 |
lemma add_nat_number_of [simp]: |
|
144 |
"(number_of v :: nat) + number_of v' = |
|
145 |
(if neg (number_of v :: int) then number_of v' |
|
146 |
else if neg (number_of v' :: int) then number_of v |
|
147 |
else number_of (v + v'))" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
148 |
by (simp add: neg_nat nat_number_of_def nat_add_distrib [symmetric] del: nat_number_of) |
23164 | 149 |
|
150 |
||
151 |
subsubsection{*Subtraction *} |
|
152 |
||
153 |
lemma diff_nat_eq_if: |
|
154 |
"nat z - nat z' = |
|
155 |
(if neg z' then nat z |
|
156 |
else let d = z-z' in |
|
157 |
if neg d then 0 else nat d)" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
158 |
by (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
159 |
|
23164 | 160 |
|
161 |
lemma diff_nat_number_of [simp]: |
|
162 |
"(number_of v :: nat) - number_of v' = |
|
163 |
(if neg (number_of v' :: int) then number_of v |
|
164 |
else let d = number_of (v + uminus v') in |
|
165 |
if neg d then 0 else nat d)" |
|
166 |
by (simp del: nat_number_of add: diff_nat_eq_if nat_number_of_def) |
|
167 |
||
168 |
||
169 |
||
170 |
subsubsection{*Multiplication *} |
|
171 |
||
172 |
lemma mult_nat_number_of [simp]: |
|
173 |
"(number_of v :: nat) * number_of v' = |
|
174 |
(if neg (number_of v :: int) then 0 else number_of (v * v'))" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
175 |
by (simp add: neg_nat nat_number_of_def nat_mult_distrib [symmetric] del: nat_number_of) |
23164 | 176 |
|
177 |
||
178 |
subsubsection{*Quotient *} |
|
179 |
||
180 |
lemma div_nat_number_of [simp]: |
|
181 |
"(number_of v :: nat) div number_of v' = |
|
182 |
(if neg (number_of v :: int) then 0 |
|
183 |
else nat (number_of v div number_of v'))" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
184 |
by (simp add: neg_nat nat_number_of_def nat_div_distrib [symmetric] del: nat_number_of) |
23164 | 185 |
|
186 |
lemma one_div_nat_number_of [simp]: |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
187 |
"Suc 0 div number_of v' = nat (1 div number_of v')" |
23164 | 188 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
189 |
||
190 |
||
191 |
subsubsection{*Remainder *} |
|
192 |
||
193 |
lemma mod_nat_number_of [simp]: |
|
194 |
"(number_of v :: nat) mod number_of v' = |
|
195 |
(if neg (number_of v :: int) then 0 |
|
196 |
else if neg (number_of v' :: int) then number_of v |
|
197 |
else nat (number_of v mod number_of v'))" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
198 |
by (simp add: neg_nat nat_number_of_def nat_mod_distrib [symmetric] del: nat_number_of) |
23164 | 199 |
|
200 |
lemma one_mod_nat_number_of [simp]: |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
201 |
"Suc 0 mod number_of v' = |
23164 | 202 |
(if neg (number_of v' :: int) then Suc 0 |
203 |
else nat (1 mod number_of v'))" |
|
204 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
|
205 |
||
206 |
||
207 |
subsubsection{* Divisibility *} |
|
208 |
||
209 |
lemmas dvd_eq_mod_eq_0_number_of = |
|
210 |
dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard] |
|
211 |
||
212 |
declare dvd_eq_mod_eq_0_number_of [simp] |
|
213 |
||
214 |
ML |
|
215 |
{* |
|
216 |
val nat_number_of_def = thm"nat_number_of_def"; |
|
217 |
||
218 |
val nat_number_of = thm"nat_number_of"; |
|
219 |
val nat_numeral_0_eq_0 = thm"nat_numeral_0_eq_0"; |
|
220 |
val nat_numeral_1_eq_1 = thm"nat_numeral_1_eq_1"; |
|
221 |
val numeral_1_eq_Suc_0 = thm"numeral_1_eq_Suc_0"; |
|
222 |
val numeral_2_eq_2 = thm"numeral_2_eq_2"; |
|
223 |
val nat_div_distrib = thm"nat_div_distrib"; |
|
224 |
val nat_mod_distrib = thm"nat_mod_distrib"; |
|
225 |
val int_nat_number_of = thm"int_nat_number_of"; |
|
226 |
val Suc_nat_eq_nat_zadd1 = thm"Suc_nat_eq_nat_zadd1"; |
|
227 |
val Suc_nat_number_of_add = thm"Suc_nat_number_of_add"; |
|
228 |
val Suc_nat_number_of = thm"Suc_nat_number_of"; |
|
229 |
val add_nat_number_of = thm"add_nat_number_of"; |
|
230 |
val diff_nat_eq_if = thm"diff_nat_eq_if"; |
|
231 |
val diff_nat_number_of = thm"diff_nat_number_of"; |
|
232 |
val mult_nat_number_of = thm"mult_nat_number_of"; |
|
233 |
val div_nat_number_of = thm"div_nat_number_of"; |
|
234 |
val mod_nat_number_of = thm"mod_nat_number_of"; |
|
235 |
*} |
|
236 |
||
237 |
||
238 |
subsection{*Comparisons*} |
|
239 |
||
240 |
subsubsection{*Equals (=) *} |
|
241 |
||
242 |
lemma eq_nat_nat_iff: |
|
243 |
"[| (0::int) <= z; 0 <= z' |] ==> (nat z = nat z') = (z=z')" |
|
244 |
by (auto elim!: nonneg_eq_int) |
|
245 |
||
246 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
247 |
lemma eq_nat_number_of [simp]: |
|
248 |
"((number_of v :: nat) = number_of v') = |
|
28969 | 249 |
(if neg (number_of v :: int) then (number_of v' :: int) \<le> 0 |
250 |
else if neg (number_of v' :: int) then (number_of v :: int) = 0 |
|
251 |
else v = v')" |
|
252 |
unfolding nat_number_of_def number_of_is_id neg_def |
|
253 |
by auto |
|
23164 | 254 |
|
255 |
||
256 |
subsubsection{*Less-than (<) *} |
|
257 |
||
258 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
259 |
lemma less_nat_number_of [simp]: |
|
260 |
"((number_of v :: nat) < number_of v') = |
|
261 |
(if neg (number_of v :: int) then neg (number_of (uminus v') :: int) |
|
262 |
else neg (number_of (v + uminus v') :: int))" |
|
28961 | 263 |
unfolding neg_def nat_number_of_def number_of_is_id |
264 |
by auto |
|
23164 | 265 |
|
266 |
||
267 |
(*Maps #n to n for n = 0, 1, 2*) |
|
268 |
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
|
269 |
||
270 |
||
271 |
subsection{*Powers with Numeric Exponents*} |
|
272 |
||
273 |
text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}. |
|
274 |
We cannot prove general results about the numeral @{term "-1"}, so we have to |
|
275 |
use @{term "- 1"} instead.*} |
|
276 |
||
23277 | 277 |
lemma power2_eq_square: "(a::'a::recpower)\<twosuperior> = a * a" |
23164 | 278 |
by (simp add: numeral_2_eq_2 Power.power_Suc) |
279 |
||
23277 | 280 |
lemma zero_power2 [simp]: "(0::'a::{semiring_1,recpower})\<twosuperior> = 0" |
23164 | 281 |
by (simp add: power2_eq_square) |
282 |
||
23277 | 283 |
lemma one_power2 [simp]: "(1::'a::{semiring_1,recpower})\<twosuperior> = 1" |
23164 | 284 |
by (simp add: power2_eq_square) |
285 |
||
286 |
lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x" |
|
287 |
apply (subgoal_tac "3 = Suc (Suc (Suc 0))") |
|
288 |
apply (erule ssubst) |
|
289 |
apply (simp add: power_Suc mult_ac) |
|
290 |
apply (unfold nat_number_of_def) |
|
291 |
apply (subst nat_eq_iff) |
|
292 |
apply simp |
|
293 |
done |
|
294 |
||
295 |
text{*Squares of literal numerals will be evaluated.*} |
|
296 |
lemmas power2_eq_square_number_of = |
|
297 |
power2_eq_square [of "number_of w", standard] |
|
298 |
declare power2_eq_square_number_of [simp] |
|
299 |
||
300 |
||
301 |
lemma zero_le_power2[simp]: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
302 |
by (simp add: power2_eq_square) |
|
303 |
||
304 |
lemma zero_less_power2[simp]: |
|
305 |
"(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))" |
|
306 |
by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
307 |
||
308 |
lemma power2_less_0[simp]: |
|
309 |
fixes a :: "'a::{ordered_idom,recpower}" |
|
310 |
shows "~ (a\<twosuperior> < 0)" |
|
311 |
by (force simp add: power2_eq_square mult_less_0_iff) |
|
312 |
||
313 |
lemma zero_eq_power2[simp]: |
|
314 |
"(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))" |
|
315 |
by (force simp add: power2_eq_square mult_eq_0_iff) |
|
316 |
||
317 |
lemma abs_power2[simp]: |
|
318 |
"abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
319 |
by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
320 |
||
321 |
lemma power2_abs[simp]: |
|
322 |
"(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
323 |
by (simp add: power2_eq_square abs_mult_self) |
|
324 |
||
325 |
lemma power2_minus[simp]: |
|
326 |
"(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})" |
|
327 |
by (simp add: power2_eq_square) |
|
328 |
||
329 |
lemma power2_le_imp_le: |
|
330 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
331 |
shows "\<lbrakk>x\<twosuperior> \<le> y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x \<le> y" |
|
332 |
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
333 |
||
334 |
lemma power2_less_imp_less: |
|
335 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
336 |
shows "\<lbrakk>x\<twosuperior> < y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x < y" |
|
337 |
by (rule power_less_imp_less_base) |
|
338 |
||
339 |
lemma power2_eq_imp_eq: |
|
340 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
341 |
shows "\<lbrakk>x\<twosuperior> = y\<twosuperior>; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> x = y" |
|
342 |
unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base, simp) |
|
343 |
||
344 |
lemma power_minus1_even[simp]: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})" |
|
345 |
apply (induct "n") |
|
346 |
apply (auto simp add: power_Suc power_add) |
|
347 |
done |
|
348 |
||
349 |
lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2" |
|
350 |
by (subst mult_commute) (simp add: power_mult) |
|
351 |
||
352 |
lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2" |
|
353 |
by (simp add: power_even_eq) |
|
354 |
||
355 |
lemma power_minus_even [simp]: |
|
356 |
"(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)" |
|
357 |
by (simp add: power_minus1_even power_minus [of a]) |
|
358 |
||
359 |
lemma zero_le_even_power'[simp]: |
|
360 |
"0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)" |
|
361 |
proof (induct "n") |
|
362 |
case 0 |
|
363 |
show ?case by (simp add: zero_le_one) |
|
364 |
next |
|
365 |
case (Suc n) |
|
366 |
have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
367 |
by (simp add: mult_ac power_add power2_eq_square) |
|
368 |
thus ?case |
|
369 |
by (simp add: prems zero_le_mult_iff) |
|
370 |
qed |
|
371 |
||
372 |
lemma odd_power_less_zero: |
|
373 |
"(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0" |
|
374 |
proof (induct "n") |
|
375 |
case 0 |
|
23389 | 376 |
then show ?case by (simp add: Power.power_Suc) |
23164 | 377 |
next |
378 |
case (Suc n) |
|
23389 | 379 |
have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
380 |
by (simp add: mult_ac power_add power2_eq_square Power.power_Suc) |
|
381 |
thus ?case |
|
382 |
by (simp add: prems mult_less_0_iff mult_neg_neg) |
|
23164 | 383 |
qed |
384 |
||
385 |
lemma odd_0_le_power_imp_0_le: |
|
386 |
"0 \<le> a ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})" |
|
387 |
apply (insert odd_power_less_zero [of a n]) |
|
388 |
apply (force simp add: linorder_not_less [symmetric]) |
|
389 |
done |
|
390 |
||
391 |
text{*Simprules for comparisons where common factors can be cancelled.*} |
|
392 |
lemmas zero_compare_simps = |
|
393 |
add_strict_increasing add_strict_increasing2 add_increasing |
|
394 |
zero_le_mult_iff zero_le_divide_iff |
|
395 |
zero_less_mult_iff zero_less_divide_iff |
|
396 |
mult_le_0_iff divide_le_0_iff |
|
397 |
mult_less_0_iff divide_less_0_iff |
|
398 |
zero_le_power2 power2_less_0 |
|
399 |
||
400 |
subsubsection{*Nat *} |
|
401 |
||
402 |
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" |
|
403 |
by (simp add: numerals) |
|
404 |
||
405 |
(*Expresses a natural number constant as the Suc of another one. |
|
406 |
NOT suitable for rewriting because n recurs in the condition.*) |
|
407 |
lemmas expand_Suc = Suc_pred' [of "number_of v", standard] |
|
408 |
||
409 |
subsubsection{*Arith *} |
|
410 |
||
411 |
lemma Suc_eq_add_numeral_1: "Suc n = n + 1" |
|
412 |
by (simp add: numerals) |
|
413 |
||
414 |
lemma Suc_eq_add_numeral_1_left: "Suc n = 1 + n" |
|
415 |
by (simp add: numerals) |
|
416 |
||
417 |
(* These two can be useful when m = number_of... *) |
|
418 |
||
419 |
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))" |
|
420 |
apply (case_tac "m") |
|
421 |
apply (simp_all add: numerals) |
|
422 |
done |
|
423 |
||
424 |
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))" |
|
425 |
apply (case_tac "m") |
|
426 |
apply (simp_all add: numerals) |
|
427 |
done |
|
428 |
||
429 |
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))" |
|
430 |
apply (case_tac "m") |
|
431 |
apply (simp_all add: numerals) |
|
432 |
done |
|
433 |
||
434 |
||
435 |
subsection{*Comparisons involving (0::nat) *} |
|
436 |
||
437 |
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*} |
|
438 |
||
439 |
lemma eq_number_of_0 [simp]: |
|
28968 | 440 |
"number_of v = (0::nat) \<longleftrightarrow> number_of v \<le> (0::int)" |
441 |
unfolding nat_number_of_def number_of_is_id by auto |
|
23164 | 442 |
|
443 |
lemma eq_0_number_of [simp]: |
|
28968 | 444 |
"(0::nat) = number_of v \<longleftrightarrow> number_of v \<le> (0::int)" |
23164 | 445 |
by (rule trans [OF eq_sym_conv eq_number_of_0]) |
446 |
||
447 |
lemma less_0_number_of [simp]: |
|
448 |
"((0::nat) < number_of v) = neg (number_of (uminus v) :: int)" |
|
449 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] Pls_def) |
|
450 |
||
451 |
||
452 |
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" |
|
28969 | 453 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric]) |
23164 | 454 |
|
455 |
||
456 |
||
457 |
subsection{*Comparisons involving @{term Suc} *} |
|
458 |
||
459 |
lemma eq_number_of_Suc [simp]: |
|
460 |
"(number_of v = Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
461 |
(let pv = number_of (Int.pred v) in |
23164 | 462 |
if neg pv then False else nat pv = n)" |
463 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
464 |
number_of_pred nat_number_of_def |
|
465 |
split add: split_if) |
|
466 |
apply (rule_tac x = "number_of v" in spec) |
|
467 |
apply (auto simp add: nat_eq_iff) |
|
468 |
done |
|
469 |
||
470 |
lemma Suc_eq_number_of [simp]: |
|
471 |
"(Suc n = number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
472 |
(let pv = number_of (Int.pred v) in |
23164 | 473 |
if neg pv then False else nat pv = n)" |
474 |
by (rule trans [OF eq_sym_conv eq_number_of_Suc]) |
|
475 |
||
476 |
lemma less_number_of_Suc [simp]: |
|
477 |
"(number_of v < Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
478 |
(let pv = number_of (Int.pred v) in |
23164 | 479 |
if neg pv then True else nat pv < n)" |
480 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
481 |
number_of_pred nat_number_of_def |
|
482 |
split add: split_if) |
|
483 |
apply (rule_tac x = "number_of v" in spec) |
|
484 |
apply (auto simp add: nat_less_iff) |
|
485 |
done |
|
486 |
||
487 |
lemma less_Suc_number_of [simp]: |
|
488 |
"(Suc n < number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
489 |
(let pv = number_of (Int.pred v) in |
23164 | 490 |
if neg pv then False else n < nat pv)" |
491 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
492 |
number_of_pred nat_number_of_def |
|
493 |
split add: split_if) |
|
494 |
apply (rule_tac x = "number_of v" in spec) |
|
495 |
apply (auto simp add: zless_nat_eq_int_zless) |
|
496 |
done |
|
497 |
||
498 |
lemma le_number_of_Suc [simp]: |
|
499 |
"(number_of v <= Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
500 |
(let pv = number_of (Int.pred v) in |
23164 | 501 |
if neg pv then True else nat pv <= n)" |
502 |
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric]) |
|
503 |
||
504 |
lemma le_Suc_number_of [simp]: |
|
505 |
"(Suc n <= number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
506 |
(let pv = number_of (Int.pred v) in |
23164 | 507 |
if neg pv then False else n <= nat pv)" |
508 |
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric]) |
|
509 |
||
510 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
511 |
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" |
23164 | 512 |
by auto |
513 |
||
514 |
||
515 |
||
516 |
subsection{*Max and Min Combined with @{term Suc} *} |
|
517 |
||
518 |
lemma max_number_of_Suc [simp]: |
|
519 |
"max (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
520 |
(let pv = number_of (Int.pred v) in |
23164 | 521 |
if neg pv then Suc n else Suc(max n (nat pv)))" |
522 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
523 |
split add: split_if nat.split) |
|
524 |
apply (rule_tac x = "number_of v" in spec) |
|
525 |
apply auto |
|
526 |
done |
|
527 |
||
528 |
lemma max_Suc_number_of [simp]: |
|
529 |
"max (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
530 |
(let pv = number_of (Int.pred v) in |
23164 | 531 |
if neg pv then Suc n else Suc(max (nat pv) n))" |
532 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
533 |
split add: split_if nat.split) |
|
534 |
apply (rule_tac x = "number_of v" in spec) |
|
535 |
apply auto |
|
536 |
done |
|
537 |
||
538 |
lemma min_number_of_Suc [simp]: |
|
539 |
"min (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
540 |
(let pv = number_of (Int.pred v) in |
23164 | 541 |
if neg pv then 0 else Suc(min n (nat pv)))" |
542 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
543 |
split add: split_if nat.split) |
|
544 |
apply (rule_tac x = "number_of v" in spec) |
|
545 |
apply auto |
|
546 |
done |
|
547 |
||
548 |
lemma min_Suc_number_of [simp]: |
|
549 |
"min (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
550 |
(let pv = number_of (Int.pred v) in |
23164 | 551 |
if neg pv then 0 else Suc(min (nat pv) n))" |
552 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
553 |
split add: split_if nat.split) |
|
554 |
apply (rule_tac x = "number_of v" in spec) |
|
555 |
apply auto |
|
556 |
done |
|
557 |
||
558 |
subsection{*Literal arithmetic involving powers*} |
|
559 |
||
560 |
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n" |
|
561 |
apply (induct "n") |
|
562 |
apply (simp_all (no_asm_simp) add: nat_mult_distrib) |
|
563 |
done |
|
564 |
||
565 |
lemma power_nat_number_of: |
|
566 |
"(number_of v :: nat) ^ n = |
|
567 |
(if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" |
|
568 |
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq |
|
569 |
split add: split_if cong: imp_cong) |
|
570 |
||
571 |
||
572 |
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] |
|
573 |
declare power_nat_number_of_number_of [simp] |
|
574 |
||
575 |
||
576 |
||
23294 | 577 |
text{*For arbitrary rings*} |
23164 | 578 |
|
23294 | 579 |
lemma power_number_of_even: |
580 |
fixes z :: "'a::{number_ring,recpower}" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
581 |
shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
582 |
unfolding Let_def nat_number_of_def number_of_Bit0 |
23164 | 583 |
apply (rule_tac x = "number_of w" in spec, clarify) |
584 |
apply (case_tac " (0::int) <= x") |
|
585 |
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square) |
|
586 |
done |
|
587 |
||
23294 | 588 |
lemma power_number_of_odd: |
589 |
fixes z :: "'a::{number_ring,recpower}" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
590 |
shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w |
23164 | 591 |
then (let w = z ^ (number_of w) in z * w * w) else 1)" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
592 |
unfolding Let_def nat_number_of_def number_of_Bit1 |
23164 | 593 |
apply (rule_tac x = "number_of w" in spec, auto) |
594 |
apply (simp only: nat_add_distrib nat_mult_distrib) |
|
595 |
apply simp |
|
23294 | 596 |
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat power_Suc) |
23164 | 597 |
done |
598 |
||
23294 | 599 |
lemmas zpower_number_of_even = power_number_of_even [where 'a=int] |
600 |
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] |
|
23164 | 601 |
|
23294 | 602 |
lemmas power_number_of_even_number_of [simp] = |
603 |
power_number_of_even [of "number_of v", standard] |
|
23164 | 604 |
|
23294 | 605 |
lemmas power_number_of_odd_number_of [simp] = |
606 |
power_number_of_odd [of "number_of v", standard] |
|
23164 | 607 |
|
608 |
||
609 |
||
610 |
ML |
|
611 |
{* |
|
26342 | 612 |
val numeral_ss = @{simpset} addsimps @{thms numerals}; |
23164 | 613 |
|
614 |
val nat_bin_arith_setup = |
|
24093 | 615 |
LinArith.map_data |
23164 | 616 |
(fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} => |
617 |
{add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms, |
|
618 |
inj_thms = inj_thms, |
|
619 |
lessD = lessD, neqE = neqE, |
|
620 |
simpset = simpset addsimps [Suc_nat_number_of, int_nat_number_of, |
|
25481 | 621 |
@{thm not_neg_number_of_Pls}, @{thm neg_number_of_Min}, |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
622 |
@{thm neg_number_of_Bit0}, @{thm neg_number_of_Bit1}]}) |
23164 | 623 |
*} |
624 |
||
24075 | 625 |
declaration {* K nat_bin_arith_setup *} |
23164 | 626 |
|
627 |
(* Enable arith to deal with div/mod k where k is a numeral: *) |
|
628 |
declare split_div[of _ _ "number_of k", standard, arith_split] |
|
629 |
declare split_mod[of _ _ "number_of k", standard, arith_split] |
|
630 |
||
631 |
lemma nat_number_of_Pls: "Numeral0 = (0::nat)" |
|
632 |
by (simp add: number_of_Pls nat_number_of_def) |
|
633 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
634 |
lemma nat_number_of_Min: "number_of Int.Min = (0::nat)" |
23164 | 635 |
apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) |
636 |
done |
|
637 |
||
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
638 |
lemma nat_number_of_Bit0: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
639 |
"number_of (Int.Bit0 w) = (let n::nat = number_of w in n + n)" |
28969 | 640 |
unfolding nat_number_of_def number_of_is_id numeral_simps Let_def |
641 |
by auto |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
642 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
643 |
lemma nat_number_of_Bit1: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
644 |
"number_of (Int.Bit1 w) = |
23164 | 645 |
(if neg (number_of w :: int) then 0 |
646 |
else let n = number_of w in Suc (n + n))" |
|
28969 | 647 |
unfolding nat_number_of_def number_of_is_id numeral_simps neg_def Let_def |
28968 | 648 |
by auto |
23164 | 649 |
|
650 |
lemmas nat_number = |
|
651 |
nat_number_of_Pls nat_number_of_Min |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
652 |
nat_number_of_Bit0 nat_number_of_Bit1 |
23164 | 653 |
|
654 |
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" |
|
655 |
by (simp add: Let_def) |
|
656 |
||
657 |
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring,recpower})" |
|
23294 | 658 |
by (simp add: power_mult power_Suc); |
23164 | 659 |
|
660 |
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring,recpower})" |
|
661 |
by (simp add: power_mult power_Suc); |
|
662 |
||
663 |
||
664 |
subsection{*Literal arithmetic and @{term of_nat}*} |
|
665 |
||
666 |
lemma of_nat_double: |
|
667 |
"0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" |
|
668 |
by (simp only: mult_2 nat_add_distrib of_nat_add) |
|
669 |
||
670 |
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)" |
|
671 |
by (simp only: nat_number_of_def) |
|
672 |
||
673 |
lemma of_nat_number_of_lemma: |
|
674 |
"of_nat (number_of v :: nat) = |
|
675 |
(if 0 \<le> (number_of v :: int) |
|
676 |
then (number_of v :: 'a :: number_ring) |
|
677 |
else 0)" |
|
678 |
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat); |
|
679 |
||
680 |
lemma of_nat_number_of_eq [simp]: |
|
681 |
"of_nat (number_of v :: nat) = |
|
682 |
(if neg (number_of v :: int) then 0 |
|
683 |
else (number_of v :: 'a :: number_ring))" |
|
684 |
by (simp only: of_nat_number_of_lemma neg_def, simp) |
|
685 |
||
686 |
||
687 |
subsection {*Lemmas for the Combination and Cancellation Simprocs*} |
|
688 |
||
689 |
lemma nat_number_of_add_left: |
|
690 |
"number_of v + (number_of v' + (k::nat)) = |
|
691 |
(if neg (number_of v :: int) then number_of v' + k |
|
692 |
else if neg (number_of v' :: int) then number_of v + k |
|
693 |
else number_of (v + v') + k)" |
|
28968 | 694 |
unfolding nat_number_of_def number_of_is_id neg_def |
695 |
by auto |
|
23164 | 696 |
|
697 |
lemma nat_number_of_mult_left: |
|
698 |
"number_of v * (number_of v' * (k::nat)) = |
|
699 |
(if neg (number_of v :: int) then 0 |
|
700 |
else number_of (v * v') * k)" |
|
701 |
by simp |
|
702 |
||
703 |
||
704 |
subsubsection{*For @{text combine_numerals}*} |
|
705 |
||
706 |
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)" |
|
707 |
by (simp add: add_mult_distrib) |
|
708 |
||
709 |
||
710 |
subsubsection{*For @{text cancel_numerals}*} |
|
711 |
||
712 |
lemma nat_diff_add_eq1: |
|
713 |
"j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)" |
|
714 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
715 |
||
716 |
lemma nat_diff_add_eq2: |
|
717 |
"i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))" |
|
718 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
719 |
||
720 |
lemma nat_eq_add_iff1: |
|
721 |
"j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)" |
|
722 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
723 |
||
724 |
lemma nat_eq_add_iff2: |
|
725 |
"i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)" |
|
726 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
727 |
||
728 |
lemma nat_less_add_iff1: |
|
729 |
"j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)" |
|
730 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
731 |
||
732 |
lemma nat_less_add_iff2: |
|
733 |
"i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)" |
|
734 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
735 |
||
736 |
lemma nat_le_add_iff1: |
|
737 |
"j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)" |
|
738 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
739 |
||
740 |
lemma nat_le_add_iff2: |
|
741 |
"i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)" |
|
742 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
743 |
||
744 |
||
745 |
subsubsection{*For @{text cancel_numeral_factors} *} |
|
746 |
||
747 |
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)" |
|
748 |
by auto |
|
749 |
||
750 |
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)" |
|
751 |
by auto |
|
752 |
||
753 |
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)" |
|
754 |
by auto |
|
755 |
||
756 |
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)" |
|
757 |
by auto |
|
758 |
||
23969 | 759 |
lemma nat_mult_dvd_cancel_disj[simp]: |
760 |
"(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))" |
|
761 |
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric]) |
|
762 |
||
763 |
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)" |
|
764 |
by(auto) |
|
765 |
||
23164 | 766 |
|
767 |
subsubsection{*For @{text cancel_factor} *} |
|
768 |
||
769 |
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)" |
|
770 |
by auto |
|
771 |
||
772 |
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)" |
|
773 |
by auto |
|
774 |
||
775 |
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)" |
|
776 |
by auto |
|
777 |
||
23969 | 778 |
lemma nat_mult_div_cancel_disj[simp]: |
23164 | 779 |
"(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)" |
780 |
by (simp add: nat_mult_div_cancel1) |
|
781 |
||
782 |
end |