2
$\begingroup$

$1)$ For the polynomial

p = x^(-4) - x^(-3) - 2x^(-2) + 2 + 3x + x^2 + 2x^4

How to change the negative exponentials into the positive exponentials,

p = x^4 - x^3 - 2x^2 + 2 + 3x + x^2 + 2x^4

$2)$ Given a series of numbers with the form (coefficient, exponent). Take {2,1},{-1,2},{1,0} and {2,4} for example, how to change them into a polynomial like

2x - x^2 + 1 + 2x^4

Thank you.

$\endgroup$
4
  • $\begingroup$ Please edit to put these in Mathematica InputForm. $\endgroup$ Commented Jul 31, 2018 at 15:42
  • 2
    $\begingroup$ p /. x^q_ -> x^Abs[q] ? $\endgroup$ Commented Jul 31, 2018 at 15:48
  • $\begingroup$ @Daniel Lichtblau Than you for your edit. $\endgroup$
    – Leonard
    Commented Aug 1, 2018 at 14:29
  • $\begingroup$ @AccidentalFourierTransform Yes, it works. Thank you. $\endgroup$
    – Leonard
    Commented Aug 1, 2018 at 14:29

3 Answers 3

2
$\begingroup$
p = x^(-4) - x^(-3) - 2 x^(-2) + 2 + 3 x + x^2 + 2 x^4 ;
lst = {{2, 1}, {-1, 2}, {1, 0}, {2, 4}};

(1)

Block[{Power}, Power[a_, x_?Negative] := Power[a, -x]; p]

2 + 3 x - x^2 - x^3 + 3 x^4

(2)

Dot[#, x^#2]& @@ Transpose[lst]

1 + 2 x - x^2 + 2 x^4

(3)

how to separate the terms with positive exponent from those with negative exponent?

Pick[p, MatchQ[Optional[_] #] /@ List @@ p] & /@ {x | x^_?Positive, x^_?Negative}

{3 x + x^2 + 2 x^4, 1/x^4 - 1/x^3 - 2/x^2}

$\endgroup$
2
  • $\begingroup$ Thank you. It takes time to digest the third answer. $\endgroup$
    – Leonard
    Commented Aug 2, 2018 at 9:11
  • $\begingroup$ @Leonard, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Commented Aug 2, 2018 at 9:13
2
$\begingroup$

For your first question (as modified by your comment below) you could use Series:

p = x^(-4)-x^(-3)-2x^(-2)+2+3x+x^2+2x^4;

Series[p, {x, Infinity, -1}] //Normal
Series[p, {x, 0, -1}] //Normal

3 x + x^2 + 2 x^4

1/x^4 - 1/x^3 - 2/x^2

For the second question, you can use FromCoefficientRules:

topoly[l_] := FromCoefficientRules[
    Replace[l, {c_, e_} :> {e} -> c, {1}],
    x
]

And, your example:

topoly[{{2,1},{-1,2},{1,0},{2,4}}]

1 + 2 x - x^2 + 2 x^4

$\endgroup$
1
  • $\begingroup$ Thank you for your help on the second question. Can I ask one more question on the first one? how to seperate the positive terms from the negative ones? That will result in $$pplus=3x + x^2 + 2x^4$$ and $$pminus=x^{-4} - x^{-3} - 2x^{-2}$$. $\endgroup$
    – Leonard
    Commented Aug 1, 2018 at 14:37
2
$\begingroup$
(* Your input *)

p = x^(-4) - x^(-3) - 2 x^(-2) + 2 + 3 x + x^2 + 2 x^4;
ls = {{2, 1}, {-1, 2}, {1, 0}, {2, 4}};

(* My solutions *)

p /. x^n_?Negative :> x^(-n)

#*x^#2 & @@@ ls // Tr
2 + 3 x - x^2 - x^3 + 3 x^4

1 + 2 x - x^2 + 2 x^4
$\endgroup$
3
  • 1
    $\begingroup$ I don't like the ReplaceAll approach because it gives an incorrect answer for something like (1-x)(1+1/x). $\endgroup$
    – Carl Woll
    Commented Aug 1, 2018 at 23:19
  • $\begingroup$ @Mr.Wizard Thank you for your answer. $\endgroup$
    – Leonard
    Commented Aug 2, 2018 at 9:16
  • $\begingroup$ @CarlWoll Valid point. I should be more careful with that. $\endgroup$
    – Mr.Wizard
    Commented Aug 2, 2018 at 21:31

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.