Normalization for module expressions #
Weak normalization: every well-typed module expression terminates. Split off from
ModuleExpressionBasics.lean (which develops syntax, typing, reduction and normal forms
without it) so that this — the other deep open fact besides confluence — stands on its own;
ModuleExpression.lean collects the consequences.
The proof is Tait's reducibility (logical relations) in its Kripke form: Red T Γ m says that
m is a well-typed weakly normalizing term of type T in context Γ, hereditarily so under
every elimination the type allows. The function case quantifies over all renamings Γ → Γ',
which is what makes the relation stable under weakening (Red.rename) — needed because the
abs case of the fundamental lemma goes under a binder.
The three candidate properties are Red.weaklyNormalizing/Red.hasType (CR1),
Red.of_step/Red.of_multiStep (backward closure, CR2) and Red.of_neutral (CR3, here in the
sharp form "a normal neutral term is reducible", since Neutral in this development already
means normal neutral). HasType.red_substituteSimultaneously is the fundamental lemma and
HasType.terminating its corollary at the identity substitution.
Renaming preserves reduction and normal forms #
A de Bruijn renaming touches only variables, so every syntactic notion of the reduction theory
is stable under it. These are the facts the Kripke clause of Red needs.
Being a procedure tuple is a property of the term's shape, not of its variables, so a renaming cannot create one.
Normal forms are stable under renaming.
Neutral forms are stable under renaming.
Reduction is stable under renaming.
Multi-step reduction is stable under renaming.
Weak normalization #
Terminating asks for a stuck reduct; the reducibility argument needs the sharper "reduces to
a normal form", which is stable under renaming (a stuck term need not stay stuck under a
renaming for any obvious syntactic reason, whereas a normal term visibly does). For well-typed
terms the two agree — Stuck.normal — and that is how Terminating is recovered at the end.
m reduces to a normal form. Refines Terminating.
Equations
- m.WeaklyNormalizing = ∃ (n : GaudisCrypt.ModuleExpression), m.MultiStepReduction n ∧ n.Normal
Instances For
Weak normalization is closed under expansion by a single step.
Weak normalization is closed under expansion along a multi-step reduction.
Renamings compose #
The reducibility relation #
Tait's reducibility candidates, Kripke-style. Red T Γ m says: m has type T in Γ and
is weakly normalizing, and hereditarily so under the eliminations T allows — projections at
a product type, and application to a reducible argument (in any context reachable from Γ by
a renaming) at a function type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
CR1, typing half.
CR1, normalization half.
CR2: reducibility is closed under expansion by a single step.
CR2 along a multi-step reduction.
CR3: a well-typed normal neutral term is reducible. (Neutral already implies Normal
in this development, so no reasoning about the term's reducts is needed.)
Reducibility is stable under weakening (any renaming of the context).
The fundamental lemma #
A substitution all of whose values are reducible at the type their index carries.
Equations
- GaudisCrypt.ModuleExpression.RedSubst Δ Γ σ = ∀ {n : ℕ} (h : n < List.length Δ), GaudisCrypt.ModuleExpression.Red Δ[n] Γ (σ n)
Instances For
Lifting a reducible substitution under a binder keeps it reducible.
The fundamental lemma of the reducibility argument: a well-typed term is reducible under every reducible substitution.
Weak normalization #
Weak normalization: every well-typed module expression reduces to a normal form, hence terminates. Instantiate the fundamental lemma at the identity substitution, which is reducible because a variable is a normal neutral term.