Class Expolynomial

java.lang.Object
org.oristool.math.expression.Expolynomial

public class Expolynomial extends Object
A sum of Exmonomial terms.
  • Field Details

    • mathContext

      public static final MathContext mathContext
  • Constructor Details

    • Expolynomial

      public Expolynomial()
      Builds an empty expolynomial.
    • Expolynomial

      public Expolynomial(Expolynomial expol)
      Builds the copy of an expolynomial.
      Parameters:
      expol - input expolynomial
  • Method Details

    • newOneInstance

      public static Expolynomial newOneInstance()
      Builds a new instance equal to the constant 1.
      Returns:
      a constant expolynomial equal to 1
    • newConstantInstance

      public static Expolynomial newConstantInstance(OmegaBigDecimal value)
      Builds a new instance equal to a given constant.
      Parameters:
      value - input value
      Returns:
      a constant expolynomial equal to value
    • getExmonomials

      public List<Exmonomial> getExmonomials()
    • addExmonomial

      public void addExmonomial(Exmonomial exmon)
      Adds an exmonomial to the sum.
      Parameters:
      exmon - input exmonomial
    • getVariables

      public Collection<Variable> getVariables()
      Returns all the variables used in this expolynomial.
      Returns:
      set of variables
    • getConstant

      public OmegaBigDecimal getConstant()
      Returns the constant value of this expolynomial of throws an IllegalStateException exception if the expolynomial is not constant.
      Returns:
      constant value of the expolynomial
      Throws:
      IllegalStateException - if the expolynomial is not constant
    • normalize

      public void normalize()
      Normalizes the expolynomial, expanding all products and sums.
    • add

      public void add(Expolynomial other)
      Adds another expolynomial.
      Parameters:
      other - input expolynomial
    • sub

      public void sub(Expolynomial other)
      Subtracts another expolynomial.
      Parameters:
      other - input expolynomial
    • multiply

      public void multiply(Expolynomial other)
      Multiplies by an expolynomial.
      Parameters:
      other - input expolynomial
    • multiply

      public void multiply(BigDecimal k)
      Multiplies by a constant.
      Parameters:
      k - constant
    • divide

      public void divide(BigDecimal k)
      Divides by a constant.
      Parameters:
      k - constant
    • substitute

      public void substitute(Variable oldVar, Variable newVar)
      Replaces oldVar with newVar.
      Parameters:
      oldVar - variable to be replaced
      newVar - new variable
    • evaluate

      Evaluates the expolynomial.
      Parameters:
      m - map with values for all the variables
      Returns:
      expolynomial value
    • evaluate

      public Expolynomial evaluate(Variable var, OmegaBigDecimal value)
      Replaces a variable with its value.
      Parameters:
      var - variable to be replaced
      value - value of the variable
      Returns:
      expolynomial after the substitution
    • evaluate

      public Expolynomial evaluate(Variable base, boolean sign, Variable offset, BigDecimal constant)
      Replaces base with +/- offset + constant.
      Parameters:
      base - variable to be replaced
      sign - true if sign of the offset is positive
      offset - offset to be added
      constant - constant to be added
      Returns:
      resulting Expolynomial
    • evaluate

      public Expolynomial evaluate(Variable base, boolean sign1, Variable offset1, boolean sign2, Variable offset2, BigDecimal constant)
      Replaces base with +/- offset1 +/- offset2 + constant.
      Parameters:
      base - variable to be replaced
      sign1 - true if sign of the first offset is positive
      offset1 - first offset to be added
      sign2 - true if sign of the second offset is positive
      offset2 - second offset to be added
      constant - constant to be added
      Returns:
      resulting Expolynomial
    • shift

      public void shift(Variable base, Variable offset)
      Replaces base with base + offset.
      Parameters:
      base - variable to be replaced
      offset - offset to be applied
    • integrate

      public Expolynomial integrate(Variable var)
      Computes the primitive function of this expolynomial.
      Parameters:
      var - integration variable
      Returns:
      primitive function
    • integrate

      public Expolynomial integrate(Variable var, OmegaBigDecimal lower, OmegaBigDecimal upper)
      Integrates this expolynomial over an interval.
      Parameters:
      var - integration variable
      lower - lower bound
      upper - upper bound
      Returns:
      resulting expolynomial
    • pow

      public void pow(int n)
      Takes the n-th power of this expolynomial.
      Parameters:
      n - exponent
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isConstant

      public boolean isConstant()
      Checks if this expolynomial is constant.
      Returns:
      true if this expolynomial is constant.
    • isExponential

      public boolean isExponential()
      Checks if this expolynomial contains a single exponential term.
      Returns:
      true if this expolynomial contains a single exponential term
    • getExponentialRate

      public BigDecimal getExponentialRate()
      The exponential rate of the single exponential term contained in this expolynomial. If other terms are present, throws an IllegalStateException.
      Returns:
      true if this expolynomial contains a single exponential term
      Throws:
      IllegalStateException - if this is not a single exponential term
    • fromString

      public static Expolynomial fromString(String string)
      Builds an exponential from a string.
      Parameters:
      string - input string
      Returns:
      exponential instantance
    • isValid

      public static boolean isValid(String string)
      Checks if the input string is a valid expolynomial expression.
      Parameters:
      string - input string
      Returns:
      true if the input string is a valid expolynomial expression.