An Introduction to Type Theory Part 2 Tallinn, September 2003 - - PowerPoint PPT Presentation

an introduction to type theory
SMART_READER_LITE
LIVE PREVIEW

An Introduction to Type Theory Part 2 Tallinn, September 2003 - - PowerPoint PPT Presentation

An Introduction to Type Theory Part 2 Tallinn, September 2003 http://www.cs.nott.ac.uk/txa/tallinn/ Thorsten Altenkirch University of Nottingham An Introduction to Type Theory p.1/46 Plan of the course 1. Intuitionistic logic from a


slide-1
SLIDE 1

An Introduction to Type Theory

Part 2

Tallinn, September 2003 http://www.cs.nott.ac.uk/˜txa/tallinn/

Thorsten Altenkirch University of Nottingham

An Introduction to Type Theory – p.1/46

slide-2
SLIDE 2

Plan of the course

  • 1. Intuitionistic logic from a type theoretic perspective
  • 2. Basic constructions of Type Theory
  • 3. Programming with dependent types

An Introduction to Type Theory – p.2/46

slide-3
SLIDE 3

Today

Basic constructions of Type Theory

An Introduction to Type Theory – p.3/46

slide-4
SLIDE 4

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

.

An Introduction to Type Theory – p.3/46

slide-5
SLIDE 5

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • An Introduction to Type Theory – p.3/46
slide-6
SLIDE 6

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • Proof or program?

An Introduction to Type Theory – p.3/46

slide-7
SLIDE 7

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • Proof or program?
✂✁ ✄ ✁ ✄ ✁ ☎ ✁
  • Pattern matching and elimination

An Introduction to Type Theory – p.3/46

slide-8
SLIDE 8

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • Proof or program?
✂✁ ✄ ✁ ✄ ✁ ☎ ✁
  • Pattern matching and elimination

Uniqueness of equality proofs

An Introduction to Type Theory – p.3/46

slide-9
SLIDE 9

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • Proof or program?
✂✁ ✄ ✁ ✄ ✁ ☎ ✁
  • Pattern matching and elimination

Uniqueness of equality proofs Inductive families

An Introduction to Type Theory – p.3/46

slide-10
SLIDE 10

Today

Basic constructions of Type Theory From Logic to Type Theory:

✂✁ ✄

. Example: Decidability of

  • Proof or program?
✂✁ ✄ ✁ ✄ ✁ ☎ ✁
  • Pattern matching and elimination

Uniqueness of equality proofs Inductive families Loose ends

An Introduction to Type Theory – p.3/46

slide-11
SLIDE 11

From Logic to Type Theory

An Introduction to Type Theory – p.4/46

slide-12
SLIDE 12

From Logic to Type Theory

In intuitionistic logic constructing proofs is very much like writing functional programs.

An Introduction to Type Theory – p.4/46

slide-13
SLIDE 13

From Logic to Type Theory

In intuitionistic logic constructing proofs is very much like writing functional programs. In Type Theory we go one step further: Proofs = Programs Propositions = Types

An Introduction to Type Theory – p.4/46

slide-14
SLIDE 14

From Logic to Type Theory

An Introduction to Type Theory – p.5/46

slide-15
SLIDE 15

From Logic to Type Theory

We will also make the following indentifications:

An Introduction to Type Theory – p.5/46

slide-16
SLIDE 16

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Function types (

  • )

An Introduction to Type Theory – p.5/46

slide-17
SLIDE 17

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Pi-types (

  • )

Function types (

  • )

An Introduction to Type Theory – p.5/46

slide-18
SLIDE 18

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Pi-types (

  • )

Function types (

  • )

Conjunction (

  • )

Existential quantification (

) Cartesian product (

)

An Introduction to Type Theory – p.5/46

slide-19
SLIDE 19

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Pi-types (

  • )

Function types (

  • )

Conjunction (

  • )

Existential quantification (

) Sigma-types (

) Cartesian product (

)

An Introduction to Type Theory – p.5/46

slide-20
SLIDE 20

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Pi-types (

  • )

Function types (

  • )

Conjunction (

  • )

Existential quantification (

) Sigma-types (

) Cartesian product (

) Disjunction Disjoint union (

)

An Introduction to Type Theory – p.5/46

slide-21
SLIDE 21

From Logic to Type Theory

We will also make the following indentifications: Implication (

  • )

Universal quantifications (

) Pi-types (

  • )

Function types (

  • )

Conjunction (

  • )

Existential quantification (

) Sigma-types (

) Cartesian product (

) Disjunction Disjoint union (

) Disjoint union (

)

An Introduction to Type Theory – p.5/46

slide-22
SLIDE 22

From Logic to Type Theory

Elimination becomes more subtle:

An Introduction to Type Theory – p.6/46

slide-23
SLIDE 23

From Logic to Type Theory

Elimination becomes more subtle:

Pattern matching We have to keep track of the steps in

the type.

An Introduction to Type Theory – p.6/46

slide-24
SLIDE 24

From Logic to Type Theory

Elimination becomes more subtle:

Pattern matching We have to keep track of the steps in

the type.

Elimination constants Get replaced by their dependent

versions.

An Introduction to Type Theory – p.6/46

slide-25
SLIDE 25

Set theoretic encodings

An Introduction to Type Theory – p.7/46

slide-26
SLIDE 26

Set theoretic encodings

Let

be sets, then:

  • ✂✄
☎ ✁ ✆ ✝✞ ☎ ✟
✟ ✁ ✠
✡ ☛
✁ ✞ ✁ ☎ ✟
✁ ✌ ✆ ✟ ✁ ☞ ✄ ☎ ✁ ✆ ✝ ✟ ✡ ✠

An Introduction to Type Theory – p.7/46

slide-27
SLIDE 27

Set theoretic encodings

Let

be sets, then:

  • ✂✄
☎ ✁ ✆ ✝✞ ☎ ✟
✟ ✁ ✠
✡ ☛
✁ ✞ ✁ ☎ ✟
✁ ✌ ✆ ✟ ✁ ☞ ✄ ☎ ✁ ✆ ✝ ✟ ✡ ✠

Let

  • be a set and for each
☎ ✟
  • let
✁ ✄ ☎ ✝

be a set, then:

✄ ☎ ✟
✁ ✄ ☎ ✝
  • ✂✄
☎ ✁ ✆ ✝ ✞ ☎ ✟
✟ ✁ ✄ ☎ ✝ ✠
✁ ✄ ☎ ✝
✡ ☛ ✄ ☎ ✟
✁ ✄ ☎ ✝ ✞ ✁ ☎ ✟
✁ ✌ ✆ ✟ ✁ ✄ ☎ ✝ ☞ ✄ ☎ ✁ ✆ ✝ ✟ ✡ ✠

An Introduction to Type Theory – p.7/46

slide-28
SLIDE 28

Example: Decidability of

  • An Introduction to Type Theory – p.8/46
slide-29
SLIDE 29

Example: Decidability of

  • In intuitionistic arithmetic we can prove
✁ ✟
✄ ☞ ✄
✝ ✂ ✄

where

✁ ✝✟✞✠

An Introduction to Type Theory – p.8/46

slide-30
SLIDE 30

Example: Decidability of

  • In intuitionistic arithmetic we can prove
✁ ✟
✄ ☞ ✄
✝ ✂ ✄

where

✁ ✝✟✞✠

We will use this example to motivate the idea that proofs = programs.

An Introduction to Type Theory – p.8/46

slide-31
SLIDE 31

Natural Numbers

An Introduction to Type Theory – p.9/46

slide-32
SLIDE 32

Natural Numbers

How to form ?

An Introduction to Type Theory – p.9/46

slide-33
SLIDE 33

Natural Numbers

How to form ?

✂✁ ✄ ✟ ✂✁ ✄ ✠

An Introduction to Type Theory – p.9/46

slide-34
SLIDE 34

Natural Numbers

How to form ?

✂✁ ✄ ✟ ✂✁ ✄ ✠

How to construct ?

An Introduction to Type Theory – p.9/46

slide-35
SLIDE 35

Natural Numbers

How to form ?

✂✁ ✄ ✟ ✂✁ ✄ ✠

How to construct ?

✄ ✁ ✟
✄ ✞ ✁ ✟ ✂✁ ✄

An Introduction to Type Theory – p.9/46

slide-36
SLIDE 36

Equality

An Introduction to Type Theory – p.10/46

slide-37
SLIDE 37

Equality

How to form ?

An Introduction to Type Theory – p.10/46

slide-38
SLIDE 38

Equality

How to form ?

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✟ ✂✁ ✄ ✠

An Introduction to Type Theory – p.10/46

slide-39
SLIDE 39

Equality

How to form ?

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✟ ✂✁ ✄ ✠

How to prove ?

An Introduction to Type Theory – p.10/46

slide-40
SLIDE 40

Equality

How to form ?

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✟ ✂✁ ✄ ✠

How to prove ?

✂✁ ✄ ✠ ☎ ✟
✁ ☎ ✟ ☎

An Introduction to Type Theory – p.10/46

slide-41
SLIDE 41

Proving decidablity

An Introduction to Type Theory – p.11/46

slide-42
SLIDE 42

Proving decidablity

We will present a proof

✁ ✟ ✂✁ ✄ ☞ ✄
✝ ☎ ✄

using pattern matching.

An Introduction to Type Theory – p.11/46

slide-43
SLIDE 43

Proving decidablity

We will present a proof

✁ ✟ ✂✁ ✄ ☞ ✄
✝ ☎ ✄

using pattern matching. We will discuss the rules for pattern matching later.

An Introduction to Type Theory – p.11/46

slide-44
SLIDE 44

Peano’s axioms

An Introduction to Type Theory – p.12/46

slide-45
SLIDE 45

Peano’s axioms

✂ ✞
✟ ✂✁ ✄ ☞ ✄
✁ ✝
✁ ✝✟✞✠

An Introduction to Type Theory – p.12/46

slide-46
SLIDE 46

Peano’s axioms

✂ ✞
✟ ✂✁ ✄ ☞ ✄
✁ ✝
✁ ✝✟✞✠

where empty pattern

An Introduction to Type Theory – p.12/46

slide-47
SLIDE 47

Peano’s axioms

✂ ✞
✟ ✂✁ ✄ ☞ ✄
✁ ✝
✁ ✝✟✞✠

where empty pattern

✂ ✞
✟ ✂✁ ✄ ☞ ✄ ✞ ✁
✁ ✝✟✞✠

An Introduction to Type Theory – p.12/46

slide-48
SLIDE 48

Peano’s axioms

✂ ✞
✟ ✂✁ ✄ ☞ ✄
✁ ✝
✁ ✝✟✞✠

where empty pattern

✂ ✞
✟ ✂✁ ✄ ☞ ✄ ✞ ✁
✁ ✝✟✞✠

where empty pattern

An Introduction to Type Theory – p.12/46

slide-49
SLIDE 49

Peano’s axioms

An Introduction to Type Theory – p.13/46

slide-50
SLIDE 50

Peano’s axioms

✞ ✄ ✞ ✟
✁ ✟
✄ ☞ ✄

An Introduction to Type Theory – p.13/46

slide-51
SLIDE 51

Peano’s axioms

✞ ✄ ✞ ✟
✁ ✟
✄ ☞ ✄

where

✞ ✄ ✞
✁ ✄ ✞

An Introduction to Type Theory – p.13/46

slide-52
SLIDE 52

Peano’s axioms

✞ ✄ ✞ ✟
✁ ✟
✄ ☞ ✄

where

✞ ✄ ✞
✁ ✄ ✞
✁ ✞ ✟
✁ ✟ ✂✁ ✄ ☞ ✄ ✞
✁ ✝

An Introduction to Type Theory – p.13/46

slide-53
SLIDE 53

Peano’s axioms

✞ ✄ ✞ ✟
✁ ✟
✄ ☞ ✄

where

✞ ✄ ✞
✁ ✄ ✞
✁ ✞ ✟
✁ ✟ ✂✁ ✄ ☞ ✄ ✞
✁ ✝

where

✁ ✞
✁ ✄ ✞
  • An Introduction to Type Theory – p.13/46
slide-54
SLIDE 54

Proving decidability

An Introduction to Type Theory – p.14/46

slide-55
SLIDE 55

Proving decidability

✁ ✟
✄ ☞ ✄ ✄
✝ ☎ ✄
✝ ✝
✄ ✞
✁ ✝ ☎ ✄ ✞
✁ ✝ ✝

An Introduction to Type Theory – p.14/46

slide-56
SLIDE 56

Proving decidability

✁ ✟
✄ ☞ ✄ ✄
✝ ☎ ✄
✝ ✝
✄ ✞
✁ ✝ ☎ ✄ ✞
✁ ✝ ✝

where

✝ ✄
✞ ✄ ✞
✁ ✂ ☞ ✡ ✄
✁ ✞
✡ ✝ ✝

An Introduction to Type Theory – p.14/46

slide-57
SLIDE 57

Proving decidability

An Introduction to Type Theory – p.15/46

slide-58
SLIDE 58

Proving decidability

✁ ✟
✄ ☞ ✄
✝ ☎ ✄

An Introduction to Type Theory – p.15/46

slide-59
SLIDE 59

Proving decidability

✁ ✟
✄ ☞ ✄
✝ ☎ ✄

where

✝ ✄
✞ ✁ ✝
✂ ✞
✝ ✠
✂ ✞
✄ ✞ ✁ ✝
✄ ✠

An Introduction to Type Theory – p.15/46

slide-60
SLIDE 60

Proof or program ?

An Introduction to Type Theory – p.16/46

slide-61
SLIDE 61

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal.

An Introduction to Type Theory – p.16/46

slide-62
SLIDE 62

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form.

An Introduction to Type Theory – p.16/46

slide-63
SLIDE 63

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form. If it is

  • then the numbers are equal and

proves this.

An Introduction to Type Theory – p.16/46

slide-64
SLIDE 64

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form. If it is

  • then the numbers are equal and

proves this. If it is

then the numbers are not equal and

✡ ✟

proves this.

An Introduction to Type Theory – p.16/46

slide-65
SLIDE 65

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form. If it is

  • then the numbers are equal and

proves this. If it is

then the numbers are not equal and

✡ ✟

proves this.

  • is a program whose specification is in its type.

An Introduction to Type Theory – p.16/46

slide-66
SLIDE 66

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form. If it is

  • then the numbers are equal and

proves this. If it is

then the numbers are not equal and

✡ ✟

proves this.

  • is a program whose specification is in its type.

Equality proofs contain no information, hence they do not have to be calculated at run time.

An Introduction to Type Theory – p.16/46

slide-67
SLIDE 67

Proof or program ?

We can use

  • to effectively decide whether two

numbers

✁ ✟ ✂✁ ✄

are equal. Reduce

to its canonical form. If it is

  • then the numbers are equal and

proves this. If it is

then the numbers are not equal and

✡ ✟

proves this.

  • is a program whose specification is in its type.

Equality proofs contain no information, hence they do not have to be calculated at run time. Hence

  • is not less efficient than an ordinary program

to determine equality of natural numbers.

An Introduction to Type Theory – p.16/46

slide-68
SLIDE 68

Proof or program ?

The same principle can be applied to other problems, e.g. once we have specified

✠ ✟
  • ✂✁
✄ ✠

An Introduction to Type Theory – p.17/46

slide-69
SLIDE 69

Proof or program ?

The same principle can be applied to other problems, e.g. once we have specified

✠ ✟
  • ✂✁
✄ ✠

we can implement a primality checker as

✠ ✟
✄ ☞ ✄
✠ ✁ ✝ ☎ ☎ ✄
✠ ✁ ✝

An Introduction to Type Theory – p.17/46

slide-70
SLIDE 70

Pattern matching for

  • An Introduction to Type Theory – p.18/46
slide-71
SLIDE 71

Pattern matching for

  • If a pattern variable

has type

we can split the pattern into two, replacing

by

  • in the first line and by
  • in the second, where
✂✁ ✄

is a fresh variable.

An Introduction to Type Theory – p.18/46

slide-72
SLIDE 72

Pattern matching for

  • If a pattern variable

has type

we can split the pattern into two, replacing

by

  • in the first line and by
  • in the second, where
✂✁ ✄

is a fresh variable. Since

may appear in the type we have to substitute

by

  • and
  • respectively.

An Introduction to Type Theory – p.18/46

slide-73
SLIDE 73

Pattern matching for

  • If a pattern variable

has type

we can split the pattern into two, replacing

by

  • in the first line and by
  • in the second, where
✂✁ ✄

is a fresh variable. Since

may appear in the type we have to substitute

by

  • and
  • respectively.

We may use the function

we are defining recursively

  • n a subpattern, (e.g.
  • above).

An Introduction to Type Theory – p.18/46

slide-74
SLIDE 74

Pattern matching for

  • If a pattern variable

has type

we can split the pattern into two, replacing

by

  • in the first line and by
  • in the second, where
✂✁ ✄

is a fresh variable. Since

may appear in the type we have to substitute

by

  • and
  • respectively.

We may use the function

we are defining recursively

  • n a subpattern, (e.g.
  • above).

The precise rules governing structural recursion in the presence of other variables and mutual recursive definitions are more involved.

An Introduction to Type Theory – p.18/46

slide-75
SLIDE 75

Pattern matching for

  • An Introduction to Type Theory – p.19/46
slide-76
SLIDE 76

Pattern matching for

has the same canonical constant

✄ ☎ ✁ ✆ ✝

as

hence the same rules for pattern matching apply.

An Introduction to Type Theory – p.19/46

slide-77
SLIDE 77

Pattern matching for

has the same canonical constant

✄ ☎ ✁ ✆ ✝

as

hence the same rules for pattern matching apply. Similarily

has canonical constants

✝ ✁
  • as

and hence the same rules for pattern matching apply.

An Introduction to Type Theory – p.19/46

slide-78
SLIDE 78

Pattern matching for

has the same canonical constant

✄ ☎ ✁ ✆ ✝

as

hence the same rules for pattern matching apply. Similarily

has canonical constants

✝ ✁
  • as

and hence the same rules for pattern matching apply. As a consequence of

  • ✂✁
✄ ✠

variables ranging

  • ver

and

types may occur in the type and have to be substituted.

An Introduction to Type Theory – p.19/46

slide-79
SLIDE 79

Elimination constants

An Introduction to Type Theory – p.20/46

slide-80
SLIDE 80

Elimination constants

As a special instance of the pattern matching rules we will derive elimination constants.

An Introduction to Type Theory – p.20/46

slide-81
SLIDE 81

Elimination constants

As a special instance of the pattern matching rules we will derive elimination constants. The principle Equivalence of pattern matching and elimination still holds.

An Introduction to Type Theory – p.20/46

slide-82
SLIDE 82

Elimination constants

As a special instance of the pattern matching rules we will derive elimination constants. The principle Equivalence of pattern matching and elimination still holds. That is every pattern matching proof can be replaced by

  • ne only using elimination constants.

An Introduction to Type Theory – p.20/46

slide-83
SLIDE 83

Elimination for

  • An Introduction to Type Theory – p.21/46
slide-84
SLIDE 84

Elimination for

  • ✂✁
✄ ✠ ✁ ✟
✟ ✂✁ ✄ ☞
✞ ✁ ✝
✂✁ ✄ ✂ ✁ ✄ ✄ ✝
  • An Introduction to Type Theory – p.21/46
slide-85
SLIDE 85

Elimination for

  • ✂✁
✄ ✠ ✁ ✟
✟ ✂✁ ✄ ☞
✞ ✁ ✝
✂✁ ✄ ✂ ✁ ✄ ✄ ✝
  • where
✂ ✁ ✄ ✄ ✝
✁ ✂
✂ ✁ ✄ ✄ ✝
✁ ✂ ✄ ✞ ✁ ✝
✁ ✄ ✂ ✁ ✄ ✄ ✝
✁ ✂ ✁ ✝

An Introduction to Type Theory – p.21/46

slide-86
SLIDE 86

One stone, two birds

An Introduction to Type Theory – p.22/46

slide-87
SLIDE 87

One stone, two birds

Note that

✂ ✁ ✄ ✄ ✝

unifies two different principles:

An Introduction to Type Theory – p.22/46

slide-88
SLIDE 88

One stone, two birds

Note that

✂ ✁ ✄ ✄ ✝

unifies two different principles:

primitive recursion We obtain simply typed primitive

recursion if the motive

  • is constant.

An Introduction to Type Theory – p.22/46

slide-89
SLIDE 89

One stone, two birds

Note that

✂ ✁ ✄ ✄ ✝

unifies two different principles:

primitive recursion We obtain simply typed primitive

recursion if the motive

  • is constant.

induction When reading

✂✁ ✄ ✠

as

we obtain the principle of induction.

An Introduction to Type Theory – p.22/46

slide-90
SLIDE 90

Elimination for

An Introduction to Type Theory – p.23/46

slide-91
SLIDE 91

Elimination for

✁ ✟ ✂✁ ✄ ✠
✁ ✝
  • ✂✁
✄ ✠
✝ ☎ ✝ ✁ ✟
✟ ✁ ☞
✁ ✄ ✝ ✂ ✞ ✄ ✝
  • An Introduction to Type Theory – p.23/46
slide-92
SLIDE 92

Elimination for

✁ ✟ ✂✁ ✄ ✠
✁ ✝
  • ✂✁
✄ ✠
✝ ☎ ✝ ✁ ✟
✟ ✁ ☞
✁ ✄ ✝ ✂ ✞ ✄ ✝
  • where
✄ ✝ ✂ ✞ ✄ ✝
✝ ☎ ✝
✄ ✝ ✂ ✞ ✄ ✝

An Introduction to Type Theory – p.23/46

slide-93
SLIDE 93

A little quiz

An Introduction to Type Theory – p.24/46

slide-94
SLIDE 94

A little quiz

What is the construct corresponding to

✄ ✝ ✂ ✞ ✄ ✝

in programming?

An Introduction to Type Theory – p.24/46

slide-95
SLIDE 95

A little quiz

What is the construct corresponding to

✄ ✝ ✂ ✞ ✄ ✝

in programming? The type corresponding to

is called Unit, written

  • .

We didn’t need an elimination constant for

, do we need one for

  • ?

An Introduction to Type Theory – p.24/46

slide-96
SLIDE 96

Elimination for

An Introduction to Type Theory – p.25/46

slide-97
SLIDE 97

Elimination for

✂✁ ✄ ✠ ✁ ✟
  • ✂✁
✄ ✠
✄ ✄ ☎ ✟
✁ ☎ ✝
  • ✂✁
✄ ✠ ✡ ✟
✟ ✁ ☎ ☞
☎ ✁ ✆ ✝
✄ ☎ ✟
✁ ☎ ✞
✁ ✄ ✝
  • An Introduction to Type Theory – p.25/46
slide-98
SLIDE 98

Elimination for

✂✁ ✄ ✠ ✁ ✟
  • ✂✁
✄ ✠
✄ ✄ ☎ ✟
✁ ☎ ✝
  • ✂✁
✄ ✠ ✡ ✟
✟ ✁ ☎ ☞
☎ ✁ ✆ ✝
✄ ☎ ✟
✁ ☎ ✞
✁ ✄ ✝
  • where
✁ ✄ ✝
✡ ✄ ☎ ✁ ✆ ✝
☎ ✆

An Introduction to Type Theory – p.25/46

slide-99
SLIDE 99

Alternative: projections

An Introduction to Type Theory – p.26/46

slide-100
SLIDE 100

Alternative: projections

There is an alternative form of elimination for

using projections.

An Introduction to Type Theory – p.26/46

slide-101
SLIDE 101

Alternative: projections

There is an alternative form of elimination for

using projections.

✂✁ ✄ ✠ ✁ ✟
  • ✂✁
✄ ✠
✄ ☎ ✟
✁ ☎
✂ ✁
✁ ✄

An Introduction to Type Theory – p.26/46

slide-102
SLIDE 102

Alternative: projections

There is an alternative form of elimination for

using projections.

✂✁ ✄ ✠ ✁ ✟
  • ✂✁
✄ ✠
✄ ☎ ✟
✁ ☎
✂ ✁
✁ ✄

where

✄ ✄ ☎ ✁ ✆ ✝
✞ ✂ ✁ ✄ ☎ ✁ ✆ ✝

An Introduction to Type Theory – p.26/46

slide-103
SLIDE 103

Comparing

✂ ✁

vs.

  • ,

An Introduction to Type Theory – p.27/46

slide-104
SLIDE 104

Comparing

✂ ✁

vs.

  • ,

Which form of elimination is better?

An Introduction to Type Theory – p.27/46

slide-105
SLIDE 105

Comparing

✂ ✁

vs.

  • ,

Which form of elimination is better? Can we use

✁ ✄ ✝

to implement

and

✞ ✂ ✁

?

An Introduction to Type Theory – p.27/46

slide-106
SLIDE 106

The axiom of choice

An Introduction to Type Theory – p.28/46

slide-107
SLIDE 107

The axiom of choice

We can use

and

✞ ✂ ✁

to implement the axiom of choice.

An Introduction to Type Theory – p.28/46

slide-108
SLIDE 108

The axiom of choice

We can use

and

✞ ✂ ✁

to implement the axiom of choice.

✁ ✟ ✂✁ ✄ ✠
  • ✂✁
✄ ✠ ✡ ✟
✄ ✆ ✟ ✁ ☞
✡ ✟ ✄ ✁ ✟
✄ ✁ ☎ ✝

An Introduction to Type Theory – p.28/46

slide-109
SLIDE 109

The axiom of choice

We can use

and

✞ ✂ ✁

to implement the axiom of choice.

✁ ✟ ✂✁ ✄ ✠
  • ✂✁
✄ ✠ ✡ ✟
✄ ✆ ✟ ✁ ☞
✡ ✟ ✄ ✁ ✟
✄ ✁ ☎ ✝

where

✁ ☎ ✟
✄ ✄ ✡ ☎ ✝ ✁ ✁ ☎ ✟
✞ ✂ ✁ ✄ ✡ ☎ ✝ ✝

An Introduction to Type Theory – p.28/46

slide-110
SLIDE 110

The axiom of choice

An Introduction to Type Theory – p.29/46

slide-111
SLIDE 111

The axiom of choice

This shows that the axiom of choice is justified constructively.

An Introduction to Type Theory – p.29/46

slide-112
SLIDE 112

The axiom of choice

This shows that the axiom of choice is justified constructively. However, in the presence of the principle of excluded middle it is a sign of non-constructive reasoning.

An Introduction to Type Theory – p.29/46

slide-113
SLIDE 113

Pattern matching for

  • An Introduction to Type Theory – p.30/46
slide-114
SLIDE 114

Pattern matching for

  • The rules for pattern matching for equality proofs

involve unification problems.

An Introduction to Type Theory – p.30/46

slide-115
SLIDE 115

Pattern matching for

  • The rules for pattern matching for equality proofs

involve unification problems. Given a pattern variable

✂ ✟ ☎

, there are the following cases:

An Introduction to Type Theory – p.30/46

slide-116
SLIDE 116

Pattern matching for

  • The rules for pattern matching for equality proofs

involve unification problems. Given a pattern variable

✂ ✟ ☎

, there are the following cases: The unification problem

is unsolvable, in this cas we can eliminate the pattern.

An Introduction to Type Theory – p.30/46

slide-117
SLIDE 117

Pattern matching for

  • The rules for pattern matching for equality proofs

involve unification problems. Given a pattern variable

✂ ✟ ☎

, there are the following cases: The unification problem

is unsolvable, in this cas we can eliminate the pattern. The unification problem

has a most general solution which is given by a substitution

  • . Then

can be replaced by

✁ ☎
  • and the substitution
  • has

to be applied to the type as well.

An Introduction to Type Theory – p.30/46

slide-118
SLIDE 118

Pattern matching for

  • The rules for pattern matching for equality proofs

involve unification problems. Given a pattern variable

✂ ✟ ☎

, there are the following cases: The unification problem

is unsolvable, in this cas we can eliminate the pattern. The unification problem

has a most general solution which is given by a substitution

  • . Then

can be replaced by

✁ ☎
  • and the substitution
  • has

to be applied to the type as well. The unification problem

is irreducible, in this case we cannot reduce the pattern.

An Introduction to Type Theory – p.30/46

slide-119
SLIDE 119

Reducing unification problems

An Introduction to Type Theory – p.31/46

slide-120
SLIDE 120

Reducing unification problems

We only consider the special case of terms over

here.

An Introduction to Type Theory – p.31/46

slide-121
SLIDE 121

Reducing unification problems

We only consider the special case of terms over

here. Problems of the form

  • can be solved trivially.

An Introduction to Type Theory – p.31/46

slide-122
SLIDE 122

Reducing unification problems

We only consider the special case of terms over

here. Problems of the form

  • can be solved trivially.

Problems of the

  • r
✄ ✞ ✄ ☞ ☞ ☞ ✄ ✞ ✁ ✝ ☞ ☞ ☞ ✝ ✝

are unsolvable.

An Introduction to Type Theory – p.31/46

slide-123
SLIDE 123

Reducing unification problems

We only consider the special case of terms over

here. Problems of the form

  • can be solved trivially.

Problems of the

  • r
✄ ✞ ✄ ☞ ☞ ☞ ✄ ✞ ✁ ✝ ☞ ☞ ☞ ✝ ✝

are unsolvable. Problems of the form

  • , where
  • does not occur in
  • can be solved and give rise to the substitution
  • .

An Introduction to Type Theory – p.31/46

slide-124
SLIDE 124

Reducing unification problems

We only consider the special case of terms over

here. Problems of the form

  • can be solved trivially.

Problems of the

  • r
✄ ✞ ✄ ☞ ☞ ☞ ✄ ✞ ✁ ✝ ☞ ☞ ☞ ✝ ✝

are unsolvable. Problems of the form

  • , where
  • does not occur in
  • can be solved and give rise to the substitution
  • .

The problem

can be reduced to

.

An Introduction to Type Theory – p.31/46

slide-125
SLIDE 125

Reducing unification problems

We only consider the special case of terms over

here. Problems of the form

  • can be solved trivially.

Problems of the

  • r
✄ ✞ ✄ ☞ ☞ ☞ ✄ ✞ ✁ ✝ ☞ ☞ ☞ ✝ ✝

are unsolvable. Problems of the form

  • , where
  • does not occur in
  • can be solved and give rise to the substitution
  • .

The problem

can be reduced to

. All other problems are irreducible.

An Introduction to Type Theory – p.31/46

slide-126
SLIDE 126

Question

An Introduction to Type Theory – p.32/46

slide-127
SLIDE 127

Question

Can we generalize our proof

✁ ✞

to

✁ ✟ ✂✁ ✄ ✠ ✡ ✟
✁ ✟
✁ ✆ ✟
✄ ✡ ☎
✆ ✝

An Introduction to Type Theory – p.32/46

slide-128
SLIDE 128

Question

Can we generalize our proof

✁ ✞

to

✁ ✟ ✂✁ ✄ ✠ ✡ ✟
✁ ✟
✁ ✆ ✟
✄ ✡ ☎
✆ ✝

where

✁ ☎ ☎ ✄
✁ ✄ ✡ ☎ ✝ ✝
✁ ☎
  • An Introduction to Type Theory – p.32/46
slide-129
SLIDE 129

Elimination for

  • An Introduction to Type Theory – p.33/46
slide-130
SLIDE 130

Elimination for

✂✁ ✄ ✠
✁ ✆ ✟
✄ ☎
  • ✂✁
✄ ✠ ✡ ✟
☎ ✄
✁ ☎ ✝ ☎ ✁ ✆ ✟
✡ ☎ ✆
  • An Introduction to Type Theory – p.33/46
slide-131
SLIDE 131

Elimination for

✂✁ ✄ ✠
✁ ✆ ✟
✄ ☎
  • ✂✁
✄ ✠ ✡ ✟
☎ ✄
✁ ☎ ✝ ☎ ✁ ✆ ✟
✡ ☎ ✆
  • where
✡ ☎ ☎ ✄
✁ ☎ ✝

An Introduction to Type Theory – p.33/46

slide-132
SLIDE 132

Pattern matching vs. elimination ?

Does the Equivalence of pattern matching and elimination still hold?

An Introduction to Type Theory – p.34/46

slide-133
SLIDE 133

Uniqueness of equality proofs.

An Introduction to Type Theory – p.35/46

slide-134
SLIDE 134

Uniqueness of equality proofs.

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✂ ✟ ☎
✂ ✂ ✠

An Introduction to Type Theory – p.35/46

slide-135
SLIDE 135

Uniqueness of equality proofs.

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✂ ✟ ☎
✂ ✂ ✠

where

✂ ✂ ✠
☎ ✄
✁ ☎ ✝ ✄
✁ ☎ ✝
✁ ✄
✁ ☎ ✝

An Introduction to Type Theory – p.35/46

slide-136
SLIDE 136

Uniqueness of equality proofs.

In the early 90ies it was an open problem wether

✂ ✂ ✠
  • could be derived from

.

An Introduction to Type Theory – p.36/46

slide-137
SLIDE 137

Uniqueness of equality proofs.

In the early 90ies it was an open problem wether

✂ ✂ ✠
  • could be derived from

. In 1993 Hofmann and Streicher showed that

✂ ✂ ✠
  • does

not hold in the groupoid model of Type Theory, although

can be interpreted.

An Introduction to Type Theory – p.36/46

slide-138
SLIDE 138

Uniqueness of equality proofs.

In the early 90ies it was an open problem wether

✂ ✂ ✠
  • could be derived from

. In 1993 Hofmann and Streicher showed that

✂ ✂ ✠
  • does

not hold in the groupoid model of Type Theory, although

can be interpreted. However, this can be fixed by introducing another elimination constant.

An Introduction to Type Theory – p.36/46

slide-139
SLIDE 139

Another elimination for

  • An Introduction to Type Theory – p.37/46
slide-140
SLIDE 140

Another elimination for

✂✁ ✄ ✠
✄ ☎
  • ✂✁
✄ ✠ ✡ ✟
✁ ☎ ✝ ☎ ✟
  • An Introduction to Type Theory – p.37/46
slide-141
SLIDE 141

Another elimination for

✂✁ ✄ ✠
✄ ☎
  • ✂✁
✄ ✠ ✡ ✟
✁ ☎ ✝ ☎ ✟
  • where
☎ ✄
✁ ☎ ✝

An Introduction to Type Theory – p.37/46

slide-142
SLIDE 142

Uniqueness of equality proofs.

An Introduction to Type Theory – p.38/46

slide-143
SLIDE 143

Uniqueness of equality proofs.

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✂ ✟ ☎
✂ ✂ ✠

An Introduction to Type Theory – p.38/46

slide-144
SLIDE 144

Uniqueness of equality proofs.

✂✁ ✄ ✠ ☎ ✁ ✆ ✟
✂ ✟ ☎
✂ ✂ ✠

where

✂ ✂ ✠
☎ ✆ ✄ ✁ ✂ ☞ ✠
✄ ✁ ☎ ☞
✁ ✄
✁ ☎ ✝ ✝ ✂ ✝
  • An Introduction to Type Theory – p.38/46
slide-145
SLIDE 145

Conor’s result

An Introduction to Type Theory – p.39/46

slide-146
SLIDE 146

Conor’s result

In 1999 Conor McBride showed as part of his PhD that Equiva- lence of pattern matching and elimination holds, when using

  • .

An Introduction to Type Theory – p.39/46

slide-147
SLIDE 147

Conor’s result

In 1999 Conor McBride showed as part of his PhD that Equiva- lence of pattern matching and elimination holds, when using

  • .

In fact he showed this in the presence of inductive families, of which

  • is a special case.

An Introduction to Type Theory – p.39/46

slide-148
SLIDE 148

in logic

An Introduction to Type Theory – p.40/46

slide-149
SLIDE 149

in logic

How to define

  • ✂✁

?

An Introduction to Type Theory – p.40/46

slide-150
SLIDE 150

in logic

How to define

  • ✂✁

?

✄ ☞

An Introduction to Type Theory – p.40/46

slide-151
SLIDE 151

in logic

How to define

  • ✂✁

?

✄ ☞

There is an alternative inductive definition.

✁ ✟ ✂✁ ✄

An Introduction to Type Theory – p.40/46

slide-152
SLIDE 152

in Type Theory

An Introduction to Type Theory – p.41/46

slide-153
SLIDE 153

in Type Theory

How to form ?

An Introduction to Type Theory – p.41/46

slide-154
SLIDE 154

in Type Theory

How to form ?

✁ ✟ ✂✁ ✄
✟ ✂✁ ✄ ✠

An Introduction to Type Theory – p.41/46

slide-155
SLIDE 155

in Type Theory

How to form ?

✁ ✟ ✂✁ ✄
✟ ✂✁ ✄ ✠

How to construct?

An Introduction to Type Theory – p.41/46

slide-156
SLIDE 156

in Type Theory

How to form ?

✁ ✟ ✂✁ ✄
✟ ✂✁ ✄ ✠

How to construct?

✁ ✟
✄ ✝ ✠
✝ ✠
✄ ✞
✞ ✁ ✝

An Introduction to Type Theory – p.41/46

slide-157
SLIDE 157

Pattern matching for

An Introduction to Type Theory – p.42/46

slide-158
SLIDE 158

Pattern matching for

✂ ✞
✁ ✁ ✂ ✟
✄ ☞ ✄

An Introduction to Type Theory – p.42/46

slide-159
SLIDE 159

Pattern matching for

✂ ✞
✁ ✁ ✂ ✟
✄ ☞ ✄

where

✂ ✞
✂ ✄ ✝ ✠
✝ ✂
✂ ✞
✄ ✞
✄ ✞ ✁ ✝ ✄ ✞ ✂ ✝ ✄ ✝ ✠
✄ ✝ ✠
✂ ✞

An Introduction to Type Theory – p.42/46

slide-160
SLIDE 160

Leq in LEGO

Inductive [Leq : Nat

  • Nat
  • Set]

Constructors [le0 :

n:Nat

Leq ze n] [leS :

m,n|Nat

(Leq m n)

  • (Leq (su m) (su n))];

An Introduction to Type Theory – p.43/46

slide-161
SLIDE 161

Elimination for Leq

decl Leq_elim :

  • C_Leq:
  • x1,x2|Nat

(Leq x1 x2)

TYPE

(

  • n:Nat

C_Leq (le0 n))

(

  • m,n|Nat
  • x1:Leq m n

(C_Leq x1)

C_Leq (leS x1))

  • x1,x2|Nat
  • z:Leq x1 x2

C_Leq z [[C_Leq:

  • x1,x2|Nat

(Leq x1 x2)

TYPE][f_le0:

  • n1:Nat

C_Leq (le0 n1)] [f_leS:

  • m,n|Nat
  • x1:Leq m n

(C_Leq x1)

C_Leq (leS x1)][n1:Nat][m,n|Nat] [x1:Leq m n] Leq_elim C_Leq f_le0 f_leS (le0 n1)

f_le0 n1 || Leq_elim C_Leq f_le0 f_leS (leS x1)

f_leS x1 (Leq_elim C_Leq f_le0 f_leS x1)]

An Introduction to Type Theory – p.44/46

slide-162
SLIDE 162

Inductive definitions

An Introduction to Type Theory – p.45/46

slide-163
SLIDE 163

Inductive definitions

Inductive definitions are a basic concept of Type Theory

An Introduction to Type Theory – p.45/46

slide-164
SLIDE 164

Inductive definitions

Inductive definitions are a basic concept of Type Theory Inductive types can be imagined as defining a collection

  • f trees.

An Introduction to Type Theory – p.45/46

slide-165
SLIDE 165

Inductive definitions

Inductive definitions are a basic concept of Type Theory Inductive types can be imagined as defining a collection

  • f trees.

We can have infinitary constructors, but they have to be strictly positive.

An Introduction to Type Theory – p.45/46

slide-166
SLIDE 166

Inductive definitions

Inductive definitions are a basic concept of Type Theory Inductive types can be imagined as defining a collection

  • f trees.

We can have infinitary constructors, but they have to be strictly positive. There are also size restrictions: there is no type of all types.

An Introduction to Type Theory – p.45/46

slide-167
SLIDE 167

Loose ends

An Introduction to Type Theory – p.46/46

slide-168
SLIDE 168

Loose ends

The role of equality in Type Theory extensional vs intensional

An Introduction to Type Theory – p.46/46

slide-169
SLIDE 169

Loose ends

The role of equality in Type Theory extensional vs intensional Universes and reflection predicative impredicative inconsistent

An Introduction to Type Theory – p.46/46