author | paulson |
Mon, 06 Sep 2004 15:57:58 +0200 | |
changeset 15182 | 5cea84e10f3e |
parent 14565 | c6dc17aab88a |
child 16417 | 9bc16273c2d4 |
permissions | -rw-r--r-- |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
1 |
(* Title: ZF/Integ/Int.thy |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
2 |
ID: $Id$ |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
4 |
Copyright 1993 University of Cambridge |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
5 |
|
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
6 |
*) |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
7 |
|
13560 | 8 |
header{*The Integers as Equivalence Classes Over Pairs of Natural Numbers*} |
9 |
||
10 |
theory Int = EquivClass + ArithSimp: |
|
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
11 |
|
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
12 |
constdefs |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
13 |
intrel :: i |
13560 | 14 |
"intrel == {p : (nat*nat)*(nat*nat). |
14511 | 15 |
\<exists>x1 y1 x2 y2. p=<<x1,y1>,<x2,y2>> & x1#+y2 = x2#+y1}" |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
16 |
|
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
17 |
int :: i |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
18 |
"int == (nat*nat)//intrel" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
19 |
|
13560 | 20 |
int_of :: "i=>i" --{*coercion from nat to int*} ("$# _" [80] 80) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
21 |
"$# m == intrel `` {<natify(m), 0>}" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
22 |
|
13560 | 23 |
intify :: "i=>i" --{*coercion from ANYTHING to int*} |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
24 |
"intify(m) == if m : int then m else $#0" |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
25 |
|
13560 | 26 |
raw_zminus :: "i=>i" |
14511 | 27 |
"raw_zminus(z) == \<Union><x,y>\<in>z. intrel``{<y,x>}" |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
28 |
|
13560 | 29 |
zminus :: "i=>i" ("$- _" [80] 80) |
9548 | 30 |
"$- z == raw_zminus (intify(z))" |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
31 |
|
13560 | 32 |
znegative :: "i=>o" |
14511 | 33 |
"znegative(z) == \<exists>x y. x<y & y\<in>nat & <x,y>\<in>z" |
9570
e16e168984e1
installation of cancellation simprocs for the integers
paulson
parents:
9548
diff
changeset
|
34 |
|
13560 | 35 |
iszero :: "i=>o" |
9570
e16e168984e1
installation of cancellation simprocs for the integers
paulson
parents:
9548
diff
changeset
|
36 |
"iszero(z) == z = $# 0" |
e16e168984e1
installation of cancellation simprocs for the integers
paulson
parents:
9548
diff
changeset
|
37 |
|
13560 | 38 |
raw_nat_of :: "i=>i" |
14511 | 39 |
"raw_nat_of(z) == natify (\<Union><x,y>\<in>z. x#-y)" |
9883 | 40 |
|
13560 | 41 |
nat_of :: "i=>i" |
9883 | 42 |
"nat_of(z) == raw_nat_of (intify(z))" |
43 |
||
13560 | 44 |
zmagnitude :: "i=>i" |
45 |
--{*could be replaced by an absolute value function from int to int?*} |
|
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
46 |
"zmagnitude(z) == |
14511 | 47 |
THE m. m\<in>nat & ((~ znegative(z) & z = $# m) | |
9548 | 48 |
(znegative(z) & $- z = $# m))" |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
49 |
|
13560 | 50 |
raw_zmult :: "[i,i]=>i" |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
51 |
(*Cannot use UN<x1,y2> here or in zadd because of the form of congruent2. |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
52 |
Perhaps a "curried" or even polymorphic congruent predicate would be |
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
53 |
better.*) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
54 |
"raw_zmult(z1,z2) == |
14511 | 55 |
\<Union>p1\<in>z1. \<Union>p2\<in>z2. split(%x1 y1. split(%x2 y2. |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
56 |
intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1)" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
57 |
|
13560 | 58 |
zmult :: "[i,i]=>i" (infixl "$*" 70) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
59 |
"z1 $* z2 == raw_zmult (intify(z1),intify(z2))" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
60 |
|
13560 | 61 |
raw_zadd :: "[i,i]=>i" |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
62 |
"raw_zadd (z1, z2) == |
14511 | 63 |
\<Union>z1\<in>z1. \<Union>z2\<in>z2. let <x1,y1>=z1; <x2,y2>=z2 |
5561
426c1e330903
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
diff
changeset
|
64 |
in intrel``{<x1#+x2, y1#+y2>}" |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
65 |
|
13560 | 66 |
zadd :: "[i,i]=>i" (infixl "$+" 65) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
67 |
"z1 $+ z2 == raw_zadd (intify(z1),intify(z2))" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
68 |
|
13560 | 69 |
zdiff :: "[i,i]=>i" (infixl "$-" 65) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
70 |
"z1 $- z2 == z1 $+ zminus(z2)" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
71 |
|
13560 | 72 |
zless :: "[i,i]=>o" (infixl "$<" 50) |
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
73 |
"z1 $< z2 == znegative(z1 $- z2)" |
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
74 |
|
13560 | 75 |
zle :: "[i,i]=>o" (infixl "$<=" 50) |
9570
e16e168984e1
installation of cancellation simprocs for the integers
paulson
parents:
9548
diff
changeset
|
76 |
"z1 $<= z2 == z1 $< z2 | intify(z1)=intify(z2)" |
9548 | 77 |
|
9654
9754ba005b64
X-symbols for ordinal, cardinal, integer arithmetic
paulson
parents:
9578
diff
changeset
|
78 |
|
12114
a8e860c86252
eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents:
11321
diff
changeset
|
79 |
syntax (xsymbols) |
13560 | 80 |
zmult :: "[i,i]=>i" (infixl "$\<times>" 70) |
81 |
zle :: "[i,i]=>o" (infixl "$\<le>" 50) --{*less than or equals*} |
|
9654
9754ba005b64
X-symbols for ordinal, cardinal, integer arithmetic
paulson
parents:
9578
diff
changeset
|
82 |
|
9964 | 83 |
syntax (HTML output) |
13560 | 84 |
zmult :: "[i,i]=>i" (infixl "$\<times>" 70) |
14565 | 85 |
zle :: "[i,i]=>o" (infixl "$\<le>" 50) |
13560 | 86 |
|
87 |
||
88 |
declare quotientE [elim!] |
|
89 |
||
90 |
subsection{*Proving that @{term intrel} is an equivalence relation*} |
|
91 |
||
92 |
(** Natural deduction for intrel **) |
|
93 |
||
94 |
lemma intrel_iff [simp]: |
|
95 |
"<<x1,y1>,<x2,y2>>: intrel <-> |
|
14511 | 96 |
x1\<in>nat & y1\<in>nat & x2\<in>nat & y2\<in>nat & x1#+y2 = x2#+y1" |
97 |
by (simp add: intrel_def) |
|
13560 | 98 |
|
99 |
lemma intrelI [intro!]: |
|
14511 | 100 |
"[| x1#+y2 = x2#+y1; x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] |
13560 | 101 |
==> <<x1,y1>,<x2,y2>>: intrel" |
14511 | 102 |
by (simp add: intrel_def) |
13560 | 103 |
|
104 |
lemma intrelE [elim!]: |
|
105 |
"[| p: intrel; |
|
106 |
!!x1 y1 x2 y2. [| p = <<x1,y1>,<x2,y2>>; x1#+y2 = x2#+y1; |
|
14511 | 107 |
x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] ==> Q |] |
13560 | 108 |
==> Q" |
14511 | 109 |
by (simp add: intrel_def, blast) |
13560 | 110 |
|
111 |
lemma int_trans_lemma: |
|
112 |
"[| x1 #+ y2 = x2 #+ y1; x2 #+ y3 = x3 #+ y2 |] ==> x1 #+ y3 = x3 #+ y1" |
|
113 |
apply (rule sym) |
|
114 |
apply (erule add_left_cancel)+ |
|
115 |
apply (simp_all (no_asm_simp)) |
|
116 |
done |
|
117 |
||
118 |
lemma equiv_intrel: "equiv(nat*nat, intrel)" |
|
14511 | 119 |
apply (simp add: equiv_def refl_def sym_def trans_def) |
13560 | 120 |
apply (fast elim!: sym int_trans_lemma) |
121 |
done |
|
122 |
||
14511 | 123 |
lemma image_intrel_int: "[| m\<in>nat; n\<in>nat |] ==> intrel `` {<m,n>} : int" |
124 |
by (simp add: int_def) |
|
13560 | 125 |
|
126 |
declare equiv_intrel [THEN eq_equiv_class_iff, simp] |
|
127 |
declare conj_cong [cong] |
|
128 |
||
129 |
lemmas eq_intrelD = eq_equiv_class [OF _ equiv_intrel] |
|
130 |
||
131 |
(** int_of: the injection from nat to int **) |
|
132 |
||
133 |
lemma int_of_type [simp,TC]: "$#m : int" |
|
14511 | 134 |
by (simp add: int_def quotient_def int_of_def, auto) |
13560 | 135 |
|
136 |
lemma int_of_eq [iff]: "($# m = $# n) <-> natify(m)=natify(n)" |
|
14511 | 137 |
by (simp add: int_of_def) |
13560 | 138 |
|
14511 | 139 |
lemma int_of_inject: "[| $#m = $#n; m\<in>nat; n\<in>nat |] ==> m=n" |
13560 | 140 |
by (drule int_of_eq [THEN iffD1], auto) |
141 |
||
142 |
||
143 |
(** intify: coercion from anything to int **) |
|
144 |
||
145 |
lemma intify_in_int [iff,TC]: "intify(x) : int" |
|
146 |
by (simp add: intify_def) |
|
147 |
||
148 |
lemma intify_ident [simp]: "n : int ==> intify(n) = n" |
|
149 |
by (simp add: intify_def) |
|
150 |
||
151 |
||
152 |
subsection{*Collapsing rules: to remove @{term intify} |
|
153 |
from arithmetic expressions*} |
|
154 |
||
155 |
lemma intify_idem [simp]: "intify(intify(x)) = intify(x)" |
|
156 |
by simp |
|
157 |
||
158 |
lemma int_of_natify [simp]: "$# (natify(m)) = $# m" |
|
159 |
by (simp add: int_of_def) |
|
160 |
||
161 |
lemma zminus_intify [simp]: "$- (intify(m)) = $- m" |
|
162 |
by (simp add: zminus_def) |
|
163 |
||
164 |
(** Addition **) |
|
165 |
||
166 |
lemma zadd_intify1 [simp]: "intify(x) $+ y = x $+ y" |
|
167 |
by (simp add: zadd_def) |
|
168 |
||
169 |
lemma zadd_intify2 [simp]: "x $+ intify(y) = x $+ y" |
|
170 |
by (simp add: zadd_def) |
|
171 |
||
172 |
(** Subtraction **) |
|
173 |
||
174 |
lemma zdiff_intify1 [simp]:"intify(x) $- y = x $- y" |
|
175 |
by (simp add: zdiff_def) |
|
176 |
||
177 |
lemma zdiff_intify2 [simp]:"x $- intify(y) = x $- y" |
|
178 |
by (simp add: zdiff_def) |
|
179 |
||
180 |
(** Multiplication **) |
|
181 |
||
182 |
lemma zmult_intify1 [simp]:"intify(x) $* y = x $* y" |
|
183 |
by (simp add: zmult_def) |
|
184 |
||
185 |
lemma zmult_intify2 [simp]:"x $* intify(y) = x $* y" |
|
186 |
by (simp add: zmult_def) |
|
187 |
||
188 |
(** Orderings **) |
|
189 |
||
190 |
lemma zless_intify1 [simp]:"intify(x) $< y <-> x $< y" |
|
191 |
by (simp add: zless_def) |
|
192 |
||
193 |
lemma zless_intify2 [simp]:"x $< intify(y) <-> x $< y" |
|
194 |
by (simp add: zless_def) |
|
195 |
||
196 |
lemma zle_intify1 [simp]:"intify(x) $<= y <-> x $<= y" |
|
197 |
by (simp add: zle_def) |
|
198 |
||
199 |
lemma zle_intify2 [simp]:"x $<= intify(y) <-> x $<= y" |
|
200 |
by (simp add: zle_def) |
|
201 |
||
202 |
||
203 |
subsection{*@{term zminus}: unary negation on @{term int}*} |
|
204 |
||
15182 | 205 |
lemma zminus_congruent: "(%<x,y>. intrel``{<y,x>}) respects intrel" |
14511 | 206 |
by (auto simp add: congruent_def add_ac) |
13560 | 207 |
|
208 |
lemma raw_zminus_type: "z : int ==> raw_zminus(z) : int" |
|
14511 | 209 |
apply (simp add: int_def raw_zminus_def) |
13560 | 210 |
apply (typecheck add: UN_equiv_class_type [OF equiv_intrel zminus_congruent]) |
211 |
done |
|
212 |
||
213 |
lemma zminus_type [TC,iff]: "$-z : int" |
|
14511 | 214 |
by (simp add: zminus_def raw_zminus_type) |
13560 | 215 |
|
216 |
lemma raw_zminus_inject: |
|
217 |
"[| raw_zminus(z) = raw_zminus(w); z: int; w: int |] ==> z=w" |
|
14511 | 218 |
apply (simp add: int_def raw_zminus_def) |
13560 | 219 |
apply (erule UN_equiv_class_inject [OF equiv_intrel zminus_congruent], safe) |
220 |
apply (auto dest: eq_intrelD simp add: add_ac) |
|
221 |
done |
|
222 |
||
223 |
lemma zminus_inject_intify [dest!]: "$-z = $-w ==> intify(z) = intify(w)" |
|
14511 | 224 |
apply (simp add: zminus_def) |
13560 | 225 |
apply (blast dest!: raw_zminus_inject) |
226 |
done |
|
227 |
||
228 |
lemma zminus_inject: "[| $-z = $-w; z: int; w: int |] ==> z=w" |
|
229 |
by auto |
|
230 |
||
231 |
lemma raw_zminus: |
|
14511 | 232 |
"[| x\<in>nat; y\<in>nat |] ==> raw_zminus(intrel``{<x,y>}) = intrel `` {<y,x>}" |
233 |
apply (simp add: raw_zminus_def UN_equiv_class [OF equiv_intrel zminus_congruent]) |
|
13560 | 234 |
done |
235 |
||
236 |
lemma zminus: |
|
14511 | 237 |
"[| x\<in>nat; y\<in>nat |] |
13560 | 238 |
==> $- (intrel``{<x,y>}) = intrel `` {<y,x>}" |
14511 | 239 |
by (simp add: zminus_def raw_zminus image_intrel_int) |
13560 | 240 |
|
241 |
lemma raw_zminus_zminus: "z : int ==> raw_zminus (raw_zminus(z)) = z" |
|
14511 | 242 |
by (auto simp add: int_def raw_zminus) |
13560 | 243 |
|
244 |
lemma zminus_zminus_intify [simp]: "$- ($- z) = intify(z)" |
|
245 |
by (simp add: zminus_def raw_zminus_type raw_zminus_zminus) |
|
246 |
||
247 |
lemma zminus_int0 [simp]: "$- ($#0) = $#0" |
|
14511 | 248 |
by (simp add: int_of_def zminus) |
13560 | 249 |
|
250 |
lemma zminus_zminus: "z : int ==> $- ($- z) = z" |
|
251 |
by simp |
|
252 |
||
253 |
||
254 |
subsection{*@{term znegative}: the test for negative integers*} |
|
255 |
||
14511 | 256 |
lemma znegative: "[| x\<in>nat; y\<in>nat |] ==> znegative(intrel``{<x,y>}) <-> x<y" |
257 |
apply (cases "x<y") |
|
258 |
apply (auto simp add: znegative_def not_lt_iff_le) |
|
259 |
apply (subgoal_tac "y #+ x2 < x #+ y2", force) |
|
260 |
apply (rule add_le_lt_mono, auto) |
|
261 |
done |
|
262 |
||
13560 | 263 |
(*No natural number is negative!*) |
264 |
lemma not_znegative_int_of [iff]: "~ znegative($# n)" |
|
14511 | 265 |
by (simp add: znegative int_of_def) |
13560 | 266 |
|
267 |
lemma znegative_zminus_int_of [simp]: "znegative($- $# succ(n))" |
|
14511 | 268 |
by (simp add: znegative int_of_def zminus natify_succ) |
13560 | 269 |
|
270 |
lemma not_znegative_imp_zero: "~ znegative($- $# n) ==> natify(n)=0" |
|
14511 | 271 |
by (simp add: znegative int_of_def zminus Ord_0_lt_iff [THEN iff_sym]) |
13560 | 272 |
|
273 |
||
274 |
subsection{*@{term nat_of}: Coercion of an Integer to a Natural Number*} |
|
275 |
||
276 |
lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)" |
|
14511 | 277 |
by (simp add: nat_of_def) |
278 |
||
15182 | 279 |
lemma nat_of_congruent: "(\<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x)) respects intrel" |
14511 | 280 |
by (auto simp add: congruent_def split add: nat_diff_split) |
281 |
||
282 |
lemma raw_nat_of: |
|
283 |
"[| x\<in>nat; y\<in>nat |] ==> raw_nat_of(intrel``{<x,y>}) = x#-y" |
|
284 |
by (simp add: raw_nat_of_def UN_equiv_class [OF equiv_intrel nat_of_congruent]) |
|
285 |
||
286 |
lemma raw_nat_of_int_of: "raw_nat_of($# n) = natify(n)" |
|
287 |
by (simp add: int_of_def raw_nat_of) |
|
13560 | 288 |
|
289 |
lemma nat_of_int_of [simp]: "nat_of($# n) = natify(n)" |
|
14511 | 290 |
by (simp add: raw_nat_of_int_of nat_of_def) |
13560 | 291 |
|
14511 | 292 |
lemma raw_nat_of_type: "raw_nat_of(z) \<in> nat" |
293 |
by (simp add: raw_nat_of_def) |
|
13560 | 294 |
|
14511 | 295 |
lemma nat_of_type [iff,TC]: "nat_of(z) \<in> nat" |
296 |
by (simp add: nat_of_def raw_nat_of_type) |
|
13560 | 297 |
|
298 |
subsection{*zmagnitude: magnitide of an integer, as a natural number*} |
|
299 |
||
300 |
lemma zmagnitude_int_of [simp]: "zmagnitude($# n) = natify(n)" |
|
14511 | 301 |
by (auto simp add: zmagnitude_def int_of_eq) |
13560 | 302 |
|
303 |
lemma natify_int_of_eq: "natify(x)=n ==> $#x = $# n" |
|
304 |
apply (drule sym) |
|
305 |
apply (simp (no_asm_simp) add: int_of_eq) |
|
306 |
done |
|
307 |
||
308 |
lemma zmagnitude_zminus_int_of [simp]: "zmagnitude($- $# n) = natify(n)" |
|
14511 | 309 |
apply (simp add: zmagnitude_def) |
13560 | 310 |
apply (rule the_equality) |
311 |
apply (auto dest!: not_znegative_imp_zero natify_int_of_eq |
|
312 |
iff del: int_of_eq, auto) |
|
313 |
done |
|
314 |
||
14511 | 315 |
lemma zmagnitude_type [iff,TC]: "zmagnitude(z)\<in>nat" |
316 |
apply (simp add: zmagnitude_def) |
|
13560 | 317 |
apply (rule theI2, auto) |
318 |
done |
|
319 |
||
320 |
lemma not_zneg_int_of: |
|
14511 | 321 |
"[| z: int; ~ znegative(z) |] ==> \<exists>n\<in>nat. z = $# n" |
322 |
apply (auto simp add: int_def znegative int_of_def not_lt_iff_le) |
|
323 |
apply (rename_tac x y) |
|
324 |
apply (rule_tac x="x#-y" in bexI) |
|
325 |
apply (auto simp add: add_diff_inverse2) |
|
13560 | 326 |
done |
327 |
||
328 |
lemma not_zneg_mag [simp]: |
|
329 |
"[| z: int; ~ znegative(z) |] ==> $# (zmagnitude(z)) = z" |
|
330 |
by (drule not_zneg_int_of, auto) |
|
331 |
||
332 |
lemma zneg_int_of: |
|
14511 | 333 |
"[| znegative(z); z: int |] ==> \<exists>n\<in>nat. z = $- ($# succ(n))" |
334 |
by (auto simp add: int_def znegative zminus int_of_def dest!: less_imp_succ_add) |
|
13560 | 335 |
|
336 |
lemma zneg_mag [simp]: |
|
337 |
"[| znegative(z); z: int |] ==> $# (zmagnitude(z)) = $- z" |
|
14511 | 338 |
by (drule zneg_int_of, auto) |
13560 | 339 |
|
14511 | 340 |
lemma int_cases: "z : int ==> \<exists>n\<in>nat. z = $# n | z = $- ($# succ(n))" |
13560 | 341 |
apply (case_tac "znegative (z) ") |
342 |
prefer 2 apply (blast dest: not_zneg_mag sym) |
|
343 |
apply (blast dest: zneg_int_of) |
|
344 |
done |
|
345 |
||
346 |
lemma not_zneg_raw_nat_of: |
|
347 |
"[| ~ znegative(z); z: int |] ==> $# (raw_nat_of(z)) = z" |
|
348 |
apply (drule not_zneg_int_of) |
|
14511 | 349 |
apply (auto simp add: raw_nat_of_type raw_nat_of_int_of) |
13560 | 350 |
done |
351 |
||
352 |
lemma not_zneg_nat_of_intify: |
|
353 |
"~ znegative(intify(z)) ==> $# (nat_of(z)) = intify(z)" |
|
354 |
by (simp (no_asm_simp) add: nat_of_def not_zneg_raw_nat_of) |
|
355 |
||
356 |
lemma not_zneg_nat_of: "[| ~ znegative(z); z: int |] ==> $# (nat_of(z)) = z" |
|
357 |
apply (simp (no_asm_simp) add: not_zneg_nat_of_intify) |
|
358 |
done |
|
359 |
||
360 |
lemma zneg_nat_of [simp]: "znegative(intify(z)) ==> nat_of(z) = 0" |
|
14511 | 361 |
apply (subgoal_tac "intify(z) \<in> int") |
362 |
apply (simp add: int_def) |
|
363 |
apply (auto simp add: znegative nat_of_def raw_nat_of |
|
364 |
split add: nat_diff_split) |
|
365 |
done |
|
13560 | 366 |
|
367 |
||
368 |
subsection{*@{term zadd}: addition on int*} |
|
369 |
||
370 |
text{*Congruence Property for Addition*} |
|
371 |
lemma zadd_congruent2: |
|
15182 | 372 |
"(%z1 z2. let <x1,y1>=z1; <x2,y2>=z2 |
373 |
in intrel``{<x1#+x2, y1#+y2>}) |
|
374 |
respects2 intrel" |
|
14511 | 375 |
apply (simp add: congruent2_def) |
13560 | 376 |
(*Proof via congruent2_commuteI seems longer*) |
377 |
apply safe |
|
378 |
apply (simp (no_asm_simp) add: add_assoc Let_def) |
|
379 |
(*The rest should be trivial, but rearranging terms is hard |
|
380 |
add_ac does not help rewriting with the assumptions.*) |
|
381 |
apply (rule_tac m1 = x1a in add_left_commute [THEN ssubst]) |
|
382 |
apply (rule_tac m1 = x2a in add_left_commute [THEN ssubst]) |
|
383 |
apply (simp (no_asm_simp) add: add_assoc [symmetric]) |
|
384 |
done |
|
385 |
||
386 |
lemma raw_zadd_type: "[| z: int; w: int |] ==> raw_zadd(z,w) : int" |
|
14511 | 387 |
apply (simp add: int_def raw_zadd_def) |
13560 | 388 |
apply (rule UN_equiv_class_type2 [OF equiv_intrel zadd_congruent2], assumption+) |
389 |
apply (simp add: Let_def) |
|
390 |
done |
|
391 |
||
392 |
lemma zadd_type [iff,TC]: "z $+ w : int" |
|
393 |
by (simp add: zadd_def raw_zadd_type) |
|
394 |
||
395 |
lemma raw_zadd: |
|
14511 | 396 |
"[| x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] |
13560 | 397 |
==> raw_zadd (intrel``{<x1,y1>}, intrel``{<x2,y2>}) = |
398 |
intrel `` {<x1#+x2, y1#+y2>}" |
|
15182 | 399 |
apply (simp add: raw_zadd_def |
400 |
UN_equiv_class2 [OF equiv_intrel equiv_intrel zadd_congruent2]) |
|
13560 | 401 |
apply (simp add: Let_def) |
402 |
done |
|
403 |
||
404 |
lemma zadd: |
|
14511 | 405 |
"[| x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] |
13560 | 406 |
==> (intrel``{<x1,y1>}) $+ (intrel``{<x2,y2>}) = |
407 |
intrel `` {<x1#+x2, y1#+y2>}" |
|
14511 | 408 |
by (simp add: zadd_def raw_zadd image_intrel_int) |
13560 | 409 |
|
410 |
lemma raw_zadd_int0: "z : int ==> raw_zadd ($#0,z) = z" |
|
14511 | 411 |
by (auto simp add: int_def int_of_def raw_zadd) |
13560 | 412 |
|
413 |
lemma zadd_int0_intify [simp]: "$#0 $+ z = intify(z)" |
|
414 |
by (simp add: zadd_def raw_zadd_int0) |
|
415 |
||
416 |
lemma zadd_int0: "z: int ==> $#0 $+ z = z" |
|
417 |
by simp |
|
418 |
||
419 |
lemma raw_zminus_zadd_distrib: |
|
420 |
"[| z: int; w: int |] ==> $- raw_zadd(z,w) = raw_zadd($- z, $- w)" |
|
14511 | 421 |
by (auto simp add: zminus raw_zadd int_def) |
13560 | 422 |
|
423 |
lemma zminus_zadd_distrib [simp]: "$- (z $+ w) = $- z $+ $- w" |
|
424 |
by (simp add: zadd_def raw_zminus_zadd_distrib) |
|
425 |
||
426 |
lemma raw_zadd_commute: |
|
427 |
"[| z: int; w: int |] ==> raw_zadd(z,w) = raw_zadd(w,z)" |
|
14511 | 428 |
by (auto simp add: raw_zadd add_ac int_def) |
13560 | 429 |
|
430 |
lemma zadd_commute: "z $+ w = w $+ z" |
|
431 |
by (simp add: zadd_def raw_zadd_commute) |
|
432 |
||
433 |
lemma raw_zadd_assoc: |
|
434 |
"[| z1: int; z2: int; z3: int |] |
|
435 |
==> raw_zadd (raw_zadd(z1,z2),z3) = raw_zadd(z1,raw_zadd(z2,z3))" |
|
14511 | 436 |
by (auto simp add: int_def raw_zadd add_assoc) |
13560 | 437 |
|
438 |
lemma zadd_assoc: "(z1 $+ z2) $+ z3 = z1 $+ (z2 $+ z3)" |
|
439 |
by (simp add: zadd_def raw_zadd_type raw_zadd_assoc) |
|
440 |
||
441 |
(*For AC rewriting*) |
|
442 |
lemma zadd_left_commute: "z1$+(z2$+z3) = z2$+(z1$+z3)" |
|
443 |
apply (simp add: zadd_assoc [symmetric]) |
|
444 |
apply (simp add: zadd_commute) |
|
445 |
done |
|
446 |
||
447 |
(*Integer addition is an AC operator*) |
|
448 |
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute |
|
449 |
||
450 |
lemma int_of_add: "$# (m #+ n) = ($#m) $+ ($#n)" |
|
14511 | 451 |
by (simp add: int_of_def zadd) |
13560 | 452 |
|
453 |
lemma int_succ_int_1: "$# succ(m) = $# 1 $+ ($# m)" |
|
454 |
by (simp add: int_of_add [symmetric] natify_succ) |
|
455 |
||
456 |
lemma int_of_diff: |
|
14511 | 457 |
"[| m\<in>nat; n le m |] ==> $# (m #- n) = ($#m) $- ($#n)" |
458 |
apply (simp add: int_of_def zdiff_def) |
|
13560 | 459 |
apply (frule lt_nat_in_nat) |
460 |
apply (simp_all add: zadd zminus add_diff_inverse2) |
|
461 |
done |
|
462 |
||
463 |
lemma raw_zadd_zminus_inverse: "z : int ==> raw_zadd (z, $- z) = $#0" |
|
14511 | 464 |
by (auto simp add: int_def int_of_def zminus raw_zadd add_commute) |
13560 | 465 |
|
466 |
lemma zadd_zminus_inverse [simp]: "z $+ ($- z) = $#0" |
|
467 |
apply (simp add: zadd_def) |
|
468 |
apply (subst zminus_intify [symmetric]) |
|
469 |
apply (rule intify_in_int [THEN raw_zadd_zminus_inverse]) |
|
470 |
done |
|
471 |
||
472 |
lemma zadd_zminus_inverse2 [simp]: "($- z) $+ z = $#0" |
|
473 |
by (simp add: zadd_commute zadd_zminus_inverse) |
|
474 |
||
475 |
lemma zadd_int0_right_intify [simp]: "z $+ $#0 = intify(z)" |
|
476 |
by (rule trans [OF zadd_commute zadd_int0_intify]) |
|
477 |
||
478 |
lemma zadd_int0_right: "z:int ==> z $+ $#0 = z" |
|
479 |
by simp |
|
480 |
||
481 |
||
482 |
subsection{*@{term zmult}: Integer Multiplication*} |
|
483 |
||
484 |
text{*Congruence property for multiplication*} |
|
485 |
lemma zmult_congruent2: |
|
15182 | 486 |
"(%p1 p2. split(%x1 y1. split(%x2 y2. |
487 |
intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1)) |
|
488 |
respects2 intrel" |
|
13560 | 489 |
apply (rule equiv_intrel [THEN congruent2_commuteI], auto) |
490 |
(*Proof that zmult is congruent in one argument*) |
|
491 |
apply (rename_tac x y) |
|
492 |
apply (frule_tac t = "%u. x#*u" in sym [THEN subst_context]) |
|
493 |
apply (drule_tac t = "%u. y#*u" in subst_context) |
|
494 |
apply (erule add_left_cancel)+ |
|
495 |
apply (simp_all add: add_mult_distrib_left) |
|
496 |
done |
|
497 |
||
498 |
||
499 |
lemma raw_zmult_type: "[| z: int; w: int |] ==> raw_zmult(z,w) : int" |
|
14511 | 500 |
apply (simp add: int_def raw_zmult_def) |
13560 | 501 |
apply (rule UN_equiv_class_type2 [OF equiv_intrel zmult_congruent2], assumption+) |
502 |
apply (simp add: Let_def) |
|
503 |
done |
|
504 |
||
505 |
lemma zmult_type [iff,TC]: "z $* w : int" |
|
506 |
by (simp add: zmult_def raw_zmult_type) |
|
507 |
||
508 |
lemma raw_zmult: |
|
14511 | 509 |
"[| x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] |
13560 | 510 |
==> raw_zmult(intrel``{<x1,y1>}, intrel``{<x2,y2>}) = |
511 |
intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}" |
|
15182 | 512 |
by (simp add: raw_zmult_def |
513 |
UN_equiv_class2 [OF equiv_intrel equiv_intrel zmult_congruent2]) |
|
13560 | 514 |
|
515 |
lemma zmult: |
|
14511 | 516 |
"[| x1\<in>nat; y1\<in>nat; x2\<in>nat; y2\<in>nat |] |
13560 | 517 |
==> (intrel``{<x1,y1>}) $* (intrel``{<x2,y2>}) = |
518 |
intrel `` {<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}" |
|
14511 | 519 |
by (simp add: zmult_def raw_zmult image_intrel_int) |
13560 | 520 |
|
521 |
lemma raw_zmult_int0: "z : int ==> raw_zmult ($#0,z) = $#0" |
|
14511 | 522 |
by (auto simp add: int_def int_of_def raw_zmult) |
13560 | 523 |
|
524 |
lemma zmult_int0 [simp]: "$#0 $* z = $#0" |
|
525 |
by (simp add: zmult_def raw_zmult_int0) |
|
526 |
||
527 |
lemma raw_zmult_int1: "z : int ==> raw_zmult ($#1,z) = z" |
|
14511 | 528 |
by (auto simp add: int_def int_of_def raw_zmult) |
13560 | 529 |
|
530 |
lemma zmult_int1_intify [simp]: "$#1 $* z = intify(z)" |
|
531 |
by (simp add: zmult_def raw_zmult_int1) |
|
532 |
||
533 |
lemma zmult_int1: "z : int ==> $#1 $* z = z" |
|
534 |
by simp |
|
535 |
||
536 |
lemma raw_zmult_commute: |
|
537 |
"[| z: int; w: int |] ==> raw_zmult(z,w) = raw_zmult(w,z)" |
|
14511 | 538 |
by (auto simp add: int_def raw_zmult add_ac mult_ac) |
13560 | 539 |
|
540 |
lemma zmult_commute: "z $* w = w $* z" |
|
541 |
by (simp add: zmult_def raw_zmult_commute) |
|
542 |
||
543 |
lemma raw_zmult_zminus: |
|
544 |
"[| z: int; w: int |] ==> raw_zmult($- z, w) = $- raw_zmult(z, w)" |
|
14511 | 545 |
by (auto simp add: int_def zminus raw_zmult add_ac) |
13560 | 546 |
|
547 |
lemma zmult_zminus [simp]: "($- z) $* w = $- (z $* w)" |
|
548 |
apply (simp add: zmult_def raw_zmult_zminus) |
|
549 |
apply (subst zminus_intify [symmetric], rule raw_zmult_zminus, auto) |
|
550 |
done |
|
551 |
||
552 |
lemma zmult_zminus_right [simp]: "w $* ($- z) = $- (w $* z)" |
|
553 |
by (simp add: zmult_commute [of w]) |
|
554 |
||
555 |
lemma raw_zmult_assoc: |
|
556 |
"[| z1: int; z2: int; z3: int |] |
|
557 |
==> raw_zmult (raw_zmult(z1,z2),z3) = raw_zmult(z1,raw_zmult(z2,z3))" |
|
14511 | 558 |
by (auto simp add: int_def raw_zmult add_mult_distrib_left add_ac mult_ac) |
13560 | 559 |
|
560 |
lemma zmult_assoc: "(z1 $* z2) $* z3 = z1 $* (z2 $* z3)" |
|
561 |
by (simp add: zmult_def raw_zmult_type raw_zmult_assoc) |
|
562 |
||
563 |
(*For AC rewriting*) |
|
564 |
lemma zmult_left_commute: "z1$*(z2$*z3) = z2$*(z1$*z3)" |
|
565 |
apply (simp add: zmult_assoc [symmetric]) |
|
566 |
apply (simp add: zmult_commute) |
|
567 |
done |
|
568 |
||
569 |
(*Integer multiplication is an AC operator*) |
|
570 |
lemmas zmult_ac = zmult_assoc zmult_commute zmult_left_commute |
|
571 |
||
572 |
lemma raw_zadd_zmult_distrib: |
|
573 |
"[| z1: int; z2: int; w: int |] |
|
574 |
==> raw_zmult(raw_zadd(z1,z2), w) = |
|
575 |
raw_zadd (raw_zmult(z1,w), raw_zmult(z2,w))" |
|
14511 | 576 |
by (auto simp add: int_def raw_zadd raw_zmult add_mult_distrib_left add_ac mult_ac) |
13560 | 577 |
|
578 |
lemma zadd_zmult_distrib: "(z1 $+ z2) $* w = (z1 $* w) $+ (z2 $* w)" |
|
579 |
by (simp add: zmult_def zadd_def raw_zadd_type raw_zmult_type |
|
580 |
raw_zadd_zmult_distrib) |
|
581 |
||
582 |
lemma zadd_zmult_distrib2: "w $* (z1 $+ z2) = (w $* z1) $+ (w $* z2)" |
|
583 |
by (simp add: zmult_commute [of w] zadd_zmult_distrib) |
|
584 |
||
585 |
lemmas int_typechecks = |
|
586 |
int_of_type zminus_type zmagnitude_type zadd_type zmult_type |
|
587 |
||
588 |
||
589 |
(*** Subtraction laws ***) |
|
590 |
||
591 |
lemma zdiff_type [iff,TC]: "z $- w : int" |
|
592 |
by (simp add: zdiff_def) |
|
593 |
||
594 |
lemma zminus_zdiff_eq [simp]: "$- (z $- y) = y $- z" |
|
595 |
by (simp add: zdiff_def zadd_commute) |
|
596 |
||
597 |
lemma zdiff_zmult_distrib: "(z1 $- z2) $* w = (z1 $* w) $- (z2 $* w)" |
|
14511 | 598 |
apply (simp add: zdiff_def) |
13560 | 599 |
apply (subst zadd_zmult_distrib) |
600 |
apply (simp add: zmult_zminus) |
|
601 |
done |
|
602 |
||
603 |
lemma zdiff_zmult_distrib2: "w $* (z1 $- z2) = (w $* z1) $- (w $* z2)" |
|
604 |
by (simp add: zmult_commute [of w] zdiff_zmult_distrib) |
|
605 |
||
606 |
lemma zadd_zdiff_eq: "x $+ (y $- z) = (x $+ y) $- z" |
|
607 |
by (simp add: zdiff_def zadd_ac) |
|
608 |
||
609 |
lemma zdiff_zadd_eq: "(x $- y) $+ z = (x $+ z) $- y" |
|
610 |
by (simp add: zdiff_def zadd_ac) |
|
611 |
||
612 |
||
613 |
subsection{*The "Less Than" Relation*} |
|
614 |
||
615 |
(*"Less than" is a linear ordering*) |
|
616 |
lemma zless_linear_lemma: |
|
617 |
"[| z: int; w: int |] ==> z$<w | z=w | w$<z" |
|
14511 | 618 |
apply (simp add: int_def zless_def znegative_def zdiff_def, auto) |
13560 | 619 |
apply (simp add: zadd zminus image_iff Bex_def) |
620 |
apply (rule_tac i = "xb#+ya" and j = "xc #+ y" in Ord_linear_lt) |
|
621 |
apply (force dest!: spec simp add: add_ac)+ |
|
622 |
done |
|
623 |
||
624 |
lemma zless_linear: "z$<w | intify(z)=intify(w) | w$<z" |
|
625 |
apply (cut_tac z = " intify (z) " and w = " intify (w) " in zless_linear_lemma) |
|
626 |
apply auto |
|
627 |
done |
|
628 |
||
629 |
lemma zless_not_refl [iff]: "~ (z$<z)" |
|
14511 | 630 |
by (auto simp add: zless_def znegative_def int_of_def zdiff_def) |
13560 | 631 |
|
632 |
lemma neq_iff_zless: "[| x: int; y: int |] ==> (x ~= y) <-> (x $< y | y $< x)" |
|
633 |
by (cut_tac z = x and w = y in zless_linear, auto) |
|
634 |
||
635 |
lemma zless_imp_intify_neq: "w $< z ==> intify(w) ~= intify(z)" |
|
636 |
apply auto |
|
637 |
apply (subgoal_tac "~ (intify (w) $< intify (z))") |
|
638 |
apply (erule_tac [2] ssubst) |
|
639 |
apply (simp (no_asm_use)) |
|
640 |
apply auto |
|
641 |
done |
|
642 |
||
643 |
(*This lemma allows direct proofs of other <-properties*) |
|
644 |
lemma zless_imp_succ_zadd_lemma: |
|
14511 | 645 |
"[| w $< z; w: int; z: int |] ==> (\<exists>n\<in>nat. z = w $+ $#(succ(n)))" |
646 |
apply (simp add: zless_def znegative_def zdiff_def int_def) |
|
13560 | 647 |
apply (auto dest!: less_imp_succ_add simp add: zadd zminus int_of_def) |
648 |
apply (rule_tac x = k in bexI) |
|
649 |
apply (erule add_left_cancel, auto) |
|
650 |
done |
|
651 |
||
652 |
lemma zless_imp_succ_zadd: |
|
14511 | 653 |
"w $< z ==> (\<exists>n\<in>nat. w $+ $#(succ(n)) = intify(z))" |
13560 | 654 |
apply (subgoal_tac "intify (w) $< intify (z) ") |
655 |
apply (drule_tac w = "intify (w) " in zless_imp_succ_zadd_lemma) |
|
656 |
apply auto |
|
657 |
done |
|
658 |
||
659 |
lemma zless_succ_zadd_lemma: |
|
660 |
"w : int ==> w $< w $+ $# succ(n)" |
|
14511 | 661 |
apply (simp add: zless_def znegative_def zdiff_def int_def) |
13560 | 662 |
apply (auto simp add: zadd zminus int_of_def image_iff) |
663 |
apply (rule_tac x = 0 in exI, auto) |
|
664 |
done |
|
665 |
||
666 |
lemma zless_succ_zadd: "w $< w $+ $# succ(n)" |
|
667 |
by (cut_tac intify_in_int [THEN zless_succ_zadd_lemma], auto) |
|
668 |
||
669 |
lemma zless_iff_succ_zadd: |
|
14511 | 670 |
"w $< z <-> (\<exists>n\<in>nat. w $+ $#(succ(n)) = intify(z))" |
13560 | 671 |
apply (rule iffI) |
672 |
apply (erule zless_imp_succ_zadd, auto) |
|
673 |
apply (rename_tac "n") |
|
674 |
apply (cut_tac w = w and n = n in zless_succ_zadd, auto) |
|
675 |
done |
|
676 |
||
14511 | 677 |
lemma zless_int_of [simp]: "[| m\<in>nat; n\<in>nat |] ==> ($#m $< $#n) <-> (m<n)" |
13560 | 678 |
apply (simp add: less_iff_succ_add zless_iff_succ_zadd int_of_add [symmetric]) |
679 |
apply (blast intro: sym) |
|
680 |
done |
|
681 |
||
682 |
lemma zless_trans_lemma: |
|
683 |
"[| x $< y; y $< z; x: int; y : int; z: int |] ==> x $< z" |
|
14511 | 684 |
apply (simp add: zless_def znegative_def zdiff_def int_def) |
13560 | 685 |
apply (auto simp add: zadd zminus image_iff) |
686 |
apply (rename_tac x1 x2 y1 y2) |
|
687 |
apply (rule_tac x = "x1#+x2" in exI) |
|
688 |
apply (rule_tac x = "y1#+y2" in exI) |
|
689 |
apply (auto simp add: add_lt_mono) |
|
690 |
apply (rule sym) |
|
691 |
apply (erule add_left_cancel)+ |
|
692 |
apply auto |
|
693 |
done |
|
694 |
||
695 |
lemma zless_trans: "[| x $< y; y $< z |] ==> x $< z" |
|
696 |
apply (subgoal_tac "intify (x) $< intify (z) ") |
|
697 |
apply (rule_tac [2] y = "intify (y) " in zless_trans_lemma) |
|
698 |
apply auto |
|
699 |
done |
|
700 |
||
701 |
lemma zless_not_sym: "z $< w ==> ~ (w $< z)" |
|
702 |
by (blast dest: zless_trans) |
|
703 |
||
704 |
(* [| z $< w; ~ P ==> w $< z |] ==> P *) |
|
705 |
lemmas zless_asym = zless_not_sym [THEN swap, standard] |
|
706 |
||
707 |
lemma zless_imp_zle: "z $< w ==> z $<= w" |
|
14511 | 708 |
by (simp add: zle_def) |
13560 | 709 |
|
710 |
lemma zle_linear: "z $<= w | w $<= z" |
|
711 |
apply (simp add: zle_def) |
|
712 |
apply (cut_tac zless_linear, blast) |
|
713 |
done |
|
714 |
||
715 |
||
716 |
subsection{*Less Than or Equals*} |
|
717 |
||
718 |
lemma zle_refl: "z $<= z" |
|
14511 | 719 |
by (simp add: zle_def) |
13560 | 720 |
|
721 |
lemma zle_eq_refl: "x=y ==> x $<= y" |
|
722 |
by (simp add: zle_refl) |
|
723 |
||
724 |
lemma zle_anti_sym_intify: "[| x $<= y; y $<= x |] ==> intify(x) = intify(y)" |
|
14511 | 725 |
apply (simp add: zle_def, auto) |
13560 | 726 |
apply (blast dest: zless_trans) |
727 |
done |
|
728 |
||
729 |
lemma zle_anti_sym: "[| x $<= y; y $<= x; x: int; y: int |] ==> x=y" |
|
730 |
by (drule zle_anti_sym_intify, auto) |
|
731 |
||
732 |
lemma zle_trans_lemma: |
|
733 |
"[| x: int; y: int; z: int; x $<= y; y $<= z |] ==> x $<= z" |
|
14511 | 734 |
apply (simp add: zle_def, auto) |
13560 | 735 |
apply (blast intro: zless_trans) |
736 |
done |
|
737 |
||
738 |
lemma zle_trans: "[| x $<= y; y $<= z |] ==> x $<= z" |
|
739 |
apply (subgoal_tac "intify (x) $<= intify (z) ") |
|
740 |
apply (rule_tac [2] y = "intify (y) " in zle_trans_lemma) |
|
741 |
apply auto |
|
742 |
done |
|
743 |
||
744 |
lemma zle_zless_trans: "[| i $<= j; j $< k |] ==> i $< k" |
|
745 |
apply (auto simp add: zle_def) |
|
746 |
apply (blast intro: zless_trans) |
|
747 |
apply (simp add: zless_def zdiff_def zadd_def) |
|
748 |
done |
|
749 |
||
750 |
lemma zless_zle_trans: "[| i $< j; j $<= k |] ==> i $< k" |
|
751 |
apply (auto simp add: zle_def) |
|
752 |
apply (blast intro: zless_trans) |
|
753 |
apply (simp add: zless_def zdiff_def zminus_def) |
|
754 |
done |
|
755 |
||
756 |
lemma not_zless_iff_zle: "~ (z $< w) <-> (w $<= z)" |
|
757 |
apply (cut_tac z = z and w = w in zless_linear) |
|
758 |
apply (auto dest: zless_trans simp add: zle_def) |
|
759 |
apply (auto dest!: zless_imp_intify_neq) |
|
760 |
done |
|
761 |
||
762 |
lemma not_zle_iff_zless: "~ (z $<= w) <-> (w $< z)" |
|
763 |
by (simp add: not_zless_iff_zle [THEN iff_sym]) |
|
764 |
||
765 |
||
766 |
subsection{*More subtraction laws (for @{text zcompare_rls})*} |
|
767 |
||
768 |
lemma zdiff_zdiff_eq: "(x $- y) $- z = x $- (y $+ z)" |
|
769 |
by (simp add: zdiff_def zadd_ac) |
|
770 |
||
771 |
lemma zdiff_zdiff_eq2: "x $- (y $- z) = (x $+ z) $- y" |
|
772 |
by (simp add: zdiff_def zadd_ac) |
|
773 |
||
774 |
lemma zdiff_zless_iff: "(x$-y $< z) <-> (x $< z $+ y)" |
|
14511 | 775 |
by (simp add: zless_def zdiff_def zadd_ac) |
13560 | 776 |
|
777 |
lemma zless_zdiff_iff: "(x $< z$-y) <-> (x $+ y $< z)" |
|
14511 | 778 |
by (simp add: zless_def zdiff_def zadd_ac) |
13560 | 779 |
|
780 |
lemma zdiff_eq_iff: "[| x: int; z: int |] ==> (x$-y = z) <-> (x = z $+ y)" |
|
14511 | 781 |
by (auto simp add: zdiff_def zadd_assoc) |
13560 | 782 |
|
783 |
lemma eq_zdiff_iff: "[| x: int; z: int |] ==> (x = z$-y) <-> (x $+ y = z)" |
|
14511 | 784 |
by (auto simp add: zdiff_def zadd_assoc) |
13560 | 785 |
|
786 |
lemma zdiff_zle_iff_lemma: |
|
787 |
"[| x: int; z: int |] ==> (x$-y $<= z) <-> (x $<= z $+ y)" |
|
14511 | 788 |
by (auto simp add: zle_def zdiff_eq_iff zdiff_zless_iff) |
13560 | 789 |
|
790 |
lemma zdiff_zle_iff: "(x$-y $<= z) <-> (x $<= z $+ y)" |
|
791 |
by (cut_tac zdiff_zle_iff_lemma [OF intify_in_int intify_in_int], simp) |
|
792 |
||
793 |
lemma zle_zdiff_iff_lemma: |
|
794 |
"[| x: int; z: int |] ==>(x $<= z$-y) <-> (x $+ y $<= z)" |
|
14511 | 795 |
apply (auto simp add: zle_def zdiff_eq_iff zless_zdiff_iff) |
13560 | 796 |
apply (auto simp add: zdiff_def zadd_assoc) |
797 |
done |
|
798 |
||
799 |
lemma zle_zdiff_iff: "(x $<= z$-y) <-> (x $+ y $<= z)" |
|
800 |
by (cut_tac zle_zdiff_iff_lemma [ OF intify_in_int intify_in_int], simp) |
|
801 |
||
802 |
text{*This list of rewrites simplifies (in)equalities by bringing subtractions |
|
803 |
to the top and then moving negative terms to the other side. |
|
804 |
Use with @{text zadd_ac}*} |
|
805 |
lemmas zcompare_rls = |
|
806 |
zdiff_def [symmetric] |
|
807 |
zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2 |
|
808 |
zdiff_zless_iff zless_zdiff_iff zdiff_zle_iff zle_zdiff_iff |
|
809 |
zdiff_eq_iff eq_zdiff_iff |
|
810 |
||
811 |
||
812 |
subsection{*Monotonicity and Cancellation Results for Instantiation |
|
813 |
of the CancelNumerals Simprocs*} |
|
814 |
||
815 |
lemma zadd_left_cancel: |
|
816 |
"[| w: int; w': int |] ==> (z $+ w' = z $+ w) <-> (w' = w)" |
|
817 |
apply safe |
|
818 |
apply (drule_tac t = "%x. x $+ ($-z) " in subst_context) |
|
819 |
apply (simp add: zadd_ac) |
|
820 |
done |
|
821 |
||
822 |
lemma zadd_left_cancel_intify [simp]: |
|
823 |
"(z $+ w' = z $+ w) <-> intify(w') = intify(w)" |
|
824 |
apply (rule iff_trans) |
|
825 |
apply (rule_tac [2] zadd_left_cancel, auto) |
|
826 |
done |
|
827 |
||
828 |
lemma zadd_right_cancel: |
|
829 |
"[| w: int; w': int |] ==> (w' $+ z = w $+ z) <-> (w' = w)" |
|
830 |
apply safe |
|
831 |
apply (drule_tac t = "%x. x $+ ($-z) " in subst_context) |
|
832 |
apply (simp add: zadd_ac) |
|
833 |
done |
|
834 |
||
835 |
lemma zadd_right_cancel_intify [simp]: |
|
836 |
"(w' $+ z = w $+ z) <-> intify(w') = intify(w)" |
|
837 |
apply (rule iff_trans) |
|
838 |
apply (rule_tac [2] zadd_right_cancel, auto) |
|
839 |
done |
|
840 |
||
841 |
lemma zadd_right_cancel_zless [simp]: "(w' $+ z $< w $+ z) <-> (w' $< w)" |
|
14511 | 842 |
by (simp add: zdiff_zless_iff [THEN iff_sym] zdiff_def zadd_assoc) |
13560 | 843 |
|
844 |
lemma zadd_left_cancel_zless [simp]: "(z $+ w' $< z $+ w) <-> (w' $< w)" |
|
845 |
by (simp add: zadd_commute [of z] zadd_right_cancel_zless) |
|
846 |
||
847 |
lemma zadd_right_cancel_zle [simp]: "(w' $+ z $<= w $+ z) <-> w' $<= w" |
|
848 |
by (simp add: zle_def) |
|
849 |
||
850 |
lemma zadd_left_cancel_zle [simp]: "(z $+ w' $<= z $+ w) <-> w' $<= w" |
|
851 |
by (simp add: zadd_commute [of z] zadd_right_cancel_zle) |
|
852 |
||
853 |
||
854 |
(*"v $<= w ==> v$+z $<= w$+z"*) |
|
855 |
lemmas zadd_zless_mono1 = zadd_right_cancel_zless [THEN iffD2, standard] |
|
856 |
||
857 |
(*"v $<= w ==> z$+v $<= z$+w"*) |
|
858 |
lemmas zadd_zless_mono2 = zadd_left_cancel_zless [THEN iffD2, standard] |
|
859 |
||
860 |
(*"v $<= w ==> v$+z $<= w$+z"*) |
|
861 |
lemmas zadd_zle_mono1 = zadd_right_cancel_zle [THEN iffD2, standard] |
|
862 |
||
863 |
(*"v $<= w ==> z$+v $<= z$+w"*) |
|
864 |
lemmas zadd_zle_mono2 = zadd_left_cancel_zle [THEN iffD2, standard] |
|
865 |
||
866 |
lemma zadd_zle_mono: "[| w' $<= w; z' $<= z |] ==> w' $+ z' $<= w $+ z" |
|
867 |
by (erule zadd_zle_mono1 [THEN zle_trans], simp) |
|
868 |
||
869 |
lemma zadd_zless_mono: "[| w' $< w; z' $<= z |] ==> w' $+ z' $< w $+ z" |
|
870 |
by (erule zadd_zless_mono1 [THEN zless_zle_trans], simp) |
|
871 |
||
872 |
||
873 |
subsection{*Comparison laws*} |
|
874 |
||
875 |
lemma zminus_zless_zminus [simp]: "($- x $< $- y) <-> (y $< x)" |
|
876 |
by (simp add: zless_def zdiff_def zadd_ac) |
|
877 |
||
878 |
lemma zminus_zle_zminus [simp]: "($- x $<= $- y) <-> (y $<= x)" |
|
879 |
by (simp add: not_zless_iff_zle [THEN iff_sym]) |
|
880 |
||
881 |
subsubsection{*More inequality lemmas*} |
|
882 |
||
883 |
lemma equation_zminus: "[| x: int; y: int |] ==> (x = $- y) <-> (y = $- x)" |
|
884 |
by auto |
|
885 |
||
886 |
lemma zminus_equation: "[| x: int; y: int |] ==> ($- x = y) <-> ($- y = x)" |
|
887 |
by auto |
|
888 |
||
889 |
lemma equation_zminus_intify: "(intify(x) = $- y) <-> (intify(y) = $- x)" |
|
890 |
apply (cut_tac x = "intify (x) " and y = "intify (y) " in equation_zminus) |
|
891 |
apply auto |
|
892 |
done |
|
893 |
||
894 |
lemma zminus_equation_intify: "($- x = intify(y)) <-> ($- y = intify(x))" |
|
895 |
apply (cut_tac x = "intify (x) " and y = "intify (y) " in zminus_equation) |
|
896 |
apply auto |
|
897 |
done |
|
898 |
||
899 |
||
900 |
subsubsection{*The next several equations are permutative: watch out!*} |
|
901 |
||
902 |
lemma zless_zminus: "(x $< $- y) <-> (y $< $- x)" |
|
903 |
by (simp add: zless_def zdiff_def zadd_ac) |
|
904 |
||
905 |
lemma zminus_zless: "($- x $< y) <-> ($- y $< x)" |
|
906 |
by (simp add: zless_def zdiff_def zadd_ac) |
|
907 |
||
908 |
lemma zle_zminus: "(x $<= $- y) <-> (y $<= $- x)" |
|
909 |
by (simp add: not_zless_iff_zle [THEN iff_sym] zminus_zless) |
|
910 |
||
911 |
lemma zminus_zle: "($- x $<= y) <-> ($- y $<= x)" |
|
912 |
by (simp add: not_zless_iff_zle [THEN iff_sym] zless_zminus) |
|
913 |
||
914 |
ML |
|
915 |
{* |
|
916 |
val zdiff_def = thm "zdiff_def"; |
|
917 |
val int_of_type = thm "int_of_type"; |
|
918 |
val int_of_eq = thm "int_of_eq"; |
|
919 |
val int_of_inject = thm "int_of_inject"; |
|
920 |
val intify_in_int = thm "intify_in_int"; |
|
921 |
val intify_ident = thm "intify_ident"; |
|
922 |
val intify_idem = thm "intify_idem"; |
|
923 |
val int_of_natify = thm "int_of_natify"; |
|
924 |
val zminus_intify = thm "zminus_intify"; |
|
925 |
val zadd_intify1 = thm "zadd_intify1"; |
|
926 |
val zadd_intify2 = thm "zadd_intify2"; |
|
927 |
val zdiff_intify1 = thm "zdiff_intify1"; |
|
928 |
val zdiff_intify2 = thm "zdiff_intify2"; |
|
929 |
val zmult_intify1 = thm "zmult_intify1"; |
|
930 |
val zmult_intify2 = thm "zmult_intify2"; |
|
931 |
val zless_intify1 = thm "zless_intify1"; |
|
932 |
val zless_intify2 = thm "zless_intify2"; |
|
933 |
val zle_intify1 = thm "zle_intify1"; |
|
934 |
val zle_intify2 = thm "zle_intify2"; |
|
935 |
val zminus_congruent = thm "zminus_congruent"; |
|
936 |
val zminus_type = thm "zminus_type"; |
|
937 |
val zminus_inject_intify = thm "zminus_inject_intify"; |
|
938 |
val zminus_inject = thm "zminus_inject"; |
|
939 |
val zminus = thm "zminus"; |
|
940 |
val zminus_zminus_intify = thm "zminus_zminus_intify"; |
|
941 |
val zminus_int0 = thm "zminus_int0"; |
|
942 |
val zminus_zminus = thm "zminus_zminus"; |
|
943 |
val not_znegative_int_of = thm "not_znegative_int_of"; |
|
944 |
val znegative_zminus_int_of = thm "znegative_zminus_int_of"; |
|
945 |
val not_znegative_imp_zero = thm "not_znegative_imp_zero"; |
|
946 |
val nat_of_intify = thm "nat_of_intify"; |
|
947 |
val nat_of_int_of = thm "nat_of_int_of"; |
|
948 |
val nat_of_type = thm "nat_of_type"; |
|
949 |
val zmagnitude_int_of = thm "zmagnitude_int_of"; |
|
950 |
val natify_int_of_eq = thm "natify_int_of_eq"; |
|
951 |
val zmagnitude_zminus_int_of = thm "zmagnitude_zminus_int_of"; |
|
952 |
val zmagnitude_type = thm "zmagnitude_type"; |
|
953 |
val not_zneg_int_of = thm "not_zneg_int_of"; |
|
954 |
val not_zneg_mag = thm "not_zneg_mag"; |
|
955 |
val zneg_int_of = thm "zneg_int_of"; |
|
956 |
val zneg_mag = thm "zneg_mag"; |
|
957 |
val int_cases = thm "int_cases"; |
|
958 |
val not_zneg_nat_of_intify = thm "not_zneg_nat_of_intify"; |
|
959 |
val not_zneg_nat_of = thm "not_zneg_nat_of"; |
|
960 |
val zneg_nat_of = thm "zneg_nat_of"; |
|
961 |
val zadd_congruent2 = thm "zadd_congruent2"; |
|
962 |
val zadd_type = thm "zadd_type"; |
|
963 |
val zadd = thm "zadd"; |
|
964 |
val zadd_int0_intify = thm "zadd_int0_intify"; |
|
965 |
val zadd_int0 = thm "zadd_int0"; |
|
966 |
val zminus_zadd_distrib = thm "zminus_zadd_distrib"; |
|
967 |
val zadd_commute = thm "zadd_commute"; |
|
968 |
val zadd_assoc = thm "zadd_assoc"; |
|
969 |
val zadd_left_commute = thm "zadd_left_commute"; |
|
970 |
val zadd_ac = thms "zadd_ac"; |
|
971 |
val int_of_add = thm "int_of_add"; |
|
972 |
val int_succ_int_1 = thm "int_succ_int_1"; |
|
973 |
val int_of_diff = thm "int_of_diff"; |
|
974 |
val zadd_zminus_inverse = thm "zadd_zminus_inverse"; |
|
975 |
val zadd_zminus_inverse2 = thm "zadd_zminus_inverse2"; |
|
976 |
val zadd_int0_right_intify = thm "zadd_int0_right_intify"; |
|
977 |
val zadd_int0_right = thm "zadd_int0_right"; |
|
978 |
val zmult_congruent2 = thm "zmult_congruent2"; |
|
979 |
val zmult_type = thm "zmult_type"; |
|
980 |
val zmult = thm "zmult"; |
|
981 |
val zmult_int0 = thm "zmult_int0"; |
|
982 |
val zmult_int1_intify = thm "zmult_int1_intify"; |
|
983 |
val zmult_int1 = thm "zmult_int1"; |
|
984 |
val zmult_commute = thm "zmult_commute"; |
|
985 |
val zmult_zminus = thm "zmult_zminus"; |
|
986 |
val zmult_zminus_right = thm "zmult_zminus_right"; |
|
987 |
val zmult_assoc = thm "zmult_assoc"; |
|
988 |
val zmult_left_commute = thm "zmult_left_commute"; |
|
989 |
val zmult_ac = thms "zmult_ac"; |
|
990 |
val zadd_zmult_distrib = thm "zadd_zmult_distrib"; |
|
991 |
val zadd_zmult_distrib2 = thm "zadd_zmult_distrib2"; |
|
992 |
val int_typechecks = thms "int_typechecks"; |
|
993 |
val zdiff_type = thm "zdiff_type"; |
|
994 |
val zminus_zdiff_eq = thm "zminus_zdiff_eq"; |
|
995 |
val zdiff_zmult_distrib = thm "zdiff_zmult_distrib"; |
|
996 |
val zdiff_zmult_distrib2 = thm "zdiff_zmult_distrib2"; |
|
997 |
val zadd_zdiff_eq = thm "zadd_zdiff_eq"; |
|
998 |
val zdiff_zadd_eq = thm "zdiff_zadd_eq"; |
|
999 |
val zless_linear = thm "zless_linear"; |
|
1000 |
val zless_not_refl = thm "zless_not_refl"; |
|
1001 |
val neq_iff_zless = thm "neq_iff_zless"; |
|
1002 |
val zless_imp_intify_neq = thm "zless_imp_intify_neq"; |
|
1003 |
val zless_imp_succ_zadd = thm "zless_imp_succ_zadd"; |
|
1004 |
val zless_succ_zadd = thm "zless_succ_zadd"; |
|
1005 |
val zless_iff_succ_zadd = thm "zless_iff_succ_zadd"; |
|
1006 |
val zless_int_of = thm "zless_int_of"; |
|
1007 |
val zless_trans = thm "zless_trans"; |
|
1008 |
val zless_not_sym = thm "zless_not_sym"; |
|
1009 |
val zless_asym = thm "zless_asym"; |
|
1010 |
val zless_imp_zle = thm "zless_imp_zle"; |
|
1011 |
val zle_linear = thm "zle_linear"; |
|
1012 |
val zle_refl = thm "zle_refl"; |
|
1013 |
val zle_eq_refl = thm "zle_eq_refl"; |
|
1014 |
val zle_anti_sym_intify = thm "zle_anti_sym_intify"; |
|
1015 |
val zle_anti_sym = thm "zle_anti_sym"; |
|
1016 |
val zle_trans = thm "zle_trans"; |
|
1017 |
val zle_zless_trans = thm "zle_zless_trans"; |
|
1018 |
val zless_zle_trans = thm "zless_zle_trans"; |
|
1019 |
val not_zless_iff_zle = thm "not_zless_iff_zle"; |
|
1020 |
val not_zle_iff_zless = thm "not_zle_iff_zless"; |
|
1021 |
val zdiff_zdiff_eq = thm "zdiff_zdiff_eq"; |
|
1022 |
val zdiff_zdiff_eq2 = thm "zdiff_zdiff_eq2"; |
|
1023 |
val zdiff_zless_iff = thm "zdiff_zless_iff"; |
|
1024 |
val zless_zdiff_iff = thm "zless_zdiff_iff"; |
|
1025 |
val zdiff_eq_iff = thm "zdiff_eq_iff"; |
|
1026 |
val eq_zdiff_iff = thm "eq_zdiff_iff"; |
|
1027 |
val zdiff_zle_iff = thm "zdiff_zle_iff"; |
|
1028 |
val zle_zdiff_iff = thm "zle_zdiff_iff"; |
|
1029 |
val zcompare_rls = thms "zcompare_rls"; |
|
1030 |
val zadd_left_cancel = thm "zadd_left_cancel"; |
|
1031 |
val zadd_left_cancel_intify = thm "zadd_left_cancel_intify"; |
|
1032 |
val zadd_right_cancel = thm "zadd_right_cancel"; |
|
1033 |
val zadd_right_cancel_intify = thm "zadd_right_cancel_intify"; |
|
1034 |
val zadd_right_cancel_zless = thm "zadd_right_cancel_zless"; |
|
1035 |
val zadd_left_cancel_zless = thm "zadd_left_cancel_zless"; |
|
1036 |
val zadd_right_cancel_zle = thm "zadd_right_cancel_zle"; |
|
1037 |
val zadd_left_cancel_zle = thm "zadd_left_cancel_zle"; |
|
1038 |
val zadd_zless_mono1 = thm "zadd_zless_mono1"; |
|
1039 |
val zadd_zless_mono2 = thm "zadd_zless_mono2"; |
|
1040 |
val zadd_zle_mono1 = thm "zadd_zle_mono1"; |
|
1041 |
val zadd_zle_mono2 = thm "zadd_zle_mono2"; |
|
1042 |
val zadd_zle_mono = thm "zadd_zle_mono"; |
|
1043 |
val zadd_zless_mono = thm "zadd_zless_mono"; |
|
1044 |
val zminus_zless_zminus = thm "zminus_zless_zminus"; |
|
1045 |
val zminus_zle_zminus = thm "zminus_zle_zminus"; |
|
1046 |
val equation_zminus = thm "equation_zminus"; |
|
1047 |
val zminus_equation = thm "zminus_equation"; |
|
1048 |
val equation_zminus_intify = thm "equation_zminus_intify"; |
|
1049 |
val zminus_equation_intify = thm "zminus_equation_intify"; |
|
1050 |
val zless_zminus = thm "zless_zminus"; |
|
1051 |
val zminus_zless = thm "zminus_zless"; |
|
1052 |
val zle_zminus = thm "zle_zminus"; |
|
1053 |
val zminus_zle = thm "zminus_zle"; |
|
1054 |
*} |
|
1055 |
||
1056 |
||
9496
07e33cac5d9c
coercion "intify" to remove type constraints from integer algebraic laws
paulson
parents:
9333
diff
changeset
|
1057 |
end |