Unification in a context of postponed equations Jesper Cockx - - PowerPoint PPT Presentation

unification in a context of postponed equations
SMART_READER_LITE
LIVE PREVIEW

Unification in a context of postponed equations Jesper Cockx - - PowerPoint PPT Presentation

Unification in a context of postponed equations Jesper Cockx DistriNet KU Leuven 4 June 2015 Postponed equations cause problems Issue 292: Heterogenous equality is crippled by the Bool = Fin 2 fix Issue 1071: Regression in unifier,


slide-1
SLIDE 1

Unification in a context of postponed equations

Jesper Cockx

DistriNet – KU Leuven

4 June 2015

slide-2
SLIDE 2

Postponed equations cause problems

Issue 292: Heterogenous equality is crippled by the Bool = Fin 2 fix Issue 1071: Regression in unifier, possibly related to modules and/or heterogeneous constraints Issue 1406: Injectivity of type constructors is partially back. Agda refutes excluded middle Issue 1408: Heterogeneous equality incompatible with univalence even –without-K Issue 1411: Order of patterns matters for checking left hand sides Issue 1427: Circumvention of forcing analysis brings back easy proof of Fin injectivity Issue 1435: Dependent pattern matching is broken

1 / 16

slide-3
SLIDE 3

The underlying problem

Current representation of heterogeneous equations lacks information: Morally different equations have same representation. I propose a better representation.

2 / 16

slide-4
SLIDE 4

Advantages of new representation

Handles previous issues in a uniform way Also accepts some new examples, especially when –without-K is enabled Theoretically appealing ⇒ possibility for correctness proof

3 / 16

slide-5
SLIDE 5

Unification in a context of postponed equations

1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

slide-6
SLIDE 6

Unification in a context of postponed equations

1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

slide-7
SLIDE 7

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym x y p q = ? lz: x ≡N z, y ≡ n

x:=z

= = ⇒ y ≡N n

y:=n

= = ⇒ () ls: x ≡N s m, y ≡N s n

x:=s m

= = = = ⇒ y ≡N s n

y:=s n

= = = ⇒ ()

4 / 16

slide-8
SLIDE 8

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym x y p q = ? lz: x ≡N z, y ≡ n

x:=z

= = ⇒ y ≡N n

y:=n

= = ⇒ () ls: x ≡N s m, y ≡N s n

x:=s m

= = = = ⇒ y ≡N s n

y:=s n

= = = ⇒ ()

4 / 16

slide-9
SLIDE 9

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym x y p q = ? lz: x ≡N z, y ≡ n

x:=z

= = ⇒ y ≡N n

y:=n

= = ⇒ () ls: x ≡N s m, y ≡N s n

x:=s m

= = = = ⇒ y ≡N s n

y:=s n

= = = ⇒ ()

4 / 16

slide-10
SLIDE 10

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym ⌊z⌋ ⌊y⌋ (lz y) q = ? antisym ⌊s x⌋ ⌊s y⌋ (ls x y p) q = ? lz: y ≡N z, z ≡N n

y:=z

= = ⇒ z ≡N n

n:=z

= = ⇒ () ls: y ≡N s m, z ≡N s n

y:=s m

= = = = ⇒ z ≡N s n

conflict

= = = = ⇒ ⊥

4 / 16

slide-11
SLIDE 11

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym ⌊z⌋ ⌊y⌋ (lz y) q = ? antisym ⌊s x⌋ ⌊s y⌋ (ls x y p) q = ? lz: y ≡N z, z ≡N n

y:=z

= = ⇒ z ≡N n

n:=z

= = ⇒ () ls: y ≡N s m, z ≡N s n

y:=s m

= = = = ⇒ z ≡N s n

conflict

= = = = ⇒ ⊥

4 / 16

slide-12
SLIDE 12

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym ⌊z⌋ ⌊z⌋ (lz ⌊z⌋) (lz ⌊z⌋) = refl antisym ⌊s x⌋ ⌊s y⌋ (ls x y p) q = ? lz: s y ≡N z, s x ≡N n

conflict

= = = = ⇒ ⊥ ls: s y ≡N s m, s x ≡N s n

injectivity

= = = = = ⇒ y ≡N m, s x ≡N s n

m:=y

= = = ⇒ s x ≡N s n

injectivity

= = = = = ⇒ x ≡N n

n:=x

= = ⇒ ()

4 / 16

slide-13
SLIDE 13

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym ⌊z⌋ ⌊z⌋ (lz ⌊z⌋) (lz ⌊z⌋) = refl antisym ⌊s x⌋ ⌊s y⌋ (ls x y p) q = ? lz: s y ≡N z, s x ≡N n

conflict

= = = = ⇒ ⊥ ls: s y ≡N s m, s x ≡N s n

injectivity

= = = = = ⇒ y ≡N m, s x ≡N s n

m:=y

= = = ⇒ s x ≡N s n

injectivity

= = = = = ⇒ x ≡N n

n:=x

= = ⇒ ()

4 / 16

slide-14
SLIDE 14

Dependent pattern matching

data ≤ : N → N → Set where lz : (n : N) → z ≤ n ls : (m n : N) → m ≤ n → s m ≤ s n antisym : (x y : N) → x ≤ y → y ≤ x → x ≡ y antisym ⌊z⌋ ⌊z⌋ (lz ⌊z⌋) (lz ⌊z⌋) = refl antisym ⌊s x⌋ ⌊s y⌋ (ls x y p) (ls ⌊y⌋ ⌊x⌋ q) = cong s (antisym x y p q)

4 / 16

slide-15
SLIDE 15

Postponed equations

Some equations cannot be solved right away f z ≡N s z

?

= ⇒ but solving later equations can change this f z ≡N s z, f ≡N→N s

f :=s

= = ⇒ s z ≡N s z

injectivity

= = = = = ⇒ z ≡N z

injectivity

= = = = = ⇒ ()

5 / 16

slide-16
SLIDE 16

Heterogeneous types

data Box : A → Set where box : (x : A) → Box x Let s, t : A, then in s ≡A t, box s Box s∼ =Box t box t the second equation has a heterogeneous type. Can we apply unification rules

  • n heterogeneous equations?

6 / 16

slide-17
SLIDE 17

Heterogeneous types

data Bool1 : Set where true1 : Bool1 false1 : Bool1 data Bool2 : Set where true2 : Bool2 false2 : Bool2

Bool1 ≡Set Bool2, true1 Bool1∼ =Bool2 true2

conflict

= = = = ⇒ ⊥ ? This allows us to prove that Bool1 ≡ Bool2!

7 / 16

slide-18
SLIDE 18

Heterogeneous types

Solution (until now): types must have the same shape

  • k: box s Box s∼

=Box t box t

injectivity

= = = = = ⇒ s ≡A t (types both have the shape Box . . .) not ok: true1 Bool1∼ =Bool2 true2

conflict

= = = = ⇒ ⊥ (types are unrelated)

8 / 16

slide-19
SLIDE 19

Unification in a context of postponed equations

1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

slide-20
SLIDE 20

Lack of information in current representation

data Box : A → Set where box : (x : A) → Box x What’s different between second equation of x ≡A y, box x Box x∼ =Box y box y and Box x ≡Set Box y, box x Box x∼ =Box y box y ? In current representation, nothing!

9 / 16

slide-21
SLIDE 21

Lack of information in current representation

data Box : A → Set where box : (x : A) → Box x What’s different between second equation of x ≡A y, box x Box x∼ =Box y box y and Box x ≡Set Box y, box x Box x∼ =Box y box y ? In current representation, nothing!

9 / 16

slide-22
SLIDE 22

Lack of information in current representation

data Box : A → Set where box : (x : A) → Box x Box x ≡ Box y, box x ∼ = box y

injectivity

= = = = = ⇒ Box x ≡ Box y, x ∼ = y

y:=x

= = ⇒ Box x ≡ Box x

deletion

= = = = ⇒ () Ok to apply injectivity b/c types are equal Types are equal because we can apply injectivity ⇒ circular argument!

10 / 16

slide-23
SLIDE 23

Lack of information in current representation

data Box : A → Set where box : (x : A) → Box x Box x ≡ Box y, box x ∼ = box y

injectivity

= = = = = ⇒ Box x ≡ Box y, x ∼ = y

y:=x

= = ⇒ Box x ≡ Box x

deletion

= = = = ⇒ () Ok to apply injectivity b/c types are equal Types are equal because we can apply injectivity ⇒ circular argument!

10 / 16

slide-24
SLIDE 24

Lack of information in current representation

data Box : A → Set where box : (x : A) → Box x Box x ≡ Box y, box x ∼ = box y

injectivity

= = = = = ⇒ Box x ≡ Box y, x ∼ = y

y:=x

= = ⇒ Box x ≡ Box x

deletion

= = = = ⇒ () Ok to apply injectivity b/c types are equal Types are equal because we can apply injectivity ⇒ circular argument!

10 / 16

slide-25
SLIDE 25

Representing postponed equations as fresh variables

data Box : A → Set where box : (x : A) → Box x What’s different between second equation of e1 : x ≡A y, e2 : box x ≡Box e1 box y and e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y ? It’s obvious now!

11 / 16

slide-26
SLIDE 26

Representing postponed equations as fresh variables

data Box : A → Set where box : (x : A) → Box x What’s different between second equation of e1 : x ≡A y, e2 : box x ≡Box e1 box y and e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y ? It’s obvious now!

11 / 16

slide-27
SLIDE 27

Unification rules require fully general indices

In order to apply injectivity,

1 the type of the equation should be a

datatype

2 the indices should be distinct equation

variables Injectivity solves the index equations as well!

12 / 16

slide-28
SLIDE 28

Examples

e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ x ≡A y

y:=x

= = ⇒ () e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y

  • injectivity

= = = = = ⇒ (not a datatype) e1 : box x ≡Box x box x

injectivity

= = = = = ⇒ (not an equation var) Uh oh...

13 / 16

slide-29
SLIDE 29

Examples

e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ x ≡A y

y:=x

= = ⇒ () e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y

  • injectivity

= = = = = ⇒ (not a datatype) e1 : box x ≡Box x box x

injectivity

= = = = = ⇒ (not an equation var) Uh oh...

13 / 16

slide-30
SLIDE 30

Examples

e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ x ≡A y

y:=x

= = ⇒ () e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y

  • injectivity

= = = = = ⇒ (not a datatype) e1 : box x ≡Box x box x

injectivity

= = = = = ⇒ (not an equation var) Uh oh...

13 / 16

slide-31
SLIDE 31

Examples

e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ x ≡A y

y:=x

= = ⇒ () e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y

  • injectivity

= = = = = ⇒ (not a datatype) e1 : box x ≡Box x box x

injectivity

= = = = = ⇒ (not an equation var) Uh oh...

13 / 16

slide-32
SLIDE 32

Examples

e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ x ≡A y

y:=x

= = ⇒ () e1 : Box x ≡Set Box y, e2 : box x ≡e1 box y

  • injectivity

= = = = = ⇒ (not a datatype) e1 : box x ≡Box x box x

injectivity

= = = = = ⇒ (not an equation var) Uh oh...

13 / 16

slide-33
SLIDE 33

Unification in a context of postponed equations

1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

slide-34
SLIDE 34

Reverse solution

When indices are regular variables, we can fix that by introducing a new equation. e1 : box x ≡Box x box x

solution−1

= = = = = = ⇒ e1 : x ≡A y, e2 : box x ≡Box e1 box y

injectivity

= = = = = ⇒ e1 : x ≡A y

y:=x

= = ⇒ ()

14 / 16

slide-35
SLIDE 35

Reverse injectivity

When indices are constructor forms, we can fix that by gathering the equations together.

e1 : box (s z) ≡Box (s z) box (s z)

injectivity−1

= = = = = = ⇒ e1 : z ≡N z, e2 : box (s z) ≡Box (s e1) box (s z)

injectivity−1

= = = = = = ⇒ e1 : s z ≡N s z, e2 : box (s z) ≡Box e1 box (s z)

injectivity

= = = = = ⇒ e1 : s z ≡N s z

injectivity

= = = = = ⇒ e1 : z ≡N z

injectivity

= = = = = ⇒ ()

15 / 16

slide-36
SLIDE 36

Exodus: implementation

I’ve tried implementing this in Agda As usual, the code is much uglier than the theory Or maybe I just haven’t found the right abstraction yet... Any ideas or insights are welcome Thank you for your attention!

16 / 16

slide-37
SLIDE 37

Exodus: implementation

I’ve tried implementing this in Agda As usual, the code is much uglier than the theory Or maybe I just haven’t found the right abstraction yet... Any ideas or insights are welcome Thank you for your attention!

16 / 16

slide-38
SLIDE 38

Exodus: implementation

I’ve tried implementing this in Agda As usual, the code is much uglier than the theory Or maybe I just haven’t found the right abstraction yet... Any ideas or insights are welcome Thank you for your attention!

16 / 16

slide-39
SLIDE 39

Exodus: implementation

I’ve tried implementing this in Agda As usual, the code is much uglier than the theory Or maybe I just haven’t found the right abstraction yet... Any ideas or insights are welcome Thank you for your attention!

16 / 16

slide-40
SLIDE 40

Exodus: implementation

I’ve tried implementing this in Agda As usual, the code is much uglier than the theory Or maybe I just haven’t found the right abstraction yet... Any ideas or insights are welcome Thank you for your attention!

16 / 16