@Override protected Multiplication create(Expression left, Expression right) { return new Multiplication(left, right); } }
/** * 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 void visit(Multiplication node) { handlebinary(node); resultExpr = new Multiplication(left, right); left=null; right=null; }
@Override public Expression visitMultiplication(MaximaParser.MultiplicationContext ctx) { return new Multiplication(visit(ctx.left), visit(ctx.right)); }
@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 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 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); }
/** recursive function to create an Expression out of a multivector * */ public Expression createExpression(GaaletMultiVector vec){ GaaletBladeTable table = vec.getTable(); if (vec.getGaalopBlades().size() <= 0) return new FloatConstant(0.0f); //empty vector Set<Integer> key = vec.getGaalopBlades().keySet(); Set<Expression> expressionBlades = new HashSet<Expression> (); // here we store every blades //multiplication with a base vector. for (Integer index :key ) { //lets create a set of the basisBlades expressions vec.getGaalopBlades().get(key); // what we do is: we search in the table for the right BladeExpression and multiplicate // it with the value of the blade stored in the multivector. //System.out.println(table.getExpression(index)+ " :: "+vec.getGaalopBlades().get(index)); expressionBlades.add(new Multiplication(table.getExpression(index),vec.getGaalopBlades().get(index))); } //this times blade return recCreateAddTree(expressionBlades); // add up all expressions }
@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//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) { 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); }
@Override public void visit(Division node) { resultValue = new Multiplication(node.getLeft(), new MathFunctionCall(node.getRight(), MathFunction.INVERT)); } };
@Override public Expression copy() { return new Multiplication(getLeft().copy(), getRight().copy()); }
@Override public void visit(Division node) { if (node.getRight() instanceof FloatConstant) { FloatConstant newLeft = new FloatConstant(1/((FloatConstant) node.getRight()).getValue()); replaceWith = new Multiplication(newLeft, node.getLeft()); } }
@Override //dfg public void visit(Exponentiation node) { if(isSquare(node)){ handlebinary(new Multiplication(node.getLeft(), node.getLeft())); }else{ handlebinary(node); } }
@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//dfg public void visit(Exponentiation node) { if (isSquare(node) && (node.getLeft() instanceof Variable)) { String varname = null; if(node.getLeft() instanceof MultivectorComponent){ varname = ((MultivectorComponent)node.getLeft()).getName() + ((MultivectorComponent)node.getLeft()).getBladeIndex(); } else varname= ((Variable)node.getLeft()).getName(); if (!myHashmap.containsKey(varname)){ myHashmap.put(varname, ( varname + "_quad")); AddedExponentiationBang = new AssignmentNode(cfg, new Variable(varname+"_quad"), new Multiplication(node.getLeft(), node.getLeft())); //new AssignmentNode(cfg,new Variable(varname+"_quad"),node.copy()); currentAssignment.insertBefore(AddedExponentiationBang); } nx = new Variable(myHashmap.get(varname)); } else // left is novariable or node is no square { node.getLeft().accept(this); Expression lhs =nx; node.getRight().accept(this); Expression rhs =nx; nx = new Exponentiation(lhs, rhs); } }
@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(Exponentiation node) { Multiplication nodeMul; if (isSquare(node)) { nodeMul = new Multiplication(node.getLeft(), node.getLeft()); nx = nodeMul; if (opstor.OperationShouldBeReplaced(nodeMul)) { nx = new Variable(opstor.getReplacementID(nodeMul)); } } else { 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 Exponentiation(lhs, rhs); } } }
@Override public void visit(Division node) { node.getLeft().accept(this); Expression left = resultExpr; node.getRight().accept(this); Expression right = resultExpr; if(left instanceof FloatConstant && ((FloatConstant)left).getValue() == 1.0) { resultExpr = new Division(left, right); } else { resultExpr = new Multiplication(left, new Division(new FloatConstant("1.0"), right)); } if ((left instanceof FloatConstant) && (right instanceof FloatConstant)) { FloatConstant leftc = (FloatConstant) left; FloatConstant rightc = (FloatConstant) right; resultExpr = new FloatConstant(leftc.getValue() / rightc.getValue()); } else if ((node.getRight() instanceof FloatConstant)) { /* division by 1 gets canceld */ FloatConstant floatConst = (FloatConstant) node.getRight(); if (floatConst.getValue() == 1.0) { resultExpr = left; } } }