Computational Higher Inductive Types Computing with Custom - - PowerPoint PPT Presentation

computational higher inductive types
SMART_READER_LITE
LIVE PREVIEW

Computational Higher Inductive Types Computing with Custom - - PowerPoint PPT Presentation

Computational Higher Inductive Types Computing with Custom Equalities Jason Gross jgross@mit.edu MIT CSAIL Student Workshop January 22, 2014 Properties of Equality Warm Up: Linked Lists Example: Unordered Sets Canonical Inhabitants Higher


slide-1
SLIDE 1

Computational Higher Inductive Types

Computing with Custom Equalities Jason Gross jgross@mit.edu

MIT CSAIL Student Workshop

January 22, 2014

slide-2
SLIDE 2

Properties of Equality Warm Up: Linked Lists Example: Unordered Sets Canonical Inhabitants Higher Inductive Types Computing with Higher Inductive Types Thank you

slide-3
SLIDE 3

Properties of Equality

slide-4
SLIDE 4

Properties of Equality

◮ Reflexivity: x = x

slide-5
SLIDE 5

Properties of Equality

◮ Reflexivity: x = x ◮ Symmetry: if x = y then y = x

slide-6
SLIDE 6

Properties of Equality

◮ Reflexivity: x = x ◮ Symmetry: if x = y then y = x ◮ Transitivity: if x = y and y = z, then x = z

slide-7
SLIDE 7

Properties of Equality

◮ Reflexivity: x = x ◮ Symmetry: if x = y then y = x ◮ Transitivity: if x = y and y = z, then x = z ◮ Leibniz rule: if x = y, then f (x) = f (y)

slide-8
SLIDE 8

Warm Up: Linked Lists

◮ Two constructors:

slide-9
SLIDE 9

Warm Up: Linked Lists

◮ Two constructors: nil, or [], and cons

slide-10
SLIDE 10

Warm Up: Linked Lists

◮ Two constructors: nil, or [], and cons ◮ Two accessors on non-nil lists:

slide-11
SLIDE 11

Warm Up: Linked Lists

◮ Two constructors: nil, or [], and cons ◮ Two accessors on non-nil lists: head and tail

slide-12
SLIDE 12

Warm Up: Linked Lists

◮ Two constructors: nil, or [], and cons ◮ Two accessors on non-nil lists: head and tail ◮ Equality is defined on an element-by-element basis

◮ [] = [] ◮ [] = [a, . . .] ◮ [a, . . .] = [] ◮ [x0, x1, . . . , xn] = [y0, y1, . . . , ym] iff [x1, . . . , xn] = [y1, . . . , ym]

and x0 = y0

slide-13
SLIDE 13

Warm Up: Linked Lists

◮ Two constructors: nil, or [], and cons ◮ Two accessors on non-nil lists: head and tail ◮ Equality is defined on an element-by-element basis

◮ [] = [] ◮ [] = [a, . . .] ◮ [a, . . .] = [] ◮ [x0, x1, . . . , xn] = [y0, y1, . . . , ym] iff [x1, . . . , xn] = [y1, . . . , ym]

and x0 = y0

◮ Fairly easy to prove the properties of equality

◮ In Coq, Agda, and Idris, you get all of these properties for free

slide-14
SLIDE 14

Example: Unordered Sets

slide-15
SLIDE 15

Example: Unordered Sets

◮ nil, or ∅

slide-16
SLIDE 16

Example: Unordered Sets

◮ nil, or ∅ ◮ add

slide-17
SLIDE 17

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove

slide-18
SLIDE 18

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains

slide-19
SLIDE 19

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree

slide-20
SLIDE 20

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree ◮ Equality is then implemented as “is one a permutation of the

  • ther?”
slide-21
SLIDE 21

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree ◮ Equality is then implemented as “is one a permutation of the

  • ther?”

◮ Fairly easy to prove that it’s an equivalence relation

slide-22
SLIDE 22

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree ◮ Equality is then implemented as “is one a permutation of the

  • ther?”

◮ Fairly easy to prove that it’s an equivalence relation ◮ Leibniz rule (if x = y, then f (x) = f (y)) is harder ◮ In Haskell, Agda, Coq, and Idris, the Leibniz rule is false!

slide-23
SLIDE 23

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree ◮ Equality is then implemented as “is one a permutation of the

  • ther?”

◮ Fairly easy to prove that it’s an equivalence relation ◮ Leibniz rule (if x = y, then f (x) = f (y)) is harder ◮ In Haskell, Agda, Coq, and Idris, the Leibniz rule is false! (or

at least not internally provable)

slide-24
SLIDE 24

Example: Unordered Sets

◮ nil, or ∅ ◮ add ◮ remove ◮ contains ◮ Often implemented internally as a list or a tree ◮ Equality is then implemented as “is one a permutation of the

  • ther?”

◮ Fairly easy to prove that it’s an equivalence relation ◮ Leibniz rule (if x = y, then f (x) = f (y)) is harder ◮ In Haskell, Agda, Coq, and Idris, the Leibniz rule is false! (or

at least not internally provable)

◮ The problem is that either you don’t have private fields, or you

can’t make use of the fact that everything is defined in terms

  • f your public methods.
slide-25
SLIDE 25

Example: Unordered Sets

Solution 1: Canonical Inhabitants

◮ Give up private fields, but use element-wise equality

slide-26
SLIDE 26

Example: Unordered Sets

Solution 1: Canonical Inhabitants

◮ Give up private fields, but use element-wise equality ◮ Define a type of “sorted lists without duplication”, and call

them sets

slide-27
SLIDE 27

Example: Unordered Sets

Solution 1: Canonical Inhabitants

◮ Give up private fields, but use element-wise equality ◮ Define a type of “sorted lists without duplication”, and call

them sets

◮ Now we can use element-wise equality, and get Leibniz (and

  • ther properties) for free
slide-28
SLIDE 28

Example: Unordered Sets

Solution 1: Canonical Inhabitants

◮ Give up private fields, but use element-wise equality ◮ Define a type of “sorted lists without duplication”, and call

them sets

◮ Now we can use element-wise equality, and get Leibniz (and

  • ther properties) for free

◮ What if we don’t have an ordering on the elements, only

equality?

slide-29
SLIDE 29

Example: Unordered Sets

Solution 1: Canonical Inhabitants

◮ Give up private fields, but use element-wise equality ◮ Define a type of “sorted lists without duplication”, and call

them sets

◮ Now we can use element-wise equality, and get Leibniz (and

  • ther properties) for free

◮ What if we don’t have an ordering on the elements, only

equality?

◮ Is this really what we wanted? We asked for unordered sets,

and instead made sorted lists.

slide-30
SLIDE 30

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types

slide-31
SLIDE 31

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types ◮ Keep the built-in equality (so we get the properties for free),

but turn it into equality up to permutation

slide-32
SLIDE 32

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types ◮ Keep the built-in equality (so we get the properties for free),

but turn it into equality up to permutation

◮ How do we get that it’s an equivalence relation for free?

slide-33
SLIDE 33

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types ◮ Keep the built-in equality (so we get the properties for free),

but turn it into equality up to permutation

◮ How do we get that it’s an equivalence relation for free?

◮ Take the reflexive symmetric transitive closure of the given

relation

slide-34
SLIDE 34

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types ◮ Keep the built-in equality (so we get the properties for free),

but turn it into equality up to permutation

◮ How do we get that it’s an equivalence relation for free?

◮ Take the reflexive symmetric transitive closure of the given

relation

◮ How do we get Leibniz for free?

slide-35
SLIDE 35

Example: Unordered Sets

Solution 2: Higher Inductive Types

◮ Higher Inductive Types ◮ Keep the built-in equality (so we get the properties for free),

but turn it into equality up to permutation

◮ How do we get that it’s an equivalence relation for free?

◮ Take the reflexive symmetric transitive closure of the given

relation

◮ How do we get Leibniz for free?

◮ Require proving it each time you define a particular function ◮ To define a function that deals with unordered sets, you have

to simultaneously prove that your function is invariant under permutations

slide-36
SLIDE 36

Computing with Higher Inductive Types

◮ It seems simple enough, so what’s the problem?

slide-37
SLIDE 37

Computing with Higher Inductive Types

◮ It seems simple enough, so what’s the problem? ◮ Having higher inductive types gives you functional

extensionality (if f (x) = g(x) for all x, then f = g), which doesn’t yet have a good computational interpretation in Coq nor Agda nor Idris

slide-38
SLIDE 38

Computing with Higher Inductive Types

◮ It seems simple enough, so what’s the problem? ◮ Having higher inductive types gives you functional

extensionality (if f (x) = g(x) for all x, then f = g), which doesn’t yet have a good computational interpretation in Coq nor Agda nor Idris

◮ Equality in Coq and Agda (--without-K) actually has a rich

structure

slide-39
SLIDE 39

Computing with Higher Inductive Types

◮ It seems simple enough, so what’s the problem? ◮ Having higher inductive types gives you functional

extensionality (if f (x) = g(x) for all x, then f = g), which doesn’t yet have a good computational interpretation in Coq nor Agda nor Idris

◮ Equality in Coq and Agda (--without-K) actually has a rich

structure

◮ If you look at proofs of equality, and equality of these proofs,

and you iterate this process, you get enough math to do topology!

slide-40
SLIDE 40

Computing with Higher Inductive Types

◮ It seems simple enough, so what’s the problem? ◮ Having higher inductive types gives you functional

extensionality (if f (x) = g(x) for all x, then f = g), which doesn’t yet have a good computational interpretation in Coq nor Agda nor Idris

◮ Equality in Coq and Agda (--without-K) actually has a rich

structure

◮ If you look at proofs of equality, and equality of these proofs,

and you iterate this process, you get enough math to do topology!

◮ This is Homotopy Type Theory

slide-41
SLIDE 41

Thank you

Thanks!

slide-42
SLIDE 42

Thank you

Thanks! Questions?

slide-43
SLIDE 43

Example: Unordered Sets

Solution 3: Parametricity

◮ Make use of the fact that private fields are private

slide-44
SLIDE 44

Example: Unordered Sets

Solution 3: Parametricity

◮ Make use of the fact that private fields are private ◮ Very hard to do!

slide-45
SLIDE 45

Example: Unordered Sets

Solution 3: Parametricity

◮ Make use of the fact that private fields are private ◮ Very hard to do! ◮ Can probably be done by way of parametricity (aka “theorems

for free”), or a generalization of it

slide-46
SLIDE 46

Example: Unordered Sets

Solution 3: Parametricity

◮ Make use of the fact that private fields are private ◮ Very hard to do! ◮ Can probably be done by way of parametricity (aka “theorems

for free”), or a generalization of it

◮ Parametricity can be given a computational interpretation,

but it’s very non-trivial to do so