82805
|
1 |
(* Title: Pure/bires.ML
|
|
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
82806
|
3 |
Author: Makarius
|
82805
|
4 |
|
|
5 |
Biresolution and resolution using nets.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature BIRES =
|
|
9 |
sig
|
82806
|
10 |
type rule = bool * thm
|
|
11 |
type 'a netpair = ('a * rule) Net.net * ('a * rule) Net.net;
|
82807
|
12 |
val insert_tagged_rule: 'a * rule -> 'a netpair -> 'a netpair
|
|
13 |
val insert_tagged_rules: ('a * rule) list -> 'a netpair -> 'a netpair
|
|
14 |
val delete_tagged_rule: rule -> 'a netpair -> 'a netpair
|
|
15 |
val delete_tagged_rules: rule list -> 'a netpair -> 'a netpair
|
82806
|
16 |
val eq_kbrl: ('a * rule) * ('a * rule) -> bool
|
82805
|
17 |
val build_net: thm list -> (int * thm) Net.net
|
|
18 |
val biresolution_from_nets_tac: Proof.context ->
|
82806
|
19 |
('a list -> rule list) -> bool -> 'a Net.net * 'a Net.net -> int -> tactic
|
|
20 |
val biresolve_from_nets_tac: Proof.context -> int netpair -> int -> tactic
|
|
21 |
val bimatch_from_nets_tac: Proof.context -> int netpair -> int -> tactic
|
82805
|
22 |
val filt_resolve_from_net_tac: Proof.context -> int -> (int * thm) Net.net -> int -> tactic
|
|
23 |
val resolve_from_net_tac: Proof.context -> (int * thm) Net.net -> int -> tactic
|
|
24 |
val match_from_net_tac: Proof.context -> (int * thm) Net.net -> int -> tactic
|
|
25 |
end
|
|
26 |
|
|
27 |
structure Bires: BIRES =
|
|
28 |
struct
|
|
29 |
|
82806
|
30 |
type rule = bool * thm; (*eres flag, see Thm.biresolution*)
|
|
31 |
|
|
32 |
type 'a netpair = ('a * rule) Net.net * ('a * rule) Net.net;
|
|
33 |
|
|
34 |
|
82805
|
35 |
(** To preserve the order of the rules, tag them with increasing integers **)
|
|
36 |
|
|
37 |
(*insert one tagged brl into the pair of nets*)
|
82807
|
38 |
fun insert_tagged_rule (kbrl as (k, (eres, th))) (inet, enet) =
|
82805
|
39 |
if eres then
|
|
40 |
(case try Thm.major_prem_of th of
|
|
41 |
SOME prem => (inet, Net.insert_term (K false) (prem, kbrl) enet)
|
82807
|
42 |
| NONE => error "insert_tagged_rule: elimination rule with no premises")
|
82805
|
43 |
else (Net.insert_term (K false) (Thm.concl_of th, kbrl) inet, enet);
|
|
44 |
|
82807
|
45 |
fun insert_tagged_rules rls = fold_rev insert_tagged_rule rls;
|
|
46 |
|
|
47 |
|
82805
|
48 |
(*delete one kbrl from the pair of nets*)
|
|
49 |
fun eq_kbrl ((_, (_, th)), (_, (_, th'))) = Thm.eq_thm_prop (th, th')
|
|
50 |
|
82807
|
51 |
fun delete_tagged_rule (brl as (eres, th)) (inet, enet) =
|
82805
|
52 |
(if eres then
|
|
53 |
(case try Thm.major_prem_of th of
|
|
54 |
SOME prem => (inet, Net.delete_term eq_kbrl (prem, ((), brl)) enet)
|
|
55 |
| NONE => (inet, enet)) (*no major premise: ignore*)
|
|
56 |
else (Net.delete_term eq_kbrl (Thm.concl_of th, ((), brl)) inet, enet))
|
|
57 |
handle Net.DELETE => (inet,enet);
|
|
58 |
|
82807
|
59 |
fun delete_tagged_rules rls = fold_rev delete_tagged_rule rls;
|
|
60 |
|
82805
|
61 |
|
|
62 |
(*biresolution using a pair of nets rather than rules.
|
|
63 |
function "order" must sort and possibly filter the list of brls.
|
|
64 |
boolean "match" indicates matching or unification.*)
|
|
65 |
fun biresolution_from_nets_tac ctxt order match (inet, enet) =
|
|
66 |
SUBGOAL
|
|
67 |
(fn (prem, i) =>
|
|
68 |
let
|
|
69 |
val hyps = Logic.strip_assums_hyp prem;
|
|
70 |
val concl = Logic.strip_assums_concl prem;
|
|
71 |
val kbrls = Net.unify_term inet concl @ maps (Net.unify_term enet) hyps;
|
|
72 |
in PRIMSEQ (Thm.biresolution (SOME ctxt) match (order kbrls) i) end);
|
|
73 |
|
|
74 |
(*versions taking pre-built nets. No filtering of brls*)
|
|
75 |
fun biresolve_from_nets_tac ctxt = biresolution_from_nets_tac ctxt order_list false;
|
|
76 |
fun bimatch_from_nets_tac ctxt = biresolution_from_nets_tac ctxt order_list true;
|
|
77 |
|
|
78 |
|
|
79 |
(*** Simpler version for resolve_tac -- only one net, and no hyps ***)
|
|
80 |
|
|
81 |
(*insert one tagged rl into the net*)
|
|
82 |
fun insert_krl (krl as (k,th)) =
|
|
83 |
Net.insert_term (K false) (Thm.concl_of th, krl);
|
|
84 |
|
|
85 |
(*build a net of rules for resolution*)
|
|
86 |
fun build_net rls =
|
|
87 |
fold_rev insert_krl (tag_list 1 rls) Net.empty;
|
|
88 |
|
|
89 |
(*resolution using a net rather than rules; pred supports filt_resolve_tac*)
|
|
90 |
fun filt_resolution_from_net_tac ctxt match pred net =
|
|
91 |
SUBGOAL (fn (prem, i) =>
|
|
92 |
let val krls = Net.unify_term net (Logic.strip_assums_concl prem) in
|
|
93 |
if pred krls then
|
|
94 |
PRIMSEQ (Thm.biresolution (SOME ctxt) match (map (pair false) (order_list krls)) i)
|
|
95 |
else no_tac
|
|
96 |
end);
|
|
97 |
|
|
98 |
(*Resolve the subgoal using the rules (making a net) unless too flexible,
|
|
99 |
which means more than maxr rules are unifiable. *)
|
|
100 |
fun filt_resolve_from_net_tac ctxt maxr net =
|
|
101 |
let fun pred krls = length krls <= maxr
|
|
102 |
in filt_resolution_from_net_tac ctxt false pred net end;
|
|
103 |
|
|
104 |
(*versions taking pre-built nets*)
|
|
105 |
fun resolve_from_net_tac ctxt = filt_resolution_from_net_tac ctxt false (K true);
|
|
106 |
fun match_from_net_tac ctxt = filt_resolution_from_net_tac ctxt true (K true);
|
|
107 |
|
|
108 |
end;
|
|
109 |
|