src/HOL/HOL.ML
changeset 923 ff1574a81019
child 1334 32a9fde85699
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/HOL.ML	Fri Mar 03 12:02:25 1995 +0100
     1.3 @@ -0,0 +1,266 @@
     1.4 +(*  Title: 	HOL/hol.ML
     1.5 +    ID:         $Id$
     1.6 +    Author: 	Tobias Nipkow
     1.7 +    Copyright   1991  University of Cambridge
     1.8 +
     1.9 +For hol.thy
    1.10 +Derived rules from Appendix of Mike Gordons HOL Report, Cambridge TR 68 
    1.11 +*)
    1.12 +
    1.13 +open HOL;
    1.14 +
    1.15 +
    1.16 +(** Equality **)
    1.17 +
    1.18 +qed_goal "sym" HOL.thy "s=t ==> t=s"
    1.19 + (fn prems => [cut_facts_tac prems 1, etac subst 1, rtac refl 1]);
    1.20 +
    1.21 +(*calling "standard" reduces maxidx to 0*)
    1.22 +bind_thm ("ssubst", (sym RS subst));
    1.23 +
    1.24 +qed_goal "trans" HOL.thy "[| r=s; s=t |] ==> r=t"
    1.25 + (fn prems =>
    1.26 +	[rtac subst 1, resolve_tac prems 1, resolve_tac prems 1]);
    1.27 +
    1.28 +(*Useful with eresolve_tac for proving equalties from known equalities.
    1.29 +	a = b
    1.30 +	|   |
    1.31 +	c = d	*)
    1.32 +qed_goal "box_equals" HOL.thy
    1.33 +    "[| a=b;  a=c;  b=d |] ==> c=d"  
    1.34 + (fn prems=>
    1.35 +  [ (rtac trans 1),
    1.36 +    (rtac trans 1),
    1.37 +    (rtac sym 1),
    1.38 +    (REPEAT (resolve_tac prems 1)) ]);
    1.39 +
    1.40 +(** Congruence rules for meta-application **)
    1.41 +
    1.42 +(*similar to AP_THM in Gordon's HOL*)
    1.43 +qed_goal "fun_cong" HOL.thy "(f::'a=>'b) = g ==> f(x)=g(x)"
    1.44 +  (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
    1.45 +
    1.46 +(*similar to AP_TERM in Gordon's HOL and FOL's subst_context*)
    1.47 +qed_goal "arg_cong" HOL.thy "x=y ==> f(x)=f(y)"
    1.48 + (fn [prem] => [rtac (prem RS subst) 1, rtac refl 1]);
    1.49 +
    1.50 +qed_goal "cong" HOL.thy
    1.51 +   "[| f = g; (x::'a) = y |] ==> f(x) = g(y)"
    1.52 + (fn [prem1,prem2] =>
    1.53 +   [rtac (prem1 RS subst) 1, rtac (prem2 RS subst) 1, rtac refl 1]);
    1.54 +
    1.55 +(** Equality of booleans -- iff **)
    1.56 +
    1.57 +qed_goal "iffI" HOL.thy
    1.58 +   "[| P ==> Q;  Q ==> P |] ==> P=Q"
    1.59 + (fn prems=> [ (REPEAT (ares_tac (prems@[impI, iff RS mp RS mp]) 1)) ]);
    1.60 +
    1.61 +qed_goal "iffD2" HOL.thy "[| P=Q; Q |] ==> P"
    1.62 + (fn prems =>
    1.63 +	[rtac ssubst 1, resolve_tac prems 1, resolve_tac prems 1]);
    1.64 +
    1.65 +val iffD1 = sym RS iffD2;
    1.66 +
    1.67 +qed_goal "iffE" HOL.thy
    1.68 +    "[| P=Q; [| P --> Q; Q --> P |] ==> R |] ==> R"
    1.69 + (fn [p1,p2] => [REPEAT(ares_tac([p1 RS iffD2, p1 RS iffD1, p2, impI])1)]);
    1.70 +
    1.71 +(** True **)
    1.72 +
    1.73 +qed_goalw "TrueI" HOL.thy [True_def] "True"
    1.74 +  (fn _ => [rtac refl 1]);
    1.75 +
    1.76 +qed_goal "eqTrueI " HOL.thy "P ==> P=True" 
    1.77 + (fn prems => [REPEAT(resolve_tac ([iffI,TrueI]@prems) 1)]);
    1.78 +
    1.79 +qed_goal "eqTrueE" HOL.thy "P=True ==> P" 
    1.80 + (fn prems => [REPEAT(resolve_tac (prems@[TrueI,iffD2]) 1)]);
    1.81 +
    1.82 +(** Universal quantifier **)
    1.83 +
    1.84 +qed_goalw "allI" HOL.thy [All_def] "(!!x::'a. P(x)) ==> !x. P(x)"
    1.85 + (fn prems => [resolve_tac (prems RL [eqTrueI RS ext]) 1]);
    1.86 +
    1.87 +qed_goalw "spec" HOL.thy [All_def] "! x::'a.P(x) ==> P(x)"
    1.88 + (fn prems => [rtac eqTrueE 1, resolve_tac (prems RL [fun_cong]) 1]);
    1.89 +
    1.90 +qed_goal "allE" HOL.thy "[| !x.P(x);  P(x) ==> R |] ==> R"
    1.91 + (fn major::prems=>
    1.92 +  [ (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ]);
    1.93 +
    1.94 +qed_goal "all_dupE" HOL.thy 
    1.95 +    "[| ! x.P(x);  [| P(x); ! x.P(x) |] ==> R |] ==> R"
    1.96 + (fn prems =>
    1.97 +  [ (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ]);
    1.98 +
    1.99 +
   1.100 +(** False ** Depends upon spec; it is impossible to do propositional logic
   1.101 +             before quantifiers! **)
   1.102 +
   1.103 +qed_goalw "FalseE" HOL.thy [False_def] "False ==> P"
   1.104 + (fn [major] => [rtac (major RS spec) 1]);
   1.105 +
   1.106 +qed_goal "False_neq_True" HOL.thy "False=True ==> P"
   1.107 + (fn [prem] => [rtac (prem RS eqTrueE RS FalseE) 1]);
   1.108 +
   1.109 +
   1.110 +(** Negation **)
   1.111 +
   1.112 +qed_goalw "notI" HOL.thy [not_def] "(P ==> False) ==> ~P"
   1.113 + (fn prems=> [rtac impI 1, eresolve_tac prems 1]);
   1.114 +
   1.115 +qed_goalw "notE" HOL.thy [not_def] "[| ~P;  P |] ==> R"
   1.116 + (fn prems => [rtac (prems MRS mp RS FalseE) 1]);
   1.117 +
   1.118 +(** Implication **)
   1.119 +
   1.120 +qed_goal "impE" HOL.thy "[| P-->Q;  P;  Q ==> R |] ==> R"
   1.121 + (fn prems=> [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
   1.122 +
   1.123 +(* Reduces Q to P-->Q, allowing substitution in P. *)
   1.124 +qed_goal "rev_mp" HOL.thy "[| P;  P --> Q |] ==> Q"
   1.125 + (fn prems=>  [ (REPEAT (resolve_tac (prems@[mp]) 1)) ]);
   1.126 +
   1.127 +qed_goal "contrapos" HOL.thy "[| ~Q;  P==>Q |] ==> ~P"
   1.128 + (fn [major,minor]=> 
   1.129 +  [ (rtac (major RS notE RS notI) 1), 
   1.130 +    (etac minor 1) ]);
   1.131 +
   1.132 +(* ~(?t = ?s) ==> ~(?s = ?t) *)
   1.133 +val [not_sym] = compose(sym,2,contrapos);
   1.134 +
   1.135 +
   1.136 +(** Existential quantifier **)
   1.137 +
   1.138 +qed_goalw "exI" HOL.thy [Ex_def] "P(x) ==> ? x::'a.P(x)"
   1.139 + (fn prems => [rtac selectI 1, resolve_tac prems 1]);
   1.140 +
   1.141 +qed_goalw "exE" HOL.thy [Ex_def]
   1.142 +  "[| ? x::'a.P(x); !!x. P(x) ==> Q |] ==> Q"
   1.143 +  (fn prems => [REPEAT(resolve_tac prems 1)]);
   1.144 +
   1.145 +
   1.146 +(** Conjunction **)
   1.147 +
   1.148 +qed_goalw "conjI" HOL.thy [and_def] "[| P; Q |] ==> P&Q"
   1.149 + (fn prems =>
   1.150 +  [REPEAT (resolve_tac (prems@[allI,impI]) 1 ORELSE etac (mp RS mp) 1)]);
   1.151 +
   1.152 +qed_goalw "conjunct1" HOL.thy [and_def] "[| P & Q |] ==> P"
   1.153 + (fn prems =>
   1.154 +   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
   1.155 +
   1.156 +qed_goalw "conjunct2" HOL.thy [and_def] "[| P & Q |] ==> Q"
   1.157 + (fn prems =>
   1.158 +   [resolve_tac (prems RL [spec] RL [mp]) 1, REPEAT(ares_tac [impI] 1)]);
   1.159 +
   1.160 +qed_goal "conjE" HOL.thy "[| P&Q;  [| P; Q |] ==> R |] ==> R"
   1.161 + (fn prems =>
   1.162 +	 [cut_facts_tac prems 1, resolve_tac prems 1,
   1.163 +	  etac conjunct1 1, etac conjunct2 1]);
   1.164 +
   1.165 +(** Disjunction *)
   1.166 +
   1.167 +qed_goalw "disjI1" HOL.thy [or_def] "P ==> P|Q"
   1.168 + (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
   1.169 +
   1.170 +qed_goalw "disjI2" HOL.thy [or_def] "Q ==> P|Q"
   1.171 + (fn [prem] => [REPEAT(ares_tac [allI,impI, prem RSN (2,mp)] 1)]);
   1.172 +
   1.173 +qed_goalw "disjE" HOL.thy [or_def] "[| P | Q; P ==> R; Q ==> R |] ==> R"
   1.174 + (fn [a1,a2,a3] =>
   1.175 +	[rtac (mp RS mp) 1, rtac spec 1, rtac a1 1,
   1.176 +	 rtac (a2 RS impI) 1, assume_tac 1, rtac (a3 RS impI) 1, assume_tac 1]);
   1.177 +
   1.178 +(** CCONTR -- classical logic **)
   1.179 +
   1.180 +qed_goalw "classical" HOL.thy [not_def]  "(~P ==> P) ==> P"
   1.181 + (fn [prem] =>
   1.182 +   [rtac (True_or_False RS (disjE RS eqTrueE)) 1,  assume_tac 1,
   1.183 +    rtac (impI RS prem RS eqTrueI) 1,
   1.184 +    etac subst 1,  assume_tac 1]);
   1.185 +
   1.186 +val ccontr = FalseE RS classical;
   1.187 +
   1.188 +(*Double negation law*)
   1.189 +qed_goal "notnotD" HOL.thy "~~P ==> P"
   1.190 + (fn [major]=>
   1.191 +  [ (rtac classical 1), (eresolve_tac [major RS notE] 1) ]);
   1.192 +
   1.193 +
   1.194 +(** Unique existence **)
   1.195 +
   1.196 +qed_goalw "ex1I" HOL.thy [Ex1_def]
   1.197 +    "[| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)"
   1.198 + (fn prems =>
   1.199 +  [REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1)]);
   1.200 +
   1.201 +qed_goalw "ex1E" HOL.thy [Ex1_def]
   1.202 +    "[| ?! x.P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R |] ==> R"
   1.203 + (fn major::prems =>
   1.204 +  [rtac (major RS exE) 1, REPEAT (etac conjE 1 ORELSE ares_tac prems 1)]);
   1.205 +
   1.206 +
   1.207 +(** Select: Hilbert's Epsilon-operator **)
   1.208 +
   1.209 +(*Easier to apply than selectI: conclusion has only one occurrence of P*)
   1.210 +qed_goal "selectI2" HOL.thy
   1.211 +    "[| P(a);  !!x. P(x) ==> Q(x) |] ==> Q(@x.P(x))"
   1.212 + (fn prems => [ resolve_tac prems 1, 
   1.213 +	        rtac selectI 1, 
   1.214 +		resolve_tac prems 1 ]);
   1.215 +
   1.216 +qed_goal "select_equality" HOL.thy
   1.217 +    "[| P(a);  !!x. P(x) ==> x=a |] ==> (@x.P(x)) = a"
   1.218 + (fn prems => [ rtac selectI2 1, 
   1.219 +		REPEAT (ares_tac prems 1) ]);
   1.220 +
   1.221 +
   1.222 +(** Classical intro rules for disjunction and existential quantifiers *)
   1.223 +
   1.224 +qed_goal "disjCI" HOL.thy "(~Q ==> P) ==> P|Q"
   1.225 + (fn prems=>
   1.226 +  [ (rtac classical 1),
   1.227 +    (REPEAT (ares_tac (prems@[disjI1,notI]) 1)),
   1.228 +    (REPEAT (ares_tac (prems@[disjI2,notE]) 1)) ]);
   1.229 +
   1.230 +qed_goal "excluded_middle" HOL.thy "~P | P"
   1.231 + (fn _ => [ (REPEAT (ares_tac [disjCI] 1)) ]);
   1.232 +
   1.233 +(*For disjunctive case analysis*)
   1.234 +fun excluded_middle_tac sP =
   1.235 +    res_inst_tac [("Q",sP)] (excluded_middle RS disjE);
   1.236 +
   1.237 +(*Classical implies (-->) elimination. *)
   1.238 +qed_goal "impCE" HOL.thy "[| P-->Q; ~P ==> R; Q ==> R |] ==> R" 
   1.239 + (fn major::prems=>
   1.240 +  [ rtac (excluded_middle RS disjE) 1,
   1.241 +    REPEAT (DEPTH_SOLVE_1 (ares_tac (prems @ [major RS mp]) 1))]);
   1.242 +
   1.243 +(*Classical <-> elimination. *)
   1.244 +qed_goal "iffCE" HOL.thy
   1.245 +    "[| P=Q;  [| P; Q |] ==> R;  [| ~P; ~Q |] ==> R |] ==> R"
   1.246 + (fn major::prems =>
   1.247 +  [ (rtac (major RS iffE) 1),
   1.248 +    (REPEAT (DEPTH_SOLVE_1 
   1.249 +	(eresolve_tac ([asm_rl,impCE,notE]@prems) 1))) ]);
   1.250 +
   1.251 +qed_goal "exCI" HOL.thy "(! x. ~P(x) ==> P(a)) ==> ? x.P(x)"
   1.252 + (fn prems=>
   1.253 +  [ (rtac ccontr 1),
   1.254 +    (REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1))  ]);
   1.255 +
   1.256 +
   1.257 +(* case distinction *)
   1.258 +
   1.259 +qed_goal "case_split_thm" HOL.thy "[| P ==> Q; ~P ==> Q |] ==> Q"
   1.260 +  (fn [p1,p2] => [cut_facts_tac [excluded_middle] 1, etac disjE 1,
   1.261 +                  etac p2 1, etac p1 1]);
   1.262 +
   1.263 +fun case_tac a = res_inst_tac [("P",a)] case_split_thm;
   1.264 +
   1.265 +(** Standard abbreviations **)
   1.266 +
   1.267 +fun stac th = rtac(th RS ssubst);
   1.268 +fun sstac ths = EVERY' (map stac ths);
   1.269 +fun strip_tac i = REPEAT(resolve_tac [impI,allI] i);