# Proposal for "Math_Polynomial (Re-proposal)"

» Description
***
This is a re-proposal of the original Math_Polynomial package I proposed which was short 1 vote. A number of people either told me they would have voted but were on vacation/work/holiday/etc. or told me I should rework some things and re-propose, so here it is.

I made the following changes people requested:
- License changed to BSD license ( Justin Patrin, Joshua Eichorn )
- Remove the .class from the filenames. ( Justin Patrin, Firman Wandayandi )
- Use is_a() instead of get_class() ( Justin Patrin, Arnaud Limbourg )
- Lots of coding style issues ( Lots of people... )
- return as language construct ( Justin Patrin )
- "and" should be &&, "or" should be || ( Justin Patrin )
- Use 'single quotes' instead of "doubles" ( Justin Patrin )
- Estimation of roots for high-degree Polynomials using Math_Numerical_RootFinding
- Use PEAR::raiseError() for error handling ( Justin Patrin )

I looked at the other Math classes and I really like Jesus Castagnetto's
classes with a data type class and an operations class. That said, the API
for this class now closely mirrors what he's done with his classes, providing
a Polynomial class and a PolynomialOp class with static methods.
***

A math package to represent and manipulate polynomials ( equations of the form ax^n + bx^(n - 1) + ... yx + z, or, for example: 5x^3 + 6x^2 + 4x + 2 )

The class follows the API of other packages in the Math category, with a Polynomial class to represent the data and a PolynomialOp class for operations on the Polynomials.

The PolynomialOp class has methods for common operations on Polynomials, including:
- mul() Multiply " "
- sub() Subtract a polynomial from another
- div() Divide one polynomial by another
- mod() Mod operation for Polynomials
- getRoots()
- getCriticalPoints()
- getDerivative() Get the Nth derivative of the Polynomial
- getTangentAt() Get a tangent to the polynomial at a given x coor.
- evaluate() Get the y value for a given x value
- getSlopeAt() Get the slope at a particular point
- etc. etc. etc.

Example usage:
``` \$p = new Polynomial('3x^2 + 2x'); \$q = new Polynomial('4x + 1'); print('P is: ' . \$p->toString() . "\n"); print('Q is: ' . \$q->toString() . "\n"); \$mul = PolynomialOp::mul(\$p, \$q); // Multiply p by q \$roots = PolynomialOp::createFromRoots(1, 2, -3); print('Here is a polynomial with the roots 1, 2, and -3: ' . \$roots->toString() . "\n"); print('f(x) is: ' . \$p->toString() . "\n"); \$der1 = PolynomialOp::getDerivative(\$p); print('f\'(x) is: ' . \$der1->toString() . ' (first derivative)' . "\n"); \$der2 = PolynomialOp::getDerivative(\$p, 2); print('f\'\'(x) is: ' . \$der2->toString() . ' (second derivative)' . "\n"); ```