This extension provides a new data type and some functions to deal with polynomials
This extension adds a new JME data type Numbas.jme.types.polynomial, representing a polynomial in a given variable.
Create a polynomial, automatically detecting the variable name from the expression. This is quite strict about what it accepts - only one variable name, and coefficients and degrees have to be literal numbers, not calculations or references to other variables.
You can either write a literal expression, or pass a string. Note that if you use a literal expression, variables defined in the scope are substituted in. It's safer to use a string.
polynomial(x^2-2x+3)polynomial("5*x^4 + 2*x")
Create a polynomial in the given variable, with the given coefficients (coefficients[i] is the coefficient of variable_name^i). Example: polynomial(x,[-1,0,1]) represents the polynomial x^2-1.
As above, but all operations on this polynomial will be calculated modulo m.
Add two polynomials
Add a constant to a polynomial - more convenient than p+polynomial(n).
Subtract p2 from p1
Subtract a constant from a polynomial (or vice versa) - more convenient than p-polynomial(n).
Multiply two polynomials
Multiply a polynomial by a constant - more convenient than p*polynomial(n).
Take polynomial p to the nth (integer, non-negative) power.
Divide p1 by p2, and throw away the remainder (polynomial quotient of p1 and p2)
Remainder when dividing p1 by p2.
Take each coefficient of p mod n.
Degree of p - highest power of the variable with a non-zero coefficient.
Are p1 and p2 equal? True if all the coefficients match.
Coefficient of x^d in p.
Evaluate the polynomial at the given point.
A JME expression equivalent to the given polynomial; you can substitute this into the correct answer for a "Mathematical expression" part, for example.
A string representation of the polynomial.
A LaTeX representation of the polynomial.
LaTeX rendering of the long division of p1 by p2.
Base object: Numbas.extensions.polynomials.Polynomial
(set it to a more convenient name, e.g. var poly = Numbas.extensions.polynomials.Polynomial)
coefficients is a dictionary of degree → coefficient. If modulo is given, all coefficients will be reduced modulo that number in any calculations using this polynomial.
Create a polynomial object from a compiled JME tree
Create a polynomial object from a JME string
Evaluate at point x to a number
Render as a LaTeX string
Is this polynomial zero?
Degree of highest power term in p with a non-zero coefficient
Negate every coefficient of p (returns a new polynomial)
Add p1 to p2
Subtract p2 from p1
Mutliply p1 by p2
nth power of p
Multiply p by constant n
Add n to the degree of each term of p
Divide p1 by p2. Returns an object {quotient: <polynomial>, remainder: <polynomial>}
Take each coefficient of p mod n (returns a new polynomial object)
Are p1 and p2 equal?
Coefficient of x^d in p.