nonuniform coercions via unification hints
play

Nonuniform Coercions via Unification Hints Claudio Sacerdoti Coen 1 - PowerPoint PPT Presentation

Nonuniform Coercions via Unification Hints Claudio Sacerdoti Coen 1 , Enrico Tassi 2 1 University of Bologna - Department of Computer Science 2 Microsoft Research-INRIA Joint Center TYPES 2010 15 October 2010 Warsaw Context of this work


  1. Nonuniform Coercions via Unification Hints Claudio Sacerdoti Coen 1 , Enrico Tassi 2 1 University of Bologna - Department of Computer Science 2 Microsoft Research-INRIA Joint Center TYPES 2010 — 15 October 2010 — Warsaw

  2. Context of this work ◮ Interactive theorem prover Matita (CIC) ◮ Formalization of formal topology (Algebraic Structures)

  3. Context of this work ◮ Interactive theorem prover Matita (CIC) ◮ Formalization of formal topology (Algebraic Structures) Kernel Refiner Type “Type Checking Inference” ? ≡ = Matita

  4. Context of this work ◮ Interactive theorem prover Matita (CIC) ◮ Formalization of formal topology (Algebraic Structures) Kernel Refiner Type “Type Checking Inference” ? ≡ = Matita ◮ Unification made user-extensible (Unification Hints)

  5. Context of this work ◮ Interactive theorem prover Matita (CIC) ◮ Formalization of formal topology (Algebraic Structures) Kernel Refiner Type “Type Checking Inference” ? ≡ = Matita ◮ Unification made user-extensible (Unification Hints) ◮ In some corner cases the system is unable to exploit the knowledge given by hints

  6. Example ✞ ☎ record Group : Type := { carr : Type, ∗ : . . . } definition Z : Group := � Z, +, 0, . . . � . lemma mulg1: ∀ G:Group, ∀ a:carr G. a ∗ 1 = a. lemma cardG gt0 : ∀ G : Group, 0 < | G | . ✝ ✆ ✞ ☎ check (mulg1 ? G 2). ✝ ✆

  7. Example ✞ ☎ record Group : Type := { carr : Type, ∗ : . . . } definition Z : Group := � Z, +, 0, . . . � . lemma mulg1: ∀ G:Group, ∀ a:carr G. a ∗ 1 = a. lemma cardG gt0 : ∀ G : Group, 0 < | G | . ✝ ✆ ✞ ☎ check (mulg1 ? G 2). ✝ ✆ Works, since 2 has type Z , and it’s context expects a term of type carr ? G and the unification algorithm knows a canonical ? solution for Z = carr ? G .

  8. Example ✞ ☎ record Group : Type := { carr : Type, ∗ : . . . } definition Z : Group := � Z, +, 0, . . . � . lemma mulg1: ∀ G:Group, ∀ a:carr G. a ∗ 1 = a. lemma cardG gt0 : ∀ G : Group, 0 < | G | . ✝ ✆ ✞ ☎ check (mulg1 ? G 2). ✝ ✆ Works, since 2 has type Z , and it’s context expects a term of type carr ? G and the unification algorithm knows a canonical ? solution for Z = carr ? G . ✞ ☎ check (cardG gt0 Z). ✝ ✆

  9. Example ✞ ☎ record Group : Type := { carr : Type, ∗ : . . . } definition Z : Group := � Z, +, 0, . . . � . lemma mulg1: ∀ G:Group, ∀ a:carr G. a ∗ 1 = a. lemma cardG gt0 : ∀ G : Group, 0 < | G | . ✝ ✆ ✞ ☎ check (mulg1 ? G 2). ✝ ✆ Works, since 2 has type Z , and it’s context expects a term of type carr ? G and the unification algorithm knows a canonical ? solution for Z = carr ? G . ✞ ☎ check (cardG gt0 Z). ✝ ✆ Error: Z has type Type but it’s context expects a term of type ? Group . The unification problem Type = Group has no solution.

  10. Outline 1. Coercions ◮ Nonuniform coercions ◮ Examples 2. Implementation ◮ Ingredients ◮ Declaring nonuniform coercions ◮ Reusing existing hints 3. Conclusions

  11. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors Γ ⊢ x : N � : Z

  12. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ( k , ( N , Z )) ∈ ∆ Γ ⊢ x : N � : Z

  13. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ( k , ( N , Z )) ∈ ∆ Γ ⊢ x : N � : Z

  14. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ( k , ( N , Z )) ∈ ∆ Γ ⊢ x : N � : Z

  15. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ( k , ( N , Z )) ∈ ∆ Γ ⊢ k x : Z Γ ⊢ x : N � : Z

  16. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k x : Z = Z Z Γ ⊢ x : N � : Z

  17. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k x : Z = Z Z Γ ⊢ x : N � k x : Z

  18. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k x : Z Z = Z Γ ⊢ x : N � k x : Z ◮ but (uniform) coercions are type theoretic functions whose insertion is type driven. ( λ . Z , ( Type , Group )) ∈ ∆ Γ ⊢ ( λ . Z ) Z : Group Γ ⊢ Z : Type � ( λ . Z ) Z : Group

  19. Type inference and coercions ◮ These problems have to be addressed by type inference Γ ⊢ t : T � t ′ : T ′ ◮ Looks like coercions could solve these typing errors ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k x : Z Z = Z Γ ⊢ x : N � k x : Z ◮ but (uniform) coercions are type theoretic functions whose insertion is type driven. ( λ . Z , ( Type , Group )) ∈ ∆ Γ ⊢ ( λ . Z ) Q : Group Γ ⊢ Q : Type � ( λ . Z ) Q : Group

  20. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: Γ ⊢ s : S � : T where variables in Γ i are replaced by unification variables.

  21. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: � � Γ i ⊢ S i → T i �→ s i t i ∈ ∆ Γ ⊢ s : S � : T where variables in Γ i are replaced by unification variables.

  22. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: ? = S S i � � Γ i ⊢ S i → T i �→ s i t i ∈ ∆ Γ ⊢ s : S � : T where variables in Γ i are replaced by unification variables.

  23. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: ? = S S i ? s = s i � � Γ i ⊢ S i → T i �→ s i t i ∈ ∆ Γ ⊢ s : S � : T where variables in Γ i are replaced by unification variables.

  24. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: ? = S S i ? s = s i � � Γ i ⊢ S i → T i ? �→ T = T i s i t i ∈ ∆ Γ ⊢ s : S � : T where variables in Γ i are replaced by unification variables.

  25. Nonuniform coercions � � S 1 → T 1 S n → T n ∆ = Γ 1 ⊢ Γ n ⊢ . . . �→ �→ s 1 t 1 s n t n where Γ i ⊢ s i : S i Γ i ⊢ t i : T i Inserting a nonuniform coercion works as follows: ? = S S i ? s = s i � � Γ i ⊢ S i → T i ? �→ T = T i s i t i ∈ ∆ Γ ⊢ s : S � t i : T where variables in Γ i are replaced by unification variables.

  26. Nonuniform coercions: examples Uniform coercions → N Z x : N ⊢ x �→ k x Nonuniform coercions Type → Group ⊢ �→ Z Z → Type Group ⊢ Q �→ Q

  27. Cheap implementation: ingredient #1 Unification hints: − → ? x := − → H myhint Γ ⊢ P ≡ Q

  28. Cheap implementation: ingredient #1 Unification hints: − → ? x := − → H myhint Γ ⊢ P ≡ Q Examples: ? G := Z ⊢ Z ≡ carr ? G

  29. Cheap implementation: ingredient #1 Unification hints: − → ? x := − → H myhint Γ ⊢ P ≡ Q Examples: ? G := Z ⊢ Z ≡ carr ? G ? A := carr G ? B := carr H ? X := product group G H G , H : Group ⊢ ? A × ? B ≡ carr ? X

  30. Cheap implementation: ingredient #1 (cont.) Note that hints define “equivalence classes” of constants, thus approximated indexing for fast retrieval must take them into account. ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k s : Z = carr Z Z Γ ⊢ s : N � k s : carr Z

  31. Cheap implementation: ingredient #1 (cont.) Note that hints define “equivalence classes” of constants, thus approximated indexing for fast retrieval must take them into account. ? ( k , ( N , Z )) ∈ ∆ Γ ⊢ k s : Z = carr Z Z Γ ⊢ s : N � k s : carr Z

  32. Cheap implementation: ingredient #2 Uniform coercion loosely indexed: ? ( result , ( ∗ , target )) ∈ ∆ Γ ⊢ result s : target = T target Γ ⊢ x : S � result s : T Note that T and target can be in the same equivalence class.

Recommend


More recommend