1
$\begingroup$

My expression is:

expr = (p^(1/3) q + 5)/(3q^2)+p^2+(p-1)^(1/3)

And I want to single out all terms with $p^k, k > 1$

How should I do that? (If there is any way other than applying Series[] would be the best, since I want it to be less time-consuming when dealing with large expr.)

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign $\endgroup$
    – Dunlop
    Sep 12 '21 at 5:04
  • 1
    $\begingroup$ Please give your expression in code. This will make it easier for others to help you out. $\endgroup$
    – Dunlop
    Sep 12 '21 at 5:05
1
$\begingroup$

And I want to single out all terms with p^k,k>1

I use this nice function getPatterns thanks to Carl Woll that he gave me as an answer long time ago. It is a handy function to have in your toolbox.

ClearAll[p, q];
expr=(p^(1/3)*q+5)/(3*q^2)+p^2+(p-1)^(1/3)+p^5+(p^(9/2)-1)^(1/3)

Mathematica graphics

getPatterns[expr_, pat_] := Last@Reap[expr /. a : pat :> Sow[a], _, Sequence @@ #2 &];

And now

getPatterns[expr, Power[p, x_] /; x > 1]

Mathematica graphics

Edit

replying to comment

if there is a term 2 q p^(1/3), it only gives p^(1/3) while neglecting 2 q factor in front under current setting. And I want to have the final answers attached with 2 q factor

You can change the pattern to

expr = (2 *q*p^(1/3)*q + 5)/(3*q^2) + p^2 + (p - 1)^(1/3) + 
  p^5 + (888*p^(1/2) - 1)^(1/3)
getPatterns[expr, any_*Power[p, x_] /; x < 1]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Thank you for your reply! But is there anyway to also single out the coefficients corresponding to the terms? $\endgroup$
    – QubitTy
    Sep 12 '21 at 5:29
  • $\begingroup$ @TianyiWang You mean the actual powers themselves? $\endgroup$
    – Nasser
    Sep 12 '21 at 5:30
  • $\begingroup$ For example, if there is a term 2 q p^(1/3), it only gives p^(1/3) while neglecting 2 q factor in front under current setting. And I want to have the final answers attached with 2 q factor. $\endgroup$
    – QubitTy
    Sep 12 '21 at 5:36
  • $\begingroup$ @TianyiWang please see edit. $\endgroup$
    – Nasser
    Sep 12 '21 at 5:41
  • $\begingroup$ It works!! Thanks a lot! $\endgroup$
    – QubitTy
    Sep 12 '21 at 6:12

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.