a tale of theories and data structures
play

A tale of theories and data-structures Jacques Carette, Musa - PowerPoint PPT Presentation

A tale of theories and data-structures Jacques Carette, Musa Al-hassy, Wolfram Kahl McMaster University, Hamilton June 4, 2018 Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 1 / 15 Lists and Monoids


  1. A tale of theories and data-structures Jacques Carette, Musa Al-hassy, Wolfram Kahl McMaster University, Hamilton June 4, 2018 Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 1 / 15

  2. Lists and Monoids Claim A List is a Free Monoid What does that really mean? Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 2 / 15

  3. Lists and Monoids Claim A List is a Free Monoid What does that really mean? Fancy explanation: The functor from the category Types of types and function, with List as its object mapping and map for homomorphism, to the category Monoid of monoids and monoid homomorphisms, is left adjoint to the forgetful functor (from Monoid to Types ). Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 2 / 15

  4. Lists and Monoids Claim A List is a Free Monoid What does that really mean? Fancy explanation: The functor from the category Types of types and function, with List as its object mapping and map for homomorphism, to the category Monoid of monoids and monoid homomorphisms, is left adjoint to the forgetful functor (from Monoid to Types ). List (equipped with constructors [] , :: and functions map , ++ , singleton , and foldr ) is the language of monoids. In other words, List is the canonical term syntax for computing with monoids. Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 2 / 15

  5. Lists and Monoids Claim A List is a Free Monoid What does that really mean? Fancy explanation: The functor from the category Types of types and function, with List as its object mapping and map for homomorphism, to the category Monoid of monoids and monoid homomorphisms, is left adjoint to the forgetful functor (from Monoid to Types ). List (equipped with constructors [] , :: and functions map , ++ , singleton , and foldr ) is the language of monoids. In other words, List is the canonical term syntax for computing with monoids. Why on earth would we care about that? Let’s see! Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 2 / 15

  6. Non-categorical version The requirements roughly translate to Monoid: Need a container C of α with a distinguished container e devoid of α ’s a binary operation ∗ that puts two containers together such that e is a left/right unit for ∗ . Functor: A way to apply a ( α → β ) function to a C α to get a C β which “plays well” with id , ◦ , ≡ and ∗ . Adjunction: An operation singleton embedding an α as a container C α an operation foldr (over arbitrary Monoid) such that both operations “play well” with each other. Extremely handy: Induction principle Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 3 / 15

  7. The plot thickens Given an arbitrary type A : CoFree Theory Free Structure Carrier Identity A Identity A Pointed Maybe A – Unary Eventually A , N × A ? Involutive A ⊎ A A × A Magma Tree A ? Semigroup NEList A ? Monoid List A ? Left Unital Semigroup List A × N ? Right Unital Semigroup N × List A ? Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 4 / 15

  8. The plot thickens Given an arbitrary type A : CoFree Theory Free Structure Carrier Identity A Identity A Pointed Maybe A – Unary Eventually A , N × A ? Involutive A ⊎ A A × A Magma Tree A ? Semigroup NEList A ? Monoid List A ? Left Unital Semigroup List A × N ? Right Unital Semigroup N × List A ? What is the Free Structure? It is “the” term language in normal form associated to the theory. Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 4 / 15

  9. Benefits Benefits of the formal approach: Obvious: Dispell silly conjectures/errors Discover some neat relationships between algebraic theories and data-structures fold (aka the counit) Induction Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 5 / 15

  10. Benefits Benefits of the formal approach: Obvious: Dispell silly conjectures/errors Discover some neat relationships between algebraic theories and data-structures fold (aka the counit) Induction Examples: counit for Unary, Involutive Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 5 / 15

  11. Extending the tale Given an arbitrary type A : Theory Free Structure Carrier Identity A Pointed Maybe A Unary N × A Involutive A ⊎ A Magma Tree A Semigroup NEList A Monoid List A Left Unital Semigroup List A × N Right Unital Semigroup N × List A Commutative Monoid ? Group ? Abelian Group ? Idempotent Comm. Monoid ? Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 6 / 15

  12. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  13. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  14. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  15. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  16. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  17. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  18. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  19. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . ◮ Summing over all elements of A is even harder . . . Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  20. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . ◮ Summing over all elements of A is even harder . . . ◮ Can build a decidable equiv. relation on A from A → N ! Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  21. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . ◮ Summing over all elements of A is even harder . . . ◮ Can build a decidable equiv. relation on A from A → N ! List A up to bag-equality (aka permutations) Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  22. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . ◮ Summing over all elements of A is even harder . . . ◮ Can build a decidable equiv. relation on A from A → N ! List A up to bag-equality (aka permutations) ◮ almost works! Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

  23. Commutative Monoid and Bag Definition A Bag (over a type A) is an unordered finite collection of x where x : A . Implementation? Inductive type ◮ Ordered! A → N ◮ No finite support! A → N plus finite support ◮ “Finite support” is hard to say constructively . . . ◮ Summing over all elements of A is even harder . . . ◮ Can build a decidable equiv. relation on A from A → N ! List A up to bag-equality (aka permutations) ◮ almost works! ◮ Commutative Monoid uses ≡ Carette, Al-hassy, Kahl (McMaster) A tale of theories and data-structures June 4, 2018 7 / 15

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