type binder_type =
- Declaration
- | Definition
+ Declaration of Cic.name * Cic.term
+ | Definition of Cic.name * Cic.term
;;
type metasenv = (int * Cic.term) list;;
-type context = (binder_type * Cic.name * Cic.term) list;;
+type named_context = binder_type list;;
-type sequent = context * Cic.term;;
+type sequent = named_context * Cic.term;;
let proof =
ref (None : (UriManager.uri * metasenv * Cic.term * Cic.term) option)
exception NotImplemented
-(*CSC: Funzione che deve sparire!!! *)
-let cic_context_of_context =
+let cic_context_of_named_context =
List.map
(function
- Declaration,_,t -> t
- | Definition,_,_ -> raise NotImplemented
+ Declaration (_,t) -> Cic.Decl t
+ | Definition (_,t) -> Cic.Def t
)
;;
+(* refine_meta_with_brand_new_metasenv meta term apply_subst_replacing *)
+(* newmetasenv *)
+(* This (heavy) function must be called when a tactic can instantiate old *)
+(* metavariables (i.e. existential variables). It substitues the metasenv *)
+(* of the proof with the result of removing [meta] from the domain of *)
+(* [newmetasenv]. Then it replaces Cic.Meta [meta] with [term] everywhere *)
+(* in the current proof. Finally it applies [apply_subst_replacing] to *)
+(* current proof. *)
+(*CSC: A questo punto perche' passare un bo' gia' istantiato, se tanto poi *)
+(*CSC: ci ripasso sopra apply_subst!!! *)
+(*CSC: Inoltre, potrebbe essere questa funzione ad applicare apply_subst a *)
+(*CSC: newmetasenv!!! *)
+let refine_meta_with_brand_new_metasenv meta term apply_subst_replacing
+ newmetasenv
+=
+ let (uri,bo,ty) =
+ match !proof with
+ None -> assert false
+ | Some (uri,_,bo,ty) -> uri,bo,ty
+ in
+ let subst_in t =
+ ProofEngineReduction.replace ~what:(Cic.Meta meta) ~with_what:term ~where:t
+ in
+ let bo' = apply_subst_replacing (subst_in bo) in
+ let metasenv' = List.remove_assoc meta newmetasenv in
+ proof := Some (uri,metasenv',bo',ty)
+;;
+
let refine_meta meta term newmetasenv =
let (uri,metasenv,bo,ty) =
match !proof with
None -> assert false
| Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
in
- let metasenv' = newmetasenv @ (List.remove_assoc meta metasenv) in
- let rec aux =
- let module C = Cic in
- function
- C.Rel _ as t -> t
- | C.Var _ as t -> t
- | C.Meta meta' when meta=meta' -> term
- | C.Meta _ as t -> t
- | C.Sort _ as t -> t
- | C.Implicit as t -> t
- | C.Cast (te,ty) -> C.Cast (aux te, aux ty)
- | C.Prod (n,s,t) -> C.Prod (n, aux s, aux t)
- | C.Lambda (n,s,t) -> C.Lambda (n, aux s, aux t)
- | C.LetIn (n,s,t) -> C.LetIn (n, aux s, aux t)
- | C.Appl l -> C.Appl (List.map aux l)
- | C.Const _ as t -> t
- | C.Abst _ as t -> t
- | C.MutInd _ as t -> t
- | C.MutConstruct _ as t -> t
- | C.MutCase (sp,cookingsno,i,outt,t,pl) ->
- C.MutCase (sp,cookingsno,i,aux outt, aux t,
- List.map aux pl)
- | C.Fix (i,fl) ->
- let substitutedfl =
- List.map
- (fun (name,i,ty,bo) -> (name, i, aux ty, aux bo))
- fl
- in
- C.Fix (i, substitutedfl)
- | C.CoFix (i,fl) ->
- let substitutedfl =
- List.map
- (fun (name,ty,bo) -> (name, aux ty, aux bo))
- fl
- in
- C.CoFix (i, substitutedfl)
+ let subst_in t =
+ ProofEngineReduction.replace ~what:(Cic.Meta meta) ~with_what:term ~where:t
in
- let metasenv'' = List.map (function i,ty -> i,(aux ty)) metasenv' in
- let bo' = aux bo in
- proof := Some (uri,metasenv'',bo',ty)
+ let metasenv' = newmetasenv @ (List.remove_assoc meta metasenv) in
+ let metasenv'' = List.map (function i,ty -> i,(subst_in ty)) metasenv' in
+ let bo' = subst_in bo in
+ proof := Some (uri,metasenv'',bo',ty)
;;
-(* Returns the first meta whose number is above the number of the higher meta. *)
+(* Returns the first meta whose number is above the *)
+(* number of the higher meta. *)
let new_meta () =
let metasenv =
match !proof with
exception Fail of string;;
+(*CSC: generatore di nomi? Chiedere il nome? *)
+let fresh_name =
+ let next_fresh_index = ref 0
+in
+ function () ->
+ incr next_fresh_index ;
+ "fresh_name" ^ string_of_int !next_fresh_index
+;;
+
+(* lambda_abstract newmeta ty *)
+(* returns a triple [bo],[context],[ty'] where *)
+(* [ty] = Pi/LetIn [context].[ty'] ([context] is a vector!) *)
+(* and [bo] = Lambda/LetIn [context].(Meta [newmeta]) *)
+(* So, lambda_abstract is the core of the implementation of *)
+(* the Intros tactic. *)
+let lambda_abstract newmeta ty =
+ let module C = Cic in
+ let rec collect_context =
+ function
+ C.Cast (te,_) -> collect_context te
+ | C.Prod (n,s,t) ->
+ let (ctx,ty,bo) = collect_context t in
+ let n' =
+ match n with
+ C.Name _ -> n
+(*CSC: generatore di nomi? Chiedere il nome? *)
+ | C.Anonimous -> C.Name (fresh_name ())
+ in
+ ((Declaration (n',s))::ctx,ty,C.Lambda(n',s,bo))
+ | C.LetIn (n,s,t) ->
+ let (ctx,ty,bo) = collect_context t in
+ ((Definition (n,s))::ctx,ty,C.LetIn(n,s,bo))
+ | _ as t -> [], t, (C.Meta newmeta)
+ in
+ let revcontext,ty',bo = collect_context ty in
+ bo,(List.rev revcontext),ty'
+;;
+
let intros () =
let module C = Cic in
let module R = CicReduction in
| Some (metano,(context,ty)) -> metano,context,ty
in
let newmeta = new_meta () in
- let rec collect_context =
- function
- C.Cast (te,_) -> collect_context te
- | C.Prod (n,s,t) ->
- let (ctx,ty,bo) = collect_context t in
- let n' =
- match n with
- C.Name _ -> n
-(*CSC: generatore di nomi? Chiedere il nome? *)
- | C.Anonimous -> C.Name "fresh_name"
- in
- ((Declaration,n',s)::ctx,ty,C.Lambda(n',s,bo))
- | C.LetIn (n,s,t) ->
- let (ctx,ty,bo) = collect_context t in
- ((Definition,n,s)::ctx,ty,C.LetIn(n,s,bo))
- | _ as t -> [], t, (C.Meta newmeta)
- in
- let revcontext',ty',bo' = collect_context ty in
- let context'' = (List.rev revcontext') @ context in
+ let (bo',newcontext,ty') = lambda_abstract newmeta ty in
+ let context'' = newcontext @ context in
refine_meta metano bo' [newmeta,ty'] ;
goal := Some (newmeta,(context'',ty'))
;;
(* Invariant: context is the actual context of the meta in the proof *)
metano,context,ty
in
- (*CSC: deve sparire! *)
- let context = cic_context_of_context context in
- if R.are_convertible (T.type_of_aux' metasenv context bo) ty then
+ let context = cic_context_of_named_context context in
+ if R.are_convertible context (T.type_of_aux' metasenv context bo) ty then
begin
refine_meta metano bo [] ;
goal := None
raise (Fail "The type of the provided term is not the one expected.")
;;
-let fix_andreas_meta mgu mgut =
- let mgul = Array.to_list mgu in
- let mgutl = Array.to_list mgut in
- let applymetas_to_metas =
- let newmeta = new_meta () in
- (* WARNING: here we are using the invariant that above the most *)
- (* recente new_meta() there are no used metas. *)
- Array.init (List.length mgul) (function i -> newmeta + i) in
- (* WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *)
- (* Here we assume that either a META has been instantiated with *)
- (* a close term or with itself. *)
- let uninstantiatedmetas =
- List.fold_right2
- (fun bo ty newmetas ->
- let module C = Cic in
- match bo with
- Cic.Meta i ->
- let newmeta = applymetas_to_metas.(i) in
- (*CSC: se ty contiene metas, queste hanno il numero errato!!! *)
- let ty_with_newmetas =
- (* Substitues (META n) with (META (applymetas_to_metas.(n))) *)
- let rec aux =
- function
- C.Rel _
- | C.Var _ as t -> t
- | C.Meta n -> C.Meta (applymetas_to_metas.(n))
- | C.Sort _
- | C.Implicit as t -> t
- | C.Cast (te,ty) -> C.Cast (aux te, aux ty)
- | C.Prod (n,s,t) -> C.Prod (n, aux s, aux t)
- | C.Lambda (n,s,t) -> C.Lambda (n, aux s, aux t)
- | C.LetIn (n,s,t) -> C.LetIn (n, aux s, aux t)
- | C.Appl l -> C.Appl (List.map aux l)
- | C.Const _ as t -> t
- | C.Abst _ -> assert false
- | C.MutInd _
- | C.MutConstruct _ as t -> t
- | C.MutCase (sp,cookingsno,i,outt,t,pl) ->
- C.MutCase (sp,cookingsno,i,aux outt, aux t,
- List.map aux pl)
- | C.Fix (i,fl) ->
- let substitutedfl =
- List.map
- (fun (name,i,ty,bo) -> (name, i, aux ty, aux bo))
- fl
- in
- C.Fix (i, substitutedfl)
- | C.CoFix (i,fl) ->
- let substitutedfl =
- List.map
- (fun (name,ty,bo) -> (name, aux ty, aux bo))
- fl
- in
- C.CoFix (i, substitutedfl)
- in
- aux ty
- in
- (newmeta,ty_with_newmetas)::newmetas
- | _ -> newmetas
- ) mgul mgutl []
+(*CSC: The call to the Intros tactic is embedded inside the code of the *)
+(*CSC: Elim tactic. Do we already need tacticals? *)
+(* Auxiliary function for apply: given a type (a backbone), it returns its *)
+(* head, a META environment in which there is new a META for each hypothesis,*)
+(* a list of arguments for the new applications and the indexes of the first *)
+(* and last new METAs introduced. The nth argument in the list of arguments *)
+(* is the nth new META lambda-abstracted as much as possible. Hence, this *)
+(* functions already provides the behaviour of Intros on the new goals. *)
+let new_metasenv_for_apply_intros ty =
+ let module C = Cic in
+ let module S = CicSubstitution in
+ let rec aux newmeta =
+ function
+ C.Cast (he,_) -> aux newmeta he
+ | C.Prod (_,s,t) ->
+ let newargument,newcontext,ty' = lambda_abstract newmeta s in
+ let (res,newmetasenv,arguments,lastmeta) =
+ aux (newmeta + 1) (S.subst newargument t)
+ in
+ res,(newmeta,ty')::newmetasenv,newargument::arguments,lastmeta
+ | t -> t,[],[],newmeta
in
- let mgul' =
- List.map
- (function
- Cic.Meta i -> Cic.Meta (applymetas_to_metas.(i))
- | _ as t -> t
- ) mgul
- in
- mgul',uninstantiatedmetas
+ let newmeta = new_meta () in
+ (* WARNING: here we are using the invariant that above the most *)
+ (* recente new_meta() there are no used metas. *)
+ let (res,newmetasenv,arguments,lastmeta) = aux newmeta ty in
+ res,newmetasenv,arguments,newmeta,lastmeta
+;;
+
+(* Auxiliary function for apply: given a type (a backbone), it returns its *)
+(* head, a META environment in which there is new a META for each hypothesis,*)
+(* a list of arguments for the new applications and the indexes of the first *)
+(* and last new METAs introduced. The nth argument in the list of arguments *)
+(* is just the nth new META. *)
+let new_metasenv_for_apply ty =
+ let module C = Cic in
+ let module S = CicSubstitution in
+ let rec aux newmeta =
+ function
+ C.Cast (he,_) -> aux newmeta he
+ | C.Prod (_,s,t) ->
+ let newargument = C.Meta newmeta in
+ let (res,newmetasenv,arguments,lastmeta) =
+ aux (newmeta + 1) (S.subst newargument t)
+ in
+ res,(newmeta,s)::newmetasenv,newargument::arguments,lastmeta
+ | t -> t,[],[],newmeta
+ in
+ let newmeta = new_meta () in
+ (* WARNING: here we are using the invariant that above the most *)
+ (* recente new_meta() there are no used metas. *)
+ let (res,newmetasenv,arguments,lastmeta) = aux newmeta ty in
+ res,newmetasenv,arguments,newmeta,lastmeta
+;;
+
+
+(*CSC: ma serve solamente la prima delle new_uninst e l'unione delle due!!! *)
+let classify_metas newmeta in_subst_domain apply_subst metasenv =
+ List.fold_right
+ (fun (i,ty) (old_uninst,new_uninst) ->
+ if in_subst_domain i then
+ old_uninst,new_uninst
+ else
+ let ty' = apply_subst ty in
+ if i < newmeta then
+ ((i,ty')::old_uninst),new_uninst
+ else
+ old_uninst,((i,ty')::new_uninst)
+ ) metasenv ([],[])
;;
(* The term bo must be closed in the current context *)
(* Invariant: context is the actual context of the meta in the proof *)
metano,context,ty
in
- (*CSC: deve sparire! *)
- let ciccontext = cic_context_of_context context in
- let mgu,mgut = CicUnification.apply metasenv ciccontext term ty in
- let mgul',uninstantiatedmetas = fix_andreas_meta mgu mgut in
- let bo' =
- if List.length mgul' = 0 then
- term
- else
- Cic.Appl (term::mgul')
- in
- refine_meta metano bo' uninstantiatedmetas ;
- match uninstantiatedmetas with
- (n,ty)::tl -> goal := Some (n,(context,ty))
- | [] -> goal := None
+ let ciccontext = cic_context_of_named_context context in
+ let termty = CicTypeChecker.type_of_aux' metasenv ciccontext term in
+ (* newmeta is the lowest index of the new metas introduced *)
+ let (consthead,newmetas,arguments,newmeta,_) =
+ new_metasenv_for_apply termty
+ in
+ let newmetasenv = newmetas@metasenv in
+ let subst = CicUnification.fo_unif newmetasenv ciccontext consthead ty in
+ let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
+ let apply_subst = CicUnification.apply_subst subst in
+(*CSC: estremamente inefficiente: fare una passata sola per rimpiazzarle tutte*)
+ let apply_subst_replacing t =
+ List.fold_left
+ (fun t (i,bo) ->
+ ProofEngineReduction.replace
+ ~what:(Cic.Meta i) ~with_what:bo ~where:t)
+ t subst
+ in
+ let old_uninstantiatedmetas,new_uninstantiatedmetas =
+ classify_metas newmeta in_subst_domain apply_subst newmetasenv
+ in
+ let bo' =
+ if List.length newmetas = 0 then
+ term
+ else
+ let arguments' = List.map apply_subst arguments in
+ Cic.Appl (term::arguments')
+ in
+ refine_meta_with_brand_new_metasenv metano bo' apply_subst_replacing
+ (new_uninstantiatedmetas@old_uninstantiatedmetas) ;
+ match new_uninstantiatedmetas with
+ [] -> goal := None
+ | (i,ty)::_ -> goal := Some (i,(context,ty))
;;
-
let eta_expand metasenv ciccontext t arg =
let module T = CicTypeChecker in
let module S = CicSubstitution in
exception NotTheRightEliminatorShape;;
exception NoHypothesesFound;;
-let elim term =
+let elim_intros term =
let module T = CicTypeChecker in
let module U = UriManager in
let module R = CicReduction in
(* Invariant: context is the actual context of the meta in the proof *)
metano,context,ty
in
- (*CSC: deve sparire! *)
- let ciccontext = cic_context_of_context context in
+ let ciccontext = cic_context_of_named_context context in
let termty = T.type_of_aux' metasenv ciccontext term in
let uri,cookingno,typeno,args =
match termty with
let ety =
T.type_of_aux' [] [] eliminator_ref
in
-
- let earity = CicUnification.get_arity ety in
- let mgu = Array.init earity (fun i -> (C.Meta i)) in
- let mgut = Array.make earity C.Implicit in
+ let (econclusion,newmetas,arguments,newmeta,lastmeta) =
+ new_metasenv_for_apply ety
+ in
(* Here we assume that we have only one inductive hypothesis to *)
(* eliminate and that it is the last hypothesis of the theorem. *)
(* A better approach would be fingering the hypotheses in some *)
(* way. *)
- let hypothesis_to_eliminate,econclusion =
- (* aux n h t *)
- (* traverses the backbone [t] looking for the last hypothesis *)
- (* and substituting Pi-abstractions with META declarations. *)
- (* [h] is the last hypothesis met up to now. [n] is the next *)
- (* unused META. *)
- let rec aux n h =
- function
- C.Prod (_,s,t) ->
- mgut.(n) <- s ;
- aux (n+1) (Some s) (CicSubstitution.subst (C.Meta n) t)
- | C.Cast (te,_) -> aux n h te
- | t -> match h with
- None -> raise NoHypothesesFound
- | Some h' -> h',t
- in
- aux 0 None ety
- in
-prerr_endline ("HTOELIM: " ^ CicPp.ppterm hypothesis_to_eliminate) ;
+ let meta_of_corpse = Cic.Meta (lastmeta - 1) in
+ let newmetasenv = newmetas @ metasenv in
prerr_endline ("ECONCLUSION: " ^ CicPp.ppterm econclusion) ;
flush stderr ;
- ignore (CicUnification.fo_unif_mgu 0 hypothesis_to_eliminate termty mgu) ;
- ignore (CicUnification.fo_unif_mgu 0 term (C.Meta (earity - 1)) mgu) ;
- let mgu = CicUnification.unwind mgu in
-prerr_endline "Dopo l'unwind dell'mgu"; flush stderr ;
- let mark = Array.make earity 1 in
- let ueconclusion =
- CicUnification.unwind_meta mgu mark econclusion
- in
+ let subst1 =
+ CicUnification.fo_unif newmetasenv ciccontext term meta_of_corpse
+ in
+ let ueconclusion = CicUnification.apply_subst subst1 econclusion in
prerr_endline ("ECONCLUSION DOPO UNWIND: " ^ CicPp.ppterm ueconclusion) ;
flush stderr ;
(* The conclusion of our elimination principle is *)
(* to refine the term. *)
let emeta, fargs =
match ueconclusion with
+(*CSC: Code to be used for Apply *)
C.Appl ((C.Meta emeta)::fargs) -> emeta,fargs
+ | C.Meta emeta -> emeta,[]
+(*CSC: Code to be used for ApplyIntros
+ C.Appl (he::fargs) ->
+ let rec find_head =
+ function
+ C.Meta emeta -> emeta
+ | C.Lambda (_,_,t) -> find_head t
+ | C.LetIn (_,_,t) -> find_head t
+ | _ ->raise NotTheRightEliminatorShape
+ in
+ find_head he,fargs
+*)
| _ -> raise NotTheRightEliminatorShape
in
+ let ty' = CicUnification.apply_subst subst1 ty in
let eta_expanded_ty =
-(*CSC: metasenv e ?????????????*)
- List.fold_left (eta_expand metasenv ciccontext) ty fargs
+ List.fold_left (eta_expand metasenv ciccontext) ty' fargs
in
-(*CSC: 0????????*)
prerr_endline ("ETAEXPANDEDTY:" ^ CicPp.ppterm eta_expanded_ty) ; flush stdout ;
- ignore (CicUnification.fo_unif_mgu 0 ueconclusion eta_expanded_ty mgu) ;
-prerr_endline "Dopo la seconda unificazione" ; flush stdout ;
- let mgu = CicUnification.unwind mgu in
- print_endline "unwind"; flush stdout;
- (* When unwinding the META that corresponds to the elimination *)
- (* predicate (which is emeta), we must also perform one-step *)
- (* beta-reduction. *)
- let mgut =
- let mark = Array.make (Array.length mgu) 1 in
- Array.map
- (CicUnification.unwind_meta_reducing mgu mark (Some emeta))
- mgut ;
+ let subst2 =
+(*CSC: passo newmetasenv, ma alcune variabili sono gia' state sostituite
+da subst1!!!! Dovrei rimuoverle o sono innocue?*)
+ CicUnification.fo_unif
+ newmetasenv ciccontext ueconclusion eta_expanded_ty
in
- print_endline "unwind_array"; flush stdout;
- let mgu' = Array.copy mgu in
- let mgut' = CicUnification.list_of_array mgut in
- print_endline "list"; flush stdout;
- Array.iteri
- (fun i ty ->
-prerr_endline ("META " ^ string_of_int i ^ ": " ^ CicPp.ppterm mgu'.(i) ^
- " == " ^ CicPp.ppterm ty) ; flush stderr ;
- let ty' =
- CicTypeChecker.type_of_aux' mgut' ciccontext mgu'.(i)
+prerr_endline "Dopo la seconda unificazione" ; flush stdout ;
+prerr_endline "unwind"; flush stderr;
+ let in_subst_domain i =
+ let eq_to_i = function (j,_) -> i=j in
+ List.exists eq_to_i subst1 ||
+ List.exists eq_to_i subst2
+ in
+ (* When unwinding the META that corresponds to the elimination *)
+ (* predicate (which is emeta), we must also perform one-step *)
+ (* beta-reduction. *)
+ let apply_subst t =
+ let t' = CicUnification.apply_subst subst1 t in
+ CicUnification.apply_subst_reducing
+ subst2 (Some (emeta,List.length fargs)) t'
+ in
+(*CSC: estremamente inefficiente: fare una passata sola per rimpiazzarle tutte*)
+ let apply_subst_replacing t =
+ let t' =
+ List.fold_left
+ (fun t (i,bo) ->
+ ProofEngineReduction.replace
+ ~what:(Cic.Meta i) ~with_what:bo ~where:t)
+ t subst1
+ in
+ List.fold_left
+ (fun t (i,bo) ->
+ ProofEngineReduction.replace
+ ~what:(Cic.Meta i) ~with_what:bo ~where:t)
+ t' subst2
+ in
+ let newmetasenv' =
+ List.map (function (i,ty) -> i, apply_subst ty) newmetasenv
+ in
+ let old_uninstantiatedmetas,new_uninstantiatedmetas =
+ classify_metas newmeta in_subst_domain apply_subst newmetasenv
in
- ignore (CicUnification.fo_unif_mgu 0 ty ty' mgu)
- ) mgut ;
- let mgu = CicUnification.unwind mgu in
- let mgut = CicUnification.unwind_array mgu mgut in
-prerr_endline "Dopo le unwind dell'mgut" ; flush stdout ;
- let mgul',uninstantiatedmetas = fix_andreas_meta mgu mgut in
-prerr_endline "Dopo il fissaggio" ; flush stdout ;
- let bo' = Cic.Appl (eliminator_ref::mgul') in
+ let arguments' = List.map apply_subst arguments in
+ let bo' = Cic.Appl (eliminator_ref::arguments') in
prerr_endline ("BODY': " ^ CicPp.ppterm bo') ; flush stdout ;
- refine_meta metano bo' uninstantiatedmetas ;
-prerr_endline "dopo refine meta" ; flush stdout ;
- match uninstantiatedmetas with
- (n,ty)::tl -> goal := Some (n,(context,ty))
- | [] -> goal := None
-;;
-
-let elim_intros term =
- elim term ;
- intros ()
+List.iter (function (i,t) -> prerr_endline ("?" ^ string_of_int i ^ ": " ^ CicPp.ppterm t)) (new_uninstantiatedmetas@old_uninstantiatedmetas) ; flush stderr ;
+ refine_meta_with_brand_new_metasenv metano bo'
+ apply_subst_replacing
+ (new_uninstantiatedmetas@old_uninstantiatedmetas) ;
+ match new_uninstantiatedmetas with
+ [] -> goal := None
+ | (i,ty)::_ -> goal := Some (i,(context,ty))
;;
let reduction_tactic reduction_function term =
None -> assert false
| Some (metano,(context,ty)) -> metano,context,ty
in
- let term' = reduction_function term in
+ let ciccontext = cic_context_of_named_context context in
+ let term' = reduction_function ciccontext term in
(* We don't know if [term] is a subterm of [ty] or a subterm of *)
(* the type of one metavariable. So we replace it everywhere. *)
(*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
(*CSC: che si guadagni nulla in fatto di efficienza. *)
let replace = ProofEngineReduction.replace ~what:term ~with_what:term' in
let ty' = replace ty in
- let context' = List.map (function (bt,n,t) -> bt,n,replace t) context in
+ let context' =
+ List.map
+ (function
+ Definition (n,t) -> Definition (n,replace t)
+ | Declaration (n,t) -> Declaration (n,replace t)
+ ) context
+ in
let metasenv' =
List.map
(function
;;
let reduction_tactic_in_scratch reduction_function ty term =
- let curi,metasenv,pbo,pty =
+ let metasenv =
match !proof with
- None -> assert false
- | Some (curi,metasenv,bo,ty) -> curi,metasenv,bo,ty
+ None -> []
+ | Some (_,metasenv,_,_) -> metasenv
in
- let (metano,context,_) =
+ let context =
match !goal with
- None -> assert false
- | Some (metano,(context,ty)) -> metano,context,ty
+ None -> []
+ | Some (_,(context,_)) -> context
in
- let term' = reduction_function term in
+ let ciccontext = cic_context_of_named_context context in
+ let term' = reduction_function ciccontext term in
ProofEngineReduction.replace ~what:term ~with_what:term' ~where:ty
;;
None -> assert false
| Some (metano,(context,ty)) -> metano,context,ty
in
- let term' = CicReduction.whd term in
+ let ciccontext = cic_context_of_named_context context in
+ let term' = CicReduction.whd ciccontext term in
(* We don't know if [term] is a subterm of [ty] or a subterm of *)
(* the type of one metavariable. So we replace it everywhere. *)
(*CSC: ma si potrebbe ovviare al problema. Ma non credo *)
(*CSC: che si guadagni nulla in fatto di efficienza. *)
let replace = ProofEngineReduction.replace ~what:term' ~with_what:term in
let ty' = replace ty in
- let context' = List.map (function (bt,n,t) -> bt,n,replace t) context in
+ let context' =
+ List.map
+ (function
+ Declaration (n,t) -> Declaration (n,replace t)
+ | Definition (n,t) -> Definition (n,replace t)
+ ) context
+ in
let metasenv' =
List.map
(function
refine_meta metano bo' [newmeta2,term; newmeta1,newmeta1ty];
goal :=
Some
- (newmeta1,((Declaration, C.Name "dummy_for_cut", term)::context,
+ (newmeta1,((Declaration (C.Name "dummy_for_cut", term))::context,
newmeta1ty))
;;
+let letin term =
+ let module C = Cic in
+ let curi,metasenv,pbo,pty =
+ match !proof with
+ None -> assert false
+ | Some (curi,metasenv,bo,ty) -> curi,metasenv,bo,ty
+ in
+ let (metano,context,ty) =
+ match !goal with
+ None -> assert false
+ | Some (metano,(context,ty)) -> metano,context,ty
+ in
+ let ciccontext = cic_context_of_named_context context in
+ let _ = CicTypeChecker.type_of_aux' metasenv ciccontext term in
+ let newmeta = new_meta () in
+ let newmetaty = CicSubstitution.lift 1 ty in
+ let bo' = C.LetIn (C.Name "dummy_for_letin",term,C.Meta newmeta) in
+ refine_meta metano bo' [newmeta,newmetaty];
+ goal :=
+ Some
+ (newmeta,
+ ((Definition (C.Name "dummy_for_letin", term))::context, newmetaty))
+;;
+
exception NotConvertible;;
(*CSC: Bug (or feature?). [input] is parsed in the context of the goal, *)
None -> assert false
| Some (metano,(context,ty)) -> metano,context,ty
in
- (*CSC: deve sparire! *)
- let ciccontext = cic_context_of_context context in
+ let ciccontext = cic_context_of_named_context context in
(* are_convertible works only on well-typed terms *)
ignore (CicTypeChecker.type_of_aux' metasenv ciccontext input) ;
- if CicReduction.are_convertible goal_input input then
+ if CicReduction.are_convertible ciccontext goal_input input then
begin
let ty' = ProofEngineReduction.replace goal_input input ty in
let metasenv' =