Pattern matching without K Jesper Cockx Dominique Devriese Frank - - PowerPoint PPT Presentation

pattern matching without k
SMART_READER_LITE
LIVE PREVIEW

Pattern matching without K Jesper Cockx Dominique Devriese Frank - - PowerPoint PPT Presentation

Pattern matching without K Jesper Cockx Dominique Devriese Frank Piessens DistriNet KU Leuven 3 September 2014 How can we recognize definitions by pattern matching that do not depend on K? By taking identity proofs into account during


slide-1
SLIDE 1

Pattern matching without K

Jesper Cockx Dominique Devriese Frank Piessens

DistriNet – KU Leuven

3 September 2014

slide-2
SLIDE 2

How can we recognize definitions by pattern matching that do not depend on K? By taking identity proofs into account during unification of the indices!

1 / 1

slide-3
SLIDE 3

How can we recognize definitions by pattern matching that do not depend on K? By taking identity proofs into account during unification of the indices!

1 / 1

slide-4
SLIDE 4

Pattern matching without K

slide-5
SLIDE 5

Pattern matching without K

slide-6
SLIDE 6

Simple pattern matching

data N : Set where z : N s : N → N min : N → N → N min x y = ?

2 / 1

slide-7
SLIDE 7

Simple pattern matching

data N : Set where z : N s : N → N min : N → N → N min z y = z min (s x) y = ?

2 / 1

slide-8
SLIDE 8

Simple pattern matching

data N : Set where z : N s : N → N min : N → N → N min z y = z min (s x) z = z min (s x) (s y) = s (min x y)

2 / 1

slide-9
SLIDE 9

Dependent pattern matching

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

3 / 1

slide-10
SLIDE 10

Dependent pattern matching

data ≤ : N → N → Set where lz : (x : N) → z ≤ x ls : (x y : N) → x ≤ y → s x ≤ s y 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 = ?

3 / 1

slide-11
SLIDE 11

Dependent pattern matching

data ≤ : N → N → Set where lz : (x : N) → z ≤ x ls : (x y : N) → x ≤ y → s x ≤ s y 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 = ?

3 / 1

slide-12
SLIDE 12

Dependent pattern matching

data ≤ : N → N → Set where lz : (x : N) → z ≤ x ls : (x y : N) → x ≤ y → s x ≤ s y 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)

3 / 1

slide-13
SLIDE 13

antisym : (m n : N) → m ≤ n → n ≤ m → m ≡ n antisym = elim≤ (λm; n; . n ≤ m → m ≡ n) (λn; e. elim≤ (λn; m; . m ≡ z → m ≡ n) (λn; e. e) (λk; l; ; ; e. elim⊥(λ . s l ≡ s k) (noConfN (s l) z e)) n z e refl) (λm; n; ; H; q. cong s (H (elim≤ (λk; l; . k ≡ s n → l ≡ s m → n ≤ m) (λ ; e; . elim⊥ (λ . n ≤ m) (noConfN z (s n) e)) (λk; l; e; ; p; q. subst (λn. n ≤ m) (noConfN (s k) (s n) p) (subst (λm. k ≤ m) (noConfN (s l) (s m) q) e)) (s n) (s m) q refl refl)))

4 / 1

slide-14
SLIDE 14

The identity type as an inductive family

data ≡ (x : A) : A → Set where refl : x ≡ x trans : (x y z : A) → x ≡ y → y ≡ z → x ≡ z trans x ⌊x⌋ ⌊x⌋ refl refl = refl

5 / 1

slide-15
SLIDE 15

The identity type as an inductive family

data ≡ (x : A) : A → Set where refl : x ≡ x trans : (x y z : A) → x ≡ y → y ≡ z → x ≡ z trans x ⌊x⌋ ⌊x⌋ refl refl = refl

5 / 1

slide-16
SLIDE 16

K follows from pattern matching

K : (P : a ≡ a → Set) → (p : P refl) → (e : a ≡ a) → P e K P p refl = p

6 / 1

slide-17
SLIDE 17

We don’t always want to assume K

K is incompatible with univalence: K implies that subst e true = true for all e : Bool ≡ Bool Univalence gives swap : Bool ≡ Bool such that subst swap true = false hence true = false!

7 / 1

slide-18
SLIDE 18

Pattern matching without K

slide-19
SLIDE 19

Unification of the indices

x ≃ x, ∆ ⇒ ∆ (Deletion) t ≃ x, ∆ ⇒ ∆[x → t] (Solution) c ¯ s ≃ c ¯ t, ∆ ⇒ ¯ s ≃ ¯ t, ∆ (Injectivity) c1 ¯ s ≃ c2 ¯ t, ∆ ⇒ ⊥ (Conflict) x ≃ c ¯ p[x], ∆ ⇒ ⊥ (Cycle)

8 / 1

slide-20
SLIDE 20

The criterium

It is not allowed to delete reflexive equations. When applying injectivity on an equation c ¯ s = c ¯ t of type D ¯ u, the indices ¯ u should be self-unifiable.

9 / 1

slide-21
SLIDE 21

Why deletion has to be disabled

UIP : (e : a ≡ a) → e ≡ refl UIP refl = refl Couldn’t solve reflexive equation a = a of type A because K has been disabled.

10 / 1

slide-22
SLIDE 22

Why injectivity has to be restricted

UIP′ : (e : refl ≡a≡a refl) → e ≡ refl UIP′ refl = refl Couldn’t solve reflexive equation a = a of type A because K has been disabled.

11 / 1

slide-23
SLIDE 23

Pattern matching without K

slide-24
SLIDE 24

Eliminating dependent pattern matching

1 Basic case analysis:

Translate each case split to an eliminator.

2 Specialization by unification:

Solve the equations on the indices.

3 Structural recursion:

Fill in the recursive calls.

12 / 1

slide-25
SLIDE 25

Heterogeneous equality

a : A b : B a ≃ b : Set a : A refl : a ≃ a eqElim : (x y : A) → (e : x ≃ y) → D x refl → D y e This elimination rule is equivalent with K . . .

13 / 1

slide-26
SLIDE 26

Homogeneous telescopic equality

We can use the first equality proof to fix the types of the following equations. a1, a2 ≡ b1, b2 ⇓ (e1 : a1 ≡ b1)(e2 : subst e1 a2 ≡ b2)

14 / 1

slide-27
SLIDE 27

Deletion

x ≃ x, ∆ ⇒ ∆ ⇓ e : x ≡ x, ∆ ⇒ ∆[e → refl] This is exactly the K axiom!

15 / 1

slide-28
SLIDE 28

Solution

t ≃ x, ∆ ⇒ ∆[x → t] ⇓ e : t ≡ x, ∆ ⇒ ∆[x → t, e → refl]

16 / 1

slide-29
SLIDE 29

Injectivity

c ¯ s ≃ c ¯ t, ∆ ⇒ ¯ s ≃ ¯ t, ∆ ⇓ e : c ¯ s ≡ c ¯ t, ∆ ⇒ ¯ e : ¯ s ≡ ¯ t, ∆[e → conf ¯ e] Indices of c ¯ s and c ¯ t should be unifiable

17 / 1

slide-30
SLIDE 30

Conflict

c1 ¯ u ≃ c2 ¯ v, ∆ ⇒ ⊥ ⇓ e : c1 ¯ s ≡ c2 ¯ t, ∆ ⇒ ⊥

18 / 1

slide-31
SLIDE 31

Cycle

x ≃ c ¯ p[x], ∆ ⇒ ⊥ ⇓ e : x ≡ c ¯ p[x], ∆ ⇒ ⊥

19 / 1

slide-32
SLIDE 32

Possible extensions

Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types

20 / 1

slide-33
SLIDE 33

Possible extensions

Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types

20 / 1

slide-34
SLIDE 34

Possible extensions

Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types

20 / 1

slide-35
SLIDE 35

Conclusion

By restricting the unification algorithm, we can make sure that K is never used. You no longer have to worry when using pattern matching for HoTT!

21 / 1

slide-36
SLIDE 36

http://people.cs.kuleuven.be/ ∼ jesper.cockx/Without-K/

slide-37
SLIDE 37

Standard library without K Fixable errors: 16

Module Functions Algebra.RingSolver

?

=H,

?

=N Data.Fin.Properties drop-suc Data.Vec.Equality trans,

?

= Data.Vec.Properties ::-injective, . . . Relation.Binary.Vec.Pointwise head, tail Data.Fin.Subset.Properties drop-there, ̸∈⊥, . . . Data.Fin.Dec ∈? Data.List.Countdown drop-suc

slide-38
SLIDE 38

Unfixable/unknown errors: 20

Module Functions Relation.Binary. HeterogeneousEquality ∼ =-to-≡, subst, cong, . . . PropositionalEquality proof-irrelevance Sigma.Pointwise Rel↔≡, inverse Data. Colist Any-cong, ⊑-Poset Covec setoid Container.Indexed setoid, natural, ◦-correct List.Any.BagAndSetEquality drop-cons Star.Decoration gmapAll, ◁ ◁ ◁ Star.Pointer lookup Vec.Properties proof-irrelevance-[]=