src/HOL/ex/meson.ML
changeset 5317 3a9214482762
parent 4663 27fa93c22b9b
child 7563 26ca52846865
equal deleted inserted replaced
5316:7a8975451a89 5317:3a9214482762
    10 NEED TO SORT LITERALS BY # OF VARS, USING ==>I/E.  ELIMINATES NEED FOR
    10 NEED TO SORT LITERALS BY # OF VARS, USING ==>I/E.  ELIMINATES NEED FOR
    11 FUNCTION nodups -- if done to goal clauses too!
    11 FUNCTION nodups -- if done to goal clauses too!
    12 *)
    12 *)
    13 
    13 
    14 writeln"File HOL/ex/meson.";
    14 writeln"File HOL/ex/meson.";
       
    15 
       
    16 context HOL.thy;
    15 
    17 
    16 (*Prove theorems using fast_tac*)
    18 (*Prove theorems using fast_tac*)
    17 fun prove_fun s = 
    19 fun prove_fun s = 
    18     prove_goal HOL.thy s
    20     prove_goal HOL.thy s
    19          (fn prems => [ cut_facts_tac prems 1, Fast_tac 1 ]);
    21          (fn prems => [ cut_facts_tac prems 1, Fast_tac 1 ]);
    70 val disj_FalseD2 = prove_fun "P|False ==> P";
    72 val disj_FalseD2 = prove_fun "P|False ==> P";
    71 
    73 
    72 (*** Generation of contrapositives ***)
    74 (*** Generation of contrapositives ***)
    73 
    75 
    74 (*Inserts negated disjunct after removing the negation; P is a literal*)
    76 (*Inserts negated disjunct after removing the negation; P is a literal*)
    75 val [major,minor] = goal HOL.thy "~P|Q ==> ((~P==>P) ==> Q)";
    77 val [major,minor] = Goal "~P|Q ==> ((~P==>P) ==> Q)";
    76 by (rtac (major RS disjE) 1);
    78 by (rtac (major RS disjE) 1);
    77 by (rtac notE 1);
    79 by (rtac notE 1);
    78 by (etac minor 2);
    80 by (etac minor 2);
    79 by (ALLGOALS assume_tac);
    81 by (ALLGOALS assume_tac);
    80 qed "make_neg_rule";
    82 qed "make_neg_rule";
    81 
    83 
    82 (*For Plaisted's "Postive refinement" of the MESON procedure*)
    84 (*For Plaisted's "Postive refinement" of the MESON procedure*)
    83 val [major,minor] = goal HOL.thy "~P|Q ==> (P ==> Q)";
    85 Goal "~P|Q ==> (P ==> Q)";
    84 by (rtac (major RS disjE) 1);
    86 by (Blast_tac 1);
    85 by (rtac notE 1);
       
    86 by (rtac minor 2);
       
    87 by (ALLGOALS assume_tac);
       
    88 qed "make_refined_neg_rule";
    87 qed "make_refined_neg_rule";
    89 
    88 
    90 (*P should be a literal*)
    89 (*P should be a literal*)
    91 val [major,minor] = goal HOL.thy "P|Q ==> ((P==>~P) ==> Q)";
    90 val [major,minor] = Goal "P|Q ==> ((P==>~P) ==> Q)";
    92 by (rtac (major RS disjE) 1);
    91 by (rtac (major RS disjE) 1);
    93 by (rtac notE 1);
    92 by (rtac notE 1);
    94 by (etac minor 1);
    93 by (etac minor 1);
    95 by (ALLGOALS assume_tac);
    94 by (ALLGOALS assume_tac);
    96 qed "make_pos_rule";
    95 qed "make_pos_rule";
    97 
    96 
    98 (*** Generation of a goal clause -- put away the final literal ***)
    97 (*** Generation of a goal clause -- put away the final literal ***)
    99 
    98 
   100 val [major,minor] = goal HOL.thy "~P ==> ((~P==>P) ==> False)";
    99 val [major,minor] = Goal "~P ==> ((~P==>P) ==> False)";
   101 by (rtac notE 1);
   100 by (rtac notE 1);
   102 by (rtac minor 2);
   101 by (rtac minor 2);
   103 by (ALLGOALS (rtac major));
   102 by (ALLGOALS (rtac major));
   104 qed "make_neg_goal";
   103 qed "make_neg_goal";
   105 
   104 
   106 val [major,minor] = goal HOL.thy "P ==> ((P==>~P) ==> False)";
   105 val [major,minor] = Goal "P ==> ((P==>~P) ==> False)";
   107 by (rtac notE 1);
   106 by (rtac notE 1);
   108 by (rtac minor 1);
   107 by (rtac minor 1);
   109 by (ALLGOALS (rtac major));
   108 by (ALLGOALS (rtac major));
   110 qed "make_pos_goal";
   109 qed "make_pos_goal";
   111 
   110 
   112 
   111 
   113 (**** Lemmas for forward proof (like congruence rules) ****)
   112 (**** Lemmas for forward proof (like congruence rules) ****)
   114 
   113 
   115 (*NOTE: could handle conjunctions (faster?) by
   114 (*NOTE: could handle conjunctions (faster?) by
   116     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
   115     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
   117 val major::prems = goal HOL.thy
   116 val major::prems = Goal
   118     "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q";
   117     "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q";
   119 by (rtac (major RS conjE) 1);
   118 by (rtac (major RS conjE) 1);
   120 by (rtac conjI 1);
   119 by (rtac conjI 1);
   121 by (ALLGOALS (eresolve_tac prems));
   120 by (ALLGOALS (eresolve_tac prems));
   122 qed "conj_forward";
   121 qed "conj_forward";
   123 
   122 
   124 val major::prems = goal HOL.thy
   123 val major::prems = Goal
   125     "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q";
   124     "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q";
   126 by (rtac (major RS disjE) 1);
   125 by (rtac (major RS disjE) 1);
   127 by (ALLGOALS (dresolve_tac prems));
   126 by (ALLGOALS (dresolve_tac prems));
   128 by (ALLGOALS (eresolve_tac [disjI1,disjI2]));
   127 by (ALLGOALS (eresolve_tac [disjI1,disjI2]));
   129 qed "disj_forward";
   128 qed "disj_forward";
   130 
   129 
   131 val major::prems = goal HOL.thy
   130 val major::prems = Goal
   132     "[| ! x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ! x. P(x)";
   131     "[| ! x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ! x. P(x)";
   133 by (rtac allI 1);
   132 by (rtac allI 1);
   134 by (resolve_tac prems 1);
   133 by (resolve_tac prems 1);
   135 by (rtac (major RS spec) 1);
   134 by (rtac (major RS spec) 1);
   136 qed "all_forward";
   135 qed "all_forward";
   137 
   136 
   138 val major::prems = goal HOL.thy
   137 val major::prems = Goal
   139     "[| ? x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ? x. P(x)";
   138     "[| ? x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ? x. P(x)";
   140 by (rtac (major RS exE) 1);
   139 by (rtac (major RS exE) 1);
   141 by (rtac exI 1);
   140 by (rtac exI 1);
   142 by (eresolve_tac prems 1);
   141 by (eresolve_tac prems 1);
   143 qed "ex_forward";
   142 qed "ex_forward";
   247     handle THM _ => (*not a conjunction*) cnf_aux [] (th, ths));
   246     handle THM _ => (*not a conjunction*) cnf_aux [] (th, ths));
   248 
   247 
   249 (**** Removal of duplicate literals ****)
   248 (**** Removal of duplicate literals ****)
   250 
   249 
   251 (*Version for removal of duplicate literals*)
   250 (*Version for removal of duplicate literals*)
   252 val major::prems = goal HOL.thy
   251 val major::prems = Goal
   253     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q";
   252     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q";
   254 by (rtac (major RS disjE) 1);
   253 by (rtac (major RS disjE) 1);
   255 by (rtac disjI1 1);
   254 by (rtac disjI1 1);
   256 by (rtac (disjCI RS disj_comm) 2);
   255 by (rtac (disjCI RS disj_comm) 2);
   257 by (ALLGOALS (eresolve_tac prems));
   256 by (ALLGOALS (eresolve_tac prems));