author | nipkow |
Sun, 29 Jan 1995 14:02:17 +0100 | |
changeset 204 | 21c405b4039f |
parent 202 | c533bc92e882 |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: HOL/hol.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 1991 University of Cambridge |
|
5 |
||
6 |
For hol.thy |
|
7 |
Derived rules from Appendix of Mike Gordons HOL Report, Cambridge TR 68 |
|
8 |
*) |
|
9 |
||
10 |
open HOL; |
|
11 |
||
12 |
||
13 |
(** Equality **) |
|
14 |
||
200 | 15 |
qed_goal "sym" HOL.thy "s=t ==> t=s" |
0 | 16 |
(fn prems => [cut_facts_tac prems 1, etac subst 1, rtac refl 1]); |
17 |
||
18 |
(*calling "standard" reduces maxidx to 0*) |
|
202 | 19 |
bind_thm ("ssubst", (sym RS subst)); |
0 | 20 |
|
200 | 21 |
qed_goal "trans" HOL.thy "[| r=s; s=t |] ==> r=t" |
0 | 22 |
(fn prems => |
23 |
[rtac subst 1, resolve_tac prems 1, resolve_tac prems 1]); |
|
24 |
||
25 |
(*Useful with eresolve_tac for proving equalties from known equalities. |
|
26 |
a = b |
|
27 |
| | |
|
28 |
c = d *) |
|
200 | 29 |
qed_goal "box_equals" HOL.thy |
0 | 30 |
"[| a=b; a=c; b=d |] ==> c=d" |
31 |
(fn prems=> |
|
32 |
[ (rtac trans 1), |
|
33 |
(rtac trans 1), |
|
34 |
(rtac sym 1), |
|
35 |
(REPEAT (resolve_tac prems 1)) ]); |
|
36 |
||
37 |
(** Congruence rules for meta-application **) |
|
38 |
||
39 |
(*similar to AP_THM in Gordon's HOL*) |
|
200 | 40 |
qed_goal "fun_cong" HOL.thy "(f::'a=>'b) = g ==> f(x)=g(x)" |
0 | 41 |
(fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]); |
42 |
||
43 |
(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*) |
|
200 | 44 |
qed_goal "arg_cong" HOL.thy "x=y ==> f(x)=f(y)" |
0 | 45 |
(fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]); |
46 |
||
200 | 47 |
qed_goal "cong" HOL.thy |
90
5c7a69cef18b
added parentheses made necessary by change of constrain's precedence
clasohm
parents:
84
diff
changeset
|
48 |
"[| f = g; (x::'a) = y |] ==> f(x) = g(y)" |
0 | 49 |
(fn [prem1,prem2] => |
50 |
[rtac (prem1 RS subst) 1, rtac (prem2 RS subst) 1, rtac refl 1]); |
|
51 |
||
52 |
(** Equality of booleans -- iff **) |
|
53 |
||
200 | 54 |
qed_goal "iffI" HOL.thy |
0 | 55 |
"[| P ==> Q; Q ==> P |] ==> P=Q" |
56 |
(fn prems=> [ (REPEAT (ares_tac (prems@[impI, iff RS mp RS mp]) 1)) ]); |
|
57 |
||
200 | 58 |
qed_goal "iffD2" HOL.thy "[| P=Q; Q |] ==> P" |
0 | 59 |
(fn prems => |
60 |
[rtac ssubst 1, resolve_tac prems 1, resolve_tac prems 1]); |
|
61 |
||
62 |
val iffD1 = sym RS iffD2; |
|
63 |
||
200 | 64 |
qed_goal "iffE" HOL.thy |
0 | 65 |
"[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R" |
66 |
(fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]); |
|
67 |
||
68 |
(** True **) |
|
69 |
||
200 | 70 |
qed_goalw "TrueI" HOL.thy [True_def] "True" |
66 | 71 |
(fn _ => [rtac refl 1]); |
0 | 72 |
|
200 | 73 |
qed_goal "eqTrueI " HOL.thy "P ==> P=True" |
0 | 74 |
(fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]); |
75 |
||
200 | 76 |
qed_goal "eqTrueE" HOL.thy "P=True ==> P" |
0 | 77 |
(fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]); |
78 |
||
79 |
(** Universal quantifier **) |
|
80 |
||
200 | 81 |
qed_goalw "allI" HOL.thy [All_def] "(!!x::'a. P(x)) ==> !x. P(x)" |
66 | 82 |
(fn prems => [resolve_tac (prems RL [eqTrueI RS ext]) 1]); |
0 | 83 |
|
200 | 84 |
qed_goalw "spec" HOL.thy [All_def] "! x::'a.P(x) ==> P(x)" |
66 | 85 |
(fn prems => [rtac eqTrueE 1, resolve_tac (prems RL [fun_cong]) 1]); |
0 | 86 |
|
200 | 87 |
qed_goal "allE" HOL.thy "[| !x.P(x); P(x) ==> R |] ==> R" |
0 | 88 |
(fn major::prems=> |
89 |
[ (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ]); |
|
90 |
||
200 | 91 |
qed_goal "all_dupE" HOL.thy |
0 | 92 |
"[| ! x.P(x); [| P(x); ! x.P(x) |] ==> R |] ==> R" |
93 |
(fn prems => |
|
94 |
[ (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ]); |
|
95 |
||
96 |
||
97 |
(** False ** Depends upon spec; it is impossible to do propositional logic |
|
98 |
before quantifiers! **) |
|
99 |
||
200 | 100 |
qed_goalw "FalseE" HOL.thy [False_def] "False ==> P" |
84 | 101 |
(fn [major] => [rtac (major RS spec) 1]); |
0 | 102 |
|
200 | 103 |
qed_goal "False_neq_True" HOL.thy "False=True ==> P" |
0 | 104 |
(fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]); |
105 |
||
106 |
||
107 |
(** Negation **) |
|
108 |
||
200 | 109 |
qed_goalw "notI" HOL.thy [not_def] "(P ==> False) ==> ~P" |
66 | 110 |
(fn prems=> [rtac impI 1, eresolve_tac prems 1]); |
0 | 111 |
|
200 | 112 |
qed_goalw "notE" HOL.thy [not_def] "[| ~P; P |] ==> R" |
75 | 113 |
(fn prems => [rtac (prems MRS mp RS FalseE) 1]); |
0 | 114 |
|
115 |
(** Implication **) |
|
116 |
||
200 | 117 |
qed_goal "impE" HOL.thy "[| P-->Q; P; Q ==> R |] ==> R" |
0 | 118 |
(fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]); |
119 |
||
120 |
(* Reduces Q to P-->Q, allowing substitution in P. *) |
|
200 | 121 |
qed_goal "rev_mp" HOL.thy "[| P; P --> Q |] ==> Q" |
0 | 122 |
(fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]); |
123 |
||
200 | 124 |
qed_goal "contrapos" HOL.thy "[| ~Q; P==>Q |] ==> ~P" |
0 | 125 |
(fn [major,minor]=> |
126 |
[ (rtac (major RS notE RS notI) 1), |
|
127 |
(etac minor 1) ]); |
|
128 |
||
129 |
(* ~(?t = ?s) ==> ~(?s = ?t) *) |
|
130 |
val [not_sym] = compose(sym,2,contrapos); |
|
131 |
||
132 |
||
133 |
(** Existential quantifier **) |
|
134 |
||
200 | 135 |
qed_goalw "exI" HOL.thy [Ex_def] "P(x) ==> ? x::'a.P(x)" |
66 | 136 |
(fn prems => [rtac selectI 1, resolve_tac prems 1]); |
0 | 137 |
|
200 | 138 |
qed_goalw "exE" HOL.thy [Ex_def] |
66 | 139 |
"[| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q" |
140 |
(fn prems => [REPEAT(resolve_tac prems 1)]); |
|
0 | 141 |
|
142 |
||
143 |
(** Conjunction **) |
|
144 |
||
200 | 145 |
qed_goalw "conjI" HOL.thy [and_def] "[| P; Q |] ==> P&Q" |
0 | 146 |
(fn prems => |
66 | 147 |
[REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)]); |
0 | 148 |
|
200 | 149 |
qed_goalw "conjunct1" HOL.thy [and_def] "[| P & Q |] ==> P" |
0 | 150 |
(fn prems => |
66 | 151 |
[resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]); |
0 | 152 |
|
200 | 153 |
qed_goalw "conjunct2" HOL.thy [and_def] "[| P & Q |] ==> Q" |
0 | 154 |
(fn prems => |
66 | 155 |
[resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]); |
0 | 156 |
|
200 | 157 |
qed_goal "conjE" HOL.thy "[| P&Q; [| P; Q |] ==> R |] ==> R" |
0 | 158 |
(fn prems => |
159 |
[cut_facts_tac prems 1, resolve_tac prems 1, |
|
160 |
etac conjunct1 1, etac conjunct2 1]); |
|
161 |
||
162 |
(** Disjunction *) |
|
163 |
||
200 | 164 |
qed_goalw "disjI1" HOL.thy [or_def] "P ==> P|Q" |
66 | 165 |
(fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
0 | 166 |
|
200 | 167 |
qed_goalw "disjI2" HOL.thy [or_def] "Q ==> P|Q" |
66 | 168 |
(fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]); |
0 | 169 |
|
200 | 170 |
qed_goalw "disjE" HOL.thy [or_def] "[| P | Q; P ==> R; Q ==> R |] ==> R" |
0 | 171 |
(fn [a1,a2,a3] => |
66 | 172 |
[rtac (mp RS mp) 1, rtac spec 1, rtac a1 1, |
155 | 173 |
rtac (a2 RS impI) 1, assume_tac 1, rtac (a3 RS impI) 1, assume_tac 1]); |
0 | 174 |
|
175 |
(** CCONTR -- classical logic **) |
|
176 |
||
200 | 177 |
qed_goalw "classical" HOL.thy [not_def] "(~P ==> P) ==> P" |
155 | 178 |
(fn [prem] => |
179 |
[rtac (True_or_False RS (disjE RS eqTrueE)) 1, assume_tac 1, |
|
180 |
rtac (impI RS prem RS eqTrueI) 1, |
|
181 |
etac subst 1, assume_tac 1]); |
|
0 | 182 |
|
155 | 183 |
val ccontr = FalseE RS classical; |
0 | 184 |
|
185 |
(*Double negation law*) |
|
200 | 186 |
qed_goal "notnotD" HOL.thy "~~P ==> P" |
0 | 187 |
(fn [major]=> |
188 |
[ (rtac classical 1), (eresolve_tac [major RS notE] 1) ]); |
|
189 |
||
190 |
||
191 |
(** Unique existence **) |
|
192 |
||
200 | 193 |
qed_goalw "ex1I" HOL.thy [Ex1_def] |
0 | 194 |
"[| P(a); !!x. P(x) ==> x=a |] ==> ?! x. P(x)" |
195 |
(fn prems => |
|
66 | 196 |
[REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)]); |
0 | 197 |
|
200 | 198 |
qed_goalw "ex1E" HOL.thy [Ex1_def] |
0 | 199 |
"[| ?! x.P(x); !!x. [| P(x); ! y. P(y) --> y=x |] ==> R |] ==> R" |
200 |
(fn major::prems => |
|
66 | 201 |
[rtac (major RS exE) 1, REPEAT (etac conjE 1 ORELSE ares_tac prems 1)]); |
0 | 202 |
|
203 |
||
204 |
(** Select: Hilbert's Epsilon-operator **) |
|
205 |
||
153 | 206 |
(*Easier to apply than selectI: conclusion has only one occurrence of P*) |
200 | 207 |
qed_goal "selectI2" HOL.thy |
153 | 208 |
"[| P(a); !!x. P(x) ==> Q(x) |] ==> Q(@x.P(x))" |
0 | 209 |
(fn prems => [ resolve_tac prems 1, |
210 |
rtac selectI 1, |
|
211 |
resolve_tac prems 1 ]); |
|
212 |
||
200 | 213 |
qed_goal "select_equality" HOL.thy |
153 | 214 |
"[| P(a); !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a" |
215 |
(fn prems => [ rtac selectI2 1, |
|
216 |
REPEAT (ares_tac prems 1) ]); |
|
217 |
||
218 |
||
0 | 219 |
(** Classical intro rules for disjunction and existential quantifiers *) |
220 |
||
200 | 221 |
qed_goal "disjCI" HOL.thy "(~Q ==> P) ==> P|Q" |
0 | 222 |
(fn prems=> |
223 |
[ (rtac classical 1), |
|
224 |
(REPEAT (ares_tac (prems@[disjI1,notI]) 1)), |
|
225 |
(REPEAT (ares_tac (prems@[disjI2,notE]) 1)) ]); |
|
226 |
||
200 | 227 |
qed_goal "excluded_middle" HOL.thy "~P | P" |
0 | 228 |
(fn _ => [ (REPEAT (ares_tac [disjCI] 1)) ]); |
229 |
||
128 | 230 |
(*For disjunctive case analysis*) |
231 |
fun excluded_middle_tac sP = |
|
232 |
res_inst_tac [("Q",sP)] (excluded_middle RS disjE); |
|
233 |
||
0 | 234 |
(*Classical implies (-->) elimination. *) |
200 | 235 |
qed_goal "impCE" HOL.thy "[| P-->Q; ~P ==> R; Q ==> R |] ==> R" |
0 | 236 |
(fn major::prems=> |
237 |
[ rtac (excluded_middle RS disjE) 1, |
|
238 |
REPEAT (DEPTH_SOLVE_1 (ares_tac (prems @ [major RS mp]) 1))]); |
|
239 |
||
240 |
(*Classical <-> elimination. *) |
|
200 | 241 |
qed_goal "iffCE" HOL.thy |
0 | 242 |
"[| P=Q; [| P; Q |] ==> R; [| ~P; ~Q |] ==> R |] ==> R" |
243 |
(fn major::prems => |
|
244 |
[ (rtac (major RS iffE) 1), |
|
245 |
(REPEAT (DEPTH_SOLVE_1 |
|
246 |
(eresolve_tac ([asm_rl,impCE,notE]@prems) 1))) ]); |
|
247 |
||
200 | 248 |
qed_goal "exCI" HOL.thy "(! x. ~P(x) ==> P(a)) ==> ? x.P(x)" |
0 | 249 |
(fn prems=> |
250 |
[ (rtac ccontr 1), |
|
251 |
(REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1)) ]); |
|
252 |
||
253 |
||
40 | 254 |
(* case distinction *) |
255 |
||
200 | 256 |
qed_goal "case_split_thm" HOL.thy "[| P ==> Q; ~P ==> Q |] ==> Q" |
40 | 257 |
(fn [p1,p2] => [cut_facts_tac [excluded_middle] 1, etac disjE 1, |
258 |
etac p2 1, etac p1 1]); |
|
259 |
||
260 |
fun case_tac a = res_inst_tac [("P",a)] case_split_thm; |
|
261 |
||
0 | 262 |
(** Standard abbreviations **) |
263 |
||
264 |
fun stac th = rtac(th RS ssubst); |
|
265 |
fun sstac ths = EVERY' (map stac ths); |
|
266 |
fun strip_tac i = REPEAT(resolve_tac [impI,allI] i); |