private Expression processFunction(String name, Expression arg) { for (MathFunction mathFunction : MathFunction.values()) if (mathFunction.toString().toLowerCase().equals(name)) return new MathFunctionCall(arg, mathFunction); throw new IllegalArgumentException("Function " + name + " is not supported by maxima parser"); }
@Override public void visit(Division node) { resultValue = new Multiplication(node.getLeft(), new MathFunctionCall(node.getRight(), MathFunction.INVERT)); } };
@Override public Expression copy() { return new MathFunctionCall(getOperand().copy(), function); }
@Override public Expression visitConstant(MaximaParser.ConstantContext ctx) { String text = ctx.getText(); if ("%pi".equals(text)) return new FloatConstant(Math.PI); if ("%i".equals(text)) return new MathFunctionCall(new FloatConstant(-1), MathFunction.SQRT); return new FloatConstant(Double.parseDouble(text)); }
@Override public void visit(MathFunctionCall node) { result = null; node.getOperand().accept(this); if (result != null) result = new MathFunctionCall(result, node.getFunction()); }
@Override public void visit(MathFunctionCall node) { node.getOperand().accept(this); resultExpr = new MathFunctionCall(resultExpr, node.getFunction()); }
@Override public void visit(MathFunctionCall node) { node.getOperand().accept(this); Expression previousExpr = resultExpr; resultExpr = new MathFunctionCall(previousExpr, node.getFunction()); if ((node.getFunction() == MathFunction.SQRT) && (previousExpr instanceof FloatConstant)) { FloatConstant operand = (FloatConstant) previousExpr; resultExpr = new FloatConstant(Math.sqrt(operand.getValue())); } else if ((node.getFunction() == MathFunction.ABS) && (previousExpr instanceof MathFunctionCall)) { /* remove abs() around sqrts, as they are always positive */ MathFunctionCall insideFunc = (MathFunctionCall) previousExpr; if (insideFunc.getFunction() == MathFunction.ABS || insideFunc.getFunction() == MathFunction.SQRT) resultExpr = previousExpr; } else if ((node.getFunction() == MathFunction.SQRT) && ((!(previousExpr instanceof MathFunctionCall)) || (((MathFunctionCall) previousExpr).getFunction() != MathFunction.ABS))) { /* insert in every sqrt() an abs() */ resultExpr = new MathFunctionCall(new MathFunctionCall(previousExpr, MathFunction.ABS), MathFunction.SQRT); } }
result.bladeExpressions[0] = new MathFunctionCall(new MathFunctionCall(i0, MathFunction.ABS), MathFunction.SQRT); result.bladeExpressions[0] = new MathFunctionCall(expressions.get(node.getOperand()).bladeExpressions[0], MathFunction.SQRT); break; default: result.bladeExpressions[0] = new MathFunctionCall(expressions.get(node.getOperand()).bladeExpressions[0], node.getFunction()); System.err.println("Warning: " + node.getFunction().toString() + " is only implemented for scalar inputs!"); break;
@Override public void visit(MathFunctionCall node) { //TODO Schluckt nachkommende werte if (opstor.OperationShouldBeReplaced(node)) { nx = new Variable(opstor.getReplacementID(node)); System.out.println("Replacer: Node in Set: ( " + node.toString() + " ) ---> Replacing with " + opstor.getReplacementID(node)); } else { node.getOperand().accept(this); nx = new MathFunctionCall(nx, node.getFunction()); } //nx = node; }
if (f.name().toLowerCase().equals(macroCallName.toLowerCase())) { result = new MathFunctionCall(node.getArguments().get(0), f); return;
boolean isSqrt = rightc.getValue() - (double) new Double(rightc.getValue()).intValue() == 0.5; if(isSqrt && rightc.getValue() != 0.5) { MathFunctionCall newsqrt = new MathFunctionCall(new Exponentiation( left, new FloatConstant(rightc.getValue() - 0.5f)), MathFunction.SQRT); resultExpr = newsqrt; MathFunctionCall newsqrt = new MathFunctionCall(left, MathFunction.SQRT); newsqrt.accept(this); } else if (rightc.getValue() == 2.0) {
new Division( result, new MathFunctionCall( new Subtraction( new FloatConstant(1), result = new Division( result, new MathFunctionCall( new Subtraction( new FloatConstant(1), result = new Negation( new Multiplication( new MathFunctionCall( node.getOperand().copy(), MathFunction.SIN if (result != zero) result = new Multiplication( new MathFunctionCall( node.getOperand().copy(), MathFunction.EXP if (result != zero) result = new Multiplication( new MathFunctionCall( node.getOperand().copy(), MathFunction.COS
Expression dv = result; result = new Multiplication( new Multiplication(dv, new MathFunctionCall(node.getLeft().copy(), MathFunction.LOG)), node.copy() ); Expression dv = result; result = new Multiplication(new Addition( new Multiplication(dv, new MathFunctionCall(node.getLeft().copy(), MathFunction.LOG)), new Division(new Multiplication(node.getRight().copy(), dLeft), node.getLeft().copy()) ),
boolean isSqrt = doubleEquals(rightc.getValue() - (double) new Double(rightc.getValue()).intValue(), 0.5f); if (isSqrt && !doubleEquals(rightc.getValue(), 0.5f)) { MathFunctionCall newsqrt = new MathFunctionCall(new Exponentiation( left, new FloatConstant(rightc.getValue() - 0.5f)), MathFunction.SQRT); resultExpr = newsqrt; setGraphModified(); } else if (doubleEquals(rightc.getValue(), 0.5f)) { MathFunctionCall newsqrt = new MathFunctionCall(left, MathFunction.SQRT); newsqrt.accept(this); setGraphModified();
node.getOperand().accept(this); Expression operandExpr = resultExpr; resultExpr = new MathFunctionCall(operandExpr, node.getFunction()); if ((node.getFunction() == MathFunction.SQRT) && isConstant(operandExpr)) {
if ((leftFunc.getFunction() == MathFunction.ABS) && (rightFunc.getFunction() == MathFunction.ABS)) { resultExpr = new MathFunctionCall(new Multiplication(rightFunc.getOperand(), leftFunc.getOperand()), MathFunction.ABS); resultExpr = new MathFunctionCall(new Multiplication(rightFunc.getOperand(), leftFunc.getOperand()), MathFunction.SQRT);
if ((leftFunc.getFunction() == MathFunction.ABS) && (rightFunc.getFunction() == MathFunction.ABS)) { resultExpr = new MathFunctionCall(new Multiplication(rightFunc.getOperand(), leftFunc.getOperand()), MathFunction.ABS); setGraphModified(); resultExpr = new MathFunctionCall(new Multiplication(rightFunc.getOperand(), leftFunc.getOperand()), MathFunction.SQRT); setGraphModified();