author | paulson |
Thu, 24 Jun 2004 17:52:02 +0200 | |
changeset 15003 | 6145dd7538d7 |
parent 14738 | 83f1a514dcb4 |
child 15013 | 34264f5e4691 |
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 |
||
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9214
diff
changeset
|
8 |
theory IntArith = Bin |
14259 | 9 |
files ("int_arith1.ML"): |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9214
diff
changeset
|
10 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
11 |
text{*Duplicate: can't understand why it's necessary*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
12 |
declare numeral_0_eq_0 [simp] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
13 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
14 |
subsection{*Instantiating Binary Arithmetic for the Integers*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
15 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
16 |
instance |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
17 |
int :: number .. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
18 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
19 |
primrec (*the type constraint is essential!*) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
20 |
number_of_Pls: "number_of bin.Pls = 0" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
21 |
number_of_Min: "number_of bin.Min = - (1::int)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
22 |
number_of_BIT: "number_of(w BIT x) = (if x then 1 else 0) + |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
23 |
(number_of w) + (number_of w)" |
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 |
declare number_of_Pls [simp del] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
26 |
number_of_Min [simp del] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
27 |
number_of_BIT [simp del] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
28 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
29 |
instance int :: number_ring |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
30 |
proof |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
31 |
show "Numeral0 = (0::int)" by (rule number_of_Pls) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
32 |
show "-1 = - (1::int)" by (rule number_of_Min) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
33 |
fix w :: bin and x :: bool |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
34 |
show "(number_of (w BIT x) :: int) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
35 |
(if x then 1 else 0) + number_of w + number_of w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
36 |
by (rule number_of_BIT) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
37 |
qed |
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 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
40 |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
41 |
subsection{*Inequality Reasoning for the Arithmetic Simproc*} |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
42 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
43 |
lemma add_numeral_0: "Numeral0 + a = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
44 |
by simp |
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 add_numeral_0_right: "a + Numeral0 = (a::'a::number_ring)" |
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 |
lemma mult_numeral_1: "Numeral1 * a = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
50 |
by simp |
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 |
lemma mult_numeral_1_right: "a * Numeral1 = (a::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
53 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
54 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
55 |
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
|
56 |
for 0 and 1 reduces the number of special cases.*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
57 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
58 |
lemmas add_0s = add_numeral_0 add_numeral_0_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
59 |
lemmas mult_1s = mult_numeral_1 mult_numeral_1_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
60 |
mult_minus1 mult_minus1_right |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
61 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
62 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
63 |
subsection{*Special Arithmetic Rules for Abstract 0 and 1*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
64 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
65 |
text{*Arithmetic computations are defined for binary literals, which leaves 0 |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
69 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
70 |
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
|
71 |
by simp |
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 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
74 |
lemmas add_number_of_eq = number_of_add [symmetric] |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
75 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
76 |
text{*Allow 1 on either or both sides*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
80 |
lemmas add_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
81 |
one_add_one_is_two |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
82 |
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
|
83 |
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
|
84 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
85 |
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
|
86 |
lemmas diff_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
90 |
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
|
91 |
lemmas eq_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
97 |
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
|
98 |
lemmas less_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
104 |
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
|
105 |
lemmas le_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
111 |
lemmas arith_special = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
112 |
add_special diff_special eq_special less_special le_special |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
113 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
114 |
|
12023 | 115 |
use "int_arith1.ML" |
116 |
setup int_arith_setup |
|
14259 | 117 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
118 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
119 |
subsection{*Lemmas About Small Numerals*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
120 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
121 |
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
|
122 |
proof - |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
123 |
have "(of_int -1 :: 'a) = of_int (- 1)" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
124 |
also have "... = - of_int 1" by (simp only: of_int_minus) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
125 |
also have "... = -1" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
126 |
finally show ?thesis . |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
127 |
qed |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
128 |
|
14738 | 129 |
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
|
130 |
by (simp add: abs_if) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
131 |
|
14436 | 132 |
lemma abs_power_minus_one [simp]: |
15003 | 133 |
"abs(-1 ^ n) = (1::'a::{ordered_idom,number_ring,recpower})" |
14436 | 134 |
by (simp add: power_abs) |
135 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
136 |
lemma of_int_number_of_eq: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
137 |
"of_int (number_of v) = (number_of v :: 'a :: number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
138 |
apply (induct v) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
139 |
apply (simp_all only: number_of of_int_add, simp_all) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
140 |
done |
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 |
text{*Lemmas for specialist use, NOT as default simprules*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
143 |
lemma mult_2: "2 * z = (z+z::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
144 |
proof - |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
145 |
have "2*z = (1 + 1)*z" by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
146 |
also have "... = z+z" by (simp add: left_distrib) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
147 |
finally show ?thesis . |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
148 |
qed |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
149 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
150 |
lemma mult_2_right: "z * 2 = (z+z::'a::number_ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
151 |
by (subst mult_commute, rule mult_2) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
152 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
153 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
154 |
subsection{*More Inequality Reasoning*} |
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
155 |
|
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
156 |
lemma zless_add1_eq: "(w < z + (1::int)) = (w<z | w=z)" |
14259 | 157 |
by arith |
158 |
||
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
159 |
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
|
160 |
by arith |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
161 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
162 |
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
|
163 |
by arith |
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
164 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
165 |
lemma zle_add1_eq_le [simp]: "(w < z + (1::int)) = (w\<le>z)" |
14259 | 166 |
by arith |
167 |
||
14365
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14353
diff
changeset
|
168 |
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
|
169 |
by arith |
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14353
diff
changeset
|
170 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
171 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
172 |
subsection{*The Functions @{term nat} and @{term int}*} |
14259 | 173 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
174 |
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
|
175 |
@{term "w + - z"}*} |
14259 | 176 |
declare Zero_int_def [symmetric, simp] |
177 |
declare One_int_def [symmetric, simp] |
|
178 |
||
179 |
text{*cooper.ML refers to this theorem*} |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
180 |
lemmas diff_int_def_symmetric = diff_int_def [symmetric, simp] |
14259 | 181 |
|
182 |
lemma nat_0: "nat 0 = 0" |
|
183 |
by (simp add: nat_eq_iff) |
|
184 |
||
185 |
lemma nat_1: "nat 1 = Suc 0" |
|
186 |
by (subst nat_eq_iff, simp) |
|
187 |
||
188 |
lemma nat_2: "nat 2 = Suc (Suc 0)" |
|
189 |
by (subst nat_eq_iff, simp) |
|
190 |
||
191 |
text{*This simplifies expressions of the form @{term "int n = z"} where |
|
192 |
z is an integer literal.*} |
|
193 |
declare int_eq_iff [of _ "number_of v", standard, simp] |
|
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13685
diff
changeset
|
194 |
|
14295 | 195 |
lemma split_nat [arith_split]: |
14259 | 196 |
"P(nat(i::int)) = ((\<forall>n. i = int n \<longrightarrow> P n) & (i < 0 \<longrightarrow> P 0))" |
13575 | 197 |
(is "?P = (?L & ?R)") |
198 |
proof (cases "i < 0") |
|
199 |
case True thus ?thesis by simp |
|
200 |
next |
|
201 |
case False |
|
202 |
have "?P = ?L" |
|
203 |
proof |
|
204 |
assume ?P thus ?L using False by clarsimp |
|
205 |
next |
|
206 |
assume ?L thus ?P using False by simp |
|
207 |
qed |
|
208 |
with False show ?thesis by simp |
|
209 |
qed |
|
210 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
211 |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
212 |
(*Analogous to zadd_int*) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
213 |
lemma zdiff_int: "n \<le> m ==> int m - int n = int (m-n)" |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
214 |
by (induct m n rule: diff_induct, simp_all) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
215 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
216 |
lemma nat_mult_distrib: "(0::int) \<le> z ==> nat (z*z') = nat z * nat z'" |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
217 |
apply (case_tac "0 \<le> z'") |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
218 |
apply (rule inj_int [THEN injD]) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
219 |
apply (simp add: zmult_int [symmetric] zero_le_mult_iff) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
220 |
apply (simp add: mult_le_0_iff) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
221 |
done |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
222 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
223 |
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
|
224 |
apply (rule trans) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
225 |
apply (rule_tac [2] nat_mult_distrib, auto) |
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 |
lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)" |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
229 |
apply (case_tac "z=0 | w=0") |
15003 | 230 |
apply (auto simp add: abs_if nat_mult_distrib [symmetric] |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
231 |
nat_mult_distrib_neg [symmetric] mult_less_0_iff) |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
232 |
done |
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
233 |
|
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
234 |
|
13685 | 235 |
subsubsection "Induction principles for int" |
236 |
||
237 |
(* `set:int': dummy construction *) |
|
238 |
theorem int_ge_induct[case_names base step,induct set:int]: |
|
239 |
assumes ge: "k \<le> (i::int)" and |
|
240 |
base: "P(k)" and |
|
241 |
step: "\<And>i. \<lbrakk>k \<le> i; P i\<rbrakk> \<Longrightarrow> P(i+1)" |
|
242 |
shows "P i" |
|
243 |
proof - |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
244 |
{ fix n have "\<And>i::int. n = nat(i-k) \<Longrightarrow> k \<le> i \<Longrightarrow> P i" |
13685 | 245 |
proof (induct n) |
246 |
case 0 |
|
247 |
hence "i = k" by arith |
|
248 |
thus "P i" using base by simp |
|
249 |
next |
|
250 |
case (Suc n) |
|
251 |
hence "n = nat((i - 1) - k)" by arith |
|
252 |
moreover |
|
253 |
have ki1: "k \<le> i - 1" using Suc.prems by arith |
|
254 |
ultimately |
|
255 |
have "P(i - 1)" by(rule Suc.hyps) |
|
256 |
from step[OF ki1 this] show ?case by simp |
|
257 |
qed |
|
258 |
} |
|
14473 | 259 |
with ge show ?thesis by fast |
13685 | 260 |
qed |
261 |
||
262 |
(* `set:int': dummy construction *) |
|
263 |
theorem int_gr_induct[case_names base step,induct set:int]: |
|
264 |
assumes gr: "k < (i::int)" and |
|
265 |
base: "P(k+1)" and |
|
266 |
step: "\<And>i. \<lbrakk>k < i; P i\<rbrakk> \<Longrightarrow> P(i+1)" |
|
267 |
shows "P i" |
|
268 |
apply(rule int_ge_induct[of "k + 1"]) |
|
269 |
using gr apply arith |
|
270 |
apply(rule base) |
|
14259 | 271 |
apply (rule step, simp+) |
13685 | 272 |
done |
273 |
||
274 |
theorem int_le_induct[consumes 1,case_names base step]: |
|
275 |
assumes le: "i \<le> (k::int)" and |
|
276 |
base: "P(k)" and |
|
277 |
step: "\<And>i. \<lbrakk>i \<le> k; P i\<rbrakk> \<Longrightarrow> P(i - 1)" |
|
278 |
shows "P i" |
|
279 |
proof - |
|
14272
5efbb548107d
Tidying of the integer development; towards removing the
paulson
parents:
14271
diff
changeset
|
280 |
{ fix n have "\<And>i::int. n = nat(k-i) \<Longrightarrow> i \<le> k \<Longrightarrow> P i" |
13685 | 281 |
proof (induct n) |
282 |
case 0 |
|
283 |
hence "i = k" by arith |
|
284 |
thus "P i" using base by simp |
|
285 |
next |
|
286 |
case (Suc n) |
|
287 |
hence "n = nat(k - (i+1))" by arith |
|
288 |
moreover |
|
289 |
have ki1: "i + 1 \<le> k" using Suc.prems by arith |
|
290 |
ultimately |
|
291 |
have "P(i+1)" by(rule Suc.hyps) |
|
292 |
from step[OF ki1 this] show ?case by simp |
|
293 |
qed |
|
294 |
} |
|
14473 | 295 |
with le show ?thesis by fast |
13685 | 296 |
qed |
297 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
298 |
theorem int_less_induct [consumes 1,case_names base step]: |
13685 | 299 |
assumes less: "(i::int) < k" and |
300 |
base: "P(k - 1)" and |
|
301 |
step: "\<And>i. \<lbrakk>i < k; P i\<rbrakk> \<Longrightarrow> P(i - 1)" |
|
302 |
shows "P i" |
|
303 |
apply(rule int_le_induct[of _ "k - 1"]) |
|
304 |
using less apply arith |
|
305 |
apply(rule base) |
|
14259 | 306 |
apply (rule step, simp+) |
307 |
done |
|
308 |
||
309 |
subsection{*Intermediate value theorems*} |
|
310 |
||
311 |
lemma int_val_lemma: |
|
312 |
"(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) --> |
|
313 |
f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))" |
|
14271 | 314 |
apply (induct_tac "n", simp) |
14259 | 315 |
apply (intro strip) |
316 |
apply (erule impE, simp) |
|
317 |
apply (erule_tac x = n in allE, simp) |
|
318 |
apply (case_tac "k = f (n+1) ") |
|
319 |
apply force |
|
320 |
apply (erule impE) |
|
15003 | 321 |
apply (simp add: abs_if split add: split_if_asm) |
14259 | 322 |
apply (blast intro: le_SucI) |
323 |
done |
|
324 |
||
325 |
lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)] |
|
326 |
||
327 |
lemma nat_intermed_int_val: |
|
328 |
"[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n; |
|
329 |
f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)" |
|
330 |
apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k |
|
331 |
in int_val_lemma) |
|
332 |
apply simp |
|
333 |
apply (erule impE) |
|
334 |
apply (intro strip) |
|
335 |
apply (erule_tac x = "i+m" in allE, arith) |
|
336 |
apply (erule exE) |
|
337 |
apply (rule_tac x = "i+m" in exI, arith) |
|
338 |
done |
|
339 |
||
340 |
||
341 |
subsection{*Products and 1, by T. M. Rasmussen*} |
|
342 |
||
343 |
lemma zmult_eq_self_iff: "(m = m*(n::int)) = (n = 1 | m = 0)" |
|
344 |
apply auto |
|
345 |
apply (subgoal_tac "m*1 = m*n") |
|
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14365
diff
changeset
|
346 |
apply (drule mult_cancel_left [THEN iffD1], auto) |
13685 | 347 |
done |
348 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
349 |
text{*FIXME: tidy*} |
14259 | 350 |
lemma pos_zmult_eq_1_iff: "0 < (m::int) ==> (m * n = 1) = (m = 1 & n = 1)" |
351 |
apply auto |
|
352 |
apply (case_tac "m=1") |
|
353 |
apply (case_tac [2] "n=1") |
|
354 |
apply (case_tac [4] "m=1") |
|
355 |
apply (case_tac [5] "n=1", auto) |
|
356 |
apply (tactic"distinct_subgoals_tac") |
|
357 |
apply (subgoal_tac "1<m*n", simp) |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
358 |
apply (rule less_1_mult, arith) |
14259 | 359 |
apply (subgoal_tac "0<n", arith) |
360 |
apply (subgoal_tac "0<m*n") |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
361 |
apply (drule zero_less_mult_iff [THEN iffD1], auto) |
14259 | 362 |
done |
363 |
||
364 |
lemma zmult_eq_1_iff: "(m*n = (1::int)) = ((m = 1 & n = 1) | (m = -1 & n = -1))" |
|
365 |
apply (case_tac "0<m") |
|
14271 | 366 |
apply (simp add: pos_zmult_eq_1_iff) |
14259 | 367 |
apply (case_tac "m=0") |
14271 | 368 |
apply (simp del: number_of_reorient) |
14259 | 369 |
apply (subgoal_tac "0 < -m") |
370 |
apply (drule_tac n = "-n" in pos_zmult_eq_1_iff, auto) |
|
371 |
done |
|
372 |
||
373 |
||
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14295
diff
changeset
|
374 |
|
14259 | 375 |
ML |
376 |
{* |
|
377 |
val zle_diff1_eq = thm "zle_diff1_eq"; |
|
378 |
val zle_add1_eq_le = thm "zle_add1_eq_le"; |
|
379 |
val nonneg_eq_int = thm "nonneg_eq_int"; |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
380 |
val abs_minus_one = thm "abs_minus_one"; |
14390 | 381 |
val of_int_number_of_eq = thm"of_int_number_of_eq"; |
14259 | 382 |
val nat_eq_iff = thm "nat_eq_iff"; |
383 |
val nat_eq_iff2 = thm "nat_eq_iff2"; |
|
384 |
val nat_less_iff = thm "nat_less_iff"; |
|
385 |
val int_eq_iff = thm "int_eq_iff"; |
|
386 |
val nat_0 = thm "nat_0"; |
|
387 |
val nat_1 = thm "nat_1"; |
|
388 |
val nat_2 = thm "nat_2"; |
|
389 |
val nat_less_eq_zless = thm "nat_less_eq_zless"; |
|
390 |
val nat_le_eq_zle = thm "nat_le_eq_zle"; |
|
391 |
||
392 |
val nat_intermed_int_val = thm "nat_intermed_int_val"; |
|
393 |
val zmult_eq_self_iff = thm "zmult_eq_self_iff"; |
|
394 |
val pos_zmult_eq_1_iff = thm "pos_zmult_eq_1_iff"; |
|
395 |
val zmult_eq_1_iff = thm "zmult_eq_1_iff"; |
|
396 |
val nat_add_distrib = thm "nat_add_distrib"; |
|
397 |
val nat_diff_distrib = thm "nat_diff_distrib"; |
|
398 |
val nat_mult_distrib = thm "nat_mult_distrib"; |
|
399 |
val nat_mult_distrib_neg = thm "nat_mult_distrib_neg"; |
|
400 |
val nat_abs_mult_distrib = thm "nat_abs_mult_distrib"; |
|
401 |
*} |
|
402 |
||
7707 | 403 |
end |