induction-induction part 3 - github pages · 2020. 11. 27. · induction-induction part 3...

40
Induction-induction Part 3 Constructing inductive-inductive types using a domain-specific type theory 1 Ambrus Kaposi j.w.w. Thorsten Altenkirch, P´ eter Divi´ anszky and Andr´ as Kov´ acs TYPES 2018 Braga 21 June 2018 1 This work was supported by the European Union, co-financed by the European Social Fund (EFOP-3.6.3-VEKOP-16-2017-00002) and COST Action EUTypes CA15123. 1 / 16

Upload: others

Post on 30-Jan-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

  • Induction-induction Part 3

    Constructing inductive-inductive types using a domain-specific type theory1

    Ambrus Kaposi

    j.w.w. Thorsten Altenkirch, Péter Diviánszky and András Kovács

    TYPES 2018Braga

    21 June 2018

    1This work was supported by the European Union, co-financed by the European Social Fund(EFOP-3.6.3-VEKOP-16-2017-00002) and COST Action EUTypes CA15123.

    1 / 16

  • Contents

    1 Another specification of IITs

    I more syntactic than Fredrik’s

    2 Constructing all IITs

    I from a universal IITI conjecture:

    inductive types universal IIT any IITJakob method this talk

    2 / 16

  • Contents

    1 Another specification of IITs

    I more syntactic than Fredrik’s

    2 Constructing all IITs

    I from a universal IITI conjecture:

    inductive types universal IIT any IITJakob method this talk

    2 / 16

  • Contents

    1 Another specification of IITs

    I more syntactic than Fredrik’s

    2 Constructing all IITs

    I from a universal IIT

    I conjecture:

    inductive types universal IIT any IITJakob method this talk

    2 / 16

  • Contents

    1 Another specification of IITs

    I more syntactic than Fredrik’s

    2 Constructing all IITs

    I from a universal IITI conjecture:

    inductive types universal IIT any IITJakob method this talk

    2 / 16

  • Another specification of IITs

    3 / 16

  • How to specify inductive types?

    By listing their constructors.

    4 / 16

  • How to specify inductive types?

    By listing their constructors.

    4 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context

    in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • What does it mean to list the constructors?

    A signature for an IIT is a context in a domain-specific type theory.

    Variables

    Empty universe U with underline for El:

    Γ ` UΓ ` a : U

    Γ ` a

    Restricted function space:

    Γ ` a : U Γ, x : a ` BΓ ` (x : a)⇒ B

    Γ ` t : (x : a)⇒ B Γ ` u : aΓ ` t u : B[x 7→ u]

    Signature for natural numbers:Θ := (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Not possible: (·, T : U, evil : (T ⇒ T )⇒ T )

    5 / 16

  • Standard model

    ` ΓΓA ∈ Set

    Γ ` AAA ∈ ΓA → Set

    Γ ` t : AtA ∈ (γ ∈ ΓA)→ AA(γ)

    (Γ, x : A)A := (γ ∈ ΓA)× AA(γ)UA(γ) := Set

    ((x : a)⇒ B)A(γ) := (α ∈ aA(γ))→ BA(γ, α)

    –A on a context gives algebras for that signature.E.g. ΘA = (N ∈ Set)× N × (N → N)

    6 / 16

  • Standard model

    ` ΓΓA ∈ Set

    Γ ` AAA ∈ ΓA → Set

    Γ ` t : AtA ∈ (γ ∈ ΓA)→ AA(γ)

    (Γ, x : A)A := (γ ∈ ΓA)× AA(γ)UA(γ) := Set

    ((x : a)⇒ B)A(γ) := (α ∈ aA(γ))→ BA(γ, α)

    –A on a context gives algebras for that signature.E.g. ΘA = (N ∈ Set)× N × (N → N)

    6 / 16

  • Logical relation interpretation

    ` ΓΓM ∈ ΓA → ΓA → Set

    Γ ` AAM ∈ ΓM γ γ′ → AA γ → AA γ′ → Set

    (Γ, x : A)M((γ, α), (γ′, α′)) := (γM : ΓM(γ, γ′))× AM(γM , α, α′)

    UM(γM , a, a′) := a→ a′ → Set

    (a)M(γM , α, α′) := aM(γM , α, α

    ′)

    ((x : a)⇒ B)M(γM , f , f ′) := (αM ∈ aM(γ, α, α′))→

    BM(

    (γM , αM), f (α), f′(α′)

    )

    7 / 16

  • Tweaked logical relation interpretation

    ` ΓΓM ∈ ΓA → ΓA → Set

    Γ ` AAM ∈ ΓM γ γ′ → AA γ → AA γ′ → Set

    (Γ, x : A)M((γ, α), (γ′, α′)) := (γM : ΓM(γ, γ′))× AM(γM , α, α′)

    UM(γM , a, a′) := a→ a′

    (a)M(γM , α, α′) := (aM(γM)(α) = α

    ′)

    ((x : a)⇒ B)M(γM , f , f ′) := (α ∈ aA(γ))→

    BM(

    (γM , refl), f (α), f′(aM(γM)(α)))

    –M on a context gives homomorphisms of algebras. E.g.

    ΘM((N, z , s), (N ′, z ′, s ′)) = (NM : N → N ′)× (NM(z) = z ′)×((α ∈ N)→ NM(s(α)) = s ′(NM(α)))

    8 / 16

  • Tweaked logical relation interpretation

    ` ΓΓM ∈ ΓA → ΓA → Set

    Γ ` AAM ∈ ΓM γ γ′ → AA γ → AA γ′ → Set

    (Γ, x : A)M((γ, α), (γ′, α′)) := (γM : ΓM(γ, γ′))× AM(γM , α, α′)

    UM(γM , a, a′) := a→ a′

    (a)M(γM , α, α′) := (aM(γM)(α) = α

    ′)

    ((x : a)⇒ B)M(γM , f , f ′) := (α ∈ aA(γ))→

    BM(

    (γM , refl), f (α), f′(aM(γM)(α)))

    –M on a context gives homomorphisms of algebras. E.g.

    ΘM((N, z , s), (N ′, z ′, s ′)) = (NM : N → N ′)× (NM(z) = z ′)×((α ∈ N)→ NM(s(α)) = s ′(NM(α)))

    8 / 16

  • Constructing inductive-inductive types

    9 / 16

  • Constructing natural numbers

    We use the domain-specific type theory:

    N := {t |Θ ` t : Nat}

    N.B.Θ = (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Constructors:zero := zero ∈ N

    suc(n ∈ N) := suc n ∈ N

    10 / 16

  • Constructing natural numbers

    We use the domain-specific type theory:

    N := {t |Θ ` t : Nat}

    N.B.Θ = (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Constructors:zero := zero ∈ N

    suc(n ∈ N) := suc n ∈ N

    10 / 16

  • Constructing natural numbers

    We use the domain-specific type theory:

    N := {t |Θ ` t : Nat}

    N.B.Θ = (·, Nat : U, zero : Nat, suc : Nat ⇒ Nat)

    Constructors:zero := zero ∈ N

    suc(n ∈ N) := suc n ∈ N

    10 / 16

  • Recursor for N

    We need:recN : N→ (x : ΘA)→ proj1(x)

    The standard interpretation of t ∈ N i.e. Θ ` t : Nat:

    tA ∈ (x ∈ ΘA)→ (Nat)A(x)︸ ︷︷ ︸=proj1(x)

    recN(t) := tA

    11 / 16

  • Recursor for N

    We need:recN : N→ (x : ΘA)→ proj1(x)

    The standard interpretation of t ∈ N i.e. Θ ` t : Nat:

    tA ∈ (x ∈ ΘA)→ (Nat)A(x)︸ ︷︷ ︸=proj1(x)

    recN(t) := tA

    11 / 16

  • Recursor for N

    We need:recN : N→ (x : ΘA)→ proj1(x)

    The standard interpretation of t ∈ N i.e. Θ ` t : Nat:

    tA ∈ (x ∈ ΘA)→ (Nat)A(x)︸ ︷︷ ︸=proj1(x)

    recN(t) := tA

    11 / 16

  • Model for the initial algebra

    Fix a Θ.` Γ

    ΓC ∈ (Θ ` ν : Γ)→ ΓA

    On the universe:UC(ν, a) := {t |Θ ` t : a}

    Initial algebra for Θ is ΘC(idΘ) ∈ ΘA.

    12 / 16

  • Model for the initial algebra

    Fix a Θ.` Γ

    ΓC ∈ (Θ ` ν : Γ)→ ΓA

    On the universe:UC(ν, a) := {t |Θ ` t : a}

    Initial algebra for Θ is ΘC(idΘ) ∈ ΘA.

    12 / 16

  • Model for the initial algebra

    Fix a Θ.` Γ

    ΓC ∈ (Θ ` ν : Γ)→ ΓA

    On the universe:UC(ν, a) := {t |Θ ` t : a}

    Initial algebra for Θ is ΘC(idΘ) ∈ ΘA.

    12 / 16

  • Model for the recursor

    Fix a Θ and a θ ∈ ΘA.

    ` ΓΓR ∈ (Θ ` ν : Γ)→ ΓM(ΓC(ν), νA(θ))

    On the universe:UR(ν, a)(t) := tA(θ)

    Recursor is given by ΘR(idΘ) ∈ ΘM(initial algebra for Θ, θ).

    13 / 16

  • Model for the recursor

    Fix a Θ and a θ ∈ ΘA.

    ` ΓΓR ∈ (Θ ` ν : Γ)→ ΓM(ΓC(ν), νA(θ))

    On the universe:UR(ν, a)(t) := tA(θ)

    Recursor is given by ΘR(idΘ) ∈ ΘM(initial algebra for Θ, θ).

    13 / 16

  • Model for the recursor

    Fix a Θ and a θ ∈ ΘA.

    ` ΓΓR ∈ (Θ ` ν : Γ)→ ΓM(ΓC(ν), νA(θ))

    On the universe:UR(ν, a)(t) := tA(θ)

    Recursor is given by ΘR(idΘ) ∈ ΘM(initial algebra for Θ, θ).

    13 / 16

  • Summary

    Domain-specific type theory for signatures.

    We do universal algebra by defining models of this type theory.

    Standard model: algebrasTweaked logical relations: algebra homomorphismsModel where U is terms: initial algebraModel where U is the standard interpretation: recursorLogical predicates: familiesTweaked dependent logical relations: sectionsModel where U is logical predicate translation: eliminator

    It seems that this extends to quotient inductive-inductive types.Challenge: higher inductive-inductive types?

    14 / 16

  • Summary

    Domain-specific type theory for signatures.

    We do universal algebra by defining models of this type theory.

    Standard model: algebrasTweaked logical relations: algebra homomorphismsModel where U is terms: initial algebraModel where U is the standard interpretation: recursorLogical predicates: familiesTweaked dependent logical relations: sectionsModel where U is logical predicate translation: eliminator

    It seems that this extends to quotient inductive-inductive types.Challenge: higher inductive-inductive types?

    14 / 16

  • CwF of CwFs

    standard model algebras contexts

    tweaked logical relations homomorphisms substitutions

    logical predicates families types

    tweaked dependent sections termslogical relations

    reflexivity in the reflexive identity morphism identity substitutiongraph model

    transitivity in the setoid morphisms composition substitutions compositionmodel

    groupoid law in the associativity substitution lawgroupoid model

    ...

    Nice internal language for universal algebra.

    15 / 16

  • CwF of CwFs

    standard model algebras contexts

    tweaked logical relations homomorphisms substitutions

    logical predicates families types

    tweaked dependent sections termslogical relations

    reflexivity in the reflexive identity morphism identity substitutiongraph model

    transitivity in the setoid morphisms composition substitutions compositionmodel

    groupoid law in the associativity substitution lawgroupoid model

    ...

    Nice internal language for universal algebra.

    15 / 16

  • Constructing inductive types à la Awodey-Frey-Speight

    System F impredicative encoding:

    N := ((x : ΘA)→ proj1(x))

    N.B.ΘA = (N ∈ Set)× N × (N → N)

    Problem: given an f ∈ ΘM(x , x ′) and an n ∈ N, f (n(x)) ?= n(x ′)

    Solution: let’s build this in the definition!

    N := (n ∈ (x : ΘA)→ proj1(x))× (∀x , x ′, f .f (n(x)) = n(x ′))

    16 / 16

  • Constructing inductive types à la Awodey-Frey-Speight

    System F impredicative encoding:

    N := ((x : ΘA)→ proj1(x))

    N.B.ΘA = (N ∈ Set)× N × (N → N)

    Problem: given an f ∈ ΘM(x , x ′) and an n ∈ N, f (n(x)) ?= n(x ′)

    Solution: let’s build this in the definition!

    N := (n ∈ (x : ΘA)→ proj1(x))× (∀x , x ′, f .f (n(x)) = n(x ′))

    16 / 16

  • Constructing inductive types à la Awodey-Frey-Speight

    System F impredicative encoding:

    N := ((x : ΘA)→ proj1(x))

    N.B.ΘA = (N ∈ Set)× N × (N → N)

    Problem: given an f ∈ ΘM(x , x ′) and an n ∈ N, f (n(x)) ?= n(x ′)

    Solution: let’s build this in the definition!

    N := (n ∈ (x : ΘA)→ proj1(x))× (∀x , x ′, f .f (n(x)) = n(x ′))

    16 / 16

  • Constructing inductive types à la Awodey-Frey-Speight

    System F impredicative encoding:

    N := ((x : ΘA)→ proj1(x))

    N.B.ΘA = (N ∈ Set)× N × (N → N)

    Problem: given an f ∈ ΘM(x , x ′) and an n ∈ N, f (n(x)) ?= n(x ′)

    Solution: let’s build this in the definition!

    N := (n ∈ (x : ΘA)→ proj1(x))× (∀x , x ′, f .f (n(x)) = n(x ′))

    16 / 16

    Another specification of IITsConstructing inductive-inductive types