1 (* Copyright (C) 2000, 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 exception CannotSubstInMeta;;
27 exception RelToHiddenHypothesis;;
44 | Some t -> Some (liftaux k t)
49 | C.Implicit as t -> t
50 | C.Cast (te,ty) -> C.Cast (liftaux k te, liftaux k ty)
51 | C.Prod (n,s,t) -> C.Prod (n, liftaux k s, liftaux (k+1) t)
52 | C.Lambda (n,s,t) -> C.Lambda (n, liftaux k s, liftaux (k+1) t)
53 | C.LetIn (n,s,t) -> C.LetIn (n, liftaux k s, liftaux (k+1) t)
54 | C.Appl l -> C.Appl (List.map (liftaux k) l)
57 | C.MutInd _ as t -> t
58 | C.MutConstruct _ as t -> t
59 | C.MutCase (sp,cookingsno,i,outty,t,pl) ->
60 C.MutCase (sp, cookingsno, i, liftaux k outty, liftaux k t,
61 List.map (liftaux k) pl)
63 let len = List.length fl in
66 (fun (name, i, ty, bo) -> (name, i, liftaux k ty, liftaux (k+len) bo))
71 let len = List.length fl in
74 (fun (name, ty, bo) -> (name, liftaux k ty, liftaux (k+len) bo))
91 n when n = k -> lift (k - 1) arg
96 | C.Meta (i, l) as t ->
101 | Some t -> Some (substaux k t)
106 | C.Implicit as t -> t
107 | C.Cast (te,ty) -> C.Cast (substaux k te, substaux k ty)
108 | C.Prod (n,s,t) -> C.Prod (n, substaux k s, substaux (k + 1) t)
109 | C.Lambda (n,s,t) -> C.Lambda (n, substaux k s, substaux (k + 1) t)
110 | C.LetIn (n,s,t) -> C.LetIn (n, substaux k s, substaux (k + 1) t)
112 (* Invariant: no Appl applied to another Appl *)
113 let tl' = List.map (substaux k) tl in
115 match substaux k he with
116 C.Appl l -> C.Appl (l@tl')
117 | _ as he' -> C.Appl (he'::tl')
119 | C.Appl _ -> assert false
120 | C.Const _ as t -> t
122 | C.MutInd _ as t -> t
123 | C.MutConstruct _ as t -> t
124 | C.MutCase (sp,cookingsno,i,outt,t,pl) ->
125 C.MutCase (sp,cookingsno,i,substaux k outt, substaux k t,
126 List.map (substaux k) pl)
128 let len = List.length fl in
131 (fun (name,i,ty,bo) -> (name, i, substaux k ty, substaux (k+len) bo))
134 C.Fix (i, substitutedfl)
136 let len = List.length fl in
139 (fun (name,ty,bo) -> (name, substaux k ty, substaux (k+len) bo))
142 C.CoFix (i, substitutedfl)
147 let undebrujin_inductive_def uri =
149 Cic.InductiveDefinition (dl,params,n_ind_params) ->
152 (fun (name,inductive,arity,constructors) ->
157 let counter = ref (List.length dl) in
161 subst (Cic.MutInd (uri,0,!counter))
167 (name,inductive,arity,constructors')
170 Cic.InductiveDefinition (dl', params, n_ind_params)
174 (* l is the relocation list *)
177 let module C = Cic in
178 if l = [] then t else
179 let rec aux k = function
181 if n <= k then t else
183 match List.nth l (n-k-1) with
184 None -> raise RelToHiddenHypothesis
187 (Failure _) -> assert false
199 RelToHiddenHypothesis -> None
204 | C.Implicit as t -> t
205 | C.Cast (te,ty) -> C.Cast (aux k te, aux k ty) (*CSC ??? *)
206 | C.Prod (n,s,t) -> C.Prod (n, aux k s, aux (k + 1) t)
207 | C.Lambda (n,s,t) -> C.Lambda (n, aux k s, aux (k + 1) t)
208 | C.LetIn (n,s,t) -> C.LetIn (n, aux k s, aux (k + 1) t)
209 | C.Appl l -> C.Appl (List.map (aux k) l)
210 | C.Const _ as t -> t
212 | C.MutInd _ as t -> t
213 | C.MutConstruct _ as t -> t
214 | C.MutCase (sp,cookingsno,i,outt,t,pl) ->
215 C.MutCase (sp,cookingsno,i,aux k outt, aux k t,
218 let len = List.length fl in
221 (fun (name,i,ty,bo) -> (name, i, aux k ty, aux (k+len) bo))
224 C.Fix (i, substitutedfl)
226 let len = List.length fl in
229 (fun (name,ty,bo) -> (name, aux k ty, aux (k+len) bo))
232 C.CoFix (i, substitutedfl)