Examples of BigDec


Examples of lipstone.joshua.parser.types.BigDec

    ArrayList<Point> reExpressed = new ArrayList<Point>();
    for (int i = 0; i < reExpression.length; i++)
      reExpression[i] = parser.preProcess(reExpression[i]);
    System.out.println(reExpression[0] + " " + reExpression[1]);
    for (Point p : points) {
      BigDec pos[] = p.getPosition();
      for (int i = 0; i < reExpression.length; i++) {
        pos[i] = new BigDec(parser.run(reExpression[i].replaceAll("[xyz]", pos[i].toString())));
      }
      Point point = new Point(p);
      System.out.println(point.getPosition()[0] + " " + point.getPosition()[1]);
      point.setPosition(pos);
      reExpressed.add(point);
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      for (int i = 0; i <= 1; i++) {
        int iterations = 0;
        numPoints = 0;
        while (numPoints <= 1.3 * 20 * (Double.parseDouble(parser.run("10^(" + accuracy + "-1)")))) {
          Double deltax = (scale[0]) / (Double.parseDouble(parser.run("10^(" + accuracy + "-1)")));
          BigDec x = new BigDec((iterations * deltax) * (1 - 2 * i));
          BigDec y = new BigDec(parser.run(equation.replaceAll("[xyz]", "(" + x.toString() + ")")));
          linePoints.add(new Point(x, y, name, color, 5));
          iterations++;
          numPoints++;
        }
        refreshLine = false;
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      @Override
      public Token action(Matcher match, Lexer lexer, Type<Number> type) throws LexerException {
        String number = match.group(2), t = match.group(4);
        if (number.contains("n"))
          if (number.startsWith("-"))
            return new Token(new PrimitiveObject<>(complexClass, new BigDec(-1)), complexType);
          else
            return new Token(new PrimitiveObject<>(complexClass, new BigDec(1)), complexType);
        if (t != null) {
          switch (t) {
            case "f":
              return new Token(new PrimitiveObject<>(floatClass, new Float(number)), floatType);
            case "d":
              return new Token(new PrimitiveObject<>(doubleClass, new Double(number)), doubleType);
            case "l":
              return new Token(new PrimitiveObject<>(longClass, new Long(number)), longType);
            case "i":
              return new Token(new PrimitiveObject<>(complexClass, new BigDec(match.group())), complexType);
          }
        }
        if (number.contains("."))
          return new Token(new PrimitiveObject<>(doubleClass, new Double(number)), doubleType);
        return new Token(new PrimitiveObject<>(integerClass, new Integer(number)), integerType);
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

  public ConsCell runOperation(String operation, ConsCell input) throws ParserException {
    if (operation.equals("abs")) {
      ConsCell temp = parser.run(input);
      if (temp.getCarType() != ConsType.NUMBER || temp.length() != 1)
        throw new UndefinedResultException("The single argument to the absolute value operation must evaluate to a number.", this);
      return new ConsCell(new BigDec(((BigDec) temp.getCar()).abs()), ConsType.NUMBER);
    }
    return null;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

              makeNegative = true;
            second.remove();
            second = current.getNextConsCell(2);
          }
          if (current.getCarType() == ConsType.NUMBER && second.getCarType() == ConsType.NUMBER) {
            BigDec num1 = (BigDec) current.getCar(), num2 = ((BigDec) second.getCar()).multiply(makeNegative ? BigDec.MINUSONE : BigDec.ONE), output = BigDec.ZERO;
            second.remove(); //num2
            current.getNextConsCell().remove(); //operator
           
            if (operator == '%')
              output = num1.mod(num2);
            else if (operator == '^') {
              while (current.getNextConsCell().getCarType() == ConsType.OPERATOR && (Character) current.getNextConsCell().getCar() == '^') {
                boolean negate = false;
                while (current.getNextConsCell(2).getCarType() == ConsType.OPERATOR) {
                  if ((Character) current.getNextConsCell(2).getCar() == '-')
                    negate = !negate;
                  current.getNextConsCell(2).remove();
                }
                if (current.getNextConsCell(2).getCarType() != ConsType.NUMBER)
                  throw new UndefinedResultException("For stacked exponents, each subsequent exponent must evaluate to a number", null);
                num2 = num2.pow(negate ? ((BigDec) current.getNextConsCell(2).getCar()).multiply(BigDec.MINUSONE) : (BigDec) current.getNextConsCell(2).getCar());
                current.getNextConsCell().remove();
                current.getNextConsCell().remove();
              }
              output = num1.pow(num2);
            }
            else if (operator == '*')
              output = num1.multiply(num2);
            else if (operator == '/')
              output = num1.divide(num2);
            else if (operator == '+')
              output = num1.add(num2);
            else if (operator == '-')
              output = num1.subtract(num2);
            else
              throw new UndefinedResultException(lastPlugin);
            current.replaceCar(new ConsCell(output, ConsType.NUMBER));
            forward = false;
          }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    parts = parts.get(0).splitOnIdentifier("=");
    if (parts.size() > 2)
      throw new UndefinedResultException("Incorrectly formatted equation.  Please use only 2-sided equalities.", null);
    if (parts.size() > 1) {
      if (parser.getVars().size() == 0 || !parser.containsVariables(input, parser.getVars())) {
        if (new BigDec(parser.run(parts.get(0)).carToString()).eq(new BigDec(parser.run(parts.get(1)).carToString())))
          return new ConsCell("true", ConsType.IDENTIFIER);
        else
          return new ConsCell("false", ConsType.IDENTIFIER);
      }
      input = parts.get(0).getLastConsCell().append(invertSign(parts.get(1))).getFirstConsCell();
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      return stepSolveDomain(equation, xMin, xMax, delta);
  }
 
  public ArrayList<BigDec> stepSolveDomain(ConsCell equation, BigDec xMin, BigDec xMax, BigDec delta) throws ParserException {
    ArrayList<BigDec> output = new ArrayList<BigDec>();
    StepSolveThread thread = new StepSolveThread(equation, parser, delta, accuracy, xMin, xMax, parser.getVars(), new BigDec(500));
    parser.getFjPool().execute(thread);
    output = thread.join();
    if (thread.error != null)
      throw thread.error;
    return output;
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

      throw thread.error;
    return output;
  }
 
  private ArrayList<BigDec> stepSolveInfinite(ConsCell equation) throws ParserException {
    BigDec xMin = BigDec.ZERO, xMax = new BigDec(1000);
    ArrayList<BigDec> answers = new ArrayList<BigDec>();
    while (answers.size() == 0) {
      for (BigDec answer : stepSolveDomain(equation, xMin, xMax, delta))
        answers.add(answer);
      if (xMin.gteq(BigDec.ZERO))
        xMin = xMin.add(xMax.multiply(new BigDec(2)));
      xMin = xMin.multiply(BigDec.MINUSONE);
    }
    return answers;
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

   */
  private ArrayList<BigDec> formSolve(ConsCell equation) throws ParserException {
    ArrayList<BigDec> solutions = new ArrayList<BigDec>();
    ArrayList<ConsCell> terms = foldSigns(getTerms(simplifyTerms(equation)));
    PairedList<ConsCell, BigDec> orders = new PairedList<>();
    BigDec highestOrder = BigDec.ZERO;
    for (ConsCell term : terms) {
      PairedList<ConsCell, ConsCell> order = orderOfTerm(term, parser.getVars());
      if (order.size() > 1)
        return new ArrayList<BigDec>();
      BigDec o = BigDec.ZERO;
      if (order.size() > 0 && order.get(order.getKeys().get(0)).getCarType() == ConsType.NUMBER)
        o = ((BigDec) order.get(order.getKeys().get(0)).getCar());
      if (o.gt(highestOrder))
        highestOrder = o;
      orders.put(term, o);
    }
   
    BigDec modifier = null;
    BigDec[] form = new BigDec[]{BigDec.ONE, BigDec.ZERO};
    if ((modifier = matchesForm(orders, highestOrder, form)) != null) { //Linear
      if (linearEquation == null) { //Initialize the linear equation structure.  This makes subsequent calls faster.
        linearEquationHooks[0] = new ConsCell("a", ConsType.IDENTIFIER);
        linearEquationHooks[1] = new ConsCell("b", ConsType.IDENTIFIER, new ConsCell('/', ConsType.OPERATOR, linearEquationHooks[0]));
        linearEquation = new ConsCell('-', ConsType.OPERATOR, linearEquationHooks[1]);
      }
     
      BigDec a = BigDec.ZERO, b = BigDec.ZERO;
     
      form[0] = form[0].subtract(modifier);
      form[1] = form[1].subtract(modifier);
      for (ConsCell term : orders) {
        BigDec order = orders.get(term);
        if (order.eq(form[1]))
          b = b.add(getCoefficient(term));
        else
          a = a.add(getCoefficient(term));
      }
     
      linearEquationHooks[0].replaceCar(new ConsCell(a, ConsType.NUMBER));
      linearEquationHooks[1].replaceCar(new ConsCell(b, ConsType.NUMBER));
      solutions.add(new BigDec(parser.run(linearEquation.clone()).toString()));
    }
   
    if (solutions.size() == 0 && (modifier = matchesForm(orders, highestOrder, (form = new BigDec[]{new BigDec(2), BigDec.ONE, BigDec.ZERO}))) != null) { //Quadratic
      if (quadraticEquation == null) { //Initialize the quadratic equation structure.  This makes subsequent calls faster.
        quadraticEquation = Tokenizer.tokenizeString("(-b\"+-\"(b^2-4*a*c)^0.5)/(2*a)");
        quadraticEquationHooks[0] = quadraticEquation.allInstancesOf(new ConsCell("a", ConsType.IDENTIFIER));
        quadraticEquationHooks[1] = quadraticEquation.allInstancesOf(new ConsCell("b", ConsType.IDENTIFIER));
        quadraticEquationHooks[2] = quadraticEquation.allInstancesOf(new ConsCell("c", ConsType.IDENTIFIER));
        quadraticEquationHooks[3] = quadraticEquation.allInstancesOf(new ConsCell("+-", ConsType.STRING));
      }
     
      BigDec a = BigDec.ZERO, b = BigDec.ZERO, c = BigDec.ZERO;
     
      form[0] = form[0].subtract(modifier);
      form[1] = form[1].subtract(modifier);
      form[2] = form[2].subtract(modifier);
      for (ConsCell term : orders) {
        BigDec order = orders.get(term);
        if (order.eq(form[2]))
          c = c.add(getCoefficient(term));
        else if (order.eq(form[1]))
          b = b.add(getCoefficient(term));
        else
          a = a.add(getCoefficient(term));
      }
     
      for (ConsCell cell : quadraticEquationHooks[0])
        cell.replaceCar(new ConsCell(a, ConsType.NUMBER)); //a
      for (ConsCell cell : quadraticEquationHooks[1])
        cell.replaceCar(new ConsCell(b, ConsType.NUMBER)); //b
      quadraticEquationHooks[2].get(0).replaceCar(new ConsCell(c, ConsType.NUMBER)); //c
     
      quadraticEquationHooks[3].get(0).replaceCar(new ConsCell('+', ConsType.OPERATOR)); //+
      solutions.add(new BigDec(parser.run(quadraticEquation.clone()).toString()));
      quadraticEquationHooks[3].get(0).replaceCar(new ConsCell('-', ConsType.OPERATOR)); //-
      solutions.add(new BigDec(parser.run(quadraticEquation.clone()).toString()));
    }
    return checkSolutions(solutions, equation, accuracy);
  }
View Full Code Here

Examples of lipstone.joshua.parser.types.BigDec

    }
    return checkSolutions(solutions, equation, accuracy);
  }
 
  private BigDec matchesForm(PairedList<ConsCell, BigDec> orders, BigDec highestOrder, BigDec[] form) throws UndefinedResultException {
    BigDec modifier = form[0].subtract(highestOrder);
    for (BigDec order : orders.getValues()) {
      boolean matches = false;
      for (BigDec o : form)
        if (o.eq(order.add(modifier))) {
          matches = true;
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.