author | wenzelm |
Sun, 14 Oct 2001 22:08:29 +0200 | |
changeset 11770 | b6bb7a853dd2 |
parent 11704 | 3c50a2cd6f00 |
child 11868 | 56db9f3a6b3e |
permissions | -rw-r--r-- |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
9269
diff
changeset
|
1 |
(* Title: HOL/Integ/IntArith.ML |
7707 | 2 |
ID: $Id$ |
3 |
Authors: Larry Paulson and Tobias Nipkow |
|
4 |
*) |
|
5 |
||
9269 | 6 |
Goal "abs(abs(x::int)) = abs(x)"; |
7 |
by(arith_tac 1); |
|
9214 | 8 |
qed "abs_abs"; |
9 |
Addsimps [abs_abs]; |
|
10 |
||
9269 | 11 |
Goal "abs(-(x::int)) = abs(x)"; |
12 |
by(arith_tac 1); |
|
9214 | 13 |
qed "abs_minus"; |
14 |
Addsimps [abs_minus]; |
|
15 |
||
9269 | 16 |
Goal "abs(x+y) <= abs(x) + abs(y::int)"; |
17 |
by(arith_tac 1); |
|
18 |
qed "triangle_ineq"; |
|
19 |
||
9214 | 20 |
|
10228 | 21 |
(*** Intermediate value theorems ***) |
22 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
23 |
Goal "(ALL i<n::nat. abs(f(i+1) - f i) <= Numeral1) --> \ |
10228 | 24 |
\ f 0 <= k --> k <= f n --> (EX i <= n. f i = (k::int))"; |
25 |
by(induct_tac "n" 1); |
|
26 |
by(Asm_simp_tac 1); |
|
27 |
by(strip_tac 1); |
|
28 |
by(etac impE 1); |
|
29 |
by(Asm_full_simp_tac 1); |
|
30 |
by(eres_inst_tac [("x","n")] allE 1); |
|
31 |
by(Asm_full_simp_tac 1); |
|
32 |
by(case_tac "k = f(n+1)" 1); |
|
33 |
by(Force_tac 1); |
|
34 |
by(etac impE 1); |
|
10702 | 35 |
by(asm_full_simp_tac (simpset() addsimps [zabs_def] |
36 |
addsplits [split_if_asm]) 1); |
|
10228 | 37 |
by(arith_tac 1); |
38 |
by(blast_tac (claset() addIs [le_SucI]) 1); |
|
39 |
val lemma = result(); |
|
40 |
||
11770 | 41 |
bind_thm("nat0_intermed_int_val", ObjectLogic.rulify_no_asm lemma); |
10228 | 42 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
43 |
Goal "[| !i. m <= i & i < n --> abs(f(i + 1::nat) - f i) <= Numeral1; m < n; \ |
10228 | 44 |
\ f m <= k; k <= f n |] ==> ? i. m <= i & i <= n & f i = (k::int)"; |
45 |
by(cut_inst_tac [("n","n-m"),("f", "%i. f(i+m)"),("k","k")]lemma 1); |
|
46 |
by(Asm_full_simp_tac 1); |
|
47 |
by(etac impE 1); |
|
48 |
by(strip_tac 1); |
|
49 |
by(eres_inst_tac [("x","i+m")] allE 1); |
|
50 |
by(arith_tac 1); |
|
51 |
by(etac exE 1); |
|
52 |
by(res_inst_tac [("x","i+m")] exI 1); |
|
53 |
by(arith_tac 1); |
|
54 |
qed "nat_intermed_int_val"; |
|
55 |
||
56 |
||
9063 | 57 |
(*** Some convenient biconditionals for products of signs ***) |
7707 | 58 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
59 |
Goal "[| (Numeral0::int) < i; Numeral0 < j |] ==> Numeral0 < i*j"; |
9063 | 60 |
by (dtac zmult_zless_mono1 1); |
61 |
by Auto_tac; |
|
62 |
qed "zmult_pos"; |
|
7707 | 63 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
64 |
Goal "[| i < (Numeral0::int); j < Numeral0 |] ==> Numeral0 < i*j"; |
9063 | 65 |
by (dtac zmult_zless_mono1_neg 1); |
66 |
by Auto_tac; |
|
67 |
qed "zmult_neg"; |
|
7707 | 68 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
69 |
Goal "[| (Numeral0::int) < i; j < Numeral0 |] ==> i*j < Numeral0"; |
9063 | 70 |
by (dtac zmult_zless_mono1_neg 1); |
71 |
by Auto_tac; |
|
72 |
qed "zmult_pos_neg"; |
|
7707 | 73 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
74 |
Goal "((Numeral0::int) < x*y) = (Numeral0 < x & Numeral0 < y | x < Numeral0 & y < Numeral0)"; |
9063 | 75 |
by (auto_tac (claset(), |
76 |
simpset() addsimps [order_le_less, linorder_not_less, |
|
77 |
zmult_pos, zmult_neg])); |
|
78 |
by (ALLGOALS (rtac ccontr)); |
|
79 |
by (auto_tac (claset(), |
|
80 |
simpset() addsimps [order_le_less, linorder_not_less])); |
|
81 |
by (ALLGOALS (etac rev_mp)); |
|
82 |
by (ALLGOALS (dtac zmult_pos_neg THEN' assume_tac)); |
|
83 |
by (auto_tac (claset() addDs [order_less_not_sym], |
|
84 |
simpset() addsimps [zmult_commute])); |
|
85 |
qed "int_0_less_mult_iff"; |
|
7707 | 86 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
87 |
Goal "((Numeral0::int) <= x*y) = (Numeral0 <= x & Numeral0 <= y | x <= Numeral0 & y <= Numeral0)"; |
9063 | 88 |
by (auto_tac (claset(), |
89 |
simpset() addsimps [order_le_less, linorder_not_less, |
|
90 |
int_0_less_mult_iff])); |
|
91 |
qed "int_0_le_mult_iff"; |
|
7707 | 92 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
93 |
Goal "(x*y < (Numeral0::int)) = (Numeral0 < x & y < Numeral0 | x < Numeral0 & Numeral0 < y)"; |
9063 | 94 |
by (auto_tac (claset(), |
95 |
simpset() addsimps [int_0_le_mult_iff, |
|
96 |
linorder_not_le RS sym])); |
|
97 |
by (auto_tac (claset() addDs [order_less_not_sym], |
|
98 |
simpset() addsimps [linorder_not_le])); |
|
99 |
qed "zmult_less_0_iff"; |
|
7707 | 100 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
101 |
Goal "(x*y <= (Numeral0::int)) = (Numeral0 <= x & y <= Numeral0 | x <= Numeral0 & Numeral0 <= y)"; |
9063 | 102 |
by (auto_tac (claset() addDs [order_less_not_sym], |
103 |
simpset() addsimps [int_0_less_mult_iff, |
|
104 |
linorder_not_less RS sym])); |
|
105 |
qed "zmult_le_0_iff"; |
|
9509 | 106 |
|
10476 | 107 |
Goal "abs (x * y) = abs x * abs (y::int)"; |
10702 | 108 |
by (simp_tac (simpset () addsplits [zabs_split] |
109 |
addsimps [zmult_less_0_iff, zle_def]) 1); |
|
10476 | 110 |
qed "abs_mult"; |
111 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
112 |
Goal "(abs x = Numeral0) = (x = (Numeral0::int))"; |
10476 | 113 |
by (simp_tac (simpset () addsplits [zabs_split]) 1); |
114 |
qed "abs_eq_0"; |
|
115 |
AddIffs [abs_eq_0]; |
|
116 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
117 |
Goal "(Numeral0 < abs x) = (x ~= (Numeral0::int))"; |
10702 | 118 |
by (simp_tac (simpset () addsplits [zabs_split]) 1); |
119 |
by (arith_tac 1); |
|
120 |
qed "zero_less_abs_iff"; |
|
121 |
AddIffs [zero_less_abs_iff]; |
|
122 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
123 |
Goal "Numeral0 <= x * (x::int)"; |
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
124 |
by (subgoal_tac "(- x) * x <= Numeral0" 1); |
10476 | 125 |
by (Asm_full_simp_tac 1); |
126 |
by (simp_tac (HOL_basic_ss addsimps [zmult_le_0_iff]) 1); |
|
127 |
by Auto_tac; |
|
128 |
qed "square_nonzero"; |
|
129 |
Addsimps [square_nonzero]; |
|
130 |
AddIs [square_nonzero]; |
|
131 |
||
132 |
||
9509 | 133 |
(*** Products and 1, by T. M. Rasmussen ***) |
134 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
135 |
Goal "(m = m*(n::int)) = (n = Numeral1 | m = Numeral0)"; |
9509 | 136 |
by Auto_tac; |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
137 |
by (subgoal_tac "m*Numeral1 = m*n" 1); |
9633
a71a83253997
better rules for cancellation of common factors across comparisons
paulson
parents:
9509
diff
changeset
|
138 |
by (dtac (zmult_cancel1 RS iffD1) 1); |
9509 | 139 |
by Auto_tac; |
140 |
qed "zmult_eq_self_iff"; |
|
141 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
142 |
Goal "[| Numeral1 < m; Numeral1 < n |] ==> Numeral1 < m*(n::int)"; |
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
143 |
by (res_inst_tac [("y","Numeral1*n")] order_less_trans 1); |
9509 | 144 |
by (rtac zmult_zless_mono1 2); |
145 |
by (ALLGOALS Asm_simp_tac); |
|
146 |
qed "zless_1_zmult"; |
|
147 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
148 |
Goal "[| Numeral0 < n; n ~= Numeral1 |] ==> Numeral1 < (n::int)"; |
9509 | 149 |
by (arith_tac 1); |
150 |
val lemma = result(); |
|
151 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
152 |
Goal "Numeral0 < (m::int) ==> (m * n = Numeral1) = (m = Numeral1 & n = Numeral1)"; |
9509 | 153 |
by Auto_tac; |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
154 |
by (case_tac "m=Numeral1" 1); |
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
155 |
by (case_tac "n=Numeral1" 2); |
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
156 |
by (case_tac "m=Numeral1" 4); |
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
157 |
by (case_tac "n=Numeral1" 5); |
9509 | 158 |
by Auto_tac; |
159 |
by distinct_subgoals_tac; |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
160 |
by (subgoal_tac "Numeral1<m*n" 1); |
9509 | 161 |
by (Asm_full_simp_tac 1); |
162 |
by (rtac zless_1_zmult 1); |
|
163 |
by (ALLGOALS (rtac lemma)); |
|
164 |
by Auto_tac; |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
165 |
by (subgoal_tac "Numeral0<m*n" 1); |
9509 | 166 |
by (Asm_simp_tac 2); |
167 |
by (dtac (int_0_less_mult_iff RS iffD1) 1); |
|
168 |
by Auto_tac; |
|
169 |
qed "pos_zmult_eq_1_iff"; |
|
170 |
||
11704
3c50a2cd6f00
* sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents:
11701
diff
changeset
|
171 |
Goal "(m*n = (Numeral1::int)) = ((m = Numeral1 & n = Numeral1) | (m = -1 & n = -1))"; |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
172 |
by (case_tac "Numeral0<m" 1); |
9509 | 173 |
by (asm_simp_tac (simpset() addsimps [pos_zmult_eq_1_iff]) 1); |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
174 |
by (case_tac "m=Numeral0" 1); |
9509 | 175 |
by (Asm_simp_tac 1); |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
10702
diff
changeset
|
176 |
by (subgoal_tac "Numeral0 < -m" 1); |
9509 | 177 |
by (arith_tac 2); |
178 |
by (dres_inst_tac [("n","-n")] pos_zmult_eq_1_iff 1); |
|
179 |
by Auto_tac; |
|
180 |
qed "zmult_eq_1_iff"; |
|
181 |