Equations
- Lean.Meta.smartUnfoldingSuffix = "_sunfold"
Equations
- Lean.Meta.mkSmartUnfoldingNameFor declName = Lean.Name.mkStr declName Lean.Meta.smartUnfoldingSuffix
Equations
- Lean.Meta.hasSmartUnfoldingDecl env declName = Lean.Environment.contains env (Lean.Meta.mkSmartUnfoldingNameFor declName)
Add auxiliary annotation to indicate the match
-expression e
must be reduced when performing smart unfolding.
Equations
- Lean.Meta.markSmartUnfoldingMatch e = Lean.mkAnnotation `sunfoldMatch e
Equations
- Lean.Meta.smartUnfoldingMatch? e = Lean.annotation? `sunfoldMatch e
Add auxiliary annotation to indicate expression e
(a match
alternative rhs) was successfully reduced by smart unfolding.
Equations
- Lean.Meta.markSmartUnfoldingMatchAlt e = Lean.mkAnnotation `sunfoldMatchAlt e
Equations
- Lean.Meta.smartUnfoldingMatchAlt? e = Lean.annotation? `sunfoldMatchAlt e
Equations
- Lean.Meta.isAuxDef constName = do let env ← Lean.getEnv pure (Lean.isAuxRecursor env constName || Lean.isNoConfusion env constName)
Equations
- One or more equations did not get rendered due to their size.
Create the i
th projection major
. It tries to use the auto-generated projection functions if available. Otherwise falls back
to Expr.proj
.
Equations
- One or more equations did not get rendered due to their size.
Return some (Expr.mvar mvarId)
if metavariable mvarId
is blocking reduction.
Auxiliary combinator for handling easy WHNF cases. It takes a function for handling the "hard" cases as an argument
- reduced: Lean.Expr → Lean.Meta.ReduceMatcherResult
- stuck: Lean.Expr → Lean.Meta.ReduceMatcherResult
- notMatcher: Lean.Meta.ReduceMatcherResult
- partialApp: Lean.Meta.ReduceMatcherResult
The "match" compiler uses if-then-else
expressions and other auxiliary declarations to compile match-expressions such as
match v with
| 'a' => 1
| 'b' => 2
| _ => 3
because it is more efficient than using casesOn
recursors.
The method reduceMatcher?
fails if these auxiliary definitions (e.g., ite
) cannot be unfolded in the current
transparency setting. This is problematic because tactics such as simp
use TransparencyMode.reducible
, and
most users assume that expressions such as
match 0 with
| 0 => 1
| 100 => 2
| _ => 3
should reduce in any transparency mode.
Thus, we define a custom canUnfoldAtMatcher
predicate for whnfMatcher
.
This solution is not very modular because modications at the match
compiler require changes here.
We claim this is defensible because it is reducing the auxiliary declaration defined by the match
compiler.
Alternative solution: tactics that use TransparencyMode.reducible
should rely on the equations we generated for match-expressions.
This solution is also not perfect because the match-expression above will not reduce during type checking when we are not using
TransparencyMode.default
or TransparencyMode.all
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Reduce kernel projection Expr.proj ..
expression.
Equations
- Lean.Meta.reduceProj? e = match e with | Lean.Expr.proj a i c a_1 => Lean.Meta.project? c i | x => pure none
Apply beta-reduction, zeta-reduction (i.e., unfold let local-decls), iota-reduction, expand let-expressions, expand assigned meta-variables.
Recall that _sunfold
auxiliary definitions contains the markers: markSmartUnfoldingMatch
(*) and markSmartUnfoldingMatchAlt
(**).
For example, consider the following definition
def r (i j : Nat) : Nat :=
i +
match j with
| Nat.zero => 1
| Nat.succ j =>
i + match j with
| Nat.zero => 2
| Nat.succ j => r i j
produces the following _sunfold
auxiliary definition with the markers
def r._sunfold (i j : Nat) : Nat :=
i +
(*) match j with
| Nat.zero => (**) 1
| Nat.succ j =>
i + (*) match j with
| Nat.zero => (**) 2
| Nat.succ j => (**) r i j
match
expressions marked with markSmartUnfoldingMatch
(*) must be reduced, otherwise the resulting term is not definitionally
equal to the given expression. The recursion may be interrupted as soon as the annotation markSmartUnfoldingAlt
(**) is reached.
For example, the term r i j.succ.succ
reduces to the definitionally equal term i + i * r i j
Auxiliary method for unfolding a class projection.
Unfold definition using "smart unfolding" if possible.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.whnfUntil e declName = do let e ← Lean.Meta.whnfHeadPred e fun e => pure !Lean.Expr.isAppOf e declName if Lean.Expr.isAppOf e declName = true then pure (some e) else pure none
Try to reduce matcher/recursor/quot applications. We say they are all "morally" recursor applications.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.reduceBoolNativeUnsafe constName = Lean.evalConstCheck Bool `Bool constName
Equations
- Lean.Meta.reduceNatNativeUnsafe constName = Lean.evalConstCheck Nat `Nat constName
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.reduceUnaryNatOp f a = Lean.Meta.withNatValue a fun a => pure (some (Lean.mkRawNatLit (f a)))
Equations
- Lean.Meta.reduceBinNatPred f a b = Lean.Meta.withNatValue a fun a => Lean.Meta.withNatValue b fun b => pure (some (Lean.toExpr (f a b)))
Equations
- One or more equations did not get rendered due to their size.
If e
is a projection function that satisfies p
, then reduce it
Equations
- One or more equations did not get rendered due to their size.