12 val facts: T -> (string * thm list) list |
12 val facts: T -> (string * thm list) list |
13 val props: T -> thm list |
13 val props: T -> thm list |
14 val could_unify: T -> term -> thm list |
14 val could_unify: T -> term -> thm list |
15 val empty: T |
15 val empty: T |
16 val add_global: (string * thm list) -> T -> T |
16 val add_global: (string * thm list) -> T -> T |
17 val add_local: bool -> (string -> bool) -> (string * thm list) -> T -> T |
17 val add_local: bool -> (string * thm list) -> T -> T |
18 val find: T -> spec -> (string * thm list) list |
18 val find: T -> spec -> (string * thm list) list |
19 end; |
19 end; |
20 |
20 |
21 structure FactIndex: FACT_INDEX = |
21 structure FactIndex: FACT_INDEX = |
22 struct |
22 struct |
27 type spec = string list * string list; |
27 type spec = string list * string list; |
28 |
28 |
29 val add_consts = fold_aterms |
29 val add_consts = fold_aterms |
30 (fn Const (c, _) => if c = Term.dummy_patternN then I else insert (op =) c | _ => I); |
30 (fn Const (c, _) => if c = Term.dummy_patternN then I else insert (op =) c | _ => I); |
31 |
31 |
32 fun add_frees known = fold_aterms |
32 val add_frees = fold_aterms (fn Free (x, _) => insert (op =) x | _ => I); |
33 (fn Free (x, _) => if known x then insert (op =) x else I | _ => I); |
|
34 |
33 |
35 fun index_term known t (cs, xs) = (add_consts t cs, add_frees known t xs); |
34 fun index_term t (cs, xs) = (add_consts t cs, add_frees t xs); |
36 |
35 |
37 fun index_thm known th idx = |
36 fun index_thm th = |
38 let val {tpairs, hyps, prop, ...} = Thm.rep_thm th in |
37 let val {tpairs, hyps, prop, ...} = Thm.rep_thm th in |
39 idx |
38 index_term prop |
40 |> index_term known prop |
39 #> fold index_term hyps |
41 |> fold (index_term known) hyps |
40 #> fold (fn (t, u) => index_term t #> index_term u) tpairs |
42 |> fold (fn (t, u) => index_term known t #> index_term known u) tpairs |
|
43 end; |
41 end; |
44 |
42 |
45 |
43 |
46 (* build index *) |
44 (* build index *) |
47 |
45 |
59 fun could_unify (Index {props, ...}) = Net.unify_term props; |
57 fun could_unify (Index {props, ...}) = Net.unify_term props; |
60 |
58 |
61 val empty = |
59 val empty = |
62 Index {facts = [], consts = Symtab.empty, frees = Symtab.empty, props = Net.empty}; |
60 Index {facts = [], consts = Symtab.empty, frees = Symtab.empty, props = Net.empty}; |
63 |
61 |
64 fun add do_props do_index known (fact as (_, ths)) (Index {facts, consts, frees, props}) = |
62 fun add do_props do_index (fact as (_, ths)) (Index {facts, consts, frees, props}) = |
65 let |
63 let |
66 val entry = (serial (), fact); |
64 val entry = (serial (), fact); |
67 val (cs, xs) = fold (index_thm known) ths ([], []); |
65 val (cs, xs) = fold index_thm ths ([], []); |
68 |
66 |
69 val (facts', consts', frees') = |
67 val (facts', consts', frees') = |
70 if do_index then |
68 if do_index then |
71 (fact :: facts, |
69 (fact :: facts, |
72 consts |> fold (fn c => Symtab.update_list (c, entry)) cs, |
70 consts |> fold (fn c => Symtab.update_list (c, entry)) cs, |
75 val props' = |
73 val props' = |
76 if do_props then props |> fold (fn th => Net.insert_term (K false) (Thm.prop_of th, th)) ths |
74 if do_props then props |> fold (fn th => Net.insert_term (K false) (Thm.prop_of th, th)) ths |
77 else props; |
75 else props; |
78 in Index {facts = facts', consts = consts', frees = frees', props = props'} end; |
76 in Index {facts = facts', consts = consts', frees = frees', props = props'} end; |
79 |
77 |
80 val add_global = add false true (K false); |
78 val add_global = add false true; |
81 val add_local = add true; |
79 val add_local = add true; |
82 |
80 |
83 |
81 |
84 (* find by consts/frees *) |
82 (* find by consts/frees *) |
85 |
83 |