Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

For example:

{t,z,x,y,w}::Coordinate.
{\mu,\nu,\rho,\sigma,\alpha,\beta,\gamma,\lambda,\tau,\pi,\xi,\iota,\omega,\kappa,\psi,\epsilon,\upsilon,p}::Indices(values={t,z,x,y,w},position=independent).
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.
metric:=[g_{t t}=-E**{2A} g z**{-2},g_{z z}=E**{2A} g**{-1} z**{-2},g_{x x}=E**{2A+\chi} z**{-2},g_{y y}=E**{2A} z**{-2},g_{w w}=E**{2A} z**{-2}];
complete(_,$g^{\mu\nu}$);
F:={F_{t t}=0,F_{t z}=-\partial_{z}{A_{t}},F_{t x}=0,F_{t y}=0,F_{t w}=0,
F_{z t}=\partial_{z}{A_{t}},F_{z z}=0,F_{z x}=0,F_{z y}=0,F_{z w}=0,
F_{x t}=0,F_{x z}=0,F_{x x}=0,F_{x y}=0,F_{x w}=0,
F_{y t}=0,F_{y z}=0,F_{y x}=0,F_{y y}=0,F_{y w}=B,
F_{w t}=0,F_{w z}=0,F_{w x}=0,F_{w y}=-B,F_{w w}=0 };


ex:=g^{\mu\nu} F_{\mu\nu};
evaluate(_,metric+F, rhsonly=True);

The error message is

RuntimeError: substitute: Argument is neither a replacement rule nor an equality

At:
  Notebook Cell (Line 15): _ = evaluate(_,metric+F, rhsonly=True); display(_)

What's wrong ? This was not an issue in the older versions.

in General questions by (1.4k points)

2 Answers

+1 vote
 
Best answer

Hi Eureka, the problem is that a while ago the notation for evaluations with multiple rules changed.

In your code use join(metric,F) instead of metric+F, i.e.

evaluate(_,join(metric,F), rhsonly=True);

You'll get zero as expected.

by (13.2k points)
selected by

Thanks a lot, Doxdrum. This information is so useful. I have a related question: When I want to let $F{z \mu}=F{\mu z}=0$, while other parts are unknown. What changes should I make to the above code?

A comment: This change doesn't seem to make much sense. For example, if I were to perform multiple substitutions at the same time, I would need to take the form of 'evaluate(_,join(join(join(A,B), C),D),rhsonly=True);`

Hi Eureka, the reason of the change have been explained by Kasper in the answers to this question.

As you will see, there is another way to join the rules... You might want to try using the tie operator ~. But it has never worked for me.

Ok, thanks. For this question:

Thanks a lot, Doxdrum. This information is so useful. I have a related question: When I want to let $F{z \mu}=F{\mu z}=0$, while other parts are unknown. What changes should I make to the above code?

Do you have any comments? I don't have any ideas [sigh]

0 votes

I have an another quetion:

The following code:

{\mu,\nu}::Indices(values={t,x,y,z}, position=fixed);
\partial{#}::PartialDerivative;
A{#}::Depends(\partial{#});
h{#}::Depends(\partial{#});
ex:=\partial_{\mu}{h^{\mu\nu} A_{\nu}};
evaluate(_);

The error message is as follows:

RuntimeError: Free indices in different terms in a sum do not match.
by (1.4k points)

(In the future please do not add new questions as replies to existing questions; it makes it difficult for other people to search the list. Thanks!)

The trouble arises for two reasons. First, you should really declare 't,x,y,z' as coordinates, otherwise you can get weird error messages like what you see, because the system interprets these symbols as abstract indices. So

{t,x,y,z}::Coordinate;

If you then run it through, you will hit another error, stating that the sympy bridge does not yet handle derivatives. That's easily circumvented by doing, instead of the last line,

evaluate(_, simplify=False);

That will give the result you are after.

Thanks, got it. I have a related question. For example, the following code:

{t,x,y,z}::Coordinate.
{\mu,\nu}::Indices(values={t,x,y,z}, position=fixed);
\partial{#}::PartialDerivative;
A{#}::Depends(\partial{#});
h{#}::Depends(\partial{#});
H:={h^{z t}=0,h^{z x}=0};

ex:=\partial_{\mu}{h^{\mu\nu} A_{\nu}};
evaluate(_,H,simplify=False);

For $h^{\mu\nu}$, $h^{z t}=h^{z x}=0$, but other components are unknow, how should I modify the above code?

I know I can use function substitute to implement it, but is there a better way?

If you give evaluate a list of rules (like your H), then it will assume that any components not specified in that list are zero. So you have to specify the non-zero components. In your case, that means everything is zero, which is not what you want.

You can thus either specify the non-zero components, e.g.

H := { h^{z y} = h^{z y}, ... }

Or you can evaluate without using H, but then do a simple substitute afterwards,

evaluate(_, simplify=False)
substitute(_, H);

Note that you will still have to add h^{t z} and h^{x z} to your list, as substitute does not apply symmetries.

Got it! Thanks again.

...