Introduction

Immutable polynomials for PHP with float coefficients. Do arithmetic, evaluate, differentiate, divide and find real roots.

Requirements#

The library needs a current PHP version. It has no runtime dependencies and does not need any extension.

Installation#

Install the library with Composer.

composer require phpmath/polynomial

A first example#

A polynomial is a sum of terms such as 2x^3 or -x. Create one from its coefficients (the numbers in front of the powers of x), starting with the constant term.

use PHPMath\Polynomial\Polynomial;

$p = Polynomial::of(5, -1, 0, 2);

echo $p;               // 2x^3 - x + 5
echo $p->degree();     // 3
echo $p->evaluate(2);  // 19

The degree is the highest power of x that has a non-zero coefficient. Calling evaluate() or any other method did not change $p. Every operation in the library returns a new Polynomial.

Where to go next#

Start with the core concepts, or jump straight to the topic you need.