Skip to content

Implement BigMath.erf(x, prec) and BigMath.erfc(x, prec) #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented Jun 21, 2025

Followup of #336

erf(x, prec)

Uses taylor series of exp(x**2)*erf(x).
Precision management is easier than normal taylor series of erf(x).

# Sign of the coefficients switches. Considering loss of significance, extra high precision is required.
erf(x) = (2/√π) * (x - x**3/3 + x**5/10 - x**7/42 + x**9/216 - ...)
# Coefficients are all positive. Need to do just what BigMath.exp(x) does.
erf(x) = (2/√π) * exp(-x**2) * (x + 2*x**3/3 + 4*x**5/15 + 8*x**7/105 + 16*x**9/945 + ...)

erfc(x, prec)

BigMath.erfc(BigDecimal(100), 10) #=> 0.64059614249217320390213389e-4345

Calculating this with 1 - erf(x, prec + extra_digits) need extra 4345 precision of erf(x). The convergence is very slow.
To calculate faster, first try asymptotic expansion and fallback to 1 - erf(x, prec + extra_digits)

erf(x) uses taylor series
erfc(x) uses asymptotic expansion if possible and fallback to 1-erf(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant