6667686970717273747576
*/ private class AdditionSubtraction extends SubRule { @Override public boolean matches(Expression expr) { Addition apb = new Addition(a, b); Subtraction bmc = new Subtraction(b, c); return new Subtraction(apb, c).matches(expr) || new Addition(a, bmc).matches(expr); }
75767778798081
new Addition(a, bmc).matches(expr); } @Override public Expression apply() { return new Sum(new Subtraction(new Addition(a.evaluate(), b.evaluate()), c.evaluate())); }
88899091929394
@Override public boolean matches(Expression expr) { Subtraction amb = new Subtraction(a, b); return new Addition(amb, c).matches(expr); }
93949596979899
return new Addition(amb, c).matches(expr); } @Override public Expression apply() { return new Sum(new Addition(new Subtraction(a.evaluate(), b.evaluate()), c.evaluate())); }
345346347348349350351352353354355
} } Expression sd = new Sqrt(dd); Expression x1 = new Division( new Addition(new Negation(b), sd), new Multiplication(two, a)); Expression x2 = new Division( new Subtraction(new Negation(b), sd), new Multiplication(two, a));