2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
14 module Index(B : Orderings.Blob) = struct
15 module U = FoUtils.Utils(B)
16 module Unif = FoUnif.Founif(B)
21 type t = Terms.direction * B.t Terms.unit_clause
23 let compare (d1,uc1) (d2,uc2) =
24 let c = Pervasives.compare d1 d2 in
25 if c <> 0 then c else U.compare_unit_clause uc1 uc2
30 Set.S with type elt = Terms.direction * B.t Terms.unit_clause
33 open Discrimination_tree
35 module FotermIndexable : Indexable with
36 type constant_name = B.t and
37 type input = B.t Terms.foterm
41 type input = B.t Terms.foterm
42 type constant_name = B.t
45 let rec aux arity = function
46 | Terms.Leaf a -> [Constant (a, arity)]
47 | Terms.Var i -> assert (arity = 0); [Variable]
48 | Terms.Node (Terms.Var _::_) ->
49 (* FIXME : should this be allowed or not ? *)
51 | Terms.Node ([] | [ _ ] ) -> assert false
52 | Terms.Node (Terms.Node _::_) -> assert false
53 | Terms.Node (hd::tl) ->
54 aux (List.length tl) hd @ List.flatten (List.map (aux 0) tl)
61 | Constant (a1,ar1), Constant (a2,ar2) ->
62 let c = B.compare a1 a2 in
63 if c <> 0 then c else Pervasives.compare ar1 ar2
64 | Variable, Variable -> 0
65 | Constant _, Variable -> ~-1
66 | Variable, Constant _ -> 1
67 | Proposition, _ | _, Proposition
68 | Datatype, _ | _, Datatype
70 | Bound _, _ | _, Bound _ -> assert false
73 let string_of_path l = String.concat "." (List.map (fun _ -> "*") l) ;;
77 module DT : DiscriminationTree with
78 type constant_name = B.t and
79 type input = B.t Terms.foterm and
80 type data = ClauseSet.elt and
81 type dataset = ClauseSet.t
82 = Make(FotermIndexable)(ClauseSet)
84 let index_unit_clause maxvar t = function
85 | (_,Terms.Equation (l,_,_,Terms.Gt),_,_) as c ->
86 DT.index t l (Terms.Left2Right, c)
87 | (_,Terms.Equation (_,r,_,Terms.Lt),_,_) as c ->
88 DT.index t r (Terms.Right2Left, c)
89 | (_,Terms.Equation (l,r,_,Terms.Incomparable),vl,_) as c ->
90 (* if are_invertible maxvar vl l r then
91 (prerr_endline ("Invertible " ^ (Pp.pp_foterm l) ^ "=" ^
93 DT.index t l (Terms.Left2Right, c))
96 (DT.index t l (Terms.Left2Right, c))
97 r (Terms.Right2Left, c)
98 | (_,Terms.Equation (l,r,_,Terms.Invertible),vl,_) as c ->
99 DT.index t l (Terms.Left2Right, c)
100 | (_,Terms.Equation (_,r,_,Terms.Eq),_,_) -> assert false
101 | (_,Terms.Predicate p,_,_) as c ->
102 DT.index t p (Terms.Nodir, c)
105 type active_set = B.t Terms.unit_clause list * DT.t