Created
September 16, 2019 20:01
-
-
Save Sintrastes/d353af006ce6a897efb8c8b97e3cebb2 to your computer and use it in GitHub Desktop.
An implementation of the Calkin-Wilf sequence in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- An implementation of the Calkin-Wilf sequence in Haskell -- gives a bijection between the natural numbers | |
-- and the (positive) rationals. | |
-- | |
-- See https://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree for more info | |
-- | |
import Data.Ratio | |
calkinWilfNext q = 1 / (2 * ( (floor q) % 1 ) - q + 1) | |
calkinWilfSequence = iterate calkinWilfNext (1%1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment