Using xCoba efficiently

1,090 views
Skip to first unread message

Barry Wardell

unread,
Mar 25, 2010, 10:48:50 AM3/25/10
to xAct Tensor Computer Algebra
Hi,

I want to use xCoba to compute the components of symmetric objects which are recursively defined in terms of combinations of partial derivatives of the metric. As a specific example, I would like to compute the components in Schwarzschild of things like the following:

definitions.png

I have managed to do so but not in a very clever or efficient way. I use IndexSet[..., ToCanonical[Symmetrize[...]]] to define each object, then convert them to the Schwarzschild basis using ToBasis[B][ToBasis[B][...]] and set the Christoffel terms that appear to 0. I then used ToValues[TraceBasisDummy[ComponentArray[...]]] to actually compute the components.

I am sure that this is not the best way to do it and would like to find a more efficient way, preferably taking advantage of the amount of symmetry to reduce the number of necessary calculations. I have looked at the examples and at xCoba.nb and found there are several possible ways to proceed. The quickest in terms of computation time seems to be the "New code" in section 5.3 of xCoba.nb, but that involves a lot of manual loops. Is there anything in xCoba that does this in a more automated way?

What would be the best approach to do this calculation with xCoba?

Regards,
Barry
definitions.png

magma

unread,
Mar 25, 2010, 11:51:05 AM3/25/10
to xAct Tensor Computer Algebra
I cannot see the definitions.png
Could you post it again please?

On Mar 25, 3:48 pm, Barry Wardell <barry.ward...@aei.mpg.de> wrote:
> Hi,
>
> I want to use xCoba to compute the components of symmetric objects which
> are recursively defined in terms of combinations of partial derivatives
> of the metric. As a specific example, I would like to compute the
> components in Schwarzschild of things like the following:
>

Barry Wardell

unread,
Mar 25, 2010, 1:53:44 PM3/25/10
to xa...@googlegroups.com
On 25/03/2010 16:51, magma wrote:
> I cannot see the definitions.png
> Could you post it again please?
>
>
Sorry, I thought I had attached the image, but must have forgotten to do
so. The image is attached now, or the Latex equivalent is:

A3_{a b c} &=& g_{(a b ,c)}\\
A4_{a b c d} &=& A3_{(a b |\rho} A3_{\tau| c d)} g^{\rho \tau} + A3_{(b
c d , a)} \\
& &+ A3_{(a b |\rho|} g_{c d ),\tau}g^{\rho \tau} + g_{(a b ,|\rho|}
g_{c d) ,\tau} g^{\rho \tau}

Barry

definitions.png

magma

unread,
Mar 25, 2010, 3:23:12 PM3/25/10
to xAct Tensor Computer Algebra
I would suggest that you post the xAct code that you used so far.
This would help/accelerate the development of an (eventual)
improvement.

Barry Wardell

unread,
Mar 25, 2010, 3:56:02 PM3/25/10
to xa...@googlegroups.com
> To unsubscribe from this group, send email to xact+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
>
OK, here's the basic structure of the code I'm using. The slowest parts
are the ToBasis[] and TraceBasisDummy[] lines. This code isn't too bad,
but when I try to go further, defining new objects with more indices in
terms of A3 and A4, it doesn't scale well and quickly becomes very
computationally expensive.

<< xAct`xCoba`
$Info = False;
$CVVerbose = False;
$PrePrint = ScreenDollarIndices;
<< xAct`ShowTime1`
$ShowTimeThreshold = 0.1;
DefManifold[M, 4, IndexRange[a, q]];
DefMetric[-1, metric[-a, -b], CD, {";", "D"}, PrintAs -> "g"];
DefTensor[t[], TangentM]; DefTensor[
r[], TangentM]; DefTensor[\[Theta][], TangentM]; DefTensor[\[Phi][], \
TangentM];
DefChart[B, M, {0, 1, 2, 3}, {t[],
r[], \[Theta][], \[Phi][]}]; DefConstantSymbol[Mass, PrintAs -> "M"];
metricarray = {
{-(1 - (2 Mass )/r[]), 0, 0, 0},
{0, (1 - (2 Mass )/r[])^-1, 0, 0},
{0, 0, r[]^2, 0},
{0, 0, 0, r[]^2 Sin[\[Theta][]]^2}
};
MetricInBasis[metric, -B, metricarray];
MetricCompute[metric, B, All, CVSimplify -> Simplify];

DefTensor[A3[-a, -b, -c], M, Symmetric[{-a, -b, -c}]];

IndexSet[A3[-a_, -b_, -c_],
ToCanonical[ Symmetrize[PD[-c][metric[-a, -b]],
IndexList[-a, -b, -c]]]];

DefTensor[A4[-a, -b, -c, -d], M, Symmetric[{-a, -b, -c, -d}]]

IndexSet[A4[-a_, -b_, -c_, -d_],
ToCanonical[
Symmetrize[ A3[-a, -b, -e] A3[-f, -c, -d] metric[e, f] +
PD[-a][A3[-b, -c, -d]] +
A3[-a, -b, -e] PD[-f][metric[-c, -d]] metric[e, f] +
PD[-e][metric[-a, -b]] metric[e, f] PD[-f][metric[-c, -d]],
IndexList[-a, -b, -c, -d]]]];

ToBasis[B][ToBasis[B][ A4[-a, -b, -c, -d] ]] /. ChristoffelPDB[_, _, _]
-> 0;

ComponentArray[%];

TraceBasisDummy[%];

ToValues[%]

JMM

unread,
Mar 25, 2010, 4:13:53 PM3/25/10
to xAct Tensor Computer Algebra
Hi Barry,

There is no general algorithm to manipulate components which is always
faster than the rest. For example, depending on whether your arrays of
components are sparse or not, it might be better to work with abstract
representations of the tensors (linear combinations of Basis objects)
or looping through dense arrays of components. The amount of symmetry
in your expressions is also highly relevant.

Hence, our goal so far in xCoba has been to provide enough tools to do
any computation, in any way you might find more efficient or clearer,
and only very recently black-box algorithms like MetricCompute have
been added, to perform very specific standard tasks.

Your problem seems general enough so that I don't see a simple trick
to accelerate the computation for general metrics. However, just by
looking at your expression, I would recommend you to do this, more or
less :

- Think first how many derivatives of the metric you will want to
compute. Compute them in a given chart/frame first and simplify the
results as much as possible. For general metrics this simplification
step could take most of the time of the whole computation. Store those
simplified results, to avoid recomputation, as components of tensors
Dg, DDg, DDDg, etc with appropriate symmetries, and all with lower
indices. Use the command RuleToSet.

- Manipulate your expressions with xTensor, and simplify with
ToCanonical. Replace the derivatives PD[g] by Dg and then use ToBasis.
In this way you will avoid ToBasis worrying about whether the
derivatives are compatible with your frame. At this step you still
have dummy b-indices. Be careful if you use non-coordinated frames.

- Select a set of independent components of the tensor An you want to
compute and compute/store only those.

- Then use TraceBasisDummy on those independent components. The
components of D..Dg will be automatically replaced by their values
(because of RuleToSet). Finally use Simplify.

- Something which is not clear to me is whether it is better to use
Symmetrize at the beginning or at the end. You seem to use it at the
beginning, but it actually could be better to do it at the end if your
expressions get too complicated. I'm not sure.

Try these suggestions, and if you still feel unhappy, send an example
to me, as suggested by Alessandro.

Cheers,
Jose.

On Mar 25, 3:48 pm, Barry Wardell <barry.ward...@aei.mpg.de> wrote:

> Hi,
>
> I want to use xCoba to compute the components of symmetric objects which
> are recursively defined in terms of combinations of partial derivatives
> of the metric. As a specific example, I would like to compute the
> components in Schwarzschild of things like the following:
>

JMM

unread,
Mar 30, 2010, 6:01:57 AM3/30/10
to xAct Tensor Computer Algebra
Dear Barry,

I had a look at your code, and I see that the ToBasis step is slow.
This is essentially because you are introducing an irrelevant
derivative in the problem, namely PD, whose influence you are later
forced to remove with the instruction ChristoffelPDB[_, _, _]-> 0.
Note that ChristoffelPDB is, by definition, the Christoffel connecting
the derivatives PDB and PD. If you define your expressions An directly
using PDB instead of PD then you don't need Christoffels, and the
computation is 20 times faster for A4 already.

A second thing is that you use ComponentArray before TraceBasisDummy.
Because the initial expression has dummies, TraceBasisDummy will have
to do the same job as many times as the number of components of the
array produced by ComponentArray. If you swap the use of those two
commands (simply reorder the lines you wrote), then it is considerably
faster.

Finally, I still think that the key to make this type of computation
faster is to precompute all derivatives of the metric and store them
in tensors Dn, and at the same time make the abstract PDB derivatives
of the metric get automatically converted into these tensors. That
means that the An expressions will be linear combinations of
contractions of Dn tensors. If you precompute upper and lower
components of these Dn tensors you also save much work to
TraceBasisDummy. All this, in combination with RuleToSet (to avoid
using ToValues), could make this computation reasonably fast from the
tensorial point of view. Of course, if the expressions you get after
using the form of the metric are large, then the time taken by
Simplify at the very end could be enormous, so that you have to think
of a guided strategy for simplification.

This is a good example of how component computations, though
conceptually straightforward, can become unmanageable if one does not
use little tricks. Let me emphasise again that xCoba aims to provide
the individual tools you need to perform generic computations in the
way you want, but does not try to decide which way is best. That would
be too difficult, I think.

Cheers,
Jose.

Barry Wardell

unread,
Mar 30, 2010, 7:03:34 AM3/30/10
to xa...@googlegroups.com
Hi Jose,

Thank you for two very detailed and helpful sets of advice. I have been working on this for the past few days, taking your previous advice into account and trying various approaches. Based on your suggestions, I am now using the following approach which is much better than before:
  1. I added "DDDMetric" and "DDDDMetric" which calculates components of higher derivatives of the metric. These use the "New Code" approach of xCoba.nb and are computed using MetricCompute[...] in a fraction of a second, so very quickly.
  2. I recursively define A3[-a,-b,-c], A4[-a,-b,-c,-d], etc. as before:


  1. DefTensor[A3[-a, -b, -c], M, Symmetric[{-a, -b, -c}]];
  1. IndexSet[A3[-a_, -b_, -c_], ToCanonical[-1/4 Symmetrize[PD[-c][metric[-a, -b]], IndexList[-a, -b, -c]]]];

  2. I use RuleToSet[...] on everything I need.
  3. I convert all derivatives of the metric to their D...Metric versions:

    Replace[..., {PD[-f_][PD[-e_][PD[-d_][PD[-c_][metric[-a_, -b_]]]]] :>
        PDBPDBPDBPDBmetric[-a, -b, -c, -d, -e, -f],
       PD[-e_][PD[-d_][PD[-c_][metric[-a_, -b_]]]] :>
        PDBPDBPDBmetric[-a, -b, -c, -d, -e],
       PD[-d_][PD[-c_][metric[-a_, -b_]]] :> PDBPDBmetric[-a, -b, -c, -d],
        PD[-c_][metric[-a_, -b_]] :> PDBmetric[-a, -b, -c]}];

  4. I use ToBasis[B][...] on the result.
  5. Finally, I apply TraceBasisDummy to each term independently since it is faster:

    TraceBasisDummy /@ %
The bottlenecks now are in steps 2 and 6. Step 2 suffers from the symmetrization when I have a large number of indices (e.g. A6). Step 6 is slowed down by terms of the form:

PD[-f][A3[-a, -b, -c]] metric[f, g] PD[-g][metric[-d, -e]]

where the contraction with the metric is causing extra slowdown.

I am now trying to improve things further. For step 2, I am trying to avoid the IndexSet part and instead computing the components of each of the A3, A4, ... using the same method as step 1. For step 6, I will try precomputing upper components of the D...Metric to avoid extra contractions with the metric.

I should also mention that right now I'm just looking at components for Schwarzschild. In this case, the tensors are very sparse. For example, the metric has only 4 non-zero components out of 16. Even better, DDDDMetric has only 5 non-zero independent components out of 4096! I guess this means that TraceBasisDummy is wasting a lot of time multiplying by zero, so I wonder if a more manual version would give a large speed up.

I will let you know when I make further progress.

Thanks,
Barry

JMM

unread,
Mar 30, 2010, 7:36:33 AM3/30/10
to xAct Tensor Computer Algebra
Hi again,

> I should also mention that right now I'm just looking at components for
> Schwarzschild. In this case, the tensors are very sparse. For example,
> the metric has only 4 non-zero components out of 16. Even better,
> DDDDMetric has only 5 non-zero independent components out of 4096! I
> guess this means that TraceBasisDummy is wasting a lot of time
> multiplying by zero, so I wonder if a more manual version would give a
> large speed up.

When this is the case you should consider manipulating tensors in the
abstract way. For instance if a contravariant tensor with m indices in
dimension n has m^n components, but only the first one is nonzero and
equal to 7 in the basis B, then it is better to write it as 7
Basis[{1,-B}, a1] ... Basis[{1, -B}, am] instead of manipulating
arrays or lists of rules. How to switch between the different forms is
explained in the second part of the KerrNewmanExamples.nb notebook,
that you can download from the xCoba webpage.

Cheers,
Jose.

Barry Wardell

unread,
Mar 31, 2010, 10:29:06 AM3/31/10
to xa...@googlegroups.com
On 30/03/2010 12:36, JMM wrote:
> Hi again,
>
>
>> I should also mention that right now I'm just looking at components for
>> Schwarzschild. In this case, the tensors are very sparse. For example,
>> the metric has only 4 non-zero components out of 16. Even better,
>> DDDDMetric has only 5 non-zero independent components out of 4096! I
>> guess this means that TraceBasisDummy is wasting a lot of time
>> multiplying by zero, so I wonder if a more manual version would give a
>> large speed up.
>>
> When this is the case you should consider manipulating tensors in the
> abstract way. For instance if a contravariant tensor with m indices in
> dimension n has m^n components, but only the first one is nonzero and
> equal to 7 in the basis B, then it is better to write it as 7
> Basis[{1,-B}, a1] ... Basis[{1, -B}, am] instead of manipulating
> arrays or lists of rules. How to switch between the different forms is
> explained in the second part of the KerrNewmanExamples.nb notebook,
> that you can download from the xCoba webpage.
>
Yes, this looks exactly like the approach I'd like to use in this case,
thanks. I'll try it out and let you know how I get on.

Barry

Reply all
Reply to author
Forward
0 new messages