# Posts in the category Tutorial

### How to implement type theory in an hour

- 25 August 2018
- Programming, Talks, Tutorial

I was purging the disk on my laptop of large files and found a video lecture which I forgot to publish. Here it is with some delay. I lectured on how to implement type theory at the School and Workshop on Univalent Mathematics in December 2017, at the University of Birmingham (UK).

You may visit the GitHub repository spartan-type-theory. There used to be a video, but I lost it.

→ continue reading (1 comment)### Spartan type theory

- 11 December 2017
- Type theory, Talks, Tutorial

The slides from the talk “Spartan type theory”, given at the School and Workshop on Univalent Mathematics.

**Download slides with speaker notes: Spartan Type Theory [PDF]**

### Univalent foundations subsume classical mathematics

- 13 January 2014
- Type theory, Logic, Tutorial

A discussion on the homotopytypetheory mailing list prompted me to write this short note. Apparently a mistaken belief has gone viral among certain mathematicians that Univalent foundations is somehow limited to constructive mathematics. This is false. Let me be perfectly clear:

*Univalent foundations subsume classical mathematics!*

The next time you hear someone having doubts about this point, please refer them to this post. A more detailed explanation follows.

→ continue reading (24 comments)### The elements of an inductive type

- 28 August 2013
- Constructive math, Type theory, Tutorial

In the HoTT book issue 460 a question by *gluttonousGrandma* (where do people get these nicknames?) once more exposed a common misunderstanding that we tried to explain in section 5.8 of the book (many thanks to Bas Spitters for putting the book into Google Books so now we can link to particular pages). Apparently the following belief is widely spread, and I admit to holding it a couple of years ago:

An inductive type contains exactly those elements that we obtain by repeatedly using the constructors.

If you believe the above statement you should keep reading. I am going to convince you that the statement is unfounded, or that at the very least it is preventing you from understanding type theory.

→ continue reading (29 comments)Mathematicians are often confused about the meaning of variables. I hear them say “a free variable is implicitly universally quantified”, by which they mean that it is ok to equate a formula $\phi$ with a free variable $x$ with its universal closure $\forall x \,.\, \phi$. I am addressing this post to those who share this opinion.

→ continue reading (31 comments)### How to implement dependent type theory III

- 28 November 2012
- Type theory, Programming, Software, Tutorial

I spent a week trying to implement higher-order pattern unification. I looked at couple of PhD dissertations, talked to lots of smart people, and failed because the substitutions were just getting in the way all the time. So today we are going to bite the bullet and implement de Bruijn indices and explicit substitutions.

The code is available on Github in the repository andrejbauer/tt (the `blog-part-III`

branch).

### How to implement dependent type theory II

- 11 November 2012
- Type theory, Programming, Software, Tutorial

I am on a roll. In the second post on how to implement dependent type theory we are going to:

- Spiff up the syntax by allowing more flexible syntax for bindings in functions and products.
- Keep track of source code locations so that we can report
*where*the error has occurred. - Perform normalization by evaluation.

### How to implement dependent type theory I

- 07 November 2012
- Type theory, Programming, Software, Tutorial

I am spending a semester at the Institute for Advanced Study where we have a special year on Univalent foundations. We are doing all sorts of things, among others experimenting with type theories. We have got some real experts here who know type theory and Coq inside out, and much more, and they're doing crazy things to Coq (I will report on them when they are done). In the meanwhile I have been thinking how one might implement dependent type theories with undecidable type checking. This is a tricky subject and I am certainly not the first one to think about it. Anyhow, if I want to experiment with type theories, I need a small prototype first. Today I will present a very minimal one, and build on it in future posts.

Make a guess, how many lines of code does it take to implement a dependent type theory with universes, dependent products, a parser, lexer, pretty-printer, and a toplevel which uses line-editing when available?

→ continue reading (9 comments)I am sitting on a tutorial on categorical semantics of dependent type theory given by Peter Lumsdaine. He is talking about categories with attributes and other variants of categories that come up in the semantics of dependent type theory. He is amazingly good at fielding questions about definitional equality from the type theorists. And it looks like some people are puzzling over pullbacks showing up, which Peter is about to explain using syntactic categories. Here is a pedestrian explanation of a very important fact:

→ continue reading (14 comments)

Substitution is pullback.

### A hott thesis

- 23 August 2012
- Type theory, News, Tutorial

Egbert Rijke successfully defended his master thesis in Utrecht a couple of weeks ago. He published it on the *Homotopy type theory* blog (here is a direct link to the PDF file (revised)). The thesis is well written and it contains several new results, but most importantly, it is a gentle yet non-trivial introduction to homotopy type theory. If you are interested in the topic but do not know where to start, Egbert's thesis might be perfect for you. As far as I know it is the first substantial piece of text written *in* (informal) homotopy type theory.

What I find most amazing about the work is that Egbert does not have to pretend to be a homotopy type theorist, like us old folks. His first contact with type theory *was* homotopy type theory, which impressed on his mind a new kind of geometric intuition about $\Pi$'s, $\Sigma$'s and $\mathrm{Id}$'s. If we perform enough such experiments on young bright students, strange things will happen.

### Definability and extensionality of the modulus of continuity functional

- 27 July 2011
- Computation, Tutorial

In an earlier post I talked about the modulus of continuity functional, where I stated that it cannot be defined without using some form of computational effects. It is a bit hard to find the proof of this fact so I am posting it on my blog in two parts, for Google and everyone else to find more easily. In the first part I show that there is no extensional modulus of continuity. In the second part I will show that every functional that is defined in PCF (simply-typed $\lambda$-calculus with natural numbers and recursion) is extensional.

→ continue reading (8 comments)### Running a classical proof with choice in Agda

- 10 May 2011
- Computation, Constructive math, Guest post, Logic, Programming, Tutorial

As a preparation for my part of a joint tutorial *Programs from proofs* at MFPS 27 at the end of this month with Ulrich Berger, Monika Seisenberger, and Paulo Oliva, I've developed in Agda some things we've been doing together.

Using

- Berardi-Bezem-Coquand functional, or alternatively,
- Berger-Oliva modified bar recursion, or alternatively,
- Escardo-Oliva countable product of selection functions,

for giving a proof term for classical countable choice, we prove the classical infinite pigeonhole principle in Agda: every infinite boolean sequence has a constant infinite subsequence, where the existential quantification is classical (double negated).

As a corollary, we get the finite pigeonhole principle, using Friedman's trick to make the existential quantifiers intuitionistic.

This we can run, and it runs fast enough. The point is to illustrate in Agda how we can get witnesses from classical proofs that use countable choice. The finite pigeonhole principle has a simple constructive proof, of course, and hence this is really for illustration only.

The main Agda files are

These are Agda files converted to html so that you can navigate them by clicking at words to go to their definitions. A zip file with all Agda files is available. Not much more information is available here.

The three little modules that implement the Berardi-Bezem-Coquand, Berger-Oliva and Escardo-Oliva functionals disable the termination checker, but no other module does. The type of these functionals in Agda is the J-shift principle, which generalizes the double-negation shift.

→ continue reading (3 comments)### Programming with effects II: Introducing eff

- 27 September 2010
- Computation, Eff, Guest post, Programming, Software, Tutorial

**[UPDATE 2012-03-08: since this post was written eff has changed considerably. For updated information, please visit the eff page.]**

****This is a second post about the programming language eff. We covered the theory behind it in a previous post. Now we turn to the programming language itself.

Please bear in mind that eff is an academic experiment. It is not meant to take over the world. Yet. We just wanted to show that the theoretical ideas about the algebraic nature of computational effects can be put into practice. Eff has many superficial similarities with Haskell. This is no surprise because there is a precise connection between algebras and monads. The main advantage of eff over Haskell is supposed to be the ease with which computational effects can be combined.

→ continue reading (7 comments)### Programming with effects I: Theory

- 27 September 2010
- Computation, Eff, Programming, Software, Talks, Tutorial

**[UPDATE 2012-03-08: since this post was written eff has changed considerably. For updated information, please visit the eff page.]**

I just returned from Paris where I was visiting the INRIA ?r² team. It was a great visit, everyone was very hospitable, the food was great, and the weather was nice. I spoke at their seminar where I presented a new programming language * eff* which is based on the idea that computational effects are algebras. The language has been designed and implemented jointly by Matija Pretnar and myself. Eff is far from being finished, but I think it is ready to be shown to the world. What follows is an extended transcript of the talk I gave in Paris. It is divided into two posts. The present one reviews the basic theory of algebras for a signature and how they are related to computational effects. The impatient readers can skip ahead to the second part, which is about the programming language.

A side remark: I have updated the blog to WordPress to 3.0 and switched to MathJax for displaying mathematics. Now I need to go through 70 old posts and convert the old ASCIIMathML notation to MathJax, as well as fix characters which got garbled during the update. Oh well, it is an investment for the future.

→ continue reading (18 comments)### Random art in Python

- 21 April 2010
- Programming, Software, Tutorial

I get asked every so often to release the source code for my random art project. The original source is written in Ocaml and is not publicly available, but here is a simple example of how you can get random art going in python in 250 lines of code.

**Download source:** randomart.py

I am discovering that mathematicians cannot tell the difference between “proof by contradiction” and “proof of negation”. This is so for good reasons, but conflation of different kinds of proofs is bad mental hygiene which leads to bad teaching practice and confusion. For reference, here is a short explanation of the difference between proof of negation and proof by contradiction.

→ continue reading (24 comments)### Tutorial on exact real numbers in Coq

- 07 January 2010
- Computation, Constructive math, Programming, Tutorial

Already a while ago videolectures.net published this **tutorial on Computer Verified Exact Analysis** by Bas Spitters and Russell O'Connor from Computability and Complexity in Analysis 2009. I forgot to advertise it, so I am doing this now. It is about an implementation of exact real arithmetic whose correctness has been verified in Coq. Russell also gave a quick tutorial on Coq.

### On programming language design

- 11 April 2009
- General, Programming, Tutorial

In a recent post I claimed that Python's lambda construct is broken. This attracted some angry responses by people who thought I was confused about how Python works. Luckily there were also many useful responses from which I learnt. This post is a response to comment 27, which asks me to say more about my calling certain design decisions in Python crazy.

→ continue reading (62 comments)### Intuitionistic mathematics for physics

- 13 August 2008
- Constructive math, Tutorial

At MSFP 2008 in Iceland I chatted with Dan Piponi about physics and intuitionistic mathematics, and he encouraged me to write down some of the ideas. I have little, if anything, original to say, so this seems like an excellent opportunity for a blog post. So let me explain why I think *intuitionistic mathematics is good for physics*.

### Representations of uncomputable and uncountable sets

- 06 February 2008
- Computation, Tutorial

Occasionally I hear claims that uncountable and uncomputable sets cannot be represented on computers. More generally, there are all sorts of misguided opinions about representations of data on computers, especially infinite data of mathematical nature. Here is a quick tutorial on the matter whose main point is:

→ continue reading (11 comments)It is

meaninglessto discuss representations of a set by a datatype without also considering operations that we want to perform on the set.

### Seemingly impossible functional programs

- 28 September 2007
- Computation, Guest post, Tutorial

Andrej has invited me to write about certain surprising functional programs. The first program, due to Ulrich Berger (1990), performs exhaustive search over the “Cantor space” of infinite sequences of binary digits. I have included references at the end. A weak form of exhaustive search amounts to checking whether or not a total predicate holds for all elements of the Cantor space. Thus, this amounts to universal quantification over the Cantor space. Can this possibly be done algorithmically, in finite time?

→ continue reading (21 comments)### Synthetic Computability (MFPS XXIII Tutorial)

- 24 May 2007
- Constructive math, Synthetic computability, Talks, Tutorial

A tutorial presented at the *Mathematical Foundations of Programming Semantics XXIII* Tutorial Day.

The famous theorem by Cantor states that the cardinality of a powerset $P(A)$ is larger than the cardinality of $A$. There are several equivalent formulations, and the one I want to consider is

Theorem (Cantor):There is no onto map $A \to P(A)$.

In this post I would like to analyze the usual proof of Cantor's theorem and present an insightful reformulation of it which has applications outside set theory.

→ continue reading (6 comments)### König's Lemma and the Kleene Tree

- 25 April 2006
- Computation, Constructive math, Publications, Tutorial

For the benefit of the topology seminar audience at the math department of University of Ljubljana, I have written a self-contained explanation of the Kleene tree, which is an interesting object in computability theory. For the benefit of the rest of the planet, I am publishing it here.

→ continue reading (2 comments)### Sometimes all functions are continuous

- 27 March 2006
- Computation, Constructive math, Tutorial

You may have heard at times that there are mathematicians who think that *all* functions are continuous. One way of explaining this is to show that all *computable* functions are continuous. The point not appreciated by many (even experts) is that the truth of this claim depends on what programming language we use.

### Proof hacking

- 15 September 2005
- Computation, Logic, Tutorial

### How many is two?

- 15 May 2005
- Constructive math, Logic, Tutorial

In constructive mathematics even very small sets can be quite a bit more interesting than in classical mathematics. Since you will not believe me that sets with at most one element are very interesting, let us look at the set of truth values, which has “two” elements.

→ continue reading (18 comments)### The Law of Excluded Middle

- 13 May 2005
- Constructive math, Tutorial