public static Sexpr sin(Sexpr arg) { if (arg.isConstant()) return new Constant(Math.Sin(arg.getValue())); else return new Sin(arg); }
public static Sexpr sub(Sexpr l, Sexpr r) { if(l.isConstant() && r.isConstant()) return new Constant(l.getValue() - r.getValue()); else if(l.isZero()) return new Negation(r); else if(r.isZero()) return l; else return new Subtraction(l,r); }
public static Sexpr mult(Sexpr l, Sexpr r) { if(l.isConstant() && r.isConstant()) return new Constant(l.getValue() * r.getValue()); else if(l.isZero() || r.isZero()) return new Constant(0); else if(l.isOne()) return r; else if(r.isOne()) return l; else return new Mult(l,r); }
public static Sexpr neg(Sexpr tecken) { if (tecken.isConstant()) return new Constant(-(tecken.getValue())); else return new Negation(tecken); }
public static Sexpr log(Sexpr arg) { if (arg.isConstant()) return new Constant(Math.Log(arg.getValue())); else return new Log(arg); }
public static Sexpr exp(Sexpr arg) { if (arg.isConstant()) return new Constant(Math.Exp(arg.getValue())); else return new Exp(arg); }
public static Sexpr div(Sexpr l, Sexpr r) { if(r.isZero()) throw new CalculatorException("F�r inte dela med noll"); else { if(l.isConstant() && r.isConstant()) return new Constant(l.getValue() / r.getValue()); else if(l.isZero()) return new Constant(0); else return new Div(l,r); } }
public static Sexpr cos(Sexpr arg) { if (arg.isConstant()) return new Constant(Math.Cos(arg.getValue())); else return new Cos(arg); }
public static Sexpr add(Sexpr l, Sexpr r) { if (l.isConstant() && r.isConstant()) { Sexpr ret = new Constant(l.getValue() + r.getValue()); // return new Constant(l.getValue() + r.getValue()); return ret; } else if (l.isZero()) return r; else if (r.isZero()) return l; else return new addition(l, r); }