author | nipkow |
Thu, 10 May 2001 17:28:40 +0200 | |
changeset 11295 | 66925f23ac7f |
parent 10702 | 9e6898befad4 |
child 11701 | 3d51fbf81c17 |
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 |
||
23 |
Goal "(ALL i<n. abs(f(i+1) - f i) <= #1) --> \ |
|
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 |
||
41 |
bind_thm("nat0_intermed_int_val", rulify_no_asm lemma); |
|
42 |
||
43 |
Goal "[| !i. m <= i & i < n --> abs(f(i+1) - f i) <= #1; m < n; \ |
|
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 |
|
9063 | 59 |
Goal "[| (#0::int) < i; #0 < j |] ==> #0 < i*j"; |
60 |
by (dtac zmult_zless_mono1 1); |
|
61 |
by Auto_tac; |
|
62 |
qed "zmult_pos"; |
|
7707 | 63 |
|
9063 | 64 |
Goal "[| i < (#0::int); j < #0 |] ==> #0 < i*j"; |
65 |
by (dtac zmult_zless_mono1_neg 1); |
|
66 |
by Auto_tac; |
|
67 |
qed "zmult_neg"; |
|
7707 | 68 |
|
9063 | 69 |
Goal "[| (#0::int) < i; j < #0 |] ==> i*j < #0"; |
70 |
by (dtac zmult_zless_mono1_neg 1); |
|
71 |
by Auto_tac; |
|
72 |
qed "zmult_pos_neg"; |
|
7707 | 73 |
|
9063 | 74 |
Goal "((#0::int) < x*y) = (#0 < x & #0 < y | x < #0 & y < #0)"; |
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 |
|
9063 | 87 |
Goal "((#0::int) <= x*y) = (#0 <= x & #0 <= y | x <= #0 & y <= #0)"; |
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 |
|
9063 | 93 |
Goal "(x*y < (#0::int)) = (#0 < x & y < #0 | x < #0 & #0 < y)"; |
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 |
|
9063 | 101 |
Goal "(x*y <= (#0::int)) = (#0 <= x & y <= #0 | x <= #0 & #0 <= y)"; |
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 |
||
10490 | 112 |
Goal "(abs x = #0) = (x = (#0::int))"; |
10476 | 113 |
by (simp_tac (simpset () addsplits [zabs_split]) 1); |
114 |
qed "abs_eq_0"; |
|
115 |
AddIffs [abs_eq_0]; |
|
116 |
||
10702 | 117 |
Goal "(#0 < abs x) = (x ~= (#0::int))"; |
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 |
||
10476 | 123 |
Goal "#0 <= x * (x::int)"; |
124 |
by (subgoal_tac "(- x) * x <= #0" 1); |
|
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 |
||
135 |
Goal "(m = m*(n::int)) = (n = #1 | m = #0)"; |
|
136 |
by Auto_tac; |
|
9633
a71a83253997
better rules for cancellation of common factors across comparisons
paulson
parents:
9509
diff
changeset
|
137 |
by (subgoal_tac "m*#1 = m*n" 1); |
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 |
||
142 |
Goal "[| #1 < m; #1 < n |] ==> #1 < m*(n::int)"; |
|
10646
37b9897dbf3a
greater use of overloaded rules (order_less_imp_le not zless_imp_zle, ...)
paulson
parents:
10490
diff
changeset
|
143 |
by (res_inst_tac [("y","#1*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 |
||
148 |
Goal "[| #0 < n; n ~= #1 |] ==> #1 < (n::int)"; |
|
149 |
by (arith_tac 1); |
|
150 |
val lemma = result(); |
|
151 |
||
152 |
Goal "#0 < (m::int) ==> (m * n = #1) = (m = #1 & n = #1)"; |
|
153 |
by Auto_tac; |
|
154 |
by (case_tac "m=#1" 1); |
|
155 |
by (case_tac "n=#1" 2); |
|
156 |
by (case_tac "m=#1" 4); |
|
157 |
by (case_tac "n=#1" 5); |
|
158 |
by Auto_tac; |
|
159 |
by distinct_subgoals_tac; |
|
160 |
by (subgoal_tac "#1<m*n" 1); |
|
161 |
by (Asm_full_simp_tac 1); |
|
162 |
by (rtac zless_1_zmult 1); |
|
163 |
by (ALLGOALS (rtac lemma)); |
|
164 |
by Auto_tac; |
|
165 |
by (subgoal_tac "#0<m*n" 1); |
|
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 |
||
171 |
Goal "(m*n = (#1::int)) = ((m = #1 & n = #1) | (m = #-1 & n = #-1))"; |
|
172 |
by (case_tac "#0<m" 1); |
|
173 |
by (asm_simp_tac (simpset() addsimps [pos_zmult_eq_1_iff]) 1); |
|
174 |
by (case_tac "m=#0" 1); |
|
175 |
by (Asm_simp_tac 1); |
|
176 |
by (subgoal_tac "#0 < -m" 1); |
|
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 |