0
$\begingroup$

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...

$\endgroup$
4
$\begingroup$
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[0] :> -b[0], 
   c[n_?Positive] :> -c[n], d[0] :> -d[0]}

op = a[3] b[2] c[1] d[0] - a[2] b[3] c[1] d[0] - a[3] b[1] c[2] d[0] + 
   a[1] b[3] c[2] d[0] + a[2] b[1] c[3] d[0];

P[op]

enter image description here

op2 = a[2] b[3] c[1] d[0] + a[0] b[3] c[2] d[1];

P[op2]

enter image description here

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – Sito
    Mar 14 at 18:24
  • 2
    $\begingroup$ @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}]]] $\endgroup$
    – b3m2a1
    Mar 14 at 18:41
  • 2
    $\begingroup$ aVec = Array[a, 4, 0]; will start the index at 0 $\endgroup$
    – Bob Hanlon
    Mar 14 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.