#naturalnumbers #RationalNumbers #RealNumbers #complexnumbers #integers
Enumerating all of the (positive) #RationalNumbers in 10 lines of #Haskell code.
---------------------------------------------
data Rational = Integer :/ Integer
properFraction :: Rational -> (Integer, Rational)
properFraction (a:/ b) = if a < b then (0, (a :/ b)) else (q, (r :/ b))
where (q, r) = a `quotRem` b
calkinwilfSuccessor :: Rational -> Rational
calkinwilfSuccessor rat = b :/ (b*n + b - a) where (n, (a :/ b)) = properFraction rat
rationals :: [Rational]
rationals = iterate calkinwilfSuccessor (1 :/ 1)
---------------------------------------------
This comes from the 2004 functional pearl paper by Gibbons, Lester and Bird. The main component is a formula credited to Moshe Newman for generating the next element in the Calkin-Wilf sequence (the sequence is simply a breadth-first search enumeration of the Calkin-Wilf tree). See also: https://en.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree#Breadth_first_traversal
The Gibbons, Lester, Bird paper contains many other neat pearls involving deforesting trees (Stern-Brocot and Calkin-Wilf trees), the above successor idea, and a continued fraction form which avoids arbitrary-precision integer division (at the cost of a continued fraction representation of the rationals).
Quick note: Generating all rationals using the above is easy. Change to prepend 0, then always produce (𝑥, -𝑥) one after the other with 𝑥 are all positive rationals coming from the above function.
Neulich hab ich ohne besonderen Grund über die reellen Zahlen gegrübelt und ihr Verhältnis zu den rationalen Zahlen. Warum auch immer, ich habe dann die reelle Achse um einen Kreis mit Radius 1/2 gewickelt und mir ist klar geworden, dass keine zwei rationalen Zahlen an derselben Stelle landen. Ist mathematisch im Grunde trivial, aber ich fand's nett. Wer es nochmal ausführlich haben will:
https://miamao.de/blog/2024-02/24.Wickeln_wir_die_reelle_Achse_um_einen_Kreis.html
#math #mathematik #pi #rationalnumbers #rationalezahlen
1/5: "Man, I was trying to reason with pi the other day. Cloud't do it."
1/2: "Oh, you can't reason with pi."
1/5: "How come?"
1/2: "Pi is irrational."
#math #MathJoke #IrrationalNumbers #RationalNumbers #dadjoke #joke
The #Distance Between #Numbers - #Numberphile
https://www.youtube.com/watch?v=Sgupo9DLMGs&ab_channel=Numberphile
#Math #Maths #Mathematics #Numbers #2Adic #2AdicMetric #RationalNumbers #RealNumbers #Limit #Infinity #Converge #Convergence #Diverge #Divergence #RecreationalMaths #RecreationalMathematics #Axiom #Axioms #Axiomatic
A lovely post on Dirichlet’s approximation theorem, which allows you to approximate irrational number with rational numbers with small denominators with guarantees on how close the irrational number is the approximation.
https://www.quantamagazine.org/how-rational-math-catches-slippery-irrational-numbers-20200310/
#Mathematics #Numbers #RationalNumbers #IrrationalNumbers #NumericalApproximations