PiMath API
    Preparing search index...

    Class Polynom

    A polynomial in one or several variables: a list of Monoms kept reduced and sorted by decreasing degree. Built from a string ("x^2-5x+6", "(x+1)^2"), a number, a monom, or from coefficients (new Polynom("x", 1, -5, 6)). A malformed string throws a ParseError. Operations modify the polynom and return it; clone() keeps the original. A failing operation leaves it unchanged.

    new Polynom("x^2-5x+6").factorize().map(f => f.display) // [ "x-2", "x-3" ]
    

    Implements

    Index
    • get monoms(): Monom[]

      A detached copy of the monoms (each one cloned). Mutating the returned array or its monoms does NOT affect the polynom — go through add / subtract / multiply / the monoms setter to modify it.

      Returns Monom[]

    • set monoms(M: Monom[]): void

      Parameters

      Returns void

    • get plotFunction(): string

      Expression to give to a plotting tool: explicit * between a coefficient and its variables.

      Returns string

    • get value(): number | undefined

      Numeric value of a constant polynom, or undefined when the degree is not zero.

      Returns number | undefined

    • Add polynoms, monoms, numbers or strings, then reduce. Modifies and returns the receiver. A string is read as a polynom ("2x+1"). Every operand is built before the receiver is touched: an invalid value throws and leaves it unchanged.

      Parameters

      Returns this

      if a string operand is malformed.

      if an operand is undefined.

    • Greatest monom dividing every term: gcd of the numerators over gcd of the denominators, and the lowest exponent of each variable (2x^3+6x^2 gives 2x^2).

      Returns Monom

    • Degree of the polynom as a fraction. Without variable, the highest total degree of a term; with one, the highest exponent of that variable.

      Parameters

      • Optionalvariable: string

      Returns Fraction

    • Remove every monom. Unlike zero, which holds the monom 0, the polynom then has no term at all.

      Returns this

    • Factorize a polynom with respect to a single variable and store the best results in factors. The variable is the explicit variable, else the sole variable of a single-variable polynom, else the default variable. Multi-variable factorization (treating other variables as symbolic constants) is not supported — the numeric solver cannot represent roots that depend on other variables.

      Parameters

      • Optionalvariable: string

      Returns Polynom[]

    • Greatest common divisor of the denominators of the coefficients.

      Returns number

    • Greatest common divisor of the numerators of the coefficients.

      Returns number

    • Coefficients from the highest degree down to the constant term (zeros included). Assumes a single variable.

      Returns Fraction[]

      when the polynom has a non-integer degree.

    • Denominator of the coefficient of each monom, in the order of the monoms.

      Returns number[]

    • Numerator of the coefficient of each monom, in the order of the monoms.

      Returns number[]

    • Whether the polynom contains a cross-term monom (a single monom carrying more than one variable, such as xy).

      Returns boolean

    • True when the variable appears in a term with a non-zero exponent.

      Parameters

      • variable: string

      Returns boolean

    • 1/P is not a polynom: the operation is not available.

      Returns this

      always. The IExpression contract returns a polynom, never null, so impossibility is a throw.

    • Whether the given string is the fully developed (expanded) form of this polynom.

      Parameters

      • polynomString: string

      Returns boolean

      when polynomString is malformed.

    • True when the division by div leaves no remainder. A degree-1 divisor is tested through its root.

      Parameters

      Returns boolean

    • True when both polynoms have the same terms, whatever their coefficients (x^2+x and 3x^2-5x).

      Parameters

      Returns boolean

    • Least common multiple of the denominators of the coefficients.

      Returns number

    • Least common multiple of the numerators of the coefficients.

      Returns number

    • Monom of the given degree for variable, or the monom of highest degree when degree is omitted. Returns the zero monom when none matches.

      Parameters

      • Optionaldegree: number | Fraction
      • Optionalvariable: string

      Returns Monom

    • First monom that contains variable, or the zero monom when none does.

      Parameters

      • variable: string

      Returns Monom

    • Every monom of the given degree for variable, or of the highest degree when degree is omitted.

      Parameters

      • Optionaldegree: number | Fraction
      • Optionalvariable: string

      Returns Monom[]

    • Multiply by polynoms, monoms, fractions, numbers or strings, then reduce. Modifies and returns the receiver. A string is read as a polynom ("x+3"). Every operand is built before the receiver is touched: an invalid value throws and leaves it unchanged.

      Parameters

      Returns this

      if a string operand is malformed.

      if an operand is undefined.

    • Raise to a non-negative integer power; the power 0 gives 1.

      Parameters

      • nb: number

      Returns this

      if nb is negative or not a safe integer.

    • A primitive with respect to variable (default x), without integration constant.

      Parameters

      • Optionalvariable: string

      Returns Polynom

      if a term has a power of -1 of the variable.

    • Sort the monoms by decreasing degree of variable (default: the default variable of the polynom), or by increasing degree when revert is true. The other variables break the ties.

      Parameters

      • Optionalvariable: string
      • revert: boolean = false

      Returns this

    • Replace a variable by a polynom (in place).

      Parameters

      Returns this

      when the replaced variable appears with a negative power.

    • Set the default variable, used when a method needs one and the polynom does not decide it.

      Parameters

      • value: string

      Returns this

      if value is not a single lowercase letter.

    • Subtract polynoms, monoms, numbers or strings, then reduce. Modifies and returns the receiver. A string is read as a polynom ("x-1"). Every operand is built before the receiver is touched: an invalid value throws and leaves it unchanged.

      Parameters

      Returns this

      if a string operand is malformed.

      if an operand is undefined.

    • Build a multivariate linear polynom: 'xyz', a, b, c, d → ax + by + cz + d.

      Parameters

      Returns Polynom

      when variables is not two or more lowercase letters.

      when more coefficients than variables+1 are given.

    • Build a polynom from an expression: sums, products, integer powers, and division by a constant.

      Parameters

      • value: string

      Returns Polynom

      if the string is malformed.

      for a division by a polynom of degree 1 or more, or a fractional power of a sum.

    • Build the polynom of degree at most 2 passing through three points, using Newton divided differences. The result is exact (fractions). When the three points are aligned, the result is a line (degree 1), or a constant when the three y are equal.

      Parameters

      Returns Polynom

      when a coordinate is not finite, or variable is not a single lowercase letter.

      when two points share the same x (no polynom is a function of that shape).

      Polynom.fromThreePoints({x: 1, y: 2}, {x: 2, y: 3}, {x: 4, y: 11}).display // "x^(2)-2x+3"