Lifting proof-relevant unification to higher dimensions Jesper - - PowerPoint PPT Presentation

lifting proof relevant unification to higher dimensions
SMART_READER_LITE
LIVE PREVIEW

Lifting proof-relevant unification to higher dimensions Jesper - - PowerPoint PPT Presentation

Lifting proof-relevant unification to higher dimensions Jesper Cockx Dominique Devriese 17 January 2017 The rewrite tactic: day one k : N n : N p : P k e : k N n ? : P n 1 / 22 The rewrite tactic: day one k : N k : N n : N n : N rewrite e


slide-1
SLIDE 1

Lifting proof-relevant unification to higher dimensions

Jesper Cockx Dominique Devriese

17 January 2017

slide-2
SLIDE 2

The rewrite tactic: day one

k : N n : N p : P k e : k ≡N n ? : P n

1 / 22

slide-3
SLIDE 3

The rewrite tactic: day one

k : N n : N p : P k e : k ≡N n ? : P n

rewrite e

= = = = ⇒ k : N n : N p : P n e : k ≡N n ? : P n

1 / 22

slide-4
SLIDE 4

The unify tactic: day one

k : N n : N p : P k e : k ≡N n ? : P n

unify e

= = = ⇒ n : N p : P n ? : P n

2 / 22

slide-5
SLIDE 5

The rewrite tactic: day two

k : N n : N p : P k e : suc k ≡N suc n ? : P n

3 / 22

slide-6
SLIDE 6

The rewrite tactic: day two

k : N n : N p : P k e : suc k ≡N suc n ? : P n

rewrite e

= = = = ⇒ k : N n : N p : P k e : suc k ≡N suc n ? : P n

3 / 22

slide-7
SLIDE 7

The unify tactic: day two

k : N n : N p : P k e : suc k ≡N suc n ? : P n

unify e

= = = ⇒ n : N p : P n ? : P n

4 / 22

slide-8
SLIDE 8

The rewrite tactic: day three

k : N n : N xs : Vec A (suc k) p : P k xs e : suc k ≡N suc n ? : P n (subst (Vec A) e xs)

5 / 22

slide-9
SLIDE 9

The rewrite tactic: day three

k : N n : N xs : Vec A (suc k) p : P k xs e : suc k ≡N suc n ? : P n (subst (Vec A) e xs)

rewrite e

= = = = ⇒ error

5 / 22

slide-10
SLIDE 10

The unify tactic: day three

k : N n : N xs : Vec A (suc k) p : P k xs e : suc k ≡N suc n ? : P n (subst (Vec A) e xs)

unify e

= = = ⇒ n : N xs : Vec A (suc n) p : P n xs ? : P n xs

6 / 22

slide-11
SLIDE 11

Proof-relevant unification Unification of indexed data Lifting unifiers to higher dimensions

slide-12
SLIDE 12

Proof-relevant unification Unification of indexed data Lifting unifiers to higher dimensions

slide-13
SLIDE 13

Proof-relevant unification

  • Represent unification rules internally
  • Rules get a computational interpretation
  • Core of dependent pattern matching

See Unifiers as Equivalences (ICFP ’16)

7 / 22

slide-14
SLIDE 14

Proof-relevant unification: example

(k n : N)(e : suc k ≡N suc n)

8 / 22

slide-15
SLIDE 15

Proof-relevant unification: example

(k n : N)(e : suc k ≡N suc n) ≃ (k n : N)(e : k ≡N n)

8 / 22

slide-16
SLIDE 16

Proof-relevant unification: example

(k n : N)(e : suc k ≡N suc n) ≃ (k n : N)(e : k ≡N n) ≃ (k : N)

8 / 22

slide-17
SLIDE 17

Proof-relevant unification: example

(k n : N)(e : suc k ≡N suc n) ≃ (k n : N)(e : k ≡N n) ≃ (k : N)

8 / 22

slide-18
SLIDE 18

Unifiers as equivalences

Goal: given some equations ¯ u ≡∆ ¯ v with free variables in Γ, find an equivalence f of type Γ(¯ e : ¯ u ≡∆ ¯ v) ≃ Γ′

9 / 22

slide-19
SLIDE 19

Unification rules

(x : A)(e : x ≡A t) ≃ ⊤ (solution) (suc x ≡N suc y) ≃ (x ≡N y) (injectivity) (left x ≡A⊎B right y) ≃ ⊥ (conflict) (n ≡N suc n) ≃ ⊥ (cycle)

10 / 22

slide-20
SLIDE 20

Telescopic equality

The type of an equation can depend on previous equations: (u : Vec A k)(v : Vec A n) (e1 : k ≡N n)(e2 : u ≡Vec A e1 v) This allows us to keep track of dependencies between equations.

11 / 22

slide-21
SLIDE 21

Proof-relevant unification Unification of indexed data Lifting unifiers to higher dimensions

slide-22
SLIDE 22

Injectivity for indexed data

Idea: simplify equations between indices together with equation between constructors: (e1 : i ≡I j)(e2 : c u ≡D e1 c v) ≃ (e : u ≡A v)

12 / 22

slide-23
SLIDE 23

Injectivity for indexed data

Idea: simplify equations between indices together with equation between constructors: (e1 : i ≡I j)(e2 : c u ≡D e1 c v) ≃ (e : u ≡A v) Indices of D must be fully general: must be distinct equation variables.

12 / 22

slide-24
SLIDE 24

Injectivity for indexed data: example

cons : (n : N)(x : A)(xs : Vec A n) → Vec A (suc n)

13 / 22

slide-25
SLIDE 25

Injectivity for indexed data: example

cons : (n : N)(x : A)(xs : Vec A n) → Vec A (suc n) (e1 : suc k ≡N suc n) (e2 : cons k x xs ≡Vec A e1 cons n y ys)

13 / 22

slide-26
SLIDE 26

Injectivity for indexed data: example

cons : (n : N)(x : A)(xs : Vec A n) → Vec A (suc n) (e1 : suc k ≡N suc n) (e2 : cons k x xs ≡Vec A e1 cons n y ys) ≃ (e′

1 : k ≡N n)(e′ 2 : x ≡A y)

(e′

3 : xs ≡Vec A e1 ys)

13 / 22

slide-27
SLIDE 27

Injectivity for indexed data: example

cons : (n : N)(x : A)(xs : Vec A n) → Vec A (suc n) (e1 : suc k ≡N suc n) (e2 : cons k x xs ≡Vec A e1 cons n y ys) ≃ (e′

1 : k ≡N n)(e′ 2 : x ≡A y)

(e′

3 : xs ≡Vec A e1 ys)

13 / 22

slide-28
SLIDE 28

What if the indices are not fully general?

(e : cons n x xs ≡Vec A (suc n) cons n y ys) ≃ ???

14 / 22

slide-29
SLIDE 29

Solution: generalizing the indices

(e : cons n x xs ≡Vec A (suc n) cons n y ys)

15 / 22

slide-30
SLIDE 30

Solution: generalizing the indices

(e : cons n x xs ≡Vec A (suc n) cons n y ys) ≃ (e1 : suc n ≡N suc n) (e2 : cons n x xs ≡Vec A e1 cons n y ys) (p : e1 ≡suc n≡Nsuc n refl)

15 / 22

slide-31
SLIDE 31

Solution: generalizing the indices

(e : cons n x xs ≡Vec A (suc n) cons n y ys) ≃ (e1 : suc n ≡N suc n) (e2 : cons n x xs ≡Vec A e1 cons n y ys) (p : e1 ≡suc n≡Nsuc n refl) ≃ (e′

1 : n ≡N n)(e′ 2 : x ≡A y)(e′ 3 : xs ≡Vec A e′

1 ys)

(p : cong suc e′

1 ≡suc n≡Nsuc n refl)

15 / 22

slide-32
SLIDE 32

Solution: generalizing the indices

(e : cons n x xs ≡Vec A (suc n) cons n y ys) ≃ (e1 : suc n ≡N suc n) (e2 : cons n x xs ≡Vec A e1 cons n y ys) (p : e1 ≡suc n≡Nsuc n refl) ≃ (e′

1 : n ≡N n)(e′ 2 : x ≡A y)(e′ 3 : xs ≡Vec A e′

1 ys)

(p : cong suc e′

1 ≡suc n≡Nsuc n refl)

15 / 22

slide-33
SLIDE 33

Higher-dimensional unification

(e′

1 : n ≡N n)(e′ 2 : x ≡A y)(e′ 3 : xs ≡Vec A e′

1 ys)

(p : cong suc e′

1 ≡suc n≡Nsuc n refl)

Now we have to solve equations between equality proofs!

16 / 22

slide-34
SLIDE 34

Proof-relevant unification Unification of indexed data Lifting unifiers to higher dimensions

slide-35
SLIDE 35

How to solve higher-dimensional equations?

Existing unification rules do not apply. . .

17 / 22

slide-36
SLIDE 36

How to solve higher-dimensional equations?

Existing unification rules do not apply. . . We solve the problem in three steps:

  • 1. lower the dimension of equations
  • 2. solve lower-dimensional equations
  • 3. lift unifier to higher dimension

17 / 22

slide-37
SLIDE 37

Step 1: lower the dimension of equations

We replace all equation variables by regular variables: instead of (e1 : n ≡N n)(e2 : x ≡A y)(e3 : xs ≡Vec A e1 ys) (p : cong suc e1 ≡suc n≡Nsuc n refl) let’s first consider (k : N)(u : A)(us : Vec A k) (e : suc k ≡N suc n)

18 / 22

slide-38
SLIDE 38

Step 2: solve lower-dimensional equations

This gives us an equivalence f of type (k : N)(u : A)(us : Vec A k) (e : suc k ≡N suc n) ≃ (u : A)(us : Vec A n)

19 / 22

slide-39
SLIDE 39

Step 3: lift unifier to higher dimension

We lift f to an equivalence f ↑ of type (e1 : n ≡N n)(e2 : x ≡A y) (e3 : xs ≡Vec A e1 ys) (p : cong suc e1 ≡suc n≡Nsuc n refl) ≃ (e2 : x ≡A y)(e3 : xs ≡Vec A n ys)

20 / 22

slide-40
SLIDE 40

Lifting equivalences: (mostly) general case

  • Theorem. If we have an equivalence f of type

(x : A)(e : b1 x ≡B x b2 x) ≃ C we can construct f ↑ of type (e : u ≡A v)(p : cong b1 e ≡r≡B es cong b2 e) ≃ (e′ : f u r ≡C f v s)

21 / 22

slide-41
SLIDE 41

Conclusion

Proof-relevant unification is useful to deal with many equality constraints.

22 / 22

slide-42
SLIDE 42

Conclusion

Proof-relevant unification is useful to deal with many equality constraints. To make it work on indexed datatypes, we need to solve higher-dimensional equations.

22 / 22

slide-43
SLIDE 43

Conclusion

Proof-relevant unification is useful to deal with many equality constraints. To make it work on indexed datatypes, we need to solve higher-dimensional equations. We can reuse existing unification rules by lifting them to higher dimensions.

22 / 22