Skip to content

Instantly share code, notes, and snippets.

@tueda
Created February 7, 2022 13:46
Show Gist options
  • Save tueda/ca7163753975c4595b9af386c0241502 to your computer and use it in GitHub Desktop.
Save tueda/ca7163753975c4595b9af386c0241502 to your computer and use it in GitHub Desktop.
(*
PolynomialDivCofficientList
Return the coefficient list by dividing polynomials;PolynomialDivCofficientList[x^2+1,x+1,x]\[LongRightArrow]{1,-2,2},which means x^2+1==(x+1)^2-2(x+1)+2.
*)
PolynomialDivCofficientList[expr_, denom_, x_] := Module[
{result, rem, cnt, i},
result = {};
rem = expr;
cnt = Floor[Exponent[expr, x]/Exponent[denom, x]];
For[i = cnt, i > 0, i--,
result = result~Append~PolynomialQuotient[rem, Power[denom, i], x];
rem = PolynomialRemainder[rem, Power[denom, i], x];
];
result~Append~rem
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment