src/HOL/HOL_lemmas.ML
changeset 9159 902ea754eee2
parent 9058 7856a01119fb
child 9404 99476cf93dad
equal deleted inserted replaced
9158:084abf3d0eff 9159:902ea754eee2
   129 
   129 
   130 
   130 
   131 (** Universal quantifier **)
   131 (** Universal quantifier **)
   132 section "!";
   132 section "!";
   133 
   133 
   134 val prems = Goalw [All_def] "(!!x::'a. P(x)) ==> ! x. P(x)";
   134 val prems = Goalw [All_def] "(!!x::'a. P(x)) ==> ALL x. P(x)";
   135 by (resolve_tac (prems RL [eqTrueI RS ext]) 1);
   135 by (resolve_tac (prems RL [eqTrueI RS ext]) 1);
   136 qed "allI";
   136 qed "allI";
   137 
   137 
   138 Goalw [All_def] "! x::'a. P(x) ==> P(x)";
   138 Goalw [All_def] "ALL x::'a. P(x) ==> P(x)";
   139 by (rtac eqTrueE 1);
   139 by (rtac eqTrueE 1);
   140 by (etac fun_cong 1);
   140 by (etac fun_cong 1);
   141 qed "spec";
   141 qed "spec";
   142 
   142 
   143 val major::prems= goal (the_context ()) "[| ! x. P(x);  P(x) ==> R |] ==> R";
   143 val major::prems= goal (the_context ()) "[| ALL x. P(x);  P(x) ==> R |] ==> R";
   144 by (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ;
   144 by (REPEAT (resolve_tac (prems @ [major RS spec]) 1)) ;
   145 qed "allE";
   145 qed "allE";
   146 
   146 
   147 val prems = goal (the_context ()) 
   147 val prems = goal (the_context ()) 
   148     "[| ! x. P(x);  [| P(x); ! x. P(x) |] ==> R |] ==> R";
   148     "[| ALL x. P(x);  [| P(x); ALL x. P(x) |] ==> R |] ==> R";
   149 by (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ;
   149 by (REPEAT (resolve_tac (prems @ (prems RL [spec])) 1)) ;
   150 qed "all_dupE";
   150 qed "all_dupE";
   151 
   151 
   152 
   152 
   153 (** False ** Depends upon spec; it is impossible to do propositional logic
   153 (** False ** Depends upon spec; it is impossible to do propositional logic
   185 Goalw [not_def] "[| ~P;  P |] ==> R";
   185 Goalw [not_def] "[| ~P;  P |] ==> R";
   186 by (etac (mp RS FalseE) 1);
   186 by (etac (mp RS FalseE) 1);
   187 by (assume_tac 1);
   187 by (assume_tac 1);
   188 qed "notE";
   188 qed "notE";
   189 
   189 
   190 bind_thm ("classical2", notE RS notI);
   190 (* Alternative ~ introduction rule: [| P ==> ~ Pa; P ==> Pa |] ==> ~ P *)
   191 
   191 bind_thm ("notI2", notE RS notI);
   192 Goal "[| P; ~P |] ==> R";
       
   193 by (etac notE 1);
       
   194 by (assume_tac 1);
       
   195 qed "rev_notE";
       
   196 
   192 
   197 
   193 
   198 (** Implication **)
   194 (** Implication **)
   199 section "-->";
   195 section "-->";
   200 
   196 
   215 val [major,minor] = Goal "[| P==>Q; ~Q |] ==> ~P";
   211 val [major,minor] = Goal "[| P==>Q; ~Q |] ==> ~P";
   216 by (rtac (minor RS contrapos) 1);
   212 by (rtac (minor RS contrapos) 1);
   217 by (etac major 1) ;
   213 by (etac major 1) ;
   218 qed "rev_contrapos";
   214 qed "rev_contrapos";
   219 
   215 
   220 (* ~(?t = ?s) ==> ~(?s = ?t) *)
   216 (* t ~= s ==> s ~= t *)
   221 bind_thm("not_sym", sym COMP rev_contrapos);
   217 bind_thm("not_sym", sym COMP rev_contrapos);
   222 
   218 
   223 
   219 
   224 (** Existential quantifier **)
   220 (** Existential quantifier **)
   225 section "?";
   221 section "EX ";
   226 
   222 
   227 Goalw [Ex_def] "P x ==> ? x::'a. P x";
   223 Goalw [Ex_def] "P x ==> EX x::'a. P x";
   228 by (etac selectI 1) ;
   224 by (etac selectI 1) ;
   229 qed "exI";
   225 qed "exI";
   230 
   226 
   231 val [major,minor] = 
   227 val [major,minor] = 
   232 Goalw [Ex_def] "[| ? x::'a. P(x); !!x. P(x) ==> Q |] ==> Q";
   228 Goalw [Ex_def] "[| EX x::'a. P(x); !!x. P(x) ==> Q |] ==> Q";
   233 by (rtac (major RS minor) 1);
   229 by (rtac (major RS minor) 1);
   234 qed "exE";
   230 qed "exE";
   235 
   231 
   236 
   232 
   237 (** Conjunction **)
   233 (** Conjunction **)
   299 by (assume_tac 1);
   295 by (assume_tac 1);
   300 qed "classical";
   296 qed "classical";
   301 
   297 
   302 bind_thm ("ccontr", FalseE RS classical);
   298 bind_thm ("ccontr", FalseE RS classical);
   303 
   299 
       
   300 (*notE with premises exchanged; it discharges ~R so that it can be used to
       
   301   make elimination rules*)
       
   302 val [premp,premnot] = Goal "[| P; ~R ==> ~P |] ==> R";
       
   303 by (rtac ccontr 1);
       
   304 by (etac ([premnot,premp] MRS notE) 1);
       
   305 qed "rev_notE";
       
   306 
   304 (*Double negation law*)
   307 (*Double negation law*)
   305 Goal "~~P ==> P";
   308 Goal "~~P ==> P";
   306 by (rtac classical 1);
   309 by (rtac classical 1);
   307 by (etac notE 1);
   310 by (etac notE 1);
   308 by (assume_tac 1);
   311 by (assume_tac 1);
   321 by (etac notE 1);
   324 by (etac notE 1);
   322 by (rtac p1 1);
   325 by (rtac p1 1);
   323 qed "swap2";
   326 qed "swap2";
   324 
   327 
   325 (** Unique existence **)
   328 (** Unique existence **)
   326 section "?!";
   329 section "EX!";
   327 
   330 
   328 val prems = Goalw [Ex1_def] "[| P(a);  !!x. P(x) ==> x=a |] ==> ?! x. P(x)";
   331 val prems = Goalw [Ex1_def] "[| P(a);  !!x. P(x) ==> x=a |] ==> EX! x. P(x)";
   329 by (REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1));
   332 by (REPEAT (ares_tac (prems@[exI,conjI,allI,impI]) 1));
   330 qed "ex1I";
   333 qed "ex1I";
   331 
   334 
   332 (*Sometimes easier to use: the premises have no shared variables.  Safe!*)
   335 (*Sometimes easier to use: the premises have no shared variables.  Safe!*)
   333 val [ex_prem,eq] = Goal
   336 val [ex_prem,eq] = Goal
   334     "[| ? x. P(x);  !!x y. [| P(x); P(y) |] ==> x=y |] ==> ?! x. P(x)";
   337     "[| EX x. P(x);  !!x y. [| P(x); P(y) |] ==> x=y |] ==> EX! x. P(x)";
   335 by (rtac (ex_prem RS exE) 1);
   338 by (rtac (ex_prem RS exE) 1);
   336 by (REPEAT (ares_tac [ex1I,eq] 1)) ;
   339 by (REPEAT (ares_tac [ex1I,eq] 1)) ;
   337 qed "ex_ex1I";
   340 qed "ex_ex1I";
   338 
   341 
   339 val major::prems = Goalw [Ex1_def]
   342 val major::prems = Goalw [Ex1_def]
   340     "[| ?! x. P(x);  !!x. [| P(x);  ! y. P(y) --> y=x |] ==> R |] ==> R";
   343     "[| EX! x. P(x);  !!x. [| P(x);  ALL y. P(y) --> y=x |] ==> R |] ==> R";
   341 by (rtac (major RS exE) 1);
   344 by (rtac (major RS exE) 1);
   342 by (REPEAT (etac conjE 1 ORELSE ares_tac prems 1));
   345 by (REPEAT (etac conjE 1 ORELSE ares_tac prems 1));
   343 qed "ex1E";
   346 qed "ex1E";
   344 
   347 
   345 Goal "?! x. P x ==> ? x. P x";
   348 Goal "EX! x. P x ==> EX x. P x";
   346 by (etac ex1E 1);
   349 by (etac ex1E 1);
   347 by (rtac exI 1);
   350 by (rtac exI 1);
   348 by (assume_tac 1);
   351 by (assume_tac 1);
   349 qed "ex1_implies_ex";
   352 qed "ex1_implies_ex";
   350 
   353 
   359 by (rtac selectI 1);
   362 by (rtac selectI 1);
   360 by (resolve_tac prems 1) ;
   363 by (resolve_tac prems 1) ;
   361 qed "selectI2";
   364 qed "selectI2";
   362 
   365 
   363 (*Easier to apply than selectI2 if witness ?a comes from an EX-formula*)
   366 (*Easier to apply than selectI2 if witness ?a comes from an EX-formula*)
   364 val [major,minor] = Goal "[| ? a. P a;  !!x. P x ==> Q x |] ==> Q (Eps P)";
   367 val [major,minor] = Goal "[| EX a. P a;  !!x. P x ==> Q x |] ==> Q (Eps P)";
   365 by (rtac (major RS exE) 1);
   368 by (rtac (major RS exE) 1);
   366 by (etac selectI2 1 THEN etac minor 1);
   369 by (etac selectI2 1 THEN etac minor 1);
   367 qed "selectI2EX";
   370 qed "selectI2EX";
   368 
   371 
   369 val prems = Goal
   372 val prems = Goal
   370     "[| P a;  !!x. P x ==> x=a |] ==> (@x. P x) = a";
   373     "[| P a;  !!x. P x ==> x=a |] ==> (@x. P x) = a";
   371 by (rtac selectI2 1);
   374 by (rtac selectI2 1);
   372 by (REPEAT (ares_tac prems 1)) ;
   375 by (REPEAT (ares_tac prems 1)) ;
   373 qed "select_equality";
   376 qed "select_equality";
   374 
   377 
   375 Goalw [Ex1_def] "[| ?!x. P x; P a |] ==> (@x. P x) = a";
   378 Goalw [Ex1_def] "[| EX!x. P x; P a |] ==> (@x. P x) = a";
   376 by (rtac select_equality 1);
   379 by (rtac select_equality 1);
   377 by (atac 1);
   380 by (atac 1);
   378 by (etac exE 1);
   381 by (etac exE 1);
   379 by (etac conjE 1);
   382 by (etac conjE 1);
   380 by (rtac allE 1);
   383 by (rtac allE 1);
   385 by (etac allE 1);
   388 by (etac allE 1);
   386 by (etac mp 1);
   389 by (etac mp 1);
   387 by (atac 1);
   390 by (atac 1);
   388 qed "select1_equality";
   391 qed "select1_equality";
   389 
   392 
   390 Goal "P (@ x. P x) =  (? x. P x)";
   393 Goal "P (@ x. P x) =  (EX x. P x)";
   391 by (rtac iffI 1);
   394 by (rtac iffI 1);
   392 by (etac exI 1);
   395 by (etac exI 1);
   393 by (etac exE 1);
   396 by (etac exE 1);
   394 by (etac selectI 1);
   397 by (etac selectI 1);
   395 qed "select_eq_Ex";
   398 qed "select_eq_Ex";
   444 by (rtac (major RS iffE) 1);
   447 by (rtac (major RS iffE) 1);
   445 by (REPEAT (DEPTH_SOLVE_1 
   448 by (REPEAT (DEPTH_SOLVE_1 
   446 	    (eresolve_tac ([asm_rl,impCE,notE]@prems) 1)));
   449 	    (eresolve_tac ([asm_rl,impCE,notE]@prems) 1)));
   447 qed "iffCE";
   450 qed "iffCE";
   448 
   451 
   449 val prems = Goal "(! x. ~P(x) ==> P(a)) ==> ? x. P(x)";
   452 val prems = Goal "(ALL x. ~P(x) ==> P(a)) ==> EX x. P(x)";
   450 by (rtac ccontr 1);
   453 by (rtac ccontr 1);
   451 by (REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1))  ;
   454 by (REPEAT (ares_tac (prems@[exI,allI,notI,notE]) 1))  ;
   452 qed "exCI";
   455 qed "exCI";
   453 
   456 
   454 Goal "x + (y+z) = y + ((x+z)::'a::plus_ac0)";
   457 Goal "x + (y+z) = y + ((x+z)::'a::plus_ac0)";
   498 end;
   501 end;
   499 
   502 
   500 
   503 
   501 fun strip_tac i = REPEAT(resolve_tac [impI,allI] i); 
   504 fun strip_tac i = REPEAT(resolve_tac [impI,allI] i); 
   502 
   505 
   503 (** strip ! and --> from proved goal while preserving !-bound var names **)
   506 (** strip ALL and --> from proved goal while preserving ALL-bound var names **)
   504 
   507 
   505 (** THIS CODE IS A MESS!!! **)
   508 (** THIS CODE IS A MESS!!! **)
   506 
   509 
   507 local
   510 local
   508 
   511