1 (* Copyright (C) 2002, 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/.
26 module Codomain = struct
28 let compare = Pervasives.compare
30 module S = Set.Make(Codomain)
31 module TI = Discrimination_tree.DiscriminationTreeIndexing(S)
37 let get_candidates univ ty =
38 S.elements (TI.retrieve_unifiables univ ty)
41 let rec unfold context = function
42 | Cic.Prod(name,s,t) ->
43 let t' = unfold ((Some (name,Cic.Decl s))::context) t in
45 | t -> ProofEngineReduction.unfold context t
47 let rec collapse_head_metas t =
49 | Cic.Appl([]) -> assert false
51 let a' = collapse_head_metas a in
53 | Cic.Meta(n,m) -> Cic.Meta(n,m)
55 let l' = List.map collapse_head_metas l in
64 | Cic.MutConstruct _ -> t
71 | Cic.CoFix _ -> Cic.Meta(-1,[])
74 let rec dummies_of_coercions =
76 | Cic.Appl (c::l) when CoercDb.is_a_coercion c <> None ->
79 let l' = List.map dummies_of_coercions l in Cic.Appl l'
80 | Cic.Lambda(n,s,t) ->
81 let s' = dummies_of_coercions s in
82 let t' = dummies_of_coercions t in
85 let s' = dummies_of_coercions s in
86 let t' = dummies_of_coercions t in
88 | Cic.LetIn(n,s,ty,t) ->
89 let s' = dummies_of_coercions s in
90 let ty' = dummies_of_coercions ty in
91 let t' = dummies_of_coercions t in
92 Cic.LetIn (n,s',ty',t')
93 | Cic.MutCase _ -> Cic.Meta (-1,[])
98 let rec head remove_coercions t =
100 if remove_coercions then dummies_of_coercions t
102 let rec aux = function
104 CicSubstitution.subst (Cic.Meta (-1,[])) (aux t)
106 in collapse_head_metas (clean_up (aux t))
110 let index univ key term =
111 (* flexible terms are not indexed *)
112 if key = Cic.Meta(-1,[]) then univ
114 ((*prerr_endline("ADD: "^CicPp.ppterm key^" |-> "^CicPp.ppterm term);*)
115 TI.index univ key term)
118 let keys context ty =
120 [head true ty; head true (unfold context ty)]
121 with ProofEngineTypes.Fail _ -> [head true ty]
123 let key term = head false term;;
125 let index_term_and_unfolded_term univ context t ty =
126 let key = head true ty in
127 let univ = index univ key t in
129 let key = head true (unfold context ty) in
131 with ProofEngineTypes.Fail _ -> univ
134 let index_local_term univ context t ty =
135 let key = head true ty in
136 let univ = index univ key t in
137 let key1 = head false ty in
139 if key<>key1 then index univ key1 t else univ in
141 let key = head true (unfold context ty) in
143 with ProofEngineTypes.Fail _ -> univ
147 let index_list univ context terms_and_types =
149 (fun acc (term,ty) ->
150 index_term_and_unfolded_term acc context term ty)
155 let remove univ context term ty =
156 let key = head true ty in
157 let univ = TI.remove_index univ key term in
159 let key = head true (unfold context ty) in
160 TI.remove_index univ key term
161 with ProofEngineTypes.Fail _ -> univ
163 let remove_uri univ uri =
164 let term = CicUtil.term_of_uri uri in
165 let ty,_ = CicTypeChecker.type_of_aux' [] [] term CicUniv.oblivion_ugraph in
166 remove univ [] term ty