Mathematica Asked on April 5, 2021
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,lin{0,1,2,3}$. I would like to define a linear function that takes op
and does the following:
$$
begin{align*}
P:
&quad a_0to a_0
&quad a_kto-a_k
&quad b_0to -b_0
&quad b_kto b_k
&quad c_0to c_0
&quad c_kto-c_k
&quad d_0to -d_0
&quad d_kto 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[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]
op2 = a[2] b[3] c[1] d[0] + a[0] b[3] c[2] d[1];
P[op2]
Correct answer by Bob Hanlon on April 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP