Ask Your Question

Revision history [back]

This is to complement the excellent answers by @dan_fulea and @B_r_u_n_o.

Sage can call Arb via ComplexBallField and RealBallField.

This allows to get a certified ball around the result.

Taking inspiration from @dan_fulea's answer, we use erfc.

Function taking two endpoints and optionally the precision to use, and returning the desired integral:

def my_phi(a, b, nbits=64):
    B = ComplexBallField(nbits)
    r = ~AA(2).sqrt()
    return ((B(a)*r).erfc() - (B(b)*r).erfc())/2

Example with the default precision:

sage: my_phi(255.5, 266.5)
[5.852432002306e-14179 +/- 3.98e-14192]

Example with increased precision:

sage: my_phi(255.5, 266.5, nbits=128)
[5.85243200230564413535455781902691e-14179 +/- 4.65e-14212]

Note about erfc and RealBallField.

So far (currently Sage 9.2.beta14), RealBallField elements have no erfc method, so we can't use that.

def my_phi(a, b, nbits=64):
    B = RealBallField(nbits)
    r = ~AA(2).sqrt()
    return ((B(a)*r).erfc() - (B(b)*r).erfc())/2

Example:

sage: my_phi(255.5, 266.5)
Traceback (most recent call last)
...
AttributeError: 'sage.rings.real_arb.RealBall' object has no attribute 'erfc'