Path: blob/main/notebooks/published/continued_fractions/continued_fractions_posts.txt
51 views
unlisted
# Social Media Posts: Continued Fractions1# Generated from: continued_fractions.ipynb23================================================================================4## TWITTER/X (< 280 chars)5================================================================================67Continued fractions reveal the hidden structure of numbers! π = [3; 7, 15, 1, 292...] gives us 355/113 - accurate to 6 decimals, known since the 5th century.89#Math #Python #NumberTheory #Science1011================================================================================12## BLUESKY (< 300 chars)13================================================================================1415Explored continued fractions today - a beautiful way to represent real numbers that reveals their arithmetic structure.1617The golden ratio φ = [1; 1, 1, 1...] is the "most irrational" number because it has the slowest-converging continued fraction.1819#Mathematics #Python #Science2021================================================================================22## THREADS (< 500 chars)23================================================================================2425Just coded up continued fractions in Python and wow, they're elegant!2627Instead of decimals, you write numbers as nested fractions:28π = 3 + 1/(7 + 1/(15 + 1/(1 + ...)))2930The magic? Truncating at any point gives the BEST possible fraction approximation.3132355/113 approximates π to 6 decimal places - Chinese mathematician Zu Chongzhi discovered this in the 5th century!3334Also learned: √2 = [1; 2, 2, 2...] - quadratic irrationals always have repeating patterns.3536#Math #Python #Science3738================================================================================39## MASTODON (< 500 chars)40================================================================================4142Implemented continued fraction algorithms in Python today.4344Key insight: convergents pₙ/qₙ satisfy45pₙ = aₙ·pₙ₋₁ + pₙ₋₂46qₙ = aₙ·qₙ₋₁ + qₙ₋₂4748These give optimal rational approximations: |x - pₙ/qₙ| < 1/(qₙ·qₙ₊₁)4950Notable examples:51• φ = [1; 1, 1, 1...] (slowest convergence)52• e = [2; 1, 2, 1, 1, 4, 1, 1, 6...]53• √2 = [1; 2, 2, 2...] (periodic!)5455Lagrange's theorem: periodic CF ⟺ quadratic irrational5657#Mathematics #Python #NumberTheory5859================================================================================60## REDDIT (Title + Body for r/learnpython or r/math)61================================================================================6263**Title:** I wrote Python code to explore continued fractions - here's why 355/113 is such a great approximation for π6465**Body:**6667I've been learning about continued fractions and implemented the algorithms in Python. Wanted to share what I learned!6869**What are continued fractions?**7071Instead of writing π as 3.14159..., you can write it as:7273π = 3 + 1/(7 + 1/(15 + 1/(1 + 1/(292 + ...))))7475Or in compact notation: π = [3; 7, 15, 1, 292, ...]7677**Why are they useful?**7879The magic is that if you truncate at any point, you get the BEST possible rational approximation for denominators up to that size:8081- [3] = 3/182- [3; 7] = 22/7 (the classic approximation!)83- [3; 7, 15] = 333/10684- [3; 7, 15, 1] = 355/113 ← accurate to 6 decimal places!8586The convergent 355/113 was discovered by Chinese mathematician Zu Chongzhi in the 5th century. It gives π ≈ 3.14159292..., incredibly close to the true value.8788**Cool patterns I found:**8990- Golden ratio φ = [1; 1, 1, 1...] - has the slowest convergence, making it the "most irrational" number91- √2 = [1; 2, 2, 2...] - repeating pattern!92- √3 = [1; 1, 2, 1, 2...] - period 29394Lagrange proved that a number has a periodic continued fraction if and only if it's a quadratic irrational (root of ax² + bx + c = 0).9596**The code:**9798The algorithm is elegant - just repeatedly take the integer part and invert the fractional part:99100```python101def to_continued_fraction(x, max_terms=20):102cf = []103for _ in range(max_terms):104a = int(np.floor(x))105cf.append(a)106frac = x - a107if abs(frac) < 1e-10:108break109x = 1.0 / frac110return cf111```112113View the full interactive notebook with convergence plots here:114https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb115116================================================================================117## FACEBOOK (< 500 chars)118================================================================================119120Ever wonder why 22/7 is used to approximate π?121122It comes from continued fractions - a beautiful way to represent numbers as nested fractions that reveals their hidden structure!123124Even better: 355/113 gives π accurate to 6 decimals. A Chinese mathematician discovered this 1500 years ago!125126I coded this up in Python and made some cool visualizations showing how the approximations converge.127128Check out the interactive notebook:129https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb130131================================================================================132## LINKEDIN (< 1000 chars)133================================================================================134135Exploring Computational Number Theory: Continued Fractions136137I recently implemented continued fraction algorithms in Python to study how they provide optimal rational approximations to real numbers.138139Key technical insights:140141• Convergent computation uses a simple recurrence relation, making it computationally efficient142• The error bound |x - pₙ/qₙ| < 1/(qₙ·qₙ₊₁) guarantees rapid convergence143• Lagrange's theorem provides a complete characterization: periodic continued fractions correspond exactly to quadratic irrationals144145Practical applications include:146- Gear ratio optimization in mechanical engineering147- Calendar calculations (leap year algorithms)148- Cryptographic key generation149- Signal processing (rational function approximation)150151The visualization shows convergence rates for π, e, √2, and the golden ratio φ. Notable finding: φ = [1; 1, 1, 1...] has the slowest convergence among all irrationals, making it extremal in Diophantine approximation theory.152153Skills demonstrated: NumPy, Matplotlib, algorithmic implementation, mathematical analysis154155View the full analysis:156https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb157158#Python #Mathematics #DataScience #NumericalComputing #ComputationalScience159160================================================================================161## INSTAGRAM (< 500 chars, visual-focused)162================================================================================163164The beauty of continued fractions visualized165166These plots show how fractions approximate irrational numbers - and the patterns are stunning.167168The golden ratio (φ) converges slowest because its continued fraction is all 1s: [1; 1, 1, 1...]169170This makes it the "most irrational" number mathematically speaking!171172Meanwhile π = [3; 7, 15, 1, 292...]173That 292 is why 355/113 is SO accurate174175Math is beautiful when you can see it176177#mathematics #dataviz #python #numbertheory #mathart #coding #science #visualization178179180