Free base-variable names of a term, in left-to-right order.
Equations
- MeTTaIL.varsOf (MeTTaIL.AST.var (MeTTaIL.DottedPath.base x_1)) = [x_1]
- MeTTaIL.varsOf (MeTTaIL.AST.var path) = []
- MeTTaIL.varsOf (MeTTaIL.AST.sexp label args) = MeTTaIL.varsOfList args
- MeTTaIL.varsOf (b.subst r v) = MeTTaIL.varsOf b ++ MeTTaIL.varsOf r
Instances For
Equations
- MeTTaIL.varsOfList [] = []
- MeTTaIL.varsOfList (a :: as) = MeTTaIL.varsOf a ++ MeTTaIL.varsOfList as
Instances For
Grammar well-formedness: rules that share a label declare the same argument sorts. This is what lets a pattern and a matched subject, both headed by the same constructor, be aligned argument by argument.
Equations
Instances For
The matcher's name lookup, projected to the bound term.
Equations
- MeTTaIL.bndLookup bnds v = Option.map (fun (x : String × MeTTaIL.AST) => x.2) (List.find? (fun (b : String × MeTTaIL.AST) => b.1 == v) bnds)
Instances For
bnds is a well-sorted substitution for Δ over Γ: each Δ-variable it binds is bound to a term
that is well-sorted at that variable's sort.
Equations
- MeTTaIL.WSsub p Γ Δ bnds = ∀ (y : String) (ty : MeTTaIL.AST) (cy : MeTTaIL.Cat), MeTTaIL.bndLookup bnds y = some ty → List.lookup y Δ = some cy → MeTTaIL.WellSorted p Γ ty cy
Instances For
Inversions for the well-sortedness relation #
A well-sorted application reveals the rule that types it.
A well-sorted argument list at the empty sort list is empty.
A well-sorted nonempty argument list splits head and tail.
A well-sorted argument list at a nonempty sort list splits, aligning head and head-sort.
Replacing one argument of a well-sorted list by a same-sorted term keeps the list well-sorted. The replacement need only preserve sorts at whatever sort the original argument had.
Variable matching either leaves the bindings unchanged (a consistent re-match, so the variable was already bound) or prepends a new binding (so the variable was previously unbound).
Shared matcher inversions #
Three small inversions factor out the structural unfolding the three families below (monotonicity, coverage, the substitution invariant) all repeat: a constructor-headed pattern forces the subject's head and reduces to a list match, and a cons list match splits into a head match and a tail match.
Monotonicity: matching only extends the binding set #
The matcher either leaves the bindings untouched (an already-bound variable that matches consistently) or prepends a new one. Either way a binding once present is found unchanged afterwards.
Matching a well-sorted pattern preserves every existing binding.
Matching a well-sorted argument list preserves every existing binding.
bndLookup version of monotonicity through a list match.
Coverage: matching binds every pattern variable #
Every variable of a well-sorted pattern is bound after a successful match.
Every variable of a well-sorted argument list is bound after a successful list match.
The well-sorted-substitution invariant #
Matching a well-sorted subject against a well-sorted pattern keeps the bindings a well-sorted substitution: each variable is bound to a term well-sorted at that variable's declared sort.
Matching against a well-sorted pattern preserves the well-sorted-substitution invariant.
Matching an argument list against a well-sorted pattern list preserves the invariant.
Subject reduction for a base rewrite #
The two halves combine: matching gives a well-sorted substitution (matchPat_wssub) that covers every
pattern variable (matchPat_cover), and instantiation preserves well-sortedness (inst_wellSorted). So a
base rewrite whose two sides are well-sorted under a shared context, applied to a well-sorted subject,
yields a well-sorted result at the same sort.
Lifting through the reduction relation #
Subject reduction lifts from base contractions to the runtime's full one-step RewStep and many-step
RewStepMany. The congruence case (a step inside an argument) holds because the argument keeps its sort,
and the Subst cases are vacuous: a well-sorted term has no Subst node. The top-level hypothesis is
exactly base-contraction preservation, supplied by subjectReduction_base for well-sorted rules.
One-step subject reduction: if base reductions preserve sorts, so does the context-closed RewStep.
Many-step subject reduction: sorts are preserved along any reduction sequence.
A worked instance: recursive subject reduction with a variable rule #
srPres declares a sort T, a constant a, and two unary symbols f, g, with the rewrite
(f x) ~> (g x) carrying a real pattern variable x : T. Reducing the ground term (f a) binds
x to a and produces (g a); subjectReduction_sr is the machine-checked statement that the result
is well-sorted at T, obtained from subjectReduction_base (so every subterm keeps its declared sort
across the variable-instantiating step).
A presentation with a constant, two unary symbols, and a variable-carrying rewrite.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The pattern (f x) is well-sorted at T in the context x : T.
The contractum (g x) is well-sorted at T in the same context.
The subject (f a) is well-sorted at T in the empty context (it is ground).