# Ticket #4498: trac_4498_arg.1.patch

File trac_4498_arg.1.patch, 5.3 KB (added by ktkohl, 9 years ago)

symbolic arg function

• ## sage/functions/all.py

# HG changeset patch
# User Karen T. Kohl <ktkohl96@gmail.com>
# Date 1326306162 21600
# 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: arg(sqrt(2)+i) arg(sqrt(2) + I) sage: latex(arg(x)) \text{arg}\left(x\right) 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 """ BuiltinFunction.__init__(self, "arg",  latex_name=r"\text{arg}", conversions=dict(maxima='arg',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.