author | ballarin |
Fri, 02 Apr 2004 14:08:30 +0200 | |
changeset 14508 | 859b11514537 |
parent 14472 | cba7c0a3ffb3 |
child 14981 | e73f8140af78 |
permissions | -rw-r--r-- |
8298 | 1 |
(* Title: Pure/Isar/net_rules.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
8298 | 5 |
|
6 |
Efficient storage of rules: preserves order, prefers later entries. |
|
7 |
*) |
|
8 |
||
9 |
signature NET_RULES = |
|
10 |
sig |
|
11 |
type 'a T |
|
12 |
val rules: 'a T -> 'a list |
|
11776 | 13 |
val retrieve: 'a T -> term -> 'a list |
12385 | 14 |
val init: ('a * 'a -> bool) -> ('a -> term) -> 'a T |
8298 | 15 |
val merge: 'a T * 'a T -> 'a T |
16 |
val delete: 'a -> 'a T -> 'a T |
|
17 |
val insert: 'a -> 'a T -> 'a T |
|
11776 | 18 |
val intro: thm T |
19 |
val elim: thm T |
|
8298 | 20 |
end; |
21 |
||
22 |
structure NetRules: NET_RULES = |
|
23 |
struct |
|
24 |
||
25 |
(* datatype rules *) |
|
26 |
||
27 |
datatype 'a T = |
|
28 |
Rules of { |
|
29 |
eq: 'a * 'a -> bool, |
|
30 |
index: 'a -> term, |
|
31 |
rules: 'a list, |
|
32 |
next: int, |
|
12385 | 33 |
net: (int * 'a) Net.net}; |
8298 | 34 |
|
12385 | 35 |
fun mk_rules eq index rules next net = |
36 |
Rules {eq = eq, index = index, rules = rules, next = next, net = net}; |
|
8298 | 37 |
|
38 |
fun rules (Rules {rules = rs, ...}) = rs; |
|
11776 | 39 |
|
12385 | 40 |
fun retrieve (Rules {rules, net, ...}) tm = |
14472
cba7c0a3ffb3
Removing the datatype declaration of "order" allows the standard General.order
paulson
parents:
13105
diff
changeset
|
41 |
Tactic.untaglist |
cba7c0a3ffb3
Removing the datatype declaration of "order" allows the standard General.order
paulson
parents:
13105
diff
changeset
|
42 |
((Library.sort (Int.compare o pairself #1) (Net.unify_term net tm))); |
8298 | 43 |
|
44 |
||
45 |
(* build rules *) |
|
46 |
||
12385 | 47 |
fun init eq index = mk_rules eq index [] ~1 Net.empty; |
8298 | 48 |
|
12385 | 49 |
fun add rule (Rules {eq, index, rules, next, net}) = |
50 |
mk_rules eq index (rule :: rules) (next - 1) |
|
51 |
(Net.insert_term ((index rule, (next, rule)), net, K false)); |
|
8298 | 52 |
|
12385 | 53 |
fun merge (Rules {eq, index, rules = rules1, ...}, Rules {rules = rules2, ...}) = |
54 |
let val rules = Library.gen_merge_lists' eq rules1 rules2 |
|
55 |
in foldr (uncurry add) (rules, init eq index) end; |
|
8298 | 56 |
|
12385 | 57 |
fun delete rule (rs as Rules {eq, index, rules, next, net}) = |
8298 | 58 |
if not (Library.gen_mem eq (rule, rules)) then rs |
12385 | 59 |
else mk_rules eq index (Library.gen_rem eq (rules, rule)) next |
60 |
(Net.delete_term ((index rule, (0, rule)), net, eq o pairself #2)); |
|
8298 | 61 |
|
12385 | 62 |
fun insert rule rs = add rule (delete rule rs); (*ensure that new rule gets precedence*) |
8298 | 63 |
|
64 |
||
65 |
(* intro/elim rules *) |
|
66 |
||
13105
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents:
12385
diff
changeset
|
67 |
val intro = init Drule.eq_thm_prop Thm.concl_of; |
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents:
12385
diff
changeset
|
68 |
val elim = init Drule.eq_thm_prop Thm.major_prem_of; |
8298 | 69 |
|
70 |
||
71 |
end; |