Ask Your Question
1

erfc for arbitrary precision real field

asked 2020-07-17 13:22:20 +0200

WhatsUp gravatar image

The following code raised a runtime error:

R = RealField(500)
print(erfc(R(28.0)))

Output:

/home/sc_serv/sage/local/lib/python3.7/site-packages/sage/rings/real_mpfr.pyx in sage.rings.real_mpfr.RealNumber.erfc (build/cythonized/sage/rings/real_mpfr.c:31648)()
   5047         """
   5048         cdef RealNumber x = self._new()
-> 5049         sig_on()
   5050         mpfr_erfc(x.value, self.value, (<RealField_class>self._parent).rnd)
   5051         sig_off()

RuntimeError: Aborted

However, it would work if the RealField is removed:

print(erfc(28.0))

Output:

6.56321584032878e-343

Is there a way to make erfc work also for arbitrary precision real fields?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-07-17 22:39:22 +0200

jaydfox gravatar image

updated 2020-07-17 22:47:27 +0200

The issue is not the RealField. The issue seems to have something to do with the precision. 28.0 is simply a RealNumber with the default precision of 53 bits. Here are my results for various precisions:

sage: erfc(RealField(53)(28))
6.56321584032878e-343
sage: erfc(RealField(64)(28))
6.56321584032878415e-343
sage: erfc(RealField(128)(28))
6.5632158403287841523809104816062747741e-343
sage: erfc(RealField(192)(28))
6.56321584032878415238091048160627477413416268994828261802e-343
sage: erfc(RealField(256)(28))
uceil_log2.c:40: MPFR assertion failed: exp < 1023
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

The real error is the "MPRF assertion failed: exp < 1023". This probably has something to do with the C implementation of mpfr_erfc, which is a third party library. I.e., it is used by SAGE, but it was not written by the SAGE team. I believe the MPFR library is still actively maintained, so maybe the SAGE team can reach out to the MPFR developers?

Edit: By the way, if you want to test with a standard double precision floating point number, put a letter 'r' after the number:

sage: isinstance(28.0, sage.rings.real_mpfr.RealNumber)
True
sage: isinstance(28.0r, float)
True
sage: erfc(28.0)
6.56321584032878e-343
sage: erfc(28.0r)
0.0
edit flag offensive delete link more
0

answered 2020-07-19 12:04:03 +0200

tmonteil gravatar image

It works for me on 9.2.beta5 compiled from source, but with MPFR coming from my distro (libmpfr-dev package from Debian buster x86_64):

sage: R = RealField(5000)
....: print(erfc(R(28.0)))
....: 
6.563215840328784152380910481606274774134162689948282618021777806342324947794861698508585865279431011096752124531902419799309548263163678405299165421468926529756254284140867535233615012322334166170928503904086662017717248546748850127772332145411464185469489280260339088060235989228965843585936313865164734112442590831250266796576150016384641751358842396622115815414226304418079260475584875218573787585295929224096136714786361975866293997811039127970371335072820687621548403207278280764251340150092695582025750001434924105792823313203560201160341102473911930337624932555374585331265969965105269933130458163745578151352533927015070036231688942582148509848578635195809075408109589600332886026100202493893872822063883882953532315845612170517048543977112601393051614315880119177110350110356515266819875606915674560735226077346306998422763124176864165134035565227108933089306529302102108301994852596238985987401162654832997613615932852294726716250359138015072257484970655748380496068667053379552628609104926576396476543030043423989862535086552019022314368469618455141719577505798386449635616469359569975605353831944590150026622030636379223666200115938783888320717911446524435737548074875506351487946003131182599893046311540255956839538210349124618319107602941518963879471841876064339644999968291611090263995185161031176788592846481694313759144524067300523377786375902794975290499947567163622335460211299103648351220548274818081256066819963433322071061349340927987304921883890192373464108935170754385292484798247e-343

So there might be a compilation issue somewhere in your build.

Note that mpmath and gmpy2 might be responsible too.

Could you please (both) give us some informations so that someone can try to understand:

  • which version of Sage did you use ?
  • which OS ?
  • did you install Sage from the distribution, and which package ?
  • did you install Sage from the binaries, and which ones ?
  • did you compile Sage yourself ?
  • if you compiled Sage, was a libmpfr-dev library installed on your ditstro ?
  • ... ?
edit flag offensive delete link more

Comments

I'm running version 9.0 on Windows. The name of the installer file was SageMath-9.0-Installer-v0.6.0.exe. Below is the output I see in sage, when I check the version:

sage: version()
'SageMath version 9.0, Release Date: 2020-01-01'

I have not recompiled, and it's running on top of cygwin, so I'm not sure if the MPFR library is part of cygwin or part of the sagemath installation.

jaydfox gravatar imagejaydfox ( 2020-07-20 03:15:00 +0200 )edit

I'm running on the sage cell server https://sagecell.sagemath.org/ and the version() command gives 'SageMath version 9.1, Release Date: 2020-05-20'. Still it doesn't work at this moment. If the issue is solved in version 9.2, then I would be happy to wait for the sage cell server to update to 9.2.

WhatsUp gravatar imageWhatsUp ( 2020-08-01 17:53:27 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-07-17 13:22:20 +0200

Seen: 445 times

Last updated: Jul 19 '20