TransWikia.com

Adapting CoefficientList (and the related functions) to work with Laurent polynomials

Mathematica Asked by Ketil Tveiten on March 29, 2021

Is there a slick way to make CoefficientList (and the other similar functions, CoefficientRules etc.) work for Laurent polynomials (i.e. where negative exponents can occur), if I don’t know a priori what the largest negative exponents are? I can of course do some ugly ad hoc thing by hand, but I’m looking for a method that works generally.

Any tips?

2 Answers

As referred to in the comments:

For single variable polynomial:

coeffl[pol_, s_Symbol] := Module[{e, mod},
  e = Exponent[pol, s, Min];
  mod = s^(-e) pol;
  CoefficientList[mod, s]
  ]

will produce coefficient list.

To obtain cofficient of exponent:

coeff[pol_, s_Symbol, exp_] := Module[{e, mod, M, cl},
  e = Exponent[pol, s, Min];
  M = Exponent[pol, s, Max];
  mod = s^(-e) pol;
  cl = CoefficientList[mod, s];
  exp /. Thread[Range[e, M] -> cl]
  ]

Test example:

coeffl[1 - 2/z^3 - 1/z^2 + 2 z + 3 z^2 + 4 z^3 + 5 z^4 + 6 z^5,z]

yields:

{-2, -1, 0, 1, 2, 3, 4, 5, 6}

and

coeff[1 - 2/z^3 - 1/z^2 + 2 z + 3 z^2 + 4 z^3 + 5 z^4 + 6 z^5,z,-3]

yields -2

EDIT

Above not ideal (general):

coefflg[pol_, s_Symbol] := Module[{e, mod},
  e = Exponent[pol, s, Min];
  If[e < 0,
   mod = s^(-e) pol;
   CoefficientList[mod, s],
   CoefficientList[pol, s]
   ]
  ]


coeffg[pol_, s_Symbol, exp_] := Module[{e, mod, M, cl},
  e = Exponent[pol, s, Min];
  M = Exponent[pol, s, Max];
  If[e < 0,
   mod = s^(-e) pol;
   cl = CoefficientList[mod, s];
   exp /. Thread[Range[e, M] -> cl]
   , Coefficient[pol, s, exp]
   ]
  ]

Answered by ubpdqn on March 29, 2021

I propose a relatively compact method

coeffrul[pol_, x_Symbol] := {# -> Coefficient[pol, x, #]} & /@ Exponent[pol, x, List];
coeffrul[x^-1 + 2 x^1.5 + 3 x^3, x]
{{-1 -> 1}, {1.5 -> 2}, {3 -> 3}}

It works not only with integer powers.

Answered by ybeltukov on March 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP