Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercises on catamorphisms #21

Open
benediktahrens opened this issue Jun 5, 2022 · 0 comments
Open

Exercises on catamorphisms #21

benediktahrens opened this issue Jun 5, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@benediktahrens
Copy link
Owner

Exercises suggested by @arnoudvanderleer - thanks a lot!

An exercise about representing functions as catamorphisms (or rewriting functions using fold):

  • We can represent numbers as big-endian binary numbers, in the set List({0, 1}): the lists with elements in the set {0, 1}. (For example, 13 becomes 1101, which becomes (cons 1 (cons 1 (cons 0 (cons 1 nil))))). Show that we can give the function bin2int: List({0, 1}) -> N, that converts big-endian binary representations to positive integers, as a catamorphism. For example, (bin2int (cons 1 (cons 0 nil))) = 2 and (bin2int (cons 1 (cons 1 (cons 0 (cons 1 nil))))) = 13). i.e. with F the functor for which List({0, 1}) is an initial algebra, show that there exists an F-algebra (N, f) such that (| f |) = bin2int.
  • We can also represent a number as a little-endian binary number. Then 13 becomes 1011, which becomes (cons 1 (cons 0 (cons 1 (cons 1 nil))))). Why can't we represent the function bin2int2: List({0, 1}) -> N, that converts little-endian binary representations back to positive integers, as a catamorphism?
  • Show that there exists an F-algebra (N x N, f) such that pr1 ∘ (| f |) is our function bin2int2, for (| f |) the catamorphism induced by f, and with pr1 the projection on the first coordinate. I.e. show that there exists some function g: List({0, 1}) -> N x N that is a catamorphism, and when restricted to the first coordinate gives our function bin2int2.
@benediktahrens benediktahrens added enhancement New feature or request good first issue Good for newcomers labels Jun 5, 2022
benediktahrens added a commit that referenced this issue Jun 12, 2022
Add an exercise on the limitations of catamorphisms. Solves #21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant