private AlgebExpression LookAndAddValue(AlgebVal val) { if (val.Coaf == 0) return this; if (this.op == Operation.Value) return this + val; if (this.op == Operation.Addition) { if (this.right.value.Value.Coaf == 0) return left.LookAndAddValue(val); else if (this.right.value.Value.Pow == val.Pow) return left + (right.value.Value + val); else return left.LookAndAddValue(val) + right; } else throw new InvalidOperationException("can only be done on addition trees"); }
public AlgebExpression(AlgebVal val) { op = Operation.Value; value = val; }
public static bool TryParse(string s, out AlgebVal av) { Regex avreg = new Regex(@"^\-?[0-9\.]*x?\^?[0-9]*$"); if (avreg.IsMatch(s)) { if (!s.Contains('x')) s = s + "x^0"; if (s.EndsWith("x")) s = s + "^1"; if (s.StartsWith("x")) s = "1" + s; av = Parse(s); return true; } av = new AlgebVal(0, 0); return false; }