Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a symbolic version of the arg function #4498

Closed
TimothyClemans mannequin opened this issue Nov 11, 2008 · 36 comments
Closed

Implement a symbolic version of the arg function #4498

TimothyClemans mannequin opened this issue Nov 11, 2008 · 36 comments

Comments

@TimothyClemans
Copy link
Mannequin

TimothyClemans mannequin commented Nov 11, 2008

It would be nice if there were a symbolic arg function, just like the symbolic sin, cos, etc., functions. Then the following would happen:

sage: f = arg(x); f
arg(x)
sage: f.subs(x=1+I)
arg(1+I)

Now we have

sage: arg(1+I)
0.785398163397
sage: type(arg(1+I))
<type 'sage.rings.real_double.RealDoubleElement'>

I.e., the arg in Sage is currently the numerical person's arg, not the symbolic person's. It just casts to CDF.

"The function should return the argument of a complex function." - Ronan Paixão

Apply

CC: @kcrisman @sagetrac-ktkohl

Component: symbolics

Keywords: sd35.5

Author: Karen Kohl, Burcin Erocal

Reviewer: Karl-Dieter Crisman, Burcin Erocal

Merged: sage-5.0.beta4

Issue created by migration from https://trac.sagemath.org/ticket/4498

@TimothyClemans TimothyClemans mannequin added this to the sage-3.2.1 milestone Nov 11, 2008
@TimothyClemans
Copy link
Mannequin Author

TimothyClemans mannequin commented Nov 11, 2008

comment:1
arg(x)
///

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/home/ronan/.sage/sage_notebook/worksheets/admin/0/code/127.py",
line 6, in <module>
   exec compile(ur'arg(x)' + '\n', '', 'single')
 File
"/home/ronan/progs/sage/local/lib/python2.5/site-packages/ZODB3-3.7.0-py2.5-linux-i686.egg/", line 1, in <module>

 File
"/home/ronan/progs/sage/local/lib/python2.5/site-packages/sage/misc/functional.py", line 67, in arg
   except AttributeError: return CDF(x).arg()
 File "complex_double.pyx", line 286, in
sage.rings.complex_double.ComplexDoubleField_class.__call__
(sage/rings/complex_double.c:3324)
 File
"/home/ronan/progs/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py", line 1454, in _complex_double_
   raise TypeError
TypeError

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Nov 12, 2008

comment:2

Please post a complete session. As is the above is not very clear.

Cheers,

Michael

@williamstein

This comment has been minimized.

@williamstein williamstein removed this from the sage-3.2.1 milestone Nov 12, 2008
@williamstein williamstein changed the title The argument function does not work with variables. Implement a symbolic version of the arg function; the current one is only for actual numbers Nov 12, 2008
@sagetrac-ronanpaixao
Copy link
Mannequin

sagetrac-ronanpaixao mannequin commented Nov 15, 2008

comment:4

Is this really an enchancement? As it is, just using arg(x) already raises an error and everything that needs arg() must be implemented numerically.

@williamstein
Copy link
Contributor

comment:5

Is this really an enchancement? As it is, just using arg(x) already
raises an error and everything that needs arg() must be implemented numerically.

Yes, this is an enhancement since it is implementing new functionality.
It would be a bug fix if there were a bug in the existing arg function, where it produced invalid results on supported input.

-- William

@burcin
Copy link

burcin commented May 27, 2010

comment:7

This was also reported in #6220. I will close that as duplicate.

@burcin burcin changed the title Implement a symbolic version of the arg function; the current one is only for actual numbers Implement a symbolic version of the arg function May 27, 2010
@sagetrac-ktkohl
Copy link
Mannequin

sagetrac-ktkohl mannequin commented Jan 11, 2012

Changed keywords from none to sd35.5

@sagetrac-ktkohl
Copy link
Mannequin

sagetrac-ktkohl mannequin commented Jan 12, 2012

symbolic arg function

@sagetrac-ktkohl
Copy link
Mannequin

sagetrac-ktkohl mannequin commented Jan 12, 2012

comment:10

Attachment: trac_4498_arg.1.patch.gz

@sagetrac-ktkohl
Copy link
Mannequin

sagetrac-ktkohl mannequin commented Jan 12, 2012

Author: Karen T. Kohl

@kcrisman
Copy link
Member

Reviewer: Karl-Dieter Crisman

@kcrisman
Copy link
Member

comment:11

There are a few small formatting issues, and it would be good to add an example showing that arg(sqrt(2)+i) remaining symbolic (as opposed to arctan(1/sqrt(2))) still evaluates correctly numerically. Otherwise looks fine. Currently running tests, as arg is likely used in a lot of places in Sage...

@kcrisman
Copy link
Member

comment:12

File "/Users/karl-dietercrisman/Downloads/sage-4.8.alpha5/devel/sage-main/sage/symbolic/random_tests.py", line 16:
    sage: [f for (one,f,arity) in _mk_full_functions()]
Expected:
    [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]
Got:
    [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh, 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]
**********************************************************************
File "/Users/karl-dietercrisman/Downloads/sage-4.8.alpha5/devel/sage-main/sage/symbolic/random_tests.py", line 238:
    sage: random_expr(5, verbose=True)
Expected:
    About to apply dirac_delta to [1]
    About to apply arccsch to [0]
    About to apply <built-in function add> to [0, arccsch(0)]
    arccsch(0)
Got:
    About to apply dirac_delta to [1]
    About to apply arcsec to [0]
    About to apply <built-in function add> to [0, arcsec(0)]
    arcsec(0)

@kcrisman
Copy link
Member

comment:13

I think the Maxima translation may not be correct.


 -- Function: carg (<z>)
     Returns the complex argument of <z>.  The complex argument is an
     angle `theta' in `(-%pi, %pi]' such that `r exp (theta %i) = <z>'
     where `r' is the magnitude of <z>.

     `carg' is a computational function, not a simplifying function.

     See also `abs' (complex magnitude), `polarform', `rectform',
     `realpart', and `imagpart'.

     Examples:

          (%i1) carg (1);
          (%o1)                           0
          (%i2) carg (1 + %i);
                                         %pi
          (%o2)                          ---
                                          4
          (%i3) carg (exp (%i));
          (%o3)                           1
          (%i4) carg (exp (%pi * %i));
          (%o4)                          %pi
          (%i5) carg (exp (3/2 * %pi * %i));
                                          %pi
          (%o5)                         - ---
                                           2
          (%i6) carg (17 * exp (2 * %i));
          (%o6)                           2


(%o3)                                true

See also Barton Willis' parg, though that only works if having loaded to_poly_solve.

@burcin
Copy link

burcin commented Feb 7, 2012

Changed reviewer from Karl-Dieter Crisman to Karl-Dieter Crisman, Burcin Erocal

@kcrisman
Copy link
Member

kcrisman commented Feb 7, 2012

comment:18

It doesn't appear that you messed anything up, except ...

sage: arg(3.0)
---------------------------------------------------------------------------
<snip>
   1426             return x.arg()
   1427         except AttributeError:
-> 1428             from sage.rings.complex_field import CC
   1429             x = CC(x)
   1430             return x.arg()

ImportError: cannot import name CC

So apparently that won't work. Otherwise the changes are fine.

@burcin
Copy link

burcin commented Feb 7, 2012

Attachment: trac_4498-arg_evalf.patch.gz

@burcin
Copy link

burcin commented Feb 7, 2012

comment:19

Apparently I didn't run tests, latex output was also broken.

attachment: trac_4498-arg_evalf.patch, to be applied after attachment: trac_4498-symbolic_arg.cleanup.patch, implements a new _evalf_() function which keeps the precision of the input. This one needs a real review. :)

@burcin

This comment has been minimized.

@burcin
Copy link

burcin commented Feb 7, 2012

Changed author from Karen T. Kohl to Karen T. Kohl, Burcin Erocal

@kcrisman
Copy link
Member

kcrisman commented Feb 7, 2012

comment:20

This makes a lot more sense. Running tests...

Why parent_d and not parent? Just wondering in case there is a convention I should be aware of.

@burcin
Copy link

burcin commented Feb 7, 2012

comment:21

Using parent as the name of the keyword argument masks the imported parent() function, which I used in the function body.

@burcin burcin added this to the sage-5.0 milestone Feb 7, 2012
@kcrisman
Copy link
Member

kcrisman commented Feb 7, 2012

comment:22

I wondered; that makes sense.

All looks well. Just a question - do you want to include any of the following as tests?

sage: arg(long(1000))
0
sage: arg(1j)
1.57079632679490
sage: arg(1J)
1.57079632679490
sage: arg(complex(0,1))
1.57079632679490
sage: arg(complex(1,0))
0.000000000000000
sage: arg(int(10))
0

It's not a big deal to me either way, I just wanted to test them.

@jdemeyer
Copy link

comment:23

This patch conflicts with #9130. Either this one or #9130 should be rebased.

@jdemeyer
Copy link

Changed work issues from random tests, Maxima to none

@jdemeyer
Copy link

Merged: sage-5.0.beta4

@fchapoton
Copy link
Contributor

Changed author from Karen T. Kohl, Burcin Erocal to Karen Kohl, Burcin Erocal

@fchapoton
Copy link
Contributor

comment:26

standard form for name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants