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)
19 type t = Terms.direction * (* direction if it is an equality *)
20 bool * (* true if indexed literal is positive *)
21 int * (* position of literal in clause *)
24 let compare (d1,p1,pos1,uc1) (d2,p2,pos2,uc2) =
25 let c = Pervasives.compare (d1,p1,pos1) (d2,p2,pos2) in
26 if c <> 0 then c else U.compare_clause uc1 uc2
31 Set.S with type elt = Terms.direction * (* direction if it is an equality *)
32 bool * (* true if indexed literal is positive *)
33 int * (* position of literal in clause *)
37 open Discrimination_tree
39 module FotermIndexable : Indexable with
40 type constant_name = B.t and
41 type input = B.t Terms.foterm
45 type input = B.t Terms.foterm
46 type constant_name = B.t
49 let rec aux arity = function
50 | Terms.Leaf a -> [Constant (a, arity)]
51 | Terms.Var i -> assert (arity = 0); [Variable]
52 | Terms.Node (Terms.Var _::_) ->
53 (* FIXME : should this be allowed or not ? *)
55 | Terms.Node ([] | [ _ ] ) -> assert false
56 | Terms.Node (Terms.Node _::_) -> assert false
57 | Terms.Node (hd::tl) ->
58 aux (List.length tl) hd @ List.flatten (List.map (aux 0) tl)
65 | Constant (a1,ar1), Constant (a2,ar2) ->
66 let c = B.compare a1 a2 in
67 if c <> 0 then c else Pervasives.compare ar1 ar2
68 | Variable, Variable -> 0
69 | Constant _, Variable -> ~-1
70 | Variable, Constant _ -> 1
71 | Proposition, _ | _, Proposition
72 | Datatype, _ | _, Datatype
74 | Bound _, _ | _, Bound _ -> assert false
77 let string_of_path l = String.concat "." (List.map (fun _ -> "*") l) ;;
81 module DT : DiscriminationTree with
82 type constant_name = B.t and
83 type input = B.t Terms.foterm and
84 type data = ClauseSet.elt and
85 type dataset = ClauseSet.t
86 = Make(FotermIndexable)(ClauseSet)
88 let index_literal t c is_pos pos = function
89 | Terms.Equation (l,_,_,Terms.Invertible)
90 | Terms.Equation (l,_,_,Terms.Gt) ->
91 DT.index t l (Terms.Left2Right,is_pos,pos,c)
92 | Terms.Equation (_,r,_,Terms.Lt) ->
93 DT.index t r (Terms.Right2Left,is_pos,pos,c)
94 | Terms.Equation (l,r,_,Terms.Incomparable) ->
96 (DT.index t l (Terms.Left2Right,is_pos,pos,c))
97 r (Terms.Right2Left,is_pos,pos,c)
98 | Terms.Equation (_,_,_,Terms.Eq) -> assert false
99 | Terms.Predicate p ->
100 DT.index t p (Terms.Nodir,is_pos,pos,c)
103 let index_clause t (_,nlit,plit,_,_ as c) =
104 let index_iter is_pos (t,pos) (lit,sel) =
105 if sel then index_literal t c is_pos pos lit,pos+1 else t,pos+1
107 let (res,_) = List.fold_left (index_iter false) (t,0) nlit in
108 fst (List.fold_left (index_iter true) (res,0) plit)
111 type active_set = B.t Terms.clause list * DT.t