]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/proofEngineReduction.ml
debian version "-8"
[helm.git] / helm / gTopLevel / proofEngineReduction.ml
1 (* Copyright (C) 2002, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 12/04/2002                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36
37 (* The code of this module is derived from the code of CicReduction *)
38
39 exception Impossible of int;;
40 exception ReferenceToDefinition;;
41 exception ReferenceToAxiom;;
42 exception ReferenceToVariable;;
43 exception ReferenceToCurrentProof;;
44 exception ReferenceToInductiveDefinition;;
45 exception WrongUriToInductiveDefinition;;
46 exception RelToHiddenHypothesis;;
47
48 (* syntactic_equality up to cookingsno for uris *)
49 (* (which is often syntactically irrilevant)    *)
50 let rec syntactic_equality t t' =
51  let module C = Cic in
52   if t = t' then true
53   else
54    match t,t' with
55       C.Rel _, C.Rel _
56     | C.Var _, C.Var _
57     | C.Meta _, C.Meta _
58     | C.Sort _, C.Sort _
59     | C.Implicit, C.Implicit -> false (* we already know that t != t' *)
60     | C.Cast (te,ty), C.Cast (te',ty') ->
61        syntactic_equality te te' &&
62         syntactic_equality ty ty'
63     | C.Prod (n,s,t), C.Prod (n',s',t') ->
64        n = n' &&
65         syntactic_equality s s' &&
66          syntactic_equality t t'
67     | C.Lambda (n,s,t), C.Lambda (n',s',t') ->
68        n = n' &&
69         syntactic_equality s s' &&
70          syntactic_equality t t'
71     | C.LetIn (n,s,t), C.LetIn(n',s',t') ->
72        n = n' &&
73         syntactic_equality s s' &&
74          syntactic_equality t t'
75     | C.Appl l, C.Appl l' ->
76        List.fold_left2 (fun b t1 t2 -> b && syntactic_equality t1 t2) true l l'
77     | C.Const (uri,_), C.Const (uri',_) -> UriManager.eq uri uri'
78     | C.MutInd (uri,_,i), C.MutInd (uri',_,i') ->
79        UriManager.eq uri uri' && i = i'
80     | C.MutConstruct (uri,_,i,j), C.MutConstruct (uri',_,i',j') ->
81        UriManager.eq uri uri' && i = i' && j = j'
82     | C.MutCase (sp,_,i,outt,t,pl), C.MutCase (sp',_,i',outt',t',pl') ->
83        UriManager.eq sp sp' && i = i' &&
84         syntactic_equality outt outt' &&
85          syntactic_equality t t' &&
86           List.fold_left2
87            (fun b t1 t2 -> b && syntactic_equality t1 t2) true pl pl'
88     | C.Fix (i,fl), C.Fix (i',fl') ->
89        i = i' &&
90         List.fold_left2
91          (fun b (name,i,ty,bo) (name',i',ty',bo') ->
92            b && name = name' && i = i' &&
93             syntactic_equality ty ty' &&
94              syntactic_equality bo bo') true fl fl'
95     | C.CoFix (i,fl), C.CoFix (i',fl') ->
96        i = i' &&
97         List.fold_left2
98          (fun b (name,ty,bo) (name',ty',bo') ->
99            b && name = name' &&
100             syntactic_equality ty ty' &&
101              syntactic_equality bo bo') true fl fl'
102     | _,_ -> false
103 ;;
104
105 (* "textual" replacement of a subterm with another one *)
106 let replace ~equality ~what ~with_what ~where =
107  let module C = Cic in
108   let rec aux =
109    function
110       t when (equality t what) -> with_what
111     | C.Rel _ as t -> t
112     | C.Var _ as t  -> t
113     | C.Meta _ as t -> t
114     | C.Sort _ as t -> t
115     | C.Implicit as t -> t
116     | C.Cast (te,ty) -> C.Cast (aux te, aux ty)
117     | C.Prod (n,s,t) -> C.Prod (n, aux s, aux t)
118     | C.Lambda (n,s,t) -> C.Lambda (n, aux s, aux t)
119     | C.LetIn (n,s,t) -> C.LetIn (n, aux s, aux t)
120     | C.Appl l ->
121        (* Invariant enforced: no application of an application *)
122        (match List.map aux l with
123            (C.Appl l')::tl -> C.Appl (l'@tl)
124          | l' -> C.Appl l')
125     | C.Const _ as t -> t
126     | C.MutInd _ as t -> t
127     | C.MutConstruct _ as t -> t
128     | C.MutCase (sp,cookingsno,i,outt,t,pl) ->
129        C.MutCase (sp,cookingsno,i,aux outt, aux t,
130         List.map aux pl)
131     | C.Fix (i,fl) ->
132        let substitutedfl =
133         List.map
134          (fun (name,i,ty,bo) -> (name, i, aux ty, aux bo))
135           fl
136        in
137         C.Fix (i, substitutedfl)
138     | C.CoFix (i,fl) ->
139        let substitutedfl =
140         List.map
141          (fun (name,ty,bo) -> (name, aux ty, aux bo))
142           fl
143        in
144         C.CoFix (i, substitutedfl)
145   in
146    aux where
147 ;;
148
149 (* Takes a well-typed term and fully reduces it. *)
150 (*CSC: It does not perform reduction in a Case *)
151 let reduce context =
152  let rec reduceaux context l =
153   let module C = Cic in
154   let module S = CicSubstitution in
155    function
156       C.Rel n as t ->
157        (match List.nth context (n-1) with
158            Some (_,C.Decl _) -> if l = [] then t else C.Appl (t::l)
159          | Some (_,C.Def bo) -> reduceaux context l (S.lift n bo)
160          | None -> raise RelToHiddenHypothesis
161        )
162     | C.Var uri as t ->
163        (match CicEnvironment.get_cooked_obj uri 0 with
164            C.Definition _ -> raise ReferenceToDefinition
165          | C.Axiom _ -> raise ReferenceToAxiom
166          | C.CurrentProof _ -> raise ReferenceToCurrentProof
167          | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition
168          | C.Variable (_,None,_) -> if l = [] then t else C.Appl (t::l)
169          | C.Variable (_,Some body,_) -> reduceaux context l body
170        )
171     | C.Meta _ as t -> if l = [] then t else C.Appl (t::l)
172     | C.Sort _ as t -> t (* l should be empty *)
173     | C.Implicit as t -> t
174     | C.Cast (te,ty) ->
175        C.Cast (reduceaux context l te, reduceaux context l ty)
176     | C.Prod (name,s,t) ->
177        assert (l = []) ;
178        C.Prod (name,
179         reduceaux context [] s,
180         reduceaux ((Some (name,C.Decl s))::context) [] t)
181     | C.Lambda (name,s,t) ->
182        (match l with
183            [] ->
184             C.Lambda (name,
185              reduceaux context [] s,
186              reduceaux ((Some (name,C.Decl s))::context) [] t)
187          | he::tl -> reduceaux context tl (S.subst he t)
188            (* when name is Anonimous the substitution should be superfluous *)
189        )
190     | C.LetIn (n,s,t) ->
191        reduceaux context l (S.subst (reduceaux context [] s) t)
192     | C.Appl (he::tl) ->
193        let tl' = List.map (reduceaux context []) tl in
194         reduceaux context (tl'@l) he
195     | C.Appl [] -> raise (Impossible 1)
196     | C.Const (uri,cookingsno) as t ->
197        (match CicEnvironment.get_cooked_obj uri cookingsno with
198            C.Definition (_,body,_,_) -> reduceaux context l body
199          | C.Axiom _ -> if l = [] then t else C.Appl (t::l)
200          | C.Variable _ -> raise ReferenceToVariable
201          | C.CurrentProof (_,_,body,_) -> reduceaux context l body
202          | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition
203        )
204     | C.MutInd (uri,_,_) as t -> if l = [] then t else C.Appl (t::l)
205     | C.MutConstruct (uri,_,_,_) as t -> if l = [] then t else C.Appl (t::l)
206     | C.MutCase (mutind,cookingsno,i,outtype,term,pl) ->
207        let decofix =
208         function
209            C.CoFix (i,fl) as t ->
210             let tys =
211              List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl
212             in
213              let (_,_,body) = List.nth fl i in
214               let body' =
215                let counter = ref (List.length fl) in
216                 List.fold_right
217                  (fun _ -> decr counter ; S.subst (C.CoFix (!counter,fl)))
218                  fl
219                  body
220               in
221                reduceaux (tys@context) [] body'
222          | C.Appl (C.CoFix (i,fl) :: tl) ->
223             let tys =
224              List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl
225             in
226              let (_,_,body) = List.nth fl i in
227               let body' =
228                let counter = ref (List.length fl) in
229                 List.fold_right
230                  (fun _ -> decr counter ; S.subst (C.CoFix (!counter,fl)))
231                  fl
232                  body
233               in
234                let tl' = List.map (reduceaux context []) tl in
235                 reduceaux (tys@context) tl' body'
236          | t -> t
237        in
238         (match decofix (reduceaux context [] term) with
239             C.MutConstruct (_,_,_,j) -> reduceaux context l (List.nth pl (j-1))
240           | C.Appl (C.MutConstruct (_,_,_,j) :: tl) ->
241              let (arity, r, num_ingredients) =
242               match CicEnvironment.get_obj mutind with
243                  C.InductiveDefinition (tl,ingredients,r) ->
244                    let (_,_,arity,_) = List.nth tl i
245                    and num_ingredients =
246                     List.fold_right
247                      (fun (k,l) i ->
248                        if k < cookingsno then i + List.length l else i
249                      ) ingredients 0
250                    in
251                     (arity,r,num_ingredients)
252                | _ -> raise WrongUriToInductiveDefinition
253              in
254               let ts =
255                let num_to_eat = r + num_ingredients in
256                 let rec eat_first =
257                  function
258                     (0,l) -> l
259                   | (n,he::tl) when n > 0 -> eat_first (n - 1, tl)
260                   | _ -> raise (Impossible 5)
261                 in
262                  eat_first (num_to_eat,tl)
263               in
264                reduceaux context (ts@l) (List.nth pl (j-1))
265          | C.Cast _ | C.Implicit ->
266             raise (Impossible 2) (* we don't trust our whd ;-) *)
267          | _ ->
268            let outtype' = reduceaux context [] outtype in
269            let term' = reduceaux context [] term in
270            let pl' = List.map (reduceaux context []) pl in
271             let res =
272              C.MutCase (mutind,cookingsno,i,outtype',term',pl')
273             in
274              if l = [] then res else C.Appl (res::l)
275        )
276     | C.Fix (i,fl) ->
277        let tys =
278         List.map (function (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) fl
279        in
280         let t' () =
281          let fl' =
282           List.map
283            (function (n,recindex,ty,bo) ->
284              (n,recindex,reduceaux context [] ty, reduceaux (tys@context) [] bo)
285            ) fl
286          in
287           C.Fix (i, fl')
288         in
289          let (_,recindex,_,body) = List.nth fl i in
290           let recparam =
291            try
292             Some (List.nth l recindex)
293            with
294             _ -> None
295           in
296            (match recparam with
297                Some recparam ->
298                 (match reduceaux context [] recparam with
299                     C.MutConstruct _
300                   | C.Appl ((C.MutConstruct _)::_) ->
301                      let body' =
302                       let counter = ref (List.length fl) in
303                        List.fold_right
304                         (fun _ -> decr counter ; S.subst (C.Fix (!counter,fl)))
305                         fl
306                         body
307                      in
308                       (* Possible optimization: substituting whd recparam in l*)
309                       reduceaux context l body'
310                   | _ -> if l = [] then t' () else C.Appl ((t' ())::l)
311                 )
312              | None -> if l = [] then t' () else C.Appl ((t' ())::l)
313            )
314     | C.CoFix (i,fl) ->
315        let tys =
316         List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl
317        in
318         let t' =
319          let fl' =
320           List.map
321            (function (n,ty,bo) ->
322              (n,reduceaux context [] ty, reduceaux (tys@context) [] bo)
323            ) fl
324          in
325           C.CoFix (i, fl')
326         in
327          if l = [] then t' else C.Appl (t'::l)
328  in
329   reduceaux context []
330 ;;
331
332 exception WrongShape;;
333 exception AlreadySimplified;;
334
335 (*CSC: I fear it is still weaker than Coq's one. For example, Coq is *)
336 (*CSCS: able to simpl (foo (S n) (S n)) to (foo (S O) n) where       *)
337 (*CSC:  Fix foo                                                      *)
338 (*CSC:   {foo [n,m:nat]:nat :=                                       *)
339 (*CSC:     Cases m of O => n | (S p) => (foo (S O) p) end            *)
340 (*CSC:   }                                                           *)
341 (* Takes a well-typed term and                                               *)
342 (*  1) Performs beta-iota-zeta reduction until delta reduction is needed     *)
343 (*  2) Attempts delta-reduction. If the residual is a Fix lambda-abstracted  *)
344 (*     w.r.t. zero or more variables and if the Fix can be reduced, than it  *)
345 (*     is reduced, the delta-reduction is succesfull and the whole algorithm *)
346 (*     is applied again to the new redex; Step 3) is applied to the result   *)
347 (*     of the recursive simplification. Otherwise, if the Fix can not be     *)
348 (*     reduced, than the delta-reductions fails and the delta-redex is       *)
349 (*     not reduced. Otherwise, if the delta-residual is not the              *)
350 (*     lambda-abstraction of a Fix, then it is reduced and the result is     *)
351 (*     directly returned, without performing step 3).                        *) 
352 (*  3) Folds the application of the constant to the arguments that did not   *)
353 (*     change in every iteration, i.e. to the actual arguments for the       *)
354 (*     lambda-abstractions that precede the Fix.                             *)
355 (*CSC: It does not perform simplification in a Case *)
356 let simpl context =
357  (* reduceaux is equal to the reduceaux locally defined inside *)
358  (*reduce, but for the const case.                             *) 
359  (**** Step 1 ****)
360  let rec reduceaux context l =
361   let module C = Cic in
362   let module S = CicSubstitution in
363    function
364       C.Rel n as t ->
365        (match List.nth context (n-1) with
366            Some (_,C.Decl _) -> if l = [] then t else C.Appl (t::l)
367          | Some (_,C.Def bo) -> reduceaux context l (S.lift n bo)
368          | None -> raise RelToHiddenHypothesis
369        )
370     | C.Var uri as t ->
371        (match CicEnvironment.get_cooked_obj uri 0 with
372            C.Definition _ -> raise ReferenceToDefinition
373          | C.Axiom _ -> raise ReferenceToAxiom
374          | C.CurrentProof _ -> raise ReferenceToCurrentProof
375          | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition
376          | C.Variable (_,None,_) -> if l = [] then t else C.Appl (t::l)
377          | C.Variable (_,Some body,_) -> reduceaux context l body
378        )
379     | C.Meta _ as t -> if l = [] then t else C.Appl (t::l)
380     | C.Sort _ as t -> t (* l should be empty *)
381     | C.Implicit as t -> t
382     | C.Cast (te,ty) ->
383        C.Cast (reduceaux context l te, reduceaux context l ty)
384     | C.Prod (name,s,t) ->
385        assert (l = []) ;
386        C.Prod (name,
387         reduceaux context [] s,
388         reduceaux ((Some (name,C.Decl s))::context) [] t)
389     | C.Lambda (name,s,t) ->
390        (match l with
391            [] ->
392             C.Lambda (name,
393              reduceaux context [] s,
394              reduceaux ((Some (name,C.Decl s))::context) [] t)
395          | he::tl -> reduceaux context tl (S.subst he t)
396            (* when name is Anonimous the substitution should be superfluous *)
397        )
398     | C.LetIn (n,s,t) ->
399        reduceaux context l (S.subst (reduceaux context [] s) t)
400     | C.Appl (he::tl) ->
401        let tl' = List.map (reduceaux context []) tl in
402         reduceaux context (tl'@l) he
403     | C.Appl [] -> raise (Impossible 1)
404     | C.Const (uri,cookingsno) as t ->
405        (match CicEnvironment.get_cooked_obj uri cookingsno with
406            C.Definition (_,body,_,_) ->
407             begin
408              try
409               (**** Step 2 ****)
410               let res,constant_args =
411                let rec aux rev_constant_args l =
412                 function
413                    C.Lambda (name,s,t) as t' ->
414                     begin
415                      match l with
416                         [] -> raise WrongShape
417                       | he::tl ->
418                          (* when name is Anonimous the substitution should be *)
419                          (* superfluous                                       *)
420                          aux (he::rev_constant_args) tl (S.subst he t)
421                     end
422                  | C.LetIn (_,s,t) ->
423                     aux rev_constant_args l (S.subst s t)
424                  | C.Fix (i,fl) as t ->
425                     let tys =
426                      List.map (function (name,_,ty,_) ->
427                       Some (C.Name name, C.Decl ty)) fl
428                     in
429                      let (_,recindex,_,body) = List.nth fl i in
430                       let recparam =
431                        try
432                         List.nth l recindex
433                        with
434                         _ -> raise AlreadySimplified
435                       in
436                        (match CicReduction.whd context recparam with
437                            C.MutConstruct _
438                          | C.Appl ((C.MutConstruct _)::_) ->
439                             let body' =
440                              let counter = ref (List.length fl) in
441                               List.fold_right
442                                (function _ ->
443                                  decr counter ; S.subst (C.Fix (!counter,fl))
444                                ) fl body
445                             in
446                              (* Possible optimization: substituting whd *)
447                              (* recparam in l                           *)
448                              reduceaux (tys@context) l body',
449                               List.rev rev_constant_args
450                          | _ -> raise AlreadySimplified
451                        )
452                  | _ -> raise WrongShape
453                in
454                 aux [] l body
455               in
456                (**** Step 3 ****)
457                let term_to_fold =
458                 match constant_args with
459                    [] -> C.Const (uri,cookingsno)
460                  | _ -> C.Appl ((C.Const (uri,cookingsno))::constant_args)
461                in
462                 let reduced_term_to_fold = reduce context term_to_fold in
463                  replace (=) reduced_term_to_fold term_to_fold res
464              with
465                 WrongShape ->
466                  (* The constant does not unfold to a Fix lambda-abstracted   *)
467                  (* w.r.t. zero or more variables. We just perform reduction. *)
468                  reduceaux context l body
469               | AlreadySimplified ->
470                  (* If we performed delta-reduction, we would find a Fix   *)
471                  (* not applied to a constructor. So, we refuse to perform *)
472                  (* delta-reduction.                                       *)
473                  if l = [] then
474                     t
475                  else
476                   C.Appl (t::l)
477             end
478          | C.Axiom _ -> if l = [] then t else C.Appl (t::l)
479          | C.Variable _ -> raise ReferenceToVariable
480          | C.CurrentProof (_,_,body,_) -> reduceaux context l body
481          | C.InductiveDefinition _ -> raise ReferenceToInductiveDefinition
482        )
483     | C.MutInd (uri,_,_) as t -> if l = [] then t else C.Appl (t::l)
484     | C.MutConstruct (uri,_,_,_) as t -> if l = [] then t else C.Appl (t::l)
485     | C.MutCase (mutind,cookingsno,i,outtype,term,pl) ->
486        let decofix =
487         function
488            C.CoFix (i,fl) as t ->
489             let tys =
490              List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl            in
491              let (_,_,body) = List.nth fl i in
492               let body' =
493                let counter = ref (List.length fl) in
494                 List.fold_right
495                  (fun _ -> decr counter ; S.subst (C.CoFix (!counter,fl)))
496                  fl
497                  body
498               in
499                reduceaux (tys@context) [] body'
500          | C.Appl (C.CoFix (i,fl) :: tl) ->
501             let tys =
502              List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl            in
503              let (_,_,body) = List.nth fl i in
504               let body' =
505                let counter = ref (List.length fl) in
506                 List.fold_right
507                  (fun _ -> decr counter ; S.subst (C.CoFix (!counter,fl)))
508                  fl
509                  body
510               in
511                let tl' = List.map (reduceaux context []) tl in
512                 reduceaux (tys@context) tl body'
513          | t -> t
514        in
515         (match decofix (reduceaux context [] term) with
516             C.MutConstruct (_,_,_,j) -> reduceaux context l (List.nth pl (j-1))
517           | C.Appl (C.MutConstruct (_,_,_,j) :: tl) ->
518              let (arity, r, num_ingredients) =
519               match CicEnvironment.get_obj mutind with
520                  C.InductiveDefinition (tl,ingredients,r) ->
521                    let (_,_,arity,_) = List.nth tl i
522                    and num_ingredients =
523                     List.fold_right
524                      (fun (k,l) i ->
525                        if k < cookingsno then i + List.length l else i
526                      ) ingredients 0
527                    in
528                     (arity,r,num_ingredients)
529                | _ -> raise WrongUriToInductiveDefinition
530              in
531               let ts =
532                let num_to_eat = r + num_ingredients in
533                 let rec eat_first =
534                  function
535                     (0,l) -> l
536                   | (n,he::tl) when n > 0 -> eat_first (n - 1, tl)
537                   | _ -> raise (Impossible 5)
538                 in
539                  eat_first (num_to_eat,tl)
540               in
541                reduceaux context (ts@l) (List.nth pl (j-1))
542          | C.Cast _ | C.Implicit ->
543             raise (Impossible 2) (* we don't trust our whd ;-) *)
544          | _ ->
545            let outtype' = reduceaux context [] outtype in
546            let term' = reduceaux context [] term in
547            let pl' = List.map (reduceaux context []) pl in
548             let res =
549              C.MutCase (mutind,cookingsno,i,outtype',term',pl')
550             in
551              if l = [] then res else C.Appl (res::l)
552        )
553     | C.Fix (i,fl) ->
554        let tys =
555         List.map (function (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) fl
556        in
557         let t' () =
558          let fl' =
559           List.map
560            (function (n,recindex,ty,bo) ->
561              (n,recindex,reduceaux context [] ty, reduceaux (tys@context) [] bo)
562            ) fl
563          in
564           C.Fix (i, fl')
565         in
566          let (_,recindex,_,body) = List.nth fl i in
567           let recparam =
568            try
569             Some (List.nth l recindex)
570            with
571             _ -> None
572           in
573            (match recparam with
574                Some recparam ->
575                 (match reduceaux context [] recparam with
576                     C.MutConstruct _
577                   | C.Appl ((C.MutConstruct _)::_) ->
578                      let body' =
579                       let counter = ref (List.length fl) in
580                        List.fold_right
581                         (fun _ -> decr counter ; S.subst (C.Fix (!counter,fl)))
582                         fl
583                         body
584                      in
585                       (* Possible optimization: substituting whd recparam in l*)
586                       reduceaux context l body'
587                   | _ -> if l = [] then t' () else C.Appl ((t' ())::l)
588                 )
589              | None -> if l = [] then t' () else C.Appl ((t' ())::l)
590            )
591     | C.CoFix (i,fl) ->
592        let tys =
593         List.map (function (name,ty,_) -> Some (C.Name name, C.Decl ty)) fl
594        in
595         let t' =
596          let fl' =
597           List.map
598            (function (n,ty,bo) ->
599              (n,reduceaux context [] ty, reduceaux (tys@context) [] bo)
600            ) fl
601          in
602          C.CoFix (i, fl')
603        in
604          if l = [] then t' else C.Appl (t'::l)
605  in
606   reduceaux context []
607 ;;