# Multiplication of tensor elements

First, without tensor fields:

reset()
H=function('H',imag_part_func=0)(x)
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
print(result)


This gives the result: -1/2*H(x)

However, when term1 and term2 are the elements of tensors as in

reset()
Man=Manifold(4, 'Man', r'\mathcal{M}')
BL.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
H=function('H',imag_part_func=0)(x)
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
T1=Man.tensor_field(0,1,[0,0,term1,0])
T2=Man.tensor_field(0,1,[0,0,term2,0])
result=T1[2]*T2[2]
print(result)


I get, 1/2*I*H(x)

I need to get -1/2*H(x) as in the first case. I can solve my problem by using .expr() for the elements of the tensor:

reset()
Man=Manifold(4, 'Man', r'\mathcal{M}')
BL.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
H=function('H',imag_part_func=0)(x)
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
T1=Man.tensor_field(0,1,[0,0,term1,0])
T2=Man.tensor_field(0,1,[0,0,term2,0])
print(result)


But is there a way to get the result I needed without .expr()? I think I am missing something about the tensor fields.

edit retag close merge delete

1

Compare with this version

from sage.manifolds.utilities import simplify_sqrt_real
H=function('H',imag_part_func=0)()
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
simplify_sqrt_real(term1*term2)

1/2*abs(H())

Man=Manifold(4, 'Man', r'\mathcal{M}')
BL.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
H=function('H',imag_part_func=0)()
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
T1=Man.tensor_field(0,1,[0,0,term1,0])
T2=Man.tensor_field(0,1,[0,0,term2,0])
T1[2]*T2[2]

1/2*abs(H())

( 2023-07-09 09:53:39 +0100 )edit

Thank you. When I try the following:

from sage.manifolds.utilities import simplify_sqrt_real
H=function('H',imag_part_func=0)(x)
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
result=simplify_sqrt_real(term1*term2)


I get 1/2*I*H(x). Without canonicalize_radical(), I get 1/2*sqrt(-H(x))*sqrt(H(x)). So, the sqrt simplification of SageManifolds is the origin of my problem, right?

( 2023-07-09 10:06:02 +0100 )edit
1

Notice that canonicalize_radical is not always right. In this case the sign of H is needed to simplify. What is worse, Sage is not good when some assumptions are needd, especially in functions definitions. I belive that SageManifolds is right in my code. Presence of x in your code makes a difference.

( 2023-07-09 10:39:25 +0100 )edit

Thank you. Is there a way to set assumptions that yield my desired result -1/2*H(x)?

( 2023-07-09 10:57:53 +0100 )edit
1

The problem is that SageManifolds and canonicalize_radical make different choice of square root. I think that your method of using expr to force the canonicalize_radical choice is OK (but not in accordance with SageManifolds)

( 2023-07-09 12:01:32 +0100 )edit

Sort by ยป oldest newest most voted

Try this version:

reset()
Man=Manifold(4, 'Man', r'\mathcal{M}')
BL.<t,r,th,ph> = Man.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
H=BL.function('H')(t,r,th,ph)
assume (H<0)
term1=(1/2)*sqrt(2)*sqrt(I*H)
term2=(1/2)*sqrt(2)*sqrt(-I*H)
T1=Man.tensor_field(0,1,[0,0,term1,0])
T2=Man.tensor_field(0,1,[0,0,term2,0])
res=T1[2]*T2[2]
res

-1/2*H

more

@achrzesz, thank you!

( 2023-07-11 19:53:29 +0100 )edit

Last question: Is there a way to define the function H as a differentiable function (i.e. diff(H,r) is not zero) of only the coordinate r, not all t, r, th, ph?

( 2023-07-12 10:04:32 +0100 )edit