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

Suppose i define a variable l:=k_{c}p_{c}, where k and c are vectors and usual summation is assumed. Then I define m to be the inverse of l i.e. m:=1/l (or I defined m:=l**{-1}). Then I computed m*l but i am not getting unity (1).

Instead I am getting output as ml.

Whats the mistake I am doing.

What should i do for the simplication involving fractions like this..please help

in General questions by

1 Answer

+1 vote
 
Best answer

If you do

 m:= l**{-1};

you create an expression 'm' (a Python object) which contains the mathematical expression l1. The thing on the left of the := is a Python name, while the thing on the right is a Cadabra expression.

Now if you write

ex:= m l;

you create another expression, called 'ex', which contains the mathematical expression ml.

If you want to tell Cadabra that it should use the content of the m object to build this expression, you need to do

ex:= @(m) l;
collect_factors(_);

(the 2nd line is there to reduce l1l to 1).

A cleaner (more Cadabra-esque) way of writing this is

 mrule:= m = l^{-1};
 ex:= m l;
 substitute(ex, mrule);
 collect_factors(ex);

Here I defined an object which contains the rule which tells Cadabra how to replace m. The reason why this is cleaner is that it generalises better to replacement rules with indices. You cannot write

 A_{\mu} := B_{\mu};    # not possible

(to replace $A{\mu}withB{\mu}),becausePythonobjectsneedtohavenamesconsistingofalphanumericcharactersonly(andA_{\mu}$ contains other stuff as well). But you can write

Arule:= A_{\mu} = B_{\mu};

and then

ex:= A_{\mu} C^{\mu};
substitute(ex, Arule);

to get BμCμ.

by (85.0k points)
...