123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenPpopenCErrorsopenNamesopenEConstropenFormulaopenUnifyletnewcnt()=letcnt=ref(-1)infunb->ifbthenincrcnt;!cntletpriority=(* pure heuristics, <=0 for non reversible *)functionRightrf->beginmatchrfwithRarrow->100|Rand->40|Ror->-15|Rfalse->-50|Rforall->100|Rexists(_,_,_)->-29end|Leftlf->matchlfwithLfalse->999|Land_->90|Lor_->40|Lforall(_,_,_)->-30|Lexists_->60|LA(_,lap)->matchlapwithLLatom->0|LLfalse(_,_)->100|LLand(_,_)->80|LLor(_,_)->70|LLforall_->-20|LLexists(_,_)->50|LLarrow(_,_,_)->-10moduleOrderedFormula=structtypet=Formula.tletcomparee1e2=(prioritye1.pat)-(prioritye2.pat)endtypeh_item=GlobRef.t*(int*Constr.t)optionmoduleHitem=structtypet=h_itemletcompare(id1,co1)(id2,co2)=letc=GlobRef.CanOrd.compareid1id2inifc=0thenletcmp(i1,c1)(i2,c2)=letc=Int.comparei1i2inifc=0thenConstr.comparec1c2elsecinOption.comparecmpco1co2elsecendmoduleCM=Map.Make(Constr)moduleHistory=Set.Make(Hitem)letcm_addsigmatypnamcm=lettyp=EConstr.to_constr~abort_on_undefined_evars:falsesigmatypintryletl=CM.findtypcminCM.addtyp(nam::l)cmwithNot_found->CM.addtyp[nam]cmletcm_removesigmatypnamcm=lettyp=EConstr.to_constr~abort_on_undefined_evars:falsesigmatypintryletl=CM.findtypcminletl0=List.filter(funid->not(GlobRef.equalidnam))linmatchl0with[]->CM.removetypcm|_->CM.addtypl0cmwithNot_found->cmmoduleHP=Heap.Functional(OrderedFormula)typet={redexes:HP.t;context:(GlobRef.tlist)CM.t;latoms:constrlist;gl:types;glatom:constroption;cnt:counter;history:History.t;depth:int}letdeepenseq={seqwithdepth=seq.depth-1}letrecorditemseq={seqwithhistory=History.additemseq.history}letlookupenvsigmaitemseq=History.memitemseq.history||matchitemwith(_,None)->false|(id,Some(m,t))->letp(id2,o)=matchowithNone->false|Some(m2,t2)->GlobRef.equalidid2&&m2>m&&more_generalenvsigma(m2,EConstr.of_constrt2)(m,EConstr.of_constrt)inHistory.existspseq.historyletadd_formulaenvsigmasidenamtseq=matchbuild_formulaenvsigmasidenamtseq.cntwithLeftf->beginmatchsidewithConcl->{seqwithredexes=HP.addfseq.redexes;gl=f.constr;glatom=None}|_->{seqwithredexes=HP.addfseq.redexes;context=cm_addsigmaf.constrnamseq.context}end|Rightt->matchsidewithConcl->{seqwithgl=t;glatom=Somet}|_->{seqwithcontext=cm_addsigmatnamseq.context;latoms=t::seq.latoms}letre_add_formula_listsigmalfseq=letdo_onefcm=iff.id==dummy_idthencmelsecm_addsigmaf.constrf.idcmin{seqwithredexes=List.fold_rightHP.addlfseq.redexes;context=List.fold_rightdo_onelfseq.context}letfind_leftsigmatseq=List.hd(CM.find(EConstr.to_constr~abort_on_undefined_evars:falsesigmat)seq.context)(*let rev_left seq=
try
let lpat=(HP.maximum seq.redexes).pat in
left_reversible lpat
with Heap.EmptyHeap -> false
*)letrectake_formulasigmaseq=lethd=HP.maximumseq.redexesandhp=HP.removeseq.redexesinifhd.id==dummy_idthenletnseq={seqwithredexes=hp}inifseq.gl==hd.constrthenhd,nseqelsetake_formulasigmanseq(* discarding deprecated goal *)elsehd,{seqwithredexes=hp;context=cm_removesigmahd.constrhd.idseq.context}letempty_seqdepth={redexes=HP.empty;context=CM.empty;latoms=[];gl=(mkMeta1);glatom=None;cnt=newcnt();history=History.empty;depth=depth}letexpand_constructor_hints=List.map_append(function|GlobRef.IndRefind->List.init(Inductiveops.nconstructors(Global.env())ind)(funi->GlobRef.ConstructRef(ind,i+1))|gr->[gr])letextend_with_ref_listenvsigmalseq=letl=expand_constructor_hintslinletfgr(seq,sigma)=letsigma,c=Evd.fresh_globalenvsigmagrinletsigma,typ=Typing.type_ofenvsigmacin(add_formulaenvsigmaHypgrtypseq,sigma)inList.fold_rightfl(seq,sigma)openHintsletextend_with_auto_hintsenvsigmalseq=letf(seq,sigma)p_a_t=matchFullHint.reprp_a_twith|Res_pfc|Give_exactc|Res_pf_THEN_trivial_failc->letc=c.hint_termin(matchEConstr.destRefsigmacwith|exceptionConstr.DestKO->seq,sigma|gr,_->letsigma,typ=Typing.type_ofenvsigmacinadd_formulaenvsigmaHintgrtypseq,sigma)|_->seq,sigmainlethaccdbname=lethdb=trysearchtable_mapdbnamewithNot_found->user_errPp.(str("Firstorder: "^dbname^" : No such Hint database"))inHint_db.fold(fun__lacc->List.fold_leftfaccl)hdbaccinList.fold_lefth(seq,sigma)lletprint_cmapmap=letprint_entrycls=letenv=Global.env()inletsigma=Evd.from_envenvinletxc=Constrextern.extern_constrenvsigma(EConstr.of_constrc)instr"| "++prlistPrinter.pr_globall++str" : "++Ppconstr.pr_constr_exprenvsigmaxc++cut()++sin(v0(str"-----"++cut()++CM.foldprint_entrymap(mt())++str"-----"))