depending on equations
play

Depending on equations A proof-relevant framework for unification - PowerPoint PPT Presentation

Depending on equations A proof-relevant framework for unification in dependent type theory Jesper Cockx DistriNet KU Leuven 3 September 2017 Unification for dependent types Unification is used for many purposes: logic programming, type


  1. Specialization by unification Agda uses unification to: • eliminate impossible cases • specialize the result type The output of unification can change Agda’s notion of equality! Main question: How to make sure the output of unification is correct? 10 / 52

  2. Depending on equations Checking dependently typed programs Unification in dependent type theory Unification of dependently typed terms

  3. Q: What is the fastest way to start a fight between type theorists? 11 / 52

  4. Q: What is the fastest way to start a fight between type theorists? A: Mention the topic of equality. 11 / 52

  5. The identity type x ≡ A y . . . a dependent type depending on x , y : A . 12 / 52

  6. The identity type x ≡ A y . . . a dependent type depending on x , y : A . . . . type theory’s built-in notion of equality. 12 / 52

  7. The identity type x ≡ A y . . . a dependent type depending on x , y : A . . . . type theory’s built-in notion of equality. . . . the type of proofs that x = y . 12 / 52

  8. Operations on the identity type : x ≡ A x refl 13 / 52

  9. Operations on the identity type : x ≡ A x refl : x ≡ A y → y ≡ A x sym 13 / 52

  10. Operations on the identity type : x ≡ A x refl : x ≡ A y → y ≡ A x sym : x ≡ A y → y ≡ A z → x ≡ A z trans 13 / 52

  11. Operations on the identity type : x ≡ A x refl : x ≡ A y → y ≡ A x sym : x ≡ A y → y ≡ A z → x ≡ A z trans : x ≡ A y → f x ≡ B f y cong f 13 / 52

  12. Operations on the identity type : x ≡ A x refl : x ≡ A y → y ≡ A x sym : x ≡ A y → y ≡ A z → x ≡ A z trans : x ≡ A y → f x ≡ B f y cong f subst P : x ≡ A y → P x → P y 13 / 52

  13. Unification problems as telescopes A unification problem consists of 1. Flexible variables x 1 : A 1 , x 2 : A 2 , . . . 2. Equations u 1 = v 1 : B 1 , . . . 14 / 52

  14. Unification problems as telescopes A unification problem consists of 1. Flexible variables x 1 : A 1 , x 2 : A 2 , . . . 2. Equations u 1 = v 1 : B 1 , . . . This can be represented as a telescope : ( x 1 : A 1 )( x 2 : A 2 ) . . . ( e 1 : u 1 ≡ B 1 v 1 )( e 2 : u 2 ≡ B 2 v 2 ) . . . e.g. ( k : N )( n : N )( e : suc k ≡ N suc n ) 14 / 52

  15. Unification problems as telescopes A unification problem consists of 1. Flexible variables Γ 2. Equations u 1 = v 1 : B 1 , . . . This can be represented as a telescope : Γ ( e 1 : u 1 ≡ B 1 v 1 )( e 2 : u 2 ≡ B 2 v 2 ) . . . e.g. ( k : N )( n : N )( e : suc k ≡ N suc n ) 14 / 52

  16. Unification problems as telescopes A unification problem consists of 1. Flexible variables Γ 2. Equations ¯ u = ¯ v : ∆ This can be represented as a telescope : Γ(¯ e : ¯ u ≡ ∆ ¯ v ) e.g. ( k : N )( n : N )( e : suc k ≡ N suc n ) 14 / 52

  17. Unifiers as telescope maps A unifier of ¯ u and ¯ v is a substitution σ : Γ ′ → Γ such that ¯ u σ = ¯ v σ . 15 / 52

  18. Unifiers as telescope maps A unifier of ¯ u and ¯ v is a substitution σ : Γ ′ → Γ such that ¯ u σ = ¯ v σ . This can be represented as a telescope map : f : Γ ′ → Γ(¯ e : ¯ u ≡ ∆ ¯ v ) e.g. f : () → ( n : N )( e : n ≡ N zero ) f () = zero ; refl 15 / 52

  19. Evidence of unification A map f : () → ( n : N )( e : n ≡ N zero ) gives us two things: 16 / 52

  20. Evidence of unification A map f : () → ( n : N )( e : n ≡ N zero ) gives us two things: 1. A value for n such that n ≡ N zero 16 / 52

  21. Evidence of unification A map f : () → ( n : N )( e : n ≡ N zero ) gives us two things: 1. A value for n such that n ≡ N zero 2. Explicit evidence e of n ≡ N zero 16 / 52

  22. Evidence of unification A map f : () → ( n : N )( e : n ≡ N zero ) gives us two things: 1. A value for n such that n ≡ N zero 2. Explicit evidence e of n ≡ N zero = ⇒ Unification is guaranteed to respect ≡ ! 16 / 52

  23. Three valid unifiers f 1 : ( k : N ) → ( k n : N )( e : k ≡ N n ) f 1 k = k ; k ; refl f 2 : () → ( k n : N )( e : k ≡ N n ) f 2 () = zero ; zero ; refl f 3 : ( k n : N ) → ( k n : N )( e : k ≡ N n ) f 3 k n = k ; k ; refl 17 / 52

  24. Most general unifiers A most general unifier of ¯ u and ¯ v is a unifier σ such that for any σ ′ with ¯ u σ ′ = ¯ v σ ′ , there is a ν such that σ ′ = σ ◦ ν . 18 / 52

  25. Most general unifiers A most general unifier of ¯ u and ¯ v is a unifier σ such that for any σ ′ with ¯ u σ ′ = ¯ v σ ′ , there is a ν such that σ ′ = σ ◦ ν . This is quite difficult to translate to type theory directly. . . 18 / 52

  26. Most general unifiers A most general unifier of ¯ u and ¯ v is a unifier σ such that for any σ ′ with ¯ u σ ′ = ¯ v σ ′ , there is a ν such that σ ′ = σ ◦ ν . This is quite difficult to translate to type theory directly. . . Intuition: if f : Γ ′ → Γ(¯ u ≡ ∆ ¯ e : ¯ v ) is MGU, v ) to Γ ′ we can go back from Γ(¯ e : ¯ u ≡ ∆ ¯ without losing any information. 18 / 52

  27. Equivalences A function f : A → B is an equivalence if it has both a left and a right inverse: isLinv : ( x : A ) → g 1 ( f x ) ≡ A x isRinv : ( y : B ) → f ( g 2 y ) ≡ B y In this case, we write f : A ≃ B . 19 / 52

  28. Most general unifiers are equivalences! v ) ≃ Γ ′ f : Γ(¯ e : ¯ u ≡ ∆ ¯ 20 / 52

  29. Example of unification ( k n : N )( e : suc k ≡ N suc n ) 21 / 52

  30. Example of unification ( k n : N )( e : suc k ≡ N suc n ) ≃ ( k n : N )( e : k ≡ N n ) 21 / 52

  31. Example of unification ( k n : N )( e : suc k ≡ N suc n ) ≃ ( k n : N )( e : k ≡ N n ) ≃ ( k : N ) 21 / 52

  32. Example of unification ( k n : N )( e : suc k ≡ N suc n ) ≃ ( k n : N )( e : k ≡ N n ) ≃ ( k : N ) f : ( k : N ) → ( k n : N )( e : suc k ≡ N suc n ) f k = k ; k ; refl 21 / 52

  33. The solution rule solution : ( x : A )( e : x ≡ A t ) ≃ () 22 / 52

  34. The deletion rule deletion : ( e : t ≡ A t ) ≃ () 23 / 52

  35. The injectivity rule injectivity suc : ( e : suc x ≡ N suc y ) ≃ ( e ′ : x ≡ N y ) 24 / 52

  36. Negative unification rules A negative unification rule applies to impossible equations, e.g. suc x = zero . 25 / 52

  37. Negative unification rules A negative unification rule applies to impossible equations, e.g. suc x = zero . This can be represented by an equivalence: ( e : suc x ≡ N zero ) ≃ ⊥ where ⊥ is the empty type . 25 / 52

  38. The conflict rule conflict suc , zero : ( e : suc x ≡ N zero ) ≃ ⊥ 26 / 52

  39. The cycle rule cycle n , suc n : ( e : n ≡ N suc n ) ≃ ⊥ 27 / 52

  40. Unifiers as equivalences By requiring unifiers to be equivalences : • we exclude bad unification rules • we can safely introduce new rules 28 / 52

  41. Unifiers as equivalences By requiring unifiers to be equivalences : • we exclude bad unification rules • we can safely introduce new rules Next, we’ll explore how this idea can help us. Any questions so far? 28 / 52

  42. Depending on equations Checking dependently typed programs Unification in dependent type theory Unification of dependently typed terms

  43. Time for the interesting bits! • Equations between types • Heterogeneous equations • Equations on indexed datatypes • Equations between equations 29 / 52

  44. Equations between types Types are first-class terms of type Type : Bool : Type , N : Type , N → N : Type , . . . 30 / 52

  45. Equations between types Types are first-class terms of type Type : Bool : Type , N : Type , N → N : Type , . . . We can form equations between types, e.g. Bool ≡ Type Bool . 30 / 52

  46. Equations between types Types are first-class terms of type Type : Bool : Type , N : Type , N → N : Type , . . . We can form equations between types, e.g. Bool ≡ Type Bool . Q: Can we apply the deletion rule? 30 / 52

  47. Equations between types Types are first-class terms of type Type : Bool : Type , N : Type , N → N : Type , . . . We can form equations between types, e.g. Bool ≡ Type Bool . Q: Can we apply the deletion rule? A: Depends on which type theory we use! 30 / 52

  48. The univalence axiom (2009) Vladimir Voevodsky 31 / 52

  49. The univalence axiom (2009) “Isomorphic types can be identified.” Vladimir Voevodsky 31 / 52

  50. The univalence axiom (2009) “Isomorphic types can be identified.” ( A ≡ B ) ≃ ( A ≃ B ) Vladimir Voevodsky 31 / 52

  51. The univalence axiom (2009) Bool is equal to Bool in two ways: Bool true false 32 / 52

  52. The univalence axiom (2009) Bool is equal to Bool in two ways: Bool true false true false Bool 32 / 52

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