ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 30 Jun 2020 08:57:16 +0200Simplifying symbolic complex normhttps://ask.sagemath.org/question/52265/simplifying-symbolic-complex-norm/Sage's simplifier seems to have trouble expanding the square-absolute value of complex numbers:
sage: x,y = var('x,y', domain=RR)
sage: (x^2 + y^2 - abs(x + i*y)^2).simplify_full ()
x^2 + y^2 - abs(x + I*y)^2
How can I ensure sage expands the square-absolute value and simplify this down to zero? I'm aware that using `(x + i*y).norm()` instead of `abs(x + i*y)^2` helps in this particular example, but that solution doesn't generalize. For instance, when I stick expressions involving `x`, `y` into vectors and compute the vector norm, the vector norm is expressed in terms of absolute values, so I still need a way to deal with the `abs`.JunTue, 30 Jun 2020 08:57:16 +0200https://ask.sagemath.org/question/52265/Importing Sage functions into Cython?https://ask.sagemath.org/question/42277/importing-sage-functions-into-cython/ I am trying to define variables in Cython part of my code like this
a,b,c = var('a,b,c')
But in this line I cant import var() function from Sage
from sage.calculus.var import var
I got this error:
$ sage -python real_sage.sage
Compiling ./real_sage.spyx...
Traceback (most recent call last):
File "real_sage.sage", line 6, in <module>
from real_sage import foo
File "real_sage.pyx", line 10, in init real_sage
File "sage/calculus/var.pyx", line 6, in init sage.calculus.var
File "/home/tunamustafakemal/sega/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function_factory.py", line 15, in <module>
from sage.symbolic.function import SymbolicFunction, sfunctions_funcs, \
File "sage/rings/integer.pxd", line 7, in init sage.symbolic.function
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer
File "sage/rings/rational.pyx", line 89, in init sage.rings.rational
File "sage/rings/real_mpfr.pyx", line 1, in init sage.rings.real_mpfr
File "sage/rings/complex_number.pxd", line 6, in init sage.libs.mpmath.utils
File "sage/rings/complex_double.pxd", line 10, in init sage.rings.complex_number
File "sage/rings/complex_double.pyx", line 94, in init sage.rings.complex_double
ImportError: cannot import name complex_number
Thanks for any support.tunaMon, 07 May 2018 06:14:53 +0200https://ask.sagemath.org/question/42277/Complex argument of an algebraic numberhttps://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/This question is closely related to [that question here](http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression). Basically I'd like to know whether there is a way to compute an *accurate symbolic expression* for the argument of an algebraic number.
That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:
sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
I know a few cases which will work.
sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
This however will break if the real or imaginary part were to contain any square roots.
sage: CC(z).arg()
0.588002603547568
This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.
I have the impression that `atan2` attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to `atan2` instead, for the cases where the argument is not an algebraic number. Can this be done?MvGFri, 02 Nov 2012 12:42:21 +0100https://ask.sagemath.org/question/9497/