Ticket #4498: trac_4498_arg.2.patch
File trac_4498_arg.2.patch, 7.8 KB (added by , 9 years ago) 


sage/functions/all.py
# HG changeset patch # User Karen T. Kohl <ktkohl96@gmail.com> # Date 1326306162 21600 # Node ID 9057d053c614a75ae65a5acac55106169fa7ccba # Parent 92c93226b64f933e0af00bbcbd1a8a79c444f43f Trac 4498: symbolic arg function diff git a/sage/functions/all.py b/sage/functions/all.py
a b 18 18 from other import ( ceil, floor, gamma, psi, factorial, 19 19 abs_symbolic, erf, sqrt, 20 20 gamma_inc, incomplete_gamma, 21 real_part, real,21 arg, real_part, real, 22 22 imag_part, imag, imaginary, conjugate) 23 23 24 24 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 b 19 19 from sage.symbolic.constants import pi 20 20 from sage.symbolic.function import is_inexact 21 21 from sage.functions.log import exp 22 from sage.functions.trig import arctan2 22 23 from sage.functions.transcendental import Ei 23 24 from sage.libs.mpmath import utils as mpmath_utils 24 25 … … 1326 1327 {'__call__': staticmethod(sqrt), 1327 1328 '__setstate__': lambda x, y: None}) 1328 1329 1330 class Function_arg(BuiltinFunction): 1331 def __init__(self): 1332 r""" 1333 The argument function for complex numbers. 1334 1335 EXAMPLES:: 1336 sage: arg(3+i) 1337 arctan(1/3) 1338 sage: arg(1+i) 1339 3/4*pi 1340 sage: arg(2+2*i) 1341 1/4*pi 1342 sage: arg(2+x) 1343 arg(x + 2) 1344 sage: arg(2.0+i+x) 1345 arg(x + 2.00000000000000 + 1.00000000000000*I) 1346 sage: arg(3) 1347 pi 1348 sage: arg(3) 1349 0 1350 sage: arg(0) 1351 0 1352 sage: arg(sqrt(2)+i) 1353 arg(sqrt(2) + I) 1354 sage: latex(arg(x)) 1355 \text{arg}\left(x\right) 1356 1357 TESTS:: 1358 sage: arg(3+i) 1359 arctan(1/3) 1360 sage: arg(1+i) 1361 3/4*pi 1362 sage: arg(2+2*i) 1363 1/4*pi 1364 sage: arg(2+x) 1365 arg(x + 2) 1366 sage: arg(2.0+i+x) 1367 arg(x + 2.00000000000000 + 1.00000000000000*I) 1368 sage: arg(3) 1369 pi 1370 sage: arg(3) 1371 0 1372 sage: arg(0) 1373 0 1374 sage: arg(0.0) 1375 0.000000000000000 1376 sage: arg(3.0) 1377 0.000000000000000 1378 sage: arg(2.5) 1379 3.14159265358979 1380 sage: arg(2.0+3*i) 1381 0.982793723247329 1382 sage: maxima(arg(x)) 1383 atan2(0,x) 1384 sage: maxima(arg(2+i)) 1385 atan(1/2) 1386 sage: maxima(arg(sqrt(2)+i)) 1387 atan(1/sqrt(2)) 1388 sage: arg(2+i) 1389 arctan(1/2) 1390 sage: arg(sqrt(2)+i) 1391 arg(sqrt(2) + I) 1392 sage: arg(sqrt(2)+i).simplify() 1393 arctan(1/2*sqrt(2)) 1394 1395 """ 1396 1397 BuiltinFunction.__init__(self, "arg", latex_name=r"\text{arg}", 1398 conversions=dict(maxima='carg',mathematica='Arg')) 1399 def _eval_(self, x): 1400 """ 1401 EXAMPLES:: 1402 1403 sage: arg(3+i) 1404 arctan(1/3) 1405 sage: arg(1+i) 1406 3/4*pi 1407 sage: arg(2+2*i) 1408 1/4*pi 1409 sage: arg(2+x) 1410 arg(x + 2) 1411 sage: arg(2.0+i+x) 1412 arg(x + 2.00000000000000 + 1.00000000000000*I) 1413 sage: arg(3) 1414 pi 1415 sage: arg(3) 1416 0 1417 sage: arg(0) 1418 0 1419 sage: arg(sqrt(2)+i) 1420 arg(sqrt(2) + I) 1421 1422 """ 1423 if not isinstance(x,Expression): 1424 # x contains no variables 1425 if is_inexact(x): 1426 # inexact complex numbers, e.g. 2.0+i 1427 return self._evalf_(x, parent(x)) 1428 else: 1429 # exact complex numbers, e.g. 2+i 1430 return arctan2(imag_part(x),real_part(x)) 1431 else: 1432 # x contains variables, e.g. 2+i+y or 2.0+i+y 1433 # or x involves an expression such as sqrt(2) 1434 return None 1435 1436 def _evalf_(self, x, parent=None): 1437 """ 1438 EXAMPLES:: 1439 1440 sage: arg(0.0) 1441 0.000000000000000 1442 sage: arg(3.0) 1443 0.000000000000000 1444 sage: arg(2.5) 1445 3.14159265358979 1446 sage: arg(2.0+3*i) 1447 0.982793723247329 1448 1449 """ 1450 try: 1451 return x.arg() 1452 except AttributeError: 1453 C = ComplexField() 1454 x = C(x) 1455 return x.arg() 1456 1457 arg=Function_arg() 1458 1459 1329 1460 ############################ 1330 1461 # Real and Imaginary Parts # 1331 1462 ############################ 
sage/misc/all.py
diff git a/sage/misc/all.py b/sage/misc/all.py
a b 80 80 81 81 from functional import (additive_order, 82 82 sqrt as numerical_sqrt, 83 arg,84 83 base_ring, 85 84 base_field, 86 85 basis, 
sage/misc/functional.py
diff git a/sage/misc/functional.py b/sage/misc/functional.py
a b 62 62 """ 63 63 return x.additive_order() 64 64 65 def arg(x):66 """67 Returns the argument of a complex number `x`.68 69 EXAMPLES::70 71 sage: z = CC(1,2)72 sage: theta = arg(z)73 sage: cos(theta)*abs(z)74 1.0000000000000075 sage: sin(theta)*abs(z)76 2.0000000000000077 """78 try: return x.arg()79 except AttributeError: return CDF(x).arg()80 81 65 def base_ring(x): 82 66 """ 83 67 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 b 16 16 sage: [f for (one,f,arity) in _mk_full_functions()] 17 17 [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch, 18 18 arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh, 19 binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch,20 dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec,21 elliptic_e u, elliptic_f, elliptic_kc, elliptic_pi, erf, exp,22 factorial, floor, heaviside, imag_part, integrate,23 kronecker_delta, log, polylog, real_part, sec, sech, sgn, sin,24 s inh, tan, tanh, unit_step, zeta, zetaderiv]19 arg, binomial, ceil, conjugate, cos, cosh, cot, coth, csc, 20 csch, dickman_rho, dilog, dirac_delta, elliptic_e, 21 elliptic_ec, elliptic_eu, elliptic_f, elliptic_kc, 22 elliptic_pi, erf, exp, factorial, floor, heaviside, imag_part, 23 integrate, kronecker_delta, log, polylog, real_part, sec, 24 sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv] 25 25 26 26 Note that this doctest will fail whenever a Pynac function is added or 27 27 removed. In that case, it is very likely that the doctests for … … 237 237 (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) 238 238 sage: random_expr(5, verbose=True) 239 239 About to apply dirac_delta to [1] 240 About to apply arccsch to [0] 241 About to apply <builtin function add> to [0, arccsch(0)] 242 arccsch(0) 240 About to apply arcsec to [0] 241 About to apply <builtin function add> to [0, arcsec(0)] 242 arcsec(0) 243 243 244 """ 244 245 vars = [(1.0, sage.calculus.calculus.var('v%d' % (n+1))) for n in range(nvars)] 245 246 if ncoeffs is None: