本文整理汇总了Python中sage.calculus.calculus.maxima.eval函数的典型用法代码示例。如果您正苦于以下问题:Python eval函数的具体用法?Python eval怎么用?Python eval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eval函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assume
def assume(self):
"""
TEST::
sage: from sage.symbolic.assumptions import GenericDeclaration
sage: decl = GenericDeclaration(x, 'even')
sage: decl.assume()
sage: cos(x*pi).simplify()
1
sage: decl2 = GenericDeclaration(x, 'odd')
sage: decl2.assume()
Traceback (most recent call last):
...
ValueError: Assumption is inconsistent
sage: decl.forget()
"""
from sage.calculus.calculus import maxima
if self._context is None:
# We get the list here because features may be added with time.
valid_features = list(maxima("features"))
if self._assumption not in [repr(x).strip() for x in list(valid_features)]:
raise ValueError, "%s not a valid assumption, must be one of %s" % (self._assumption, valid_features)
cur = maxima.get("context")
self._context = maxima.newcontext('context' + maxima._next_var_name())
try:
maxima.eval("declare(%s, %s)" % (repr(self._var), self._assumption))
# except TypeError, mess:
# if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
# raise ValueError, "Assumption is inconsistent"
except RuntimeError, mess:
if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
raise ValueError, "Assumption is inconsistent"
else:
raise
maxima.set("context", cur)
示例2: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.orthogonal_polys._done
False
Then after using one of these functions, it changes::
sage: from sage.functions.orthogonal_polys import chebyshev_T
sage: chebyshev_T(2,x)
2*(x - 1)^2 + 4*x - 3
sage: sage.functions.orthogonal_polys._done
True
Note that because here we use a Pynac variable ``x``,
the representation of the function is different from
its actual doctest, where a polynomial indeterminate
``x`` is used.
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
# TODO -- make it possible to use the intervals returned
# instead of just discarding this info!
maxima.eval("orthopoly_returns_intervals:false;")
_done = True
示例3: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.special._done
False
Then after using one of these functions, it changes::
sage: from sage.functions.special import airy_ai
sage: airy_ai(1.0)
0.135292416313
sage: sage.functions.special._done
True
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
maxima.eval('orthopoly_returns_intervals:false;')
_done = True
示例4: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.special._done
False
Then after using one of the MaximaFunctions, it changes::
sage: from sage.functions.special import elliptic_ec
sage: elliptic_ec(0.1)
1.53075763689776
sage: sage.functions.special._done
True
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
maxima.eval('orthopoly_returns_intervals:false;')
_done = True
示例5: gen_laguerre
def gen_laguerre(n, a, x):
"""
Returns the generalized Laguerre polynomial for integers `n > -1`.
Typically, a = 1/2 or a = -1/2.
REFERENCE:
- table on page 789 in AS.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(2,1,x)
1/2*x^2 - 3*x + 3
sage: gen_laguerre(2,1/2,x)
1/2*x^2 - 5/2*x + 15/8
sage: gen_laguerre(2,-1/2,x)
1/2*x^2 - 3/2*x + 3/8
sage: gen_laguerre(2,0,x)
1/2*x^2 - 2*x + 1
sage: gen_laguerre(3,0,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
"""
from sage.functions.all import sqrt
_init()
return sage_eval(maxima.eval("gen_laguerre(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
示例6: legendre_P
def legendre_P(n, x):
"""
Returns the Legendre polynomial of the first kind for integers
`n > -1`.
REFERENCE:
- AS 22.5.35 page 779.
EXAMPLES::
sage: P.<t> = QQ[]
sage: legendre_P(2,t)
3/2*t^2 - 1/2
sage: legendre_P(3, 1.1)
1.67750000000000
sage: legendre_P(3, 1 + I)
7/2*I - 13/2
sage: legendre_P(3, MatrixSpace(ZZ, 2)([1, 2, -4, 7]))
[-179 242]
[-484 547]
sage: legendre_P(3, GF(11)(5))
8
"""
_init()
return sage_eval(maxima.eval("legendre_p(%s,x)" % ZZ(n)), locals={"x": x})
示例7: gen_laguerre
def gen_laguerre(n, a, x):
"""
Returns the generalized Laguerre polynomial for integers `n > -1`.
Typically, `a = 1/2` or `a = -1/2`.
REFERENCES:
- Table on page 789 in [ASHandbook]_.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(2,1,x)
1/2*x^2 - 3*x + 3
sage: gen_laguerre(2,1/2,x)
1/2*x^2 - 5/2*x + 15/8
sage: gen_laguerre(2,-1/2,x)
1/2*x^2 - 3/2*x + 3/8
sage: gen_laguerre(2,0,x)
1/2*x^2 - 2*x + 1
sage: gen_laguerre(3,0,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
"""
_init()
return sage_eval(maxima.eval("gen_laguerre(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
示例8: ultraspherical
def ultraspherical(n, a, x):
"""
Returns the ultraspherical (or Gegenbauer) polynomial for integers
`n > -1`.
Computed using Maxima.
REFERENCE:
- AS 22.5.27
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(2,3/2,x)
15/2*x^2 - 3/2
sage: ultraspherical(2,1/2,x)
3/2*x^2 - 1/2
sage: ultraspherical(1,1,x)
2*x
sage: t = PolynomialRing(RationalField(),"t").gen()
sage: gegenbauer(3,2,t)
32*t^3 - 12*t
"""
_init()
return sage_eval(maxima.eval("ultraspherical(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
示例9: hermite
def hermite(n, x):
"""
Returns the Hermite polynomial for integers `n > -1`.
REFERENCE:
- AS 22.5.40 and 22.5.41, page 779.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(2,x)
4*x^2 - 2
sage: hermite(3,x)
8*x^3 - 12*x
sage: hermite(3,2)
40
sage: S.<y> = PolynomialRing(RR)
sage: hermite(3,y)
8.00000000000000*y^3 - 12.0000000000000*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
"""
_init()
return sage_eval(maxima.eval("hermite(%s,x)" % ZZ(n)), locals={"x": x})
示例10: bessel_Y
def bessel_Y(nu,z,algorithm="maxima", prec=53):
r"""
Implements the "Y-Bessel function", or "Bessel function of the 2nd
kind", with index (or "order") nu and argument z.
.. note::
Currently only prec=53 is supported.
Defn::
cos(pi n)*bessel_J(nu, z) - bessel_J(-nu, z)
-------------------------------------------------
sin(nu*pi)
if nu is not an integer and by taking a limit otherwise.
Sometimes bessel_Y(n,z) is denoted Y_n(z) in the literature.
This is computed using Maxima by default.
EXAMPLES::
sage: bessel_Y(2,1.1,"scipy")
-1.4314714939...
sage: bessel_Y(2,1.1)
-1.4314714939590...
sage: bessel_Y(3.001,2.1)
-1.0299574976424...
TESTS::
sage: bessel_Y(2,1.1, algorithm="pari")
Traceback (most recent call last):
...
NotImplementedError: The Y-Bessel function is only implemented for the maxima and scipy algorithms
"""
if algorithm=="scipy":
if prec != 53:
raise ValueError, "for the scipy algorithm the precision must be 53"
import scipy.special
ans = str(scipy.special.yv(float(nu),complex(real(z),imag(z))))
ans = ans.replace("(","")
ans = ans.replace(")","")
ans = ans.replace("j","*I")
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"
return RR(maxima.eval("bessel_y(%s,%s)"%(float(nu),float(z))))
elif algorithm == "pari":
raise NotImplementedError, "The Y-Bessel function is only implemented for the maxima and scipy algorithms"
else:
raise ValueError, "unknown algorithm '%s'"%algorithm
示例11: _maxima_init_evaled_
def _maxima_init_evaled_(self, n, x):
"""
Evaluate the Chebyshev polynomial ``self`` with maxima.
EXAMPLES::
sage: var('n, x')
(n, x)
sage: chebyshev_T._maxima_init_evaled_(1,x)
'_SAGE_VAR_x'
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
chebyshev_t(_SAGE_VAR_n,chebyshev_t(_SAGE_VAR_n,_SAGE_VAR_x))
"""
return maxima.eval("chebyshev_t({0},{1})".format(n._maxima_init_(), x._maxima_init_()))
示例12: chebyshev_U
def chebyshev_U(n, x):
"""
Returns the Chebyshev function of the second kind for integers `n>-1`.
REFERENCE:
- AS, 22.8.3 page 783 and AS 6.1.22 page 256.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: chebyshev_U(2,x)
4*x^2 - 1
"""
_init()
return sage_eval(maxima.eval("chebyshev_u(%s,x)" % ZZ(n)), locals={"x": x})
示例13: hermite
def hermite(n,x):
"""
Returns the Hermite polynomial for integers `n > -1`.
REFERENCE:
- [ASHandbook]_ 22.5.40 and 22.5.41, page 779.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(2,x)
4*x^2 - 2
sage: hermite(3,x)
8*x^3 - 12*x
sage: hermite(3,2)
40
sage: S.<y> = PolynomialRing(RR)
sage: hermite(3,y)
8.00000000000000*y^3 - 12.0000000000000*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
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(0,x)
1
sage: hermite(-1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: hermite(-7,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('hermite(%s,x)'%ZZ(n)), locals={'x':x})
示例14: chebyshev_T
def chebyshev_T(n, x):
"""
Returns the Chebyshev function of the first kind for integers
`n>-1`.
REFERENCE:
- AS 22.5.31 page 778 and AS 6.1.22 page 256.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: chebyshev_T(2,x)
2*x^2 - 1
"""
_init()
return sage_eval(maxima.eval("chebyshev_t(%s,x)" % ZZ(n)), locals={"x": x})
示例15: ultraspherical
def ultraspherical(n,a,x):
"""
Returns the ultraspherical (or Gegenbauer) polynomial for integers
`n > -1`.
Computed using Maxima.
REFERENCE:
- [ASHandbook]_ 22.5.27
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(2,3/2,x)
15/2*x^2 - 3/2
sage: ultraspherical(2,1/2,x)
3/2*x^2 - 1/2
sage: ultraspherical(1,1,x)
2*x
sage: t = PolynomialRing(RationalField(),"t").gen()
sage: gegenbauer(3,2,t)
32*t^3 - 12*t
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(0,1,x)
1
sage: ultraspherical(-1,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: ultraspherical(-7,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('ultraspherical(%s,%s,x)'%(ZZ(n),a)), locals={'x':x})