# 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
|
b
|
|
| 719 | 719 | 1.2660658777520... |
| 720 | 720 | sage: bessel_I(1,1,"scipy") |
| 721 | 721 | 0.565159103992... |
| | 722 | |
| | 723 | Check whether the return value is real whenever the argument is real (#10251):: |
| | 724 | |
| | 725 | sage: bessel_I(5, 1.5, algorithm='scipy') in RR |
| | 726 | True |
| | 727 | |
| 722 | 728 | """ |
| 723 | 729 | if algorithm=="pari": |
| 724 | 730 | from sage.libs.pari.all import pari |
| … |
… |
|
| 741 | 747 | ans = ans.replace("(","") |
| 742 | 748 | ans = ans.replace(")","") |
| 743 | 749 | ans = ans.replace("j","*I") |
| 744 | | return sage_eval(ans) |
| | 750 | ans = sage_eval(ans) |
| | 751 | return real(ans) if z in RR else ans # Return real value when arg is real |
| 745 | 752 | elif algorithm == "maxima": |
| 746 | 753 | if prec != 53: |
| 747 | 754 | raise ValueError, "for the maxima algorithm the precision must be 53" |
| … |
… |
|
| 804 | 811 | 0.0583793793051868 |
| 805 | 812 | sage: bessel_J(3,10,"scipy") |
| 806 | 813 | 0.0583793793052... |
| | 814 | |
| | 815 | Check whether the return value is real whenever the argument is real (#10251):: |
| | 816 | sage: bessel_J(5, 1.5, algorithm='scipy') in RR |
| | 817 | True |
| 807 | 818 | """ |
| 808 | 819 | |
| 809 | 820 | if algorithm=="pari": |
| … |
… |
|
| 829 | 840 | ans = ans.replace("(","") |
| 830 | 841 | ans = ans.replace(")","") |
| 831 | 842 | ans = ans.replace("j","*I") |
| 832 | | return sage_eval(ans) |
| | 843 | ans = sage_eval(ans) |
| | 844 | return real(ans) if z in RR else ans |
| 833 | 845 | elif algorithm == "maxima": |
| 834 | 846 | if prec != 53: |
| 835 | 847 | raise ValueError, "for the maxima algorithm the precision must be 53" |
| … |
… |
|
| 871 | 883 | Traceback (most recent call last): |
| 872 | 884 | ... |
| 873 | 885 | NotImplementedError: The K-Bessel function is only implemented for the pari and scipy algorithms |
| | 886 | |
| | 887 | Check whether the return value is real whenever the argument is real (#10251):: |
| | 888 | |
| | 889 | sage: bessel_K(5, 1.5, algorithm='scipy') in RR |
| | 890 | True |
| | 891 | |
| 874 | 892 | """ |
| 875 | 893 | if algorithm=="scipy": |
| 876 | 894 | if prec != 53: |
| … |
… |
|
| 880 | 898 | ans = ans.replace("(","") |
| 881 | 899 | ans = ans.replace(")","") |
| 882 | 900 | ans = ans.replace("j","*I") |
| 883 | | return sage_eval(ans) |
| | 901 | ans = sage_eval(ans) |
| | 902 | return real(ans) if z in RR else ans |
| 884 | 903 | elif algorithm == 'pari': |
| 885 | 904 | from sage.libs.pari.all import pari |
| 886 | 905 | try: |
| … |
… |
|
| 945 | 964 | ans = ans.replace("(","") |
| 946 | 965 | ans = ans.replace(")","") |
| 947 | 966 | ans = ans.replace("j","*I") |
| 948 | | return sage_eval(ans) |
| | 967 | ans = sage_eval(ans) |
| | 968 | return real(ans) if z in RR else ans |
| 949 | 969 | elif algorithm == "maxima": |
| 950 | 970 | if prec != 53: |
| 951 | 971 | raise ValueError, "for the maxima algorithm the precision must be 53" |