Skip to content

math.poly

polynomials written as coefficient lists: evaluate, multiply, divide, differentiate and find roots

Polynomials, like 2x² - 3x + 5, written as a list of coefficients from the highest power down: [2, -3, 5].

Whole-number and fraction coefficients give exact answers, except for finding roots, which is always numeric.

Tags: algebra

  • poly_eval the polynomial’s value at x, from its coefficients highest power first
  • poly_mul the product of two polynomials
  • poly_div divide polynomial a by b, giving the list [quotient, remainder]
  • poly_deriv the derivative of a polynomial, as a coefficient list
  • poly_roots every root of the polynomial, real or complex, found numerically
poly_eval(p: list, x: any) -> any

the polynomial’s value at x, from its coefficients highest power first

1
poly_eval([2, -3, 5], 4)25
Example outputCtrl+Enter to run

See also poly_roots, poly_deriv

poly_mul(a: list, b: list) -> list

the product of two polynomials

1
poly_mul([1, 1], [1, -1])[1, 0, -1]
Example outputCtrl+Enter to run

See also poly_div

poly_div(a: list, b: list) -> list

divide polynomial a by b, giving the list [quotient, remainder]

1
poly_div([1, 0, -1], [1, -1])[[1, 1], [0]]
2
poly_div([1, 2, 3], [1, 1])[[1, 1], [2]]
Example outputCtrl+Enter to run

See also poly_mul

poly_deriv(p: list) -> list

the derivative of a polynomial, as a coefficient list

1
poly_deriv([3, 2, 1])[6, 2]
Example outputCtrl+Enter to run

See also poly_eval

poly_roots(p: list) -> list

every root of the polynomial, real or complex, found numerically

Real roots come back as plain numbers

1
poly_roots([1, -3, 2])[1, 2]
2
poly_roots([1, 0, 1])[-1i, 1i]
Example outputCtrl+Enter to run

See also poly_eval, root

1
# 2x² - 3x + 5 at x = 4
2
poly_eval([2, -3, 5], 4)25
3
# the roots of x² - 3x + 2
4
poly_roots([1, -3, 2])[1, 2]
5
# (x + 1)(x - 1)
6
poly_mul([1, 1], [1, -1])[1, 0, -1]
7
# divide x² - 1 by x - 1, as quotient and remainder
8
poly_div([1, 0, -1], [1, -1])[[1, 1], [0]]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.