author | haftmann |
Fri, 25 Jan 2008 14:54:41 +0100 | |
changeset 25965 | 05df64f786a4 |
parent 25919 | 8b1c0d434824 |
child 26086 | 3c243098b64a |
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 |
25965 | 21 |
nat_number_of_def [code inline]: "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'") |
|
70 |
apply (auto simp add: div_nonneg_neg_le0 DIVISION_BY_ZERO_DIV) |
|
71 |
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO) |
|
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'))" |
|
148 |
by (force dest!: neg_nat |
|
149 |
simp del: nat_number_of |
|
150 |
simp add: nat_number_of_def nat_add_distrib [symmetric]) |
|
151 |
||
152 |
||
153 |
subsubsection{*Subtraction *} |
|
154 |
||
155 |
lemma diff_nat_eq_if: |
|
156 |
"nat z - nat z' = |
|
157 |
(if neg z' then nat z |
|
158 |
else let d = z-z' in |
|
159 |
if neg d then 0 else nat d)" |
|
160 |
apply (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0) |
|
161 |
done |
|
162 |
||
163 |
lemma diff_nat_number_of [simp]: |
|
164 |
"(number_of v :: nat) - number_of v' = |
|
165 |
(if neg (number_of v' :: int) then number_of v |
|
166 |
else let d = number_of (v + uminus v') in |
|
167 |
if neg d then 0 else nat d)" |
|
168 |
by (simp del: nat_number_of add: diff_nat_eq_if nat_number_of_def) |
|
169 |
||
170 |
||
171 |
||
172 |
subsubsection{*Multiplication *} |
|
173 |
||
174 |
lemma mult_nat_number_of [simp]: |
|
175 |
"(number_of v :: nat) * number_of v' = |
|
176 |
(if neg (number_of v :: int) then 0 else number_of (v * v'))" |
|
177 |
by (force dest!: neg_nat |
|
178 |
simp del: nat_number_of |
|
179 |
simp add: nat_number_of_def nat_mult_distrib [symmetric]) |
|
180 |
||
181 |
||
182 |
||
183 |
subsubsection{*Quotient *} |
|
184 |
||
185 |
lemma div_nat_number_of [simp]: |
|
186 |
"(number_of v :: nat) div number_of v' = |
|
187 |
(if neg (number_of v :: int) then 0 |
|
188 |
else nat (number_of v div number_of v'))" |
|
189 |
by (force dest!: neg_nat |
|
190 |
simp del: nat_number_of |
|
191 |
simp add: nat_number_of_def nat_div_distrib [symmetric]) |
|
192 |
||
193 |
lemma one_div_nat_number_of [simp]: |
|
194 |
"(Suc 0) div number_of v' = (nat (1 div number_of v'))" |
|
195 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
|
196 |
||
197 |
||
198 |
subsubsection{*Remainder *} |
|
199 |
||
200 |
lemma mod_nat_number_of [simp]: |
|
201 |
"(number_of v :: nat) mod number_of v' = |
|
202 |
(if neg (number_of v :: int) then 0 |
|
203 |
else if neg (number_of v' :: int) then number_of v |
|
204 |
else nat (number_of v mod number_of v'))" |
|
205 |
by (force dest!: neg_nat |
|
206 |
simp del: nat_number_of |
|
207 |
simp add: nat_number_of_def nat_mod_distrib [symmetric]) |
|
208 |
||
209 |
lemma one_mod_nat_number_of [simp]: |
|
210 |
"(Suc 0) mod number_of v' = |
|
211 |
(if neg (number_of v' :: int) then Suc 0 |
|
212 |
else nat (1 mod number_of v'))" |
|
213 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
|
214 |
||
215 |
||
216 |
subsubsection{* Divisibility *} |
|
217 |
||
218 |
lemmas dvd_eq_mod_eq_0_number_of = |
|
219 |
dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard] |
|
220 |
||
221 |
declare dvd_eq_mod_eq_0_number_of [simp] |
|
222 |
||
223 |
ML |
|
224 |
{* |
|
225 |
val nat_number_of_def = thm"nat_number_of_def"; |
|
226 |
||
227 |
val nat_number_of = thm"nat_number_of"; |
|
228 |
val nat_numeral_0_eq_0 = thm"nat_numeral_0_eq_0"; |
|
229 |
val nat_numeral_1_eq_1 = thm"nat_numeral_1_eq_1"; |
|
230 |
val numeral_1_eq_Suc_0 = thm"numeral_1_eq_Suc_0"; |
|
231 |
val numeral_2_eq_2 = thm"numeral_2_eq_2"; |
|
232 |
val nat_div_distrib = thm"nat_div_distrib"; |
|
233 |
val nat_mod_distrib = thm"nat_mod_distrib"; |
|
234 |
val int_nat_number_of = thm"int_nat_number_of"; |
|
235 |
val Suc_nat_eq_nat_zadd1 = thm"Suc_nat_eq_nat_zadd1"; |
|
236 |
val Suc_nat_number_of_add = thm"Suc_nat_number_of_add"; |
|
237 |
val Suc_nat_number_of = thm"Suc_nat_number_of"; |
|
238 |
val add_nat_number_of = thm"add_nat_number_of"; |
|
239 |
val diff_nat_eq_if = thm"diff_nat_eq_if"; |
|
240 |
val diff_nat_number_of = thm"diff_nat_number_of"; |
|
241 |
val mult_nat_number_of = thm"mult_nat_number_of"; |
|
242 |
val div_nat_number_of = thm"div_nat_number_of"; |
|
243 |
val mod_nat_number_of = thm"mod_nat_number_of"; |
|
244 |
*} |
|
245 |
||
246 |
||
247 |
subsection{*Comparisons*} |
|
248 |
||
249 |
subsubsection{*Equals (=) *} |
|
250 |
||
251 |
lemma eq_nat_nat_iff: |
|
252 |
"[| (0::int) <= z; 0 <= z' |] ==> (nat z = nat z') = (z=z')" |
|
253 |
by (auto elim!: nonneg_eq_int) |
|
254 |
||
255 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
256 |
lemma eq_nat_number_of [simp]: |
|
257 |
"((number_of v :: nat) = number_of v') = |
|
258 |
(if neg (number_of v :: int) then (iszero (number_of v' :: int) | neg (number_of v' :: int)) |
|
259 |
else if neg (number_of v' :: int) then iszero (number_of v :: int) |
|
260 |
else iszero (number_of (v + uminus v') :: int))" |
|
261 |
apply (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def |
|
262 |
eq_nat_nat_iff eq_number_of_eq nat_0 iszero_def |
|
263 |
split add: split_if cong add: imp_cong) |
|
264 |
apply (simp only: nat_eq_iff nat_eq_iff2) |
|
265 |
apply (simp add: not_neg_eq_ge_0 [symmetric]) |
|
266 |
done |
|
267 |
||
268 |
||
269 |
subsubsection{*Less-than (<) *} |
|
270 |
||
271 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
272 |
lemma less_nat_number_of [simp]: |
|
273 |
"((number_of v :: nat) < number_of v') = |
|
274 |
(if neg (number_of v :: int) then neg (number_of (uminus v') :: int) |
|
275 |
else neg (number_of (v + uminus v') :: int))" |
|
276 |
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def |
|
277 |
nat_less_eq_zless less_number_of_eq_neg zless_nat_eq_int_zless |
|
278 |
cong add: imp_cong, simp add: Pls_def) |
|
279 |
||
280 |
||
281 |
(*Maps #n to n for n = 0, 1, 2*) |
|
282 |
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
|
283 |
||
284 |
||
285 |
subsection{*Powers with Numeric Exponents*} |
|
286 |
||
287 |
text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}. |
|
288 |
We cannot prove general results about the numeral @{term "-1"}, so we have to |
|
289 |
use @{term "- 1"} instead.*} |
|
290 |
||
23277 | 291 |
lemma power2_eq_square: "(a::'a::recpower)\<twosuperior> = a * a" |
23164 | 292 |
by (simp add: numeral_2_eq_2 Power.power_Suc) |
293 |
||
23277 | 294 |
lemma zero_power2 [simp]: "(0::'a::{semiring_1,recpower})\<twosuperior> = 0" |
23164 | 295 |
by (simp add: power2_eq_square) |
296 |
||
23277 | 297 |
lemma one_power2 [simp]: "(1::'a::{semiring_1,recpower})\<twosuperior> = 1" |
23164 | 298 |
by (simp add: power2_eq_square) |
299 |
||
300 |
lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x" |
|
301 |
apply (subgoal_tac "3 = Suc (Suc (Suc 0))") |
|
302 |
apply (erule ssubst) |
|
303 |
apply (simp add: power_Suc mult_ac) |
|
304 |
apply (unfold nat_number_of_def) |
|
305 |
apply (subst nat_eq_iff) |
|
306 |
apply simp |
|
307 |
done |
|
308 |
||
309 |
text{*Squares of literal numerals will be evaluated.*} |
|
310 |
lemmas power2_eq_square_number_of = |
|
311 |
power2_eq_square [of "number_of w", standard] |
|
312 |
declare power2_eq_square_number_of [simp] |
|
313 |
||
314 |
||
315 |
lemma zero_le_power2[simp]: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
316 |
by (simp add: power2_eq_square) |
|
317 |
||
318 |
lemma zero_less_power2[simp]: |
|
319 |
"(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))" |
|
320 |
by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
321 |
||
322 |
lemma power2_less_0[simp]: |
|
323 |
fixes a :: "'a::{ordered_idom,recpower}" |
|
324 |
shows "~ (a\<twosuperior> < 0)" |
|
325 |
by (force simp add: power2_eq_square mult_less_0_iff) |
|
326 |
||
327 |
lemma zero_eq_power2[simp]: |
|
328 |
"(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))" |
|
329 |
by (force simp add: power2_eq_square mult_eq_0_iff) |
|
330 |
||
331 |
lemma abs_power2[simp]: |
|
332 |
"abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
333 |
by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
334 |
||
335 |
lemma power2_abs[simp]: |
|
336 |
"(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
337 |
by (simp add: power2_eq_square abs_mult_self) |
|
338 |
||
339 |
lemma power2_minus[simp]: |
|
340 |
"(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})" |
|
341 |
by (simp add: power2_eq_square) |
|
342 |
||
343 |
lemma power2_le_imp_le: |
|
344 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
345 |
shows "\<lbrakk>x\<twosuperior> \<le> y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x \<le> y" |
|
346 |
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
347 |
||
348 |
lemma power2_less_imp_less: |
|
349 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
350 |
shows "\<lbrakk>x\<twosuperior> < y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x < y" |
|
351 |
by (rule power_less_imp_less_base) |
|
352 |
||
353 |
lemma power2_eq_imp_eq: |
|
354 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
355 |
shows "\<lbrakk>x\<twosuperior> = y\<twosuperior>; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> x = y" |
|
356 |
unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base, simp) |
|
357 |
||
358 |
lemma power_minus1_even[simp]: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})" |
|
359 |
apply (induct "n") |
|
360 |
apply (auto simp add: power_Suc power_add) |
|
361 |
done |
|
362 |
||
363 |
lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2" |
|
364 |
by (subst mult_commute) (simp add: power_mult) |
|
365 |
||
366 |
lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2" |
|
367 |
by (simp add: power_even_eq) |
|
368 |
||
369 |
lemma power_minus_even [simp]: |
|
370 |
"(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)" |
|
371 |
by (simp add: power_minus1_even power_minus [of a]) |
|
372 |
||
373 |
lemma zero_le_even_power'[simp]: |
|
374 |
"0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)" |
|
375 |
proof (induct "n") |
|
376 |
case 0 |
|
377 |
show ?case by (simp add: zero_le_one) |
|
378 |
next |
|
379 |
case (Suc n) |
|
380 |
have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
381 |
by (simp add: mult_ac power_add power2_eq_square) |
|
382 |
thus ?case |
|
383 |
by (simp add: prems zero_le_mult_iff) |
|
384 |
qed |
|
385 |
||
386 |
lemma odd_power_less_zero: |
|
387 |
"(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0" |
|
388 |
proof (induct "n") |
|
389 |
case 0 |
|
23389 | 390 |
then show ?case by (simp add: Power.power_Suc) |
23164 | 391 |
next |
392 |
case (Suc n) |
|
23389 | 393 |
have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
394 |
by (simp add: mult_ac power_add power2_eq_square Power.power_Suc) |
|
395 |
thus ?case |
|
396 |
by (simp add: prems mult_less_0_iff mult_neg_neg) |
|
23164 | 397 |
qed |
398 |
||
399 |
lemma odd_0_le_power_imp_0_le: |
|
400 |
"0 \<le> a ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})" |
|
401 |
apply (insert odd_power_less_zero [of a n]) |
|
402 |
apply (force simp add: linorder_not_less [symmetric]) |
|
403 |
done |
|
404 |
||
405 |
text{*Simprules for comparisons where common factors can be cancelled.*} |
|
406 |
lemmas zero_compare_simps = |
|
407 |
add_strict_increasing add_strict_increasing2 add_increasing |
|
408 |
zero_le_mult_iff zero_le_divide_iff |
|
409 |
zero_less_mult_iff zero_less_divide_iff |
|
410 |
mult_le_0_iff divide_le_0_iff |
|
411 |
mult_less_0_iff divide_less_0_iff |
|
412 |
zero_le_power2 power2_less_0 |
|
413 |
||
414 |
subsubsection{*Nat *} |
|
415 |
||
416 |
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" |
|
417 |
by (simp add: numerals) |
|
418 |
||
419 |
(*Expresses a natural number constant as the Suc of another one. |
|
420 |
NOT suitable for rewriting because n recurs in the condition.*) |
|
421 |
lemmas expand_Suc = Suc_pred' [of "number_of v", standard] |
|
422 |
||
423 |
subsubsection{*Arith *} |
|
424 |
||
425 |
lemma Suc_eq_add_numeral_1: "Suc n = n + 1" |
|
426 |
by (simp add: numerals) |
|
427 |
||
428 |
lemma Suc_eq_add_numeral_1_left: "Suc n = 1 + n" |
|
429 |
by (simp add: numerals) |
|
430 |
||
431 |
(* These two can be useful when m = number_of... *) |
|
432 |
||
433 |
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))" |
|
434 |
apply (case_tac "m") |
|
435 |
apply (simp_all add: numerals) |
|
436 |
done |
|
437 |
||
438 |
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))" |
|
439 |
apply (case_tac "m") |
|
440 |
apply (simp_all add: numerals) |
|
441 |
done |
|
442 |
||
443 |
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))" |
|
444 |
apply (case_tac "m") |
|
445 |
apply (simp_all add: numerals) |
|
446 |
done |
|
447 |
||
448 |
||
449 |
subsection{*Comparisons involving (0::nat) *} |
|
450 |
||
451 |
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*} |
|
452 |
||
453 |
lemma eq_number_of_0 [simp]: |
|
454 |
"(number_of v = (0::nat)) = |
|
455 |
(if neg (number_of v :: int) then True else iszero (number_of v :: int))" |
|
456 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0) |
|
457 |
||
458 |
lemma eq_0_number_of [simp]: |
|
459 |
"((0::nat) = number_of v) = |
|
460 |
(if neg (number_of v :: int) then True else iszero (number_of v :: int))" |
|
461 |
by (rule trans [OF eq_sym_conv eq_number_of_0]) |
|
462 |
||
463 |
lemma less_0_number_of [simp]: |
|
464 |
"((0::nat) < number_of v) = neg (number_of (uminus v) :: int)" |
|
465 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] Pls_def) |
|
466 |
||
467 |
||
468 |
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" |
|
469 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0) |
|
470 |
||
471 |
||
472 |
||
473 |
subsection{*Comparisons involving @{term Suc} *} |
|
474 |
||
475 |
lemma eq_number_of_Suc [simp]: |
|
476 |
"(number_of v = Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
477 |
(let pv = number_of (Int.pred v) in |
23164 | 478 |
if neg pv then False else nat pv = n)" |
479 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
480 |
number_of_pred nat_number_of_def |
|
481 |
split add: split_if) |
|
482 |
apply (rule_tac x = "number_of v" in spec) |
|
483 |
apply (auto simp add: nat_eq_iff) |
|
484 |
done |
|
485 |
||
486 |
lemma Suc_eq_number_of [simp]: |
|
487 |
"(Suc n = number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
488 |
(let pv = number_of (Int.pred v) in |
23164 | 489 |
if neg pv then False else nat pv = n)" |
490 |
by (rule trans [OF eq_sym_conv eq_number_of_Suc]) |
|
491 |
||
492 |
lemma less_number_of_Suc [simp]: |
|
493 |
"(number_of v < Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
494 |
(let pv = number_of (Int.pred v) in |
23164 | 495 |
if neg pv then True else nat pv < n)" |
496 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
497 |
number_of_pred nat_number_of_def |
|
498 |
split add: split_if) |
|
499 |
apply (rule_tac x = "number_of v" in spec) |
|
500 |
apply (auto simp add: nat_less_iff) |
|
501 |
done |
|
502 |
||
503 |
lemma less_Suc_number_of [simp]: |
|
504 |
"(Suc n < number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
505 |
(let pv = number_of (Int.pred v) in |
23164 | 506 |
if neg pv then False else n < nat pv)" |
507 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
508 |
number_of_pred nat_number_of_def |
|
509 |
split add: split_if) |
|
510 |
apply (rule_tac x = "number_of v" in spec) |
|
511 |
apply (auto simp add: zless_nat_eq_int_zless) |
|
512 |
done |
|
513 |
||
514 |
lemma le_number_of_Suc [simp]: |
|
515 |
"(number_of v <= Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
516 |
(let pv = number_of (Int.pred v) in |
23164 | 517 |
if neg pv then True else nat pv <= n)" |
518 |
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric]) |
|
519 |
||
520 |
lemma le_Suc_number_of [simp]: |
|
521 |
"(Suc n <= number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
522 |
(let pv = number_of (Int.pred v) in |
23164 | 523 |
if neg pv then False else n <= nat pv)" |
524 |
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric]) |
|
525 |
||
526 |
||
527 |
lemma lemma1: "(m+m = n+n) = (m = (n::int))" |
|
528 |
by auto |
|
529 |
||
530 |
lemma lemma2: "m+m ~= (1::int) + (n + n)" |
|
531 |
apply auto |
|
532 |
apply (drule_tac f = "%x. x mod 2" in arg_cong) |
|
533 |
apply (simp add: zmod_zadd1_eq) |
|
534 |
done |
|
535 |
||
536 |
lemma eq_number_of_BIT_BIT: |
|
537 |
"((number_of (v BIT x) ::int) = number_of (w BIT y)) = |
|
538 |
(x=y & (((number_of v) ::int) = number_of w))" |
|
539 |
apply (simp only: number_of_BIT lemma1 lemma2 eq_commute |
|
540 |
OrderedGroup.add_left_cancel add_assoc OrderedGroup.add_0_left |
|
541 |
split add: bit.split) |
|
542 |
apply simp |
|
543 |
done |
|
544 |
||
545 |
lemma eq_number_of_BIT_Pls: |
|
546 |
"((number_of (v BIT x) ::int) = Numeral0) = |
|
547 |
(x=bit.B0 & (((number_of v) ::int) = Numeral0))" |
|
548 |
apply (simp only: simp_thms add: number_of_BIT number_of_Pls eq_commute |
|
549 |
split add: bit.split cong: imp_cong) |
|
550 |
apply (rule_tac x = "number_of v" in spec, safe) |
|
551 |
apply (simp_all (no_asm_use)) |
|
552 |
apply (drule_tac f = "%x. x mod 2" in arg_cong) |
|
553 |
apply (simp add: zmod_zadd1_eq) |
|
554 |
done |
|
555 |
||
556 |
lemma eq_number_of_BIT_Min: |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
557 |
"((number_of (v BIT x) ::int) = number_of Int.Min) = |
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
558 |
(x=bit.B1 & (((number_of v) ::int) = number_of Int.Min))" |
23164 | 559 |
apply (simp only: simp_thms add: number_of_BIT number_of_Min eq_commute |
560 |
split add: bit.split cong: imp_cong) |
|
561 |
apply (rule_tac x = "number_of v" in spec, auto) |
|
562 |
apply (drule_tac f = "%x. x mod 2" in arg_cong, auto) |
|
563 |
done |
|
564 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
565 |
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" |
23164 | 566 |
by auto |
567 |
||
568 |
||
569 |
||
570 |
subsection{*Max and Min Combined with @{term Suc} *} |
|
571 |
||
572 |
lemma max_number_of_Suc [simp]: |
|
573 |
"max (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
574 |
(let pv = number_of (Int.pred v) in |
23164 | 575 |
if neg pv then Suc n else Suc(max n (nat pv)))" |
576 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
577 |
split add: split_if nat.split) |
|
578 |
apply (rule_tac x = "number_of v" in spec) |
|
579 |
apply auto |
|
580 |
done |
|
581 |
||
582 |
lemma max_Suc_number_of [simp]: |
|
583 |
"max (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
584 |
(let pv = number_of (Int.pred v) in |
23164 | 585 |
if neg pv then Suc n else Suc(max (nat pv) n))" |
586 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
587 |
split add: split_if nat.split) |
|
588 |
apply (rule_tac x = "number_of v" in spec) |
|
589 |
apply auto |
|
590 |
done |
|
591 |
||
592 |
lemma min_number_of_Suc [simp]: |
|
593 |
"min (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
594 |
(let pv = number_of (Int.pred v) in |
23164 | 595 |
if neg pv then 0 else Suc(min n (nat pv)))" |
596 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
597 |
split add: split_if nat.split) |
|
598 |
apply (rule_tac x = "number_of v" in spec) |
|
599 |
apply auto |
|
600 |
done |
|
601 |
||
602 |
lemma min_Suc_number_of [simp]: |
|
603 |
"min (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
604 |
(let pv = number_of (Int.pred v) in |
23164 | 605 |
if neg pv then 0 else Suc(min (nat pv) n))" |
606 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
607 |
split add: split_if nat.split) |
|
608 |
apply (rule_tac x = "number_of v" in spec) |
|
609 |
apply auto |
|
610 |
done |
|
611 |
||
612 |
subsection{*Literal arithmetic involving powers*} |
|
613 |
||
614 |
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n" |
|
615 |
apply (induct "n") |
|
616 |
apply (simp_all (no_asm_simp) add: nat_mult_distrib) |
|
617 |
done |
|
618 |
||
619 |
lemma power_nat_number_of: |
|
620 |
"(number_of v :: nat) ^ n = |
|
621 |
(if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" |
|
622 |
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq |
|
623 |
split add: split_if cong: imp_cong) |
|
624 |
||
625 |
||
626 |
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] |
|
627 |
declare power_nat_number_of_number_of [simp] |
|
628 |
||
629 |
||
630 |
||
23294 | 631 |
text{*For arbitrary rings*} |
23164 | 632 |
|
23294 | 633 |
lemma power_number_of_even: |
634 |
fixes z :: "'a::{number_ring,recpower}" |
|
635 |
shows "z ^ number_of (w BIT bit.B0) = (let w = z ^ (number_of w) in w * w)" |
|
23164 | 636 |
unfolding Let_def nat_number_of_def number_of_BIT bit.cases |
637 |
apply (rule_tac x = "number_of w" in spec, clarify) |
|
638 |
apply (case_tac " (0::int) <= x") |
|
639 |
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square) |
|
640 |
done |
|
641 |
||
23294 | 642 |
lemma power_number_of_odd: |
643 |
fixes z :: "'a::{number_ring,recpower}" |
|
644 |
shows "z ^ number_of (w BIT bit.B1) = (if (0::int) <= number_of w |
|
23164 | 645 |
then (let w = z ^ (number_of w) in z * w * w) else 1)" |
646 |
unfolding Let_def nat_number_of_def number_of_BIT bit.cases |
|
647 |
apply (rule_tac x = "number_of w" in spec, auto) |
|
648 |
apply (simp only: nat_add_distrib nat_mult_distrib) |
|
649 |
apply simp |
|
23294 | 650 |
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat power_Suc) |
23164 | 651 |
done |
652 |
||
23294 | 653 |
lemmas zpower_number_of_even = power_number_of_even [where 'a=int] |
654 |
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] |
|
23164 | 655 |
|
23294 | 656 |
lemmas power_number_of_even_number_of [simp] = |
657 |
power_number_of_even [of "number_of v", standard] |
|
23164 | 658 |
|
23294 | 659 |
lemmas power_number_of_odd_number_of [simp] = |
660 |
power_number_of_odd [of "number_of v", standard] |
|
23164 | 661 |
|
662 |
||
663 |
||
664 |
ML |
|
665 |
{* |
|
25481 | 666 |
val numeral_ss = simpset() addsimps @{thms numerals}; |
23164 | 667 |
|
668 |
val nat_bin_arith_setup = |
|
24093 | 669 |
LinArith.map_data |
23164 | 670 |
(fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} => |
671 |
{add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms, |
|
672 |
inj_thms = inj_thms, |
|
673 |
lessD = lessD, neqE = neqE, |
|
674 |
simpset = simpset addsimps [Suc_nat_number_of, int_nat_number_of, |
|
25481 | 675 |
@{thm not_neg_number_of_Pls}, @{thm neg_number_of_Min}, |
676 |
@{thm neg_number_of_BIT}]}) |
|
23164 | 677 |
*} |
678 |
||
24075 | 679 |
declaration {* K nat_bin_arith_setup *} |
23164 | 680 |
|
681 |
(* Enable arith to deal with div/mod k where k is a numeral: *) |
|
682 |
declare split_div[of _ _ "number_of k", standard, arith_split] |
|
683 |
declare split_mod[of _ _ "number_of k", standard, arith_split] |
|
684 |
||
685 |
lemma nat_number_of_Pls: "Numeral0 = (0::nat)" |
|
686 |
by (simp add: number_of_Pls nat_number_of_def) |
|
687 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
688 |
lemma nat_number_of_Min: "number_of Int.Min = (0::nat)" |
23164 | 689 |
apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) |
690 |
done |
|
691 |
||
692 |
lemma nat_number_of_BIT_1: |
|
693 |
"number_of (w BIT bit.B1) = |
|
694 |
(if neg (number_of w :: int) then 0 |
|
695 |
else let n = number_of w in Suc (n + n))" |
|
696 |
apply (simp only: nat_number_of_def Let_def split: split_if) |
|
697 |
apply (intro conjI impI) |
|
698 |
apply (simp add: neg_nat neg_number_of_BIT) |
|
699 |
apply (rule int_int_eq [THEN iffD1]) |
|
700 |
apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms) |
|
701 |
apply (simp only: number_of_BIT zadd_assoc split: bit.split) |
|
702 |
apply simp |
|
703 |
done |
|
704 |
||
705 |
lemma nat_number_of_BIT_0: |
|
706 |
"number_of (w BIT bit.B0) = (let n::nat = number_of w in n + n)" |
|
707 |
apply (simp only: nat_number_of_def Let_def) |
|
708 |
apply (cases "neg (number_of w :: int)") |
|
709 |
apply (simp add: neg_nat neg_number_of_BIT) |
|
710 |
apply (rule int_int_eq [THEN iffD1]) |
|
711 |
apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms) |
|
712 |
apply (simp only: number_of_BIT zadd_assoc) |
|
713 |
apply simp |
|
714 |
done |
|
715 |
||
716 |
lemmas nat_number = |
|
717 |
nat_number_of_Pls nat_number_of_Min |
|
718 |
nat_number_of_BIT_1 nat_number_of_BIT_0 |
|
719 |
||
720 |
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" |
|
721 |
by (simp add: Let_def) |
|
722 |
||
723 |
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring,recpower})" |
|
23294 | 724 |
by (simp add: power_mult power_Suc); |
23164 | 725 |
|
726 |
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring,recpower})" |
|
727 |
by (simp add: power_mult power_Suc); |
|
728 |
||
729 |
||
730 |
subsection{*Literal arithmetic and @{term of_nat}*} |
|
731 |
||
732 |
lemma of_nat_double: |
|
733 |
"0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" |
|
734 |
by (simp only: mult_2 nat_add_distrib of_nat_add) |
|
735 |
||
736 |
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)" |
|
737 |
by (simp only: nat_number_of_def) |
|
738 |
||
739 |
lemma of_nat_number_of_lemma: |
|
740 |
"of_nat (number_of v :: nat) = |
|
741 |
(if 0 \<le> (number_of v :: int) |
|
742 |
then (number_of v :: 'a :: number_ring) |
|
743 |
else 0)" |
|
744 |
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat); |
|
745 |
||
746 |
lemma of_nat_number_of_eq [simp]: |
|
747 |
"of_nat (number_of v :: nat) = |
|
748 |
(if neg (number_of v :: int) then 0 |
|
749 |
else (number_of v :: 'a :: number_ring))" |
|
750 |
by (simp only: of_nat_number_of_lemma neg_def, simp) |
|
751 |
||
752 |
||
753 |
subsection {*Lemmas for the Combination and Cancellation Simprocs*} |
|
754 |
||
755 |
lemma nat_number_of_add_left: |
|
756 |
"number_of v + (number_of v' + (k::nat)) = |
|
757 |
(if neg (number_of v :: int) then number_of v' + k |
|
758 |
else if neg (number_of v' :: int) then number_of v + k |
|
759 |
else number_of (v + v') + k)" |
|
760 |
by simp |
|
761 |
||
762 |
lemma nat_number_of_mult_left: |
|
763 |
"number_of v * (number_of v' * (k::nat)) = |
|
764 |
(if neg (number_of v :: int) then 0 |
|
765 |
else number_of (v * v') * k)" |
|
766 |
by simp |
|
767 |
||
768 |
||
769 |
subsubsection{*For @{text combine_numerals}*} |
|
770 |
||
771 |
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)" |
|
772 |
by (simp add: add_mult_distrib) |
|
773 |
||
774 |
||
775 |
subsubsection{*For @{text cancel_numerals}*} |
|
776 |
||
777 |
lemma nat_diff_add_eq1: |
|
778 |
"j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)" |
|
779 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
780 |
||
781 |
lemma nat_diff_add_eq2: |
|
782 |
"i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))" |
|
783 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
784 |
||
785 |
lemma nat_eq_add_iff1: |
|
786 |
"j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)" |
|
787 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
788 |
||
789 |
lemma nat_eq_add_iff2: |
|
790 |
"i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)" |
|
791 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
792 |
||
793 |
lemma nat_less_add_iff1: |
|
794 |
"j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)" |
|
795 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
796 |
||
797 |
lemma nat_less_add_iff2: |
|
798 |
"i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)" |
|
799 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
800 |
||
801 |
lemma nat_le_add_iff1: |
|
802 |
"j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)" |
|
803 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
804 |
||
805 |
lemma nat_le_add_iff2: |
|
806 |
"i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)" |
|
807 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
808 |
||
809 |
||
810 |
subsubsection{*For @{text cancel_numeral_factors} *} |
|
811 |
||
812 |
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)" |
|
813 |
by auto |
|
814 |
||
815 |
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)" |
|
816 |
by auto |
|
817 |
||
818 |
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)" |
|
819 |
by auto |
|
820 |
||
821 |
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)" |
|
822 |
by auto |
|
823 |
||
23969 | 824 |
lemma nat_mult_dvd_cancel_disj[simp]: |
825 |
"(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))" |
|
826 |
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric]) |
|
827 |
||
828 |
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)" |
|
829 |
by(auto) |
|
830 |
||
23164 | 831 |
|
832 |
subsubsection{*For @{text cancel_factor} *} |
|
833 |
||
834 |
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)" |
|
835 |
by auto |
|
836 |
||
837 |
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)" |
|
838 |
by auto |
|
839 |
||
840 |
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)" |
|
841 |
by auto |
|
842 |
||
23969 | 843 |
lemma nat_mult_div_cancel_disj[simp]: |
23164 | 844 |
"(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)" |
845 |
by (simp add: nat_mult_div_cancel1) |
|
846 |
||
847 |
end |