12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289(************************************************************************)(* * The Rocq Prover / The Rocq 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.DeclarationmoduleERelevance=structincludeEvd.MiniEConstr.ERelevanceletequalsigmar1r2=Sorts.relevance_equal(kindsigmar1)(kindsigmar2)letis_irrelevant=Evd.is_relevance_irrelevantletrelevant=makeRelevantletirrelevant=makeIrrelevantendmoduleESorts=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_sorts=letr=Sorts.relevance_of_sort(unsafe_to_sortss)inERelevance.makerletqualitysigmas=Sorts.quality(kindsigmas)letquality_or_setsigmas=ifis_setsigmasthenUnivGen.QualityOrSet.setelseUnivGen.QualityOrSet.of_quality@@Sorts.quality(kindsigmas)endmoduleEInstance=structincludeEvd.MiniEConstr.EInstanceletequalsigmai1i2=UVars.Instance.equal(kindsigmai1)(kindsigmai2)letlengthu=UVars.Instance.length(unsafe_to_instanceu)endmoduleExpand:sigtypettypekind=(t,t,ESorts.t,EInstance.t,ERelevance.t)Constr.kind_of_termtypehandlevalmake:Evd.econstr->handle*tvalrepr:Evd.evar_map->handle->t->Evd.econstrvalliftn_handle:int->handle->handlevalkind:Evd.evar_map->handle->t->handle*kindvalexpand_instance:skip:bool->Evd.undefinedEvd.evar_info->handle->tSList.t->tSList.tvaliter:Evd.evar_map->(handle->t->unit)->handle->kind->unitvaliter_with_binders:Evd.evar_map->('a->'a)->('a->handle->t->unit)->'a->handle->kind->unitend=structincludeEvd.Expandtypet=Evd.econstrtypekind=(t,t,ESorts.t,EInstance.t,ERelevance.t)Constr.kind_of_termletmakec=(empty_handle,c)letrepr=expandletitersigmafhknd=matchkndwith|Evar(evk,args)->letevi=Evd.find_undefinedsigmaevkinletargs=expand_instance~skip:falseevihargsin(* Despite the type, the sparse list contains no default element *)SList.Skip.iter(fh)args|Rel_|Meta_|Var_|Sort_|Const_|Ind_|Construct_|Int_|Float_|String_->()|Cast(c,_,t)->fhc;fht|Prod(_,t,c)->fht;f(liftn_handle1h)c|Lambda(_,t,c)->fht;f(liftn_handle1h)c|LetIn(_,b,t,c)->fhb;fht;f(liftn_handle1h)c|App(c,l)->fhc;Array.Fun1.iterfhl|Case(_,_,pms,(p,_),iv,c,bl)->Array.Fun1.iterfhpms;f(liftn_handle(Array.length(fstp))h)(sndp);iter_invert(fh)iv;fhc;Array.Fun1.iter(funh(ctx,b)->f(liftn_handle(Array.lengthctx)h)b)hbl|Proj(_p,_r,c)->fhc|Fix(_,(_,tl,bl))->Array.Fun1.iterfhtl;Array.Fun1.iterf(liftn_handle(Array.lengthtl)h)bl|CoFix(_,(_,tl,bl))->Array.Fun1.iterfhtl;Array.Fun1.iterf(liftn_handle(Array.lengthtl)h)bl|Array(_u,t,def,ty)->Array.iter(fh)t;fhdef;fhtyletiter_with_binderssigmagflhknd=matchkndwith|Evar(evk,args)->letevi=Evd.find_undefinedsigmaevkinletargs=expand_instance~skip:falseevihargsin(* Despite the type, the sparse list contains no default element *)SList.Skip.iter(flh)args|Rel_|Meta_|Var_|Sort_|Const_|Ind_|Construct_|Int_|Float_|String_->()|Cast(c,_,t)->flhc;flht|Prod(_,t,c)->flht;f(gl)(liftn_handle1h)c|Lambda(_,t,c)->flht;f(gl)(liftn_handle1h)c|LetIn(_,b,t,c)->flhb;flht;f(gl)(liftn_handle1h)c|App(c,args)->flhc;Array.iter(func->flhc)args|Case(_,_,pms,(p,_),iv,c,bl)->Array.iter(func->flhc)pms;f(iterateg(Array.length(fstp))l)(liftn_handle(Array.length(fstp))h)(sndp);iter_invert(func->flhc)iv;flhc;Array.iter(fun(ctx,b)->f(iterateg(Array.lengthctx)l)(liftn_handle(Array.lengthctx)h)b)bl|Proj(_p,_r,c)->flhc|Fix(_,(_,tl,bl))->Array.iter(func->flhc)tl;Array.iter(f(iterateg(Array.lengthtl)l)(liftn_handle(Array.lengthtl)h))bl|CoFix(_,(_,tl,bl))->Array.iter(func->flhc)tl;Array.iter(f(iterateg(Array.lengthtl)l)(liftn_handle(Array.lengthtl)h))bl|Array(_u,t,def,ty)->Array.iter(func->flhc)t;flhdef;flhtyendinclude(Evd.MiniEConstr:moduletypeofEvd.MiniEConstrwithmoduleERelevance:=ERelevanceandmoduleESorts:=ESortsandmoduleEInstance:=EInstance)typetypes=ttypeconstr=ttypeexistential=tpexistentialtypecase_return=(t,ERelevance.t)pcase_returntypecase_branch=(t,ERelevance.t)pcase_branchtypecase_invert=tpcase_inverttypecase=(t,t,EInstance.t,ERelevance.t)pcasetyperec_declaration=(t,t,ERelevance.t)prec_declarationtypefixpoint=(t,t,ERelevance.t)pfixpointtypecofixpoint=(t,t,ERelevance.t)pcofixpointtypeunsafe_judgment=(constr,types)Environ.punsafe_judgmenttypeunsafe_type_judgment=(types,ESorts.t)Environ.punsafe_type_judgmenttypenamed_declaration=(constr,types,ERelevance.t)Context.Named.Declaration.pttyperel_declaration=(constr,types,ERelevance.t)Context.Rel.Declaration.pttypecompacted_declaration=(constr,types,ERelevance.t)Context.Compacted.Declaration.pttypenamed_context=(constr,types,ERelevance.t)Context.Named.pttypecompacted_context=compacted_declarationlisttyperel_context=(constr,types,ERelevance.t)Context.Rel.pttype'abinder_annot=('a,ERelevance.t)Context.pbinder_annotletannotRx=Context.make_annotxERelevance.relevantletnameRx=annotR(Namex)letanonR=annotRAnonymoustype'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,r,c)=of_kind(Proj(p,r,c))letmkArrowt1rt2=of_kind(Prod(make_annotAnonymousr,t1,t2))letmkArrowRt1t2=mkArrowt1ERelevance.relevantt2letmkInti=of_kind(Inti)letmkFloatf=of_kind(Floatf)letmkStrings=of_kind(Strings)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=matchRocqlib.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,r,c)->(p,r,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_nsigman=ifn<0thenanomalyPp.(str"decompose_lambda_n: integer parameter must be positive");letreclamdec_reclnc=ifInt.equaln0then(l,c)elsematchkindsigmacwith|Lambda(x,t,c)->lamdec_rec((x,t)::l)(n-1)c|Cast(c,_,_)->lamdec_reclnc|_->anomalyPp.(str"decompose_lambda_n: not enough abstractions")inlamdec_rec[]nletdecompose_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_nsigman=ifn<0thenanomalyPp.(str"decompose_prod_n: integer parameter must be positive");letrecproddec_reclnc=ifInt.equaln0then(l,c)elsematchkindsigmacwith|Prod(x,t,c)->proddec_rec((x,t)::l)(n-1)c|Cast(c,_,_)->proddec_reclnc|_->anomalyPp.(str"decompose_prod_n: not enough products")inproddec_rec[]nletdecompose_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_eq,unsafe_relevance_eq)with|Refl,Refl->funx->xletunsafe_to_branches:case_brancharray->Constr.case_brancharray=matchEvd.MiniEConstr.(unsafe_eq,unsafe_relevance_eq)with|Refl,Refl->funx->xletof_return:Constr.case_return->case_return=matchEvd.MiniEConstr.(unsafe_eq,unsafe_relevance_eq)with|Refl,Refl->funx->xletunsafe_to_return:case_return->Constr.case_return=matchEvd.MiniEConstr.(unsafe_eq,unsafe_relevance_eq)with|Refl,Refl->funx->xletof_binder_annot:'aConstr.binder_annot->'abinder_annot=matchEvd.MiniEConstr.unsafe_relevance_eqwith|Refl->funx->xletto_binder_annotsigma(x:_binder_annot):_Constr.binder_annot=letRefl=unsafe_relevance_eqinContext.map_annot_relevance(ERelevance.kindsigma)xletto_rel_declsigma(d:rel_declaration):Constr.rel_declaration=letRefl=unsafe_eqinletRefl=unsafe_relevance_eqinContext.Rel.Declaration.map_constr_with_relevance(ERelevance.kindsigma)(to_constrsigma)dletto_rel_contextsigma(ctx:rel_context):Constr.rel_context=letRefl=unsafe_eqinletRefl=unsafe_relevance_eqinList.Smart.map(to_rel_declsigma)ctxletto_named_declsigma(d:named_declaration):Constr.named_declaration=letRefl=unsafe_eqinletRefl=unsafe_relevance_eqinContext.Named.Declaration.map_constr_with_relevance(ERelevance.kindsigma)(to_constrsigma)dletto_named_contextsigma(ctx:named_context):Constr.named_context=letRefl=unsafe_eqinletRefl=unsafe_relevance_eqinList.Smart.map(to_named_declsigma)ctxletmap_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,r),iv,c,bl)=Inductive.expand_caseenv(ci,u,pms,p,iv,c,bl)inletp=of_constrpinletr=ERelevance.makerinletc=of_constrcinletiv=of_case_invertivinletbl=of_constr_arrayblin(ci,(p,r),iv,c,bl)letannotate_caseenvsigma(ci,u,pms,p,iv,c,blascase)=let(_,(p,r),_,_,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,r),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)ctxinletnas=letgen:typeab.(a,b)eq->(_,a)Context.pbinder_annotarray->(_,b)Context.pbinder_annotarray=funReflx->xingenunsafe_relevance_eqnasinletans=Inductive.instantiate_contextuparamsubstnasctxinletans:rel_context=matchEvd.MiniEConstr.(unsafe_eq,unsafe_relevance_eq)with|Refl,Refl->ansinansletcontract_caseenv_sigma(ci,(p,r),iv,c,bl)=letp=unsafe_to_constrpinletr=ERelevance.unsafe_to_relevancerinletiv=unsafe_to_case_invertivinletc=unsafe_to_constrcinletbl=unsafe_to_constr_arrayblinlet(ci,u,pms,p,iv,c,bl)=Inductive.contract_caseenv(ci,(p,r),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_|String_)->()|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(_,_,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)cmp0c1c2letcmp_inductivescv_pb(mind,indasspec)nargsu1u2cstrs=letopenUnivProbleminmatchmind.Declarations.mind_variancewith|None->enforce_eq_instances_univsfalseu1u2cstrs|Somevariances->letnum_param_arity=Conversion.inductive_cumulativity_argumentsspecinifnot(Int.equalnum_param_aritynargs)thenenforce_eq_instances_univsfalseu1u2cstrselsecompare_cumulative_instancescv_pbvariancesu1u2cstrsletcmp_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_univsfalseu1u2cstrselseletqs1,us1=UVars.Instance.to_arrayu1andqs2,us2=UVars.Instance.to_arrayu2inletcstrs=enforce_eq_qualitiesqs1qs2cstrsinArray.fold_left2(funcstrsu1u2->UnivProblem.(Set.add(UWeak(u1,u2))cstrs))cstrsus1us2leteq_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_pb[|UVars.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!cstrselseNoneletadd_universes_of_instancesigma(qs,us)u=letu=EInstance.kindsigmauinletqs',us'=UVars.Instance.levelsuinletqs=Sorts.Quality.(Set.fold(funqqs->matchqwith|QVarq->Sorts.QVar.Set.addqqs|QConstant_->qs)qs'qs)inqs,Univ.Level.Set.unionusus'letadd_relevancesigma(qs,usasv)r=letopenSortsin(* NB this normalizes above_prop to Relevant which makes it disappear *)matchERelevance.kindsigmarwith|Irrelevant|Relevant->v|RelevanceVarq->QVar.Set.addqqs,usletunivs_and_qvars_visitorsigma=letopenUnivinletvisit_sort(qs,usasacc)s=matchESorts.kindsigmaswith|Sorts.Typeu->qs,Universe.levels~init:usu|Sorts.QSort(q,u)->Sorts.QVar.Set.addqqs,Universe.levels~init:usu|Sorts.(SProp|Prop|Set)->accinletvisit_instanceaccu=add_universes_of_instancesigmaaccuinletvisit_relevanceaccr=add_relevancesigmaaccrin{Vars.visit_sort=visit_sort;visit_instance=visit_instance;visit_relevance=visit_relevance;}letuniverses_of_constr?(init=Sorts.QVar.Set.empty,Univ.Level.Set.empty)sigmac=letvisit=univs_and_qvars_visitorsigmainletrecauxsc=letkc=kindsigmacinlets=Vars.visit_kind_univsvisitskcinmatchkcwith|Evar(k,args)->letconcl=Evd.evar_concl(Evd.find_undefinedsigmak)infoldsigmaaux(auxsconcl)c|_->foldsigmaauxscinauxinitcopenContextopenEnvironletcast_list:typeab.(a,b)eq->alist->blist=funReflx->xletcast_vect:typeab.(a,b)eq->aarray->barray=funReflx->xletcast_rel_decl:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Rel.Declaration.pt->(b,b,d)Rel.Declaration.pt=funReflReflx->xletcast_rel_context:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Rel.pt->(b,b,d)Rel.pt=funReflReflx->xletcast_rec_decl:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Constr.prec_declaration->(b,b,d)Constr.prec_declaration=funReflReflx->xletcast_named_decl:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Named.Declaration.pt->(b,b,d)Named.Declaration.pt=funReflReflx->xletcast_named_context:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Named.pt->(b,b,d)Named.pt=funReflReflx->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=letsubst=EInstance.unsafe_to_instancesubstincast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.subst_instance_contextsubst(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letsubst_instance_constrsubstc=letsubst=EInstance.unsafe_to_instancesubstinof_constr(Vars.subst_instance_constrsubst(to_constrc))letsubst_instance_relevancesubstr=letsubst=EInstance.unsafe_to_instancesubstinletr=ERelevance.unsafe_to_relevancerinletr=UVars.subst_instance_relevancesubstrinERelevance.maker(** Operations that dot NOT commute with evar-normalization *)letnoccurnsigmanterm=letrecoccur_recnhc=let(h,knd)=Expand.kindsigmahcinmatchkndwith|Relm->ifInt.equalmnthenraiseLocalOccur|Evar(evk,l)->letevi=Evd.find_undefinedsigmaevkinletl=Expand.expand_instance~skip:trueevihlinSList.Skip.iter(func->occur_recnhc)l|_->Expand.iter_with_binderssigmasuccoccur_recnhkndinleth,term=Expand.maketermintryoccur_recnhterm;truewithLocalOccur->falseletnoccur_betweensigmanmterm=letrecoccur_recnhc=let(h,knd)=Expand.kindsigmahcinmatchkndwith|Relp->ifn<=p&&p<n+mthenraiseLocalOccur|Evar(evk,l)->letevi=Evd.find_undefinedsigmaevkinletl=Expand.expand_instance~skip:trueevihlinSList.Skip.iter(func->occur_recnhc)l|_->Expand.iter_with_binderssigmasuccoccur_recnhkndinleth,term=Expand.maketermintryoccur_recnhterm;truewithLocalOccur->falseletclosednsigmanc=letrecclosed_recnhc=let(h,knd)=Expand.kindsigmahcinmatchkndwith|Relm->ifm>nthenraiseLocalOccur|Evar(evk,l)->letevi=Evd.find_undefinedsigmaevkinletl=Expand.expand_instance~skip:trueevihlinSList.Skip.iter(func->closed_recnhc)l|_->Expand.iter_with_binderssigmasuccclosed_recnhkndinleth,c=Expand.makecintryclosed_recnhc;truewithLocalOccur->falseletclosed0sigmac=closednsigma0cletsubst_of_rel_context_instancectxsubst=cast_list(symunsafe_eq)(Vars.subst_of_rel_context_instance(cast_rel_contextunsafe_equnsafe_relevance_eqctx)(cast_vectunsafe_eqsubst))letsubst_of_rel_context_instance_listctxsubst=cast_list(symunsafe_eq)(Vars.subst_of_rel_context_instance_list(cast_rel_contextunsafe_equnsafe_relevance_eqctx)(cast_listunsafe_eqsubst))letliftn_rel_contextnkctx=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.liftn_rel_contextnk(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letlift_rel_contextnctx=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.lift_rel_contextn(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letsubstnl_rel_contextsubstnctx=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.substnl_rel_context(cast_listunsafe_eqsubst)n(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letsubstl_rel_contextsubstctx=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.substl_rel_context(cast_listunsafe_eqsubst)(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letsmash_rel_contextctx=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(Vars.smash_rel_context(cast_rel_contextunsafe_equnsafe_relevance_eqctx))letesubst:(int->'a->t)->'aEsubst.subs->t->t=matchunsafe_eqwith|Refl->Vars.esubstend(* 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)tctxletrecisAritysigmac=matchkindsigmacwith|Prod(_,_,c)->isAritysigmac|LetIn(_,_,_,c)->isAritysigmac|Cast(c,_,_)->isAritysigmac|Sort_->true|_->falsetypearity=rel_context*ESorts.tletmkArity(ctx,s)=it_mkProd_or_LetIn(mkSorts)ctxletdestAritysigma=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[]letpush_relde=push_rel(cast_rel_declunsafe_equnsafe_relevance_eqd)eletpush_rel_contextde=push_rel_context(cast_rel_contextunsafe_equnsafe_relevance_eqd)eletpush_rec_typesde=push_rec_types(cast_rec_declunsafe_equnsafe_relevance_eqd)eletpush_namedde=push_named(cast_named_declunsafe_equnsafe_relevance_eqd)eletpush_named_contextde=push_named_context(cast_named_contextunsafe_equnsafe_relevance_eqd)eletpush_named_context_valde=push_named_context_val(cast_named_declunsafe_equnsafe_relevance_eqd)eletrel_contexte=cast_rel_context(symunsafe_eq)(symunsafe_relevance_eq)(rel_contexte)letnamed_contexte=cast_named_context(symunsafe_eq)(symunsafe_relevance_eq)(named_contexte)letval_of_named_contexte=val_of_named_context(cast_named_contextunsafe_equnsafe_relevance_eqe)letnamed_context_of_vale=cast_named_context(symunsafe_eq)(symunsafe_relevance_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)(symunsafe_relevance_eq)(lookup_relie)letlookup_namedne=cast_named_decl(symunsafe_eq)(symunsafe_relevance_eq)(lookup_namedne)letlookup_named_valne=cast_named_decl(symunsafe_eq)(symunsafe_relevance_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_eq,unsafe_relevance_eqwith|Refl,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.tbinder_annot*t*t|LetInTypeofName.tbinder_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_|String_|Array_)->failwith"Not a type"moduleUnsafe=structletto_relevance=ERelevance.unsafe_to_relevanceletto_sorts=ESorts.unsafe_to_sortsletto_instance=EInstance.unsafe_to_instanceletto_constr=unsafe_to_constrletto_constr_array=unsafe_to_constr_arrayletto_binder_annot:'abinder_annot->'aConstr.binder_annot=matchunsafe_relevance_eqwithRefl->funx->xletto_rel_decl=unsafe_to_rel_declletto_named_decl=unsafe_to_named_declletto_named_context=letgen:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Context.Named.pt->(b,b,d)Context.Named.pt=funReflReflx->xingenunsafe_equnsafe_relevance_eqletto_rel_context=letgen:typeabcd.(a,b)eq->(c,d)eq->(a,a,c)Context.Rel.pt->(b,b,d)Context.Rel.pt=funReflReflx->xingenunsafe_equnsafe_relevance_eqletto_case_invert=unsafe_to_case_invertleteq=unsafe_eqletrelevance_eq=unsafe_relevance_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