unification in a context of postponed equations
play

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,


  1. Unification in a context of postponed equations Jesper Cockx DistriNet – KU Leuven 4 June 2015

  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

  3. The underlying problem Current representation of heterogeneous equations lacks information: Morally different equations have same representation. I propose a better representation. 2 / 16

  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

  5. Unification in a context of postponed equations 1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

  6. Unification in a context of postponed equations 1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

  7. Dependent pattern matching ≤ : N → N → Set where data 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 x ≡ N z , y := n x := z lz : = = ⇒ y ≡ N n = = ⇒ () y ≡ n x ≡ N s m , x := s m y := s n ls : = = = = ⇒ y ≡ N s n = = = ⇒ () y ≡ N s n 4 / 16

  8. Dependent pattern matching ≤ : N → N → Set where data 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 x ≡ N z , y := n x := z lz : = = ⇒ y ≡ N n = = ⇒ () y ≡ n x ≡ N s m , x := s m y := s n ls : = = = = ⇒ y ≡ N s n = = = ⇒ () y ≡ N s n 4 / 16

  9. Dependent pattern matching ≤ : N → N → Set where data 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 x ≡ N z , y := n x := z lz : = = ⇒ y ≡ N n = = ⇒ () y ≡ n x ≡ N s m , x := s m y := s n ls : = = = = ⇒ y ≡ N s n = = = ⇒ () y ≡ N s n 4 / 16

  10. Dependent pattern matching ≤ : N → N → Set where data 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 y ≡ N z , y := z n := z lz : = = ⇒ z ≡ N n = = ⇒ () z ≡ N n y ≡ N s m , y := s m conflict ls : = = = = ⇒ z ≡ N s n = = = = ⇒ ⊥ z ≡ N s n 4 / 16

  11. Dependent pattern matching ≤ : N → N → Set where data 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 y ≡ N z , y := z n := z lz : = = ⇒ z ≡ N n = = ⇒ () z ≡ N n y ≡ N s m , y := s m conflict ls : = = = = ⇒ z ≡ N s n = = = = ⇒ ⊥ z ≡ N s n 4 / 16

  12. Dependent pattern matching ≤ : N → N → Set where data 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 s y ≡ N z , conflict lz : = = = = ⇒ ⊥ s x ≡ N n s y ≡ N s m , y ≡ N m , injectivity = = = = = ⇒ s x ≡ N s n s x ≡ N s n ls : m := y injectivity n := x = = = ⇒ s x ≡ N s n = = = = = ⇒ x ≡ N n = = ⇒ () 4 / 16

  13. Dependent pattern matching ≤ : N → N → Set where data 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 s y ≡ N z , conflict lz : = = = = ⇒ ⊥ s x ≡ N n s y ≡ N s m , y ≡ N m , injectivity = = = = = ⇒ s x ≡ N s n s x ≡ N s n ls : m := y injectivity n := x = = = ⇒ s x ≡ N s n = = = = = ⇒ x ≡ N n = = ⇒ () 4 / 16

  14. Dependent pattern matching ≤ : N → N → Set where data 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 ) 4 / 16

  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

  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 on heterogeneous equations? 6 / 16

  17. Heterogeneous types data Bool1 : Set where data Bool2 : Set where true1 : Bool1 true2 : Bool2 false1 : Bool1 false2 : Bool2 ≡ Set Bool1 Bool2 , conflict = = = = ⇒ ⊥ ? true1 Bool1 ∼ = Bool2 true2 This allows us to prove that Bool1 �≡ Bool2 ! 7 / 16

  18. Heterogeneous types Solution (until now): types must have the same shape injectivity ok: box s Box s ∼ = Box t box t = = = = = ⇒ s ≡ A t (types both have the shape Box . . . ) conflict not ok: true1 Bool1 ∼ = Bool2 true2 = = = = ⇒ ⊥ (types are unrelated) 8 / 16

  19. Unification in a context of postponed equations 1 Why do we need unification? 2 A context of postponed equations 3 Reverse unification rules

  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 = Box y box y and Box x y , ≡ Set Box y , box x Box x ∼ box x Box x ∼ = Box y box y ? In current representation, nothing! 9 / 16

  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 = Box y box y and Box x y , ≡ Set Box y , box x Box x ∼ box x Box x ∼ = Box y box y ? In current representation, nothing! 9 / 16

  22. Lack of information in current representation data Box : A → Set where box : ( x : A ) → Box x Box x ≡ Box y , Ok to apply injectivity box x ∼ = box y b/c types are equal ⇒ Box x ≡ Box y , injectivity = = = = = x ∼ = y Types are equal because y := x = = ⇒ Box x ≡ Box x we can apply injectivity deletion = = = = ⇒ () ⇒ circular argument! 10 / 16

  23. Lack of information in current representation data Box : A → Set where box : ( x : A ) → Box x Box x ≡ Box y , Ok to apply injectivity box x ∼ = box y b/c types are equal ⇒ Box x ≡ Box y , injectivity = = = = = x ∼ = y Types are equal because y := x = = ⇒ Box x ≡ Box x we can apply injectivity deletion = = = = ⇒ () ⇒ circular argument! 10 / 16

  24. Lack of information in current representation data Box : A → Set where box : ( x : A ) → Box x Box x ≡ Box y , Ok to apply injectivity box x ∼ = box y b/c types are equal ⇒ Box x ≡ Box y , injectivity = = = = = x ∼ = y Types are equal because y := x = = ⇒ Box x ≡ Box x we can apply injectivity deletion = = = = ⇒ () ⇒ circular argument! 10 / 16

  25. Representing postponed equations as fresh variables data Box : A → Set where box : ( x : A ) → Box x What’s different between second equation of e 1 : e 2 : box x ≡ Box e 1 box y and e 1 : Box x ≡ Set Box y , x ≡ A y , ? e 2 : box x ≡ e 1 box y It’s obvious now! 11 / 16

  26. Representing postponed equations as fresh variables data Box : A → Set where box : ( x : A ) → Box x What’s different between second equation of e 1 : e 2 : box x ≡ Box e 1 box y and e 1 : Box x ≡ Set Box y , x ≡ A y , ? e 2 : box x ≡ e 1 box y It’s obvious now! 11 / 16

  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

  28. � Examples e 1 : x ≡ A y , y := x injectivity = = = = = ⇒ x ≡ A y = = ⇒ () e 2 : box x ≡ Box e 1 box y e 1 : Box x ≡ Set Box y , injectivity = = = = = ⇒ (not a datatype) e 2 : box x ≡ e 1 box y injectivity e 1 : box x ≡ Box x box x � = = = = = ⇒ (not an equation var) Uh oh... 13 / 16

  29. � Examples e 1 : x ≡ A y , y := x injectivity = = = = = ⇒ x ≡ A y = = ⇒ () e 2 : box x ≡ Box e 1 box y e 1 : Box x ≡ Set Box y , injectivity = = = = = ⇒ (not a datatype) e 2 : box x ≡ e 1 box y injectivity e 1 : box x ≡ Box x box x � = = = = = ⇒ (not an equation var) Uh oh... 13 / 16

Recommend


More recommend