12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openCErrorsopenUtilopenNamesopenConstropenContextmoduleNamedDecl=Context.Named.DeclarationmoduleESorts=structincludeEvd.MiniEConstr.ESortsletequalsigmas1s2=Sorts.equal(kindsigmas1)(kindsigmas2)letis_smallsigmas=Sorts.is_small(kindsigmas)letis_propsigmas=Sorts.is_prop(kindsigmas)letis_spropsigmas=Sorts.is_sprop(kindsigmas)letis_setsigmas=Sorts.is_set(kindsigmas)letprop=makeSorts.propletsprop=makeSorts.spropletset=makeSorts.setlettype1=makeSorts.type1letsupersigmas=make(Sorts.super(kindsigmas))letrelevance_of_sortsigmas=letr=Sorts.relevance_of_sort(unsafe_to_sortss)inUState.nf_relevance(Evd.evar_universe_contextsigma)rletfamilysigmas=Sorts.family(kindsigmas)endmoduleEInstance=structincludeEvd.MiniEConstr.EInstanceletequalsigmai1i2=Univ.Instance.equal(kindsigmai1)(kindsigmai2)endinclude(Evd.MiniEConstr:moduletypeofEvd.MiniEConstrwithmoduleESorts:=ESortsandmoduleEInstance:=EInstance)typetypes=ttypeconstr=ttypeexistential=tpexistentialtypecase_return=tpcase_returntypecase_branch=tpcase_branchtypecase_invert=tpcase_inverttypecase=(t,t,EInstance.t)pcasetypefixpoint=(t,t)pfixpointtypecofixpoint=(t,t)pcofixpointtypeunsafe_judgment=(constr,types)Environ.punsafe_judgmenttypeunsafe_type_judgment=(types,ESorts.t)Environ.punsafe_type_judgmenttypenamed_declaration=(constr,types)Context.Named.Declaration.pttyperel_declaration=(constr,types)Context.Rel.Declaration.pttypecompacted_declaration=(constr,types)Context.Compacted.Declaration.pttypenamed_context=(constr,types)Context.Named.pttypecompacted_context=compacted_declarationlisttyperel_context=(constr,types)Context.Rel.pttype'apuniverses='a*EInstance.tletin_punivsa=(a,EInstance.empty)letmkSProp=of_kind(Sort(ESorts.makeSorts.sprop))letmkProp=of_kind(Sort(ESorts.makeSorts.prop))letmkSet=of_kind(Sort(ESorts.makeSorts.set))letmkTypeu=of_kind(Sort(ESorts.make(Sorts.sort_of_univu)))letmkReln=of_kind(Reln)letmkVarid=of_kind(Varid)letmkMetan=of_kind(Metan)letmkEvare=of_kind(Evare)letmkSorts=of_kind(Sorts)letmkCast(b,k,t)=of_kind(Cast(b,k,t))letmkProd(na,t,u)=of_kind(Prod(na,t,u))letmkLambda(na,t,c)=of_kind(Lambda(na,t,c))letmkLetIn(na,b,t,c)=of_kind(LetIn(na,b,t,c))letmkApp(f,arg)=of_kind(App(f,arg))letmkConstUpc=of_kind(Constpc)letmkIndUpi=of_kind(Indpi)letmkConstructUpc=of_kind(Constructpc)letmkConstructUi((ind,u),i)=of_kind(Construct((ind,i),u))letmkCase(ci,u,pms,c,iv,r,p)=of_kind(Case(ci,u,pms,c,iv,r,p))letmkFixf=of_kind(Fixf)letmkCoFixf=of_kind(CoFixf)letmkProj(p,c)=of_kind(Proj(p,c))letmkArrowt1rt2=of_kind(Prod(make_annotAnonymousr,t1,t2))letmkArrowRt1t2=mkArrowt1Sorts.Relevantt2letmkInti=of_kind(Inti)letmkFloatf=of_kind(Floatf)letmkArray(u,t,def,ty)=of_kind(Array(u,t,def,ty))letmkRef(gr,u)=letopenGlobRefinmatchgrwith|ConstRefc->mkConstU(c,u)|IndRefind->mkIndU(ind,u)|ConstructRefc->mkConstructU(c,u)|VarRefx->mkVarxletmkLEvar=Evd.MiniEConstr.mkLEvarlettype1=mkSortESorts.type1letapplist(f,arg)=mkApp(f,Array.of_listarg)letapplistcfarg=mkApp(f,Array.of_listarg)letisRelsigmac=matchkindsigmacwithRel_->true|_->falseletisVarsigmac=matchkindsigmacwithVar_->true|_->falseletisIndsigmac=matchkindsigmacwithInd_->true|_->falseletisEvarsigmac=matchkindsigmacwithEvar_->true|_->falseletisMetasigmac=matchkindsigmacwithMeta_->true|_->falseletisSortsigmac=matchkindsigmacwithSort_->true|_->falseletisCastsigmac=matchkindsigmacwithCast_->true|_->falseletisAppsigmac=matchkindsigmacwithApp_->true|_->falseletisLambdasigmac=matchkindsigmacwithLambda_->true|_->falseletisLetInsigmac=matchkindsigmacwithLetIn_->true|_->falseletisProdsigmac=matchkindsigmacwithProd_->true|_->falseletisConstsigmac=matchkindsigmacwithConst_->true|_->falseletisConstructsigmac=matchkindsigmacwithConstruct_->true|_->falseletisFixsigmac=matchkindsigmacwithFix_->true|_->falseletisCoFixsigmac=matchkindsigmacwithCoFix_->true|_->falseletisCasesigmac=matchkindsigmacwithCase_->true|_->falseletisProjsigmac=matchkindsigmacwithProj_->true|_->falseletrecisTypesigmac=matchkindsigmacwith|Sorts->(matchESorts.kindsigmaswith|Sorts.Type_->true|_->false)|Cast(c,_,_)->isTypesigmac|_->falseletisVarIdsigmaidc=matchkindsigmacwithVarid'->Id.equalidid'|_->falseletisRelNsigmanc=matchkindsigmacwithReln'->Int.equalnn'|_->falseletisRefsigmac=matchkindsigmacwith|Const_|Ind_|Construct_|Var_->true|_->falseletisRefXenvsigmaxc=letopenGlobRefinmatchx,kindsigmacwith|ConstRefc,Const(c',_)->Environ.QConstant.equalenvcc'|IndRefi,Ind(i',_)->Environ.QInd.equalenvii'|ConstructRefi,Construct(i',_)->Environ.QConstruct.equalenvii'|VarRefid,Varid'->Id.equalidid'|_->falseletis_lib_refenvsigmaxc=matchCoqlib.lib_ref_optxwith|Somex->isRefXenvsigmaxc|None->falseletdestRelsigmac=matchkindsigmacwith|Relp->p|_->raiseDestKOletdestVarsigmac=matchkindsigmacwith|Varp->p|_->raiseDestKOletdestIndsigmac=matchkindsigmacwith|Indp->p|_->raiseDestKOletdestEvarsigmac=matchkindsigmacwith|Evarp->p|_->raiseDestKOletdestMetasigmac=matchkindsigmacwith|Metap->p|_->raiseDestKOletdestSortsigmac=matchkindsigmacwith|Sortp->p|_->raiseDestKOletdestCastsigmac=matchkindsigmacwith|Cast(c,k,t)->(c,k,t)|_->raiseDestKOletdestAppsigmac=matchkindsigmacwith|App(f,a)->(f,a)|_->raiseDestKOletdestLambdasigmac=matchkindsigmacwith|Lambda(na,t,c)->(na,t,c)|_->raiseDestKOletdestLetInsigmac=matchkindsigmacwith|LetIn(na,b,t,c)->(na,b,t,c)|_->raiseDestKOletdestProdsigmac=matchkindsigmacwith|Prod(na,t,c)->(na,t,c)|_->raiseDestKOletdestConstsigmac=matchkindsigmacwith|Constp->p|_->raiseDestKOletdestConstructsigmac=matchkindsigmacwith|Constructp->p|_->raiseDestKOletdestFixsigmac=matchkindsigmacwith|Fixp->p|_->raiseDestKOletdestCoFixsigmac=matchkindsigmacwith|CoFixp->p|_->raiseDestKOletdestCasesigmac=matchkindsigmacwith|Case(ci,u,pms,t,iv,c,p)->(ci,u,pms,t,iv,c,p)|_->raiseDestKOletdestProjsigmac=matchkindsigmacwith|Proj(p,c)->(p,c)|_->raiseDestKOletdestRefsigmac=letopenGlobRefinmatchkindsigmacwith|Varx->VarRefx,EInstance.empty|Const(c,u)->ConstRefc,u|Ind(ind,u)->IndRefind,u|Construct(c,u)->ConstructRefc,u|_->raiseDestKOletdecompose_appsigmac=matchkindsigmacwith|App(f,cl)->(f,cl)|_->(c,[||])letdecompose_app_listsigmac=matchkindsigmacwith|App(f,cl)->(f,Array.to_listcl)|_->(c,[])letdecompose_lambdasigmac=letreclamdec_reclc=matchkindsigmacwith|Lambda(x,t,c)->lamdec_rec((x,t)::l)c|Cast(c,_,_)->lamdec_reclc|_->l,cinlamdec_rec[]cletdecompose_lambda_declssigmac=letopenRel.Declarationinletreclamdec_reclc=matchkindsigmacwith|Lambda(x,t,c)->lamdec_rec(Context.Rel.add(LocalAssum(x,t))l)c|LetIn(x,b,t,c)->lamdec_rec(Context.Rel.add(LocalDef(x,b,t))l)c|Cast(c,_,_)->lamdec_reclc|_->l,cinlamdec_recContext.Rel.emptycletdecompose_lambda_n_assumsigmanc=letopenRel.Declarationinifn<0thenanomalyPp.(str"decompose_lambda_n_assum: integer parameter must be positive.");letreclamdec_reclnc=ifInt.equaln0thenl,celsematchkindsigmacwith|Lambda(x,t,c)->lamdec_rec(Context.Rel.add(LocalAssum(x,t))l)(n-1)c|LetIn(x,b,t,c)->lamdec_rec(Context.Rel.add(LocalDef(x,b,t))l)nc|Cast(c,_,_)->lamdec_reclnc|c->anomalyPp.(str"decompose_lambda_n_assum: not enough abstractions.")inlamdec_recContext.Rel.emptyncletdecompose_lambda_n_declssigman=letopenRel.Declarationinifn<0thenanomalyPp.(str"decompose_lambda_n_decls: integer parameter must be positive.");letreclamdec_reclnc=ifInt.equaln0thenl,celsematchkindsigmacwith|Lambda(x,t,c)->lamdec_rec(Context.Rel.add(LocalAssum(x,t))l)(n-1)c|LetIn(x,b,t,c)->lamdec_rec(Context.Rel.add(LocalDef(x,b,t))l)(n-1)c|Cast(c,_,_)->lamdec_reclnc|c->anomalyPp.(str"decompose_lambda_n_decls: not enough abstractions.")inlamdec_recContext.Rel.emptynletrecto_lambdasigmanprod=ifInt.equaln0thenprodelsematchkindsigmaprodwith|Prod(na,ty,bd)->mkLambda(na,ty,to_lambdasigma(n-1)bd)|Cast(c,_,_)->to_lambdasigmanc|_->anomalyPp.(str"Not enough products.")letdecompose_prodsigmac=letrecproddec_reclc=matchkindsigmacwith|Prod(x,t,c)->proddec_rec((x,t)::l)c|Cast(c,_,_)->proddec_reclc|_->l,cinproddec_rec[]cletdecompose_prod_declssigmac=letopenRel.Declarationinletrecproddec_reclc=matchkindsigmacwith|Prod(x,t,c)->proddec_rec(Context.Rel.add(LocalAssum(x,t))l)c|LetIn(x,b,t,c)->proddec_rec(Context.Rel.add(LocalDef(x,b,t))l)c|Cast(c,_,_)->proddec_reclc|_->l,cinproddec_recContext.Rel.emptycletdecompose_prod_n_declssigmanc=letopenRel.Declarationinifn<0thenanomalyPp.(str"decompose_prod_n_decls: integer parameter must be positive.");letrecprodec_reclnc=ifInt.equaln0thenl,celsematchkindsigmacwith|Prod(x,t,c)->prodec_rec(Context.Rel.add(LocalAssum(x,t))l)(n-1)c|LetIn(x,b,t,c)->prodec_rec(Context.Rel.add(LocalDef(x,b,t))l)(n-1)c|Cast(c,_,_)->prodec_reclnc|c->anomalyPp.(str"decompose_prod_n_decls: not enough assumptions.")inprodec_recContext.Rel.emptyncletprod_declssigmat=fst(decompose_prod_declssigmat)letexistential_type=Evd.existential_typeletliftnc=of_constr(Vars.liftn(unsafe_to_constrc))letof_branches:Constr.case_brancharray->case_brancharray=matchEvd.MiniEConstr.unsafe_eqwith|Refl->funx->xletunsafe_to_branches:case_brancharray->Constr.case_brancharray=matchEvd.MiniEConstr.unsafe_eqwith|Refl->funx->xletof_return:Constr.case_return->case_return=matchEvd.MiniEConstr.unsafe_eqwith|Refl->funx->xletunsafe_to_return:case_return->Constr.case_return=matchEvd.MiniEConstr.unsafe_eqwith|Refl->funx->xletmap_branchesfbr=letfc=unsafe_to_constr(f(of_constrc))inof_branches(Constr.map_branchesf(unsafe_to_branchesbr))letmap_return_predicatefp=letfc=unsafe_to_constr(f(of_constrc))inof_return(Constr.map_return_predicatef(unsafe_to_returnp))letmap_instancesigmafevkargs=letrecmapctxargs=matchctx,SList.viewargswith|[],None->SList.empty|decl::ctx,Some(Somec,rem)->letc'=fcinletrem'=mapctxreminifc'==c&&rem'==remthenargselseifConstr.isVarId(NamedDecl.get_iddecl)c'thenSList.defaultrem'elseSList.consc'rem'|decl::ctx,Some(None,rem)->letc=Constr.mkVar(NamedDecl.get_iddecl)inletc'=fcinletrem'=mapctxreminifc'==c&&rem'==remthenargselseSList.consc'rem'|[],Some_|_::_,None->assertfalseinletEvarInfoevi=Evd.findsigmaevkinletctx=Evd.evar_filtered_contexteviinmapctxargsletmapsigmafc=letfc=unsafe_to_constr(f(of_constrc))inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar(evk,args)->letargs'=map_instancesigmafevkargsinifargs'==argsthenof_constrcelseof_constr@@Constr.mkEvar(evk,args')|_->of_constr(Constr.mapfc)letmap_with_binderssigmagflc=letflc=unsafe_to_constr(fl(of_constrc))inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar(evk,args)->letargs'=map_instancesigma(func->flc)evkargsinifargs'==argsthenof_constrcelseof_constr@@Constr.mkEvar(evk,args')|_->of_constr(Constr.map_with_bindersgflc)letmap_existentialsigmaf((evk,args)asev:existential)=letfc=unsafe_to_constr(f(of_constrc))inletargs:Constr.tSList.t=matchEvd.MiniEConstr.unsafe_eqwithRefl->argsinletargs'=map_instancesigmafevkargsinifargs'==argsthenevelseletargs':tSList.t=matchEvd.MiniEConstr.unsafe_eqwithRefl->args'in(evk,args')letitersigmafc=letfc=f(of_constrc)inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar((evk,_)asev)->letargs=Evd.expand_existential0sigmaevinList.iter(func->fc)args|_->Constr.iterfcletexpand_caseenv_sigma(ci,u,pms,p,iv,c,bl)=letu=EInstance.unsafe_to_instanceuinletpms=unsafe_to_constr_arraypmsinletp=unsafe_to_returnpinletiv=unsafe_to_case_invertivinletc=unsafe_to_constrcinletbl=unsafe_to_branchesblinlet(ci,p,iv,c,bl)=Inductive.expand_caseenv(ci,u,pms,p,iv,c,bl)inletp=of_constrpinletc=of_constrcinletiv=of_case_invertivinletbl=of_constr_arrayblin(ci,p,iv,c,bl)letannotate_caseenvsigma(ci,u,pms,p,iv,c,blascase)=let(_,p,_,_,bl)=expand_caseenvsigmacaseinletp=(* Too bad we need to fetch this data in the environment, should be in the
case_info instead. *)let(_,mip)=Inductive.lookup_mind_specifenvci.ci_indindecompose_lambda_n_declssigma(mip.Declarations.mind_nrealdecls+1)pinletmk_brcn=decompose_lambda_n_declssigmancinletbl=Array.map2mk_brblci.ci_cstr_ndeclsin(ci,u,pms,p,iv,c,bl)letexpand_branchenv_sigmaupms(ind,i)(nas,_br)=letopenDeclarationsinletu=EInstance.unsafe_to_instanceuinletpms=unsafe_to_constr_arraypmsinlet(mib,mip)=Inductive.lookup_mind_specifenvindinletparamdecl=Vars.subst_instance_contextumib.mind_params_ctxtinletparamsubst=Vars.subst_of_rel_context_instanceparamdeclpmsinlet(ctx,_)=mip.mind_nf_lc.(i-1)inlet(ctx,_)=List.chopmip.mind_consnrealdecls.(i-1)ctxinletans=Inductive.instantiate_contextuparamsubstnasctxinletans:rel_context=matchEvd.MiniEConstr.unsafe_eqwithRefl->ansinansletcontract_caseenv_sigma(ci,p,iv,c,bl)=letp=unsafe_to_constrpinletiv=unsafe_to_case_invertivinletc=unsafe_to_constrcinletbl=unsafe_to_constr_arrayblinlet(ci,u,pms,p,iv,c,bl)=Inductive.contract_caseenv(ci,p,iv,c,bl)inletu=EInstance.makeuinletpms=of_constr_arraypmsinletp=of_returnpinletiv=of_case_invertivinletc=of_constrcinletbl=of_branchesblin(ci,u,pms,p,iv,c,bl)letiter_with_full_bindersenvsigmagfnc=letopenContext.Rel.Declarationinmatchkindsigmacwith|(Rel_|Meta_|Var_|Sort_|Const_|Ind_|Construct_|Int_|Float_)->()|Cast(c,_,t)->fnc;fnt|Prod(na,t,c)->fnt;f(g(LocalAssum(na,t))n)c|Lambda(na,t,c)->fnt;f(g(LocalAssum(na,t))n)c|LetIn(na,b,t,c)->fnb;fnt;f(g(LocalDef(na,b,t))n)c|App(c,l)->fnc;Array.Fun1.iterfnl|Evar((_,l)asev)->letl=Evd.expand_existentialsigmaevinList.iter(func->fnc)l|Case(ci,u,pms,p,iv,c,bl)->let(ci,_,pms,p,iv,c,bl)=annotate_caseenvsigma(ci,u,pms,p,iv,c,bl)inletf_ctx(ctx,c)=f(List.fold_rightgctxn)cinArray.Fun1.iterfnpms;f_ctxp;iter_invert(fn)iv;fnc;Array.iterf_ctxbl|Proj(p,c)->fnc|Fix(_,(lna,tl,bl))->Array.iter(fn)tl;letn'=Array.fold_left2_i(funinnat->g(LocalAssum(na,liftit))n)nlnatlinArray.iter(fn')bl|CoFix(_,(lna,tl,bl))->Array.iter(fn)tl;letn'=Array.fold_left2_i(funinnat->g(LocalAssum(na,liftit))n)nlnatlinArray.iter(fn')bl|Array(_u,t,def,ty)->Array.Fun1.iterfnt;fndef;fntyletiter_with_binderssigmagfnc=letflc=fl(of_constrc)inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar((evk,_)asev)->letargs=Evd.expand_existential0sigmaevinList.iter(func->fnc)args|_->Constr.iter_with_bindersgfncletfoldsigmafaccc=letfaccc=facc(of_constrc)inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar((evk,_)asev)->letargs=Evd.expand_existential0sigmaevinList.fold_leftfaccargs|_->Constr.foldfacccletfold_with_binderssigmagfeaccc=letfeaccc=feacc(of_constrc)inletc=unsafe_to_constr@@whd_evarsigmacinmatchConstr.kindcwith|Evar((evk,_)asev)->letargs=Evd.expand_existential0sigmaevinList.fold_left(funaccc->feaccc)accargs|_->Constr.fold_constr_with_bindersgfeacccletcompare_genkeq_insteq_sorteq_constreq_evarsnargsc1c2=(c1==c2)||Constr.compare_head_gen_withkkeq_insteq_sorteq_constreq_evarsnargsc1c2leteq_existentialsigmaeq(evk1,args1)(evk2,args2)=ifEvar.equalevk1evk2thenletargs1=Evd.expand_existentialsigma(evk1,args1)inletargs2=Evd.expand_existentialsigma(evk2,args2)inList.equaleqargs1args2elsefalseleteq_constrsigmac1c2=letkindc=kindsigmacinleteq_inst_i1i2=EInstance.equalsigmai1i2inleteq_sortss1s2=ESorts.equalsigmas1s2inleteq_existentialeqe1e2=eq_existentialsigma(eq0)e1e2inletreceq_constrnargsc1c2=compare_genkindeq_insteq_sorts(eq_existentialeq_constr)eq_constrnargsc1c2ineq_constr0c1c2leteq_constr_nounivssigmac1c2=letkindc=kindsigmacinleteq_existentialeqe1e2=eq_existentialsigma(eq0)e1e2inletreceq_constrnargsc1c2=compare_genkind(fun___->true)(fun__->true)(eq_existentialeq_constr)eq_constrnargsc1c2ineq_constr0c1c2letcompare_constrsigmacmpc1c2=letkindc=kindsigmacinleteq_inst_i1i2=EInstance.equalsigmai1i2inleteq_sortss1s2=ESorts.equalsigmas1s2inleteq_existentialeqe1e2=eq_existentialsigma(eq0)e1e2inletcmpnargsc1c2=cmpc1c2incompare_genkindeq_insteq_sorts(eq_existentialcmp)cmp0c1c2letcompare_cumulative_instancescv_pbnargs_okvariancesuu'cstrs=letopenUnivProbleminifnotnargs_okthenenforce_eq_instances_univsfalseuu'cstrselseletmakeu=Sorts.sort_of_univ@@Univ.Universe.makeuinCArray.fold_left3(funcstrsvuu'->letopenUniv.Varianceinmatchvwith|Irrelevant->Set.add(UWeak(u,u'))cstrs|Covariant->(matchcv_pbwith|Conversion.CONV->Set.add(UEq(makeu,makeu'))cstrs|Conversion.CUMUL->Set.add(ULe(makeu,makeu'))cstrs)|Invariant->Set.add(UEq(makeu,makeu'))cstrs)cstrsvariances(Univ.Instance.to_arrayu)(Univ.Instance.to_arrayu')letcmp_inductivescv_pb(mind,indasspec)nargsu1u2cstrs=letopenUnivProbleminmatchmind.Declarations.mind_variancewith|None->enforce_eq_instances_univsfalseu1u2cstrs|Somevariances->letnum_param_arity=Conversion.inductive_cumulativity_argumentsspecincompare_cumulative_instancescv_pb(Int.equalnum_param_aritynargs)variancesu1u2cstrsletcmp_constructors(mind,ind,cnsasspec)nargsu1u2cstrs=letopenUnivProbleminmatchmind.Declarations.mind_variancewith|None->enforce_eq_instances_univsfalseu1u2cstrs|Some_->letnum_cnstr_args=Conversion.constructor_cumulativity_argumentsspecinifnot(Int.equalnum_cnstr_argsnargs)thenenforce_eq_instances_univsfalseu1u2cstrselseArray.fold_left2(funcstrsu1u2->UnivProblem.(Set.add(UWeak(u1,u2))cstrs))cstrs(Univ.Instance.to_arrayu1)(Univ.Instance.to_arrayu2)leteq_universesenvsigmacstrscv_pbrefargsll'=ifEInstance.is_emptylthen(assert(EInstance.is_emptyl');true)elseletl=EInstance.kindsigmalandl'=EInstance.kindsigmal'inletopenGlobRefinletopenUnivProbleminmatchrefargswith|Some(ConstRefc,1)whenEnviron.is_array_typeenvc->cstrs:=compare_cumulative_instancescv_pbtrue[|Univ.Variance.Irrelevant|]ll'!cstrs;true|None|Some(ConstRef_,_)->cstrs:=enforce_eq_instances_univstruell'!cstrs;true|Some(VarRef_,_)->assertfalse(* variables don't have instances *)|Some(IndRefind,nargs)->letmind=Environ.lookup_mind(fstind)envincstrs:=cmp_inductivescv_pb(mind,sndind)nargsll'!cstrs;true|Some(ConstructRef((mi,ind),ctor),nargs)->letmind=Environ.lookup_mindmienvincstrs:=cmp_constructors(mind,ind,ctor)nargsll'!cstrs;truelettest_constr_universesenvsigmaleq?(nargs=0)mn=letopenUnivProbleminletkindc=kindsigmacinifm==nthenSomeSet.emptyelseletcstrs=refSet.emptyinletcv_pb=ifleqthenConversion.CUMULelseConversion.CONVinleteq_universesrefargsll'=eq_universesenvsigmacstrsConversion.CONVrefargsll'andleq_universesrefargsll'=eq_universesenvsigmacstrscv_pbrefargsll'inleteq_sortss1s2=lets1=ESorts.kindsigmas1inlets2=ESorts.kindsigmas2inifSorts.equals1s2thentrueelse(cstrs:=Set.add(UEq(s1,s2))!cstrs;true)inletleq_sortss1s2=lets1=ESorts.kindsigmas1inlets2=ESorts.kindsigmas2inifSorts.equals1s2thentrueelse(cstrs:=Set.add(ULe(s1,s2))!cstrs;true)inleteq_existentialeqe1e2=eq_existentialsigma(eq0)e1e2inletreceq_constr'nargsmn=compare_genkindeq_universeseq_sorts(eq_existentialeq_constr')eq_constr'nargsmninletres=ifleqthenletreccompare_leqnargsmn=Constr.compare_head_gen_leq_withkindkindleq_universesleq_sorts(eq_existentialeq_constr')eq_constr'leq_constr'nargsmnandleq_constr'nargsmn=m==n||compare_leqnargsmnincompare_leqnargsmnelseConstr.compare_head_gen_withkindkindeq_universeseq_sorts(eq_existentialeq_constr')eq_constr'nargsmninifresthenSome!cstrselseNoneleteq_constr_universesenvsigma?nargsmn=test_constr_universesenvsigmafalse?nargsmnletleq_constr_universesenvsigma?nargsmn=test_constr_universesenvsigmatrue?nargsmnletcompare_head_gen_projenvsigmaequeqseqeveqc'nargsmn=letkindc=kindsigmacinmatchkindm,kindnwith|Proj(p,c),App(f,args)|App(f,args),Proj(p,c)->(matchkindfwith|Const(p',u)whenEnviron.QConstant.equalenv(Projection.constantp)p'->letnpars=Projection.nparspinifArray.lengthargs==npars+1theneqc'0cargs.(npars)elsefalse|_->false)|_->Constr.compare_head_gen_withkindkindequeqseqeveqc'nargsmnleteq_constr_universes_projenvsigmamn=letopenUnivProbleminifm==nthenSomeSet.emptyelseletcstrs=refSet.emptyinleteq_universesrefll'=eq_universesenvsigmacstrsConversion.CONVrefll'inleteq_sortss1s2=lets1=ESorts.kindsigmas1inlets2=ESorts.kindsigmas2inifSorts.equals1s2thentrueelse(cstrs:=Set.add(UEq(s1,s2))!cstrs;true)inleteq_existentialeqe1e2=eq_existentialsigma(eq0)e1e2inletreceq_constr'nargsmn=m==n||compare_head_gen_projenvsigmaeq_universeseq_sorts(eq_existentialeq_constr')eq_constr'nargsmninletres=eq_constr'0mninifresthenSome!cstrselseNoneletuniverses_of_constrsigmac=letopenUnivinletrecauxsc=matchkindsigmacwith|Const(c,u)->Level.Set.foldLevel.Set.add(Instance.levels(EInstance.kindsigmau))s|Ind((mind,_),u)|Construct(((mind,_),_),u)->Level.Set.foldLevel.Set.add(Instance.levels(EInstance.kindsigmau))s|Sortu->letsort=ESorts.kindsigmauinifSorts.is_smallsortthenselseLevel.Set.foldLevel.Set.add(Sorts.levelssort)s|Evar(k,args)->letconcl=Evd.evar_concl(Evd.find_undefinedsigmak)infoldsigmaaux(auxsconcl)c|Array(u,_,_,_)->lets=Level.Set.foldLevel.Set.add(Instance.levels(EInstance.kindsigmau))sinfoldsigmaauxsc|Case(_,u,_,_,_,_,_)->lets=Level.Set.foldLevel.Set.add(Instance.levels(EInstance.kindsigmau))sinfoldsigmaauxsc|_->foldsigmaauxscinauxLevel.Set.emptycopenContextopenEnvironletcast_list:typeab.(a,b)eq->alist->blist=funReflx->xletcast_vect:typeab.(a,b)eq->aarray->barray=funReflx->xletcast_rel_decl:typeab.(a,b)eq->(a,a)Rel.Declaration.pt->(b,b)Rel.Declaration.pt=funReflx->xletcast_rel_context:typeab.(a,b)eq->(a,a)Rel.pt->(b,b)Rel.pt=funReflx->xletcast_rec_decl:typeab.(a,b)eq->(a,a)Constr.prec_declaration->(b,b)Constr.prec_declaration=funReflx->xletcast_named_decl:typeab.(a,b)eq->(a,a)Named.Declaration.pt->(b,b)Named.Declaration.pt=funReflx->xletcast_named_context:typeab.(a,b)eq->(a,a)Named.pt->(b,b)Named.pt=funReflx->xmoduleVars=structexceptionLocalOccurletto_constr=unsafe_to_constrletto_rel_decl=unsafe_to_rel_decltypeinstance=tarraytypeinstance_list=tlisttypesubstl=tlist(** Operations that commute with evar-normalization *)letlift=liftletliftnnmc=of_constr(Vars.liftnnm(to_constrc))letsubstnlsubstnc=of_constr(Vars.substnl(cast_listunsafe_eqsubst)n(to_constrc))letsubstlsubstc=of_constr(Vars.substl(cast_listunsafe_eqsubst)(to_constrc))letsubst1cr=of_constr(Vars.subst1(to_constrc)(to_constrr))letsubstnl_declsubstnd=of_rel_decl(Vars.substnl_decl(cast_listunsafe_eqsubst)n(to_rel_decld))letsubstl_declsubstd=of_rel_decl(Vars.substl_decl(cast_listunsafe_eqsubst)(to_rel_decld))letsubst1_declcd=of_rel_decl(Vars.subst1_decl(to_constrc)(to_rel_decld))typesubstituend=Vars.substituendletmake_substituendc=Vars.make_substituend(unsafe_to_constrc)letlift_substituendns=of_constr(Vars.lift_substituendns)letreplace_vars=replace_vars(* (subst_var str t) substitute (Var str) by (Rel 1) in t *)letsubst_varsigmastrt=replace_varssigma[(str,mkRel1)]t(* (subst_vars [id1;...;idn] t) substitute (Var idj) by (Rel j) in t *)letsubstn_varssigmapvarsc=let_,subst=List.fold_left(fun(n,l)var->((n+1),(var,mkReln)::l))(p,[])varsinreplace_varssigma(List.revsubst)cletsubst_varssigmasubstc=substn_varssigma1substcletsubst_univs_level_constrsubstc=of_constr(Vars.subst_univs_level_constrsubst(to_constrc))letsubst_instance_contextsubstctx=cast_rel_context(symunsafe_eq)(Vars.subst_instance_contextsubst(cast_rel_contextunsafe_eqctx))letsubst_instance_constrsubstc=of_constr(Vars.subst_instance_constrsubst(to_constrc))(** Operations that dot NOT commute with evar-normalization *)letnoccurnsigmanterm=letrecoccur_recnc=matchkindsigmacwith|Relm->ifInt.equalmnthenraiseLocalOccur|Evar(_,l)->SList.Skip.iter(func->occur_recnc)l|_->iter_with_binderssigmasuccoccur_recncintryoccur_recnterm;truewithLocalOccur->falseletnoccur_betweensigmanmterm=letrecoccur_recnc=matchkindsigmacwith|Relp->ifn<=p&&p<n+mthenraiseLocalOccur|Evar(_,l)->SList.Skip.iter(func->occur_recnc)l|_->iter_with_binderssigmasuccoccur_recncintryoccur_recnterm;truewithLocalOccur->falseletclosednsigmanc=letrecclosed_recnc=matchkindsigmacwith|Relm->ifm>nthenraiseLocalOccur|Evar(_,l)->SList.Skip.iter(func->closed_recnc)l|_->iter_with_binderssigmasuccclosed_recncintryclosed_recnc;truewithLocalOccur->falseletclosed0sigmac=closednsigma0cletsubst_of_rel_context_instancectxsubst=cast_list(symunsafe_eq)(Vars.subst_of_rel_context_instance(cast_rel_contextunsafe_eqctx)(cast_vectunsafe_eqsubst))letsubst_of_rel_context_instance_listctxsubst=cast_list(symunsafe_eq)(Vars.subst_of_rel_context_instance_list(cast_rel_contextunsafe_eqctx)(cast_listunsafe_eqsubst))letliftn_rel_contextnkctx=cast_rel_context(symunsafe_eq)(Vars.liftn_rel_contextnk(cast_rel_contextunsafe_eqctx))letlift_rel_contextnctx=cast_rel_context(symunsafe_eq)(Vars.lift_rel_contextn(cast_rel_contextunsafe_eqctx))letsubstnl_rel_contextsubstnctx=cast_rel_context(symunsafe_eq)(Vars.substnl_rel_context(cast_listunsafe_eqsubst)n(cast_rel_contextunsafe_eqctx))letsubstl_rel_contextsubstctx=cast_rel_context(symunsafe_eq)(Vars.substl_rel_context(cast_listunsafe_eqsubst)(cast_rel_contextunsafe_eqctx))letsmash_rel_contextctx=cast_rel_context(symunsafe_eq)(Vars.smash_rel_context(cast_rel_contextunsafe_eqctx))letesubst:(int->'a->t)->'aEsubst.subs->t->t=matchunsafe_eqwith|Refl->Vars.esubstendletrecisAritysigmac=matchkindsigmacwith|Prod(_,_,c)->isAritysigmac|LetIn(_,b,_,c)->isAritysigma(Vars.subst1bc)|Cast(c,_,_)->isAritysigmac|Sort_->true|_->falsetypearity=rel_context*ESorts.tletdestAritysigma=letopenContext.Rel.Declarationinletrecprodec_reclc=matchkindsigmacwith|Prod(x,t,c)->prodec_rec(LocalAssum(x,t)::l)c|LetIn(x,b,t,c)->prodec_rec(LocalDef(x,b,t)::l)c|Cast(c,_,_)->prodec_reclc|Sorts->l,s|_->anomaly~label:"destArity"(Pp.str"not an arity.")inprodec_rec[](* Constructs either [forall x:t, c] or [let x:=b:t in c] *)letmkProd_or_LetIndeclc=letopenContext.Rel.Declarationinmatchdeclwith|LocalAssum(na,t)->mkProd(na,t,c)|LocalDef(na,b,t)->mkLetIn(na,b,t,c)(* Constructs either [forall x:t, c] or [c] in which [x] is replaced by [b] *)letmkProd_wo_LetIndeclc=letopenContext.Rel.Declarationinmatchdeclwith|LocalAssum(na,t)->mkProd(na,t,c)|LocalDef(_,b,_)->Vars.subst1bcletmkLambda_or_LetIndeclc=letopenContext.Rel.Declarationinmatchdeclwith|LocalAssum(na,t)->mkLambda(na,t,c)|LocalDef(na,b,t)->mkLetIn(na,b,t,c)letmkLambda_wo_LetIndeclc=letopenContext.Rel.Declarationinmatchdeclwith|LocalAssum(na,t)->mkLambda(na,t,c)|LocalDef(_,b,_)->Vars.subst1bcletmkNamedProdsigmaidtypc=mkProd(map_annotName.mk_nameid,typ,Vars.subst_varsigmaid.binder_namec)letmkNamedLambdasigmaidtypc=mkLambda(map_annotName.mk_nameid,typ,Vars.subst_varsigmaid.binder_namec)letmkNamedLetInsigmaidc1tc2=mkLetIn(map_annotName.mk_nameid,c1,t,Vars.subst_varsigmaid.binder_namec2)letmkNamedProd_or_LetInsigmadeclc=letopenContext.Named.Declarationinmatchdeclwith|LocalAssum(id,t)->mkNamedProdsigmaidtc|LocalDef(id,b,t)->mkNamedLetInsigmaidbtcletmkNamedLambda_or_LetInsigmadeclc=letopenContext.Named.Declarationinmatchdeclwith|LocalAssum(id,t)->mkNamedLambdasigmaidtc|LocalDef(id,b,t)->mkNamedLetInsigmaidbtcletmkNamedProd_wo_LetInsigmadeclc=letopenContext.Named.Declarationinmatchdeclwith|LocalAssum(id,t)->mkNamedProdsigmaidtc|LocalDef(id,b,t)->Vars.subst1bcletit_mkProdinit=List.fold_left(func(n,t)->mkProd(n,t,c))initletit_mkLambdainit=List.fold_left(func(n,t)->mkLambda(n,t,c))initletcompose_lamlb=it_mkLambdablletit_mkProd_or_LetIntctx=List.fold_left(funcd->mkProd_or_LetIndc)tctxletit_mkLambda_or_LetIntctx=List.fold_left(funcd->mkLambda_or_LetIndc)tctxletit_mkProd_wo_LetIntctx=List.fold_left(funcd->mkProd_wo_LetIndc)tctxletit_mkLambda_wo_LetIntctx=List.fold_left(funcd->mkLambda_wo_LetIndc)tctxletit_mkNamedProd_or_LetInsigmatctx=List.fold_left(funcd->mkNamedProd_or_LetInsigmadc)tctxletit_mkNamedLambda_or_LetInsigmatctx=List.fold_left(funcd->mkNamedLambda_or_LetInsigmadc)tctxletit_mkNamedProd_wo_LetInsigmatctx=List.fold_left(funcd->mkNamedProd_wo_LetInsigmadc)tctxletpush_relde=push_rel(cast_rel_declunsafe_eqd)eletpush_rel_contextde=push_rel_context(cast_rel_contextunsafe_eqd)eletpush_rec_typesde=push_rec_types(cast_rec_declunsafe_eqd)eletpush_namedde=push_named(cast_named_declunsafe_eqd)eletpush_named_contextde=push_named_context(cast_named_contextunsafe_eqd)eletpush_named_context_valde=push_named_context_val(cast_named_declunsafe_eqd)eletrel_contexte=cast_rel_context(symunsafe_eq)(rel_contexte)letnamed_contexte=cast_named_context(symunsafe_eq)(named_contexte)letval_of_named_contexte=val_of_named_context(cast_named_contextunsafe_eqe)letnamed_context_of_vale=cast_named_context(symunsafe_eq)(named_context_of_vale)letof_existential:Constr.existential->existential=letgen:typeab.(a,b)eq->'c*bSList.t->'c*aSList.t=funReflx->xingenunsafe_eqletlookup_relie=cast_rel_decl(symunsafe_eq)(lookup_relie)letlookup_namedne=cast_named_decl(symunsafe_eq)(lookup_namedne)letlookup_named_valne=cast_named_decl(symunsafe_eq)(lookup_named_ctxtne)letmap_rel_context_in_envfenvsign=letrecauxenvacc=function|d::sign->aux(push_reldenv)(Context.Rel.Declaration.map_constr(fenv)d::acc)sign|[]->accinauxenv[](List.revsign)letmatch_named_context_val:named_context_val->(named_declaration*named_context_val)option=matchunsafe_eqwith|Refl->match_named_context_valletidentity_subst_val:named_context_val->tSList.t=functx->SList.defaultn(List.lengthctx.Environ.env_named_ctx)SList.emptyletfresh_global?loc?rigid?namesenvsigmareference=let(evd,t)=Evd.fresh_global?loc?rigid?namesenvsigmareferenceinevd,tletis_global=isRefX(** Kind of type *)typekind_of_type=|SortTypeofESorts.t|CastTypeoftypes*t|ProdTypeofName.tContext.binder_annot*t*t|LetInTypeofName.tContext.binder_annot*t*t*t|AtomicTypeoft*tarrayletkind_of_typesigmat=matchkindsigmatwith|Sorts->SortTypes|Cast(c,_,t)->CastType(c,t)|Prod(na,t,c)->ProdType(na,t,c)|LetIn(na,b,t,c)->LetInType(na,b,t,c)|App(c,l)->AtomicType(c,l)|(Rel_|Meta_|Var_|Evar_|Const_|Proj_|Case_|Fix_|CoFix_|Ind_)->AtomicType(t,[||])|(Lambda_|Construct_|Int_|Float_|Array_)->failwith"Not a type"moduleUnsafe=structletto_sorts=ESorts.unsafe_to_sortsletto_instance=EInstance.unsafe_to_instanceletto_constr=unsafe_to_constrletto_constr_array=unsafe_to_constr_arrayletto_rel_decl=unsafe_to_rel_declletto_named_decl=unsafe_to_named_declletto_named_context=letgen:typeab.(a,b)eq->(a,a)Context.Named.pt->(b,b)Context.Named.pt=funReflx->xingenunsafe_eqletto_rel_context=letgen:typeab.(a,b)eq->(a,a)Context.Rel.pt->(b,b)Context.Rel.pt=funReflx->xingenunsafe_eqletto_case_invert=unsafe_to_case_invertleteq=unsafe_eqendmoduleUnsafeMonomorphic=structletmkConstc=of_kind(Const(in_punivsc))letmkIndi=of_kind(Ind(in_punivsi))letmkConstructc=of_kind(Construct(in_punivsc))end(* deprecated *)letdecompose_lambda_assum=decompose_lambda_declsletdecompose_prod_assum=decompose_prod_declsletdecompose_prod_n_assum=decompose_prod_n_declsletprod_assum=prod_declsletdecompose_lam=decompose_lambdaletdecompose_lam_n_assum=decompose_lambda_n_assumletdecompose_lam_n_decls=decompose_lambda_n_declsletdecompose_lam_assum=decompose_lambda_assumincludeUnsafeMonomorphic