Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/rws/17678-1' of git://trac.sagemath.org/sage into tes…
Browse files Browse the repository at this point in the history
…t_avoid_recompilation

Conflicts:
	src/sage/symbolic/ring.pyx
	src/sage/tests/french_book/recequadiff.py
  • Loading branch information
arminstraub committed Aug 7, 2016
2 parents b630b41 + 8267479 commit 02cb5f5
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 30 deletions.
117 changes: 98 additions & 19 deletions src/sage/functions/bessel.py
Expand Up @@ -125,7 +125,7 @@
sage: bessel_J(0, x)
bessel_J(0, x)
sage: bessel_J(0, 0)
bessel_J(0, 0)
1
sage: bessel_J(0, x).diff(x)
-1/2*bessel_J(1, x) + 1/2*bessel_J(-1, x)
Expand Down Expand Up @@ -224,11 +224,12 @@

# remove after deprecation period
from sage.calculus.calculus import maxima
from sage.functions.other import real, imag
from sage.functions.trig import sin, cos
from sage.functions.other import real, imag, sqrt
from sage.misc.sage_eval import sage_eval
from sage.rings.real_mpfr import RealField
from sage.plot.plot import plot
from sage.rings.all import ZZ
from sage.rings.all import ZZ, QQ


class Function_Bessel_J(BuiltinFunction):
Expand Down Expand Up @@ -341,6 +342,37 @@ def __init__(self):
maxima='bessel_j',
sympy='besselj'))

def _eval_(self, n, x):
"""
EXAMPLES::
sage: n = var('n')
sage: bessel_J(0, 0)
1
sage: bessel_J(5/2, 0)
0
sage: bessel_J(-5/2, 0)
Infinity
sage: bessel_J(1/2, x)
sqrt(2)*sqrt(1/(pi*x))*sin(x)
sage: bessel_J(-1/2, x)
sqrt(2)*sqrt(1/(pi*x))*cos(x)
sage: bessel_J(n, 0)
bessel_J(n, 0)
"""
from sage.rings.infinity import unsigned_infinity
if x == 0:
if n == 0:
return ZZ(1)
elif n > 0 or n in ZZ:
return ZZ(0)
elif not isinstance(n, Expression):
return unsigned_infinity
elif n == QQ(1)/2:
return sqrt(2/pi/x) * sin(x)
elif n == QQ(-1)/2:
return sqrt(2/pi/x) * cos(x)

def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
Expand Down Expand Up @@ -521,6 +553,29 @@ def __init__(self):
maxima='bessel_y',
sympy='bessely'))

def _eval_(self, n, x):
"""
EXAMPLES::
sage: n = var('n')
sage: bessel_Y(1, 0)
Infinity
sage: bessel_Y(1/2, x)
-sqrt(2)*sqrt(1/(pi*x))*cos(x)
sage: bessel_Y(-1/2, x)
sqrt(2)*sqrt(1/(pi*x))*sin(x)
"""
from sage.rings.infinity import infinity, unsigned_infinity
if x == 0:
if n == 0:
return -infinity
elif not isinstance(n, Expression):
return unsigned_infinity
elif n == QQ(1)/2:
return -sqrt(2/pi/x) * cos(x)
elif n == QQ(-1)/2:
return sqrt(2/pi/x) * sin(x)

def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
Expand Down Expand Up @@ -698,26 +753,43 @@ def _eval_(self, n, x):
"""
EXAMPLES::
sage: y=var('y')
sage: bessel_I(y,x)
sage: n,y = var('n,y')
sage: bessel_I(y, x)
bessel_I(y, x)
sage: bessel_I(0.0, 1.0)
1.26606587775201
sage: bessel_I(0, 0)
1
sage: bessel_I(7/2, 0)
0
sage: bessel_I(-7/2, 0)
Infinity
sage: bessel_I(1/2, 1)
sqrt(2)*sinh(1)/sqrt(pi)
sage: bessel_I(-1/2, pi)
sqrt(2)*cosh(pi)/pi
sage: bessel_I(n, 0)
bessel_I(n, 0)
"""
from sage.rings.infinity import unsigned_infinity
# special identities
if n == Integer(1) / Integer(2):
if x == 0:
if n == 0:
return ZZ(1)
elif n > 0 or n in ZZ:
return ZZ(0)
elif not isinstance(n, Expression):
return unsigned_infinity
if n == QQ(1)/2:
return sqrt(2 / (pi * x)) * sinh(x)
elif n == -Integer(1) / Integer(2):
elif n == -QQ(1)/2:
return sqrt(2 / (pi * x)) * cosh(x)


def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_I(0.0, 1.0)
1.26606587775201
sage: bessel_I(1,3).n(digits=20)
3.9533702174026093965
"""
Expand Down Expand Up @@ -793,9 +865,9 @@ class Function_Bessel_K(BuiltinFunction):
-1/2*bessel_K(3, x) - 1/2*bessel_K(1, x)
sage: bessel_K(1/2, x)
bessel_K(1/2, x)
sqrt(1/2)*sqrt(pi)*e^(-x)/sqrt(x)
sage: bessel_K(1/2, -1)
bessel_K(1/2, -1)
-I*sqrt(1/2)*sqrt(pi)*e
sage: bessel_K(1/2, 1)
sqrt(1/2)*sqrt(pi)*e^(-1)
Expand Down Expand Up @@ -879,23 +951,30 @@ def _eval_(self, n, x):
"""
EXAMPLES::
sage: bessel_K(1,0)
bessel_K(1, 0)
sage: bessel_K(1.0, 0.0)
+infinity
sage: bessel_K(-1, 1).n(128)
0.60190723019723457473754000153561733926
"""
sage: n = var('n')
sage: bessel_K(1, 0)
Infinity
sage: bessel_K(1/2, x)
sqrt(1/2)*sqrt(pi)*e^(-x)/sqrt(x)
sage: bessel_K(n, 0)
bessel_K(n, 0)
"""
from sage.rings.infinity import unsigned_infinity
# special identity
if n == Integer(1) / Integer(2) and x > 0:
if x == 0 and not isinstance(n, Expression):
return unsigned_infinity
if n == QQ(1)/2 or n == -QQ(1)/2 and x > 0:
return sqrt(pi / 2) * exp(-x) * x ** (-Integer(1) / Integer(2))


def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_K(0.0, 1.0)
0.421024438240708
sage: bessel_K(-1, 1).n(128)
0.60190723019723457473754000153561733926
sage: bessel_K(0, RealField(128)(1))
0.42102443824070833333562737921260903614
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/infinity.py
Expand Up @@ -481,7 +481,7 @@ def _div_(self, other):
sage: SR(infinity) / unsigned_infinity
Traceback (most recent call last):
...
ValueError: unsigned oo times smaller number not defined
RuntimeError: indeterminate expression: 0 * infinity encountered.
"""
return self * ~other

Expand Down
2 changes: 1 addition & 1 deletion src/sage/symbolic/expression.pyx
Expand Up @@ -3067,7 +3067,7 @@ cdef class Expression(CommutativeRingElement):
sage: x*unsigned_infinity
Traceback (most recent call last):
...
ValueError: oo times number < oo not defined
RuntimeError: indeterminate expression: infinity * f(x) encountered.
sage: SR(oo)*SR(oo)
+Infinity
Expand Down
9 changes: 7 additions & 2 deletions src/sage/symbolic/ring.pyx
Expand Up @@ -96,6 +96,8 @@ cdef class SymbolicRing(CommutativeRing):
2
sage: SR.coerce(-infinity)
-Infinity
sage: SR.coerce(unsigned_infinity)
Infinity
sage: SR.has_coerce_map_from(ZZ['t'])
True
sage: SR.has_coerce_map_from(ZZ['t,u,v'])
Expand All @@ -114,6 +116,8 @@ cdef class SymbolicRing(CommutativeRing):
True
sage: SR.has_coerce_map_from(ComplexBallField())
True
sage: SR.has_coerce_map_from(UnsignedInfinityRing)
True
TESTS:
Expand Down Expand Up @@ -177,7 +181,8 @@ cdef class SymbolicRing(CommutativeRing):
from sage.rings.polynomial.laurent_polynomial_ring import is_LaurentPolynomialRing

from sage.rings.all import (ComplexField,
RLF, CLF, AA, QQbar, InfinityRing)
RLF, CLF, AA, QQbar, InfinityRing,
UnsignedInfinityRing)
from sage.rings.finite_rings.finite_field_base import is_FiniteField

from sage.interfaces.maxima import Maxima
Expand All @@ -190,7 +195,7 @@ cdef class SymbolicRing(CommutativeRing):
elif is_PolynomialRing(R) or is_MPolynomialRing(R) or is_FractionField(R) or is_LaurentPolynomialRing(R):
base = R.base_ring()
return base is not self and self.has_coerce_map_from(base)
elif (R is InfinityRing
elif (R is InfinityRing or R is UnsignedInfinityRing
or is_RealIntervalField(R) or is_ComplexIntervalField(R)
or isinstance(R, RealBallField)
or isinstance(R, ComplexBallField)
Expand Down
15 changes: 8 additions & 7 deletions src/sage/tests/french_book/recequadiff.py
Expand Up @@ -12,6 +12,9 @@
sage: x = var('x')
sage: y = function('y')(x)
sage: _C = SR.var("_C")
sage: _K1 = SR.var("_K1")
sage: _K2 = SR.var("_K2")
Sage example in ./recequadiff.tex, line 179::
Expand Down Expand Up @@ -104,10 +107,8 @@
Sage example in ./recequadiff.tex, line 367::
sage: solve(ed, y)[0].subs(_C==5).rhs()
Traceback (most recent call last):
...
NameError: name '_C' is not defined
sage: solve(ed, y)[0].subs(_C == 5).rhs()
e^(-sqrt(-2*cos(x) + 10))
Sage example in ./recequadiff.tex, line 377::
Expand All @@ -129,16 +130,16 @@
sage: P = Graphics()
sage: for k in range(1,20,2):
... P += plot(solve(ed, y)[0].subs(c==1+k/4).rhs(), x, -3, 3)
... P += plot(solve(ed, y)[0].subs(c == 1+k/4).rhs(), x, -3, 3)
sage: P
Graphics object consisting of 11 graphics primitives
Graphics object consisting of 10 graphics primitives
Sage example in ./recequadiff.tex, line 426::
sage: P = Graphics()
sage: for j in [0,1]:
... for k in range(1,10,2):
... f = solve(ed,y)[j].subs(c==2+0.25*k).rhs()
... f = solve(ed,y)[j].subs(c == 2+0.25*k).rhs()
... P += plot(f, x, -3, 3)
sage: P
Graphics object consisting of 10 graphics primitives
Expand Down

0 comments on commit 02cb5f5

Please sign in to comment.