+ All Categories
Home > Documents > Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory...

Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory...

Date post: 22-Aug-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
121
Computational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University ACM PoPL Tutorial Session January 2018
Transcript
Page 1: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational (Higher) Type Theory

Robert Harper and Carlo Angiuli

Computer Science DepartmentCarnegie Mellon University

ACM PoPL Tutorial Session January 2018

Page 2: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Vladimir Voevodsky 1966-2017Photo credit: Wikipedia

Page 3: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Acknowledgements

Thanks to many, including

• Collaborators: Evan Cavallo, Kuen-Bang Hou (Favonia), Daniel R. Licata,Jonathan Sterling, Todd Wilson.

• Colleagues: Steve Awodey, Marc Bezem, Guillaume Brunerie, Thierry Coquand,Simon Huber, Anders Mortberg.

• Inspiration: Robert Constable, Per Martin-Lof, Dana Scott, Vladimir Voevodsky.

Supported by AFOSR MURI FA9550-15-1-0053.

Page 4: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

References

Primary sources for these lectures:

• Carlo Angiuli and Robert Harper. “Meaning Explanations at Higher Dimension.”Indagationes Mathematicae 29 (2018), pages 135–149. Special Issue: L.E.J. Brouwerafter 50 years.

• Carlo Angiuli, Kuen-Bang Hou (Favonia), and Robert Harper. “Computational HigherType Theory III: Univalent Universes and Exact Equality.”https://arxiv.org/abs/1712.01800.

• Evan Cavallo and Robert Harper. “Computational Higher Type Theory IV: InductiveTypes.” https://arxiv.org/abs/1801.01568.

See also:

• Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mortberg. “Cubical typetheory: a constructive interpretation of the univalence axiom.” To appear, 2018.

• Carlo Angiuli, Guillaume Brunerie, Thierry Coquand, Kuen-Bang Hou (Favonia), RobertHarper, and Daniel R. Licata. “Cartesian Cubical Type Theory.” To appear, 2018.

Page 5: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Formal Type TheoryMartin-Lof; Coquand; HoTT

A formal type theory is inductively defined by rules:

• Formation: Γ ` A type, Γ ` M : A.

• Definitional equivalence: Γ ` A ≡ B, Γ ` M ≡ N : A.

Axioms and rules are chosen to ensure:

• Not non-constructive, eg no unrestricted LEM.

• Formal correspondence to logics, eg HA, IHOL.

• Decidability of all assertions.

Ought to admit a computational interpretation as programs.

Page 6: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Formal Type TheoryMartin-Lof; Coquand; HoTT

A formal type theory is inductively defined by rules:

• Formation: Γ ` A type, Γ ` M : A.

• Definitional equivalence: Γ ` A ≡ B, Γ ` M ≡ N : A.

Axioms and rules are chosen to ensure:

• Not non-constructive, eg no unrestricted LEM.

• Formal correspondence to logics, eg HA, IHOL.

• Decidability of all assertions.

Ought to admit a computational interpretation as programs.

Page 7: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Formal Type TheoryMartin-Lof; Coquand; HoTT

A formal type theory is inductively defined by rules:

• Formation: Γ ` A type, Γ ` M : A.

• Definitional equivalence: Γ ` A ≡ B, Γ ` M ≡ N : A.

Axioms and rules are chosen to ensure:

• Not non-constructive, eg no unrestricted LEM.

• Formal correspondence to logics, eg HA, IHOL.

• Decidability of all assertions.

Ought to admit a computational interpretation as programs.

Page 8: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Intensional Type TheoryMartin-Lof

The canonical formal dependent type theory: ITT.

• Inductive types: nat, bool, sums, well-founded trees.

• Dependent function and product types: Πx :A.B, Σx :A.B.

• Identity type: IdA(M,N).

Identity type is the least reflexive relation:

• Reflexivity: reflA(M) : IdA(M,M).

• Induction: if P : IdA(M,N) and u:A ` Q : C [M,M, reflA(M)],then J(u.Q;P) : C [M,N,P].

Page 9: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Intensional Type TheoryMartin-Lof

The canonical formal dependent type theory: ITT.

• Inductive types: nat, bool, sums, well-founded trees.

• Dependent function and product types: Πx :A.B, Σx :A.B.

• Identity type: IdA(M,N).

Identity type is the least reflexive relation:

• Reflexivity: reflA(M) : IdA(M,M).

• Induction: if P : IdA(M,N) and u:A ` Q : C [M,M, reflA(M)],then J(u.Q;P) : C [M,N,P].

Page 10: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning of ITTMartin-Lof

Normalization: reduction of open terms.

• Variables are indeterminates, obey substitution.

• Canonicity via characterization of closed normal forms.

Meaning explanations: evaluation of closed terms.

• Variables range over closed terms, obey functionality.

• Canonicity by definition of observable values.

Page 11: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning of ITTMartin-Lof

Normalization: reduction of open terms.

• Variables are indeterminates, obey substitution.

• Canonicity via characterization of closed normal forms.

Meaning explanations: evaluation of closed terms.

• Variables range over closed terms, obey functionality.

• Canonicity by definition of observable values.

Page 12: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Identity Type in ITT

Equational reasoning is handled by the identity type:

x : nat, y : nat ` P(x , y) : Idnat(x + y , y + x)

The proof P(x , y) is non-trivial: induction on x and y .

Type families respect identity proofs:

x , y : nat ` Vec†(P(x , y)) : IdU (Vec(x + y),Vec(y + x)).

Page 13: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Identity Type in ITT

Equational reasoning is handled by the identity type:

x : nat, y : nat ` P(x , y) : Idnat(x + y , y + x)

The proof P(x , y) is non-trivial: induction on x and y .

Type families respect identity proofs:

x , y : nat ` Vec†(P(x , y)) : IdU (Vec(x + y),Vec(y + x)).

Page 14: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Identity Type in ITT

Identity proofs in IdU (A,B) induce coercions:

a, b : U , p : IdU (a, b) ` coerce(p) : a→ b

In particular, for any M,N : nat,

coerce(Vec†(P(M,N))) : Vec(M + N)→ Vec(N + M)

But for closed M and N these types are definitionally equal!

Thus, no coercion is needed at run-time!

Page 15: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Identity Type in ITT

Identity proofs in IdU (A,B) induce coercions:

a, b : U , p : IdU (a, b) ` coerce(p) : a→ b

In particular, for any M,N : nat,

coerce(Vec†(P(M,N))) : Vec(M + N)→ Vec(N + M)

But for closed M and N these types are definitionally equal!

Thus, no coercion is needed at run-time!

Page 16: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Program Extraction for ITTCoq

Program extraction exploits irrelevance of identity proofs.

• Evaluate only closed terms of observable type.

• Erase uses of identity elimination.

Meaning explanation emphasizes extraction and execution.

• No transport operations to erase.

• Exact equality: x , y : nat� x + y.

= y + x ∈ nat.

Page 17: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Program Extraction for ITTCoq

Program extraction exploits irrelevance of identity proofs.

• Evaluate only closed terms of observable type.

• Erase uses of identity elimination.

Meaning explanation emphasizes extraction and execution.

• No transport operations to erase.

• Exact equality: x , y : nat� x + y.

= y + x ∈ nat.

Page 18: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Homotopy Type TheoryHofmann & Streicher; Awodey & Warren; Voevodsky

IdA(M,N) may be considered as type of paths.

Univalence: if E : Equiv(A,B) is an equivalence, then

ua(E ) : IdU (A,B).

Higher inductive types, such as the “circle”, C:

base : Cloop : IdC(base, base).

Page 19: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Homotopy Type TheoryHofmann & Streicher; Awodey & Warren; Voevodsky

IdA(M,N) may be considered as type of paths.

Univalence: if E : Equiv(A,B) is an equivalence, then

ua(E ) : IdU (A,B).

Higher inductive types, such as the “circle”, C:

base : Cloop : IdC(base, base).

Page 20: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Homotopy Type Theory

Coercions are no longer erasable!

coerce(ua(. . . )) : nat + nat→ bool× nat

(Even for closed terms.)

What is the computational content of HoTT?

coerce(ua(. . . )) 7−→ ???

Identity elimination does not eliminate identifications!

Page 21: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Homotopy Type Theory

Coercions are no longer erasable!

coerce(ua(. . . )) : nat + nat→ bool× nat

(Even for closed terms.)

What is the computational content of HoTT?

coerce(ua(. . . )) 7−→ ???

Identity elimination does not eliminate identifications!

Page 22: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

Judgmental account of higher structure of types:

• What is a path in a type?

• Define the action of a path.

• Ensure that paths can be composed.

Identity type splits into two concepts:

• Exact equality: M.

= N ∈ A.

• Path type: Pathx .A(M,N).

Page 23: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

Judgmental account of higher structure of types:

• What is a path in a type?

• Define the action of a path.

• Ensure that paths can be composed.

Identity type splits into two concepts:

• Exact equality: M.

= N ∈ A.

• Path type: Pathx .A(M,N).

Page 24: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning ExplanationsMartin-Lof; Constable; Allen

Start with a programming language:

• Programs are closed terms.

• Evaluation M ⇓ V to a canonical form aka value.

Types are programs that name specifications of programs.

• A type means A ⇓ V and V names a specification.

• if A type, then M.

= M ′ ∈ A means M ⇓ V and M ′ ⇓ V ′ and V and V ′ behavethe same in the sense of A.

What matters is behavior, not form!

Page 25: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning ExplanationsMartin-Lof; Constable; Allen

Start with a programming language:

• Programs are closed terms.

• Evaluation M ⇓ V to a canonical form aka value.

Types are programs that name specifications of programs.

• A type means A ⇓ V and V names a specification.

• if A type, then M.

= M ′ ∈ A means M ⇓ V and M ′ ⇓ V ′ and V and V ′ behavethe same in the sense of A.

What matters is behavior, not form!

Page 26: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning ExplanationsMartin-Lof; Constable; Allen

Start with a programming language:

• Programs are closed terms.

• Evaluation M ⇓ V to a canonical form aka value.

Types are programs that name specifications of programs.

• A type means A ⇓ V and V names a specification.

• if A type, then M.

= M ′ ∈ A means M ⇓ V and M ′ ⇓ V ′ and V and V ′ behavethe same in the sense of A.

What matters is behavior, not form!

Page 27: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

Variables are interpreted semantically.

• Range over closed terms satisfying a type.

• Respect equality at that type.

Functionality: a : A� N ∈ B means

M.

= M ′ ∈ A implies N[M/a].

= N[M ′/a] ∈ B[M/a].

Extensionality: a : A� N.

= N ′ ∈ B means

M.

= M ′ ∈ A implies N[M/a].

= N ′[M ′/a] ∈ B[M/a].

Page 28: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

Variables are interpreted semantically.

• Range over closed terms satisfying a type.

• Respect equality at that type.

Functionality: a : A� N ∈ B means

M.

= M ′ ∈ A implies N[M/a].

= N[M ′/a] ∈ B[M/a].

Extensionality: a : A� N.

= N ′ ∈ B means

M.

= M ′ ∈ A implies N[M/a].

= N ′[M ′/a] ∈ B[M/a].

Page 29: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

Proof theories are secondary, a matter of pragmatics.

• No privileged proof theory. (Down with C-H!).

• No requirement of decidability of judgments.

RedPRL proof theory is a refinement logic.

• Inspired by NuPRL.

• Emphasizes program extraction.

Inverts the conceptual order in ITT and related formalisms!

Page 30: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

Proof theories are secondary, a matter of pragmatics.

• No privileged proof theory. (Down with C-H!).

• No requirement of decidability of judgments.

RedPRL proof theory is a refinement logic.

• Inspired by NuPRL.

• Emphasizes program extraction.

Inverts the conceptual order in ITT and related formalisms!

Page 31: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

Proof theories are secondary, a matter of pragmatics.

• No privileged proof theory. (Down with C-H!).

• No requirement of decidability of judgments.

RedPRL proof theory is a refinement logic.

• Inspired by NuPRL.

• Emphasizes program extraction.

Inverts the conceptual order in ITT and related formalisms!

Page 32: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Computational Meaning Explanations

A specification is a symmetric, transitive relation on closed values.

Equal specifications must specify the same behavior,i.e., be interchangeable as classifiers.

The construction of a type system ensures that specifications satisfy these conditions.

Page 33: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Booleans

Programs:

• bool, true, false are canonical.

• if (true;P;Q) 7−→ P.

• if (false;P;Q) 7−→ Q.

• if M 7−→ M ′ then if (M;P;Q) 7−→ if (M ′;P;Q).

The type bool specifies that true and false are equal only to themselves.

bool is an inductive type.

Page 34: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Booleans

Programs:

• bool, true, false are canonical.

• if (true;P;Q) 7−→ P.

• if (false;P;Q) 7−→ Q.

• if M 7−→ M ′ then if (M;P;Q) 7−→ if (M ′;P;Q).

The type bool specifies that true and false are equal only to themselves.

bool is an inductive type.

Page 35: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Booleans

Theorem (Dependent Elimination)

If M ∈ bool and P ∈ A[true/a] and Q ∈ A[false/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Behavioral Typing)

If M.

= true ∈ bool and P ∈ A[true/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Shannon Expansion)

If a : bool� M ∈ A, then

a : bool� M.

= if(a;M[true/a];M[false/a]) ∈ A.

Page 36: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Booleans

Theorem (Dependent Elimination)

If M ∈ bool and P ∈ A[true/a] and Q ∈ A[false/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Behavioral Typing)

If M.

= true ∈ bool and P ∈ A[true/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Shannon Expansion)

If a : bool� M ∈ A, then

a : bool� M.

= if(a;M[true/a];M[false/a]) ∈ A.

Page 37: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Booleans

Theorem (Dependent Elimination)

If M ∈ bool and P ∈ A[true/a] and Q ∈ A[false/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Behavioral Typing)

If M.

= true ∈ bool and P ∈ A[true/a], then if (M;P;Q) ∈ A[M/a].

Theorem (Shannon Expansion)

If a : bool� M ∈ A, then

a : bool� M.

= if(a;M[true/a];M[false/a]) ∈ A.

Page 38: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Programs:

• (a:A)→ B and λa.M are canonical.

• app(λa.P,N) 7−→ P[N/a].

• if M 7−→ M ′, then app(M,N) 7−→ app(M ′,N).

The value λa.M satisfies the spec. (a:A)→ B iff

a : A� M ∈ B.

Values λa.M and λa.M ′ are equal in (a:A)→ B iff

a : A� M.

= M ′ ∈ B [Ψ].

Page 39: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Programs:

• (a:A)→ B and λa.M are canonical.

• app(λa.P,N) 7−→ P[N/a].

• if M 7−→ M ′, then app(M,N) 7−→ app(M ′,N).

The value λa.M satisfies the spec. (a:A)→ B iff

a : A� M ∈ B.

Values λa.M and λa.M ′ are equal in (a:A)→ B iff

a : A� M.

= M ′ ∈ B [Ψ].

Page 40: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Programs:

• (a:A)→ B and λa.M are canonical.

• app(λa.P,N) 7−→ P[N/a].

• if M 7−→ M ′, then app(M,N) 7−→ app(M ′,N).

The value λa.M satisfies the spec. (a:A)→ B iff

a : A� M ∈ B.

Values λa.M and λa.M ′ are equal in (a:A)→ B iff

a : A� M.

= M ′ ∈ B [Ψ].

Page 41: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Theorem (Dependent Elim)

If M ∈ (a:A)→ B, and N ∈ A, then app(M,N) ∈ B[N/a].

Theorem (β Equality)

If λa.P ∈ (a:A)→ B and N ∈ A, then

app(λa.P,N).

= P[N/a] ∈ B[N/a].

Theorem (Extensionality)

If a : A� app(M, a).

= app(N, a) ∈ B, then

M.

= N ∈ (a:A)→ B.

Page 42: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Theorem (Dependent Elim)

If M ∈ (a:A)→ B, and N ∈ A, then app(M,N) ∈ B[N/a].

Theorem (β Equality)

If λa.P ∈ (a:A)→ B and N ∈ A, then

app(λa.P,N).

= P[N/a] ∈ B[N/a].

Theorem (Extensionality)

If a : A� app(M, a).

= app(N, a) ∈ B, then

M.

= N ∈ (a:A)→ B.

Page 43: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Theorem (Dependent Elim)

If M ∈ (a:A)→ B, and N ∈ A, then app(M,N) ∈ B[N/a].

Theorem (β Equality)

If λa.P ∈ (a:A)→ B and N ∈ A, then

app(λa.P,N).

= P[N/a] ∈ B[N/a].

Theorem (Extensionality)

If a : A� app(M, a).

= app(N, a) ∈ B, then

M.

= N ∈ (a:A)→ B.

Page 44: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Exact EqualityMartin-Lof

Programs:

• EqA(M,N) and ? are canonical.

• No elimination form needed!

The value ? satisfies spec. EqA(M,N) iff M.

= N ∈ A.

The value ? is equal only to itself whenever it satisfies EqA(M,N).

Page 45: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Exact EqualityMartin-Lof

TheoremIf M ∈ A, then ? ∈ EqA(M,M).

TheoremIf P ∈ EqA(M,N), then M

.= N ∈ A.

Page 46: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Exact EqualityMartin-Lof

TheoremIf M ∈ A, then ? ∈ EqA(M,M).

TheoremIf P ∈ EqA(M,N), then M

.= N ∈ A.

Page 47: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Demonstration

Please enjoy Carlo’s demo of RedPRL!

Page 48: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Obligatory Cat PhotoThanks to Tran Ma

Page 49: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

HoTT encodes path structure in identification types:

A, IdA(M,N), IdIdA(M,N)(P,Q), . . .

Paths re-expressed using the interval I = [0, 1]:

• Points: A.

• Lines btw points: I A,

• Squares, lines btw lines: I (I A) ∼= I2 ; A,

• Cubes, lines btw squares: I3 A, . . .

• n-cubes: In A

Page 50: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

HoTT encodes path structure in identification types:

A, IdA(M,N), IdIdA(M,N)(P,Q), . . .

Paths re-expressed using the interval I = [0, 1]:

• Points: A.

• Lines btw points: I A,

• Squares, lines btw lines: I (I A) ∼= I2 ; A,

• Cubes, lines btw squares: I3 A, . . .

• n-cubes: In A

Page 51: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming LanguageLicata, Brunerie; Coquand, et al.

Cubical syntax:

• Dimensions r := 0 | 1 | x .

• Contexts Ψ = x1, . . . , xn.

• Substitutions ψ = 〈r1/x1, . . . rn/xn〉 : Ψ′ → Ψ.

• Action on terms: M ψ

Cartesian cubes = substitutions are structural:

• Faces: 0/x , 1/x .

• Re-indexing: y/x .

• Weakening aka degeneracy: silent.

• Exchange aka symmetry: y , x/x , y .

• Contraction aka diagonal: z , z/x , y .

Page 52: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming LanguageLicata, Brunerie; Coquand, et al.

Cubical syntax:

• Dimensions r := 0 | 1 | x .

• Contexts Ψ = x1, . . . , xn.

• Substitutions ψ = 〈r1/x1, . . . rn/xn〉 : Ψ′ → Ψ.

• Action on terms: M ψ

Cartesian cubes = substitutions are structural:

• Faces: 0/x , 1/x .

• Re-indexing: y/x .

• Weakening aka degeneracy: silent.

• Exchange aka symmetry: y , x/x , y .

• Contraction aka diagonal: z , z/x , y .

Page 53: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Substitutions act on cubes:

• Faces: M〈0/x〉, M〈1/x〉• Diagonals: M〈x/y〉

y

x

M〈1/x〉〈1/y〉.

= M〈1/y〉〈1/x〉.

= M〈x/y〉〈1/x〉

M〈0/x〉 M〈1/x〉

M〈0/y〉

M〈1/y〉

M

Page 54: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Substitutions act on cubes:

• Faces: M〈0/x〉, M〈1/x〉

• Diagonals: M〈x/y〉

y

x

M〈1/x〉〈1/y〉.

= M〈1/y〉〈1/x〉.

= M〈x/y〉〈1/x〉

M〈0/x〉 M〈1/x〉

M〈0/y〉

M〈1/y〉

M

Page 55: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Substitutions act on cubes:

• Faces: M〈0/x〉, M〈1/x〉• Diagonals: M〈x/y〉

y

x

M〈1/x〉〈1/y〉.

= M〈1/y〉〈1/x〉.

= M〈x/y〉〈1/x〉

M〈0/x〉 M〈1/x〉

M〈0/y〉

M〈1/y〉

M〈x/y〉

Page 56: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Substitutions act on cubes:

• Faces: M〈0/x〉, M〈1/x〉• Diagonals: M〈x/y〉

y

x

M〈1/x〉〈1/y〉.

= M〈1/y〉〈1/x〉.

= M〈x/y〉〈1/x〉

M〈0/x〉 M〈1/x〉

M〈0/y〉

M〈1/y〉

M〈x/y〉

Page 57: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Any cube can be seen as a degenerate cube of higher dimension:

y

xN〈0/x〉 N〈1/x〉

N

N〈0/x〉 N〈1/x〉

N〈0/x〉 N〈1/x〉

N

N

Page 58: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Any cube can be seen as a degenerate cube of higher dimension:

y

xN〈0/x〉 N〈1/x〉

N

N〈0/x〉 N〈1/x〉

N〈0/x〉 N〈1/x〉

N

N

Page 59: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming LanguageLicata, Brunerie; Coquand, et al.

Evaluation: M ⇓ V [Ψ].

Conventional functional programming constructs:

• Booleans, pairs, functions.

• Lazy dynamics (weak head reduction).

Unconventional functional programming constructs:

• Circle: C, base, loopx ,C-elima.A(M;N, x .P).

• Kan operations: coe, hcom.

Page 60: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming LanguageLicata, Brunerie; Coquand, et al.

Evaluation: M ⇓ V [Ψ].

Conventional functional programming constructs:

• Booleans, pairs, functions.

• Lazy dynamics (weak head reduction).

Unconventional functional programming constructs:

• Circle: C, base, loopx ,C-elima.A(M;N, x .P).

• Kan operations: coe, hcom.

Page 61: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming LanguageLicata, Brunerie; Coquand, et al.

Evaluation: M ⇓ V [Ψ].

Conventional functional programming constructs:

• Booleans, pairs, functions.

• Lazy dynamics (weak head reduction).

Unconventional functional programming constructs:

• Circle: C, base, loopx ,C-elima.A(M;N, x .P).

• Kan operations: coe, hcom.

Page 62: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Programming Language

Evaluation is sensitive to dimensions:

loop0 7−→ base

loop1 7−→ base

C-elima.A(base;N, x .P) 7−→ N

C-elima.A(loopy ;N, x .P) 7−→ P〈y/x〉.

base.

= loopx〈0/x〉 loopx〈1/x〉.

= baseloopx

Page 63: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

If A type [Ψ], then all faces of A evaluate to specifications:

• Aψ ⇓ V [Ψ′] for all ψ : Ψ′ → Ψ, and

• Value V names a specification of values.

If M ∈ A [Ψ], then all faces of M satisfy the spec given by A.

That is, for every ψ : Ψ′ → Ψ,

• M ψ ⇓ V , and

• V satisfies the specification given by Aψ.

(Actually, we must define equal types and equal members.)

Page 64: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

If A type [Ψ], then all faces of A evaluate to specifications:

• Aψ ⇓ V [Ψ′] for all ψ : Ψ′ → Ψ, and

• Value V names a specification of values.

If M ∈ A [Ψ], then all faces of M satisfy the spec given by A.

That is, for every ψ : Ψ′ → Ψ,

• M ψ ⇓ V , and

• V satisfies the specification given by Aψ.

(Actually, we must define equal types and equal members.)

Page 65: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Higher Meaning Explanations

If A type [Ψ], then all faces of A evaluate to specifications:

• Aψ ⇓ V [Ψ′] for all ψ : Ψ′ → Ψ, and

• Value V names a specification of values.

If M ∈ A [Ψ], then all faces of M satisfy the spec given by A.

That is, for every ψ : Ψ′ → Ψ,

• M ψ ⇓ V , and

• V satisfies the specification given by Aψ.

(Actually, we must define equal types and equal members.)

Page 66: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Specifications

Specifications are cubical symmetric, and transitive binary relations.

If V is a canonical type, then all of its faces must be types:

for all ψ : Ψ′ → Ψ, Vψ type [Ψ′].

If W is canonical of type V , then its faces must be elements:

for all ψ : Ψ′ → Ψ, Wψ ∈ Vψ [Ψ′].

Page 67: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Specifications

Specifications are cubical symmetric, and transitive binary relations.

If V is a canonical type, then all of its faces must be types:

for all ψ : Ψ′ → Ψ, Vψ type [Ψ′].

If W is canonical of type V , then its faces must be elements:

for all ψ : Ψ′ → Ψ, Wψ ∈ Vψ [Ψ′].

Page 68: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Cubical Specifications

Specifications are cubical symmetric, and transitive binary relations.

If V is a canonical type, then all of its faces must be types:

for all ψ : Ψ′ → Ψ, Vψ type [Ψ′].

If W is canonical of type V , then its faces must be elements:

for all ψ : Ψ′ → Ψ, Wψ ∈ Vψ [Ψ′].

Page 69: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coherence

An ambiguity arises for A type [Ψ]:

• Aψ1 ⇓ V1 and V1ψ2 ⇓ V2.

• A(ψ1 · ψ2) ⇓ V12.

But are V2 and V12 the same canonical type?

• Not necessarily the same program.

• But should have the same elements and equality.

Coherence demands that they determine the same specification.

Page 70: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coherence

An ambiguity arises for A type [Ψ]:

• Aψ1 ⇓ V1 and V1ψ2 ⇓ V2.

• A(ψ1 · ψ2) ⇓ V12.

But are V2 and V12 the same canonical type?

• Not necessarily the same program.

• But should have the same elements and equality.

Coherence demands that they determine the same specification.

Page 71: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Meaning of Variables

Term variables express functional dependence on closed values at all dimensions.

Thus a : A� B type [Ψ] means for all ψ : Ψ′ → Ψ,

if M.

= N ∈ A [Ψ′], then Bψ[M/a].

= Bψ[N/a] type [Ψ′].

In particular, type families transform lines into lines:

if M ∈ A [Ψ, x ]︸ ︷︷ ︸line in A

, then B[M/a] type [Ψ, x ]︸ ︷︷ ︸line of types

.

Page 72: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Meaning of Variables

Term variables express functional dependence on closed values at all dimensions.

Thus a : A� B type [Ψ] means for all ψ : Ψ′ → Ψ,

if M.

= N ∈ A [Ψ′], then Bψ[M/a].

= Bψ[N/a] type [Ψ′].

In particular, type families transform lines into lines:

if M ∈ A [Ψ, x ]︸ ︷︷ ︸line in A

, then B[M/a] type [Ψ, x ]︸ ︷︷ ︸line of types

.

Page 73: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Pre- and Kan TypesVoevodsky (HTS)

These conditions define cubical pre-types

• From zero- to higher-dimensional types.

• Not sufficient for HoTT.

A full-fledged type must satisfy the Kan conditions:

• Type lines induce coercions between types.

• Paths must be closed under Kan composition.

Page 74: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Pre- and Kan TypesVoevodsky (HTS)

These conditions define cubical pre-types

• From zero- to higher-dimensional types.

• Not sufficient for HoTT.

A full-fledged type must satisfy the Kan conditions:

• Type lines induce coercions between types.

• Paths must be closed under Kan composition.

Page 75: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Type lines A type [Ψ, x ] induce coercions:

coer r ′x .A (M) ∈ A〈r ′/x〉 [Ψ] when M ∈ A〈r/x〉 [Ψ].

Coercion along A type [Ψ, x ] is trivial when r = r ′:

coer rx .A (M)

.= M ∈ A〈r/x〉 [Ψ].

Each type defines the meaning of coercion along lines!

Page 76: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Type lines A type [Ψ, x ] induce coercions:

coer r ′x .A (M) ∈ A〈r ′/x〉 [Ψ] when M ∈ A〈r/x〉 [Ψ].

Coercion along A type [Ψ, x ] is trivial when r = r ′:

coer rx .A (M)

.= M ∈ A〈r/x〉 [Ψ].

Each type defines the meaning of coercion along lines!

Page 77: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Type lines A type [Ψ, x ] induce coercions:

coer r ′x .A (M) ∈ A〈r ′/x〉 [Ψ] when M ∈ A〈r/x〉 [Ψ].

Coercion along A type [Ψ, x ] is trivial when r = r ′:

coer rx .A (M)

.= M ∈ A〈r/x〉 [Ψ].

Each type defines the meaning of coercion along lines!

Page 78: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Diagrammatically,

A〈0/x〉 A〈1/x〉A

Mcoe0 0x .A (M)

.=

coe0 1x .A (M)

Page 79: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Diagrammatically,

A〈0/x〉 A〈1/x〉A

Mcoe0 0x .A (M)

.=

coe0 1x .A (M)

Page 80: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Diagrammatically,

A〈0/x〉 A〈1/x〉A

Mcoe0 0x .A (M)

.=

coe0 1x .A (M)

∈coe0 x

x .A (M)

Page 81: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Coercion along a Line of Types

Diagrammatically,

A〈0/x〉 A〈1/x〉A

Mcoe0 0x .A (M)

.=

coe0 1x .A (M)

∈coe0 x

x .A (M)

Page 82: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Kan Composition

P〈0/x〉 P〈1/x〉 Q〈0/x〉 Q〈1/x〉

.=

P Q

P · Q

Paths in a type must compose.

• if P ∈ A [Ψ, x ], and Q ∈ A [Ψ, x ],

and

• P〈1/x〉 .= Q〈0/x〉 ∈ A [Ψ],

then

• there exists P · Q ∈ A [Ψ, x ],

• satisfying composition and identity laws up to higher paths.

Miraculously, there is a simple way to capture the full meaning!

Page 83: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Kan Composition

P〈0/x〉 P〈1/x〉 Q〈0/x〉 Q〈1/x〉.=

P Q

P · Q

Paths in a type must compose.

• if P ∈ A [Ψ, x ], and Q ∈ A [Ψ, x ], and

• P〈1/x〉 .= Q〈0/x〉 ∈ A [Ψ],

then

• there exists P · Q ∈ A [Ψ, x ],

• satisfying composition and identity laws up to higher paths.

Miraculously, there is a simple way to capture the full meaning!

Page 84: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Kan Composition

P〈0/x〉 P〈1/x〉 Q〈0/x〉 Q〈1/x〉.=

P Q

P · Q

Paths in a type must compose.

• if P ∈ A [Ψ, x ], and Q ∈ A [Ψ, x ], and

• P〈1/x〉 .= Q〈0/x〉 ∈ A [Ψ], then

• there exists P · Q ∈ A [Ψ, x ],

• satisfying composition and identity laws up to higher paths.

Miraculously, there is a simple way to capture the full meaning!

Page 85: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Kan Composition

P〈0/x〉 P〈1/x〉 Q〈0/x〉 Q〈1/x〉.=

P Q

P · Q

Paths in a type must compose.

• if P ∈ A [Ψ, x ], and Q ∈ A [Ψ, x ], and

• P〈1/x〉 .= Q〈0/x〉 ∈ A [Ψ], then

• there exists P · Q ∈ A [Ψ, x ],

• satisfying composition and identity laws up to higher paths.

Miraculously, there is a simple way to capture the full meaning!

Page 86: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Kan Composition

P〈0/x〉 P〈1/x〉 Q〈0/x〉 Q〈1/x〉.=

P Q

P · Q

Paths in a type must compose.

• if P ∈ A [Ψ, x ], and Q ∈ A [Ψ, x ], and

• P〈1/x〉 .= Q〈0/x〉 ∈ A [Ψ], then

• there exists P · Q ∈ A [Ψ, x ],

• satisfying composition and identity laws up to higher paths.

Miraculously, there is a simple way to capture the full meaning!

Page 87: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The HCom Diagram

Pictorially,x

yM0

.= N0 M1

.= P0

N1 P1

M.

= hcom0 0A (M; ~T )

N P

hcom0 1A (M; ~T )

hcom0 yA (M; ~T )

Symbolically,

hcom0 yA ( M︸︷︷︸

cap

; x = 0 ↪→ y .N, x = 1 ↪→ y .P︸ ︷︷ ︸tube ~T

) ∈ A [Ψ, x , y ].

Page 88: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Composition and Inversion from HCom

Concatenation and reversal are definable:

P0

P0

P1

Q1

P0 Q

P

P · Q

P0

P1

P0

P0

P P0

P0

P−1

Kan composition suffices to derive composition laws.

Page 89: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Strict Booleans

The type bool is defined such that for all M and Ψ,

M ∈ bool [Ψ] iff M ⇓ true or M ⇓ false.

Therefore, we can make bool Kan:

• coer r ′.bool(M) 7−→ M for any M, r , r ′.

• hcomr r ′bool (M; ~T ) 7−→ M for any M, ~T , r , r ′.

The properties of bool stated earlier carry over directly.

• Same proofs, using equality pre-type for equations.

• e.g., Shannon expansion.

Page 90: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Strict Booleans

The type bool is defined such that for all M and Ψ,

M ∈ bool [Ψ] iff M ⇓ true or M ⇓ false.

Therefore, we can make bool Kan:

• coer r ′.bool(M) 7−→ M for any M, r , r ′.

• hcomr r ′bool (M; ~T ) 7−→ M for any M, ~T , r , r ′.

The properties of bool stated earlier carry over directly.

• Same proofs, using equality pre-type for equations.

• e.g., Shannon expansion.

Page 91: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

Canonical:

• wbool, true, and false as before.

• fcomr r ′(M; ~T ), where r 6= r ′.

Fcom = formal composition of booleans:

N

M

N ′

Page 92: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

Canonical:

• wbool, true, and false as before.

• fcomr r ′(M; ~T ), where r 6= r ′.

Fcom = formal composition of booleans:

N

M

N ′

Page 93: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

Conditional offloads composition to the motive at higher dims!

ifa.A(true;P;Q) 7−→ P

ifa.A(false;P;Q) 7−→ Q

ifa.A( N

M

N ′ ;P;Q) 7−→

ifa.A(N;P;Q)

ifa.A(M;P;Q)

ifa.A(N′;P;Q)

Result composition is heterogeneous.

Page 94: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

The motive of the conditional on wbool must be Kan!

a : wbool� A typeKan [Ψ].

Theorem (Dependent Elimination)

If M ∈ bool [Ψ] and P ∈ A[true/a] [Ψ] and Q ∈ A[false/a] [Ψ], then

ifa.A(M;P;Q) ∈ A[M/a] [Ψ].

Looks unremarkable, but is not trivial because of higher dim’s.

Page 95: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

The motive of the conditional on wbool must be Kan!

a : wbool� A typeKan [Ψ].

Theorem (Dependent Elimination)

If M ∈ bool [Ψ] and P ∈ A[true/a] [Ψ] and Q ∈ A[false/a] [Ψ], then

ifa.A(M;P;Q) ∈ A[M/a] [Ψ].

Looks unremarkable, but is not trivial because of higher dim’s.

Page 96: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Weak Booleans

The motive of the conditional on wbool must be Kan!

a : wbool� A typeKan [Ψ].

Theorem (Dependent Elimination)

If M ∈ bool [Ψ] and P ∈ A[true/a] [Ψ] and Q ∈ A[false/a] [Ψ], then

ifa.A(M;P;Q) ∈ A[M/a] [Ψ].

Looks unremarkable, but is not trivial because of higher dim’s.

Page 97: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Circle

The circle C is like wbool.

C-elima.A(base;N, x .P) 7−→ N

C-elima.A(loopy ;N, x .P) 7−→ P〈y/x〉

C-elima.A( M

M ′

M ′′ ;N, x .P) 7−→

C-elima.A(M;N, x .P)

C-elima.A(M′;N, x .P)

C-elima.A(M′′;N, x .P)

Iterations of loop defined using formal composition.

Page 98: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Circle

The circle C is like wbool.

C-elima.A(base;N, x .P) 7−→ N

C-elima.A(loopy ;N, x .P) 7−→ P〈y/x〉

C-elima.A( M

M ′

M ′′ ;N, x .P) 7−→

C-elima.A(M;N, x .P)

C-elima.A(M′;N, x .P)

C-elima.A(M′′;N, x .P)

Iterations of loop defined using formal composition.

Page 99: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Abstraction and application as before:

• Canonical: (a:A)→ B, λa.M.

• Non-canonical: app(M,N).

• Computation: app(λa.P,N) 7−→ P[N/a].

Coercion co- and contra-variantly:

coer r ′

x .(a:A)→B(M) 7−→ λa.coer r ′x .B (app(M, coer

′ rx .A (a))).

Kan composition by extensionality:

hcomr r ′

(a:A)→B(M; ~T ) 7−→ λa.hcomr r ′B (app(M, a); app( ~T , a)).

Page 100: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Abstraction and application as before:

• Canonical: (a:A)→ B, λa.M.

• Non-canonical: app(M,N).

• Computation: app(λa.P,N) 7−→ P[N/a].

Coercion co- and contra-variantly:

coer r ′

x .(a:A)→B(M) 7−→ λa.coer r ′x .B (app(M, coer

′ rx .A (a))).

Kan composition by extensionality:

hcomr r ′

(a:A)→B(M; ~T ) 7−→ λa.hcomr r ′B (app(M, a); app( ~T , a)).

Page 101: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Functions

Abstraction and application as before:

• Canonical: (a:A)→ B, λa.M.

• Non-canonical: app(M,N).

• Computation: app(λa.P,N) 7−→ P[N/a].

Coercion co- and contra-variantly:

coer r ′

x .(a:A)→B(M) 7−→ λa.coer r ′x .B (app(M, coer

′ rx .A (a))).

Kan composition by extensionality:

hcomr r ′

(a:A)→B(M; ~T ) 7−→ λa.hcomr r ′B (app(M, a); app( ~T , a)).

Page 102: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Paths

The type Pathx .A(P0,P1) specifies paths in A with end points P0 and P1.

Dimension abstraction and application:

• Pathx .A(P0,P1), 〈x〉M are canonical.

• (〈x〉M)@r 7−→ M〈r/x〉.

Paths are Kan, provided that A is Kan.

Page 103: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Paths

Coercion: coe0 1y .Pathx.A(P0,P1)(M) 7−→

〈x〉com0 1y .A (M@x ; x = 0 ↪→ y .P0, x = 1 ↪→ y .P1).

y

xP0〈0/y〉

.= M@0 M@1

.= P1〈1/y〉

M@x

P0〈1/y〉 P1〈1/y〉

P0 P1

Page 104: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, Revisited

HoTT identity type splits into two concepts:

• Exact equality: extensional, evidence-free.

• Paths of arbitrary dimension.

Both may be internalized:

• Equality pre-type, may or may not be Kan.

• Path type, always Kan.

Equality proofs are irrelevant and erasable.

Coercion and composition express the computational content of paths in each type.

Page 105: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, Revisited

HoTT identity type splits into two concepts:

• Exact equality: extensional, evidence-free.

• Paths of arbitrary dimension.

Both may be internalized:

• Equality pre-type, may or may not be Kan.

• Path type, always Kan.

Equality proofs are irrelevant and erasable.

Coercion and composition express the computational content of paths in each type.

Page 106: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, Revisited

HoTT identity type splits into two concepts:

• Exact equality: extensional, evidence-free.

• Paths of arbitrary dimension.

Both may be internalized:

• Equality pre-type, may or may not be Kan.

• Path type, always Kan.

Equality proofs are irrelevant and erasable.

Coercion and composition express the computational content of paths in each type.

Page 107: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, Revisited

Path type admits structure of identity type.

• Intro: reflA(M) ∈ Path .A(M,M).

• Elim: J(u.Q;P) with P ∈ Path .A(M,N).

Does not validate β law, because reflexivity is not special.

Page 108: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, RevisitedAwodey; Cavallo

Jdentity type is definable as free Kan type on reflexivity:

• Validates β law for J.

• Elimination commutes with free Kan structure.

Admits computation: J is never “stuck.”

But does not validate type-directed path laws!

It seems that we cannot have it both ways!

Page 109: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

HoTT, RevisitedAwodey; Cavallo

Jdentity type is definable as free Kan type on reflexivity:

• Validates β law for J.

• Elimination commutes with free Kan structure.

Admits computation: J is never “stuck.”

But does not validate type-directed path laws!

It seems that we cannot have it both ways!

Page 110: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

RedPRL: Proof Refinement LogicSterling, Hou, Angiuli

notation meaning

Ψ | Γ =⇒ A true ; e There exists a term e such that if Γ ctx [Ψ], thenΓ� A typepre [Ψ] and Γ� e ∈ A [Ψ].

Ψ | Γ =⇒ A.

= B typek If Γ ctx [Ψ], then Γ� A.

= B typek [Ψ].

Ψ | Γ =⇒ e synth ; A There exists a term A such that if Γ ctx [Ψ],then Γ� A typepre [Ψ] and Γ� e ∈ A [Ψ].

Ψ | Γ =⇒ A v B If Γ ctx [Ψ], then Γ � A typepre [Ψ] and Γ �B typepre [Ψ], and Γ, a : A� a ∈ B [Ψ].

Ψ | Γ =⇒ A v Ukω If Γ ctx [Ψ], then there exists some level i and

kind k ′ ≤ k such that Γ� A.

= Uk′

i typepre [Ψ].

Page 111: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

Demonstration

Please enjoy Carlo’s demonstration of RedPRL!

Page 112: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

References I

Stuart F Allen, Mark Bickford, Robert L Constable, Richard Eaton, Christoph Kreitz, Lori Lorigo, and Evan Moran. Innovations in computationaltype theory using Nuprl. Journal of Applied Logic, 4(4):428–469, 2006.

Carlo Angiuli and Robert Harper. Meaning explanations at higher dimension. Indagationes Mathematicae, 29:135–149, 2018. Virtual Special Issue –L.E.J. Brouwer after 50 years.

Carlo Angiuli, Guillaume Brunerie, Thierry Coquand, Kuen-Bang Hou (Favonia), Robert Harper, and Daniel R. Licata. Cartesian cubical type theory.(Unpublished manuscript), December 2017a.

Carlo Angiuli, Kuen-Bang Hou (Favonia), and Robert Harper. Computational higher type theory III: Univalent universes and exact equality. Preprint,December 2017b. URL https://arxiv.org/abs/1712.01800.

Marc Bezem, Thierry Coquand, and Simon Huber. A model of type theory in cubical sets. In 19th International Conference on Types for Proofs andPrograms (TYPES 2013), volume 26, pages 107–128, 2014.

Evan Cavallo and Robert Harper. Computational higher type theory IV: Inductive types. Preprint, January 2018. URLhttps://arxiv.org/abs/1801.01568.

Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mortberg. Cubical type theory: a constructive interpretation of the univalence axiom. toappear in the proceedings of TYPES 2015, 2015.

Simon Huber. Canonicity for cubical type theory. Preprint arXiv:1607.04156v1 [cs.LO], July 2016.

Jonathan Sterling, Kuen-Bang Hou (Favonia), Evan Cavallo, Carlo Angiuli, James Wilcox, Eugene Akentyev, David Christiansen, Daniel Gratzer, andDarin Morrison. RedPRL – the People’s Refinement Logic. http://www.redprl.org/, 2017.

Vladimir Voevodsky. A simple type system with two identity types. Lecture notes, February 2013. URLhttps://www.math.ias.edu/vladimir/sites/math.ias.edu.vladimir/files/HTS.pdf.

Page 113: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

InvRefl

(path [_] (path [_] ty a a) ($ PathInv ty a a (abs [_] a)) (abs [_] a))

abs x => abs y =>

yx

z

· ·

· ·a

a

a(@ ($ PathInv ty a a (abs [ ] a)) y)

·

·

·

·

a

a

a

·

·

Page 114: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

InvRefl

(path [_] (path [_] ty a a) ($ PathInv ty a a (abs [_] a)) (abs [_] a))

abs x => abs y =>

yx

z

· ·

· ·a

a

a

(@ ($ PathInv ty a a (abs [ ] a)) y)

·

·

·

·

a

a

a

·

·

Page 115: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

InvRefl

(path [_] (path [_] ty a a) ($ PathInv ty a a (abs [_] a)) (abs [_] a))

abs x => abs y =>

yx

z

· ·

· ·a

a

a

(@ ($ PathInv ty a a (abs [ ] a)) y)

·

·

·

·

a

a

a

·

·

Page 116: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Univalence TypeFavonia; CCHM

M

N0 N1N

Vinx(M,N)E

A

B0 B1B

Vx(A,B,E )E ∼

Page 117: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Univalence TypeFavonia; CCHM

M N1

N0 N1N

Vinx(M,N)

E

A B1

B0 B1B

Vx(A,B,E )

E ∼

Page 118: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Coe Diagram

Given M ∈ A [Ψ, x ]:

M0 M1M

∈ A0 A1A

Then coex yx .Ax

(Mx) ∈ Ay [Ψ, x , y ]:

xy

M0 coe1 0x .Ax

(M1)

coe0 1x .Ax

(M0) M1

coex 0x .Ax

(Mx) ∈ A0

coe0 yx .Ax

(M0) ∈ Ay coe1 yx .Ax

(M1) ∈ Ay

coex 1x .Ax

(Mx) ∈ A1

coex yx .Ax

(Mx)

Page 119: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Coe Diagram

Given M ∈ A [Ψ, x ]:

M0 M1M

∈ A0 A1A

Then coex yx .Ax

(Mx) ∈ Ay [Ψ, x , y ]:

xy

M0 coe1 0x .Ax

(M1)

coe0 1x .Ax

(M0) M1

coex 0x .Ax

(Mx) ∈ A0

coe0 yx .Ax

(M0) ∈ Ay coe1 yx .Ax

(M1) ∈ Ay

coex 1x .Ax

(Mx) ∈ A1

M

Page 120: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Com Diagram

com0 1y .A (M; x = 0 ↪→ y .N0, x = 1 ↪→ y .N1) ∈ A〈1/y〉 [Ψ, x ]

yx

∈ A〈1/y〉

· ·

· ·

M ∈ A〈0/y〉

A〈0/x〉 3 N0 N1 ∈ A〈1/x〉

· ·

coey 1y .A〈0/x〉(N0)

coey 1y .A〈1/x〉(N1)

coe0 1y .A (M)

Page 121: Computational (Higher) Type Theoryrwh/talks/POPL18-Tutorial.pdfComputational (Higher) Type Theory Robert Harper and Carlo Angiuli Computer Science Department Carnegie Mellon University

The Com Diagram

com0 1y .A (M; x = 0 ↪→ y .N0, x = 1 ↪→ y .N1) ∈ A〈1/y〉 [Ψ, x ]

yx

∈ A〈1/y〉

· ·

· ·

M ∈ A〈0/y〉

A〈0/x〉 3 N0 N1 ∈ A〈1/x〉

· ·

coey 1y .A〈0/x〉(N0)

coey 1y .A〈1/x〉(N1)

coe0 1y .A (M)


Recommended