Class Formula

java.lang.Object
math.differentialcalculus.Formula

public class Formula extends Object
  • Field Details

    • name

      private String name
      The name assigned to the object.
    • data

      private List<String> data
      The portion of the main expression stored by the object.. usually an SBP.
    • tokenExponentMap

      HashMap<String,List<String>> tokenExponentMap
      Stores all the exponents(which are usually lists of compound tokens as the values in this map, the keys are the unique names used to replace them as the power of the token. e.g if x^(2+3*x+4*y) is scanned, we get x,^,(,2,+,3,*,x,+,4,*,y,) the sublist in brackets is stored as a list in the tokenExponentMap and its key is the name used to store it. This name is auto-generated and used to replace the sub-list that is in brackets, the brackets included. It is also used as the key in this map. E.g. if the name chosen is formula_1 then the key to the map is formula_1, and its value is that sub-list.
  • Constructor Details

  • Method Details

    • setData

      public void setData(List<String> data)
    • getData

      public List<String> getData()
    • approxEquals

      public static boolean approxEquals(double num1, double num2)
    • setName

      public void setName(String name)
    • getName

      public String getName()
    • getVariables

      public ArrayList<String> getVariables()
      Returns:
      an ArrayList containing all the variable names found in this Formula object.
    • hasSameVariables

      public boolean hasSameVariables(Formula formula)
      Parameters:
      formula - The Formula object that we are comparing this Formula object with.
      Returns:
      true if both objects have no variables at all, or if both objects have exactly the same number and the same set of variable names.
    • getFactor

      public double getFactor(Formula formula)
      Parameters:
      formula - The Formula to express as a scalar factor of this Formula...Evaluates this/formula and returns true if the result will always be a constant and Nan if otherwise.
      Returns:
      a constant which is the ratio of this Formula and the parameter Formula and returns Nan if not possible.
    • isEquivalentTo

      public boolean isEquivalentTo(Formula formula)
      This method compares two Formula objects to see if they are mathematically equivalent.
      Parameters:
      formula - The Formula object to be compared with this Formula.
      Returns:
      true if both objects will always evaluate to a common value.
    • simplifyCompoundTokens

      static void simplifyCompoundTokens(List<String> list)
      A Compound token is simply used to describe a group of tokens found between 2 +|- and +|- symbols or before a +|- symbol(at the beginning of the parent list before any +|- has been encountered) or at the end of the parent list after all +|- have been passed. They typically never include any + or - symbol
      Parameters:
      list - A group of tokens that do not contain any +|- but represent a mathematically correct expression.. e.g. 2,*,x,*,x e.t.c.
    • simplify

      public static void simplify(List<String> list)
      Simplifies a Single-Bracket-Pair algebraic expressions's tokens.
      Parameters:
      list - An ArrayList of tokens of an algebraic expressions.
    • toString

      public String toString()
      Overrides:
      toString in class Object