Skip to content

Commit

Permalink
doctest changes and a few fixes in support of pynac-0.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Apr 20, 2016
1 parent 39b85b0 commit 11e2b78
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/sage/functions/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
sage: exp(RDF('2.5'))
12.182493960703473
sage: exp(I*pi/12)
1/12*sqrt(6)*(sqrt(3) + 3) - 1/12*I*sqrt(6)*(sqrt(3) - 3)
(1/4*I + 1/4)*sqrt(6) - (1/4*I - 1/4)*sqrt(2)
To prevent automatic evaluation, use the ``hold`` parameter::
Expand Down
60 changes: 42 additions & 18 deletions src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@


from sage.symbolic.ring import SR, is_SymbolicVariable
from sage.symbolic.function import BuiltinFunction
from sage.symbolic.function import BuiltinFunction, GinacFunction
from sage.symbolic.expression import Expression
from sage.functions.other import factorial, binomial
from sage.structure.all import parent
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def gen_legendre_Q(n, m, x):
return ((n-m+1)*x*gen_legendre_Q(n,m-1,x)-(n+m-1)*gen_legendre_Q(n-1,m-1,x))/sqrt(1-x**2)


def hermite(n, x):
class Func_hermite(GinacFunction):
"""
Returns the Hermite polynomial for integers `n > -1`.
Expand All @@ -1257,13 +1257,13 @@ def hermite(n, x):
40
sage: S.<y> = PolynomialRing(RR)
sage: hermite(3,y)
8.00000000000000*y^3 - 12.0000000000000*y
8*y^3 - 12*y
sage: R.<x,y> = QQ[]
sage: hermite(3,y^2)
8*y^6 - 12*y^2
sage: w = var('w')
sage: hermite(3,2*w)
8*(8*w^2 - 3)*w
64*w^3 - 24*w
Check that :trac:`17192` is fixed::
Expand All @@ -1274,19 +1274,27 @@ def hermite(n, x):
sage: hermite(-1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
RuntimeError: hermite_eval: The index n must be a nonnegative integer
sage: hermite(-7,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
RuntimeError: hermite_eval: The index n must be a nonnegative integer
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
def __init__(self):
r"""
Init method for the Hermite polynomials.
_init()
return sage_eval(maxima.eval('hermite(%s,x)'%ZZ(n)), locals={'x':x})
EXAMPLES::
sage: loads(dumps(hermite))
hermite
"""
GinacFunction.__init__(self, "hermite", nargs=2, latex_name=r"H",
conversions={'maxima':'hermite', 'mathematica':'HermiteH',
'maple':'HermiteH'})

hermite = Func_hermite()

def jacobi_P(n, a, b, x):
r"""
Expand Down Expand Up @@ -1381,7 +1389,7 @@ def legendre_Q(n, x):
return sage_eval(maxima.eval('legendre_q(%s,x)'%ZZ(n)), locals={'x':x})


def ultraspherical(n, a, x):
class Func_ultraspherical(GinacFunction):
"""
Returns the ultraspherical (or Gegenbauer) polynomial for integers
`n > -1`.
Expand All @@ -1394,6 +1402,8 @@ def ultraspherical(n, a, x):
EXAMPLES::
sage: ultraspherical(8, 101/11, x)
795972057547264/214358881*x^8 - 62604543852032/19487171*x^6...
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(2,3/2,x)
15/2*x^2 - 3/2
Expand All @@ -1404,6 +1414,12 @@ def ultraspherical(n, a, x):
sage: t = PolynomialRing(RationalField(),"t").gen()
sage: gegenbauer(3,2,t)
32*t^3 - 12*t
sage: var('x')
x
sage: for N in range(100):
....: n = ZZ.random_element().abs() + 5
....: a = QQ.random_element().abs() + 5
....: assert ((n+1)*ultraspherical(n+1,a,x) - 2*x*(n+a)*ultraspherical(n,a,x) + (n+2*a-1)*ultraspherical(n-1,a,x)).expand().is_zero()
Check that :trac:`17192` is fixed::
Expand All @@ -1414,20 +1430,28 @@ def ultraspherical(n, a, x):
sage: ultraspherical(-1,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
RuntimeError: gegenb_eval: The index n must be a nonnegative integer
sage: ultraspherical(-7,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
RuntimeError: gegenb_eval: The index n must be a nonnegative integer
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
def __init__(self):
r"""
Init method for the ultraspherical polynomials.
_init()
return sage_eval(maxima.eval('ultraspherical(%s,%s,x)'%(ZZ(n),a)), locals={'x':x})
EXAMPLES::
sage: loads(dumps(ultraspherical))
gegenbauer
"""
GinacFunction.__init__(self, "gegenbauer", nargs=3, latex_name=r"C",
conversions={'maxima':'ultraspherical', 'mathematica':'GegenbauerC',
'maple':'GegenbauerC'})

gegenbauer = ultraspherical
ultraspherical = Func_ultraspherical()
gegenbauer = Func_ultraspherical()


class Func_laguerre(OrthogonalFunction):
Expand Down
27 changes: 23 additions & 4 deletions src/sage/functions/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,54 @@ def __init__(self):
1/4*sqrt(-2*sqrt(6) - 2*sqrt(2) + 8)
sage: sin(pi/30)
-1/8*sqrt(5) + 1/4*sqrt(-3/2*sqrt(5) + 15/2) - 1/8
sage: sin(104*pi/105)
sin(1/105*pi)
sage: cos(pi/8)
1/2*sqrt(sqrt(2) + 2)
sage: cos(pi/10)
1/2*sqrt(1/2*sqrt(5) + 5/2)
1/4*sqrt(2*sqrt(5) + 10)
sage: cos(pi/12)
1/12*sqrt(6)*(sqrt(3) + 3)
1/4*sqrt(6) + 1/4*sqrt(2)
sage: cos(pi/15)
1/8*sqrt(5) + 1/4*sqrt(3/2*sqrt(5) + 15/2) - 1/8
sage: cos(pi/24)
1/4*sqrt(2*sqrt(6) + 2*sqrt(2) + 8)
sage: cos(104*pi/105)
-cos(1/105*pi)
sage: tan(pi/5)
sqrt(-2*sqrt(5) + 5)
sage: tan(pi/8)
sqrt(2) - 1
sage: tan(pi/10)
sqrt(-2/5*sqrt(5) + 1)
1/5*sqrt(-10*sqrt(5) + 25)
sage: tan(pi/16)
-sqrt(2) + sqrt(2*sqrt(2) + 4) - 1
sage: tan(pi/20)
sqrt(5) - 1/2*sqrt(8*sqrt(5) + 20) + 1
sqrt(5) - sqrt(2*sqrt(5) + 5) + 1
sage: tan(pi/24)
sqrt(6) - sqrt(3) + sqrt(2) - 2
sage: tan(104*pi/105)
-tan(1/105*pi)
sage: cot(104*pi/105)
-cot(1/105*pi)
sage: sec(104*pi/105)
-sec(1/105*pi)
sage: csc(104*pi/105)
csc(1/105*pi)
sage: all(sin(rat*pi).n(200)-sin(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/30,7/30,11/30,13/30,1/8,3/8,1/24,5/24,7/24,11/24])
True
sage: all(cos(rat*pi).n(200)-cos(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/10,3/10,1/12,5/12,1/15,2/15,4/15,7/15,1/8,3/8,1/24,5/24,11/24])
True
sage: all(tan(rat*pi).n(200)-tan(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/10,3/10,1/20,3/20,7/20,9/20,1/8,3/8,1/16,3/16,5/16,7/16,1/24,5/24,7/24,11/24])
True
Check that :trac:`20456` is fixed::
sage: assume(x>0)
sage: sin(pi*x)
sin(pi*x)
sage: forget()
"""
GinacFunction.__init__(self, "sin", latex_name=r"\sin",
conversions=dict(maxima='sin',mathematica='Sin'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def dvalue(self):
sage: HeckeTriangleGroup(6).dvalue()
1/108
sage: HeckeTriangleGroup(10).dvalue()
e^(2*euler_gamma - 2*pi/sqrt(1/2*sqrt(5) + 5/2) + psi(4/5) + psi(7/10))
e^(2*euler_gamma - 4*pi/sqrt(2*sqrt(5) + 10) + psi(4/5) + psi(7/10))
sage: HeckeTriangleGroup(infinity).dvalue()
1/64
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/modform_hecketriangle/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
sage: G.is_arithmetic()
False
sage: G.dvalue()
e^(2*euler_gamma - 2*sqrt(6)*pi/(sqrt(3) + 3) + psi(19/24) + psi(17/24))
e^(2*euler_gamma - 4*pi/(sqrt(6) + sqrt(2)) + psi(19/24) + psi(17/24))
sage: AA(G.lam())
1.9318516525781...?
Expand Down
16 changes: 16 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,22 @@ cdef class Expression(CommutativeRingElement):
sage: latex(ex)
\left(e^{\sqrt{x}}\right)^{x}
Test simplification of powers involving the reciprocal
logarithm of the (positive) base::
sage: 2^(1/log(2))
e
sage: 2^(x/log(2))
e^x
sage: 2^(-x^2/2/log(2))
e^(-1/2*x^2)
sage: x^(x/log(x))
x^(x/log(x))
sage: assume(x > 0)
sage: x^(x/log(x))
e^x
sage: forget()
Test base a Python numeric type::
sage: int(2)^x
Expand Down
8 changes: 8 additions & 0 deletions src/sage/symbolic/pynac.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,14 @@ cdef bint py_is_real(object a) except +:
if type(a) is int or isinstance(a, Integer) or\
type(a) is long or type(a) is float:
return True
try:
P = parent_c(a)
if P.is_field() and P.is_finite():
return False
except NotImplementedError:
return False
except AttributeError:
pass
return py_imag(a) == 0

cdef bint py_is_prime(object n) except +:
Expand Down
8 changes: 8 additions & 0 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ cdef class SymbolicRing(CommutativeRing):
3*x^5*log(y)
sage: t.operator(), t.operands()
(<function mul_vararg at 0x...>, [x^5, log(y), 3])
Check that :trac:`20162` is fixed::
sage: k.<a> = GF(9)
sage: SR(a).is_real()
False
sage: SR(a).is_positive()
False
"""
cdef GEx exp
if is_Expression(x):
Expand Down

0 comments on commit 11e2b78

Please sign in to comment.