Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file proof.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157(** Proofs and tactics. *)openLplibopenBaseopenTimedopenCoreopenTermopenPrintopenCommonopenPos(** Type of goals. *)typegoal_typ={goal_meta:meta(** Goal metavariable. *);goal_hyps:Env.t(** Precomputed scoping environment. *);goal_type:term(** Precomputed type. *)}typegoal=|Typofgoal_typ(** Typing goal. *)|Unifofconstr(** Unification goal. *)letis_typ:goal->bool=functionTyp_->true|Unif_->falseletis_unif:goal->bool=functionTyp_->false|Unif_->trueletget_constr:goal->constr=functionUnifc->c|Typ_->invalid_arg(__FILE__^"get_constr")moduleGoal=structtypet=goal(** [ctxt g] returns the typing context of the goal [g]. *)letctxt:goal->ctxt=fung->matchgwith|Typgt->Env.to_ctxtgt.goal_hyps|Unif(c,_,_)->c(** [env g] returns the scoping environment of the goal [g]. *)letenv:goal->Env.t=fung->matchgwith|Unif(c,_,_)->lett,n=Ctxt.to_prodcmk_Typeinfst(Env.of_prod_nthcnt)|Typgt->gt.goal_hyps(** [of_meta m] creates a goal from the meta [m]. *)letof_meta:meta->goal=funm->letgoal_hyps,goal_type=(*let s = Format.asprintf "%s, of_meta %a(%d):%a" __LOC__
meta m m.meta_arity term !(m.meta_type) in*)Env.of_prod_nth[]m.meta_arity!(m.meta_type)inTyp{goal_meta=m;goal_hyps;goal_type}(** [simpl f g] simplifies the goal [g] with the function [f]. *)letsimpl:(ctxt->term->term)->goal->goal=funfg->matchgwith|Typgt->Typ{gtwithgoal_type=f(Env.to_ctxtgt.goal_hyps)gt.goal_type}|Unif(c,t,u)->Unif(c,fct,fcu)(** [bindlib_ctxt g] computes a Bindlib context from a goal. *)letbindlib_ctxt:goal->Bindlib.ctxt=fung->matchgwith|Typgt->letadd_namec(n,_)=Bindlib.reserve_namencinList.fold_leftadd_nameBindlib.empty_ctxtgt.goal_hyps|Unif(c,_,_)->letadd_namec(v,_,_)=Bindlib.reserve_name(Bindlib.name_ofv)cinList.fold_leftadd_nameBindlib.empty_ctxtc(** [pp ppf g] prints on [ppf] the goal [g] without its hypotheses. *)letpp:goalpp=funppfg->letbctx=bindlib_ctxtginletterm=term_inbctxinmatchgwith|Typgt->outppf"%a: %a"metagt.goal_metatermgt.goal_type|Unif(_,t,u)->outppf"%a ≡ %a"termttermu(** [hyps ppf g] prints on [ppf] the hypotheses of the goal [g]. *)lethyps:goalpp=funppfg->letbctx=bindlib_ctxtginletterm=term_inbctxinlethypshypppfl=ifl<>[]thenoutppf"@[<v>%a@,\
-----------------------------------------------\
---------------------------------@,@]"(List.pp(funppf->outppf"%a@,"hyp)"")(List.revl);inmatchgwith|Typgt->leteltppf(s,(_,t,u))=matchuwith|None->outppf"%a: %a"uidsterm(Bindlib.unboxt)|Someu->outppf"%a ≔ %a"uidsterm(Bindlib.unboxu)inhypseltppfgt.goal_hyps|Unif(c,_,_)->leteltppf(x,a,t)=outppf"%a: %a"varxterma;matchtwith|None->()|Somet->outppf" ≔ %a"termtinhypseltppfcend(** [add_goals_of_problem p gs] extends the list of goals [gs] with the
metavariables and constraints of [p]. *)letadd_goals_of_problem:problem->goallist->goallist=funpgs->letgs=MetaSet.fold(funmgs->Goal.of_metam::gs)!p.metasgsinletfgsc=Unifc::gsinletgs=List.fold_leftfgs!p.to_solveinList.fold_leftfgs!p.unsolved(** Representation of the proof state of a theorem. *)typeproof_state={proof_name:strloc(** Name of the theorem. *);proof_term:metaoption(** Optional metavariable holding the goal associated to a symbol used as a
theorem/definition and not just a simple declaration *);proof_goals:goallist(** Open goals (focused goal is first). *)}(** [finished ps] tells whether there are unsolved goals in [ps]. *)letfinished:proof_state->bool=funps->ps.proof_goals=[](** [goals ppf gl] prints the goal list [gl] to channel [ppf]. *)letgoals:proof_statepp=funppfps->matchps.proof_goalswith|[]->outppf"No goals."|g::_->outppf"@[<v>%a%a@]"Goal.hypsg(funppf->List.iteri(funig->outppf"%d. %a@,"iGoal.ppg))ps.proof_goals(** [remove_solved_goals ps] removes from the proof state [ps] the typing
goals that are solved. *)letremove_solved_goals:proof_state->proof_state=funps->letf=function|Typgt->!(gt.goal_meta.meta_value)=None|Unif_->truein{pswithproof_goals=List.filterfps.proof_goals}(** [meta_of_key ps i] returns [Some m] where [m] is a meta of [ps] whose key
is [i], or else it returns [None]. *)letmeta_of_key:proof_state->int->metaoption=funpskey->letf=function|Typ{goal_meta=m;_}whenm.meta_key=key->Somem|_->NoneinList.find_mapfps.proof_goals(** [focus_env ps] returns the scoping environment of the focused goal or the
empty environment if there is none. *)letfocus_env:proof_stateoption->Env.t=funps->matchpswith|None->Env.empty|Some(ps)->matchps.proof_goalswith|[]->Env.empty|g::_->Goal.envg