1 package JSci.maths.symbolic; 2 3 import JSci.maths.*; 4 import JSci.maths.fields.*; 5 import JSci.maths.groups.*; 6 7 import java.util.*; 8 9 class Negative extends Expression { 10 11 private final Expression arg; 12 13 public Negative(Expression arg) { 14 this.arg=arg; 15 } 16 17 public String toString() { 18 String r = "-"; 19 if (arg.getPriority()<getPriority()) r+="("+arg+")"; 20 else r+=""+arg; 21 return r; 22 } 23 24 public Expression differentiate(Variable x) { 25 return new Negative(arg.differentiate(x)); 26 } 27 28 public Expression evaluate() { 29 Expression a = arg.evaluate(); 30 if (a instanceof Constant) { 31 AbelianGroup.Member p = (AbelianGroup.Member)((Constant)a).getValue(); 32 return new Constant(p.negate()); 33 } 34 return new Negative(a); 35 } 36 37 protected int getPriority() {return -1;} 38 39 public Object getSet() { return arg.getSet(); } 40 41 } 42 43 44 45 | Popular Tags |