1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
28 open Discrimination_tree
30 module TermOT : Set.OrderedType with type t = NCic.term = struct
32 let compare = Pervasives.compare
35 module TermSet = Set.Make(TermOT)
37 module NCicIndexable : Indexable
38 with type input = NCic.term
39 and type constant_name = NReference.reference = struct
41 type input = NCic.term
42 type constant_name = NReference.reference
45 | Constant (ref,arity) ->
46 "("^NReference.string_of_reference ref ^ "," ^ string_of_int arity^")"
48 "("^string_of_int i ^ "," ^ string_of_int arity^")"
50 | Proposition -> "Prop"
55 let path_string_of t =
56 let rec aux arity depth = function
57 | NCic.Appl ((NCic.Meta _|NCic.Implicit _)::_) -> [Variable]
58 | NCic.Appl (NCic.Lambda _ :: _) -> [Variable] (* maybe we should b-reduce *)
59 | NCic.Appl [] -> assert false
60 | NCic.Appl l when depth > 10 || List.length l > 50 -> [Variable]
61 | NCic.Appl (hd::tl) ->
62 aux (List.length tl) depth hd @
63 List.flatten (List.map (aux 0 (depth+1)) tl)
64 | NCic.Lambda _ | NCic.Prod _ -> [Variable]
65 (* I think we should CicSubstitution.subst Implicit t *)
66 | NCic.LetIn _ -> [Variable] (* z-reduce? *)
67 | NCic.Meta _ | NCic.Implicit _ -> assert (arity = 0); [Variable]
68 | NCic.Rel i -> [Bound (i, arity)]
69 | NCic.Sort (NCic.Prop) -> assert (arity=0); [Proposition]
70 | NCic.Sort _ -> assert (arity=0); [Datatype]
71 | NCic.Const (u) -> [Constant (u, arity)]
72 | NCic.Match _ -> [Dead]
79 | Constant (u1,a1),Constant (u2,a2) ->
80 let x = NReference.compare u1 u2 in
81 if x = 0 then Pervasives.compare a1 a2 else x
82 | e1,e2 -> Pervasives.compare e1 e2
85 let string_of_path l = String.concat "." (List.map ppelem l) ;;
89 module DiscriminationTree = Make(NCicIndexable)(TermSet)