Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file LLProof_conv.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174(* This file is free software, part of Zipperposition. See file "license" for more details. *)openLogtkmoduleT=TypedSTermtypell_subst=(T.t,T.t)Var.Subst.tletsection=LLProof.sectionleterrorfmsg=Util.errorf~where:"llproof_conv"msgletconv_subst~ctx(p:Subst.Projection.t):ll_subst=List.fold_left(funlsubst(v,t)->letv=Type.cast_var_unsafevinletprefix=ifType.is_tType(HVar.tyv)then"A"else"X"inletv=Term.Conv.var_to_simple_var~prefixctxvinlett=Term.Conv.to_simple_termctx(Term.of_term_unsafet)inassert(not(Var.Subst.memlsubstv));Var.Subst.addlsubstvt)Var.Subst.empty(Subst.Projection.bindingsp)typestate={ctx:Term.Conv.ctx;tbl:LLProof.tProof.S.Tbl.t;}letopen_forall=T.unfold_binderBinder.Forallletrecconv_proofstp:LLProof.t=beginmatchProof.S.Tbl.getst.tblpwith|Somer->r|None->letres=conv_stepstpinProof.S.Tbl.addst.tblpres;resendandconv_stepstp=Util.debugf~section5"(@[llproof.conv.step@ %a@])"(funk->kProof.S.pp_notrec1p);letres=Proof.Result.to_form~ctx:st.ctx(Proof.S.resultp)inletvars,_=open_forallresin(* introduce local symbols for making proof checking locally ground.
Some variables are typed using other variables, so we
need to substitute eagerly *)letintros=letl=List.mapi(funiv->v,T.const~ty:(Var.tyv)(ID.makef"sk_%d"i))varsinletsubst=Var.Subst.of_listlinList.map(fun(_,c)->T.Subst.evalsubstc)lin(* convert result *)letres=matchProof.Step.kind@@Proof.S.steppwith|Proof.Inference(rule,tags)|Proof.Simplification(rule,tags)->letlocal_intros=refVar.Subst.emptyinletparents=List.map(conv_parentstresintroslocal_introstags)(Proof.Step.parents@@Proof.S.stepp)inletlocal_intros=Var.Subst.to_list!local_intros|>List.rev_mapsndinLLProof.inference~intros~local_intros~tags(T.rename_all_varsres)(Proof.Rule.namerule)parents|Proof.Esarule->letl=List.map(function|Proof.P_ofp->conv_proofstp|Proof.P_subst_->assertfalse)(Proof.Step.parents@@Proof.S.stepp)inLLProof.esa(T.rename_all_varsres)(Proof.Rule.namerule)l|Proof.Trivial->LLProof.trivialres|Proof.By_defid->LLProof.by_defidres|Proof.Define(id,_)->LLProof.defineidres|Proof.Intro(_,Proof.R_assert)->LLProof.assert_res|Proof.Intro(_,(Proof.R_goal|Proof.R_lemma))->LLProof.goalres|Proof.Intro(_,(Proof.R_def|Proof.R_decl))->LLProof.trivialresinUtil.debugf~section4"(@[llproof.conv.step.->@ :from %a@ :to %a@])"(funk->kProof.S.pp_notrec1pLLProof.ppres);res(* convert parent of the given result formula. Also make instantiations
explicit. *)andconv_parentststep_resintroslocal_introstags(parent:Proof.Parent.t):LLProof.parent=Util.debugf~section5"(@[llproof.conv_parent@ %a@])"(funk->kProof.pp_parentparent);(* rename variables of result of inference *)letvars_step_res,_=open_forallstep_resinifList.lengthintros<>List.lengthvars_step_resthen(errorf"length mismatch, cannot do intros@ :res %a@ :with [@[%a@]]"T.ppstep_res(Util.pp_list~sep:","T.pp)intros);letintro_subst=Var.Subst.of_list(List.combinevars_step_resintros)in(* build an instantiation step, if needed *)letprev_proof,p_instantiated_res=matchparentwith|Proof.P_ofp->letp_res=Proof.Result.to_form~ctx:st.ctx(Proof.S.resultp)inletp=conv_proofstpinp,p_res|Proof.P_subst(p,subst)->(* perform instantiation *)assert(not(Subst.Projection.is_emptysubst));(* instantiated result of [p] *)letp_instantiated_res,inst_subst=Proof.Result.to_form_subst~ctx:st.ctxsubst(Proof.S.resultp)inletp_res=Proof.Result.to_form~ctx:st.ctx(Proof.S.resultp)in(* convert [p] itself *)letp=conv_proofstpin(* find instantiation for [p] by looking at variables of [p_res] *)letinst:LLProof.inst=letvars_p,_=open_forallp_resinList.map(funv->beginmatchVar.Subst.findinst_substvwith|Somet->t|None->errorf"cannot find variable `%a`@ \
in inst-subst {%a}@ :inst-res %a@ :res %a@ \
:parent %a@ :intros [@[%a@]]"Var.pp_fullcv(Var.Subst.ppT.pp)inst_substT.ppp_instantiated_resT.ppstep_resProof.pp_parentparent(Util.pp_list~sep:","T.pp)introsend)vars_pinLLProof.instantiate~tagsp_instantiated_respinst,p_instantiated_resin(* now open foralls in [p_instantiated_res]
and find which variable of [intros] they rename into *)letinst_intros:LLProof.inst=letvars_instantiated,_=T.unfold_binderBinder.forallp_instantiated_resinList.map(funv->beginmatchVar.Subst.findintro_substvwith|Somet->t|None->beginmatchVar.Subst.find!local_introsvwith|Somet->t|None->(* introduce local_intro *)letc=ID.makef"sk_%d"(List.lengthintros+Var.Subst.size!local_intros)|>T.const~ty:(Var.tyv|>T.Subst.evalintro_subst)inlocal_intros:=Var.Subst.add!local_introsvc;Util.debugf~section5"(@[llproof.conv.add_local_intro@ %a := %a@ :p-instantiated `%a`@])"(funk->kVar.pp_fullcvT.ppcT.ppp_instantiated_res);cendend)vars_instantiatedinLLProof.p_instprev_proofinst_introsletconv(p:Proof.t):LLProof.t=letst={ctx=Term.Conv.create();tbl=Proof.S.Tbl.create32;}inconv_proofstp