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

Hi, I was wondering whether (or how) I can tell Cadabra to treat an object like a parameter, not like a (rank-0) tensor. I have the following code:

{i,j,k}::Indices(vector);
N::Integer;
{i,j,k}::Integer(1..N);

_ := S^{i}\_{j}^{k} S\_{i}^{j}\_{k} + 15*N*S^{i j k} S\_{i j k};
canonicalise(_);
sort_sum(_);

The output is $S^{ijk} S_{ijk} + 15N S^{ijk} S_{ijk}$.

However, I would like Cadabra to collect terms pretending that $N$ is just a number, i.e. I would like the result to be $(1+15N) S^{ijk} S_{ijk}$.

Is it possible?

in General questions by

1 Answer

0 votes

Use the factor_in algorithm, as in

{i,j,k}::Indices(vector);
_ := S^{i}_{j}^{k} S_{i}^{j}_{k} + 15*N*S^{i j k} S_{i j k};
canonicalise(_);
factor_in(_, $N$);

which produces the result you wanted.

(incidentally, Cadabra makes no distinction between 'parameters' and 'rank-0 tensors', at least not when it comes to this kind of problem).

by (83.1k points)

Thanks for the answer! This works, but sometimes not all terms were collected. In this case I would receive terms, which belong together, in different orderings, e.g. I define an ordering through

{N, Q_#, g_#, R_#, \tau_#, \omega_#}::SortOrder;

and $Q_{ij}$ as symmetric,

Q_{i j}::Symmetric;

However, the result after using factor_in(_, \$N\$) would be something like

$(5 N^2+12 N) Q{ij} + Q{ij} (10 N^3 -13) - (6 N^3+50 N^2) Q_{ji}$

(swapped indices, or tensors and scalars in different order). Unfortunately, I wasn't able to make up a minimal example; as soon as I go from the full computation to a simple example, the problem disappears (so it might be something else that causes the problem).

Any ideas what could be wrong with my code? Or how to tell Cadabra to order the terms correctly and apply symmetries?

Thank you!

factor_in requires an expression which was previously run through canonicalise if you want to have symmetries taken into account. Also, you need to tell it which powers to collect. See the example below (based on your sample line):

Q_{i j}::Symmetric;
ex:= 5 N**2 Q_{i j} + 12 N Q_{i j} + Q_{i j} 10 N**3 - 13 Q_{i j} - 6 N**3 Q_{j i} 
          - 50 N**2 Q_{j i};
canonicalise(_);
factor_in(_, $N, N**2, N**3$);

which produces

$$\left(-45{N}^{2}+12N+4{N}^{3}-13\right) Q_{i j}$$

...