Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Parameterized Kripke Logical Relation, Relation-Bundle Equivalence, and Semantic Validity

Definition
Abel2018_LogicalRelation

by kmehltretter82 · Nov 7, 2026 · Mathlib 0df444a (Lean v4.33.1)

conversion-checkingdecidabilitydependent-typeslogical-relationsnormalizationtype-theory

Section 3.2 to Section 3.6: Reducibility predicates for neutral types (RedNe) and natural numbers (RedNat, RedNatTerm, RedNatTermEq), the Kripke logical relation (LogRel, LogRelAt) parameterized by eqrel : EqRelSet and stratified across the two-element metatheoretic index TypeLevel (zero < one) to represent the paper's inductive-recursive universe reducibility in Lean 4, relation bundles (RedRel) and bundle equivalence (RedRelEquiv), decoded reducibility judgments (RedType, RedEq, RedTerm, RedTermEq), and semantic substitution validity (ValidSubst, ValidSubstEq, FundCtxMotive, FundTypeMotive, FundTermMotive, FundTypeEqMotive, FundTermEqMotive).

Definition code
/-
Copyright (c) 2016 Joakim Öhman, Andrea Vezzosi, Andreas Abel.
Lean translation prepared for the Feasible Univalence project, 2026.
Released under the MIT license; see the source artifact LICENSE.

Source: Andreas Abel, Joakim Öhman, and Andrea Vezzosi,
"Decidability of Conversion for Type Theory in Type Theory",
Proceedings of the ACM on Programming Languages 2(POPL), Article 23, 2018
(doi:10.1145/3158111), Section 3, and Agda artifact mr-ohman/logrel-mltt v2.1
(commit eb2b15ab1c4b45923025834d3bb798943cb44b8e),
Definition/LogicalRelation.agda, Definition/LogicalRelation/Substitution.agda,
and Definition/LogicalRelation/Fundamental.agda.
-/
import Definitions.Def_Abel2018_Algorithm

namespace Abel2018

/-- Reducible neutral type with explicit WHNF `K` (`Γ ⊩ne A`). -/
structure RedNeAt (eqrel : EqRelSet) (Γ : Context) (A K : Term) : Prop where
  D : TypeStarWf Γ A K
  neK : Neutral K
  KeqK : eqrel.NeEqRel Γ K K .univ

/-- Reducible neutral type (`Γ ⊩ne A`). -/
inductive RedNe (eqrel : EqRelSet) (Γ : Context) (A : Term) : Prop where
  | mk (K : Term) (D : TypeStarWf Γ A K) (neK : Neutral K) (KeqK : eqrel.NeEqRel Γ K K .univ)

/-- Reducible neutral type equality (`Γ ⊩ne A ≡ B / [A]`). -/
inductive RedNeEq (eqrel : EqRelSet) (Γ : Context) (K B : Term) : Prop where
  | mk (M : Term) (D' : TypeStarWf Γ B M) (neM : Neutral M) (KeqM : eqrel.NeEqRel Γ K M .univ)

/-- Reducible neutral term in WHNF (`Γ ⊩neNf k ∷ A`). -/
structure RedNeNf (eqrel : EqRelSet) (Γ : Context) (k A : Term) : Prop where
  neK : Neutral k
  hk : HasType Γ k A
  keqk : eqrel.NeEqRel Γ k k A

/-- Reducible neutral term (`Γ ⊩ne t ∷ A / [A]`). -/
inductive RedNeTerm (eqrel : EqRelSet) (Γ : Context) (K t : Term) : Prop where
  | mk (k : Term) (d : StarWf Γ t k K) (nf : RedNeNf eqrel Γ k K)

/-- Reducible neutral term equality in WHNF (`Γ ⊩neNf k ≡ m ∷ A`). -/
structure RedNeNfEq (eqrel : EqRelSet) (Γ : Context) (k m A : Term) : Prop where
  neK : Neutral k
  neM : Neutral m
  keqm : eqrel.NeEqRel Γ k m A

/-- Reducible neutral term equality (`Γ ⊩ne t ≡ u ∷ A / [A]`). -/
inductive RedNeTermEq (eqrel : EqRelSet) (Γ : Context) (K t u : Term) : Prop where
  | mk (k m : Term) (d : StarWf Γ t k K) (d' : StarWf Γ u m K) (nf : RedNeNfEq eqrel Γ k m K)

/-- Reducible natural number type (`Γ ⊩ℕ A`). -/
abbrev RedNat (Γ : Context) (A : Term) : Prop :=
  TypeStarWf Γ A .nat

/-- Reducible natural number type equality (`Γ ⊩ℕ A ≡ B`). -/
abbrev RedNatEq (Γ : Context) (B : Term) : Prop :=
  TypeStar Γ B .nat

mutual
  /-- Reducible natural number term (`Γ ⊩ℕ t ∷ℕ`). -/
  inductive RedNatTerm (eqrel : EqRelSet) (Γ : Context) : Term → Prop where
    | mk (t n : Term)
        (d : StarWf Γ t n .nat)
        (neqn : eqrel.TermEqRel Γ n n .nat)
        (prop : NaturalProp eqrel Γ n) :
        RedNatTerm eqrel Γ t

  /-- WHNF property of reducible natural number terms (`Natural-prop`). -/
  inductive NaturalProp (eqrel : EqRelSet) (Γ : Context) : Term → Prop where
    | suc {n : Term} : RedNatTerm eqrel Γ n → NaturalProp eqrel Γ (.succ n)
    | zero : NaturalProp eqrel Γ .zero
    | ne {n : Term} : RedNeNf eqrel Γ n .nat → NaturalProp eqrel Γ n
end

mutual
  /-- Reducible natural number term equality (`Γ ⊩ℕ t ≡ u ∷ℕ`). -/
  inductive RedNatTermEq (eqrel : EqRelSet) (Γ : Context) : Term → Term → Prop where
    | mk (t u k k' : Term)
        (d : StarWf Γ t k .nat)
        (d' : StarWf Γ u k' .nat)
        (keqk' : eqrel.TermEqRel Γ k k' .nat)
        (prop : NaturalEqProp eqrel Γ k k') :
        RedNatTermEq eqrel Γ t u

  /-- WHNF property of reducible natural number term equality (`[Natural]-prop`). -/
  inductive NaturalEqProp (eqrel : EqRelSet) (Γ : Context) : Term → Term → Prop where
    | suc {n n' : Term} : RedNatTermEq eqrel Γ n n' → NaturalEqProp eqrel Γ (.succ n) (.succ n')
    | zero : NaturalEqProp eqrel Γ .zero .zero
    | ne {n n' : Term} : RedNeNfEq eqrel Γ n n' .nat → NaturalEqProp eqrel Γ n n'
end

/-- Universe levels `⁰` and `¹`. -/
inductive TypeLevel where
  | zero
  | one
  deriving DecidableEq, Repr

/-- Strict ordering `⁰ < ¹` on `TypeLevel`. -/
inductive TypeLevelLT : TypeLevel → TypeLevel → Prop where
  | zeroLT : TypeLevelLT .zero .one

/-- Bundle of decoded relations for a reducible type:
type equality (`eqType`), term reducibility (`hasTerm`), and term equality (`eqTerm`). -/
structure RedRel : Type 1 where
  eqType : Term → Prop
  hasTerm : Term → Prop
  eqTerm : Term → Term → Prop

/-- Equivalence of two `RedRel` bundles across all three decoded predicates. -/
def RedRelEquiv (rel₁ rel₂ : RedRel) : Prop :=
  (∀ {B}, rel₁.eqType B ↔ rel₂.eqType B) ∧
  (∀ {t}, rel₁.hasTerm t ↔ rel₂.hasTerm t) ∧
  (∀ {t u}, rel₁.eqTerm t u ↔ rel₂.eqTerm t u)

/-- Reducible universe type with explicit lower level `l'` (`Γ ⊩¹U`). -/
structure RedUAt (l' l : TypeLevel) (Γ : Context) : Prop where
  lt : TypeLevelLT l' l
  wf : CtxWf Γ

/-- Reducible universe type (`Γ ⊩¹U`). -/
inductive RedU (l : TypeLevel) (Γ : Context) : Prop where
  | mk (l' : TypeLevel) (lt : TypeLevelLT l' l) (wf : CtxWf Γ)

/-- Reducible term of universe type (`Γ ⊩¹U t ∷U/ l<`). -/
inductive RedUTerm (eqrel : EqRelSet) (rec : Context → Term → RedRel → Prop)
    (Γ : Context) (t : Term) : Prop where
  | mk (A : Term)
      (d : StarWf Γ t A .univ)
      (typeA : SmallTypeView A)
      (AeqA : eqrel.TermEqRel Γ A A .univ)
      (ht : ∃ rel, rec Γ t rel)

/-- Reducible term equality of universe type (`Γ ⊩¹U t ≡ u ∷U/ l<`). -/
inductive RedUTermEq (eqrel : EqRelSet) (rec : Context → Term → RedRel → Prop)
    (Γ : Context) (t u : Term) : Prop where
  | mk (A B : Term)
      (d : StarWf Γ t A .univ)
      (d' : StarWf Γ u B .univ)
      (typeA : SmallTypeView A)
      (typeB : SmallTypeView B)
      (AeqB : eqrel.TermEqRel Γ A B .univ)
      (relt : RedRel)
      (ht : rec Γ t relt)
      (hu : ∃ relu, rec Γ u relu)
      (tequ : relt.eqType u)

/-- Relation bundle for `U`. -/
def RedURel (eqrel : EqRelSet) (rec : Context → Term → RedRel → Prop) (Γ : Context) : RedRel where
  eqType B := B = .univ
  hasTerm t := RedUTerm eqrel rec Γ t
  eqTerm t u := RedUTermEq eqrel rec Γ t u

/-- Relation bundle for `ℕ`. -/
def RedNatRel (eqrel : EqRelSet) (Γ : Context) : RedRel where
  eqType B := RedNatEq Γ B
  hasTerm t := RedNatTerm eqrel Γ t
  eqTerm t u := RedNatTermEq eqrel Γ t u

/-- Relation bundle for neutral types. -/
def RedNeRel (eqrel : EqRelSet) (Γ : Context) (K : Term) : RedRel where
  eqType B := RedNeEq eqrel Γ K B
  hasTerm t := RedNeTerm eqrel Γ K t
  eqTerm t u := RedNeTermEq eqrel Γ K t u

/-- Helper predicates for domain and codomain relation families in `Π`. -/
abbrev RelFEqType (relF : Wk → Context → RedRel → Prop) (ρ : Wk) (Δ : Context) (B : Term) : Prop :=
  ∃ rel, relF ρ Δ rel ∧ rel.eqType B

abbrev RelFHasTerm (relF : Wk → Context → RedRel → Prop) (ρ : Wk) (Δ : Context) (a : Term) : Prop :=
  ∃ rel, relF ρ Δ rel ∧ rel.hasTerm a

abbrev RelFEqTerm (relF : Wk → Context → RedRel → Prop) (ρ : Wk) (Δ : Context) (a b : Term) : Prop :=
  ∃ rel, relF ρ Δ rel ∧ rel.eqTerm a b

abbrev RelGEqType (relG : Wk → Context → Term → RedRel → Prop)
    (ρ : Wk) (Δ : Context) (a B : Term) : Prop :=
  ∃ rel, relG ρ Δ a rel ∧ rel.eqType B

abbrev RelGHasTerm (relG : Wk → Context → Term → RedRel → Prop)
    (ρ : Wk) (Δ : Context) (a t : Term) : Prop :=
  ∃ rel, relG ρ Δ a rel ∧ rel.hasTerm t

abbrev RelGEqTerm (relG : Wk → Context → Term → RedRel → Prop)
    (ρ : Wk) (Δ : Context) (a t u : Term) : Prop :=
  ∃ rel, relG ρ Δ a rel ∧ rel.eqTerm t u

/-- Reducible `Π`-type equality (`Γ ⊩¹Π A ≡ B / [A]`). -/
inductive RedPiEq (eqrel : EqRelSet) (Γ : Context) (F G : Term)
    (relF : Wk → Context → RedRel → Prop)
    (relG : Wk → Context → Term → RedRel → Prop)
    (B : Term) : Prop where
  | mk (F' G' : Term)
      (D' : TypeStar Γ B (.pi F' G'))
      (AeqB : eqrel.TypeEqRel Γ (.pi F G) (.pi F' G'))
      (FeqF' : ∀ {ρ Δ}, WkCtx ρ Δ Γ → CtxWf Δ → RelFEqType relF ρ Δ (wk ρ F'))
      (GeqG' : ∀ {ρ Δ a}, WkCtx ρ Δ Γ → CtxWf Δ → RelFHasTerm relF ρ Δ a →
        RelGEqType relG ρ Δ a (subst0 (wk (.lift ρ) G') a))

/-- Reducible term of `Π`-type (`Γ ⊩¹Π t ∷ A / [A]`). -/
inductive RedPiTerm (eqrel : EqRelSet) (Γ : Context) (F G : Term)
    (relF : Wk → Context → RedRel → Prop)
    (relG : Wk → Context → Term → RedRel → Prop)
    (t : Term) : Prop where
  | mk (f : Term)
      (d : StarWf Γ t f (.pi F G))
      (funcF : FunctionView f)
      (feqf : eqrel.TermEqRel Γ f f (.pi F G))
      (appEq : ∀ {ρ Δ a b}, WkCtx ρ Δ Γ → CtxWf Δ →
        RelFHasTerm relF ρ Δ a →
        RelFHasTerm relF ρ Δ b →
        RelFEqTerm relF ρ Δ a b →
        RelGEqTerm relG ρ Δ a (.app (wk ρ f) a) (.app (wk ρ f) b))
      (appTerm : ∀ {ρ Δ a}, WkCtx ρ Δ Γ → CtxWf Δ →
        RelFHasTerm relF ρ Δ a →
        RelGHasTerm relG ρ Δ a (.app (wk ρ f) a))

/-- Reducible term equality of `Π`-type (`Γ ⊩¹Π t ≡ u ∷ A / [A]`). -/
inductive RedPiTermEq (eqrel : EqRelSet) (Γ : Context) (F G : Term)
    (relF : Wk → Context → RedRel → Prop)
    (relG : Wk → Context → Term → RedRel → Prop)
    (t u : Term) : Prop where
  | mk (f g : Term)
      (d : StarWf Γ t f (.pi F G))
      (d' : StarWf Γ u g (.pi F G))
      (funcF : FunctionView f)
      (funcG : FunctionView g)
      (feqg : eqrel.TermEqRel Γ f g (.pi F G))
      (ht : RedPiTerm eqrel Γ F G relF relG t)
      (hu : RedPiTerm eqrel Γ F G relF relG u)
      (appEq : ∀ {ρ Δ a}, WkCtx ρ Δ Γ → CtxWf Δ →
        RelFHasTerm relF ρ Δ a →
        RelGEqTerm relG ρ Δ a (.app (wk ρ f) a) (.app (wk ρ g) a))

/-- Relation bundle for `Π`-types. -/
def RedPiRel (eqrel : EqRelSet) (Γ : Context) (F G : Term)
    (relF : Wk → Context → RedRel → Prop)
    (relG : Wk → Context → Term → RedRel → Prop) : RedRel where
  eqType B := RedPiEq eqrel Γ F G relF relG B
  hasTerm t := RedPiTerm eqrel Γ F G relF relG t
  eqTerm t u := RedPiTermEq eqrel Γ F G relF relG t u

/-- One level of the logical relation (`LogRel` in `Definition/LogicalRelation.agda`),
parameterized by the lower-level relation `rec`. -/
inductive LogRel (eqrel : EqRelSet) (l : TypeLevel)
    (rec : ∀ (l' : TypeLevel), TypeLevelLT l' l → Context → Term → RedRel → Prop) :
    Context → Term → RedRel → Prop where
  | U {Γ : Context} {l' : TypeLevel} (hU : RedUAt l' l Γ) :
      LogRel eqrel l rec Γ .univ (RedURel eqrel (rec l' hU.lt) Γ)
  | nat {Γ : Context} {A : Term} (D : RedNat Γ A) :
      LogRel eqrel l rec Γ A (RedNatRel eqrel Γ)
  | ne {Γ : Context} {A K : Term} (neA : RedNeAt eqrel Γ A K) :
      LogRel eqrel l rec Γ A (RedNeRel eqrel Γ K)
  | pi {Γ : Context} {A F G : Term}
      (D : TypeStarWf Γ A (.pi F G))
      (hF : TypeWf Γ F)
      (hG : TypeWf (F :: Γ) G)
      (AeqA : eqrel.TypeEqRel Γ (.pi F G) (.pi F G))
      (relF : Wk → Context → RedRel → Prop)
      (relG : Wk → Context → Term → RedRel → Prop)
      (hF_ex : ∀ {ρ Δ}, WkCtx ρ Δ Γ → CtxWf Δ → ∃ rel, relF ρ Δ rel)
      (derivF : ∀ {ρ Δ} (_hρ : WkCtx ρ Δ Γ) (_hΔ : CtxWf Δ) (rel : RedRel),
        relF ρ Δ rel → LogRel eqrel l rec Δ (wk ρ F) rel)
      (hG_ex : ∀ {ρ Δ a}, WkCtx ρ Δ Γ → CtxWf Δ →
        RelFHasTerm relF ρ Δ a → ∃ rel, relG ρ Δ a rel)
      (derivG : ∀ {ρ Δ a} (_hρ : WkCtx ρ Δ Γ) (_hΔ : CtxWf Δ)
        (_ha : RelFHasTerm relF ρ Δ a) (rel : RedRel),
        relG ρ Δ a rel → LogRel eqrel l rec Δ (subst0 (wk (.lift ρ) G) a) rel)
      (Gext : ∀ {ρ Δ a b}, WkCtx ρ Δ Γ → CtxWf Δ →
        RelFHasTerm relF ρ Δ a →
        RelFHasTerm relF ρ Δ b →
        RelFEqTerm relF ρ Δ a b →
        RelGEqType relG ρ Δ a (subst0 (wk (.lift ρ) G) b)) :
      LogRel eqrel l rec Γ A (RedPiRel eqrel Γ F G relF relG)
  | emb {Γ : Context} {A : Term} {l' : TypeLevel} {rel : RedRel}
      (hlt : TypeLevelLT l' l)
      (hA : rec l' hlt Γ A rel) :
      LogRel eqrel l rec Γ A rel

/-- Empty lower-level relation at level `⁰`. -/
def logRelRecZero : ∀ (l' : TypeLevel), TypeLevelLT l' .zero → Context → Term → RedRel → Prop :=
  fun _ hlt ↦ nomatch hlt

/-- Level recursion for `LogRel` (`logRelRec` in `Definition/LogicalRelation.agda`). -/
def logRelRec (eqrel : EqRelSet) :
    ∀ (l l' : TypeLevel), TypeLevelLT l' l → Context → Term → RedRel → Prop
  | .zero => logRelRecZero
  | .one => fun _ .zeroLT ↦ LogRel eqrel .zero logRelRecZero

/-- The logical relation at level `l` (`kit l`). -/
abbrev LogRelAt (eqrel : EqRelSet) (l : TypeLevel) : Context → Term → RedRel → Prop :=
  LogRel eqrel l (logRelRec eqrel l)

/-- Reducibility of a type at level `l` (`Γ ⊩⟨ l ⟩ A`). -/
def RedType (eqrel : EqRelSet) (l : TypeLevel) (Γ : Context) (A : Term) : Prop :=
  ∃ rel, LogRelAt eqrel l Γ A rel

/-- Reducible type equality (`Γ ⊩⟨ l ⟩ A ≡ B / [A]`). -/
def RedEq {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (_hA : RedType eqrel l Γ A) (B : Term) : Prop :=
  ∃ rel, LogRelAt eqrel l Γ A rel ∧ rel.eqType B

/-- Reducible term (`Γ ⊩⟨ l ⟩ t ∷ A / [A]`). -/
def RedTerm {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (_hA : RedType eqrel l Γ A) (t : Term) : Prop :=
  ∃ rel, LogRelAt eqrel l Γ A rel ∧ rel.hasTerm t

/-- Reducible term equality (`Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]`). -/
def RedTermEq {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (_hA : RedType eqrel l Γ A) (t u : Term) : Prop :=
  ∃ rel, LogRelAt eqrel l Γ A rel ∧ rel.eqTerm t u

/-- Bundled `Π`-reducibility data with explicit domain `F` and codomain `G` (`Γ ⊩′⟨ l ⟩Π A`). -/
structure RedPiAt (eqrel : EqRelSet) (l : TypeLevel) (Γ : Context) (A F G : Term) : Prop where
  D : TypeStarWf Γ A (.pi F G)
  hF : TypeWf Γ F
  hG : TypeWf (F :: Γ) G
  AeqA : eqrel.TypeEqRel Γ (.pi F G) (.pi F G)
  redF : ∀ {ρ Δ}, WkCtx ρ Δ Γ → CtxWf Δ → RedType eqrel l Δ (wk ρ F)
  redG : ∀ {ρ Δ a} (hρ : WkCtx ρ Δ Γ) (hΔ : CtxWf Δ),
    RedTerm (redF hρ hΔ) a → RedType eqrel l Δ (subst0 (wk (.lift ρ) G) a)
  Gext : ∀ {ρ Δ a b} (hρ : WkCtx ρ Δ Γ) (hΔ : CtxWf Δ)
    (ha : RedTerm (redF hρ hΔ) a) (_hb : RedTerm (redF hρ hΔ) b),
    RedTermEq (redF hρ hΔ) a b →
    RedEq (redG hρ hΔ ha) (subst0 (wk (.lift ρ) G) b)

/-- Bundled `Π`-reducibility data (`Γ ⊩′⟨ l ⟩Π A`). -/
inductive RedPi (eqrel : EqRelSet) (l : TypeLevel) (Γ : Context) (A : Term) : Prop where
  | mk (F G : Term)
      (D : TypeStarWf Γ A (.pi F G))
      (hF : TypeWf Γ F)
      (hG : TypeWf (F :: Γ) G)
      (AeqA : eqrel.TypeEqRel Γ (.pi F G) (.pi F G))
      (redF : ∀ {ρ Δ}, WkCtx ρ Δ Γ → CtxWf Δ → RedType eqrel l Δ (wk ρ F))
      (redG : ∀ {ρ Δ a} (hρ : WkCtx ρ Δ Γ) (hΔ : CtxWf Δ),
        RedTerm (redF hρ hΔ) a → RedType eqrel l Δ (subst0 (wk (.lift ρ) G) a))
      (Gext : ∀ {ρ Δ a b} (hρ : WkCtx ρ Δ Γ) (hΔ : CtxWf Δ)
        (ha : RedTerm (redF hρ hΔ) a) (_hb : RedTerm (redF hρ hΔ) b),
        RedTermEq (redF hρ hΔ) a b →
        RedEq (redG hρ hΔ ha) (subst0 (wk (.lift ρ) G) b))

/-- Logical relation for substitutions (`Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ`). -/
def ValidSubst (eqrel : EqRelSet) (Δ : Context) (σ : Subst) : Context → Prop
  | [] => True
  | A :: Γ =>
      ValidSubst eqrel Δ (tailSubst σ) Γ ∧
      ∃ (l : TypeLevel) (pA : RedType eqrel l Δ (subst (tailSubst σ) A)),
        RedTerm pA (headSubst σ)

/-- Logical relation for equality of substitutions (`Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]`). -/
def ValidSubstEq (eqrel : EqRelSet) (Δ : Context) (σ σ' : Subst) : Context → Prop
  | [] => True
  | A :: Γ =>
      ValidSubstEq eqrel Δ (tailSubst σ) (tailSubst σ') Γ ∧
      ∃ (l : TypeLevel) (pA : RedType eqrel l Δ (subst (tailSubst σ) A)),
        RedTermEq pA (headSubst σ) (headSubst σ')

/-- Pointwise type validity at a target context `Δ` and substitution `σ`. -/
structure ValidTypeAt (eqrel : EqRelSet) (l : TypeLevel) (Δ Γ : Context)
    (σ : Subst) (A : Term) : Prop where
  red : RedType eqrel l Δ (subst σ A)
  eq : ∀ {σ' : Subst},
    ValidSubst eqrel Δ σ' Γ →
    ValidSubstEq eqrel Δ σ σ' Γ →
    RedEq red (subst σ' A)

/-- Validity of types (`Γ ⊩ᵛ⟨ l ⟩ A / [Γ]`). -/
def ValidType (eqrel : EqRelSet) (l : TypeLevel) (Γ : Context) (A : Term) : Prop :=
  ∀ {Δ : Context} {σ : Subst},
    CtxWf Δ → ValidSubst eqrel Δ σ Γ →
    ValidTypeAt eqrel l Δ Γ σ A

/-- Validity of contexts (`⊩ᵛ Γ`). -/
inductive ValidCtx (eqrel : EqRelSet) : Context → Prop where
  | nil : ValidCtx eqrel []
  | cons {Γ : Context} {A : Term} {l : TypeLevel} :
      ValidCtx eqrel Γ → ValidType eqrel l Γ A → ValidCtx eqrel (A :: Γ)

/-- Pointwise term validity at a target context `Δ` and substitution `σ`. -/
structure ValidTermAt {eqrel : EqRelSet} {l : TypeLevel} {Δ : Context} (Γ : Context)
    {σ : Subst} {A : Term} (pA : RedType eqrel l Δ (subst σ A)) (t : Term) : Prop where
  term : RedTerm pA (subst σ t)
  eq : ∀ {σ' : Subst},
    ValidSubst eqrel Δ σ' Γ →
    ValidSubstEq eqrel Δ σ σ' Γ →
    RedTermEq pA (subst σ t) (subst σ' t)

/-- Validity of terms (`Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]`). -/
def ValidTerm {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (hA : ValidType eqrel l Γ A) (t : Term) : Prop :=
  ∀ {Δ : Context} {σ : Subst} (hΔ : CtxWf Δ) (hσ : ValidSubst eqrel Δ σ Γ),
    ValidTermAt Γ (hA hΔ hσ).red t

/-- Validity of type equality (`Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A]`). -/
def ValidTypeEq {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (hA : ValidType eqrel l Γ A) (B : Term) : Prop :=
  ∀ {Δ : Context} {σ : Subst} (hΔ : CtxWf Δ) (hσ : ValidSubst eqrel Δ σ Γ),
    RedEq (hA hΔ hσ).red (subst σ B)

/-- Validity of term equality (`Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A]`). -/
def ValidTermEq {eqrel : EqRelSet} {l : TypeLevel} {Γ : Context} {A : Term}
    (hA : ValidType eqrel l Γ A) (t u : Term) : Prop :=
  ∀ {Δ : Context} {σ : Subst} (hΔ : CtxWf Δ) (hσ : ValidSubst eqrel Δ σ Γ),
    RedTermEq (hA hΔ hσ).red (subst σ t) (subst σ u)

/-- Valid term equality bundled with validity of its type and terms (`[ Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] ]`). -/
structure ModelsTermEq (eqrel : EqRelSet) (l : TypeLevel) (Γ : Context) (t u A : Term) : Prop where
  validA : ValidType eqrel l Γ A
  validt : ValidTerm validA t
  validu : ValidTerm validA u
  validEq : ValidTermEq validA t u

/-- Validity of term reduction (`Γ ⊩ᵛ t ⇒ u ∷ A / [Γ]`). -/
def ValidRedTerm (eqrel : EqRelSet) (Γ : Context) (t u A : Term) : Prop :=
  ∀ {Δ : Context} {σ : Subst},
    CtxWf Δ → ValidSubst eqrel Δ σ Γ →
    Step Δ (subst σ t) (subst σ u) (subst σ A)

abbrev FundCtxMotive (eqrel : EqRelSet) (Γ : Context) : Prop :=
  ValidCtx eqrel Γ

abbrev FundTypeMotive (eqrel : EqRelSet) (Γ : Context) (A : Term) : Prop :=
  ValidCtx eqrel Γ ∧ ValidType eqrel .one Γ A

abbrev FundTermMotive (eqrel : EqRelSet) (Γ : Context) (t A : Term) : Prop :=
  ValidCtx eqrel Γ ∧ ∃ (hA : ValidType eqrel .one Γ A), ValidTerm hA t

abbrev FundTypeEqMotive (eqrel : EqRelSet) (Γ : Context) (A B : Term) : Prop :=
  ValidCtx eqrel Γ ∧
  ∃ (hA : ValidType eqrel .one Γ A), ValidType eqrel .one Γ B ∧ ValidTypeEq hA B

abbrev FundTermEqMotive (eqrel : EqRelSet) (Γ : Context) (t u A : Term) : Prop :=
  ValidCtx eqrel Γ ∧ ModelsTermEq eqrel .one Γ t u A

end Abel2018
Source
Andreas Abel, Joakim Öhman, and Andrea Vezzosi, 'Decidability of Conversion for Type Theory in Type Theory', Proceedings of the ACM on Programming Languages (PACMPL), Vol. 2, No. POPL, Article 23, January 2018, pp. 23:1-23:29 (doi:10.1145/3158111). Mechanized Agda artifact: https://github.com/mr-ohman/logrel-mltt (commit eb2b15ab1c4b45923025834d3bb798943cb44b8e). Sections 3.2-3.6 (`LogicalRelation.agda`, `Valid.agda`).
Read-back

What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)

All definitions reside in the Abel2018 namespace (Def_Abel2018_LogicalRelation.lean) and import Def_Abel2018_Algorithm.

Base Reducibility Predicates (Neutral Types and N\mathbb{N}N)

  • RedNeAt (RedNeAt(eqrel,Γ,A,K)\mathsf{RedNeAt}(\mathit{eqrel}, \Gamma, A, K)RedNeAt(eqrel,Γ,A,K)) & RedNe (RedNe(eqrel,Γ,A)\mathsf{RedNe}(\mathit{eqrel}, \Gamma, A)RedNe(eqrel,Γ,A)): TypeStarWf(Γ,A,K)∧Neutral(K)∧eqrel.NeEqRel(Γ,K,K,univ)\mathsf{TypeStarWf}(\Gamma, A, K) \land \mathsf{Neutral}(K) \land \mathit{eqrel}.\mathsf{NeEqRel}(\Gamma, K, K, \mathsf{univ})TypeStarWf(Γ,A,K)∧Neutral(K)∧eqrel.NeEqRel(Γ,K,K,univ) (existentially quantified over KKK in RedNe).
  • RedNeEq (RedNeEq(eqrel,Γ,K,B)\mathsf{RedNeEq}(\mathit{eqrel}, \Gamma, K, B)RedNeEq(eqrel,Γ,K,B)): ∃M,  TypeStarWf(Γ,B,M)∧Neutral(M)∧eqrel.NeEqRel(Γ,K,M,univ)\exists M,\; \mathsf{TypeStarWf}(\Gamma, B, M) \land \mathsf{Neutral}(M) \land \mathit{eqrel}.\mathsf{NeEqRel}(\Gamma, K, M, \mathsf{univ})∃M,TypeStarWf(Γ,B,M)∧Neutral(M)∧eqrel.NeEqRel(Γ,K,M,univ).
  • RedNeNf (RedNeNf(eqrel,Γ,k,A)\mathsf{RedNeNf}(\mathit{eqrel}, \Gamma, k, A)RedNeNf(eqrel,Γ,k,A)): Neutral(k)∧HasType(Γ,k,A)∧eqrel.NeEqRel(Γ,k,k,A)\mathsf{Neutral}(k) \land \mathsf{HasType}(\Gamma, k, A) \land \mathit{eqrel}.\mathsf{NeEqRel}(\Gamma, k, k, A)Neutral(k)∧HasType(Γ,k,A)∧eqrel.NeEqRel(Γ,k,k,A).
  • RedNeTerm (RedNeTerm(eqrel,Γ,K,t)\mathsf{RedNeTerm}(\mathit{eqrel}, \Gamma, K, t)RedNeTerm(eqrel,Γ,K,t)): ∃k,  StarWf(Γ,t,k,K)∧RedNeNf(eqrel,Γ,k,K)\exists k,\; \mathsf{StarWf}(\Gamma, t, k, K) \land \mathsf{RedNeNf}(\mathit{eqrel}, \Gamma, k, K)∃k,StarWf(Γ,t,k,K)∧RedNeNf(eqrel,Γ,k,K).
  • RedNeNfEq (RedNeNfEq(eqrel,Γ,k,m,A)\mathsf{RedNeNfEq}(\mathit{eqrel}, \Gamma, k, m, A)RedNeNfEq(eqrel,Γ,k,m,A)): Neutral(k)∧Neutral(m)∧eqrel.NeEqRel(Γ,k,m,A)\mathsf{Neutral}(k) \land \mathsf{Neutral}(m) \land \mathit{eqrel}.\mathsf{NeEqRel}(\Gamma, k, m, A)Neutral(k)∧Neutral(m)∧eqrel.NeEqRel(Γ,k,m,A).
  • RedNeTermEq (RedNeTermEq(eqrel,Γ,K,t,u)\mathsf{RedNeTermEq}(\mathit{eqrel}, \Gamma, K, t, u)RedNeTermEq(eqrel,Γ,K,t,u)): ∃k,m,  StarWf(Γ,t,k,K)∧StarWf(Γ,u,m,K)∧RedNeNfEq(eqrel,Γ,k,m,K)\exists k, m,\; \mathsf{StarWf}(\Gamma, t, k, K) \land \mathsf{StarWf}(\Gamma, u, m, K) \land \mathsf{RedNeNfEq}(\mathit{eqrel}, \Gamma, k, m, K)∃k,m,StarWf(Γ,t,k,K)∧StarWf(Γ,u,m,K)∧RedNeNfEq(eqrel,Γ,k,m,K).
  • RedNat: RedNat(Γ,A):≡TypeStarWf(Γ,A,nat)\mathsf{RedNat}(\Gamma, A) :\equiv \mathsf{TypeStarWf}(\Gamma, A, \mathsf{nat})RedNat(Γ,A):≡TypeStarWf(Γ,A,nat).
  • RedNatEq: RedNatEq(Γ,B):≡TypeStar(Γ,B,nat)\mathsf{RedNatEq}(\Gamma, B) :\equiv \mathsf{TypeStar}(\Gamma, B, \mathsf{nat})RedNatEq(Γ,B):≡TypeStar(Γ,B,nat).
  • RedNatTerm & NaturalProp (mutual inductive):
    • RedNatTerm(eqrel,Γ,t)\mathsf{RedNatTerm}(\mathit{eqrel}, \Gamma, t)RedNatTerm(eqrel,Γ,t) holds iff ∃n,  StarWf(Γ,t,n,nat)∧eqrel.TermEqRel(Γ,n,n,nat)∧NaturalProp(eqrel,Γ,n)\exists n,\; \mathsf{StarWf}(\Gamma, t, n, \mathsf{nat}) \land \mathit{eqrel}.\mathsf{TermEqRel}(\Gamma, n, n, \mathsf{nat}) \land \mathsf{NaturalProp}(\mathit{eqrel}, \Gamma, n)∃n,StarWf(Γ,t,n,nat)∧eqrel.TermEqRel(Γ,n,n,nat)∧NaturalProp(eqrel,Γ,n),
    • NaturalProp(eqrel,Γ,⋅)\mathsf{NaturalProp}(\mathit{eqrel}, \Gamma, \cdot)NaturalProp(eqrel,Γ,⋅) has constructors suc:RedNatTerm(eqrel,Γ,n)→NaturalProp(eqrel,Γ,succ(n))\mathsf{suc} : \mathsf{RedNatTerm}(\mathit{eqrel}, \Gamma, n) \to \mathsf{NaturalProp}(\mathit{eqrel}, \Gamma, \mathsf{succ}(n))suc:RedNatTerm(eqrel,Γ,n)→NaturalProp(eqrel,Γ,succ(n)), zero:NaturalProp(eqrel,Γ,zero)\mathsf{zero} : \mathsf{NaturalProp}(\mathit{eqrel}, \Gamma, \mathsf{zero})zero:NaturalProp(eqrel,Γ,zero), and ne:RedNeNf(eqrel,Γ,n,nat)→NaturalProp(eqrel,Γ,n)\mathsf{ne} : \mathsf{RedNeNf}(\mathit{eqrel}, \Gamma, n, \mathsf{nat}) \to \mathsf{NaturalProp}(\mathit{eqrel}, \Gamma, n)ne:RedNeNf(eqrel,Γ,n,nat)→NaturalProp(eqrel,Γ,n).
  • RedNatTermEq & NaturalEqProp (mutual inductive):
    • RedNatTermEq(eqrel,Γ,t,u)\mathsf{RedNatTermEq}(\mathit{eqrel}, \Gamma, t, u)RedNatTermEq(eqrel,Γ,t,u) holds iff ∃k,k′,  StarWf(Γ,t,k,nat)∧StarWf(Γ,u,k′,nat)∧eqrel.TermEqRel(Γ,k,k′,nat)∧NaturalEqProp(eqrel,Γ,k,k′)\exists k, k',\; \mathsf{StarWf}(\Gamma, t, k, \mathsf{nat}) \land \mathsf{StarWf}(\Gamma, u, k', \mathsf{nat}) \land \mathit{eqrel}.\mathsf{TermEqRel}(\Gamma, k, k', \mathsf{nat}) \land \mathsf{NaturalEqProp}(\mathit{eqrel}, \Gamma, k, k')∃k,k′,StarWf(Γ,t,k,nat)∧StarWf(Γ,u,k′,nat)∧eqrel.TermEqRel(Γ,k,k′,nat)∧NaturalEqProp(eqrel,Γ,k,k′),
    • NaturalEqProp(eqrel,Γ,⋅,⋅)\mathsf{NaturalEqProp}(\mathit{eqrel}, \Gamma, \cdot, \cdot)NaturalEqProp(eqrel,Γ,⋅,⋅) has constructors suc:RedNatTermEq(eqrel,Γ,n,n′)→NaturalEqProp(eqrel,Γ,succ(n),succ(n′))\mathsf{suc} : \mathsf{RedNatTermEq}(\mathit{eqrel}, \Gamma, n, n') \to \mathsf{NaturalEqProp}(\mathit{eqrel}, \Gamma, \mathsf{succ}(n), \mathsf{succ}(n'))suc:RedNatTermEq(eqrel,Γ,n,n′)→NaturalEqProp(eqrel,Γ,succ(n),succ(n′)), zero:NaturalEqProp(eqrel,Γ,zero,zero)\mathsf{zero} : \mathsf{NaturalEqProp}(\mathit{eqrel}, \Gamma, \mathsf{zero}, \mathsf{zero})zero:NaturalEqProp(eqrel,Γ,zero,zero), and ne:RedNeNfEq(eqrel,Γ,n,n′,nat)→NaturalEqProp(eqrel,Γ,n,n′)\mathsf{ne} : \mathsf{RedNeNfEq}(\mathit{eqrel}, \Gamma, n, n', \mathsf{nat}) \to \mathsf{NaturalEqProp}(\mathit{eqrel}, \Gamma, n, n')ne:RedNeNfEq(eqrel,Γ,n,n′,nat)→NaturalEqProp(eqrel,Γ,n,n′).

Universe Levels, Relation Bundles, Bundle Equivalence, and Π\PiΠ-Types

  • TypeLevel: Two-element inductive type {zero,one}\{\mathsf{zero}, \mathsf{one}\}{zero,one} with strict ordering TypeLevelLT having constructor zeroLT:TypeLevelLT(zero,one)\mathsf{zeroLT} : \mathsf{TypeLevelLT}(\mathsf{zero}, \mathsf{one})zeroLT:TypeLevelLT(zero,one).
  • RedRel: Structure in Type 1 with fields eqType:Term→Prop\mathsf{eqType} : \mathsf{Term} \to \mathsf{Prop}eqType:Term→Prop, hasTerm:Term→Prop\mathsf{hasTerm} : \mathsf{Term} \to \mathsf{Prop}hasTerm:Term→Prop, and eqTerm:Term→Term→Prop\mathsf{eqTerm} : \mathsf{Term} \to \mathsf{Term} \to \mathsf{Prop}eqTerm:Term→Term→Prop.
  • RedRelEquiv: Equivalence of two RedRel bundles rel1,rel2:RedRel\mathit{rel}_1, \mathit{rel}_2 : \mathsf{RedRel}rel1​,rel2​:RedRel across all three decoded predicates:
RedRelEquiv(rel1,rel2):≡(∀B,  rel1.eqType(B)↔rel2.eqType(B))∧(∀t,  rel1.hasTerm(t)↔rel2.hasTerm(t))∧(∀t,u,  rel1.eqTerm(t,u)↔rel2.eqTerm(t,u)).\mathsf{RedRelEquiv}(\mathit{rel}_1, \mathit{rel}_2) :\equiv \big(\forall B,\; \mathit{rel}_1.\mathsf{eqType}(B) \leftrightarrow \mathit{rel}_2.\mathsf{eqType}(B)\big) \land \big(\forall t,\; \mathit{rel}_1.\mathsf{hasTerm}(t) \leftrightarrow \mathit{rel}_2.\mathsf{hasTerm}(t)\big) \land \big(\forall t, u,\; \mathit{rel}_1.\mathsf{eqTerm}(t, u) \leftrightarrow \mathit{rel}_2.\mathsf{eqTerm}(t, u)\big).RedRelEquiv(rel1​,rel2​):≡(∀B,rel1​.eqType(B)↔rel2​.eqType(B))∧(∀t,rel1​.hasTerm(t)↔rel2​.hasTerm(t))∧(∀t,u,rel1​.eqTerm(t,u)↔rel2​.eqTerm(t,u)).
  • RedUAt & RedU: RedUAt(l′,l,Γ):≡TypeLevelLT(l′,l)∧CtxWf(Γ)\mathsf{RedUAt}(l', l, \Gamma) :\equiv \mathsf{TypeLevelLT}(l', l) \land \mathsf{CtxWf}(\Gamma)RedUAt(l′,l,Γ):≡TypeLevelLT(l′,l)∧CtxWf(Γ), and RedU(l,Γ):≡∃l′,  RedUAt(l′,l,Γ)\mathsf{RedU}(l, \Gamma) :\equiv \exists l',\; \mathsf{RedUAt}(l', l, \Gamma)RedU(l,Γ):≡∃l′,RedUAt(l′,l,Γ).
  • RedUTerm: Given rec:Context→Term→RedRel→Prop\mathit{rec} : \mathsf{Context} \to \mathsf{Term} \to \mathsf{RedRel} \to \mathsf{Prop}rec:Context→Term→RedRel→Prop, holds on (Γ,t)(\Gamma, t)(Γ,t) iff ∃A,  StarWf(Γ,t,A,univ)∧SmallTypeView(A)∧eqrel.TermEqRel(Γ,A,A,univ)∧(∃rel,  rec(Γ,t,rel))\exists A,\; \mathsf{StarWf}(\Gamma, t, A, \mathsf{univ}) \land \mathsf{SmallTypeView}(A) \land \mathit{eqrel}.\mathsf{TermEqRel}(\Gamma, A, A, \mathsf{univ}) \land (\exists \mathit{rel},\; \mathit{rec}(\Gamma, t, \mathit{rel}))∃A,StarWf(Γ,t,A,univ)∧SmallTypeView(A)∧eqrel.TermEqRel(Γ,A,A,univ)∧(∃rel,rec(Γ,t,rel)).
  • RedUTermEq: Holds on (Γ,t,u)(\Gamma, t, u)(Γ,t,u) iff ∃A,B,relt,  StarWf(Γ,t,A,univ)∧StarWf(Γ,u,B,univ)∧SmallTypeView(A)∧SmallTypeView(B)∧eqrel.TermEqRel(Γ,A,B,univ)∧rec(Γ,t,relt)∧(∃relu,  rec(Γ,u,relu))∧relt.eqType(u)\exists A, B, \mathit{relt},\; \mathsf{StarWf}(\Gamma, t, A, \mathsf{univ}) \land \mathsf{StarWf}(\Gamma, u, B, \mathsf{univ}) \land \mathsf{SmallTypeView}(A) \land \mathsf{SmallTypeView}(B) \land \mathit{eqrel}.\mathsf{TermEqRel}(\Gamma, A, B, \mathsf{univ}) \land \mathit{rec}(\Gamma, t, \mathit{relt}) \land (\exists \mathit{relu},\; \mathit{rec}(\Gamma, u, \mathit{relu})) \land \mathit{relt}.\mathsf{eqType}(u)∃A,B,relt,StarWf(Γ,t,A,univ)∧StarWf(Γ,u,B,univ)∧SmallTypeView(A)∧SmallTypeView(B)∧eqrel.TermEqRel(Γ,A,B,univ)∧rec(Γ,t,relt)∧(∃relu,rec(Γ,u,relu))∧relt.eqType(u).
  • Relation Bundles: RedURel, RedNatRel, RedNeRel, and RedPiRel (built from RedPiEq, RedPiTerm, RedPiTermEq using Kripke families relF\mathit{relF}relF and relG\mathit{relG}relG and helper abbreviations RelFEqType, RelFHasTerm, RelFEqTerm, RelGEqType, RelGHasTerm, RelGEqTerm).

Stratified Logical Relation (LogRel, LogRelAt) and Semantic Validity

  • LogRel: Inductive relation LogRel(eqrel,l,rec):Context→Term→RedRel→Prop\mathsf{LogRel}(\mathit{eqrel}, l, \mathit{rec}) : \mathsf{Context} \to \mathsf{Term} \to \mathsf{RedRel} \to \mathsf{Prop}LogRel(eqrel,l,rec):Context→Term→RedRel→Prop with 5 constructors (U, nat, ne, pi, emb).
  • logRelRecZero, logRelRec, & LogRelAt: Stratifies LogRel across zero\mathsf{zero}zero and one\mathsf{one}one, defining LogRelAt(eqrel,l):≡LogRel(eqrel,l,logRelRec(eqrel,l))\mathsf{LogRelAt}(\mathit{eqrel}, l) :\equiv \mathsf{LogRel}(\mathit{eqrel}, l, \mathsf{logRelRec}(\mathit{eqrel}, l))LogRelAt(eqrel,l):≡LogRel(eqrel,l,logRelRec(eqrel,l)).
  • Decoded Reducibility Judgments: RedType, RedEq, RedTerm, RedTermEq, and bundled Π\PiΠ-reducibility structures RedPiAt and RedPi.
  • Semantic Substitutions & Validity: ValidSubst, ValidSubstEq, ValidTypeAt, ValidType, ValidCtx, ValidTermAt, ValidTerm, ValidTypeEq, ValidTermEq, ModelsTermEq, ValidRedTerm, and the 5 fundamental theorem motives FundCtxMotive, FundTypeMotive, FundTermMotive, FundTypeEqMotive, FundTermEqMotive.
Human review
  • Endorsed by Shuze Chen · Nov 7, 2026

    Confirmed by the moderator at approval.

  • Endorsed by kmehltretter82 · Nov 7, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me