Class Polynomial<R extends Ring<R>>

  • All Implemented Interfaces:
    Serializable, javolution.lang.Immutable, javolution.lang.Realtime, javolution.lang.ValueType, GroupAdditive<Polynomial<R>>, Ring<Polynomial<R>>, Structure<Polynomial<R>>
    Direct Known Subclasses:
    Constant

    public class Polynomial<R extends Ring<R>>
    extends Function<R,​R>
    implements Ring<Polynomial<R>>

    This class represents a mathematical expression involving a sum of powers in one or more variables multiplied by coefficients (such as x² + x·y + 3y²).

    Polynomials are characterized by the type of variable they operate upon. For example:[code] Variable> varX = new Variable.Local>("x"); Polynomial> x = Polynomial.valueOf(Amount.valueOf(1, SI.METER), varX); and Variable varX = new Variable.Local("x"); Polynomial x = Polynomial.valueOf(Complex.ONE, varX);[/code] are two different polynomials, the first one operates on physical measures, whereas the second operates on complex numbers.

    Terms (others than ONE) having zero (additive identity) for coefficient are automatically removed.

    See Also:
    Serialized Form
    • Method Detail

      • valueOf

        public static <R extends Ring<R>> Polynomial<R> valueOf​(R coefficient,
                                                                Variable<R> variable)
        Returns an univariate polynomial of degree one with the specified coefficient multiplier.
        Parameters:
        coefficient - the coefficient for the variable of degree 1.
        variable - the variable for this polynomial.
        Returns:
        valueOf(coefficient, Term.valueOf(variable, 1))
      • valueOf

        public static <R extends Ring<R>> Polynomial<R> valueOf​(R coefficient,
                                                                Term term)
        Returns a polynomial corresponding to the specified term with the specified coefficient multiplier.
        Parameters:
        coefficient - the coefficient multiplier.
        term - the term multiplicand.
        Returns:
        coefficient * term
      • getTerms

        public Set<Term> getTerms()
        Returns the terms of this polynomial.
        Returns:
        this polynomial's terms.
      • getCoefficient

        public final R getCoefficient​(Term term)
        Returns the coefficient for the specified term.
        Parameters:
        term - the term for which the coefficient is returned.
        Returns:
        the coefficient for the specified term or null if this polynomial does not contain the specified term.
      • getOrder

        public int getOrder​(Variable<R> v)
        Returns the order of this polynomial for the specified variable.
        Returns:
        the polynomial order relative to the specified variable.
      • plus

        public Polynomial<R> plus​(R constantValue)
        Returns the sum of this polynomial with a constant polynomial having the specified value (convenience method).
        Parameters:
        constantValue - the value of the constant polynomial to add.
        Returns:
        this + Constant.valueOf(constantValue)
      • times

        public Polynomial<R> times​(R constantValue)
        Returns the product of this polynomial with a constant polynomial having the specified value (convenience method).
        Parameters:
        constantValue - the value of the constant polynomial to multiply.
        Returns:
        this · Constant.valueOf(constantValue)
      • plus

        public Polynomial<R> plus​(Polynomial<R> that)
        Returns the sum of two polynomials.
        Specified by:
        plus in interface GroupAdditive<R extends Ring<R>>
        Parameters:
        that - the polynomial being added.
        Returns:
        this + that
      • minus

        public Polynomial<R> minus​(Polynomial<R> that)
        Returns the difference of two polynomials.
        Parameters:
        that - the polynomial being subtracted.
        Returns:
        this - that
      • times

        public Polynomial<R> times​(Polynomial<R> that)
        Returns the product of two polynomials.
        Specified by:
        times in interface Ring<R extends Ring<R>>
        Parameters:
        that - the polynomial multiplier.
        Returns:
        this · that
      • compose

        public Polynomial<R> compose​(Polynomial<R> that)
        Returns the composition of this polynomial with the one specified.
        Parameters:
        that - the polynomial for which the return value is passed as argument to this function.
        Returns:
        the polynomial (this o that)
        Throws:
        FunctionException - if this function is not univariate.
      • compose

        public <Z> Function<Z,​R> compose​(Function<Z,​R> that)
        Description copied from class: Function
        Returns the composition of this function with the one specified.
        Overrides:
        compose in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        that - the function for which the return value is passed as argument to this function.
        Returns:
        the function (this o that)
      • plus

        public Function<R,​R> plus​(Function<R,​R> that)
        Description copied from class: Function
        Returns the sum of this function with the one specified.
        Overrides:
        plus in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        that - the function to be added.
        Returns:
        this + that.
      • minus

        public Function<R,​R> minus​(Function<R,​R> that)
        Description copied from class: Function
        Returns the difference of this function with the one specified.
        Overrides:
        minus in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        that - the function to be subtracted.
        Returns:
        this - that.
      • times

        public Function<R,​R> times​(Function<R,​R> that)
        Description copied from class: Function
        Returns the product of this function with the one specified.
        Overrides:
        times in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        that - the function multiplier.
        Returns:
        this · that.
      • pow

        public Polynomial<R> pow​(int n)
        Description copied from class: Function
        Returns this function raised at the specified exponent.
        Overrides:
        pow in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        n - the exponent.
        Returns:
        thisn
      • getVariables

        public List<Variable<R>> getVariables()
        Description copied from class: Function
        Returns a lexically ordered list of the variables (or arguments) for this function (empty list for constant functions).
        Specified by:
        getVariables in class Function<R extends Ring<R>,​R extends Ring<R>>
        Returns:
        this function current unset variables (sorted).
      • evaluate

        public R evaluate()
        Description copied from class: Function
        Evaluates this function using its variables current values.
        Specified by:
        evaluate in class Function<R extends Ring<R>,​R extends Ring<R>>
        Returns:
        the evaluation of this function.
      • equals

        public boolean equals​(Object obj)
        Description copied from class: Function
        Indicates if this function is equals to the specified object.
        Overrides:
        equals in class Function<R extends Ring<R>,​R extends Ring<R>>
        Parameters:
        obj - the object to be compared with.
        Returns:
        true if this function and the specified argument represent the same function; false otherwise.
      • toText

        public javolution.text.Text toText()
        Description copied from class: Function
        Returns the textual representation of this real-time object (equivalent to toString except that the returned value can be allocated from the local context space).
        Specified by:
        toText in interface javolution.lang.Realtime
        Specified by:
        toText in class Function<R extends Ring<R>,​R extends Ring<R>>
        Returns:
        this object's textual representation.
      • copy

        public Polynomial<R> copy()
        Returns a copy of this polynomial allocated by the calling thread (possibly on the stack).
        Specified by:
        copy in interface javolution.lang.ValueType
        Returns:
        an identical and independant copy of this polynomial.