Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

differential (1-form) simplifies a bit too much

Hi Manifolds experts

I am trying to calculate the total differential of a function F(X) = 1 / x^2 (in 4 dimensions) on a curved space time. The code below works but the denominators of the partial derivatives are expanded. It's a bit unreadable.

Question: what would be the correct way so the denominators are e.g. (x^2)^2 or any other shorter form where the terms are collected? As you can see in the code, I tried to change the simplification function but that was not enough.

Bonus question: in the code, I wrote out x^2 in full as -t^2 + x^2 + y^2 + z^2. Is there a way to write it as something like x^2 or g[_μν] x[^μ] x[^ν] ? I tried but couldn't find how and got syntax errors.

Here is my code:

from sage.all import *
from IPython.display import display, Math, Latex
from sage.manifolds.calculus_method import CalculusMethod
%display latex

M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,x,y,z> = M.chart()

cm = CalculusMethod(base_field_type='real')
cm.set_simplify_function(simplify)
display(cm)

F = M.scalar_field(1/(-t^2 + x^2 + y^2 + z^2))
display(F.display())
display(diff(F).display())

I am using SageMath version 9.5, Release Date: 2022-01-30. My OS is Ubuntu 22.04 (itself on WSL2 on Windows 11 latest).

Thank you GPN

differential (1-form) simplifies a bit too much

Hi Manifolds experts

I am trying to calculate the total differential of a function F(X) = 1 / x^2 (in 4 dimensions) on a curved space time. The code below works but the denominators of the partial derivatives are expanded. It's a bit unreadable.

Question: what would be the correct way so the denominators are e.g. (x^2)^2 or any other shorter form where the terms are collected? As you can see in the code, I tried to change the simplification function but that was not enough.

Bonus question: in the code, I wrote out x^2 in full as -t^2 + x^2 + y^2 + z^2. Is there a way to write it as something like x^2 or g[_μν] x[^μ] x[^ν] ? I tried but couldn't find how and got syntax errors.

Here is my code:

from sage.all import *
from IPython.display import display, Math, Latex
from sage.manifolds.calculus_method import CalculusMethod
%display latex

M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,x,y,z> = M.chart()

cm = CalculusMethod(base_field_type='real')
cm.set_simplify_function(simplify)
display(cm)

F = M.scalar_field(1/(-t^2 + x^2 + y^2 + z^2))
display(F.display())
display(diff(F).display())

I am using SageMath version 9.5, Release Date: 2022-01-30. My OS is Ubuntu 22.04 (itself on WSL2 on Windows 11 latest).

Thank you GPN