pattern matching without k
play

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 13 May 2014 How can we recognize definitions by pattern matching that do not depend on K? By taking identity proofs into account during


  1. Pattern matching without K Jesper Cockx Dominique Devriese Frank Piessens DistriNet – KU Leuven 13 May 2014

  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 / 20

  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 / 20

  4. Pattern matching without K 1 Dependent pattern matching 2 The K axiom 3 Translation to eliminators 4 Proof-relevant unification

  5. Pattern matching without K 1 Dependent pattern matching 2 The K axiom 3 Translation to eliminators 4 Proof-relevant unification

  6. Simple pattern matching data N : Set where z : N s : N → N min : N → N → N y = ? x min 2 / 20

  7. Simple pattern matching data N : Set where z : N s : N → N min : N → N → N y = z min z ( s x ) y = ? min 2 / 20

  8. Simple pattern matching data N : Set where z : N s : N → N min : N → N → N = z y min z ( s x ) z = z min ( s x ) ( s y ) = s ( min x y ) min 2 / 20

  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 = ? x y p q antisym 3 / 20

  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 ⌊ z ⌋ ⌊ y ⌋ ( lz y ) = ? q antisym ⌊ s x ⌋ ⌊ s y ⌋ ( ls x y p ) q = ? antisym 3 / 20

  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 ⌊ z ⌋ ⌊ z ⌋ ( lz ⌊ z ⌋ ) ( lz ⌊ z ⌋ ) = refl antisym ⌊ s x ⌋ ⌊ s y ⌋ ( ls x y p ) q = ? antisym 3 / 20

  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 ⌊ z ⌋ ⌊ z ⌋ ( lz ⌊ z ⌋ ) ( lz ⌊ z ⌋ ) = refl antisym ⌊ s x ⌋ ⌊ s y ⌋ ( ls x y p ) ( ls ⌊ y ⌋ ⌊ x ⌋ q ) antisym = cong s ( antisym x y p q ) 3 / 20

  13. Pattern matching without K 1 Dependent pattern matching 2 The K axiom 3 Translation to eliminators 4 Proof-relevant unification

  14. The identity type as an inductive family ≡ ( x : A ) : A → Set where data refl : x ≡ x trans : ( x y z : A ) → x ≡ y → y ≡ z → x ≡ z trans x ⌊ x ⌋ ⌊ x ⌋ refl refl = refl 4 / 20

  15. The identity type as an inductive family ≡ ( x : A ) : A → Set where data refl : x ≡ x trans : ( x y z : A ) → x ≡ y → y ≡ z → x ≡ z trans x ⌊ x ⌋ ⌊ x ⌋ refl refl = refl 4 / 20

  16. K follows from pattern matching K : ( P : a ≡ a → Set ) → ( p : P refl ) → ( e : a ≡ a ) → P e P p refl = p K 5 / 20

  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 ! 6 / 20

  18. The –without-K flag in Agda When making a case split, the indices must be applications of constructors to distinct variables (constructor parameters are treated as other arguments). These distinct variables must not be free in the parameters. 7 / 20

  19. New specification of –without-K It is not allowed to delete reflexive equations. When applying injectivity on an equation s = c ¯ c ¯ t of type D ¯ u , the indices ¯ u should be self-unifiable . 8 / 20

  20. Pattern matching without K 1 Dependent pattern matching 2 The K axiom 3 Translation to eliminators 4 Proof-relevant unification

  21. 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. 9 / 20

  22. Specialization by unification x ≃ x , ∆ ⇒ ∆ (Deletion) t ≃ x , ∆ ⇒ ∆[ x �→ t ] (Solution) s ≃ c ¯ s ≃ ¯ c ¯ t , ∆ ⇒ ¯ t , ∆ (Injectivity) s ≃ c 2 ¯ c 1 ¯ t , ∆ ⇒ ⊥ (Conflict) x ≃ c ¯ p [ x ] , ∆ ⇒ ⊥ (Cycle) 10 / 20

  23. 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 ) ( noConf N ( 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 ) ( noConf N z ( s n ) e )) ( λ k ; l ; e ; ; p ; q . subst ( λ n . n ≤ m ) ( noConf N ( s k ) ( s n ) p ) ( subst ( λ m . k ≤ m ) ( noConf N ( s l ) ( s m ) q ) e )) ( s n ) ( s m ) q refl refl ))) 11 / 20

  24. Pattern matching without K 1 Dependent pattern matching 2 The K axiom 3 Translation to eliminators 4 Proof-relevant unification

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

  26. Homogeneous telescopic equality We can use the first equality proof to fix the types of the following equations. a 1 , a 2 ≡ b 1 , b 2 ⇓ ( e 1 : a 1 ≡ b 1 )( e 2 : subst e 1 a 2 ≡ b 2 ) 13 / 20

  27. Deletion x ≃ x , ∆ ⇒ ∆ ⇓ e : x ≡ x , ∆ ⇒ ∆[ e �→ refl ] 14 / 20

  28. Solution t ≃ x , ∆ ⇒ ∆[ x �→ t ] ⇓ e : t ≡ x , ∆ ⇒ ∆[ x �→ t , e �→ refl ] 15 / 20

  29. Injectivity s ≃ c ¯ s ≃ ¯ c ¯ t , ∆ ⇒ ¯ t , ∆ ⇓ s ≡ c ¯ s ≡ ¯ t , ∆ ⇒ ¯ t , ∆[ e �→ conf ¯ e : c ¯ e : ¯ e ] 16 / 20

  30. Conflict c 1 ¯ u ≃ c 2 ¯ v , ∆ ⇒ ⊥ ⇓ s ≡ c 2 ¯ t , ∆ ⇒ ⊥ e : c 1 ¯ 17 / 20

  31. Cycle x ≃ c ¯ p [ x ] , ∆ ⇒ ⊥ ⇓ e : x ≡ c ¯ p [ x ] , ∆ ⇒ ⊥ 18 / 20

  32. Future work Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types 19 / 20

  33. Future work Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types 19 / 20

  34. Future work Detecting types that satisfy K (i.e. sets) Implementing the translation to eliminators Extending pattern matching to higher inductive types 19 / 20

  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! 20 / 20

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

  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

  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-[]=

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

  40. 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.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend