# How to filter out "relevant" information from expression

I have an expression of the form

op = a3 b2 c1 d0 - a2 b3 c1 d0 - a3 b1 c2 d0 + a1 b3 c2 d0 + a2 b1 c3 d0 +...


that is, each term is of the form $$a_i b_jc_kd_l$$, where $$i,j,k,l\in\{0,1,2,3\}$$. I would like to define a linear function that takes op and does the following: \begin{align*} P: &\quad a_0\to a_0\\ &\quad a_k\to-a_k\\ &\quad b_0\to -b_0\\ &\quad b_k\to b_k\\ &\quad c_0\to c_0\\ &\quad c_k\to-c_k\\ &\quad d_0\to -d_0\\ &\quad d_k\to d_k. \end{align*} As an example: \begin{align*} P(a_2 b_3 c_1 d_0+ a_0 b_3 c_2 d_1)&= (-a_2)b_3(-c_1)(-d_0)+a_0b_3(-c_2)d_1\\ &=-a_2 b_3 c_1 d_0-a_0b_3c_2d_1. \end{align*} My problem is that I don't know how to filter out the relevant information from a term, i.e. given a3 b2 c1 d0 I would first need {{a,3},{b,2},...}. One could then define $$P$$ for a tupel { , } via a switch statement or something like that...

ClearAll["Global*"]


What you want is greatly simplified if you use indexed variables. You can use Format to display the output of indexed variables in any desired manner.

(Format[#[n_]] := Subscript[#, n]) & /@ {a, b, c, d};

P[op_] := op /. {a[n_?Positive] :> -a[n], b :> -b,
c[n_?Positive] :> -c[n], d :> -d}

op = a b c d - a b c d - a b c d +
a b c d + a b c d;

P[op] op2 = a b c d + a b c d;

P[op2] • Thanks, but I don't have the input in indexed form... Is there a way to achieve this? The input is generated from vectors a={a1,a1,a2,a3}, ... using LeviCivitaTensor and TensorContract
– Sito
Mar 14 at 18:24
• @Sito you can write aVec = Array[a, {howeverManyTermsYouNeed}] and then then do all the LeviCevitaTensor/TensorContract work with these vectors of indexed variables. Post-hoc, you can also do expr /. s_Symbol?(StringMatchQ[SymbolName[#], ("a" | "b" | "c") ~~ NumberString] &) :> Symbol[StringTake[SymbolName[s], {1}]][ToExpression[StringDrop[SymbolName[s], {1}]]] Mar 14 at 18:41
• aVec = Array[a, 4, 0]; will start the index at 0` Mar 14 at 18:58