Ticket #11948: 11948.patch

File 11948.patch, 6.1 KB (added by jdemeyer, 18 months ago)
• sage/functions/other.py

# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1319474587 -7200
# Node ID 5da8e8e0d10e0abc38bcd88f5099044d5370cdfb
# Parent  bda8f14b0bf36072c1a064b2acdf17a94c78d1ee
Fix numeric evaluation of error function

diff --git a/sage/functions/other.py b/sage/functions/other.py
 a _eval_ = BuiltinFunction._eval_default def __init__(self): r""" The error function, defined as The error function, defined for real values as \text{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt. This function is also defined for complex values, via analytic continuation. Sage currently only implements the error function (via a call to PARI) when the input is real. Sage implements the error function via the erfc() function in PARI. EXAMPLES:: sage: loads(dumps(erf)) erf The following fails because we haven't implemented erf yet for complex values:: sage: complex(erf(3*I)) Traceback (most recent call last): ... TypeError: unable to simplify to complex approximation TESTS: Check if conversion from maxima elements work:: """ BuiltinFunction.__init__(self, "erf", latex_name=r"\text{erf}") def _evalf_(self, x, parent=None): def _evalf_(self, x, parent): """ EXAMPLES:: sage: erf(2).n() 0.995322265018953 sage: erf(2).n(150) Traceback (most recent call last): ... NotImplementedError: erf not implemented for precision higher than 53 sage: erf(2).n(200) 0.99532226501895273416206925636725292861089179704006007673835 sage: erf(pi - 1/2*I).n(100) 1.0000111669099367825726058952 + 1.6332655417638522934072124548e-6*I TESTS: Check that PARI/GP through the GP interface gives the same answer:: sage: gp.set_real_precision(59)  # random 38 sage: print gp.eval("1 - erfc(1)"); print erf(1).n(200); 0.84270079294971486934122063508260925929606699796630290845994 0.84270079294971486934122063508260925929606699796630290845994 """ try: prec = parent.prec() except AttributeError: # not a Sage parent prec = 0 if prec > 53: raise NotImplementedError, "erf not implemented for precision higher than 53" return parent(1 - pari(float(x)).erfc()) return parent(1) - parent(pari(x).erfc(prec)) def _derivative_(self, x, diff_param=None): """
• sage/symbolic/expression.pyx

diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
 a EXAMPLES:: sage: complex(I) 1j 1j sage: complex(erf(3*I)) Traceback (most recent call last): ... TypeError: unable to simplify to complex approximation (1.0000000000000002+1629.8673238578601j) """ try: return self._eval_self(complex) sage: taylor(a*log(z), z, 2, 3) 1/24*(z - 2)^3*a - 1/8*(z - 2)^2*a + 1/2*(z - 2)*a + a*log(2) :: :: sage: taylor(sqrt (sin(x) + a*x + 1), x, 0, 3) 1/48*(3*a^3 + 9*a^2 + 9*a - 1)*x^3 - 1/8*(a^2 + 2*a + 1)*x^2 + 1/2*(a + 1)*x + 1 :: :: sage: taylor (sqrt (x + 1), x, 0, 5) 7/256*x^5 - 5/128*x^4 + 1/16*x^3 - 1/8*x^2 + 1/2*x + 1 :: :: sage: taylor (1/log (x + 1), x, 0, 3) -19/720*x^3 + 1/24*x^2 - 1/12*x + 1/x + 1/2 :: :: sage: taylor (cos(x) - sec(x), x, 0, 5) -1/6*x^4 - x^2 :: :: sage: taylor ((cos(x) - sec(x))^3, x, 0, 9) -1/2*x^8 - x^6 :: :: sage: taylor (1/(cos(x) - sec(x))^3, x, 0, 5) -15377/7983360*x^4 - 6767/604800*x^2 + 11/120/x^2 + 1/2/x^4 - 1/x^6 - 347/15120 Ticket #7472 fixed (Taylor polynomial in more variables) :: TESTS: Check that ticket #7472 is fixed (Taylor polynomial in more variables):: sage: x,y=var('x y'); taylor(x*y^3,(x,1),(y,1),4) (y - 1)^3*(x - 1) + (y - 1)^3 + 3*(y - 1)^2*(x - 1) + 3*(y - 1)^2 + 3*(y - 1)*(x - 1) + x + 3*y - 3 -  multiplicities - bool (default: False); if True, return corresponding multiplicities.  This keyword is incompatible with to_poly_solve=True and does not make any sense when solving inequality. any sense when solving inequality. -  solution_dict - bool (default: False); if True or non-zero, return a list of dictionaries containing solutions. Not used Maxima's to_poly_solver package to search for more possible solutions, but possibly encounter approximate solutions. This keyword is incompatible with multiplicities=True and is not used when solving inequality. Setting to_poly_solve and is not used when solving inequality. Setting to_poly_solve to 'force' (string) omits Maxima's solve command (usefull when some solution of trigonometric equations are lost). sage: solve(Q*sqrt(Q^2 + 2) - 1, Q) [Q == 1/sqrt(Q^2 + 2)] sage: solve(Q*sqrt(Q^2 + 2) - 1, Q, to_poly_solve=True) [Q == 1/sqrt(-sqrt(2) + 1), Q == 1/sqrt(sqrt(2) + 1)] [Q == 1/sqrt(-sqrt(2) + 1), Q == 1/sqrt(sqrt(2) + 1)] In some cases there may be infinitely many solutions indexed by a dummy variable.  If it begins with z, it is implicitly