From: Enrico Tassi Date: Fri, 3 Oct 2008 11:04:07 +0000 (+0000) Subject: - NCicPp.ppterm applies the substitution X-Git-Tag: make_still_working~4704 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=1ef41da37d7b39da1521f53d3b22981556bfbe68;p=helm.git - NCicPp.ppterm applies the substitution - NCicReduction.are_convertible does not take in input the get_relevance function any longer, there is a ref set by the typechecker module - fixes to the convert-machines and small-delta-step logic --- diff --git a/helm/software/components/ng_kernel/.depend b/helm/software/components/ng_kernel/.depend index b3fbf55f3..aafbcd14e 100644 --- a/helm/software/components/ng_kernel/.depend +++ b/helm/software/components/ng_kernel/.depend @@ -4,8 +4,8 @@ nCicSubstitution.cmi: nCic.cmo oCic2NCic.cmi: nUri.cmi nReference.cmi nCic.cmo nCic2OCic.cmi: nUri.cmi nReference.cmi nCic.cmo nCicLibrary.cmi: nUri.cmi nCic.cmo -nCicEnvironment.cmi: nUri.cmi nReference.cmi nCic.cmo nCicPp.cmi: nCic.cmo +nCicEnvironment.cmi: nUri.cmi nReference.cmi nCic.cmo nCicReduction.cmi: nCic.cmo nCicTypeChecker.cmi: nUri.cmi nCic.cmo nCicUntrusted.cmi: nCic.cmo @@ -29,12 +29,12 @@ nCic2OCic.cmo: nUri.cmi nReference.cmi nCic.cmo nCic2OCic.cmi nCic2OCic.cmx: nUri.cmx nReference.cmx nCic.cmx nCic2OCic.cmi nCicLibrary.cmo: oCic2NCic.cmi nUri.cmi nCic2OCic.cmi nCicLibrary.cmi nCicLibrary.cmx: oCic2NCic.cmx nUri.cmx nCic2OCic.cmx nCicLibrary.cmi +nCicPp.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmo nCicPp.cmi +nCicPp.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx nCicPp.cmi nCicEnvironment.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmo \ nCicEnvironment.cmi nCicEnvironment.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx \ nCicEnvironment.cmi -nCicPp.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmo nCicPp.cmi -nCicPp.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx nCicPp.cmi nCicReduction.cmo: nReference.cmi nCicUtils.cmi nCicSubstitution.cmi \ nCicEnvironment.cmi nCic.cmo nCicReduction.cmi nCicReduction.cmx: nReference.cmx nCicUtils.cmx nCicSubstitution.cmx \ @@ -45,5 +45,7 @@ nCicTypeChecker.cmo: nUri.cmi nReference.cmi nCicUtils.cmi \ nCicTypeChecker.cmx: nUri.cmx nReference.cmx nCicUtils.cmx \ nCicSubstitution.cmx nCicReduction.cmx nCicPp.cmx nCicEnvironment.cmx \ nCic.cmx nCicTypeChecker.cmi -nCicUntrusted.cmo: nReference.cmi nCic.cmo nCicUntrusted.cmi -nCicUntrusted.cmx: nReference.cmx nCic.cmx nCicUntrusted.cmi +nCicUntrusted.cmo: nReference.cmi nCicUtils.cmi nCicSubstitution.cmi nCic.cmo \ + nCicUntrusted.cmi +nCicUntrusted.cmx: nReference.cmx nCicUtils.cmx nCicSubstitution.cmx nCic.cmx \ + nCicUntrusted.cmi diff --git a/helm/software/components/ng_kernel/.depend.opt b/helm/software/components/ng_kernel/.depend.opt index a4affb50b..985fec0df 100644 --- a/helm/software/components/ng_kernel/.depend.opt +++ b/helm/software/components/ng_kernel/.depend.opt @@ -1,11 +1,11 @@ nReference.cmi: nUri.cmi nCicUtils.cmi: nCic.cmx +nCicPp.cmi: nCic.cmx nCicSubstitution.cmi: nCic.cmx oCic2NCic.cmi: nUri.cmi nReference.cmi nCic.cmx nCic2OCic.cmi: nUri.cmi nReference.cmi nCic.cmx nCicLibrary.cmi: nUri.cmi nCic.cmx nCicEnvironment.cmi: nUri.cmi nReference.cmi nCic.cmx -nCicPp.cmi: nCic.cmx nCicReduction.cmi: nCic.cmx nCicTypeChecker.cmi: nUri.cmi nCic.cmx nCicUntrusted.cmi: nCic.cmx @@ -17,6 +17,8 @@ nReference.cmo: nUri.cmi nReference.cmi nReference.cmx: nUri.cmx nReference.cmi nCicUtils.cmo: nReference.cmi nCic.cmx nCicUtils.cmi nCicUtils.cmx: nReference.cmx nCic.cmx nCicUtils.cmi +nCicPp.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmx nCicPp.cmi +nCicPp.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx nCicPp.cmi nCicSubstitution.cmo: nReference.cmi nCicUtils.cmi nCic.cmx \ nCicSubstitution.cmi nCicSubstitution.cmx: nReference.cmx nCicUtils.cmx nCic.cmx \ @@ -33,8 +35,6 @@ nCicEnvironment.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmx \ nCicEnvironment.cmi nCicEnvironment.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx \ nCicEnvironment.cmi -nCicPp.cmo: nUri.cmi nReference.cmi nCicLibrary.cmi nCic.cmx nCicPp.cmi -nCicPp.cmx: nUri.cmx nReference.cmx nCicLibrary.cmx nCic.cmx nCicPp.cmi nCicReduction.cmo: nReference.cmi nCicUtils.cmi nCicSubstitution.cmi \ nCicEnvironment.cmi nCic.cmx nCicReduction.cmi nCicReduction.cmx: nReference.cmx nCicUtils.cmx nCicSubstitution.cmx \ @@ -45,5 +45,7 @@ nCicTypeChecker.cmo: nUri.cmi nReference.cmi nCicUtils.cmi \ nCicTypeChecker.cmx: nUri.cmx nReference.cmx nCicUtils.cmx \ nCicSubstitution.cmx nCicReduction.cmx nCicPp.cmx nCicEnvironment.cmx \ nCic.cmx nCicTypeChecker.cmi -nCicUntrusted.cmo: nReference.cmi nCic.cmx nCicUntrusted.cmi -nCicUntrusted.cmx: nReference.cmx nCic.cmx nCicUntrusted.cmi +nCicUntrusted.cmo: nReference.cmi nCicUtils.cmi nCicSubstitution.cmi nCic.cmx \ + nCicUntrusted.cmi +nCicUntrusted.cmx: nReference.cmx nCicUtils.cmx nCicSubstitution.cmx nCic.cmx \ + nCicUntrusted.cmi diff --git a/helm/software/components/ng_kernel/Makefile b/helm/software/components/ng_kernel/Makefile index 670429b99..fedcaa4d8 100644 --- a/helm/software/components/ng_kernel/Makefile +++ b/helm/software/components/ng_kernel/Makefile @@ -9,8 +9,8 @@ INTERFACE_FILES = \ oCic2NCic.mli \ nCic2OCic.mli \ nCicLibrary.mli \ - nCicEnvironment.mli \ nCicPp.mli \ + nCicEnvironment.mli \ nCicReduction.mli \ nCicTypeChecker.mli \ nCicUntrusted.mli diff --git a/helm/software/components/ng_kernel/check.ml b/helm/software/components/ng_kernel/check.ml index c1ce42607..a61e6a8ff 100644 --- a/helm/software/components/ng_kernel/check.ml +++ b/helm/software/components/ng_kernel/check.ml @@ -73,7 +73,6 @@ let _ = prerr_endline (HelmLogger.string_of_html_msg html_msg)); CicParser.impredicative_set := false; NCicTypeChecker.set_logger logger; - NCicPp.set_ppterm NCicPp.trivial_pp_term; Helm_registry.load_from "conf.xml"; let alluris = try diff --git a/helm/software/components/ng_kernel/nCicPp.ml b/helm/software/components/ng_kernel/nCicPp.ml index 5f29d25d8..73c3f572c 100644 --- a/helm/software/components/ng_kernel/nCicPp.ml +++ b/helm/software/components/ng_kernel/nCicPp.ml @@ -11,17 +11,6 @@ (* $Id$ *) -let ppterm = - ref (fun ~context:_ ~subst:_ ~metasenv:_ ?inside_fix _ -> - ignore (inside_fix) ; "Please, set a pp callback") -;; - -let set_ppterm f = ppterm := f;; - -let ppterm ~context ~subst ~metasenv ?inside_fix t = - !ppterm ~context ~subst ~metasenv ?inside_fix t -;; - module C = NCic module R = NReference @@ -54,7 +43,7 @@ let r2s pp_fix_name r = with NCicLibrary.ObjectNotFound _ -> R.string_of_reference r ;; -let trivial_pp_term ~context ~subst:_ ~metasenv:_ ?(inside_fix=false) t = +let ppterm ~context ~subst ~metasenv:_ ?(inside_fix=false) t = let buff = Buffer.create 100 in let f = Format.formatter_of_buffer buff in let module F = Format in @@ -132,11 +121,18 @@ let trivial_pp_term ~context ~subst:_ ~metasenv:_ ?(inside_fix=false) t = if not toplevel then F.fprintf f ")"; F.fprintf f "@]" | C.Implicit _ -> F.fprintf f "?" + | C.Meta (n,lc) when List.mem_assoc n subst -> + let _,_,t,_ = List.assoc n subst in + aux ctx (NCicSubstitution.subst_meta lc t) | C.Meta (n,(shift,C.Irl len)) -> F.fprintf f "?%d(%d,%d)" n shift len | C.Meta (n,(shift,C.Ctx l)) -> F.fprintf f "?%d(%d,[" n shift; - List.iter (fun x -> aux ctx x; F.fprintf f ",") l; + if List.length l > 0 then + begin + aux ctx (List.hd l); + List.iter (fun x -> F.fprintf f ",";aux ctx x) (List.tl l); + end; F.fprintf f "])" | C.Sort C.Prop -> F.fprintf f "Prop" | C.Sort (C.Type []) -> F.fprintf f "IllFormedUniverse" diff --git a/helm/software/components/ng_kernel/nCicPp.mli b/helm/software/components/ng_kernel/nCicPp.mli index 50204fe99..1654cdfb2 100644 --- a/helm/software/components/ng_kernel/nCicPp.mli +++ b/helm/software/components/ng_kernel/nCicPp.mli @@ -11,13 +11,6 @@ (* $Id$ *) -val set_ppterm: - (context:NCic.context -> - subst:NCic.substitution -> - metasenv:NCic.metasenv -> - ?inside_fix:bool -> - NCic.term -> string) -> unit - val ppterm: context:NCic.context -> subst:NCic.substitution -> @@ -30,11 +23,4 @@ val ppcontext: metasenv:NCic.metasenv -> NCic.context -> string -val trivial_pp_term: - context:NCic.context -> - subst:NCic.substitution -> - metasenv:NCic.metasenv -> - ?inside_fix:bool -> - NCic.term -> string - val ppobj: NCic.obj -> string diff --git a/helm/software/components/ng_kernel/nCicReduction.ml b/helm/software/components/ng_kernel/nCicReduction.ml index 4de73408f..bd7cbc842 100644 --- a/helm/software/components/ng_kernel/nCicReduction.ml +++ b/helm/software/components/ng_kernel/nCicReduction.ml @@ -171,8 +171,12 @@ let whd = R.whd let (===) x y = Pervasives.compare x y = 0 ;; +let get_relevance = ref (fun ~subst:_ _ _ -> assert false);; + +let set_get_relevance f = get_relevance := f;; + (* t1, t2 must be well-typed *) -let are_convertible ?(subst=[]) get_exact_relev = +let are_convertible ?(subst=[]) = let rec aux test_eq_only context t1 t2 = let alpha_eq test_eq_only t1 t2 = if t1 === t2 then @@ -239,7 +243,7 @@ let are_convertible ?(subst=[]) get_exact_relev = tl1 tl2 true relevance with Invalid_argument _ -> false | HExtlib.FailureAt fail -> - let relevance = get_exact_relev ~subst context hd1 tl1 in + let relevance = !get_relevance ~subst context hd1 tl1 in let _,relevance = HExtlib.split_nth fail relevance in let b,relevance = (match relevance with | [] -> assert false @@ -256,7 +260,7 @@ let are_convertible ?(subst=[]) get_exact_relev = | (C.Appl (hd1::tl1), C.Appl (hd2::tl2)) -> aux test_eq_only context hd1 hd2 && - let relevance = get_exact_relev ~subst context hd1 tl1 in + let relevance = !get_relevance ~subst context hd1 tl1 in (try HExtlib.list_forall_default3 (fun t1 t2 b -> not b || aux test_eq_only context t1 t2) diff --git a/helm/software/components/ng_kernel/nCicReduction.mli b/helm/software/components/ng_kernel/nCicReduction.mli index 56b8ee06c..4828fbc2b 100644 --- a/helm/software/components/ng_kernel/nCicReduction.mli +++ b/helm/software/components/ng_kernel/nCicReduction.mli @@ -16,10 +16,12 @@ val whd : NCic.context -> NCic.term -> NCic.term +val set_get_relevance : + (subst:NCic.substitution -> + NCic.context -> NCic.term -> NCic.term list -> bool list) -> unit + val are_convertible : ?subst:NCic.substitution -> - (subst:NCic.substitution -> - NCic.context -> NCic.term -> NCic.term list -> bool list) -> NCic.context -> NCic.term -> NCic.term -> bool diff --git a/helm/software/components/ng_kernel/nCicSubstitution.ml b/helm/software/components/ng_kernel/nCicSubstitution.ml index 1e3856fff..240dd0b27 100644 --- a/helm/software/components/ng_kernel/nCicSubstitution.ml +++ b/helm/software/components/ng_kernel/nCicSubstitution.ml @@ -19,8 +19,7 @@ let debug_print = fun _ -> ();; let lift_from k n = let rec liftaux k = function | C.Rel m as t -> if m < k then t else C.Rel (m + n) - | C.Meta (i,(m,l)) as t when k <= m -> - if n = 0 then t else C.Meta (i,(m+n,l)) + | C.Meta (i,(m,l)) when k <= m+1 -> C.Meta (i,(m+n,l)) | C.Meta (_,(m,C.Irl l)) as t when k > l + m -> t | C.Meta (i,(m,l)) -> let lctx = NCicUtils.expand_local_context l in @@ -36,6 +35,7 @@ let lift ?(from=1) n t = else lift_from from n t ;; + (* subst t1 t2 *) (* substitutes [t1] for [Rel 1] in [t2] *) (* if avoid_beta_redexes is true (default: false) no new beta redexes *) diff --git a/helm/software/components/ng_kernel/nCicTypeChecker.ml b/helm/software/components/ng_kernel/nCicTypeChecker.ml index cf445a8f0..806238ce3 100644 --- a/helm/software/components/ng_kernel/nCicTypeChecker.ml +++ b/helm/software/components/ng_kernel/nCicTypeChecker.ml @@ -389,7 +389,7 @@ let rec typeof ~subst ~metasenv context term = | C.LetIn (n,ty,t,bo) -> let ty_t = typeof_aux context t in let _ = typeof_aux context ty in - if not (R.are_convertible ~subst get_relevance context ty_t ty) then + if not (R.are_convertible ~subst context ty_t ty) then raise (TypeCheckerFailure (lazy (Printf.sprintf @@ -460,7 +460,7 @@ let rec typeof ~subst ~metasenv context term = let ty_branch = type_of_branch ~subst context leftno outtype cons ty_cons 0 in - j+1, R.are_convertible ~subst get_relevance context ty_p ty_branch, + j+1, R.are_convertible ~subst context ty_p ty_branch, ty_p, ty_branch else j,false,old_p_ty,old_exp_p_ty @@ -522,7 +522,7 @@ let rec typeof ~subst ~metasenv context term = (_,C.Decl t1), (_,C.Decl t2) | (_,C.Def (t1,_)), (_,C.Def (t2,_)) | (_,C.Def (_,t1)), (_,C.Decl t2) -> - if not (R.are_convertible ~subst get_relevance tl t1 t2) then + if not (R.are_convertible ~subst tl t1 t2) then raise (TypeCheckerFailure (lazy (Printf.sprintf @@ -573,7 +573,7 @@ let rec typeof ~subst ~metasenv context term = with Failure _ -> t) | _ -> t in - if not (R.are_convertible ~subst get_relevance context optimized_t ct) + if not (R.are_convertible ~subst context optimized_t ct) then raise (TypeCheckerFailure @@ -584,7 +584,7 @@ let rec typeof ~subst ~metasenv context term = (PP.ppterm ~subst ~metasenv ~context t)))) | t, (_,C.Decl ct) -> let type_t = typeof_aux context t in - if not (R.are_convertible ~subst get_relevance context type_t ct) then + if not (R.are_convertible ~subst context type_t ct) then raise (TypeCheckerFailure (lazy (Printf.sprintf ("Not well typed metavariable local context: "^^ @@ -609,7 +609,7 @@ let rec typeof ~subst ~metasenv context term = let arity2 = R.whd ~subst context arity2 in match arity1,arity2 with | C.Prod (name,so1,de1), C.Prod (_,so2,de2) -> - if not (R.are_convertible ~subst get_relevance context so1 so2) then + if not (R.are_convertible ~subst context so1 so2) then raise (TypeCheckerFailure (lazy (Printf.sprintf "In outtype: expected %s, found %s" (PP.ppterm ~subst ~metasenv ~context so1) @@ -618,7 +618,7 @@ let rec typeof ~subst ~metasenv context term = aux ((name, C.Decl so1)::context) (mkapp (S.lift 1 ind) (C.Rel 1)) de1 de2 | C.Sort _, C.Prod (name,so,ta) -> - if not (R.are_convertible ~subst get_relevance context so ind) then + if not (R.are_convertible ~subst context so ind) then raise (TypeCheckerFailure (lazy (Printf.sprintf "In outtype: expected %s, found %s" (PP.ppterm ~subst ~metasenv ~context ind) @@ -659,7 +659,7 @@ and eat_prods ~subst ~metasenv context he ty_he args_with_ty = | (arg, ty_arg)::tl -> match R.whd ~subst context ty_he with | C.Prod (_,s,t) -> - if R.are_convertible ~subst get_relevance context ty_arg s then + if R.are_convertible ~subst context ty_arg s then aux (S.subst ~avoid_beta_redexes:true arg t) tl else raise @@ -736,11 +736,11 @@ and check_mutual_inductive_defs uri ~metasenv ~subst leftno tyl = let convertible = match item1,item2 with (n1,C.Decl ty1),(n2,C.Decl ty2) -> - n1 = n2 && R.are_convertible ~subst get_relevance context ty1 ty2 + n1 = n2 && R.are_convertible ~subst context ty1 ty2 | (n1,C.Def (bo1,ty1)),(n2,C.Def (bo2,ty2)) -> n1 = n2 - && R.are_convertible ~subst get_relevance context ty1 ty2 - && R.are_convertible ~subst get_relevance context bo1 bo2 + && R.are_convertible ~subst context ty1 ty2 + && R.are_convertible ~subst context bo1 bo2 | _,_ -> false in if not convertible then @@ -1120,7 +1120,7 @@ let typecheck_context ~metasenv ~subst context = | name,C.Def (te,ty) -> ignore (typeof ~metasenv ~subst:[] context ty); let ty' = typeof ~metasenv ~subst:[] context te in - if not (R.are_convertible ~subst get_relevance context ty' ty) then + if not (R.are_convertible ~subst context ty' ty) then raise (AssertFailure (lazy (Printf.sprintf ( "the type of the definiens for %s in the context is not "^^ "convertible with the declared one.\n"^^ @@ -1158,7 +1158,7 @@ let typecheck_subst ~metasenv subst = typecheck_context ~metasenv ~subst context; ignore (typeof ~metasenv ~subst context ty); let ty' = typeof ~metasenv ~subst context bo in - if not (R.are_convertible ~subst get_relevance context ty' ty) then + if not (R.are_convertible ~subst context ty' ty) then raise (AssertFailure (lazy (Printf.sprintf ( "the type of the definiens for %d in the substitution is not "^^ "convertible with the declared one.\n"^^ @@ -1179,7 +1179,7 @@ let typecheck_obj (uri,_height,metasenv,subst,kind) = | C.Constant (relevance,_,Some te,ty,_) -> let _ = typeof ~subst ~metasenv [] ty in let ty_te = typeof ~subst ~metasenv [] te in - if not (R.are_convertible ~subst get_relevance [] ty_te ty) then + if not (R.are_convertible ~subst [] ty_te ty) then raise (TypeCheckerFailure (lazy (Printf.sprintf ( "the type of the body is not convertible with the declared one.\n"^^ "inferred type:\n%s\nexpected type:\n%s") @@ -1211,7 +1211,7 @@ let typecheck_obj (uri,_height,metasenv,subst,kind) = in List.iter2 (fun (_,_,x,ty,_) bo -> let ty_bo = typeof ~subst ~metasenv types bo in - if not (R.are_convertible ~subst get_relevance types ty_bo ty) + if not (R.are_convertible ~subst types ty_bo ty) then raise (TypeCheckerFailure (lazy ("(Co)Fix: ill-typed bodies"))) else if inductive then begin @@ -1287,4 +1287,6 @@ E.set_typecheck_obj typecheck_obj obj) ;; +let _ = NCicReduction.set_get_relevance get_relevance;; + (* EOF *) diff --git a/helm/software/components/ng_kernel/rt.ml b/helm/software/components/ng_kernel/rt.ml index 3843d5a78..997bc2e3c 100644 --- a/helm/software/components/ng_kernel/rt.ml +++ b/helm/software/components/ng_kernel/rt.ml @@ -14,7 +14,6 @@ let _ = Helm_registry.load_from "conf.xml"; CicParser.impredicative_set := false; - NCicPp.set_ppterm NCicPp.trivial_pp_term; let u = UriManager.uri_of_string Sys.argv.(1) in let o, _ = CicEnvironment.get_obj CicUniv.oblivion_ugraph u in prerr_endline "VECCHIO"; diff --git a/helm/software/components/ng_refiner/check.ml b/helm/software/components/ng_refiner/check.ml index 79ed2f037..0f92a18a3 100644 --- a/helm/software/components/ng_refiner/check.ml +++ b/helm/software/components/ng_refiner/check.ml @@ -213,15 +213,17 @@ let _ = match ity with | NCic.Appl [eq;t;a;b] -> NCic.Appl [eq;t;NCicReduction.whd ~delta:0 ctx a;b] - | t -> t + | t -> NCicReduction.whd ~delta:0 ctx t in +(* prerr_endline (Printf.sprintf "%s == %s" (NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx ity) (NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx sty)); +*) let metasenv, subst = try - prerr_endline ("INIZIO: " ^ NUri.string_of_uri u); +(* prerr_endline ("INIZIO: " ^ NUri.string_of_uri u); *) NCicUnification.unify menv [] ctx ity sty with | NCicUnification.Uncertain msg @@ -234,9 +236,9 @@ let _ = (NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx ity) (NCicPp.ppterm ~metasenv:menv ~subst:[] ~context:ctx sty)); [], [] + | Sys.Break -> [],[] in - if (NCicReduction.are_convertible - ~subst (fun ~subst:_ _ _ _ ->[]) ctx ity sty) + if (NCicReduction.are_convertible ~subst ctx ity sty) then prerr_endline ("OK: " ^ NUri.string_of_uri u) else diff --git a/helm/software/components/ng_refiner/nCicUnification.ml b/helm/software/components/ng_refiner/nCicUnification.ml index 51ea8809b..99286591d 100644 --- a/helm/software/components/ng_refiner/nCicUnification.ml +++ b/helm/software/components/ng_refiner/nCicUnification.ml @@ -72,7 +72,12 @@ let indent = ref "";; let inside c = indent := !indent ^ String.make 1 c;; let outside () = indent := String.sub !indent 0 (String.length !indent -1);; -let pp s = prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ s);; +(* +let pp s = + prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ s);; +*) + +let pp _ = ();; let rec beta_expand num test_eq_only swap metasenv subst context t arg = let rec aux (n,context,test_eq_only as k) (metasenv, subst as acc) t' = @@ -119,7 +124,7 @@ let rec beta_expand num test_eq_only swap metasenv subst context t arg = and beta_expand_many test_equality_only swap metasenv subst context t args = (*D*) inside 'B'; try let rc = pp (String.concat ", " (List.map (NCicPp.ppterm ~metasenv ~subst ~context) - args) ^ " in " ^ NCicPp.ppterm ~metasenv ~subst ~context t); + args) ^ " ∈ " ^ NCicPp.ppterm ~metasenv ~subst ~context t); let _, subst, metasenv, hd = List.fold_right (fun arg (num,subst,metasenv,t) -> @@ -129,6 +134,8 @@ and beta_expand_many test_equality_only swap metasenv subst context t args = num+1,subst,metasenv,t) args (1,subst,metasenv,t) in + pp ("Head syntesized by b-exp: " ^ + NCicPp.ppterm ~metasenv ~subst ~context hd); metasenv, subst, hd (*D*) in outside (); rc with exn -> outside (); raise exn @@ -151,7 +158,9 @@ and instantiate test_eq_only metasenv subst context n lc t swap = ^ NCicPp.ppterm ~metasenv ~subst ~context ty_t); let metasenv, subst = unify test_eq_only metasenv subst context lty ty_t in let (metasenv, subst), t = - NCicMetaSubst.delift metasenv subst context n lc t + try NCicMetaSubst.delift metasenv subst context n lc t + with NCicMetaSubst.Uncertain msg -> raise (Uncertain msg) + | NCicMetaSubst.MetaSubstFailure msg -> raise (UnificationFailure msg) in (* Unifying the types may have already instantiated n. *) try @@ -360,29 +369,41 @@ and unify test_eq_only metasenv subst context t1 t2 = | _ -> raise (uncert_exc metasenv subst context t1 t2) (*D*) in outside(); rc with exn -> outside (); raise exn in - let height_of is_whd = function + let height_of = function | NCic.Const (Ref.Ref (_,Ref.Def h)) | NCic.Const (Ref.Ref (_,Ref.Fix (_,_,h))) | NCic.Appl(NCic.Const(Ref.Ref(_,Ref.Def h))::_) | NCic.Appl(NCic.Const(Ref.Ref(_,Ref.Fix (_,_,h)))::_) -> h, false - | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> max_int, true -(* | NCic.Rel _ -> 1, WRONG *) - | _ when is_whd -> 0, false - | _ -> max_int, false + | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> 0, true + | _ -> 0, false in - let small_delta_step is_whd (_,_,t1,_ as m1) (_,_,t2,_ as m2) = - let h1, flex1 = height_of is_whd t1 in - let h2, flex2 = height_of is_whd t2 in - let delta = if h1 = h2 then max 0 (h1 -1) else min h1 h2 in - NCicReduction.reduce_machine ~delta ~subst context m1, - NCicReduction.reduce_machine ~delta ~subst context m2, - if is_whd && flex1 && flex2 then 0 else delta + let put_in_whd m1 m2 = + NCicReduction.reduce_machine ~delta:max_int ~subst context m1, + NCicReduction.reduce_machine ~delta:max_int ~subst context m2, + false (* not in normal form *) + in + let small_delta_step (_,_,t1,_ as m1) (_,_,t2,_ as m2) = + let h1, flex1 = height_of t1 in + let h2, flex2 = height_of t2 in + let delta = + if flex1 then max 0 (h2 - 1) else + if flex2 then max 0 (h1 - 1) else + if h1 = h2 then max 0 (h1 -1) else min h1 h2 + in + pp ("DELTA STEP TO: " ^ string_of_int delta); + let m1' = NCicReduction.reduce_machine ~delta ~subst context m1 in + let m2' = NCicReduction.reduce_machine ~delta ~subst context m2 in + m1', m2', (m1' == m1 && m2' == m2) || delta = 0 + (* if we have as heads two Fix of height n>0, they may or may not + * reduce, depending on their rec argument... we thus check if + * something changed or not. This relies on the reduction machine + * preserving the original machine if it performs no action *) in let rec unif_machines metasenv subst = function - | ((k1,e1,t1,s1 as m1),(k2,e2,t2,s2 as m2),delta) -> + | ((k1,e1,t1,s1 as m1),(k2,e2,t2,s2 as m2),are_normal) -> (*D*) inside 'M'; try let rc = - pp ((if delta > 100 then "∞" else string_of_int delta) ^ " " ^ + pp ((if are_normal then "*" else " ") ^ " " ^ NCicPp.ppterm ~metasenv ~subst ~context (NCicReduction.unwind m1) ^ " === " ^ NCicPp.ppterm ~metasenv ~subst ~context (NCicReduction.unwind m2)); @@ -394,8 +415,7 @@ and unify test_eq_only metasenv subst context t1 t2 = try let t1 = NCicReduction.from_stack t1 in let t2 = NCicReduction.from_stack t2 in - unif_machines metasenv subst - (small_delta_step true t1 t2) + unif_machines metasenv subst (put_in_whd t1 t2) with UnificationFailure _ | Uncertain _ when not b -> metasenv, subst in @@ -413,19 +433,19 @@ and unify test_eq_only metasenv subst context t1 t2 = (NCicReduction.unwind (k2,e2,t2,List.rev l2)) in try check_stack (List.rev s1) (List.rev s2) relevance (metasenv,subst) - with UnificationFailure _ | Uncertain _ when delta > 0 -> + with UnificationFailure _ | Uncertain _ when not are_normal -> (* let delta = delta - 1 in let red = NCicReduction.reduce_machine ~delta ~subst context in *) - unif_machines metasenv subst (small_delta_step true m1 m2) + unif_machines metasenv subst (small_delta_step m1 m2) (*D*) in outside(); rc with exn -> outside (); raise exn in try fo_unif test_eq_only metasenv subst t1 t2 with UnificationFailure msg | Uncertain msg as exn -> try unif_machines metasenv subst - (small_delta_step false (0,[],t1,[]) (0,[],t2,[])) + (put_in_whd (0,[],t1,[]) (0,[],t2,[])) with | UnificationFailure _ -> raise (UnificationFailure msg) | Uncertain _ -> raise exn