author | wenzelm |
Sun, 20 Jul 2025 20:31:04 +0200 | |
changeset 82888 | 051177553f16 |
parent 82873 | e567fd948ff0 |
child 82889 | a299162422f0 |
permissions | -rw-r--r-- |
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 |
82808 | 11 |
val subgoals_of: rule -> int |
12 |
val subgoals_ord: rule ord |
|
13 |
val no_subgoals: rule -> bool |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
14 |
|
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
15 |
type tag = {weight: int, index: int} |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
16 |
val tag_weight_ord: tag ord |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
17 |
val tag_index_ord: tag ord |
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
18 |
val tag_ord: tag ord |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
19 |
val weighted_tag_ord: bool -> tag ord |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
20 |
val tag_order: (tag * 'a) list -> 'a list |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
21 |
val weight_tag: int -> tag |
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
22 |
|
82827 | 23 |
eqtype kind |
24 |
val intro_bang_kind: kind |
|
25 |
val elim_bang_kind: kind |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
26 |
val dest_bang_kind: kind |
82827 | 27 |
val intro_kind: kind |
28 |
val elim_kind: kind |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
29 |
val dest_kind: kind |
82827 | 30 |
val intro_query_kind: kind |
31 |
val elim_query_kind: kind |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
32 |
val dest_query_kind: kind |
82842
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
33 |
val kind_safe: kind -> bool |
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
34 |
val kind_unsafe: kind -> bool |
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
35 |
val kind_extra: kind -> bool |
82827 | 36 |
val kind_index: kind -> int |
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
37 |
val kind_is_elim: kind -> bool |
82873 | 38 |
val kind_make_elim: kind -> thm -> thm |
82863 | 39 |
val kind_name: kind -> string |
82827 | 40 |
val kind_domain: kind list |
82828 | 41 |
val kind_values: 'a -> 'a list |
82827 | 42 |
val kind_map: kind -> ('a -> 'a) -> 'a list -> 'a list |
43 |
val kind_rule: kind -> thm -> rule |
|
82842
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
44 |
val kind_description: kind -> string |
82827 | 45 |
val kind_title: kind -> string |
46 |
||
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
47 |
type 'a decl = {kind: kind, tag: tag, info: 'a} |
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
48 |
val decl_ord: 'a decl ord |
82854
86915cddda08
clarified declaration equivalence --- follow original classical.ML, before 8aa1c98b948b;
wenzelm
parents:
82848
diff
changeset
|
49 |
val decl_eq_kind: 'a decl * 'a decl -> bool |
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
50 |
type 'a decls |
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
51 |
val has_decls: 'a decls -> thm -> bool |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
52 |
val get_decls: 'a decls -> thm -> 'a decl list |
82844
ebfb0e011c95
clarified signature: prefer canonical order (latest declarations first);
wenzelm
parents:
82843
diff
changeset
|
53 |
val dest_decls: 'a decls -> (thm * 'a decl -> bool) -> (thm * 'a decl) list |
82864 | 54 |
val pretty_decls: Proof.context -> 'a decls -> Pretty.T list |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
55 |
val merge_decls: 'a decls * 'a decls -> 'a decl list * 'a decls |
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
56 |
val extend_decls: thm * 'a decl -> 'a decls -> 'a decl option * 'a decls |
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
57 |
val remove_decls: thm -> 'a decls -> 'a decl list * 'a decls |
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
58 |
val empty_decls: 'a decls |
82827 | 59 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
60 |
type netpair = (tag * rule) Net.net * (tag * rule) Net.net |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
61 |
val empty_netpair: netpair |
82888 | 62 |
val pretty_netpair: Proof.context -> string -> netpair -> Pretty.T list |
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
63 |
val insert_tagged_rule: tag * rule -> netpair -> netpair |
82848
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
64 |
val delete_tagged_rule: int * thm -> netpair -> netpair |
82827 | 65 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
66 |
val biresolution_from_nets_tac: Proof.context -> tag ord -> (rule -> bool) option -> |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
67 |
bool -> netpair -> int -> tactic |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
68 |
val biresolve_from_nets_tac: Proof.context -> netpair -> int -> tactic |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
69 |
val bimatch_from_nets_tac: Proof.context -> netpair -> int -> tactic |
82811 | 70 |
|
71 |
type net = (int * thm) Net.net |
|
72 |
val build_net: thm list -> net |
|
73 |
val filt_resolve_from_net_tac: Proof.context -> int -> net -> int -> tactic |
|
74 |
val resolve_from_net_tac: Proof.context -> net -> int -> tactic |
|
75 |
val match_from_net_tac: Proof.context -> net -> int -> tactic |
|
82805 | 76 |
end |
77 |
||
78 |
structure Bires: BIRES = |
|
79 |
struct |
|
80 |
||
82827 | 81 |
(** Rule kinds and declarations **) |
82808 | 82 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
83 |
(* type rule *) |
82806 | 84 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
85 |
type rule = bool * thm; (*see Thm.biresolution*) |
82806 | 86 |
|
82808 | 87 |
fun subgoals_of (true, thm) = Thm.nprems_of thm - 1 |
88 |
| subgoals_of (false, thm) = Thm.nprems_of thm; |
|
89 |
||
90 |
val subgoals_ord = int_ord o apply2 subgoals_of; |
|
91 |
||
82809 | 92 |
fun no_subgoals (true, thm) = Thm.one_prem thm |
93 |
| no_subgoals (false, thm) = Thm.no_prems thm; |
|
82808 | 94 |
|
82806 | 95 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
96 |
(* tagged rules *) |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
97 |
|
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
98 |
type tag = {weight: int, index: int}; |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
99 |
|
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
100 |
val tag_weight_ord: tag ord = int_ord o apply2 #weight; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
101 |
val tag_index_ord: tag ord = int_ord o apply2 #index; |
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
102 |
|
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
103 |
val tag_ord: tag ord = tag_weight_ord ||| tag_index_ord; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
104 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
105 |
fun weighted_tag_ord weighted = if weighted then tag_ord else tag_index_ord; |
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
106 |
|
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
107 |
fun tag_order list = make_order_list tag_ord NONE list; |
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
108 |
|
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
109 |
fun weight_tag weight : tag = {weight = weight, index = 0}; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
110 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
111 |
fun next_tag next ({weight, ...}: tag) = {weight = weight, index = next}; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
112 |
|
82812
ea8d633fd4a8
just one type Bires.netpair, based on Bires.tag with explicit weight;
wenzelm
parents:
82811
diff
changeset
|
113 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
114 |
(* kind: intro/elim/dest *) |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
115 |
|
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
116 |
datatype kind = Kind of {index: int, is_elim: bool, make_elim: bool}; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
117 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
118 |
fun make_intro_kind i = Kind {index = i, is_elim = false, make_elim = false}; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
119 |
fun make_elim_kind i = Kind {index = i, is_elim = true, make_elim = false}; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
120 |
fun make_dest_kind i = Kind {index = i, is_elim = true, make_elim = true}; |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
121 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
122 |
val intro_bang_kind = make_intro_kind 0; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
123 |
val elim_bang_kind = make_elim_kind 0; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
124 |
val dest_bang_kind = make_dest_kind 0; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
125 |
|
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
126 |
val intro_kind = make_intro_kind 1; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
127 |
val elim_kind = make_elim_kind 1; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
128 |
val dest_kind = make_dest_kind 1; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
129 |
|
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
130 |
val intro_query_kind = make_intro_kind 2; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
131 |
val elim_query_kind = make_elim_kind 2; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
132 |
val dest_query_kind = make_dest_kind 2; |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
133 |
|
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
134 |
val kind_infos = |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
135 |
[(intro_bang_kind, ("safe introduction", "(intro!)")), |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
136 |
(elim_bang_kind, ("safe elimination", "(elim!)")), |
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
137 |
(dest_bang_kind, ("safe destruction", "(dest!)")), |
82864 | 138 |
(intro_kind, ("unsafe introduction", "(intro)")), |
139 |
(elim_kind, ("unsafe elimination", "(elim)")), |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
140 |
(dest_kind, ("unsafe destruction", "(dest)")), |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
141 |
(intro_query_kind, ("extra introduction", "(intro?)")), |
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
142 |
(elim_query_kind, ("extra elimination", "(elim?)")), |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
143 |
(dest_query_kind, ("extra destruction", "(dest?)"))]; |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
144 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
145 |
fun kind_safe (Kind {index, ...}) = index = 0; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
146 |
fun kind_unsafe (Kind {index, ...}) = index = 1; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
147 |
fun kind_extra (Kind {index, ...}) = index = 2; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
148 |
fun kind_index (Kind {index, ...}) = index; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
149 |
fun kind_is_elim (Kind {is_elim, ...}) = is_elim; |
82873 | 150 |
fun kind_make_elim (Kind {make_elim, ...}) = make_elim ? Tactic.make_elim; |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
151 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
152 |
fun kind_name (Kind {is_elim, make_elim, ...}) = |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
153 |
if is_elim andalso make_elim then "destruction rule" |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
154 |
else if is_elim then "elimination rule" |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
155 |
else "introduction rule"; |
82863 | 156 |
|
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
157 |
val kind_domain = map #1 kind_infos; |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
158 |
|
82828 | 159 |
fun kind_values x = |
160 |
replicate (length (distinct (op =) (map kind_index kind_domain))) x; |
|
161 |
||
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
162 |
fun kind_map kind f = nth_map (kind_index kind) f; |
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
82864
diff
changeset
|
163 |
fun kind_rule kind thm : rule = (kind_is_elim kind, thm); |
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
164 |
|
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
165 |
val the_kind_info = the o AList.lookup (op =) kind_infos; |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
166 |
|
82842
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
167 |
fun kind_description kind = |
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
168 |
let val (a, b) = the_kind_info kind |
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
169 |
in a ^ " " ^ b end; |
8aa1c98b948b
maintain collective rule declarations via type Bires.decls, with netpair operations derived from it;
wenzelm
parents:
82840
diff
changeset
|
170 |
|
82817
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
171 |
fun kind_title kind = |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
172 |
let val (a, b) = the_kind_info kind |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
173 |
in a ^ " rules " ^ b end; |
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
174 |
|
be1fb22d9e2a
clarified signature: more explicit type Bires.kind;
wenzelm
parents:
82812
diff
changeset
|
175 |
|
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
176 |
(* rule declarations in canonical order *) |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
177 |
|
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
178 |
type 'a decl = {kind: kind, tag: tag, info: 'a}; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
179 |
|
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
180 |
fun decl_ord (args: 'a decl * 'a decl) = tag_index_ord (apply2 #tag args); |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
181 |
|
82854
86915cddda08
clarified declaration equivalence --- follow original classical.ML, before 8aa1c98b948b;
wenzelm
parents:
82848
diff
changeset
|
182 |
fun decl_eq_kind ({kind, ...}: 'a decl, {kind = kind', ...}: 'a decl) = kind = kind'; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
183 |
|
82829
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
184 |
fun next_decl next ({kind, tag, info}: 'a decl) : 'a decl = |
57c331dc167d
clarified signature: anticipate use in src/Provers/classical.ML;
wenzelm
parents:
82828
diff
changeset
|
185 |
{kind = kind, tag = next_tag next tag, info = info}; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
186 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
187 |
|
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
188 |
abstype 'a decls = Decls of {next: int, rules: 'a decl list Proptab.table} |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
189 |
with |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
190 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
191 |
local |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
192 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
193 |
fun dup_decls (Decls {rules, ...}) (thm, decl) = |
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
194 |
member decl_eq_kind (Proptab.lookup_list rules thm) decl; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
195 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
196 |
fun add_decls (thm, decl) (Decls {next, rules}) = |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
197 |
let |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
198 |
val decl' = next_decl next decl; |
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
199 |
val decls' = Decls {next = next - 1, rules = Proptab.cons_list (thm, decl') rules}; |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
200 |
in (decl', decls') end; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
201 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
202 |
in |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
203 |
|
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
204 |
fun has_decls (Decls {rules, ...}) = Proptab.defined rules; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
205 |
|
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
206 |
fun get_decls (Decls {rules, ...}) = Proptab.lookup_list rules; |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
207 |
|
82844
ebfb0e011c95
clarified signature: prefer canonical order (latest declarations first);
wenzelm
parents:
82843
diff
changeset
|
208 |
fun dest_decls (Decls {rules, ...}) pred = |
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
209 |
build (rules |> Proptab.fold (fn (th, ds) => ds |> fold (fn d => pred (th, d) ? cons (th, d)))) |
82844
ebfb0e011c95
clarified signature: prefer canonical order (latest declarations first);
wenzelm
parents:
82843
diff
changeset
|
210 |
|> sort (decl_ord o apply2 #2); |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
211 |
|
82864 | 212 |
fun pretty_decls ctxt decls = |
213 |
kind_domain |> map_filter (fn kind => |
|
214 |
(case dest_decls decls (fn (_, {kind = kind', ...}) => kind = kind') of |
|
215 |
[] => NONE |
|
216 |
| ds => |
|
217 |
SOME (Pretty.big_list (kind_title kind ^ ":") |
|
218 |
(map (Thm.pretty_thm_item ctxt o #1) ds)))); |
|
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
219 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
220 |
fun merge_decls (decls1, decls2) = |
82844
ebfb0e011c95
clarified signature: prefer canonical order (latest declarations first);
wenzelm
parents:
82843
diff
changeset
|
221 |
decls1 |> fold_map add_decls (rev (dest_decls decls2 (not o dup_decls decls1))); |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
222 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
223 |
fun extend_decls (thm, decl) decls = |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
224 |
if dup_decls decls (thm, decl) then (NONE, decls) |
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
225 |
else add_decls (thm, decl) decls |>> SOME; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
226 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
227 |
fun remove_decls thm (decls as Decls {next, rules}) = |
82839
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
228 |
(case get_decls decls thm of |
60ec2b2dc55a
clarified signature: rule declarations work via "info" as internal rule (which coincides with external rule);
wenzelm
parents:
82836
diff
changeset
|
229 |
[] => ([], decls) |
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
230 |
| old_decls => (old_decls, Decls {next = next, rules = Proptab.delete thm rules})); |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
231 |
|
82855
df2d774bcf21
proper thm ord that conforms to Thm.eq_thm_prop (amending f5fd9b41188a): relevant for declarations in a locale contex with assumptions, e.g. "locale test = assumes True begin declare refl [rule del] end";
wenzelm
parents:
82854
diff
changeset
|
232 |
val empty_decls = Decls {next = ~1, rules = Proptab.empty}; |
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
233 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
234 |
end; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
235 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
236 |
end; |
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
237 |
|
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
238 |
|
82827 | 239 |
(* discrimination nets for intr/elim rules *) |
240 |
||
241 |
type netpair = (tag * rule) Net.net * (tag * rule) Net.net; |
|
242 |
||
243 |
val empty_netpair: netpair = (Net.empty, Net.empty); |
|
244 |
||
82888 | 245 |
fun pretty_netpair ctxt title (inet, enet) = |
246 |
let |
|
247 |
fun pretty_entry ({weight, ...}: tag, (_, thm): rule) = |
|
248 |
Pretty.item [Pretty.str (string_of_int weight), Pretty.brk 1, Thm.pretty_thm ctxt thm]; |
|
249 |
||
250 |
fun pretty_net elim net = |
|
251 |
(case Net.content net |> sort_distinct (tag_ord o apply2 #1) |> map pretty_entry of |
|
252 |
[] => NONE |
|
253 |
| prts => SOME (Pretty.big_list (title ^ " " ^ (if elim then "elim" else "intro")) prts)); |
|
254 |
in map_filter I [pretty_net false inet, pretty_net true enet] end; |
|
255 |
||
82827 | 256 |
|
257 |
(** Natural Deduction using (bires_flg, rule) pairs **) |
|
258 |
||
259 |
(** To preserve the order of the rules, tag them with decreasing integers **) |
|
260 |
||
261 |
fun insert_tagged_rule (tagged_rule as (_, (eres, th))) ((inet, enet): netpair) = |
|
262 |
if eres then |
|
263 |
(case try Thm.major_prem_of th of |
|
264 |
SOME prem => (inet, Net.insert_term (K false) (prem, tagged_rule) enet) |
|
265 |
| NONE => error "insert_tagged_rule: elimination rule with no premises") |
|
266 |
else (Net.insert_term (K false) (Thm.concl_of th, tagged_rule) inet, enet); |
|
267 |
||
82848
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
268 |
fun delete_tagged_rule (index, th) ((inet, enet): netpair) = |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
269 |
let |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
270 |
fun eq ((), ({index = index', ...}, _)) = index = index'; |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
271 |
val inet' = Net.delete_term_safe eq (Thm.concl_of th, ()) inet; |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
272 |
val enet' = |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
273 |
(case try Thm.major_prem_of th of |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
274 |
SOME prem => Net.delete_term_safe eq (prem, ()) enet |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
275 |
| NONE => enet); |
0a8977dcb21a
more accurate delete operation via authentic index --- minor performance tuning;
wenzelm
parents:
82844
diff
changeset
|
276 |
in (inet', enet') end; |
82827 | 277 |
|
278 |
||
279 |
(*biresolution using a pair of nets rather than rules: |
|
280 |
boolean "match" indicates matching or unification.*) |
|
281 |
fun biresolution_from_nets_tac ctxt ord pred match ((inet, enet): netpair) = |
|
282 |
SUBGOAL |
|
283 |
(fn (prem, i) => |
|
284 |
let |
|
285 |
val hyps = Logic.strip_assums_hyp prem; |
|
286 |
val concl = Logic.strip_assums_concl prem; |
|
287 |
val tagged_rules = Net.unify_term inet concl @ maps (Net.unify_term enet) hyps; |
|
288 |
val order = make_order_list ord pred; |
|
289 |
in PRIMSEQ (Thm.biresolution (SOME ctxt) match (order tagged_rules) i) end); |
|
290 |
||
291 |
(*versions taking pre-built nets. No filtering of brls*) |
|
292 |
fun biresolve_from_nets_tac ctxt = biresolution_from_nets_tac ctxt tag_ord NONE false; |
|
293 |
fun bimatch_from_nets_tac ctxt = biresolution_from_nets_tac ctxt tag_ord NONE true; |
|
294 |
||
82826
f5fd9b41188a
efficient rule declarations in canonical order, for update of netpairs and print operation;
wenzelm
parents:
82819
diff
changeset
|
295 |
|
82819 | 296 |
(** Simpler version for resolve_tac -- only one net, and no hyps **) |
82805 | 297 |
|
82811 | 298 |
type net = (int * thm) Net.net; |
82805 | 299 |
|
300 |
(*build a net of rules for resolution*) |
|
82811 | 301 |
fun build_net rls : net = |
302 |
fold_rev (fn (k, th) => Net.insert_term (K false) (Thm.concl_of th, (k, th))) |
|
303 |
(tag_list 1 rls) Net.empty; |
|
82805 | 304 |
|
305 |
(*resolution using a net rather than rules; pred supports filt_resolve_tac*) |
|
306 |
fun filt_resolution_from_net_tac ctxt match pred net = |
|
307 |
SUBGOAL (fn (prem, i) => |
|
308 |
let val krls = Net.unify_term net (Logic.strip_assums_concl prem) in |
|
309 |
if pred krls then |
|
310 |
PRIMSEQ (Thm.biresolution (SOME ctxt) match (map (pair false) (order_list krls)) i) |
|
311 |
else no_tac |
|
312 |
end); |
|
313 |
||
314 |
(*Resolve the subgoal using the rules (making a net) unless too flexible, |
|
315 |
which means more than maxr rules are unifiable. *) |
|
316 |
fun filt_resolve_from_net_tac ctxt maxr net = |
|
317 |
let fun pred krls = length krls <= maxr |
|
318 |
in filt_resolution_from_net_tac ctxt false pred net end; |
|
319 |
||
320 |
(*versions taking pre-built nets*) |
|
321 |
fun resolve_from_net_tac ctxt = filt_resolution_from_net_tac ctxt false (K true); |
|
322 |
fun match_from_net_tac ctxt = filt_resolution_from_net_tac ctxt true (K true); |
|
323 |
||
324 |
end; |