123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155moduleB=Kernel.BasicmoduleT=Kernel.Termtypeuniv=Sinf|VarofB.name|Enumofinttypepred=|Axiomofuniv*univ|Cumulofuniv*univ|Ruleofuniv*univ*univtypecstr=Predofpred|EqVarofB.name*B.namemoduleC=Set.Make(structtypet=cstrletcompare=compareend)letmd_theory=ref@@B.mk_mident""letmd_univ=ref(B.mk_mident"")letpvar()=B.mk_name!md_theory(B.mk_ident"var")letsort()=B.mk_name!md_theory(B.mk_ident"Sort")lettyp()=B.mk_name!md_theory(B.mk_ident"type")letset()=B.mk_name!md_theory(B.mk_ident"set")letprop()=B.mk_name!md_theory(B.mk_ident"prop")letuniv()=B.mk_name!md_theory(B.mk_ident"Univ")letcast'()=B.mk_name!md_theory(B.mk_ident"cast'")letaxiom()=B.mk_name!md_theory(B.mk_ident"Axiom")letrule()=B.mk_name!md_theory(B.mk_ident"Rule")letcumul()=B.mk_name!md_theory(B.mk_ident"Cumul")letenum()=B.mk_name!md_theory(B.mk_ident"enum")letuzero()=B.mk_name!md_theory(B.mk_ident"uzero")letusucc()=B.mk_name!md_theory(B.mk_ident"usucc")letsubtype()=B.mk_name!md_theory(B.mk_ident"SubType")letforall()=B.mk_name!md_theory(B.mk_ident"forall")letsinf()=B.mk_name!md_theory(B.mk_ident"sinf")lettrue_()=T.mk_ConstB.dloc(B.mk_name!md_theory(B.mk_ident"true"))letrecterm_of_leveli=assert(i>=0);ifi=0thenT.mk_ConstB.dloc(uzero())elseT.mk_App(T.mk_ConstB.dloc(usucc()))(term_of_level(i-1))[]letterm_of_univu=letlc=B.dlocinmatchuwith|Sinf->T.mk_Constlc(sinf())|Varn->T.mk_Constlcn|Enumi->T.mk_App(T.mk_ConstB.dloc(enum()))(term_of_leveli)[]letterm_of_predp=letlc=B.dlocinmatchpwith|Axiom(s,s')->T.mk_App2(T.mk_Constlc(axiom()))[term_of_univs;term_of_univs']|Cumul(s,s')->T.mk_App2(T.mk_Constlc(cumul()))[term_of_univs;term_of_univs']|Rule(s,s',s'')->T.mk_App2(T.mk_Constlc(rule()))[term_of_univs;term_of_univs';term_of_univs'']letpattern_of_level_=failwith"todo pattern of level"letis_constcstt=matchtwithT.Const(_,n)->B.name_eqcstn|_->falseletis_varmd_elabt=matchtwithT.Const(_,n)->B.mdn=md_elab|_->falseletis_enumt=matchtwithT.App(f,_,[])whenis_const(enum())f->true|_->falseletis_subtypet=matchtwith|T.App(f,_,[_;_;_])whenis_const(subtype())f->true|_->falseletextract_subtypet=matchtwith|T.App(f,_,[_;_;_])asswhenis_const(subtype())f->s|_->assertfalseletis_forallt=matchtwith|T.App(f,_,[_;_])whenis_const(forall())f->true|_->falseletextract_forallt=matchtwith|T.App(f,_,[_;T.Lam(_,_,_,t)])whenis_const(forall())f->t|_->assertfalseletis_cast't=matchtwithT.App(f,_,_)whenis_const(cast'())f->true|_->falseletextract_cast't=matchtwith|T.App(f,s1,[s2;a;b;t])whenis_const(cast'())f->(s1,s2,a,b,t)|T.App(f,s1,s2::a::b::m::n)whenis_const(cast'())f->(s1,s2,a,b,T.mk_App2mn)|_->Format.eprintf"%a@."Api.Pp.Default.print_termt;assertfalseletrecextract_level:T.term->int=funt->matchtwith|T.Const(_,n)whenB.name_eqn(uzero())->0|T.App(T.Const(_,n),l,[])whenB.name_eqn(usucc())->1+extract_levell|_->assertfalseexceptionNot_univexceptionNot_predletextract_univ:T.term->univ=funt->matchtwith|T.Const(_,n)whenn=sinf()->Sinf|T.Const(_,n)->Varn|T.App(T.Const(_,c),n,[])whenB.name_eqc(enum())->Enum(extract_leveln)|_->Format.eprintf"%a@."Api.Pp.Default.print_termt;assertfalseletextract_predt=matchtwith|T.App(f,s,[s'])whenis_const(axiom())f->Axiom(extract_univs,extract_univs')|T.App(f,s,[s'])whenis_const(cumul())f->Cumul(extract_univs,extract_univs')|T.App(f,s,[s';s''])whenis_const(rule())f->Rule(extract_univs,extract_univs',extract_univs'')|_->raiseNot_pred