src/HOL/ex/meson.ML
author clasohm
Wed, 22 Mar 1995 12:42:34 +0100
changeset 969 b051e2fc2e34
child 1465 5d7a7e439cec
permissions -rw-r--r--
converted ex with curried function application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     1
(*  Title: 	HOL/ex/meson
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     5
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     6
The MESON resolution proof procedure for HOL
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     7
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     8
When making clauses, avoids using the rewriter -- instead uses RS recursively
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     9
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
writeln"File HOL/ex/meson.";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    12
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    13
(*Prove theorems using fast_tac*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    14
fun prove_fun s = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    15
    prove_goal HOL.thy s
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    16
	 (fn prems => [ cut_facts_tac prems 1, fast_tac HOL_cs 1 ]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    17
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    18
(**** Negation Normal Form ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    19
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    20
(*** de Morgan laws ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    21
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    22
val not_conjD = prove_fun "~(P&Q) ==> ~P | ~Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    23
val not_disjD = prove_fun "~(P|Q) ==> ~P & ~Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    24
val not_notD = prove_fun "~~P ==> P";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    25
val not_allD = prove_fun  "~(! x.P(x)) ==> ? x. ~P(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    26
val not_exD = prove_fun   "~(? x.P(x)) ==> ! x. ~P(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    27
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    28
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
(*** Removal of --> and <-> (positive and negative occurrences) ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    31
val imp_to_disjD = prove_fun "P-->Q ==> ~P | Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    32
val not_impD = prove_fun   "~(P-->Q) ==> P & ~Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    33
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    34
val iff_to_disjD = prove_fun "P=Q ==> (~P | Q) & (~Q | P)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    35
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    36
(*Much more efficient than (P & ~Q) | (Q & ~P) for computing CNF*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    37
val not_iffD = prove_fun "~(P=Q) ==> (P | Q) & (~P | ~Q)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    38
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    39
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    40
(**** Pulling out the existential quantifiers ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    41
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    42
(*** Conjunction ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    43
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    44
val conj_exD1 = prove_fun "(? x.P(x)) & Q ==> ? x. P(x) & Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    45
val conj_exD2 = prove_fun "P & (? x.Q(x)) ==> ? x. P & Q(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    46
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    47
(*** Disjunction ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    48
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    49
(*DO NOT USE with forall-Skolemization: makes fewer schematic variables!!
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    50
  With ex-Skolemization, makes fewer Skolem constants*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    51
val disj_exD = prove_fun "(? x.P(x)) | (? x.Q(x)) ==> ? x. P(x) | Q(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    52
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    53
val disj_exD1 = prove_fun "(? x.P(x)) | Q ==> ? x. P(x) | Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    54
val disj_exD2 = prove_fun "P | (? x.Q(x)) ==> ? x. P | Q(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    55
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    56
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    57
(**** Skolemization -- pulling "?" over "!" ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    58
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    59
(*"Axiom" of Choice, proved using the description operator*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    60
val [major] = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    61
    "! x. ? y. Q x y ==> ? f. ! x. Q x (f x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    62
by (cut_facts_tac [major] 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    63
by (fast_tac (HOL_cs addEs [selectI]) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    64
qed "choice";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    65
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    66
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    67
(***** Generating clauses for the Meson Proof Procedure *****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    68
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    69
(*** Disjunctions ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    70
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    71
val disj_assoc = prove_fun "(P|Q)|R ==> P|(Q|R)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    72
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    73
val disj_comm = prove_fun "P|Q ==> Q|P";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    74
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    75
val disj_FalseD1 = prove_fun "False|P ==> P";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    76
val disj_FalseD2 = prove_fun "P|False ==> P";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    77
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    78
(*** Generation of contrapositives ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    79
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    80
(*Inserts negated disjunct after removing the negation; P is a literal*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    81
val [major,minor] = goal HOL.thy "~P|Q ==> ((~P==>P) ==> Q)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    82
by (rtac (major RS disjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    83
by (rtac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    84
by (etac minor 2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    85
by (ALLGOALS assume_tac);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    86
qed "make_neg_rule";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    87
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    88
(*For Plaisted's "Postive refinement" of the MESON procedure*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    89
val [major,minor] = goal HOL.thy "~P|Q ==> (P ==> Q)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    90
by (rtac (major RS disjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    91
by (rtac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    92
by (rtac minor 2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    93
by (ALLGOALS assume_tac);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    94
qed "make_refined_neg_rule";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    95
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    96
(*P should be a literal*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    97
val [major,minor] = goal HOL.thy "P|Q ==> ((P==>~P) ==> Q)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    98
by (rtac (major RS disjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    99
by (rtac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   100
by (etac minor 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   101
by (ALLGOALS assume_tac);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   102
qed "make_pos_rule";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   103
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   104
(*** Generation of a goal clause -- put away the final literal ***)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   105
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   106
val [major,minor] = goal HOL.thy "~P ==> ((~P==>P) ==> False)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   107
by (rtac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   108
by (rtac minor 2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   109
by (ALLGOALS (rtac major));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   110
qed "make_neg_goal";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   111
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   112
val [major,minor] = goal HOL.thy "P ==> ((P==>~P) ==> False)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   113
by (rtac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   114
by (rtac minor 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   115
by (ALLGOALS (rtac major));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   116
qed "make_pos_goal";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   117
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   118
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   119
(**** Lemmas for forward proof (like congruence rules) ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   120
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   121
(*NOTE: could handle conjunctions (faster?) by
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   122
    nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   123
val major::prems = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   124
    "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   125
by (rtac (major RS conjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   126
by (rtac conjI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   127
by (ALLGOALS (eresolve_tac prems));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   128
qed "conj_forward";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   129
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   130
val major::prems = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   131
    "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   132
by (rtac (major RS disjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   133
by (ALLGOALS (dresolve_tac prems));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   134
by (ALLGOALS (eresolve_tac [disjI1,disjI2]));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   135
qed "disj_forward";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   136
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   137
val major::prems = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   138
    "[| ! x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ! x. P(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   139
by (rtac allI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   140
by (resolve_tac prems 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   141
by (rtac (major RS spec) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   142
qed "all_forward";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   143
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   144
val major::prems = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   145
    "[| ? x. P'(x);  !!x. P'(x) ==> P(x) |] ==> ? x. P(x)";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   146
by (rtac (major RS exE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   147
by (rtac exI 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   148
by (eresolve_tac prems 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   149
qed "ex_forward";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   150
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   151
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   152
(**** Operators for forward proof ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   153
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   154
(*raises exception if no rules apply -- unlike RL*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   155
fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   156
  | tryres (th, []) = raise THM("tryres", 0, [th]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   157
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   158
val prop_of = #prop o rep_thm;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   159
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   160
(*Permits forward proof from rules that discharge assumptions*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   161
fun forward_res nf state =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   162
  case Sequence.pull
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   163
	(tapply(ALLGOALS (METAHYPS (fn [prem] => rtac (nf prem) 1)), 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   164
		state))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   165
  of Some(th,_) => th
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   166
   | None => raise THM("forward_res", 0, [state]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   167
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   168
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   169
(*Negation Normal Form*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   170
val nnf_rls = [imp_to_disjD, iff_to_disjD, not_conjD, not_disjD,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   171
	       not_impD, not_iffD, not_allD, not_exD, not_notD];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   172
fun make_nnf th = make_nnf (tryres(th, nnf_rls))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   173
    handle THM _ => 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   174
	forward_res make_nnf
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   175
      	   (tryres(th, [conj_forward,disj_forward,all_forward,ex_forward]))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   176
    handle THM _ => th;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   177
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   178
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   179
(*Are any of the constants in "bs" present in the term?*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   180
fun has_consts bs = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   181
  let fun has (Const(a,_)) = a mem bs
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   182
	| has (f$u) = has f orelse has u
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   183
	| has (Abs(_,_,t)) = has t
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   184
	| has _ = false
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   185
  in  has  end;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   186
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   187
(*Pull existential quantifiers (Skolemization)*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   188
fun skolemize th = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   189
  if not (has_consts ["Ex"] (prop_of th)) then th
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   190
  else skolemize (tryres(th, [choice, conj_exD1, conj_exD2,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   191
			  disj_exD, disj_exD1, disj_exD2]))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   192
    handle THM _ => 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   193
	skolemize (forward_res skolemize
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   194
		(tryres (th, [conj_forward, disj_forward, all_forward])))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   195
    handle THM _ => forward_res skolemize (th RS ex_forward);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   196
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   197
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   198
(**** Clause handling ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   199
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   200
fun literals (Const("Trueprop",_) $ P) = literals P
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   201
  | literals (Const("op |",_) $ P $ Q) = literals P @ literals Q
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   202
  | literals (Const("not",_) $ P) = [(false,P)]
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   203
  | literals P = [(true,P)];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   204
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   205
(*number of literals in a term*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   206
val nliterals = length o literals;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   207
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   208
(*to delete tautologous clauses*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   209
fun taut_lits [] = false
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   210
  | taut_lits ((flg,t)::ts) = (not flg,t) mem ts orelse taut_lits ts;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   211
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   212
val is_taut = taut_lits o literals o prop_of;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   213
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   214
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   215
(*Generation of unique names -- maxidx cannot be relied upon to increase!
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   216
  Cannot rely on "variant", since variables might coincide when literals
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   217
  are joined to make a clause... 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   218
  19 chooses "U" as the first variable name*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   219
val name_ref = ref 19;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   220
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   221
(*Replaces universally quantified variables by FREE variables -- because
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   222
  assumptions may not contain scheme variables.  Later, call "generalize". *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   223
fun freeze_spec th =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   224
  let val sth = th RS spec
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   225
      val newname = (name_ref := !name_ref + 1;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   226
                     radixstring(26, "A", !name_ref))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   227
  in  read_instantiate [("x", newname)] sth  end;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   228
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   229
fun resop nf [prem] = resolve_tac (nf prem) 1;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   230
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   231
(*Conjunctive normal form, detecting tautologies early.
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   232
  Strips universal quantifiers and breaks up conjunctions. *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   233
fun cnf_aux seen (th,ths) = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   234
  if taut_lits (literals(prop_of th) @ seen)  then ths
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   235
  else if not (has_consts ["All","op &"] (prop_of th))  then th::ths
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   236
  else (*conjunction?*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   237
        cnf_aux seen (th RS conjunct1, 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   238
		      cnf_aux seen (th RS conjunct2, ths))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   239
  handle THM _ => (*universal quant?*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   240
	cnf_aux  seen (freeze_spec th,  ths)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   241
  handle THM _ => (*disjunction?*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   242
    let val tac = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   243
	(METAHYPS (resop (cnf_nil seen)) 1) THEN
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   244
	(STATE (fn st' => 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   245
		METAHYPS (resop (cnf_nil (literals (concl_of st') @ seen))) 1))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   246
    in  Sequence.list_of_s (tapply(tac, th RS disj_forward))  @  ths
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   247
    end
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   248
and cnf_nil seen th = cnf_aux seen (th,[]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   249
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   250
(*Top-level call to cnf -- it's safe to reset name_ref*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   251
fun cnf (th,ths) = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   252
   (name_ref := 19;  cnf (th RS conjunct1, cnf (th RS conjunct2, ths))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   253
    handle THM _ => (*not a conjunction*) cnf_aux [] (th, ths));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   254
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   255
(**** Removal of duplicate literals ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   256
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   257
(*Version for removal of duplicate literals*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   258
val major::prems = goal HOL.thy
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   259
    "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   260
by (rtac (major RS disjE) 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   261
by (rtac disjI1 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   262
by (rtac (disjCI RS disj_comm) 2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   263
by (ALLGOALS (eresolve_tac prems));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   264
by (etac notE 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   265
by (assume_tac 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   266
qed "disj_forward2";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   267
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   268
(*Forward proof, passing extra assumptions as theorems to the tactic*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   269
fun forward_res2 nf hyps state =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   270
  case Sequence.pull
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   271
	(tapply(REPEAT 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   272
	   (METAHYPS (fn major::minors => rtac (nf (minors@hyps) major) 1) 1), 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   273
	   state))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   274
  of Some(th,_) => th
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   275
   | None => raise THM("forward_res2", 0, [state]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   276
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   277
(*Remove duplicates in P|Q by assuming ~P in Q
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   278
  rls (initially []) accumulates assumptions of the form P==>False*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   279
fun nodups_aux rls th = nodups_aux rls (th RS disj_assoc)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   280
    handle THM _ => tryres(th,rls)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   281
    handle THM _ => tryres(forward_res2 nodups_aux rls (th RS disj_forward2),
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   282
			   [disj_FalseD1, disj_FalseD2, asm_rl])
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   283
    handle THM _ => th;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   284
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   285
(*Remove duplicate literals, if there are any*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   286
fun nodups th =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   287
    if null(findrep(literals(prop_of th))) then th
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   288
    else nodups_aux [] th;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   289
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   290
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   291
(**** Generation of contrapositives ****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   292
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   293
(*Associate disjuctions to right -- make leftmost disjunct a LITERAL*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   294
fun assoc_right th = assoc_right (th RS disj_assoc)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   295
	handle THM _ => th;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   296
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   297
(*Must check for negative literal first!*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   298
val clause_rules = [disj_assoc, make_neg_rule, make_pos_rule];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   299
val refined_clause_rules = [disj_assoc, make_refined_neg_rule, make_pos_rule];
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   300
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   301
(*Create a goal or support clause, conclusing False*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   302
fun make_goal th =   (*Must check for negative literal first!*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   303
    make_goal (tryres(th, clause_rules)) 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   304
  handle THM _ => tryres(th, [make_neg_goal, make_pos_goal]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   305
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   306
(*Sort clauses by number of literals*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   307
fun fewerlits(th1,th2) = nliterals(prop_of th1) < nliterals(prop_of th2);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   308
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   309
(*TAUTOLOGY CHECK SHOULD NOT BE NECESSARY!*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   310
fun sort_clauses ths = sort fewerlits (filter (not o is_taut) ths);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   311
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   312
(*Convert all suitable free variables to schematic variables*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   313
fun generalize th = forall_elim_vars 0 (forall_intr_frees th);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   314
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   315
(*make clauses from a list of theorems*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   316
fun make_clauses ths = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   317
    sort_clauses (map (generalize o nodups) (foldr cnf (ths,[])));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   318
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   319
(*Create a Horn clause*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   320
fun make_horn crules th = make_horn crules (tryres(th,crules)) 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   321
		          handle THM _ => th;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   322
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   323
(*Generate Horn clauses for all contrapositives of a clause*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   324
fun add_contras crules (th,hcs) = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   325
  let fun rots (0,th) = hcs
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   326
	| rots (k,th) = zero_var_indexes (make_horn crules th) ::
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   327
			rots(k-1, assoc_right (th RS disj_comm))
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   328
  in case nliterals(prop_of th) of
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   329
	1 => th::hcs
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   330
      | n => rots(n, assoc_right th)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   331
  end;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   332
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   333
(*Convert a list of clauses to (contrapositive) Horn clauses*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   334
fun make_horns ths = foldr (add_contras clause_rules) (ths,[]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   335
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   336
(*Find an all-negative support clause*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   337
fun is_negative th = forall (not o #1) (literals (prop_of th));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   338
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   339
val neg_clauses = filter is_negative;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   340
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   341
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   342
(***** MESON PROOF PROCEDURE *****)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   343
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   344
fun rhyps (Const("==>",_) $ (Const("Trueprop",_) $ A) $ phi,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   345
	   As) = rhyps(phi, A::As)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   346
  | rhyps (_, As) = As;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   347
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   348
(** Detecting repeated assumptions in a subgoal **)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   349
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   350
(*The stringtree detects repeated assumptions.*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   351
fun ins_term (net,t) = Net.insert_term((t,t), net, op aconv);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   352
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   353
(*detects repetitions in a list of terms*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   354
fun has_reps [] = false
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   355
  | has_reps [_] = false
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   356
  | has_reps [t,u] = (t aconv u)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   357
  | has_reps ts = (foldl ins_term (Net.empty, ts);  false)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   358
    		  handle INSERT => true; 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   359
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   360
(*Loop checking: FAIL if trying to prove the same thing twice
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   361
  -- repeated literals*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   362
val check_tac = SUBGOAL (fn (prem,_) =>
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   363
  if has_reps (rhyps(prem,[]))  then  no_tac  else  all_tac); 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   364
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   365
(* net_resolve_tac actually made it slower... *)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   366
fun prolog_step_tac horns i = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   367
    (assume_tac i APPEND resolve_tac horns i) THEN
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   368
    (ALLGOALS check_tac) THEN
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   369
    (TRYALL eq_assume_tac);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   370
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   371
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   372
(*Sums the sizes of the subgoals, ignoring hypotheses (ancestors)*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   373
local fun addconcl(prem,sz) = size_of_term (Logic.strip_assums_concl prem) + sz
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   374
in
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   375
fun size_of_subgoals st = foldr addconcl (prems_of st, 0)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   376
end;
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   377
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   378
(*Could simply use nprems_of, which would count remaining subgoals -- no
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   379
  discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   380
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   381
fun best_prolog_tac sizef horns = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   382
    BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac horns 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   383
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   384
fun depth_prolog_tac horns = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   385
    DEPTH_FIRST (has_fewer_prems 1) (prolog_step_tac horns 1);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   386
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   387
(*Return all negative clauses, as possible goal clauses*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   388
fun gocls cls = map make_goal (neg_clauses cls);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   389
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   390
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   391
fun skolemize_tac prems = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   392
    cut_facts_tac (map (skolemize o make_nnf) prems)  THEN'
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   393
    REPEAT o (etac exE);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   394
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   395
fun MESON sko_tac = SELECT_GOAL
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   396
 (EVERY1 [rtac ccontr,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   397
	  METAHYPS (fn negs =>
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   398
		    EVERY1 [skolemize_tac negs,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   399
			    METAHYPS (sko_tac o make_clauses)])]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   400
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   401
fun best_meson_tac sizef = 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   402
  MESON (fn cls => 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   403
	 resolve_tac (gocls cls) 1
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   404
	 THEN_BEST_FIRST 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   405
 	 (has_fewer_prems 1, sizef,
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   406
	  prolog_step_tac (make_horns cls) 1));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   407
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   408
(*First, breaks the goal into independent units*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   409
val safe_meson_tac =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   410
     SELECT_GOAL (TRY (safe_tac HOL_cs) THEN 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   411
		  TRYALL (best_meson_tac size_of_subgoals));
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   412
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   413
val depth_meson_tac =
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   414
     MESON (fn cls => EVERY [resolve_tac (gocls cls) 1, 
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   415
			     depth_prolog_tac (make_horns cls)]);
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   416
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
   417
writeln"Reached end of file.";