Skip to content

Bit-burst algorithm version of BigMath.erf and BigMath.erfc#458

Open
tompng wants to merge 1 commit into
ruby:masterfrom
tompng:bigmath_erf_bitburst
Open

Bit-burst algorithm version of BigMath.erf and BigMath.erfc#458
tompng wants to merge 1 commit into
ruby:masterfrom
tompng:bigmath_erf_bitburst

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented Dec 1, 2025

Implement Bit-burst algorithm version of BigMath.erf and BigMath.erfc

Bit-burst algorithm implementation

Repeatedly apply Taylor expansion at increasing x.

  1. Split x into x0 + x1 + x2 + ...
  2. Calculate f(x0) by Taylor expansion(erf) or asymptotic expansion(erfc)
  3. Calculate f(x0 + x1) by Taylor expansion of f at x0
  4. Calculate f(x0 + x1 + x2) by Taylor expansion of f at x0 + x1
  5. So on...

Each Taylor expansion calculation uses binary-splitting method.
Details are described in source code comment.

Benchmark

# Erf of integer

BigMath.erf(10, 10000)
# processing time: 0.324237s → 0.094490s
BigMath.erf(10, 100000)
# processing time: 13.380194s → 1.044322s

# Erf of full-precision number

BigMath.erf(BigDecimal(2).sqrt(10000), 10000)
# processing time: 0.501813s → 0.268420s
BigMath.erf(BigDecimal(2).sqrt(100000), 100000)
# processing time: 21.532002s → 5.708505s

# Erfc of integer

BigMath.erfc(1234, 10000)
# processing time: 0.216168s → 0.094400s
BigMath.erfc(1234, 100000)
# processing time: 19.402288s → 1.258311s

# Erfc of full-precision number

BigMath.erfc(1234 + BigDecimal(4).div(7, 10000), 10000)
# processing time: 4.616296s → 0.219974s
BigMath.erfc(1234 + BigDecimal(4).div(7, 20000), 20000)
# processing time: 23.335180s → 0.572202s
BigMath.erfc(1234 + BigDecimal(4).div(7, 100000), 100000)
# processing time: 1137.080714s → 5.270239s

@tompng tompng force-pushed the bigmath_erf_bitburst branch from 96e40ba to ace2d32 Compare December 2, 2025 15:08
@mrkn mrkn added this to the v4.1 milestone Dec 10, 2025
@tompng tompng force-pushed the bigmath_erf_bitburst branch 2 times, most recently from f60ba6f to ce7f6ab Compare January 30, 2026 17:16
@tompng tompng force-pushed the bigmath_erf_bitburst branch 4 times, most recently from c0f23ef to d035b6e Compare May 8, 2026 19:28
@tompng tompng force-pushed the bigmath_erf_bitburst branch from d035b6e to 2b7d8df Compare May 17, 2026 07:58
@tompng tompng changed the title BigMath.erf/erfc with Bitburst algorithm Bit-burst algorithm version of BigMath.erf and BigMath.erfc May 17, 2026
@tompng tompng marked this pull request as ready for review May 17, 2026 08:45
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.

2 participants