1
$\begingroup$

I have some algebraic term that looks like this,

Conjugate[Subscript[u, 1, 1]] Conjugate[Subscript[u, 2, 1]] 
\!\(\*SubsuperscriptBox[\(u\), \(1, 1\), \(2\)]\)

$$u_{1,1}^2 \left(u_{1,1}\right){}^* \left(u_{2,1}\right){}^*$$

or, the following

Conjugate[Subscript[u, 1, 1]]^2 
\!\(\*SubsuperscriptBox[\(u\), \(1, 1\), \(2\)]\)

$$u_{1,2}^2 \left(\left(u_{1,1}\right){}^*\right){}^2$$

or

Conjugate[Subscript[u, 1,1]]^2 Subscript[u, 2,1] Subscript[u, 4,1]

$$u_{2,1} u_{4,1} \left(\left(u_{1,1}\right){}^*\right){}^2$$ or

 Conjugate[Subscript[u, 1,1]] Conjugate[Subscript[u, 3,1]] Subscript[u, 2,1] Subscript[u, 3,1]

$$u_{2,1} u_{3,1} \left(u_{1,1}\right){}^* \left(u_{3,1}\right){}^*$$ I want to get two list - one containing the normal terms and the other containing the conjugate terms. The list should contain repeated terms seperately not as power e.g here, for the first example, the list of normal terms should look like

$$ {u_{1,1},u_{1,1}} $$

and the list of conjugate term should look like,

$$u_{1,1},u_{2,1}$$ How can I achieve that in Mathematica simply. Seems like Mathematica List function cannot seperate the individual factors in $u_{1,1}^2$. Probably pattern matching is possible though it seem scomplicated to write a formula that can handle arbitary powers and all usecases. Is there a simpler way to achieve this? Thank you in advance.

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to the Mathematica Stack Exchange. Please load Mathematica code for your expression that can be copied, pasted and executed in our own notebook sessions. It reduces ambiguity and enables a focused interaction between the OP and potential respondents. $\endgroup$
    – Syed
    Oct 28, 2023 at 6:34

2 Answers 2

1
$\begingroup$
term =
 Subscript[u, 1, 1]^2*Conjugate[Subscript[u, 1, 1]]*Conjugate[Subscript[u, 2, 1]]

{normal, conjugate} =
 term /. Times[Power[a_, n_], b__] :> {Table[a, n], Last /@ {b}}

enter image description here

normal

enter image description here

conjugate

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much @eldo. I am sorry for not mentioning already in the question but, the terms may appear at different combinations (edited now). This can resolve only the first case. $\endgroup$ Oct 28, 2023 at 10:59
0
$\begingroup$
Clear["Global`*"];
testexprs = {
  Conjugate[Subscript[u, 1, 1]] Conjugate[Subscript[u, 2, 1]] 
   
\!\(\*SubsuperscriptBox[\(u\), \(1, 1\), \(2\)]\)
  , Conjugate[Subscript[u, 1, 1]]^2 
   
\!\(\*SubsuperscriptBox[\(u\), \(1, 1\), \(2\)]\), 
  Conjugate[Subscript[u, 1, 1]]^2 Subscript[u, 2, 1] Subscript[u, 4, 1]
  , Conjugate[Subscript[u, 1, 1]] Conjugate[
    Subscript[u, 3, 1]] Subscript[u, 2, 1] Subscript[u, 3, 1]
  }


Replace[#, Conjugate[a_] :> a, {2}] &@
         GatherBy[#, Head] &@Flatten[#, 1] &@
     Cases[#, Power[a_, n_.] :> ConstantArray[a, n]] & /@ testexprs //
   Prepend[#, {"Conjugate", "Normal"}] & // 
 Grid[#, Alignment -> Center, Dividers -> All, 
   ItemSize -> {Automatic, 1.5}] &

Result:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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