Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ok-landscape
GitHub Repository: Ok-landscape/computational-pipeline
Path: blob/main/notebooks/published/continued_fractions/continued_fractions_posts.txt
51 views
unlisted
1
# Social Media Posts: Continued Fractions
2
# Generated from: continued_fractions.ipynb
3
4
================================================================================
5
## TWITTER/X (< 280 chars)
6
================================================================================
7
8
Continued 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.
9
10
#Math #Python #NumberTheory #Science
11
12
================================================================================
13
## BLUESKY (< 300 chars)
14
================================================================================
15
16
Explored continued fractions today - a beautiful way to represent real numbers that reveals their arithmetic structure.
17
18
The golden ratio φ = [1; 1, 1, 1...] is the "most irrational" number because it has the slowest-converging continued fraction.
19
20
#Mathematics #Python #Science
21
22
================================================================================
23
## THREADS (< 500 chars)
24
================================================================================
25
26
Just coded up continued fractions in Python and wow, they're elegant!
27
28
Instead of decimals, you write numbers as nested fractions:
29
π = 3 + 1/(7 + 1/(15 + 1/(1 + ...)))
30
31
The magic? Truncating at any point gives the BEST possible fraction approximation.
32
33
355/113 approximates π to 6 decimal places - Chinese mathematician Zu Chongzhi discovered this in the 5th century!
34
35
Also learned: √2 = [1; 2, 2, 2...] - quadratic irrationals always have repeating patterns.
36
37
#Math #Python #Science
38
39
================================================================================
40
## MASTODON (< 500 chars)
41
================================================================================
42
43
Implemented continued fraction algorithms in Python today.
44
45
Key insight: convergents pₙ/qₙ satisfy
46
pₙ = aₙ·pₙ₋₁ + pₙ₋₂
47
qₙ = aₙ·qₙ₋₁ + qₙ₋₂
48
49
These give optimal rational approximations: |x - pₙ/qₙ| < 1/(qₙ·qₙ₊₁)
50
51
Notable examples:
52
• φ = [1; 1, 1, 1...] (slowest convergence)
53
• e = [2; 1, 2, 1, 1, 4, 1, 1, 6...]
54
• √2 = [1; 2, 2, 2...] (periodic!)
55
56
Lagrange's theorem: periodic CF ⟺ quadratic irrational
57
58
#Mathematics #Python #NumberTheory
59
60
================================================================================
61
## REDDIT (Title + Body for r/learnpython or r/math)
62
================================================================================
63
64
**Title:** I wrote Python code to explore continued fractions - here's why 355/113 is such a great approximation for π
65
66
**Body:**
67
68
I've been learning about continued fractions and implemented the algorithms in Python. Wanted to share what I learned!
69
70
**What are continued fractions?**
71
72
Instead of writing π as 3.14159..., you can write it as:
73
74
π = 3 + 1/(7 + 1/(15 + 1/(1 + 1/(292 + ...))))
75
76
Or in compact notation: π = [3; 7, 15, 1, 292, ...]
77
78
**Why are they useful?**
79
80
The magic is that if you truncate at any point, you get the BEST possible rational approximation for denominators up to that size:
81
82
- [3] = 3/1
83
- [3; 7] = 22/7 (the classic approximation!)
84
- [3; 7, 15] = 333/106
85
- [3; 7, 15, 1] = 355/113 ← accurate to 6 decimal places!
86
87
The convergent 355/113 was discovered by Chinese mathematician Zu Chongzhi in the 5th century. It gives π ≈ 3.14159292..., incredibly close to the true value.
88
89
**Cool patterns I found:**
90
91
- Golden ratio φ = [1; 1, 1, 1...] - has the slowest convergence, making it the "most irrational" number
92
- √2 = [1; 2, 2, 2...] - repeating pattern!
93
- √3 = [1; 1, 2, 1, 2...] - period 2
94
95
Lagrange proved that a number has a periodic continued fraction if and only if it's a quadratic irrational (root of ax² + bx + c = 0).
96
97
**The code:**
98
99
The algorithm is elegant - just repeatedly take the integer part and invert the fractional part:
100
101
```python
102
def to_continued_fraction(x, max_terms=20):
103
cf = []
104
for _ in range(max_terms):
105
a = int(np.floor(x))
106
cf.append(a)
107
frac = x - a
108
if abs(frac) < 1e-10:
109
break
110
x = 1.0 / frac
111
return cf
112
```
113
114
View the full interactive notebook with convergence plots here:
115
https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb
116
117
================================================================================
118
## FACEBOOK (< 500 chars)
119
================================================================================
120
121
Ever wonder why 22/7 is used to approximate π?
122
123
It comes from continued fractions - a beautiful way to represent numbers as nested fractions that reveals their hidden structure!
124
125
Even better: 355/113 gives π accurate to 6 decimals. A Chinese mathematician discovered this 1500 years ago!
126
127
I coded this up in Python and made some cool visualizations showing how the approximations converge.
128
129
Check out the interactive notebook:
130
https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb
131
132
================================================================================
133
## LINKEDIN (< 1000 chars)
134
================================================================================
135
136
Exploring Computational Number Theory: Continued Fractions
137
138
I recently implemented continued fraction algorithms in Python to study how they provide optimal rational approximations to real numbers.
139
140
Key technical insights:
141
142
• Convergent computation uses a simple recurrence relation, making it computationally efficient
143
• The error bound |x - pₙ/qₙ| < 1/(qₙ·qₙ₊₁) guarantees rapid convergence
144
• Lagrange's theorem provides a complete characterization: periodic continued fractions correspond exactly to quadratic irrationals
145
146
Practical applications include:
147
- Gear ratio optimization in mechanical engineering
148
- Calendar calculations (leap year algorithms)
149
- Cryptographic key generation
150
- Signal processing (rational function approximation)
151
152
The 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.
153
154
Skills demonstrated: NumPy, Matplotlib, algorithmic implementation, mathematical analysis
155
156
View the full analysis:
157
https://cocalc.com/github/Ok-landscape/computational-pipeline/blob/main/notebooks/published/continued_fractions.ipynb
158
159
#Python #Mathematics #DataScience #NumericalComputing #ComputationalScience
160
161
================================================================================
162
## INSTAGRAM (< 500 chars, visual-focused)
163
================================================================================
164
165
The beauty of continued fractions visualized
166
167
These plots show how fractions approximate irrational numbers - and the patterns are stunning.
168
169
The golden ratio (φ) converges slowest because its continued fraction is all 1s: [1; 1, 1, 1...]
170
171
This makes it the "most irrational" number mathematically speaking!
172
173
Meanwhile π = [3; 7, 15, 1, 292...]
174
That 292 is why 355/113 is SO accurate
175
176
Math is beautiful when you can see it
177
178
#mathematics #dataviz #python #numbertheory #mathart #coding #science #visualization
179
180