Documentation

Lean.Meta.Sym.Canon

Type-directed canonicalizer #

Canonicalizes expressions by normalizing types and instances. At the top level, it traverses applications, foralls, lambdas, and let-bindings, classifying each argument as a type, instance, implicit, or value using shouldCanon. Values are recursively visited but not normalized. Types and instances receive targeted reductions.

Reductions (applied only in type positions) #

Instance canonicalization #

Instances are re-synthesized via synthInstance. The instance type is first normalized using the type-level reductions above, so that OfNat (Fin (2+1)) 0 and OfNat (Fin 3) 0 produce the same canonical instance.

Two caches #

The canonicalizer maintains separate caches for type-level and value-level contexts. The same expression may canonicalize differently depending on whether it appears in a type position (where reductions are applied) or a value position (where it is only traversed). Caches are keyed by Expr (structural equality), not pointer equality, because the canonicalizer runs before shareCommon and enters binders using locally nameless representation.

Future work #

If needed we should add support for user-defined extensions.

Returns true if shouldCannon pinfos i arg is not .visit. This is a helper function used to implement mbtc.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Canonicalize e by normalizing types, instances, and support arguments. Types receive targeted reductions (eta, projection, match/ite, Nat arithmetic). Instances are re-synthesized. Values are traversed but not reduced. Runs at reducible transparency.

    Equations
    Instances For