tinycodinglm / ai /ai-0017.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame Contribute Delete
7.89 kB
my-agent trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

Task: summarize user's text

User

Yes. There is a genuine higher-convergence alternative to Chudnovsky.
The Berndt–Chan (m=3315) Ramanujan-type series gives about 75.3178 decimal digits per term, versus about 14.1816 digits/term for Chudnovsky, so it needs about 5.31× fewer terms for the same number of digits.
A later Campbell preprint extends this family to about 153.8732 digits/term, but that construction is substantially more complicated. (arXiv)
That does not automatically mean it is 5× faster in wall-clock time. Chudnovsky's binary splitting and highly optimized multiplication are extremely effective, which is why record computations still use it. The latest y-cruncher record listed through 2025 was computed with its Chudnovsky machinery. (Number World)
Also: Gauss–Legendre / Brent–Salamin is much faster in convergence per iteration than Chudnovsky, but there is an important catch: an iteration becomes substantially more expensive as the precision grows.
The algorithm is
$$
a_0=1,\qquad
b_0=\frac1{\sqrt2},\qquad
t_0=\frac14,\qquad
p_0=1,
$$
and
$$
a_{n+1}=\frac{a_n+b_n}{2},
$$
$$
b_{n+1}=\sqrt{a_nb_n},
$$
$$
t_{n+1}=t_n-p_n(a_n-a_{n+1})^2,
$$
$$
p_{n+1}=2p_n.
$$
Then
$$
\boxed{
\pi=\lim_{n\to\infty}
\frac{(a_n+b_n)^2}{4t_n}
}
$$
and it has quadratic convergence. (MathWorld)
### Why it looks ridiculously fast
The AGM satisfies
$$
a_{n+1}-b_{n+1}
=O!\left((a_n-b_n)^2\right),
$$
so the error essentially squares every iteration.
Thus, roughly,
$$
D_{n+1}\approx 2D_n,
$$
where (D_n) is the number of correct decimal digits.
For example, the first few approximations are
$$
3.1405792505221686\ldots
$$
$$
3.141592646213543\ldots
$$
$$
3.141592653589794\ldots
$$
so only a handful of iterations already reaches ordinary floating-point precision.

A useful proof of the quadratic convergence

Put
$$
c_n=\frac{a_n-b_n}{2}.
$$
Since
$$
a_{n+1}=\frac{a_n+b_n}{2},
\qquad
b_{n+1}=\sqrt{a_nb_n},
$$
we have
$$
a_{n+1}^2-b_{n+1}^2

\left(\frac{a_n+b_n}{2}\right)^2-a_nb_n

\frac{(a_n-b_n)^2}{4}
=c_n^2.
$$
Therefore
$$
a_{n+1}-b_{n+1}

\frac{c_n^2}{a_{n+1}+b_{n+1}}.
$$
Since (a_n,b_n\to M), where
$$
M=\operatorname{AGM}
\left(1,\frac1{\sqrt2}\right),
$$
we obtain asymptotically
$$
a_{n+1}-b_{n+1}
\sim
\frac{(a_n-b_n)^2}{8M}.
$$
Hence
$$
\boxed{
|a_{n+1}-b_{n+1}|

O(|a_n-b_n|^2)
}
$$
which is quadratic convergence.
The Brent–Salamin identity then gives
$$
\boxed{
\pi

\frac{4M^2}
{1-\displaystyle\sum_{j=1}^{\infty}2^{j+1}c_j^2}
}
$$
with
$$
M=\operatorname{AGM}
\left(1,\frac1{\sqrt2}\right).
$$
This is equivalent to the (t_n) formulation above. (MathWorld)

But is it actually faster than Chudnovsky?

For moderate precision, AGM is extremely attractive.
For huge precision, not necessarily.

Algorithm Convergence Main expensive operation
Chudnovsky ~14.18 decimal digits/term Large integer multiplication
Gauss–Legendre quadratic, roughly doubles digits/iteration High-precision square root
Borwein quartic quartic Several high-precision operations
Borwein quintic quintic More complicated high-precision operations
The amusing part is that Chudnovsky has terrible-looking convergence by iteration count but excellent computational structure. Binary splitting turns its series into large integer arithmetic that modern multiplication algorithms handle extremely well.
So:
$$
\boxed{\text{fewer iterations} \neq \text{faster computation}}
$$
which is one of those irritating cases where asymptotic convergence politely refuses to tell you the whole story.
For example, to obtain (10^6) digits, Gauss–Legendre only needs on the order of
$$
\log_2(10^6)\approx 20
$$
iterations, but those iterations involve million-digit square roots. Chudnovsky needs roughly
$$
\frac{10^6}{14.18}\approx 70,500
$$
series terms, but binary splitting makes those terms dramatically cheaper to aggregate.
For very large record computations, Chudnovsky-style binary splitting therefore remains highly competitive despite its lower convergence order.

One important terminology point

The Gauss–Legendre algorithm for (\pi) is not the same thing as Gauss–Legendre quadrature. Here "Gauss–Legendre" refers to the AGM-based π algorithm, also called the Brent–Salamin algorithm. (MathWorld)
And if the actual goal is "find something genuinely better than Chudnovsky for arbitrary huge precision", then the interesting direction is not Gauss–Legendre. It is the quartic/quintic/high-order Borwein algorithms, or the more recent higher-order modular identities. (MathWorld)

Assistant

Summary

  • Berndt–Chan (m=3315) is a genuine higher-convergence π series:

    • ~75.32 digits/term
    • Chudnovsky: ~14.18 digits/term
    • Therefore ~5.3× fewer terms theoretically.
  • A later Campbell construction reaches ~153.87 digits/term, but is considerably more complicated.

  • Fewer terms does not mean faster overall. Chudnovsky's binary splitting makes its terms exceptionally efficient to aggregate, which is why it remains dominant for huge computations.

Gauss–Legendre / Brent–Salamin

It uses the AGM:

$$
a_{n+1}=\frac{a_n+b_n}{2},\qquad
b_{n+1}=\sqrt{a_nb_n}
$$

with corresponding (t_n,p_n), then

$$
\pi=\lim_{n\to\infty}\frac{(a_n+b_n)^2}{4t_n}.
$$

Its convergence is quadratic, meaning the number of correct digits roughly doubles every iteration.

The key proof is:

$$
a_{n+1}^2-b_{n+1}^2
=\frac{(a_n-b_n)^2}{4},
$$

so

$$
a_{n+1}-b_{n+1}

\frac{(a_n-b_n)^2}
{4(a_{n+1}+b_{n+1})}
=O((a_n-b_n)^2).
$$

Thus the error is squared each iteration.

The catch

At high precision, each AGM iteration requires expensive high-precision square roots.

So roughly:

Algorithm Convergence Main cost
Chudnovsky ~14.18 digits/term Integer multiplication
Gauss–Legendre Quadratic High-precision square root
Borwein quartic Quartic Several high-precision operations
Borwein quintic Quintic More complicated operations

For (10^6) digits:

  • Gauss–Legendre: only about 20 iterations
  • Chudnovsky: about 70,500 terms

But those 20 AGM iterations operate on million-digit numbers, while Chudnovsky's binary splitting + fast multiplication makes its huge term count computationally efficient.

Bottom line

$$
\boxed{\text{Convergence rate} \neq \text{real-world speed}}
$$

For arbitrary huge precision, the more interesting candidates beyond Chudnovsky are Borwein quartic/quintic methods and newer higher-order modular identities, rather than simply Gauss–Legendre.