Ask Your Question

GPN's profile - activity

2024-02-11 20:32:22 +0200 received badge  Notable Question (source)
2024-02-11 20:32:22 +0200 received badge  Popular Question (source)
2024-01-05 09:44:32 +0200 received badge  Necromancer (source)
2024-01-05 09:44:32 +0200 received badge  Self-Learner (source)
2024-01-04 19:42:25 +0200 marked best answer How to collect the derivatives in an expression for a scalar field

Please consider the following example; it calculates the commutator of two vector fields acting on a scalar field, that is to say it calculates [u,v]f.

from sage.all import *

%display latex

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

u0 = function(r'u_0')(t,x,y,z)
u1 = function(r'u_1')(t,x,y,z)
u2 = function(r'u_2')(t,x,y,z)
u3 = function(r'u_3')(t,x,y,z)
u = M.vector_field(u0,u1,u2,u3, latex_name=r'\mathbf{u}')
v0 = function(r'v_0')(t,x,y,z)
v1 = function(r'v_1')(t,x,y,z)
v2 = function(r'v_2')(t,x,y,z)
v3 = function(r'v_3')(t,x,y,z)
v = M.vector_field(v0,v1,v2,v3, latex_name=r'\mathbf{v}')

f = M.scalar_field(function('f')(t,x,y,z), latex_name='f')
commutator_f = u(v(f)) - v(u(f))
commutator_f

This works. Now I can look at the expression for [u,v]f using

commutator_f.expr()

This also works but has many terms that I would like to collect - I would like all terms that are derivatives of f to "go to the right". I tried

commutator_f.expr().collect(f)

but that does not work: TypeError: no canonical coercion from Algebra of differentiable scalar fields on the 4-dimensional Lorentzian manifold M to Symbolic Ring.

How can I do this please?

Using SageMath version 9.5, Release Date: 2022-01-30, on Ubuntu 22.04.

Thank you

GPN

2023-12-24 12:28:13 +0200 answered a question 2r^2 interpreted as 2^2

Try the following code, notice the "*" I added: var('r') 2*r^2 I hope its what you want GPN

2023-12-13 17:49:54 +0200 received badge  Popular Question (source)
2023-12-09 22:25:18 +0200 received badge  Supporter (source)
2023-12-09 22:22:50 +0200 marked best answer Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

Hi Manifolds experts, and many thanks in advance for any help.

I am trying to do a simple exercise (as I thought) to understand how SageMath Manifolds "composes" transitions between maps. Actually, I was very impressed this can be done.

To do this myself, I define the usual cartesian coordinates X and spherical coordinates Y. In addition, define spherical orthonormal coordinates H.

Here is my code to set it all up:

from sage.all import *
from IPython.display import display, Math, Latex

%display latex

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

U = M.open_subset('U', coord_def={X: (y!=0, x<0)})
X_U = X.restrict(U)
display(Latex(f'$X_U = {latex(X_U)}$'))
Y.<t,r,th,ph> = U.chart(r't:(-oo,+oo) r:(0,+oo) th:(0,+pi):\theta ph:(0,2*pi):\phi')

transit_Y_to_X = Y.transition_map(X, [
    t, r*sin(th)*cos(ph), r*sin(th)*sin(ph), r*cos(th)
])

transit_Y_to_X.set_inverse(
    t, sqrt(x^2+y^2+z^2), arccos(z/sqrt(x^2+y^2+z^2)), atan2(y,x)
)

H.<t,r,th_,ph_> = U.chart(r't:(-oo,+oo) r:(0,+oo) th_:(0,+oo):\hat{θ} ph_:(0,+oo):\hat{φ}')
transit_H_to_Y = H.transition_map(Y, [
    t, r, th_/r, ph_/(r*sin(th))
])
display(transit_H_to_Y)
display(transit_H_to_Y.display())
transit_H_to_Y.inverse().display()

Then, I introduce the composed transition (the point of my exercise):

transit_H_to_X = transit_Y_to_X * transit_H_to_Y
display(transit_H_to_X)
display(transit_H_to_X.display())

transit_H_to_X.set_inverse(
    t,
    sqrt(x^2+y^2+z^2),
    r*arccos(z/sqrt(x^2+y^2+z^2)),
    r*sin(th)*atan2(y,x)
)
transit_X_to_H = transit_H_to_X.inverse()
display(transit_X_to_H)
display(transit_X_to_H.display())

and try to plot H against X:

H.plot(chart=X,
    ambient_coords=(x,y,z), fixed_coords={t:0},
    ranges={r:(1,1.1), th_:(1.1,1.2)}, number_values=3,
)

This fails with errors TypeError: cannot evaluate symbolic expression numerically. Any ideas on how I can make this work, please? What am I doing wrong?

I am using SageMath 9.5 on Ubuntu 22.04.

Thanks

GPN

2023-12-09 22:21:09 +0200 commented answer Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

First of all, many thanks for reviewing my code so thoroughly. I do believe you found a real mistake in the original set

2023-12-08 11:34:01 +0200 answered a question Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

Hi all. I think I have found an answer, but it is not a "happy" one. The crucial issue was with the line transit_H_to_

2023-12-07 19:25:26 +0200 commented question Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

@Max_Alekseyev thanks, tried that again just now. More generally I think if you do not specify a range then it will try

2023-12-07 19:13:24 +0200 received badge  Commentator
2023-12-07 19:13:24 +0200 commented question Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

@Max_Alekseyev thanks, tried that and its not the answer. More generally I think if you do not specify a range then it w

2023-12-07 17:09:50 +0200 asked a question Plotting transition-of-transition fails with "cannot evaluate symbolic expression"

Plotting transition-of-transition fails with "cannot evaluate symbolic expression" Hi Manifolds experts, and many thanks

2023-12-07 12:05:37 +0200 commented question Expression.simplify() takes no "algorithm" keyword

@dan_fulea thank you

2023-12-07 01:22:17 +0200 asked a question Expression.simplify() takes no "algorithm" keyword

Expression.simplify() takes no "algorithm" keyword Hi Sage experts. I am trying to run the following example, which is

2023-12-05 22:08:55 +0200 received badge  Nice Answer (source)
2023-12-05 16:13:47 +0200 commented answer How to collect the derivatives in an expression for a scalar field

@slelievre thanks.

2023-12-05 15:51:53 +0200 received badge  Student (source)
2023-12-05 15:51:47 +0200 received badge  Self-Learner (source)
2023-12-05 15:51:47 +0200 received badge  Teacher (source)
2023-12-05 15:40:32 +0200 answered a question How to collect the derivatives in an expression for a scalar field

Based on the advice from @max and @eric_g - the following works: commutator_f.expr() \ .collect(diff(f)[0].expr())

2023-12-05 15:38:51 +0200 commented question How to collect the derivatives in an expression for a scalar field

cool, I will try that

2023-12-04 23:32:27 +0200 commented question How to collect the derivatives in an expression for a scalar field

Thanks for the suggestion, I tried. It gets rid of the error but nothing is collected. I then also tried commutator_f.e

2023-12-04 22:39:07 +0200 asked a question How to collect the derivatives in an expression for a scalar field

How to collect the derivatives in an expression for a scalar field Please consider the following example; it calculates

2023-11-26 16:08:21 +0200 marked best answer How to express (-t^2 + x^2 + y^2 + z^2) as (x_μ)^2 ?

Hi Manifolds experts

I'm a newbie to Sage Manifolds; I find it fascinating, thanks! I have searched for the answer in the forum and documentation but so far without success.

In the code below, 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.

Also: is there a way to make the output show the denominator as something like x^2 or g[_μν] x[^μ] x[^ν] ?

Here is my code:

from sage.all import *
%display latex

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

F = M.scalar_field(1/(-t^2 + x^2 + y^2 + z^2))
dF = diff(F)
dF.apply_map(factor)
display(dF.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

2023-11-26 16:08:17 +0200 commented answer How to express (-t^2 + x^2 + y^2 + z^2) as (x_μ)^2 ?

cool! @achrzesz

2023-11-26 11:45:44 +0200 commented answer grad on a generic metric

Thank you @eric_g

2023-11-26 11:40:54 +0200 commented answer How to express (-t^2 + x^2 + y^2 + z^2) as (x_μ)^2 ?

@achrzesz thank you. That does solve the second question (how to show x^2 in the output). Is there also an answer to the

2023-11-26 09:41:36 +0200 asked a question How to express (-t^2 + x^2 + y^2 + z^2) as (x_μ)^2 ?

How to express (-t^2 + x^2 + y^2 + z^2) as (x_μ)^2 ? Hi Manifolds experts I'm a newbie to Sage Manifolds; I find it fas

2023-11-26 09:28:25 +0200 edited question differential (1-form) simplifies a bit too much

differential (1-form) simplifies a bit too much Hi Manifolds experts I am trying to calculate the total differential of

2023-11-26 09:27:47 +0200 marked best answer 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.

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

2023-11-25 16:12:30 +0200 asked a question differential (1-form) simplifies a bit too much

differential (1-form) simplifies a bit too much Hi Manifolds experts I am trying to calculate the total differential of

2023-11-21 22:13:44 +0200 received badge  Editor (source)
2023-11-21 22:13:44 +0200 edited answer Plot spines show in middle of graph

With the advice from @achrzesz and a bit more work, the correct solution is from sage.all import * from sage.numerical.

2023-11-21 22:13:13 +0200 answered a question Plot spines show in middle of graph

With the advice from @achrzesz and a bit more work, the correct solution is from sage. All import * from sage.numerical

2023-11-21 22:11:41 +0200 commented answer Plot spines show in middle of graph

Thank you! The key point was p.show(frame=True,axes=False) which put the axes outside the plot. But actually to compl

2023-11-21 22:02:32 +0200 marked best answer Plot spines show in middle of graph

Hi. I am new to SageMath. I like what I see, thanks!

I ran into a tiny but annoying problem: I draw a region_plot and it works very well, but the spines of the plot are drawn down the middle. I tried to make them go away using the standard matplotlib capabilities but they will not disappear. Here is my code:

reset()

a,b,c,x,y = var('a b c x y')

from matplotlib import spines, axes
i = 16
p = region_plot(
    tan(x^2 - y^2)>0,
    (-i*pi,+i*pi), (-i*pi,+i*pi),
    incol='green',outcol='lightblue',
)
p.matplotlib().axes[0].spines[['left', 'bottom']].set_position('zero')
p.matplotlib().axes[0].spines[['top', 'right']].set_visible(False)
p

I am using SageMath on - Ubuntu 22.04 installed in WSL - Notebook is VSCode notebook with vscode-Jupyter extension - Vscode version 1.80

The entire above code is run in a single cell

Thanks

2023-11-21 22:02:24 +0200 commented answer Plot spines show in middle of graph

Thank you! The key point was p.show(frame=True,axes=False) which put the axes outside the plot. That was good enough

2023-11-21 21:13:32 +0200 marked best answer grad on a generic metric

Hi.

First, thank you for SageMath Manifolds! I find it fascinating. I am a newbie, and I have indeed looked through the forum and the documentation, but am still stuck. So please excuse if my question is trivial in your eyes.

I am trying to write down the grad of a scalar field in a relatively generic way, but getting the error

ValueError: no common basis for the contraction

At a higher level, my goal is to prove a few basic lemmas about the grad, both as an exercise to learn Manifolds and as part of a larger project.

The following code just sets up the preliminaries and defines the metric:

# preliminaries
from sage. All import *
from sage.manifolds.operators import *
M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,x,y,z> = M.chart()
U = M.open_subset('U', coord_def={X: (y!=0, x<0)})
X_U = X.restrict(U)
F = U.scalar_field(function('f')(t,x,y,z), chart=X_U, name='F')
F.display()

# definition of metric
g = M.metric('g',)
print(g)
g[0,0] = function('g00')(t,x,y,z)
g[1,0] = g[0,1] = function('g01')(t,x,y,z)
g[2,0] = g[0,2] = function('g02')(t,x,y,z)
g[3,0] = g[0,3] = function('g03')(t,x,y,z)
g[1,1] = function('g11')(t,x,y,z)
g[1,2] = g[2,1] = function('g12')(t,x,y,z)
g[1,3] = g[3,1] = function('g13')(t,x,y,z)
g[2,2] = function('g22')(t,x,y,z)
g[2,3] = g[3,2] = function('g23')(t,x,y,z)
g[3,3] = function('g33')(t,x,y,z)
g.display()

All of the above works (thank you). But now I try to do:

grad(F)

and I get the error above.

Obviously I am missing something basic.

Thank you GPN

2023-11-21 21:13:32 +0200 received badge  Scholar (source)
2023-11-21 21:13:04 +0200 commented answer grad on a generic metric

Here is an additional find: that code is part of a bigger notebook which had the line Parallelism().set(nproc=4) Base

2023-11-21 21:12:14 +0200 commented answer grad on a generic metric

Here is an additional find: that code is part of a bigger notebook which had the line Parallelism().set(nproc=4) Base

2023-11-21 20:57:28 +0200 commented answer grad on a generic metric

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