an introduction to type theory
play

An Introduction to Type Theory Part 2 Tallinn, September 2003 - PowerPoint PPT Presentation

An Introduction to Type Theory Part 2 Tallinn, September 2003 http://www.cs.nott.ac.uk/txa/tallinn/ Thorsten Altenkirch University of Nottingham An Introduction to Type Theory p.1/46 Plan of the course 1. Intuitionistic logic from a


  1. ☞ ✄ ✝ ✁ ✞ � � ✄ � ✁ ✆ ✟ ✁ � ✟ � ✞ ✂ ✁ � Peano’s axioms �✂✁ ✝✟✞✠ An Introduction to Type Theory – p.12/46

  2. ✄ ✄ ✝ ✁ ✞ � � � ☞ ✁ ✆ ✟ ✁ � ✟ � ✞ ✂ ✁ � Peano’s axioms �✂✁ ✝✟✞✠ where empty pattern An Introduction to Type Theory – p.12/46

  3. � � � � � ✁ ✂ ✞ � ✟ ✁ � ✁ ✟ ✁ ✄ ☞ ✄ ✞ ✆ ✆ � ✟ ✁ ✂ ✞ � ✟ � ✁ ✝ � ✄ ☞ ✄ � � ✞ ✁ ✝ ✁ Peano’s axioms �✂✁ ✝✟✞✠ where empty pattern �✂✁ ✝✟✞✠ An Introduction to Type Theory – p.12/46

  4. � � � ✝ � ✁ ✂ ✞ � ✟ ✁ � ✁ ✟ � ✄ ☞ ✄ ✞ ✆ ✆ � ✟ ✁ ✂ ✞ � ✟ � ✁ ✁ � ✄ ☞ ✄ � � ✞ ✁ ✝ ✁ Peano’s axioms �✂✁ ✝✟✞✠ where empty pattern �✂✁ ✝✟✞✠ where empty pattern An Introduction to Type Theory – p.12/46

  5. Peano’s axioms An Introduction to Type Theory – p.13/46

  6. ✄ � � � ✞ � ✝ ✁ � � ✄ ☞ ✁ ✁ � ✟ ✁ ✁ � � ✟ ✞ ✄ ✞ ✠ ✞ Peano’s axioms An Introduction to Type Theory – p.13/46

  7. ✞ ✄ ✁ ✝ � ✠ ✞ ✄ ✞ � � � � ✠ ✁ � ✝ � � ✠ ✁ ✄ � � � ✟ ✠ ✞ ✄ ✞ ✟ � � ✁ ✁ � ✞ ✁ ✄ ☞ ✄ � � ✁ ✝ � ✞ Peano’s axioms where An Introduction to Type Theory – p.13/46

  8. An Introduction to Type Theory – p.13/46 ✞ ✞ ✁ ✂ � ✝ � ✄ � ✁ ✠ � � ✝ � ✟ � � ✞ ✁ � � � ✝ ✁ � ✁ � ✞ ✄ ☞ ✄ ✟ ✁ ✁ ✠ � ✁ ☞ ✄ ✁ � ✟ ✁ � � � ✟ ✞ ✄ ✞ ✠ ✄ � ✄ � � � ✞ ✄ ✞ ✠ ✁ ✁ ✞ � � ✞ � ✝ Peano’s axioms �✂✁ where

  9. An Introduction to Type Theory – p.13/46 ✄ ✝ ✁ ✞ � � ✞ ✄ ☞ ✟ � ✁ ✁ � � ✟ ✞ ✁ ✂ � � � � ✄ � ✁ ✠ � � ✝ ✝ � ✞ ✁ ✁ ✠ � ✄ � � ✞ ✁ ✂ � ✝ � ✞ � � ✝ ✁ � � ✄ ☞ ✄ ✁ ✟ ✄ ✁ ✁ � � ✟ ✞ ✄ ✞ ✠ ✞ � � � ✝ � ✁ ✠ � ✄ ✞ � � ✞ ✄ ✞ ✠ � ✠ ✁ ✁ � Peano’s axioms �✂✁ where where

  10. Proving decidability An Introduction to Type Theory – p.14/46

  11. ✄ ✞ ✁ ✝ ✝ � ✄ ✄ ✞ � � ✁ ✠ ✝ ☎ ✄ ✞ � ✄ � ✞ ✁ � � ✝ � � � ✞ ✟ � � ✁ ✁ ✟ ✁ ✄ ✄ ☞ ✄ ✄ � � ✁ ✝ ☎ ✝ Proving decidability An Introduction to Type Theory – p.14/46

  12. An Introduction to Type Theory – p.14/46 ✞ ✞ � � ✠ ✝ � ✁ � ✞ ✄ ✠ ✁ � ✄ ✝ ✂ � � ✝ � ✝ ✂ � � ✄ ✁ ✡ ✝ ✝ ✡ ✁ � ✞ ✁ ✂ � ✄ ☞ � ✂ ✁ ✄ � ✂ � � ✝ ✡ � ✂ ✄ � ✠ ☞ ✄ � ✄ ☎ ✝ ✁ � � ✄ ✄ ✄ ✁ ✁ � ✟ ✁ ✁ � � ✟ ✞ � � � ✝ ✞ ✝ � � ✠ ✝ ✝ ✁ ✞ � ✄ � ✞ ✄ ☎ ✝ ✁ ✞ � � ✞ ✄ ✄ � Proving decidability where

  13. Proving decidability An Introduction to Type Theory – p.15/46

  14. ☞ ✠ � ✄ � ✄ ☎ ✝ ✁ � � ✄ ✄ ✝ ✁ � ✟ ✁ ✁ � � ✟ � � ✁ Proving decidability An Introduction to Type Theory – p.15/46

  15. An Introduction to Type Theory – p.15/46 ✝ ✞ ✂ ✁ � ✄ � ✂ � � � � � ✞ ✄ � � ✠ ✝ ✁ � � ✞ ✂ � ✝ � � ✝ ✁ � � � ✠ ✄ ✁ � ✞ � ✠ ✠ � ✝ ✁ ✞ ✄ ✝ � ✞ ✄ � � ✁ ✄ ✠ ✄ ✁ � ✄ � ✄ ☎ ✝ ✁ � � ☞ � ✄ ✁ � ✟ ✁ ✁ � � ✟ � � ✝ ✠ � ✝ ✂ � � ✝ ✁ ✞ ✄ � � � ✠ � ✁ ✠ � ✄ ✝ ✂ � � � � � Proving decidability where

  16. Proof or program ? An Introduction to Type Theory – p.16/46

  17. ✠ � � � ✁ ✁ ✟ ✄ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ An Introduction to Type Theory – p.16/46

  18. � � � ✠ ✁ ✄ ✟ ✁ ✁ � � � ✠ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. An Introduction to Type Theory – p.16/46

  19. � ✄ ✝ ✁ � � � ✠ � ✟ � � ✟ ✁ ✁ � � ✁ � � ✠ ✂ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. If it is then the numbers are equal and proves this. An Introduction to Type Theory – p.16/46

  20. ✂ � � � ✟ � ✂ � ✝ � � ✡ ✡ ✁ � � � ✠ ✟ � ✄ ✄ ✟ ✁ ✁ � � ✁ � � ✠ ✁ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. If it is then the numbers are equal and proves this. If it is then the numbers are not equal and proves this. An Introduction to Type Theory – p.16/46

  21. � ✡ ✄ � � ✂ ✝ ✟ � � ✟ � � ✁ ✡ � ✁ � ✂ ✁ ✠ � � � � � ✁ � ✟ ✠ ✄ ✁ � ✠ � Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. If it is then the numbers are equal and proves this. If it is then the numbers are not equal and proves this. is a program whose specification is in its type. An Introduction to Type Theory – p.16/46

  22. � � ✝ � � ✟ � � ✁ � � ✁ ✂ � ✡ ✠ ✡ ✟ � ✄ ✂ � � ✁ � � � ✠ ✠ � ✄ � ✟ ✁ ✁ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. If it is then the numbers are equal and proves this. If it is then the numbers are not equal and proves this. is a program whose specification is in its type. Equality proofs contain no information, hence they do not have to be calculated at run time . An Introduction to Type Theory – p.16/46

  23. � ✟ � ✂ ✝ � � � ✄ ✠ � ✁ � ✟ � ✂ � ✁ ✁ ✡ ✁ ✠ � � � � � ✁ ✟ � ✠ ✄ � � ✠ � � ✡ Proof or program ? We can use to effectively decide whether two numbers are equal. �✂✁ Reduce to its canonical form. If it is then the numbers are equal and proves this. If it is then the numbers are not equal and proves this. is a program whose specification is in its type. Equality proofs contain no information, hence they do not have to be calculated at run time . Hence is not less efficient than an ordinary program to determine equality of natural numbers. An Introduction to Type Theory – p.16/46

  24. ✟ � ✠ � � � ✁ ✠ ✄ � ✁ ✄ Proof or program ? The same principle can be applied to other problems, e.g. once we have specified �✂✁ An Introduction to Type Theory – p.17/46

  25. � � ✁ ✁ ✟ � ✁ ✄ ☞ ✄ � ✠ � ✁ ✠ ✁ ✝ ☎ ☎ ✄ � ✟ ✁ � ✁ ✝ � � � ✁ ✠ ✟ � ✄ � � ✁ ✄ ✠ ✠ � ✞ � � � Proof or program ? The same principle can be applied to other problems, e.g. once we have specified �✂✁ we can implement a primality checker as An Introduction to Type Theory – p.17/46

  26. � Pattern matching for An Introduction to Type Theory – p.18/46

  27. ✟ � � ✁ ✞ � ✁ ✄ � ✄ ✁ � Pattern matching for If a pattern variable has type we can split the pattern into two, replacing by in the first line and by in the second, where is a fresh variable. �✂✁ An Introduction to Type Theory – p.18/46

  28. ✁ ✁ � ✞ ✄ � ✟ � � � ✞ � ✁ ✄ ✁ � ✁ Pattern matching for If a pattern variable has type we can split the pattern into two, replacing by in the first line and by in the second, where is a fresh variable. �✂✁ Since may appear in the type we have to substitute by and respectively. An Introduction to Type Theory – p.18/46

  29. � ✞ � ✁ ✡ ✁ � ✄ � ✟ � � ✞ � ✁ ✄ ✁ � ✁ Pattern matching for If a pattern variable has type we can split the pattern into two, replacing by in the first line and by in the second, where is a fresh variable. �✂✁ Since may appear in the type we have to substitute by and respectively. We may use the function we are defining recursively on a subpattern, (e.g. above). An Introduction to Type Theory – p.18/46

  30. ✞ ✁ � ✄ � ✞ � � � ✡ � ✁ ✄ ✁ � � ✁ ✁ ✟ Pattern matching for If a pattern variable has type we can split the pattern into two, replacing by in the first line and by in the second, where is a fresh variable. �✂✁ Since may appear in the type we have to substitute by and respectively. We may use the function we are defining recursively on a subpattern, (e.g. above). The precise rules governing structural recursion in the presence of other variables and mutual recursive definitions are more involved. An Introduction to Type Theory – p.18/46

  31. � Pattern matching for An Introduction to Type Theory – p.19/46

  32. ✄ ✝ ✄ � ✟ � ☞ ✁ ✁ � ☎ ✁ ✆ Pattern matching for has the same canonical constant as hence the same rules for pattern matching apply. An Introduction to Type Theory – p.19/46

  33. ✂ ✝ � ✂ ✁ ☎ � � ✁ ✁ � ✆ ✝ ✁ ☎ ✄ � ✁ ☞ � ✟ � ✄ ✂ Pattern matching for has the same canonical constant as hence the same rules for pattern matching apply. Similarily has canonical constants as and hence the same rules for pattern matching apply. An Introduction to Type Theory – p.19/46

  34. ✁ ✄ ✁ ✂ ✄ � ✂ � � ✝ ✂ � � ✁ ☎ � ✠ � ✁ ✄ ✝ ✆ ✁ ☎ ✄ ☎ ✁ ☞ � ✟ � ✄ � Pattern matching for has the same canonical constant as hence the same rules for pattern matching apply. Similarily has canonical constants as and hence the same rules for pattern matching apply. As a consequence of variables ranging �✂✁ over and types may occur in the type and have to be substituted. An Introduction to Type Theory – p.19/46

  35. Elimination constants An Introduction to Type Theory – p.20/46

  36. Elimination constants As a special instance of the pattern matching rules we will derive elimination constants. An Introduction to Type Theory – p.20/46

  37. Elimination constants As a special instance of the pattern matching rules we will derive elimination constants. The principle Equivalence of pattern matching and elimination still holds. An Introduction to Type Theory – p.20/46

  38. Elimination constants As a special instance of the pattern matching rules we will derive elimination constants. The principle Equivalence of pattern matching and elimination still holds. That is every pattern matching proof can be replaced by one only using elimination constants. An Introduction to Type Theory – p.20/46

  39. � Elimination for An Introduction to Type Theory – p.21/46

  40. An Introduction to Type Theory – p.21/46 ✄ ✄ ✞ ✁ ✝ � ✟ ✄ ✂ ✁ ✄ � ✝ � ✁ � ✁ ✂ � ✟ � � � � ✁ ✟ � ✟ � ✁ ✄ � ✄ ✠ ✁ � � � ✂ ✟ � ✁ ✟ ✄ ☞ �✂✁ Elimination for �✂✁ �✂✁

  41. An Introduction to Type Theory – p.21/46 ✂ ✝ ✄ ✄ ✁ ✂ ✁ � � ✁ ✁ ✁ � ✝ ✄ ✄ ✁ ✂ � � ✁ ✟ ✄ ✝ ✁ ✂ ✁ ✁ � ✝ ✄ ✁ ✂ ✂ ✄ ✁ ✂ � ✝ ✁ ✞ ✄ � � � ✟ ✄ ✟ ✁ � ✟ ✂ � � ✁ ✂ ✠ ✄ � ✄ ✁ � ✟ � ☞ � ✁ � ✁ � ✁ � ✝ ✄ ✄ ✁ ✂ ✄ ✟ � ✝ ✁ ✞ ✄ � �✂✁ Elimination for �✂✁ �✂✁ where

  42. One stone, two birds An Introduction to Type Theory – p.22/46

  43. ✂ ✁ ✄ ✄ ✝ � ✁ One stone, two birds Note that unifies two different principles: An Introduction to Type Theory – p.22/46

  44. ✂ ✁ ✄ ✄ ✝ � ✁ � One stone, two birds Note that unifies two different principles: primitive recursion We obtain simply typed primitive recursion if the motive is constant. An Introduction to Type Theory – p.22/46

  45. � ✄ ✂ ✁ ✄ ✄ ✝ � ✁ � ✠ ✄ � ✁ One stone, two birds Note that unifies two different principles: primitive recursion We obtain simply typed primitive recursion if the motive is constant. induction When reading as we obtain the �✂✁ principle of induction. An Introduction to Type Theory – p.22/46

  46. Elimination for An Introduction to Type Theory – p.23/46

  47. An Introduction to Type Theory – p.23/46 ☎ ✆ ✟ ✁ ☞ � ✄ � ✂ � ✆ ✝ � ✟ � ✁ ✟ ✄ ✝ ✂ ✞ ✄ ✝ � ✁ � ✁ � ✟ � � � ✁ � ✝ ✁ ✁ ✟ ✄ ✠ � ✟ ✄ � ☎ ✁ ✝ � ✄ ✠ � ☎ ✝ ✂ � ✄ ☞ � ✟ ☎ � ✟ � �✂✁ Elimination for �✂✁

  48. An Introduction to Type Theory – p.23/46 ✄ ✄ ✁ � ✁ � ✝ ✄ ✞ ✂ ✝ � ✂ � ✟ � ✁ � ✁ � ✝ ✄ ✞ � ✝ � � ✆ ✁ � ✝ ✆ � ✂ � ✄ ✁ ✁ ☎ � ✝ ✄ ✞ ✂ ✝ ✄ ☎ � � ✝ ✂ ✝ ✄ ✝ ☞ � ✟ ☎ � ✟ � ✠ ✄ � ✁ ✁ ☎ � ✄ ✟ � ✠ ✄ ✟ ✁ ✁ � ✄ � ✂ ☎ � ✝ ✆ � ✂ � ✄ � ☞ � ✁ ✟ ✆ � ✟ ✁ ✝ ☎ ✝ ✟ �✂✁ Elimination for �✂✁ where

  49. A little quiz An Introduction to Type Theory – p.24/46

  50. ✄ ✝ ✂ ✞ ✄ ✝ � ✁ A little quiz What is the construct corresponding to in programming? An Introduction to Type Theory – p.24/46

  51. ✂ � ✠ � � � ✂ ✠ ✁ � � ✝ ✄ ✞ ✂ ✝ ✄ � A little quiz What is the construct corresponding to in programming? The type corresponding to is called Unit, written . We didn’t need an elimination constant for , do we need one for ? An Introduction to Type Theory – p.24/46

  52. Elimination for An Introduction to Type Theory – p.25/46

  53. An Introduction to Type Theory – p.25/46 ✆ ✟ ☎ ✄ ✟ � ✝ ✁ ☞ ☎ ✄ � ☞ ☎ ✁ � ✁ ✆ � � � ✟ � ✡ ✁ ✝ ☎ ✄ ✁ ✁ � � ✞ ✟ � � ☞ ✟ ✄ ✠ ✁ ✟ � � ✄ ✠ � ✟ ✄ ✄ ☎ ✟ � ☞ � ✟ ☎ � ✟ ✡ ✠ ✄ � ✝ ☎ ✁ Elimination for �✂✁ �✂✁ �✂✁

  54. An Introduction to Type Theory – p.25/46 � ✡ ✁ � ✝ ✄ ✁ ✁ � ✞ ✟ ☎ ✁ ☞ � ✟ ☎ ✄ ✟ � � ✝ ✄ ✆ ☎ ✡ � ✝ ✆ ✁ ☎ ✡ � ✁ � ✝ ✄ ✁ ✁ � � ✞ � ✆ � � ✁ ☞ � ✟ ☎ ✄ ✄ ✟ ✠ ✝ ✄ � � ✟ ✁ ✠ ✄ ✟ ✁ ☎ � ☞ ☎ ✄ � ☞ ☎ ✁ ✟ ✆ � � ✟ ☎ � ✟ ✡ ✠ ✄ Elimination for �✂✁ �✂✁ �✂✁ where

  55. Alternative: projections An Introduction to Type Theory – p.26/46

  56. ✄ Alternative: projections There is an alternative form of elimination for using projections. An Introduction to Type Theory – p.26/46

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