1 package JSci.maths.symbolic; 2 3 import JSci.maths.*; 4 import JSci.maths.groups.*; 5 import JSci.maths.fields.*; 6 7 import java.util.*; 8 9 10 public class Variable extends Expression { 11 private final String name; 12 private final Object valueSet; 13 private Member value=null; 14 15 21 public Variable(String n,Object valueSet) { 22 name=n; 23 this.valueSet=valueSet; 24 } 25 26 29 public void setValue(Member o) { 30 if (o==null) { value=null; return; } 31 if (valueSet.getClass().isInstance(o.getSet())) 32 value=o; 33 else 34 throw new ClassCastException ("Variable "+this+" set to "+o.getSet()+" value ("+valueSet+" required."); 35 } 36 37 40 public Member getValue() { 41 return value; 42 } 43 44 public boolean equals(Object o) { 45 if (!(o instanceof Variable)) return false; 46 else return this==o; 47 } 48 49 public String toString() { return name; } 50 51 public Expression differentiate(Variable x) { 52 if (this.equals(x)) return new Constant(((Ring)valueSet).one()); 53 else return new Constant(((AbelianGroup)valueSet).zero()); 54 } 55 56 public Expression evaluate() { 57 if (value==null) return this; 58 if (value instanceof Expression) return ((Expression)value).evaluate(); 59 return new Constant(value); 60 } 61 62 protected int getPriority() {return 20;} 63 64 public Object getSet() { return (AbelianGroup)valueSet; } 65 66 } 67 | Popular Tags |