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

Is there a way to define patterns for use in substitute or zoom containing a fixed free index? Indices in patterns seem to always treated as wildcards, meaning x^{a} matches x^{b} as well. Whereas this is often what I want, there are many cases where I want to select terms based on a fixed free index, so x^{a} should match x^{a} only, not x^{b} for a dummy or another free index b. Is there a way to achieve this?

in General questions by (220 points)

1 Answer

+1 vote
 
Best answer

There isn't a pattern for that, but you can simulate it by first contracting your expression with a dummy vector and then substituting in there. So e.g.

{a,b,c}::Indices.
ex:= x^a + x^b x_b y^a;
ex := @(ex) f_a:
distribute(_);
substitute(_, $x^a f_a -> z^a f_a$);
factor_out(_, $f_a$);
by (80.3k points)
selected by

Why is the substitute step necessary here? This seems to work without the substitute step. Is there some subtlety that necessitates this substitute step in more complicated cases?

...