Transforming a complex function f:C->C into a function g:R^2->R^2

24 views
Skip to first unread message

Robert Jacobson

unread,
May 1, 2017, 2:43:32 PM5/1/17
to sage-support
I am wanting to hand off a holomorphic function to an external library, but the library only works with real numbers (operations with C++ doubles). Thus I wish to have Sage compute functions u and v for which f(x+i y) = u(x,y) + i v(x,y) such that u and v are expressed only in terms of operations on real numbers, i.e., without the imaginary unit i. I am impressed by how far I can get by simply calling f(x+i y).real_part(), but abs(x+I*y) is not rewritten as sqrt(x+I*y). A simple example session to illustrate:

sage: y, z = var('y, z')
sage: assume(x, 'real')
sage: assume(y, 'real')
sage: abs(x+I*y)
abs(x + I*y)
sage: abs(x+I*y).real_part()
abs(x + I*y)
sage: norm(x+I*y)
x^2 + y^2
sage: log(x+I*y).real_part()
log(abs(x + I*y))
sage: sin(x+I*y).real_part()
cosh(y)*sin(x)

Is there a simple way to do what I am trying to do? Perhaps by asking Sage to replace abs(z) with sqrt(norm(z))?

Best,

Robert

Dominique Laurain

unread,
May 1, 2017, 3:31:12 PM5/1/17
to sage-support
Hello Robert,

I wonder why you want to use the "abs()" function, when the "absolute value" function has no meaning for complex numbers.
How you define the 'greater than' (>)  operator in complex numbers ?
It is hazardous to mix symbolic computing (var, sqrt,..language) and field operators....because off the scene, symbolic expressions have their own operators.
Yes : if you take norm(z) where z is a complex field element you get a real number...and then you can use abs() function (because ordered field).

Dominique

Robert Jacobson

unread,
May 1, 2017, 4:04:43 PM5/1/17
to sage-support


On Monday, 1 May 2017 15:31:12 UTC-4, Dominique Laurain wrote:
I wonder why you want to use the "abs()" function, when the "absolute value" function has no meaning for complex numbers.

The modulus of a complex number z is often called the absolute value of z and is typeset as |z|. The definition of this operation is |z|=sqrt(x^2+y^2) which you will recognize as the Euclidean distance on the complex plane between the origin and z, or the L^2 norm of z viewed as a vector in R^2. This terminology and notation are standard in the subject. Observe that insofar as this definition goes, no reference is made to the field properties of the complex numbers as such (although see below).

In computer algebra systems, the modulus of a complex number z is denoted almost universally using the same notation as the absolute value of a real number.
 
How you define the 'greater than' (>)  operator in complex numbers ?
It is hazardous to mix symbolic computing (var, sqrt,..language) and field operators....because off the scene, symbolic expressions have their own operators.
Yes : if you take norm(z) where z is a complex field element you get a real number...and then you can use abs() function (because ordered field).

In the case of abs(z), z complex, there is a convenient connection between abs(z) and norm(z), but you have it backwards: it's the norm(z) function, defined as the field norm of z, that is defined in terms of the field properties of the complex numbers in Sage. The field norm of a complex number is just it's product with it's conjugate! So abs(z) = sqrt(norm(z)).

In my particular problem, I'm not choosing abs(z). Rather, Sage sometimes produces abs(z) when I ask for the real part of an expression. Consider:

sage: y = var('y')
sage: assume(x, 'real')
sage: assume(y, 'real')
sage: log(x+I*y).real_part()
log(abs(x + I*y))


Best,

Robert

Dominique Laurain

unread,
May 1, 2017, 5:29:10 PM5/1/17
to sage-support
OK Robert : I misunderstood.
I cannot help either 
Dominique
Reply all
Reply to author
Forward
0 new messages