# Ticket #4498: trac_4498_arg.3.patch

File trac_4498_arg.3.patch, 8.1 KB (added by ktkohl, 9 years ago)

symbolic arg--fixed whitespace issues--use this one instead of others

• ## sage/functions/all.py

# HG changeset patch
# User Karen T. Kohl <ktkohl96@gmail.com>
# Date 1326306162 21600
# Node ID 6a250b57f11f590c35c331cac2a29fba9e694d9c
# Parent  92c93226b64f933e0af00bbcbd1a8a79c444f43f
Trac 4498:  symbolic arg function

diff --git a/sage/functions/all.py b/sage/functions/all.py
 a from other import ( ceil, floor, gamma, psi, factorial, abs_symbolic, erf, sqrt, gamma_inc, incomplete_gamma, real_part, real, arg, real_part, real, imag_part, imag, imaginary, conjugate) from log import (exp, log, ln, polylog, dilog)
• ## sage/functions/other.py

diff --git a/sage/functions/other.py b/sage/functions/other.py
 a from sage.symbolic.constants import pi from sage.symbolic.function import is_inexact from sage.functions.log import exp from sage.functions.trig import arctan2 from sage.functions.transcendental import Ei from sage.libs.mpmath import utils as mpmath_utils {'__call__': staticmethod(sqrt), '__setstate__': lambda x, y: None}) class Function_arg(BuiltinFunction): def __init__(self): r""" The argument function for complex numbers. EXAMPLES:: sage: arg(3+i) arctan(1/3) sage: arg(-1+i) 3/4*pi sage: arg(2+2*i) 1/4*pi sage: arg(2+x) arg(x + 2) sage: arg(2.0+i+x) arg(x + 2.00000000000000 + 1.00000000000000*I) sage: arg(-3) pi sage: arg(3) 0 sage: arg(0) 0 sage: latex(arg(x)) \text{arg}\left(x\right) sage: maxima(arg(x)) atan2(0,x) sage: maxima(arg(2+i)) atan(1/2) sage: maxima(arg(sqrt(2)+i)) atan(1/sqrt(2)) sage: arg(2+i) arctan(1/2) sage: arg(sqrt(2)+i) arg(sqrt(2) + I) sage: arg(sqrt(2)+i).simplify() arctan(1/2*sqrt(2)) TESTS:: sage: arg(3+i) arctan(1/3) sage: arg(-1+i) 3/4*pi sage: arg(2+2*i) 1/4*pi sage: arg(2+x) arg(x + 2) sage: arg(2.0+i+x) arg(x + 2.00000000000000 + 1.00000000000000*I) sage: arg(-3) pi sage: arg(3) 0 sage: arg(0) 0 sage: arg(0.0) 0.000000000000000 sage: arg(3.0) 0.000000000000000 sage: arg(-2.5) 3.14159265358979 sage: arg(2.0+3*i) 0.982793723247329 sage: maxima(arg(x)) atan2(0,x) sage: maxima(arg(2+i)) atan(1/2) sage: maxima(arg(sqrt(2)+i)) atan(1/sqrt(2)) sage: arg(2+i) arctan(1/2) sage: arg(sqrt(2)+i) arg(sqrt(2) + I) sage: arg(sqrt(2)+i).simplify() arctan(1/2*sqrt(2)) """ BuiltinFunction.__init__(self, "arg",  latex_name=r"\text{arg}", conversions=dict(maxima='carg',mathematica='Arg')) def _eval_(self, x): """ EXAMPLES:: sage: arg(3+i) arctan(1/3) sage: arg(-1+i) 3/4*pi sage: arg(2+2*i) 1/4*pi sage: arg(2+x) arg(x + 2) sage: arg(2.0+i+x) arg(x + 2.00000000000000 + 1.00000000000000*I) sage: arg(-3) pi sage: arg(3) 0 sage: arg(0) 0 sage: arg(sqrt(2)+i) arg(sqrt(2) + I) """ if not isinstance(x,Expression): # x contains no variables if is_inexact(x): # inexact complex numbers, e.g. 2.0+i return self._evalf_(x, parent(x)) else: # exact complex numbers, e.g. 2+i return arctan2(imag_part(x),real_part(x)) else: # x contains variables, e.g. 2+i+y or 2.0+i+y # or x involves an expression such as sqrt(2) return None def _evalf_(self, x, parent=None): """ EXAMPLES:: sage: arg(0.0) 0.000000000000000 sage: arg(3.0) 0.000000000000000 sage: arg(-2.5) 3.14159265358979 sage: arg(2.0+3*i) 0.982793723247329 """ try: return x.arg() except AttributeError: C = ComplexField() x = C(x) return x.arg() arg=Function_arg() ############################ # Real and Imaginary Parts # ############################
• ## sage/misc/all.py

diff --git a/sage/misc/all.py b/sage/misc/all.py
 a from functional import (additive_order, sqrt as numerical_sqrt, arg, base_ring, base_field, basis,
• ## sage/misc/functional.py

diff --git a/sage/misc/functional.py b/sage/misc/functional.py
 a """ return x.additive_order() def arg(x): """ Returns the argument of a complex number x. EXAMPLES:: sage: z = CC(1,2) sage: theta = arg(z) sage: cos(theta)*abs(z) 1.00000000000000 sage: sin(theta)*abs(z) 2.00000000000000 """ try: return x.arg() except AttributeError: return CDF(x).arg() def base_ring(x): """ Returns the base ring over which x is defined.
• ## sage/symbolic/random_tests.py

diff --git a/sage/symbolic/random_tests.py b/sage/symbolic/random_tests.py
 a sage: [f for (one,f,arity) in _mk_full_functions()] [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh, binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch, dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec, elliptic_eu, elliptic_f, elliptic_kc, elliptic_pi, erf, exp, factorial, floor, heaviside, imag_part, integrate, kronecker_delta, log, polylog, real_part, sec, sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv] arg, binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch, dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec, elliptic_eu, elliptic_f, elliptic_kc, elliptic_pi, erf, exp, factorial, floor, heaviside, imag_part, integrate, kronecker_delta, log, polylog, real_part, sec, sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv] Note that this doctest will fail whenever a Pynac function is added or removed.  In that case, it is very likely that the doctests for (euler_gamma - v3^(-e) + (v2 - factorial(-e/v2))^(((2.85879036573 - 1.18163393202*I)*v2 + (2.85879036573 - 1.18163393202*I)*v3)*pi - 0.247786879678 + 0.931826724898*I)*arccsc((0.891138386848 - 0.0936820840629*I)/v1) - (0.553423153995 - 0.5481180572*I)*v3 + 0.149683576515 - 0.155746451854*I)*v1 + arccsch(pi + e)*elliptic_f(khinchin*v2, 1.4656989704 + 0.863754357069*I) sage: random_expr(5, verbose=True) About to apply dirac_delta to [1] About to apply arccsch to [0] About to apply to [0, arccsch(0)] arccsch(0) About to apply arcsec to [0] About to apply to [0, arcsec(0)] arcsec(0) """ vars = [(1.0, sage.calculus.calculus.var('v%d' % (n+1))) for n in range(nvars)] if ncoeffs is None: