Simplifications and sagemanifold

77 views
Skip to first unread message

Rogerio

unread,
Sep 2, 2022, 2:09:23 AM9/2/22
to sage-support
Components of tensors in sagemanifolds are nicely simplified through methods of chart functions. However, for large and complicated expressions, such simplifications are very time consuming.
Is it possible to turn off these simplifications? I was not able to find it along the documentation.

It would be great to have something like

M = Manifold(4, 'M')
M.options.simplifications = False

If have a metric with components given by functions of `sage.calculus.var.function`, for example, it take hours to calculate the Riemann tensor. Calculating the same Riemann tensor using lists and SR, on the other hand, takes only a few seconds.

Eric Gourgoulhon

unread,
Sep 3, 2022, 11:55:33 AM9/3/22
to sage-support
Le vendredi 2 septembre 2022 à 08:09:23 UTC+2, roger...@gmail.com a écrit :
Components of tensors in sagemanifolds are nicely simplified through methods of chart functions. However, for large and complicated expressions, such simplifications are very time consuming.
Is it possible to turn off these simplifications?

Yes, via the method M.set_simplify_function. It suffices to pass a fast function as argument, like simplify. 
For instance:

sage: M = Manifold(4, 'M')
sage: X.<t,x,y,z> = M.chart()
sage: M.set_simplify_function(simplify)

NB: the call to M.set_simplify_function must be done after the chart(s) have been defined. It can also be done chartwise, via
X.calculus_method().set_simplify_function(simplify)

See
for details.

Best wishes,

Eric.

Rogerio

unread,
Sep 4, 2022, 1:35:18 AM9/4/22
to sage-support
Thank you very much Eric! It works perfectly well for my needs.
I've tested the time spent for calculating the Riemann tensor (restarting the kernel to avoid cache) for three different simplifying methods: the standard, the simplify, and a function that just returns the expression. It makes a huge difference.

For the Kerr-Newman metric, without simplification is ~500x faster (considering the wall time).

- default
CPU times: user 5min 6s, sys: 4.16 s, total: 5min 10s
Wall time: 3min

- simplify
CPU times: user 40.1 s, sys: 359 ms, total: 40.4 s
Wall time: 27.3 s

- no simplification
CPU times: user 468 ms, sys: 785 µs, total: 468 ms
Wall time: 340 ms


For the metric given by

[-1, 0, 0, 0]
[0, h11(t, r, th, ph), h12(t, r, th, ph), h13(t, r, th, ph)]
[0, h12(t, r, th, ph), h22(t, r, th, ph), h23(t, r, th, ph)]
[0, h13(t, r, th, ph), h23(t, r, th, ph), h33(t, r, th, ph)]

the results are more even impressive. No simplification is ~4000x faster.

- default
CPU times: user 40min 26s, sys: 17.9 s, total: 40min 43s
Wall time: 31min 29s

- simplify
CPU times: user 3min 10s, sys: 978 ms, total: 3min 11s
Wall time: 2min 44s

- no simplification
CPU times: user 715 ms, sys: 14.2 ms, total: 729 ms
Wall time: 573 ms

Best wishes,

Rogerio

Eric Gourgoulhon

unread,
Sep 4, 2022, 11:49:11 AM9/4/22
to sage-support
Thank you for these instructive benchmarks!

Best wishes,

Eric. 

Reply all
Reply to author
Forward
0 new messages