author | paulson |
Mon, 28 Jun 2004 11:15:13 +0200 | |
changeset 15008 | 5abd18710a1f |
parent 14890 | 51f28df21c8b |
child 15032 | 02aed07e01bf |
permissions | -rw-r--r-- |
9869 | 1 |
(* Title: HOL/Tools/meson.ML |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
2 |
ID: $Id$ |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
4 |
Copyright 1992 University of Cambridge |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
5 |
|
9869 | 6 |
The MESON resolution proof procedure for HOL. |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
7 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
8 |
When making clauses, avoids using the rewriter -- instead uses RS recursively |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
9 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
10 |
NEED TO SORT LITERALS BY # OF VARS, USING ==>I/E. ELIMINATES NEED FOR |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
11 |
FUNCTION nodups -- if done to goal clauses too! |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
12 |
*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
13 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
14 |
local |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
15 |
|
12299 | 16 |
val not_conjD = thm "meson_not_conjD"; |
17 |
val not_disjD = thm "meson_not_disjD"; |
|
18 |
val not_notD = thm "meson_not_notD"; |
|
19 |
val not_allD = thm "meson_not_allD"; |
|
20 |
val not_exD = thm "meson_not_exD"; |
|
21 |
val imp_to_disjD = thm "meson_imp_to_disjD"; |
|
22 |
val not_impD = thm "meson_not_impD"; |
|
23 |
val iff_to_disjD = thm "meson_iff_to_disjD"; |
|
24 |
val not_iffD = thm "meson_not_iffD"; |
|
25 |
val conj_exD1 = thm "meson_conj_exD1"; |
|
26 |
val conj_exD2 = thm "meson_conj_exD2"; |
|
27 |
val disj_exD = thm "meson_disj_exD"; |
|
28 |
val disj_exD1 = thm "meson_disj_exD1"; |
|
29 |
val disj_exD2 = thm "meson_disj_exD2"; |
|
30 |
val disj_assoc = thm "meson_disj_assoc"; |
|
31 |
val disj_comm = thm "meson_disj_comm"; |
|
32 |
val disj_FalseD1 = thm "meson_disj_FalseD1"; |
|
33 |
val disj_FalseD2 = thm "meson_disj_FalseD2"; |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
34 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
35 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
36 |
(**** Operators for forward proof ****) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
37 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
38 |
(*raises exception if no rules apply -- unlike RL*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
39 |
fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls)) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
40 |
| tryres (th, []) = raise THM("tryres", 0, [th]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
41 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
42 |
val prop_of = #prop o rep_thm; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
43 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
44 |
(*Permits forward proof from rules that discharge assumptions*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
45 |
fun forward_res nf st = |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
46 |
case Seq.pull (ALLGOALS (METAHYPS (fn [prem] => rtac (nf prem) 1)) st) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
47 |
of Some(th,_) => th |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
48 |
| None => raise THM("forward_res", 0, [st]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
49 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
50 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
51 |
(*Are any of the constants in "bs" present in the term?*) |
9869 | 52 |
fun has_consts bs = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
53 |
let fun has (Const(a,_)) = a mem bs |
14763 | 54 |
| has (Const ("Hilbert_Choice.Eps",_) $ _) = false |
55 |
(*ignore constants within @-terms*) |
|
9869 | 56 |
| has (f$u) = has f orelse has u |
57 |
| has (Abs(_,_,t)) = has t |
|
58 |
| has _ = false |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
59 |
in has end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
60 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
61 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
62 |
(**** Clause handling ****) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
63 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
64 |
fun literals (Const("Trueprop",_) $ P) = literals P |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
65 |
| literals (Const("op |",_) $ P $ Q) = literals P @ literals Q |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
66 |
| literals (Const("Not",_) $ P) = [(false,P)] |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
67 |
| literals P = [(true,P)]; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
68 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
69 |
(*number of literals in a term*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
70 |
val nliterals = length o literals; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
71 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
72 |
(*to detect, and remove, tautologous clauses*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
73 |
fun taut_lits [] = false |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
74 |
| taut_lits ((flg,t)::ts) = (not flg,t) mem ts orelse taut_lits ts; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
75 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
76 |
(*Include False as a literal: an occurrence of ~False is a tautology*) |
9869 | 77 |
fun is_taut th = taut_lits ((true, HOLogic.false_const) :: |
78 |
literals (prop_of th)); |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
79 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
80 |
(*Generation of unique names -- maxidx cannot be relied upon to increase! |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
81 |
Cannot rely on "variant", since variables might coincide when literals |
9869 | 82 |
are joined to make a clause... |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
83 |
19 chooses "U" as the first variable name*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
84 |
val name_ref = ref 19; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
85 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
86 |
(*Replaces universally quantified variables by FREE variables -- because |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
87 |
assumptions may not contain scheme variables. Later, call "generalize". *) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
88 |
fun freeze_spec th = |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
89 |
let val sth = th RS spec |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
90 |
val newname = (name_ref := !name_ref + 1; |
9869 | 91 |
radixstring(26, "A", !name_ref)) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
92 |
in read_instantiate [("x", newname)] sth end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
93 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
94 |
fun resop nf [prem] = resolve_tac (nf prem) 1; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
95 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
96 |
(*Conjunctive normal form, detecting tautologies early. |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
97 |
Strips universal quantifiers and breaks up conjunctions. *) |
9869 | 98 |
fun cnf_aux seen (th,ths) = |
14763 | 99 |
if taut_lits (literals(prop_of th) @ seen) |
100 |
then ths (*tautology ignored*) |
|
101 |
else if not (has_consts ["All","op &"] (prop_of th)) |
|
102 |
then th::ths (*no work to do, terminate*) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
103 |
else (*conjunction?*) |
9869 | 104 |
cnf_aux seen (th RS conjunct1, |
105 |
cnf_aux seen (th RS conjunct2, ths)) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
106 |
handle THM _ => (*universal quant?*) |
9869 | 107 |
cnf_aux seen (freeze_spec th, ths) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
108 |
handle THM _ => (*disjunction?*) |
9869 | 109 |
let val tac = |
110 |
(METAHYPS (resop (cnf_nil seen)) 1) THEN |
|
111 |
(fn st' => st' |> |
|
112 |
METAHYPS (resop (cnf_nil (literals (concl_of st') @ seen))) 1) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
113 |
in Seq.list_of (tac (th RS disj_forward)) @ ths end |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
114 |
and cnf_nil seen th = cnf_aux seen (th,[]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
115 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
116 |
(*Top-level call to cnf -- it's safe to reset name_ref*) |
9869 | 117 |
fun cnf (th,ths) = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
118 |
(name_ref := 19; cnf (th RS conjunct1, cnf (th RS conjunct2, ths)) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
119 |
handle THM _ => (*not a conjunction*) cnf_aux [] (th, ths)); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
120 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
121 |
(**** Removal of duplicate literals ****) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
122 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
123 |
(*Forward proof, passing extra assumptions as theorems to the tactic*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
124 |
fun forward_res2 nf hyps st = |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
125 |
case Seq.pull |
9869 | 126 |
(REPEAT |
127 |
(METAHYPS (fn major::minors => rtac (nf (minors@hyps) major) 1) 1) |
|
128 |
st) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
129 |
of Some(th,_) => th |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
130 |
| None => raise THM("forward_res2", 0, [st]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
131 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
132 |
(*Remove duplicates in P|Q by assuming ~P in Q |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
133 |
rls (initially []) accumulates assumptions of the form P==>False*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
134 |
fun nodups_aux rls th = nodups_aux rls (th RS disj_assoc) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
135 |
handle THM _ => tryres(th,rls) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
136 |
handle THM _ => tryres(forward_res2 nodups_aux rls (th RS disj_forward2), |
9869 | 137 |
[disj_FalseD1, disj_FalseD2, asm_rl]) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
138 |
handle THM _ => th; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
139 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
140 |
(*Remove duplicate literals, if there are any*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
141 |
fun nodups th = |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
142 |
if null(findrep(literals(prop_of th))) then th |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
143 |
else nodups_aux [] th; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
144 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
145 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
146 |
(**** Generation of contrapositives ****) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
147 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
148 |
(*Associate disjuctions to right -- make leftmost disjunct a LITERAL*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
149 |
fun assoc_right th = assoc_right (th RS disj_assoc) |
9869 | 150 |
handle THM _ => th; |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
151 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
152 |
(*Must check for negative literal first!*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
153 |
val clause_rules = [disj_assoc, make_neg_rule, make_pos_rule]; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
154 |
|
14733
3eda95792083
conversion to clauses for ordinary resolution rather than ME
paulson
parents:
13105
diff
changeset
|
155 |
(*For ordinary resolution. *) |
3eda95792083
conversion to clauses for ordinary resolution rather than ME
paulson
parents:
13105
diff
changeset
|
156 |
val resolution_clause_rules = [disj_assoc, make_neg_rule', make_pos_rule']; |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
157 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
158 |
(*Create a goal or support clause, conclusing False*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
159 |
fun make_goal th = (*Must check for negative literal first!*) |
9869 | 160 |
make_goal (tryres(th, clause_rules)) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
161 |
handle THM _ => tryres(th, [make_neg_goal, make_pos_goal]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
162 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
163 |
(*Sort clauses by number of literals*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
164 |
fun fewerlits(th1,th2) = nliterals(prop_of th1) < nliterals(prop_of th2); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
165 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
166 |
(*TAUTOLOGY CHECK SHOULD NOT BE NECESSARY!*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
167 |
fun sort_clauses ths = sort (make_ord fewerlits) (filter (not o is_taut) ths); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
168 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
169 |
(*Convert all suitable free variables to schematic variables*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
170 |
fun generalize th = forall_elim_vars 0 (forall_intr_frees th); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
171 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
172 |
(*Create a meta-level Horn clause*) |
9869 | 173 |
fun make_horn crules th = make_horn crules (tryres(th,crules)) |
174 |
handle THM _ => th; |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
175 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
176 |
(*Generate Horn clauses for all contrapositives of a clause*) |
9869 | 177 |
fun add_contras crules (th,hcs) = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
178 |
let fun rots (0,th) = hcs |
9869 | 179 |
| rots (k,th) = zero_var_indexes (make_horn crules th) :: |
180 |
rots(k-1, assoc_right (th RS disj_comm)) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
181 |
in case nliterals(prop_of th) of |
9869 | 182 |
1 => th::hcs |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
183 |
| n => rots(n, assoc_right th) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
184 |
end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
185 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
186 |
(*Use "theorem naming" to label the clauses*) |
9869 | 187 |
fun name_thms label = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
188 |
let fun name1 (th, (k,ths)) = |
9869 | 189 |
(k-1, Thm.name_thm (label ^ string_of_int k, th) :: ths) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
190 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
191 |
in fn ths => #2 (foldr name1 (ths, (length ths, []))) end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
192 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
193 |
(*Find an all-negative support clause*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
194 |
fun is_negative th = forall (not o #1) (literals (prop_of th)); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
195 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
196 |
val neg_clauses = filter is_negative; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
197 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
198 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
199 |
(***** MESON PROOF PROCEDURE *****) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
200 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
201 |
fun rhyps (Const("==>",_) $ (Const("Trueprop",_) $ A) $ phi, |
9869 | 202 |
As) = rhyps(phi, A::As) |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
203 |
| rhyps (_, As) = As; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
204 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
205 |
(** Detecting repeated assumptions in a subgoal **) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
206 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
207 |
(*The stringtree detects repeated assumptions.*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
208 |
fun ins_term (net,t) = Net.insert_term((t,t), net, op aconv); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
209 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
210 |
(*detects repetitions in a list of terms*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
211 |
fun has_reps [] = false |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
212 |
| has_reps [_] = false |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
213 |
| has_reps [t,u] = (t aconv u) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
214 |
| has_reps ts = (foldl ins_term (Net.empty, ts); false) |
9869 | 215 |
handle INSERT => true; |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
216 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
217 |
(*Like TRYALL eq_assume_tac, but avoids expensive THEN calls*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
218 |
fun TRYALL_eq_assume_tac 0 st = Seq.single st |
9869 | 219 |
| TRYALL_eq_assume_tac i st = |
220 |
TRYALL_eq_assume_tac (i-1) (eq_assumption i st) |
|
221 |
handle THM _ => TRYALL_eq_assume_tac (i-1) st; |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
222 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
223 |
(*Loop checking: FAIL if trying to prove the same thing twice |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
224 |
-- if *ANY* subgoal has repeated literals*) |
9869 | 225 |
fun check_tac st = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
226 |
if exists (fn prem => has_reps (rhyps(prem,[]))) (prems_of st) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
227 |
then Seq.empty else Seq.single st; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
228 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
229 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
230 |
(* net_resolve_tac actually made it slower... *) |
9869 | 231 |
fun prolog_step_tac horns i = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
232 |
(assume_tac i APPEND resolve_tac horns i) THEN check_tac THEN |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
233 |
TRYALL eq_assume_tac; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
234 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
235 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
236 |
in |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
237 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
238 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
239 |
(*Sums the sizes of the subgoals, ignoring hypotheses (ancestors)*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
240 |
local fun addconcl(prem,sz) = size_of_term(Logic.strip_assums_concl prem) + sz |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
241 |
in |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
242 |
fun size_of_subgoals st = foldr addconcl (prems_of st, 0) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
243 |
end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
244 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
245 |
(*Negation Normal Form*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
246 |
val nnf_rls = [imp_to_disjD, iff_to_disjD, not_conjD, not_disjD, |
9869 | 247 |
not_impD, not_iffD, not_allD, not_exD, not_notD]; |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
248 |
fun make_nnf th = make_nnf (tryres(th, nnf_rls)) |
9869 | 249 |
handle THM _ => |
250 |
forward_res make_nnf |
|
251 |
(tryres(th, [conj_forward,disj_forward,all_forward,ex_forward])) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
252 |
handle THM _ => th; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
253 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
254 |
(*Pull existential quantifiers (Skolemization)*) |
9869 | 255 |
fun skolemize th = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
256 |
if not (has_consts ["Ex"] (prop_of th)) then th |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
257 |
else skolemize (tryres(th, [choice, conj_exD1, conj_exD2, |
9869 | 258 |
disj_exD, disj_exD1, disj_exD2])) |
259 |
handle THM _ => |
|
260 |
skolemize (forward_res skolemize |
|
261 |
(tryres (th, [conj_forward, disj_forward, all_forward]))) |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
262 |
handle THM _ => forward_res skolemize (th RS ex_forward); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
263 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
264 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
265 |
(*Make clauses from a list of theorems, previously Skolemized and put into nnf. |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
266 |
The resulting clauses are HOL disjunctions.*) |
9869 | 267 |
fun make_clauses ths = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
268 |
sort_clauses (map (generalize o nodups) (foldr cnf (ths,[]))); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
269 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
270 |
(*Convert a list of clauses to (contrapositive) Horn clauses*) |
9869 | 271 |
fun make_horns ths = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
272 |
name_thms "Horn#" |
13105
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents:
12299
diff
changeset
|
273 |
(gen_distinct Drule.eq_thm_prop (foldr (add_contras clause_rules) (ths,[]))); |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
274 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
275 |
(*Could simply use nprems_of, which would count remaining subgoals -- no |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
276 |
discrimination as to their size! With BEST_FIRST, fails for problem 41.*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
277 |
|
9869 | 278 |
fun best_prolog_tac sizef horns = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
279 |
BEST_FIRST (has_fewer_prems 1, sizef) (prolog_step_tac horns 1); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
280 |
|
9869 | 281 |
fun depth_prolog_tac horns = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
282 |
DEPTH_FIRST (has_fewer_prems 1) (prolog_step_tac horns 1); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
283 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
284 |
(*Return all negative clauses, as possible goal clauses*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
285 |
fun gocls cls = name_thms "Goal#" (map make_goal (neg_clauses cls)); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
286 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
287 |
|
15008 | 288 |
fun skolemize_prems_tac prems = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
289 |
cut_facts_tac (map (skolemize o make_nnf) prems) THEN' |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
290 |
REPEAT o (etac exE); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
291 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
292 |
(*Shell of all meson-tactics. Supplies cltac with clauses: HOL disjunctions*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
293 |
fun MESON cltac = SELECT_GOAL |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
294 |
(EVERY1 [rtac ccontr, |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
295 |
METAHYPS (fn negs => |
15008 | 296 |
EVERY1 [skolemize_prems_tac negs, |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
297 |
METAHYPS (cltac o make_clauses)])]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
298 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
299 |
(** Best-first search versions **) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
300 |
|
9869 | 301 |
fun best_meson_tac sizef = |
302 |
MESON (fn cls => |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
303 |
THEN_BEST_FIRST (resolve_tac (gocls cls) 1) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
304 |
(has_fewer_prems 1, sizef) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
305 |
(prolog_step_tac (make_horns cls) 1)); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
306 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
307 |
(*First, breaks the goal into independent units*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
308 |
val safe_best_meson_tac = |
9869 | 309 |
SELECT_GOAL (TRY Safe_tac THEN |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
310 |
TRYALL (best_meson_tac size_of_subgoals)); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
311 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
312 |
(** Depth-first search version **) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
313 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
314 |
val depth_meson_tac = |
9869 | 315 |
MESON (fn cls => EVERY [resolve_tac (gocls cls) 1, |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
316 |
depth_prolog_tac (make_horns cls)]); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
317 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
318 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
319 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
320 |
(** Iterative deepening version **) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
321 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
322 |
(*This version does only one inference per call; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
323 |
having only one eq_assume_tac speeds it up!*) |
9869 | 324 |
fun prolog_step_tac' horns = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
325 |
let val (horn0s, hornps) = (*0 subgoals vs 1 or more*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
326 |
take_prefix Thm.no_prems horns |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
327 |
val nrtac = net_resolve_tac horns |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
328 |
in fn i => eq_assume_tac i ORELSE |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
329 |
match_tac horn0s i ORELSE (*no backtracking if unit MATCHES*) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
330 |
((assume_tac i APPEND nrtac i) THEN check_tac) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
331 |
end; |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
332 |
|
9869 | 333 |
fun iter_deepen_prolog_tac horns = |
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
334 |
ITER_DEEPEN (has_fewer_prems 1) (prolog_step_tac' horns); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
335 |
|
9869 | 336 |
val iter_deepen_meson_tac = |
337 |
MESON (fn cls => |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
338 |
(THEN_ITER_DEEPEN (resolve_tac (gocls cls) 1) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
339 |
(has_fewer_prems 1) |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
340 |
(prolog_step_tac' (make_horns cls)))); |
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
341 |
|
9869 | 342 |
fun meson_claset_tac cs = |
343 |
SELECT_GOAL (TRY (safe_tac cs) THEN TRYALL iter_deepen_meson_tac); |
|
344 |
||
345 |
val meson_tac = CLASET' meson_claset_tac; |
|
346 |
||
347 |
||
14813 | 348 |
(**** Code to support ordinary resolution, rather than Model Elimination ****) |
14744 | 349 |
|
15008 | 350 |
(*Convert a list of clauses (disjunctions) to meta-level clauses (==>), |
351 |
with no contrapositives, for ordinary resolution.*) |
|
14744 | 352 |
|
353 |
(*Rules to convert the head literal into a negated assumption. If the head |
|
354 |
literal is already negated, then using notEfalse instead of notEfalse' |
|
355 |
prevents a double negation.*) |
|
356 |
val notEfalse = read_instantiate [("R","False")] notE; |
|
357 |
val notEfalse' = rotate_prems 1 notEfalse; |
|
358 |
||
359 |
fun negate_nead th = |
|
360 |
th RS notEfalse handle THM _ => th RS notEfalse'; |
|
361 |
||
362 |
(*Converting one clause*) |
|
363 |
fun make_meta_clause th = negate_nead (make_horn resolution_clause_rules th); |
|
364 |
||
365 |
fun make_meta_clauses ths = |
|
366 |
name_thms "MClause#" |
|
367 |
(gen_distinct Drule.eq_thm_prop (map make_meta_clause ths)); |
|
368 |
||
369 |
(*Permute a rule's premises to move the i-th premise to the last position.*) |
|
370 |
fun make_last i th = |
|
371 |
let val n = nprems_of th |
|
372 |
in if 1 <= i andalso i <= n |
|
373 |
then Thm.permute_prems (i-1) 1 th |
|
374 |
else raise THM("make_last", i, [th]) |
|
375 |
end; |
|
376 |
||
377 |
(*Maps a rule that ends "... ==> P ==> False" to "... ==> ~P" while suppressing |
|
378 |
double-negations.*) |
|
379 |
val negate_head = rewrite_rule [atomize_not, not_not RS eq_reflection]; |
|
380 |
||
381 |
(*Maps the clause [P1,...Pn]==>False to [P1,...,P(i-1),P(i+1),...Pn] ==> ~P*) |
|
382 |
fun select_literal i cl = negate_head (make_last i cl); |
|
383 |
||
14813 | 384 |
(*Top-level Skolemization. Allows part of the conversion to clauses to be |
385 |
expressed as a tactic (or Isar method). Each assumption of the selected |
|
386 |
goal is converted to NNF and then its existential quantifiers are pulled |
|
387 |
to the front. Finally, all existential quantifiers are eliminated, |
|
388 |
leaving !!-quantified variables. Perhaps Safe_tac should follow, but it |
|
389 |
might generate many subgoals.*) |
|
390 |
val skolemize_tac = |
|
391 |
SUBGOAL |
|
392 |
(fn (prop,_) => |
|
393 |
let val ts = Logic.strip_assums_hyp prop |
|
394 |
in EVERY1 |
|
395 |
[METAHYPS |
|
396 |
(fn hyps => (cut_facts_tac (map (skolemize o make_nnf) hyps) 1 |
|
397 |
THEN REPEAT (etac exE 1))), |
|
398 |
REPEAT_DETERM_N (length ts) o (etac thin_rl)] |
|
399 |
end); |
|
400 |
||
15008 | 401 |
(*Top-level conversion to clauses (disjunctions). Each clause has |
402 |
leading !!-bound universal variables, to express generality.*) |
|
403 |
val make_clauses_tac = |
|
404 |
SUBGOAL |
|
405 |
(fn (prop,_) => |
|
406 |
let val ts = Logic.strip_assums_hyp prop |
|
407 |
in EVERY1 |
|
408 |
[METAHYPS |
|
409 |
(fn hyps => |
|
410 |
(cut_rules_tac (map forall_intr_vars (make_clauses hyps)) 1)), |
|
411 |
REPEAT_DETERM_N (length ts) o (etac thin_rl)] |
|
412 |
end); |
|
413 |
||
14744 | 414 |
|
415 |
||
416 |
(** proof method setup **) |
|
9869 | 417 |
|
418 |
local |
|
419 |
||
420 |
fun meson_meth ctxt = |
|
10821 | 421 |
Method.SIMPLE_METHOD' HEADGOAL |
422 |
(CHANGED_PROP o meson_claset_tac (Classical.get_local_claset ctxt)); |
|
9869 | 423 |
|
14890 | 424 |
val skolemize_meth = |
425 |
Method.SIMPLE_METHOD' HEADGOAL |
|
426 |
(CHANGED_PROP o skolemize_tac); |
|
427 |
||
15008 | 428 |
val make_clauses_meth = |
429 |
Method.SIMPLE_METHOD' HEADGOAL |
|
430 |
(CHANGED_PROP o make_clauses_tac); |
|
431 |
||
9869 | 432 |
in |
433 |
||
434 |
val meson_setup = |
|
435 |
[Method.add_methods |
|
14813 | 436 |
[("meson", Method.ctxt_args meson_meth, |
437 |
"The MESON resolution proof procedure"), |
|
14890 | 438 |
("skolemize", Method.no_args skolemize_meth, |
15008 | 439 |
"Skolemization into existential quantifiers"), |
440 |
("make_clauses", Method.no_args make_clauses_meth, |
|
441 |
"Conversion to !!-quantified disjunctions")]]; |
|
9840
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
442 |
|
9dfcb0224f8c
meson.ML moved from HOL/ex to HOL/Tools: meson_tac installed by default
paulson
parents:
diff
changeset
|
443 |
end; |
9869 | 444 |
|
445 |
end; |