Examples of BigDec


Examples of lipstone.joshua.parser.types.BigDec

        temp = temp.remove();
      if (temp == null)
        break;
    } while (!(temp = temp.getNextConsCell()).isNull());
   
    BigDec limits[] = {BigDec.ZERO, BigDec.ZERO};
    temp = parser.run(parts.get(1));
    if (temp.getCarType() != ConsType.NUMBER)
      throw new InvalidOperationException("The second and third parameters for the integrate operation must both evaluate to a number", this, "integrate", parts);
    limits[0] = (BigDec) temp.getCar();
    temp = parser.run(parts.get(2));
    if (temp.getCarType() != ConsType.NUMBER)
      throw new InvalidOperationException("The second and third parameters for the integrate operation must both evaluate to a number", this, "integrate", parts);
    limits[1] = (BigDec) temp.getCar();
    if (limits[1] == limits[0])
      return BigDec.ZERO;
    if (limits[1].lt(limits[0])) {
      BigDec tempLim = limits[0];
      limits[0] = limits[1];
      limits[1] = tempLim;
    };
    BigDec answer = BigDec.ZERO;
    if (method.equalsIgnoreCase("trapezoidal"))
      answer = trapezoidal(parts.get(0), limits[0], limits[1], N);
    var = "[xyz]";
    return answer;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   *            the amount to subtract from N
   * @return the standard deviation of this set
   * @throws ParserException
   */
  public BigDec getSTDEV(int subtracter) throws ParserException {
    BigDec mean = getMean(), sigma = BigDec.ZERO;
    if (set.size() <= 1)
      return BigDec.ZERO;
    //Construct sigma
    for (BigDec d : set) {
      ConsCell temp = parser.run(new ConsCell(new ConsCell(d, ConsType.NUMBER, new ConsCell('-', ConsType.OPERATOR, new ConsCell(mean, ConsType.NUMBER), ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL));
      sigma = sigma.add(new BigDec(temp.toString()));
    }
    //Run the root
    return new BigDec(parser.run(new ConsCell(new ConsCell(sigma, ConsType.NUMBER, new ConsCell('/', ConsType.OPERATOR, new ConsCell(new BigDec(set.size() - subtracter), ConsType.NUMBER), ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL, new ConsCell('^', ConsType.OPERATOR, new ConsCell(new BigDec(0.5), ConsType.NUMBER), ConsType.CONS_CELL), ConsType.CONS_CELL)).toString());
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    var = "[xyz]";
    return answer;
  }
 
  private BigDec trapezoidal(ConsCell equation, BigDec min, BigDec max, int N) throws ParserException {
    BigDec output = BigDec.ZERO;
    NIThread thread = new NIThread(equation, parser, N, maxN, accuracy, min, max, new BigDec(500), var, this);
    output = parser.getFjPool().invoke(thread);
    if (thread.error != null)
      throw thread.error;
    return output;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   * @return the most common item in this set
   */
  public BigDec getMode() {
    ArrayList<BigDec> tempSet = new ArrayList<BigDec>(set); //Holds the old set and its order
    sort();
    BigDec mode = BigDec.ZERO, prev = set.get(0);
    int max = 0, count = 0;
    for (int i = 0; i < set.size(); i++) {
      BigDec d = set.get(i);
      if (d.neq(prev)) {
        if (count >= max) {
          max = count;
          mode = set.get(i - 1);
        }
        count = 0;
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      throw thread.error;
    return output;
  }
 
  private ConsCell derivative(ConsCell input) throws ParserException {
    BigDec slope = BigDec.ZERO, slopePos = BigDec.ZERO, slopeNeg = BigDec.ZERO, x = BigDec.ZERO;
    ArrayList<ConsCell> parts = input.splitOnSeparator();
    ConsCell temp = parser.run(parts.get(1));
    if (temp.getCarType() != ConsType.NUMBER) {
      return symbolicDerivative(input);
    }
    x = (BigDec) temp.getCar();
    slopePos = pointDerivative(parts.get(0).clone(), x, 1.0);
    slopeNeg = pointDerivative(parts.get(0), x, -1.0);
    slope = slopePos.add(slopeNeg).divide(new BigDec(2));
    return new ConsCell(slope, ConsType.NUMBER);
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    for (ConsCell varCell : varCells)
      varCell.replaceCar(new ConsCell(x, ConsType.NUMBER));
    ConsCell temp = parser.run(equation);
    if (temp.getCarType() != ConsType.NUMBER)
      throw new UndefinedResultException("The second argument to the derivative operation must cause the first to evaluate to a number.", this);
    BigDec slope = BigDec.ZERO, prevSlope = BigDec.ONE, deltaX = new BigDec(0.0001), y1 = (BigDec) temp.getCar();
   
    BigDec x2 = x.add(deltaX.multiply(new BigDec(direction)));
    for (ConsCell varCell : varCells)
      varCell.replaceCar(new ConsCell(x2, ConsType.NUMBER));
    temp = parser.run(equation);
    if (temp.getCarType() != ConsType.NUMBER)
      throw new UndefinedResultException("The second argument to the derivative operation must cause the first to evaluate to a number.", this);
    //In basic types:  slope = (y1 - Double.parseDouble(parser.run(equation.replaceAll(var, new Double(x+deltaX*direction).toString())))/(x-(x+deltaX*direction)));
    slope = y1.subtract((BigDec) temp.getCar()).divide(deltaX.multiply(new BigDec(direction)));
   
    while (slope.subtract(prevSlope).abs().doubleValue() > accuracy) {
      prevSlope = slope;
      deltaX = deltaX.divide(new BigDec(10.0));
      x2 = x.add(deltaX.multiply(new BigDec(direction)));
      for (ConsCell varCell : varCells)
        varCell.replaceCar(new ConsCell(x2, ConsType.NUMBER));
      temp = parser.run(equation);
      if (temp.getCarType() != ConsType.NUMBER)
        throw new UndefinedResultException("The second argument to the derivative operation must cause the first to evaluate to a number.", this);
      //In basic types:  slope = (y1 - Double.parseDouble(parser.run(equation.replaceAll(var, new Double(x+deltaX*direction).toString())))/(x-(x+deltaX*direction)));
      slope = y1.subtract((BigDec) temp.getCar()).divide(deltaX.multiply(new BigDec(direction)));
    }
    if ((slope.abs().doubleValue() < accuracy) && equation.length() < 4)
      slope = BigDec.ZERO;
    var = "[xyz]";
    return slope.multiply(BigDec.MINUSONE);
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      section.getLastConsCell().remove();
    return section;
  }
 
  private ConsCell stopCases(ConsCell term, ArrayList<String> vars) throws ParserException {
    BigDec coefficient = parser.getCAS().getCoefficient(term, vars);
    if (!parser.containsVariables(term, vars) || coefficient.eq(BigDec.ZERO))
      return new ConsCell(BigDec.ZERO, ConsType.NUMBER, new ConsCell("{true}", ConsType.OBJECT), ConsType.CONS_CELL);
    PairedList<ConsCell, ConsCell> orders = parser.getCAS().orderOfTerm(term, vars);
    int remaining = orders.size();
    for (String str : vars) { //Basically, if a variable's power is 1, taking its derivative gets rid of it.
      if (!orders.containsKey(new ConsCell(str, ConsType.IDENTIFIER)))
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    for (int i = 0; i < functionDerivatives.length; i += 2)
      if (check.equalsIgnoreCase(functionDerivatives[i])) {
        type = i;
        break;
      }
    BigDec coefficient = parser.getCAS().getCoefficient(term, vars);
    ConsCell result = coefficient.neq(BigDec.ONE) ? new ConsCell(coefficient, ConsType.NUMBER, new ConsCell('*', ConsType.OPERATOR), ConsType.CONS_CELL).getLastConsCell() : new ConsCell();
    if (type > -1 && term.getNextConsCell(offset).length() == 1) {
      ConsCell inner = term.getNextConsCell(offset).getCarType() == ConsType.CONS_CELL ? (ConsCell) term.getNextConsCell(offset).getCar() : term.getNextConsCell(offset);
      ConsCell functionOutput = Tokenizer.tokenizeString(functionDerivatives[type + 1]);
      ArrayList<ConsCell> cells = functionOutput.allInstancesOf(new ConsCell("n", ConsType.IDENTIFIER));
      for (ConsCell cell : cells)
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      derivative = new ConsCell(symbolicDerivative(left, vars), ConsType.CONS_CELL, new ConsCell('*', ConsType.CONS_CELL, new ConsCell(right.clone(), ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL);
    if (parser.containsVariables(right, vars))
      derivative = derivative.append(new ConsCell('-', ConsType.OPERATOR, new ConsCell(left.clone(), ConsType.CONS_CELL, new ConsCell('*', ConsType.OPERATOR, new ConsCell(symbolicDerivative(right, vars),
          ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL));
    derivative = new ConsCell(derivative.getFirstConsCell(), ConsType.CONS_CELL);
    derivative.append(new ConsCell('/', ConsType.OPERATOR, new ConsCell(right.clone(), ConsType.CONS_CELL, new ConsCell('^', ConsType.OPERATOR, new ConsCell(new BigDec(2),
        ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL), ConsType.CONS_CELL));
    current.getNextConsCell().removeAll();
    current.replace(derivative);
    return current.getFirstConsCell();
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   
    boolean isMax = false;
    while (!isMax) {
      for (int i = 0; i < ioSet.length; i++) {
        ioSet[i] = ioSet[i].pp();
        if (ioSet[i].gt(new BigDec(max.get(i)))) {
          isMax = true;
          ioSet[i] = BigDec.ZERO;
        }
        else {
          isMax = false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.