author | haftmann |
Sat, 19 May 2007 11:33:30 +0200 | |
changeset 23024 | 70435ffe077d |
parent 22997 | d4f3b015b50b |
child 23057 | 68b152e8ea86 |
permissions | -rw-r--r-- |
14259 | 1 |
(* Title: HOL/Integ/IntArith.thy |
2 |
ID: $Id$ |
|
3 |
Authors: Larry Paulson and Tobias Nipkow |
|
4 |
*) |
|
12023 | 5 |
|
6 |
header {* Integer arithmetic *} |
|
7 |
||
15131 | 8 |
theory IntArith |
22059 | 9 |
imports Numeral "../Wellfounded_Relations" |
22997 | 10 |
uses "~~/src/Provers/Arith/assoc_fold.ML" ("int_arith1.ML") |
15131 | 11 |
begin |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9214
diff
changeset
|
12 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
13 |
text{*Duplicate: can't understand why it's necessary*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
14 |
declare numeral_0_eq_0 [simp] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
15 |
|
16413 | 16 |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
17 |
subsection{*Inequality Reasoning for the Arithmetic Simproc*} |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
18 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
19 |
lemma add_numeral_0: "Numeral0 + a = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
20 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
21 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
22 |
lemma add_numeral_0_right: "a + Numeral0 = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
23 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
24 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
25 |
lemma mult_numeral_1: "Numeral1 * a = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
26 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
27 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
28 |
lemma mult_numeral_1_right: "a * Numeral1 = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
29 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
30 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
31 |
text{*Theorem lists for the cancellation simprocs. The use of binary numerals |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
32 |
for 0 and 1 reduces the number of special cases.*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
33 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
34 |
lemmas add_0s = add_numeral_0 add_numeral_0_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
35 |
lemmas mult_1s = mult_numeral_1 mult_numeral_1_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
36 |
mult_minus1 mult_minus1_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
37 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
38 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
39 |
subsection{*Special Arithmetic Rules for Abstract 0 and 1*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
40 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
41 |
text{*Arithmetic computations are defined for binary literals, which leaves 0 |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
42 |
and 1 as special cases. Addition already has rules for 0, but not 1. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
43 |
Multiplication and unary minus already have rules for both 0 and 1.*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
44 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
45 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
46 |
lemma binop_eq: "[|f x y = g x y; x = x'; y = y'|] ==> f x' y' = g x' y'" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
47 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
48 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
49 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
50 |
lemmas add_number_of_eq = number_of_add [symmetric] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
51 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
52 |
text{*Allow 1 on either or both sides*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
53 |
lemma one_add_one_is_two: "1 + 1 = (2::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
54 |
by (simp del: numeral_1_eq_1 add: numeral_1_eq_1 [symmetric] add_number_of_eq) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
55 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
56 |
lemmas add_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
57 |
one_add_one_is_two |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
58 |
binop_eq [of "op +", OF add_number_of_eq numeral_1_eq_1 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
59 |
binop_eq [of "op +", OF add_number_of_eq refl numeral_1_eq_1, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
60 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
61 |
text{*Allow 1 on either or both sides (1-1 already simplifies to 0)*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
62 |
lemmas diff_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
63 |
binop_eq [of "op -", OF diff_number_of_eq numeral_1_eq_1 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
64 |
binop_eq [of "op -", OF diff_number_of_eq refl numeral_1_eq_1, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
65 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
66 |
text{*Allow 0 or 1 on either side with a binary numeral on the other*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
67 |
lemmas eq_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
68 |
binop_eq [of "op =", OF eq_number_of_eq numeral_0_eq_0 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
69 |
binop_eq [of "op =", OF eq_number_of_eq numeral_1_eq_1 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
70 |
binop_eq [of "op =", OF eq_number_of_eq refl numeral_0_eq_0, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
71 |
binop_eq [of "op =", OF eq_number_of_eq refl numeral_1_eq_1, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
72 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
73 |
text{*Allow 0 or 1 on either side with a binary numeral on the other*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
74 |
lemmas less_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
75 |
binop_eq [of "op <", OF less_number_of_eq_neg numeral_0_eq_0 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
76 |
binop_eq [of "op <", OF less_number_of_eq_neg numeral_1_eq_1 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
77 |
binop_eq [of "op <", OF less_number_of_eq_neg refl numeral_0_eq_0, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
78 |
binop_eq [of "op <", OF less_number_of_eq_neg refl numeral_1_eq_1, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
79 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
80 |
text{*Allow 0 or 1 on either side with a binary numeral on the other*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
81 |
lemmas le_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
82 |
binop_eq [of "op \<le>", OF le_number_of_eq numeral_0_eq_0 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
83 |
binop_eq [of "op \<le>", OF le_number_of_eq numeral_1_eq_1 refl, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
84 |
binop_eq [of "op \<le>", OF le_number_of_eq refl numeral_0_eq_0, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
85 |
binop_eq [of "op \<le>", OF le_number_of_eq refl numeral_1_eq_1, standard] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
86 |
|
22192 | 87 |
lemmas arith_special[simp] = |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
88 |
add_special diff_special eq_special less_special le_special |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
89 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
90 |
|
22192 | 91 |
lemma min_max_01: "min (0::int) 1 = 0 & min (1::int) 0 = 0 & |
92 |
max (0::int) 1 = 1 & max (1::int) 0 = 1" |
|
93 |
by(simp add:min_def max_def) |
|
94 |
||
95 |
lemmas min_max_special[simp] = |
|
96 |
min_max_01 |
|
97 |
max_def[of "0::int" "number_of v", standard, simp] |
|
98 |
min_def[of "0::int" "number_of v", standard, simp] |
|
99 |
max_def[of "number_of u" "0::int", standard, simp] |
|
100 |
min_def[of "number_of u" "0::int", standard, simp] |
|
101 |
max_def[of "1::int" "number_of v", standard, simp] |
|
102 |
min_def[of "1::int" "number_of v", standard, simp] |
|
103 |
max_def[of "number_of u" "1::int", standard, simp] |
|
104 |
min_def[of "number_of u" "1::int", standard, simp] |
|
105 |
||
12023 | 106 |
use "int_arith1.ML" |
107 |
setup int_arith_setup |
|
14259 | 108 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
109 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
110 |
subsection{*Lemmas About Small Numerals*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
111 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
112 |
lemma of_int_m1 [simp]: "of_int -1 = (-1 :: 'a :: number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
113 |
proof - |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
114 |
have "(of_int -1 :: 'a) = of_int (- 1)" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
115 |
also have "... = - of_int 1" by (simp only: of_int_minus) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
116 |
also have "... = -1" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
117 |
finally show ?thesis . |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
118 |
qed |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
119 |
|
14738 | 120 |
lemma abs_minus_one [simp]: "abs (-1) = (1::'a::{ordered_idom,number_ring})" |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
121 |
by (simp add: abs_if) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
122 |
|
14436 | 123 |
lemma abs_power_minus_one [simp]: |
15003 | 124 |
"abs(-1 ^ n) = (1::'a::{ordered_idom,number_ring,recpower})" |
14436 | 125 |
by (simp add: power_abs) |
126 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
127 |
lemma of_int_number_of_eq: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
128 |
"of_int (number_of v) = (number_of v :: 'a :: number_ring)" |
15013 | 129 |
by (simp add: number_of_eq) |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
130 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
131 |
text{*Lemmas for specialist use, NOT as default simprules*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
132 |
lemma mult_2: "2 * z = (z+z::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
133 |
proof - |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
134 |
have "2*z = (1 + 1)*z" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
135 |
also have "... = z+z" by (simp add: left_distrib) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
136 |
finally show ?thesis . |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
137 |
qed |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
138 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
139 |
lemma mult_2_right: "z * 2 = (z+z::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
140 |
by (subst mult_commute, rule mult_2) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
141 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
142 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
143 |
subsection{*More Inequality Reasoning*} |
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
144 |
|
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
145 |
lemma zless_add1_eq: "(w < z + (1::int)) = (w<z | w=z)" |
14259 | 146 |
by arith |
147 |
||
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
148 |
lemma add1_zle_eq: "(w + (1::int) \<le> z) = (w<z)" |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
149 |
by arith |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
150 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
151 |
lemma zle_diff1_eq [simp]: "(w \<le> z - (1::int)) = (w<z)" |
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
152 |
by arith |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
153 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
154 |
lemma zle_add1_eq_le [simp]: "(w < z + (1::int)) = (w\<le>z)" |
14259 | 155 |
by arith |
156 |
||
14365
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14353
diff
changeset
|
157 |
lemma int_one_le_iff_zero_less: "((1::int) \<le> z) = (0 < z)" |
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14353
diff
changeset
|
158 |
by arith |
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14353
diff
changeset
|
159 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
160 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
161 |
subsection{*The Functions @{term nat} and @{term int}*} |
14259 | 162 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
163 |
text{*Simplify the terms @{term "int 0"}, @{term "int(Suc 0)"} and |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
164 |
@{term "w + - z"}*} |
14259 | 165 |
declare Zero_int_def [symmetric, simp] |
166 |
declare One_int_def [symmetric, simp] |
|
167 |
||
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
168 |
lemmas diff_int_def_symmetric = diff_int_def [symmetric, simp] |
14259 | 169 |
|
170 |
lemma nat_0: "nat 0 = 0" |
|
171 |
by (simp add: nat_eq_iff) |
|
172 |
||
173 |
lemma nat_1: "nat 1 = Suc 0" |
|
174 |
by (subst nat_eq_iff, simp) |
|
175 |
||
176 |
lemma nat_2: "nat 2 = Suc (Suc 0)" |
|
177 |
by (subst nat_eq_iff, simp) |
|
178 |
||
16413 | 179 |
lemma one_less_nat_eq [simp]: "(Suc 0 < nat z) = (1 < z)" |
180 |
apply (insert zless_nat_conj [of 1 z]) |
|
181 |
apply (auto simp add: nat_1) |
|
182 |
done |
|
183 |
||
14259 | 184 |
text{*This simplifies expressions of the form @{term "int n = z"} where |
185 |
z is an integer literal.*} |
|
22801 | 186 |
lemmas int_eq_iff_number_of [simp] = int_eq_iff [of _ "number_of v", standard] |
17085 | 187 |
|
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13685
diff
changeset
|
188 |
|
14295 | 189 |
lemma split_nat [arith_split]: |
14259 | 190 |
"P(nat(i::int)) = ((\<forall>n. i = int n \<longrightarrow> P n) & (i < 0 \<longrightarrow> P 0))" |
13575 | 191 |
(is "?P = (?L & ?R)") |
192 |
proof (cases "i < 0") |
|
193 |
case True thus ?thesis by simp |
|
194 |
next |
|
195 |
case False |
|
196 |
have "?P = ?L" |
|
197 |
proof |
|
198 |
assume ?P thus ?L using False by clarsimp |
|
199 |
next |
|
200 |
assume ?L thus ?P using False by simp |
|
201 |
qed |
|
202 |
with False show ?thesis by simp |
|
203 |
qed |
|
204 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
205 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
206 |
(*Analogous to zadd_int*) |
15013 | 207 |
lemma zdiff_int: "n \<le> m ==> int m - int n = int (m-n)" |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
208 |
by (induct m n rule: diff_induct, simp_all) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
209 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
210 |
lemma nat_mult_distrib: "(0::int) \<le> z ==> nat (z*z') = nat z * nat z'" |
22801 | 211 |
apply (cases "0 \<le> z'") |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
212 |
apply (rule inj_int [THEN injD]) |
16413 | 213 |
apply (simp add: int_mult zero_le_mult_iff) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
214 |
apply (simp add: mult_le_0_iff) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
215 |
done |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
216 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
217 |
lemma nat_mult_distrib_neg: "z \<le> (0::int) ==> nat(z*z') = nat(-z) * nat(-z')" |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
218 |
apply (rule trans) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
219 |
apply (rule_tac [2] nat_mult_distrib, auto) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
220 |
done |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
221 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
222 |
lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)" |
22801 | 223 |
apply (cases "z=0 | w=0") |
15003 | 224 |
apply (auto simp add: abs_if nat_mult_distrib [symmetric] |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
225 |
nat_mult_distrib_neg [symmetric] mult_less_0_iff) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
226 |
done |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
227 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
228 |
|
17472 | 229 |
subsection "Induction principles for int" |
13685 | 230 |
|
22059 | 231 |
text{*Well-founded segments of the integers*} |
232 |
||
233 |
definition |
|
234 |
int_ge_less_than :: "int => (int * int) set" |
|
235 |
where |
|
236 |
"int_ge_less_than d = {(z',z). d \<le> z' & z' < z}" |
|
237 |
||
238 |
theorem wf_int_ge_less_than: "wf (int_ge_less_than d)" |
|
239 |
proof - |
|
240 |
have "int_ge_less_than d \<subseteq> measure (%z. nat (z-d))" |
|
241 |
by (auto simp add: int_ge_less_than_def) |
|
242 |
thus ?thesis |
|
243 |
by (rule wf_subset [OF wf_measure]) |
|
244 |
qed |
|
245 |
||
246 |
text{*This variant looks odd, but is typical of the relations suggested |
|
247 |
by RankFinder.*} |
|
248 |
||
249 |
definition |
|
250 |
int_ge_less_than2 :: "int => (int * int) set" |
|
251 |
where |
|
252 |
"int_ge_less_than2 d = {(z',z). d \<le> z & z' < z}" |
|
253 |
||
254 |
theorem wf_int_ge_less_than2: "wf (int_ge_less_than2 d)" |
|
255 |
proof - |
|
256 |
have "int_ge_less_than2 d \<subseteq> measure (%z. nat (1+z-d))" |
|
257 |
by (auto simp add: int_ge_less_than2_def) |
|
258 |
thus ?thesis |
|
259 |
by (rule wf_subset [OF wf_measure]) |
|
260 |
qed |
|
261 |
||
13685 | 262 |
(* `set:int': dummy construction *) |
263 |
theorem int_ge_induct[case_names base step,induct set:int]: |
|
264 |
assumes ge: "k \<le> (i::int)" and |
|
265 |
base: "P(k)" and |
|
266 |
step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)" |
|
267 |
shows "P i" |
|
268 |
proof - |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
269 |
{ fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k \<le> i \<Longrightarrow> P i" |
13685 | 270 |
proof (induct n) |
271 |
case 0 |
|
272 |
hence "i = k" by arith |
|
273 |
thus "P i" using base by simp |
|
274 |
next |
|
275 |
case (Suc n) |
|
276 |
hence "n = nat((i - 1) - k)" by arith |
|
277 |
moreover |
|
278 |
have ki1: "k \<le> i - 1" using Suc.prems by arith |
|
279 |
ultimately |
|
280 |
have "P(i - 1)" by(rule Suc.hyps) |
|
281 |
from step[OF ki1 this] show ?case by simp |
|
282 |
qed |
|
283 |
} |
|
14473 | 284 |
with ge show ?thesis by fast |
13685 | 285 |
qed |
286 |
||
287 |
(* `set:int': dummy construction *) |
|
288 |
theorem int_gr_induct[case_names base step,induct set:int]: |
|
289 |
assumes gr: "k < (i::int)" and |
|
290 |
base: "P(k+1)" and |
|
291 |
step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)" |
|
292 |
shows "P i" |
|
293 |
apply(rule int_ge_induct[of "k + 1"]) |
|
294 |
using gr apply arith |
|
295 |
apply(rule base) |
|
14259 | 296 |
apply (rule step, simp+) |
13685 | 297 |
done |
298 |
||
299 |
theorem int_le_induct[consumes 1,case_names base step]: |
|
300 |
assumes le: "i \<le> (k::int)" and |
|
301 |
base: "P(k)" and |
|
302 |
step: "\<And>i. \<lbrakk>i \<le> k; P i\<rbrakk> \<Longrightarrow> P(i - 1)" |
|
303 |
shows "P i" |
|
304 |
proof - |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
305 |
{ fix n have "\<And>i::int. n = nat(k-i) \<Longrightarrow> i \<le> k \<Longrightarrow> P i" |
13685 | 306 |
proof (induct n) |
307 |
case 0 |
|
308 |
hence "i = k" by arith |
|
309 |
thus "P i" using base by simp |
|
310 |
next |
|
311 |
case (Suc n) |
|
312 |
hence "n = nat(k - (i+1))" by arith |
|
313 |
moreover |
|
314 |
have ki1: "i + 1 \<le> k" using Suc.prems by arith |
|
315 |
ultimately |
|
316 |
have "P(i+1)" by(rule Suc.hyps) |
|
317 |
from step[OF ki1 this] show ?case by simp |
|
318 |
qed |
|
319 |
} |
|
14473 | 320 |
with le show ?thesis by fast |
13685 | 321 |
qed |
322 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
323 |
theorem int_less_induct [consumes 1,case_names base step]: |
13685 | 324 |
assumes less: "(i::int) < k" and |
325 |
base: "P(k - 1)" and |
|
326 |
step: "\<And>i. \<lbrakk>i < k; P i\<rbrakk> \<Longrightarrow> P(i - 1)" |
|
327 |
shows "P i" |
|
328 |
apply(rule int_le_induct[of _ "k - 1"]) |
|
329 |
using less apply arith |
|
330 |
apply(rule base) |
|
14259 | 331 |
apply (rule step, simp+) |
332 |
done |
|
333 |
||
334 |
subsection{*Intermediate value theorems*} |
|
335 |
||
336 |
lemma int_val_lemma: |
|
337 |
"(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) --> |
|
338 |
f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))" |
|
14271 | 339 |
apply (induct_tac "n", simp) |
14259 | 340 |
apply (intro strip) |
341 |
apply (erule impE, simp) |
|
342 |
apply (erule_tac x = n in allE, simp) |
|
343 |
apply (case_tac "k = f (n+1) ") |
|
344 |
apply force |
|
345 |
apply (erule impE) |
|
15003 | 346 |
apply (simp add: abs_if split add: split_if_asm) |
14259 | 347 |
apply (blast intro: le_SucI) |
348 |
done |
|
349 |
||
350 |
lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)] |
|
351 |
||
352 |
lemma nat_intermed_int_val: |
|
353 |
"[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n; |
|
354 |
f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)" |
|
355 |
apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k |
|
356 |
in int_val_lemma) |
|
357 |
apply simp |
|
358 |
apply (erule exE) |
|
359 |
apply (rule_tac x = "i+m" in exI, arith) |
|
360 |
done |
|
361 |
||
362 |
||
363 |
subsection{*Products and 1, by T. M. Rasmussen*} |
|
364 |
||
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
365 |
lemma zabs_less_one_iff [simp]: "(\<bar>z\<bar> < 1) = (z = (0::int))" |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
366 |
by arith |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
367 |
|
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
368 |
lemma abs_zmult_eq_1: "(\<bar>m * n\<bar> = 1) ==> \<bar>m\<bar> = (1::int)" |
22801 | 369 |
apply (cases "\<bar>n\<bar>=1") |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
370 |
apply (simp add: abs_mult) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
371 |
apply (rule ccontr) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
372 |
apply (auto simp add: linorder_neq_iff abs_mult) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
373 |
apply (subgoal_tac "2 \<le> \<bar>m\<bar> & 2 \<le> \<bar>n\<bar>") |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
374 |
prefer 2 apply arith |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
375 |
apply (subgoal_tac "2*2 \<le> \<bar>m\<bar> * \<bar>n\<bar>", simp) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
376 |
apply (rule mult_mono, auto) |
13685 | 377 |
done |
378 |
||
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
379 |
lemma pos_zmult_eq_1_iff_lemma: "(m * n = 1) ==> m = (1::int) | m = -1" |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
380 |
by (insert abs_zmult_eq_1 [of m n], arith) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
381 |
|
14259 | 382 |
lemma pos_zmult_eq_1_iff: "0 < (m::int) ==> (m * n = 1) = (m = 1 & n = 1)" |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
383 |
apply (auto dest: pos_zmult_eq_1_iff_lemma) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
384 |
apply (simp add: mult_commute [of m]) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
385 |
apply (frule pos_zmult_eq_1_iff_lemma, auto) |
14259 | 386 |
done |
387 |
||
388 |
lemma zmult_eq_1_iff: "(m*n = (1::int)) = ((m = 1 & n = 1) | (m = -1 & n = -1))" |
|
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
389 |
apply (rule iffI) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
390 |
apply (frule pos_zmult_eq_1_iff_lemma) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
391 |
apply (simp add: mult_commute [of m]) |
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15140
diff
changeset
|
392 |
apply (frule pos_zmult_eq_1_iff_lemma, auto) |
14259 | 393 |
done |
394 |
||
20355 | 395 |
|
22997 | 396 |
subsection {* Legacy ML bindings *} |
20699 | 397 |
|
22801 | 398 |
ML {* |
399 |
val of_int_number_of_eq = @{thm of_int_number_of_eq}; |
|
400 |
val nat_0 = @{thm nat_0}; |
|
401 |
val nat_1 = @{thm nat_1}; |
|
14259 | 402 |
*} |
403 |
||
7707 | 404 |
end |