package lambdapi
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=0e2e73e0ea0c674f1263bf85ed3453ed3d6084d38eea29974a03ba9e382d29d7
sha512=2831db57fcd09206687a92fc9ee7d363e87bcec5167949e9c8161d41c63d5887b9f3556bfd63a7a9a0c12e5a5dc61a397baf4f496ebdb2a2fce122142c05e7a1
doc/lambdapi.handle/Handle/Rewrite/index.html
Module Handle.RewriteSource
Implementation of the rewrite tactic.
type eq_config = {symb_P : Core.Term.sym;(*Encoding of propositions.
*)symb_T : Core.Term.sym;(*Encoding of types.
*)symb_eq : Core.Term.sym;(*Equality proposition.
*)symb_eqind : Core.Term.sym;(*Induction principle on equality.
*)symb_refl : Core.Term.sym;(*Reflexivity of equality.
*)
}Equality configuration.
type binder_rewrite_config = {symb_arr : Core.Term.sym;(*HOL non-dependent function type constructor.
*)symb_funext : Core.Term.sym;(*Functional extensionality principle.
*)
}Additional configuration needed only when rewrite has to lift an equality over a binder.
get_eq_config ss pos returns the current configuration for equality, used by tactics such as “rewrite” or “reflexivity”.
get_binder_rewrite_config ss pos returns the configuration needed for binder-dependent rewrite occurrences.
val get_eq_data :
eq_config ->
Common.Pos.popt ->
Core.Term.term ->
(Core.Term.term * Core.Term.term * Core.Term.term) * Core.Term.var listget_eq_data pos cfg a returns ((a,l,r),[v1;..;vn]) if a ≡ Π v1:A1, .., Π vn:An, P (eq a l r) and fails otherwise.
Type of a term with the free variables that need to be substituted. It is usually used to store the LHS of a proof of equality, together with the variables that were quantified over.
matches p t instantiates the TRefs of p so that p becomes equal to t and returns true if all TRefs of p could be instantiated, and false otherwise. With allow_binder_holes, a TRef belonging to a selection pattern may match a term containing a variable bound inside p. Callers must preserve the scope of those variables when using the assignments, or discard them.
matching_subs (xs,p) t attempts to match the pattern p containing the variables xs with the term t. If successful, it returns Some ts where ts is an array of terms such that substituting xs by the corresponding elements of ts in p yields t.
WARNING: Some elements of ts may be uninstantiated TRefs. This happens if not all xs are in LibTerm.free_vars p, for instance when some xs are type variables not occurring in p, for instance when trying to apply an equation of the form x = ... with x of polymorphic type. This could be improved by generating p_terms instead of terms. Indeed, in this case, we could replace uninstantiated TRefs by underscores.
check_subs vars ts checks that no element of ts is an uninstantiated TRef.
val matching_subs_check_TRef :
Common.Pos.popt ->
(Core.Term.var array * Core.Term.term) ->
Core.Term.term ->
Core.Term.term arraytype binder_frame = {binder_var : Core.Term.var;binder_typ : Core.Term.term;binder_path : int list;
}Binder frame enclosing a subterm. binder_path identifies the original binder by the path to its body, storing child indices in reverse order. Application children are 0 for the function and 1 for the argument; abstraction/product children are 0 for the domain and 1 for the body; let children are 0 for the type, 1 for the definition and 2 for the body. The path recognises the same binder across traversals even when unbinding creates fresh variables. binder_var is the variable opened in this traversal, with type binder_typ.
abstract_over_frame frame t abstracts t over the variable recorded in frame, using the frame's binder type.
abstract_over_frames frames t abstracts t over all frames. The frame list must be ordered from innermost to outermost binder, and the returned abstractions are nested from outermost to innermost binder.
same_binder_paths frames frames' tells whether frames and frames' identify the same original enclosing binders across independent traversals of the goal.
apply_to_frames t frames applies t to the variables in frames. The frame list must be ordered from innermost to outermost binder.
val adapt_to_frames :
binder_frame list ->
binder_frame list ->
Core.Term.term ->
Core.Term.termadapt_to_frames frames frames' t adapts references in t to variables bound by frames so that they refer to the corresponding variables bound by frames'.
val same_under_binders :
binder_frame list ->
binder_frame list ->
Core.Term.term ->
Core.Term.term ->
boolsame_under_binders first_frames frames first t tells whether t is the same term as first, modulo the fresh variables generated when unbinding the same original enclosing binders.
val find_subterm_from :
binder_frame list ->
int list ->
(binder_frame list -> Core.Term.term -> 'a option) ->
Core.Term.term ->
'a optionfind_subterm_from binders path try_match t searches t, trying each candidate before its children. try_match receives its enclosing frames and term, and returns Some result on success. Failed attempts are rolled back before descending. Children are searched in application order, with binder domains and let definitions before bodies. Initial frames are ordered from innermost to outermost; paths store child indices in reverse. A successful result retains the state established by try_match.
type subst_under_binders = {subst : Core.Term.term array;redex : Core.Term.term;binders : binder_frame list;
}Result of a successful binder-aware rewrite occurrence search.
val find_subst_from :
binder_frame list ->
int list ->
to_subst ->
Core.Term.term ->
subst_under_binders optionfind_subst_from binders path (xs,p) t searches for the first subterm of t matching p. It returns the substitution for xs, the matched term and its enclosing binder frames. binders and path are the known enclosing context of t, ordered as in find_subterm_from.
val find_subst_in_region :
Common.Pos.popt ->
binder_frame list ->
to_subst ->
Core.Term.term ->
subst_under_bindersfind_subst_in_region pos binders (vars,p) t searches for p in an already-selected region t, preserving the binder context enclosing the region.
find_subst pos (vars,p) t returns the search result for the first occurrence of p in t, or fails if no subterm matches. It also checks that all variables in vars have been instantiated.
replace_wild_by_tref t substitutes every wildcard of t by a distinct fresh TRef.
Result of matching a rewrite selector pattern. term is the actual matched goal subterm; binders records its enclosing binder frames.
val find_subterm_matching_from :
binder_frame list ->
int list ->
Core.Term.term ->
Core.Term.term ->
selected_term_under_binders optionfind_subterm_matching_from binders path p t tries to find a subterm of t that matches p by instantiating the TRefs of p and records the binders enclosing the selected subterm. binders and path are the already-known enclosing binder context of t. The binder list is ordered from innermost to outermost binder.
val find_subterm_matching :
Common.Pos.popt ->
Core.Term.term ->
Core.Term.term ->
selected_term_under_bindersfind_subterm_matching pos p t returns the first selected subterm matching p in t, or fails if no subterm matches.
type contextual_selection = {pat_l : Core.Term.term;pat_l_binders : binder_frame list;id_val : Core.Term.term;id_val_binders : binder_frame list;id_path : int list;id_paths : int list list;
}Result of matching a contextual pattern such as id in p. pat_l is the actual matched goal context before rewriting, retained directly rather than reconstructed from p. id_val is the term denoted by id inside it. Both terms retain their enclosing binder frames in pat_l_binders and id_val_binders, respectively. id_path is the first occurrence of id, and id_paths records every occurrence. These paths are relative to pat_l and are stored in reverse order, as in the rewrite traversal.
val match_contextual_pattern :
Core.Term.var ->
Core.Term.term ->
binder_frame list ->
Core.Term.term ->
contextual_selection optionmatch_contextual_pattern selector p binders t matches one candidate t against p, collecting all occurrences of selector. The selected paths are relative to t; binders records its enclosing context.
val find_contextual_selection :
Common.Pos.popt ->
Core.Term.binder ->
Core.Term.term ->
contextual_selectionfind_contextual_selection pos p goal finds the first subterm of goal matching the contextual pattern p. It matches the context and identifies the selector occurrence together.
val replace_under_binders_from :
binder_frame list ->
int list ->
(binder_frame list -> int list -> Core.Term.term -> Core.Term.term option) ->
Core.Term.term ->
Core.Term.termreplace_under_binders_from binders path f goal traverses goal while recording enclosing binder frames. binders and path are the already-known enclosing binder context of goal. At each subterm t, f binders path t may return a replacement. The path is relative to the initial goal unless path is supplied by a containing search. If f returns a replacement, traversal does not descend below t.
val replace_under_binders :
(binder_frame list -> Core.Term.term -> Core.Term.term option) ->
Core.Term.term ->
Core.Term.termreplace_under_binders f goal traverses goal while recording enclosing binder frames. At each subterm t, f binders t may return a replacement. If it does, traversal does not descend below t.
val bind_pattern :
?at:??? ->
binder_frame list ->
Core.Term.var ->
Core.Term.term ->
binder_frame list ->
Core.Term.term ->
Core.Term.termbind_pattern ~at binders z lhs relevant goal replaces occurrences matching the instantiated lhs in goal by z applied to the relevant bound variables. relevant is the list of binder frames that the equality is lifted over. lhs is already abstracted over these frames. Candidates must use the same original binders and match after abstraction over their local frames. binders is the already-known enclosing context of goal; at optionally restricts replacement to selected paths.
val replace_selected_under_binders :
binder_frame list ->
Core.Term.term ->
Core.Term.term ->
Core.Term.term ->
Core.Term.termreplace_selected_under_binders selected_binders selected replacement goal replaces every occurrence of selected in goal by replacement, adapting references from the variables recorded in selected_binders to the corresponding fresh variables when the same original binders are unbound again while traversing goal.
type prepared_rewrite = {eq_type : Core.Term.term;lhs : Core.Term.term;rhs : Core.Term.term;proof : Core.Term.term;pred_bind : Core.Term.binder;new_term : Core.Term.term;
}Data prepared for the final equality-induction rewrite step.
Equality data being lifted over one or more binders.
hol_domain_of_binder cfg pos typ returns a when typ is convertible to T a, and fails otherwise.
val lift_over_frame :
eq_config ->
binder_rewrite_config ->
Common.Pos.popt ->
binder_frame ->
eq_data ->
eq_datalift_over_frame cfg binder_cfg pos frame (a,l,r,p) lifts the equality data p : P (eq a l r) over frame using funExt.
val prepare_eq_data_under_binders :
Core.Sig_state.t ->
eq_config ->
Common.Pos.popt ->
binder_frame list ->
Core.Term.term ->
eq_data ->
eq_data * binder_frame listprepare_eq_data_under_binders ss cfg pos binders redex data lifts data over every enclosing binder on which redex depends. It returns the lifted equality data and the relevant binders.
val prepare_rewrite_from :
?at:??? ->
binder_frame list ->
Core.Sig_state.t ->
eq_config ->
Common.Pos.popt ->
Core.Term.term ->
eq_data ->
subst_under_binders ->
prepared_rewriteprepare_rewrite_from ~at binders ss cfg pos goal eq_data found prepares the equality data, predicate and rewritten term for a rewrite occurrence. binders is the already-known enclosing binder context of goal. If the redex depends on enclosing binders, the equality is lifted over the relevant ones and the context abstracts the resulting function-level occurrence. at optionally restricts replacement to selected paths.
val prepare_rewrite :
Core.Sig_state.t ->
eq_config ->
Common.Pos.popt ->
Core.Term.term ->
eq_data ->
subst_under_binders ->
prepared_rewriteprepare_rewrite ss cfg pos goal eq_data found is prepare_rewrite_from with no initial enclosing binders.
val swap :
eq_config ->
Core.Term.term ->
Core.Term.term ->
Core.Term.term ->
Core.Term.term ->
Core.Term.termswap cfg a r l t returns a term of type P (eq a l r) from a term t of type P (eq a r l).
at_selector selected path tells whether path names an occurrence of the contextual selector identifier. Paths are relative to selected.pat_l; repeated uses of the identifier are all included.
within_selector selected path tells whether path is at or below a region named by the contextual selector identifier. Paths are relative to selected.pat_l and store child indices in reverse order, so a descendant path ends with its region's path.
val rewrite_in_context :
Core.Sig_state.t ->
eq_config ->
Common.Pos.popt ->
Core.Term.term ->
eq_data ->
(int list -> bool) ->
contextual_selection ->
subst_under_binders ->
Core.Term.term
* Core.Term.binder
* Core.Term.term
* Core.Term.term
* Core.Term.term
* Core.Term.termrewrite_in_context ss cfg pos goal data at selected found prepares a rewrite inside the matched selected.pat_l, then reinserts the rewritten context and predicate into goal. data is the instantiated equality (type, LHS, RHS, proof); found records the first redex and its enclosing binders. at restricts replacement to paths relative to the matched context. The result contains the prepared equality type, whole-goal predicate binder, rewritten goal, equality proof and sides.
val rewrite :
Core.Sig_state.t ->
Core.Term.problem ->
Common.Pos.popt ->
Goal.goal_typ ->
bool ->
(Core.Term.term, Core.Term.binder) Parsing.Syntax.rwpatt option ->
Core.Term.term ->
Core.Term.termrewrite ss p pos gt l2r pat t generates a term for the refine tactic representing the application of the rewrite tactic to the goal type gt. Every occurrence of the first instance of the left-hand side is replaced by the right-hand side of the obtained proof (or the reverse if l2r is false). pat is an optional SSReflect pattern. t is the equational lemma that is applied. It handles the full set of SSReflect patterns.