79528362

Date: 2025-03-23 02:21:01
Score: 1
Natty:
Report link

Firstly, I would welcome you to the issue of computer precision in doing calculations. As commented by Martin Brown below your question, 1e-36 is fairly close to 0 as far as double precision computing goes.

Secondly, I would suggest you consider implementing a common practice in many languages where some "tolerance" is used to decide if something is sufficiently close to zero that we consider it as such. mpmath.chop(x, tol=None) is a function used to do just this.

Furthermore, mpmath has documentation which discusses setting or changing the precision which is worth a read.

Lastly, to address your question of "how to use Legendre function correctly", this really depends on your use case, to which you would need to provide more detail. You may only need 3 or 4 decimal places, in which case the mpmath.chop(x, tol=1e-4) route would work well enough.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Kiwi