123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenCErrorsopenNamesopenFormulaopenUnifyletnewcnt()=letcnt=ref(-1)infunb->ifbthenincrcnt;!cntletpriority:typea.apattern->int=(* pure heuristics, <=0 for non reversible *)functionRightPatternrf->beginmatchrfwithRarrow->100|Rand->40|Ror->-15|Rfalse->-50|Rforall->100|Rexists(_,_,_)->-29end|LeftPatternlf->matchlfwithLfalse->999|Land_->90|Lor_->40|Lforall(_,_,_)->-30|Lexists_->60|LAlap->matchlapwithLLatom->0|LLfalse(_,_)->100|LLand(_,_)->80|LLor(_,_)->70|LLforall_->-20|LLexists(_,_)->50|LLarrow(_,_,_)->-10moduleOrderedFormula=structtypet=Formula.any_formulaletcompare(AnyFormulae1)(AnyFormulae2)=(prioritye1.pat)-(prioritye2.pat)endtypeh_item=GlobRef.t*Unify.Item.toptionleth_canonizeenv(hr,item)=(Environ.QGlobRef.canonizeenvhr,item)moduleHitem=structtypet=h_itemletcompare(id1,co1)(id2,co2)=letc=GlobRef.UserOrd.compareid1id2inifc=0thenOption.compareUnify.Item.compareco1co2elsecendmoduleHistory=Set.Make(Hitem)moduleHP=Heap.Functional(OrderedFormula)typeseqgoal=GoalTermofFormula.uid|GoalAtomofatom|GoalDummytypet={redexes:HP.t;state:Env.t;latoms:atomlist;gl:seqgoal;cnt:counter;history:History.t;hyps:Id.Set.t;depth:int}lethas_fuelseq=seq.depth>0letiter_redexesfseq=HP.iter(fun(AnyFormulap)->fp.atoms)seq.redexesletdeepenseq={seqwithdepth=seq.depth-1}letrecordenvitemseq={seqwithhistory=History.add(h_canonizeenvitem)seq.history}letlookupenvsigmaitemseq=History.mem(h_canonizeenvitem)seq.history||matchitemwith(_,None)->false|(id,Somei1)->letp(id2,o)=matchowithNone->false|Somei2->Environ.QGlobRef.equalenvidid2&&more_generalenvsigmai2i1inHistory.existspseq.historyletadd_concl~flagsenvsigmatseq=matchbuild_formula~flagsseq.stateenvsigmaConclgoal_idtseq.cntwith|state,Leftf->{seqwithredexes=HP.add(AnyFormulaf)seq.redexes;gl=GoalTermf.uid;state}|state,Rightt->{seqwithgl=GoalAtomt;state}letadd_formula~flags~hintenvsigmaidtseq=letside=Hyphintinlethyps=matchidwith|GlobRef.VarRefid->Id.Set.addidseq.hyps|_->seq.hypsinmatchbuild_formula~flagsseq.stateenvsigmaside(formula_idenvid)tseq.cntwith|state,Leftf->{seqwithredexes=HP.add(AnyFormulaf)seq.redexes;hyps;state}|state,Rightt->{seqwithlatoms=t::seq.latoms;hyps;state}letre_add_formula_listsigmalfseq=letdo_id(AnyFormulaf)hyps=matchf.idwith|GoalId->hyps|FormulaId(GlobRef.VarRefid)->Id.Set.addidhyps|FormulaId_->hypsin{seqwithredexes=List.fold_rightHP.addlfseq.redexes;hyps=List.fold_rightdo_idlfseq.hyps;}letmem_hypidseq=Id.Set.memidseq.hypsletrectake_formulaenvsigmaseq=lethd=HP.maximumseq.redexesinlethp=HP.removeseq.redexesinletAnyFormulahd0=hdinmatchhd0.idwith|GoalId->letnseq={seqwithredexes=hp}inbeginmatchseq.glwith|GoalTermtwhenFormula.eq_uidthd0.uid->hd,nseq|GoalAtom_|GoalTerm_|GoalDummy->take_formulaenvsigmanseq(* discarding deprecated goal *)end|FormulaIdid->lethyps=matchidwith|GlobRef.VarRefid->Id.Set.removeidseq.hyps|_->seq.hypsinhd,{seqwithredexes=hp;hyps;}letempty_seqdepth={redexes=HP.empty;latoms=[];gl=GoalDummy;cnt=newcnt();history=History.empty;depth=depth;hyps=Id.Set.empty;state=Env.empty}letmake_simple_atomsseq=letratoms=matchseq.glwith|GoalAtomt->[t]|GoalTerm_|GoalDummy->[]in{negative=seq.latoms;positive=ratoms}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_list~flagsenvsigmalseq=letl=expand_constructor_hintslinletfgr(seq,sigma)=letsigma,c=Evd.fresh_globalenvsigmagrinletsigma,typ=Typing.type_ofenvsigmacin(add_formula~flags~hint:falseenvsigmagrtypseq,sigma)inList.fold_rightfl(seq,sigma)openHintsletextend_with_auto_hints~flagsenvsigmalseq=letf(seq,sigma)p_a_t=matchFullHint.reprp_a_twith|Res_pfc|Give_exactc|Res_pf_THEN_trivial_failc->letc=snd@@hint_as_termcin(matchEConstr.destRefsigmacwith|exceptionConstr.DestKO->seq,sigma|gr,_->letsigma,typ=Typing.type_ofenvsigmacinadd_formula~flags~hint:trueenvsigmagrtypseq,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)lletstateseq=seq.state