המספר האמיתי אורכו אינסופי ולא ניתן להצגה כשבר כלשהו אבל ניתן לבניה ככל מיני סדרות שונות ומשונות. תורת ההסתברות מוכיחה כי בכל מספר אי-רציונלי נורמלי, כל רצף סופי של ספרות חייב להופיע. לא ידוע אם π (פאי) הוא מספר נורמלי. מספר נורמלי הוא מספר ממשי אי-רציונלי שבו, בבסיס מסוים (כמו בסיס 10), כל ספרה מופיעה בתדירות שווה בטווח הארוך, וכל רצף אפשרי של ספרות מופיע בהסתברות הצפויה. למרות שהמספר π נחקר רבות וחושב עד טריליוני ספרות, אין הוכחה לכך שהוא נורמלי באף בסיס. עם זאת, ניתוחים סטטיסטיים של הספרות הידועות שלו מצביעים על כך שהן מתנהגות כאילו π הוא מספר נורמלי, אך זו אינה הוכחה. רבים מהמתמטיקאים משערים ש-π הוא מספר נורמלי, אך הוכחה לכך נותרה בעיה פתוחה בתורת המספרים.
הפיזיקאי ריצרד פיינמן הביע פעם משאלה לזכור בעל פה את 767 הספרות הראשונות של פאי אחרי הנקודה. הסיבה היא ש-שש הספרות האחרונות ברצף הן תשע וזה די מרשים לסיים כך את ההקראה: " אחד אחד שלוש ארבע תשע תשע תשע תשע תשע תשע!" ולרדת מהבמה לקול תשואות הקהל. בכל מקרה גם רצף של 1000 תשיעיות יהיה קיים איפשהו במספר.
הרחבות, סקריפטים, נוסחאות מסובכות ובינה מלאכותית
import itertools
def pi_digits():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4 * q + r - t < n * t:
yield n
nr = 10 * (r - n * t)
n = (10 * (3 * q + r)) // t - 10 * n
q *= 10
r = nr
else:
nr = (2 * q + r) * l
nn = (q * (7 * k + 2) + r * l) // (t * l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
if __name__ == "__main__":
for digit in pi_digits(): # Runs forever until manually stopped
The Chudnovsky Algorithm for Computing π
The Chudnovsky algorithm is one of the most efficient methods for calculating π to high precision. Developed by the Chudnovsky brothers (David and Gregory) in the late 1980s, it's remarkable for its efficiency and is still used today for record-breaking π calculations.
The Formula
The algorithm is based on the following series representation of 1/π:
Where C = 426880√10005
When implemented, the formula is typically rewritten as:
Why It's So Efficient
The Chudnovsky algorithm has several key advantages:
-
Rapid Convergence: Each term of the series gives approximately 14 additional decimal digits of π.
-
Binary Splitting: The algorithm can be implemented using binary splitting, a technique that accelerates the computation of large factorial terms.
-
Linear Complexity: The algorithm has approximately linear complexity when computing n digits of π, meaning doubling the digits roughly doubles the computation time.
Historical Impact
This algorithm has been used for virtually all recent π-computation records. For example:
- In 2019, Emma Haruka Iwao used it with Google Cloud to calculate π to 31.4 trillion digits
- In 2021, researchers used it to calculate π to 62.8 trillion digits
In the Code
In the code I provided, I included both the traditional Chudnovsky implementation and a simpler arctangent-based approach. The traditional Chudnovsky algorithm is more complex to implement correctly because:
- It requires efficient factorial calculations for large numbers
- It needs specialized techniques for managing the precision of intermediate calculations
- The binary splitting optimization requires careful implementation
The arctangent formula I used instead (π = 16·arctan(1/5) - 4·arctan(1/239)) is simpler to implement but converges more slowly. For truly high-precision calculations (trillions of digits), the properly optimized Chudnovsky algorithm would be the preferred choice.