@Override//dfg public void visit(Multiplication node) { node.getLeft().accept(this); Expression lhs =nx; node.getRight().accept(this); Expression rhs =nx; nx = new Multiplication(lhs, rhs); }
@Override public void visit(Multiplication node) { 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.getLeft().accept(this); Expression lhs = nx; node.getRight().accept(this); Expression rhs = nx; nx = new Multiplication(lhs, rhs); } } @Override
@Override protected Multiplication create(Expression left, Expression right) { return new Multiplication(left, right); } }
@Override public void visit(Exponentiation exponentiation) { if (isSquare(exponentiation)) { Multiplication m = new Multiplication(exponentiation.getLeft(), exponentiation.getLeft()); m.accept(this); } else { code.append("pow("); exponentiation.getLeft().accept(this); code.append(','); exponentiation.getRight().accept(this); code.append(')'); } }
@Override public void visit(Multiplication node) { handlebinary(node); resultExpr = new Multiplication(left, right); left=null; right=null; }
@Override public void visit(Exponentiation exponentiation) { if (isSquare(exponentiation)) { Multiplication m = new Multiplication(exponentiation.getLeft(), exponentiation.getLeft()); m.accept(this); } else { append("Math.pow("); exponentiation.getLeft().accept(this); append(','); exponentiation.getRight().accept(this); append(')'); } }
@Override public void visit(Multiplication node) { result = null; node.getLeft().accept(this); Expression leftResult = result; node.getRight().accept(this); Expression rightResult = result; if (leftResult != null || rightResult != null) result = new Multiplication(leftResult, rightResult); }
/** * Creates an exponentation node that squares the given expression. * * @param base The expression that should be squared. A deep copy will be created. * @return An exponentation object that exponentiates the given base with a float constant of 2.0. */ public static Multiplication square(Expression base) { return new Multiplication(base, base.copy()); }
@Override public Expression copy() { return new Multiplication(getLeft().copy(), getRight().copy()); }
/** * Converts this multiplication to a human readable string representation. * * @return The string "<code>left * right</code>" where left and right have both been converted to * strings using their toString methods. */ public String toString() { return bracketComposite(getLeft()) + " * " + bracketComposite(getRight()); }
@Override public Expression visitMultiplication(MaximaParser.MultiplicationContext ctx) { return new Multiplication(visit(ctx.left), visit(ctx.right)); }
@Override public void visit(Multiplication node) { node.getLeft().accept(this); Expression dLeft = result; node.getRight().accept(this); Expression dRight = result; if (dLeft == zero) { if (dRight == zero) { result = zero; } else { result = new Multiplication(node.getLeft().copy(), dRight); } } else { //dLeft != zero !! if (dRight == zero) { result = new Multiplication(dLeft, node.getRight().copy()); } else { result = new Addition( new Multiplication(dLeft, node.getRight().copy()), new Multiplication(node.getLeft().copy(), dRight) ); } } }
@Override public Object visitMultiplication(CluCalcParser.MultiplicationContext ctx) { return new Multiplication((Expression) visit(ctx.left), (Expression) visit(ctx.right)); }
@Override public void visit(Multiplication node) { node.getLeft().accept(this); Expression left = resultExpr; node.getRight().accept(this); Expression right = resultExpr; resultExpr = new Multiplication(left, right); if ((left instanceof FloatConstant) && (right instanceof FloatConstant)) { 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);
@Override public void visit(Exponentiation node) { if (node.getRight() instanceof FloatConstant) { double constant = ((FloatConstant) node.getRight()).getValue(); int integer = (int) Math.round(constant); if (integer>0 && integer<=3) if (Math.abs(constant-integer) < 10E-7) { //Unfold //TODO chs set a new temporary variable, if left is of big height switch (integer) { case 1: result = node.getLeft(); return; case 2: result = new Multiplication(node.getLeft(), node.getLeft()); return; case 3: result = new Multiplication(new Multiplication(node.getLeft(),node.getLeft()), node.getLeft()); return; } } } super.visit(node); }