Ticket #10251: 10251_rebase_bessel_scipy.2.patch

File 10251_rebase_bessel_scipy.2.patch, 3.2 KB (added by jvkersch, 2 years ago)
• sage/functions/special.py

```# HG changeset patch
# User Joris Vankerschaver <joris.vankerschaver@gmail.com>
# Date 1296089613 28800
# Node ID f5675304d61546d1de1ea0a0f51e71a64d74e303
# Parent  063ffd2a1aa7c0aaf2f7548513dc8ee546a0a108
Rebase of 10251: Bessel functions have small imaginary component

diff -r 063ffd2a1aa7 -r f5675304d615 sage/functions/special.py```
 a 1.2660658777520... sage: bessel_I(1,1,"scipy") 0.565159103992... Check whether the return value is real whenever the argument is real (#10251):: sage: bessel_I(5, 1.5, algorithm='scipy') in RR True """ if algorithm=="pari": from sage.libs.pari.all import pari ans = ans.replace("(","") ans = ans.replace(")","") ans = ans.replace("j","*I") return sage_eval(ans) ans = sage_eval(ans) return real(ans) if z in RR else ans # Return real value when arg is real elif algorithm == "maxima": if prec != 53: raise ValueError, "for the maxima algorithm the precision must be 53" 0.0583793793051868 sage: bessel_J(3,10,"scipy") 0.0583793793052... Check whether the return value is real whenever the argument is real (#10251):: sage: bessel_J(5, 1.5, algorithm='scipy') in RR True """ if algorithm=="pari": ans = ans.replace("(","") ans = ans.replace(")","") ans = ans.replace("j","*I") return sage_eval(ans) ans = sage_eval(ans) return real(ans) if z in RR else ans elif algorithm == "maxima": if prec != 53: raise ValueError, "for the maxima algorithm the precision must be 53" Traceback (most recent call last): ... NotImplementedError: The K-Bessel function is only implemented for the pari and scipy algorithms Check whether the return value is real whenever the argument is real (#10251):: sage: bessel_K(5, 1.5, algorithm='scipy') in RR True """ if algorithm=="scipy": if prec != 53: ans = ans.replace("(","") ans = ans.replace(")","") ans = ans.replace("j","*I") return sage_eval(ans) ans = sage_eval(ans) return real(ans) if z in RR else ans elif algorithm == 'pari': from sage.libs.pari.all import pari try: ans = ans.replace("(","") ans = ans.replace(")","") ans = ans.replace("j","*I") return sage_eval(ans) ans = sage_eval(ans) return real(ans) if z in RR else ans elif algorithm == "maxima": if prec != 53: raise ValueError, "for the maxima algorithm the precision must be 53"