@Override
public boolean isApplicable(Rule rule) {
boolean isApplicable = false;
List<Expression> subs = new ArrayList();
Expression t;
subs.addAll(terms);
for (int i = 0; i < subs.size(); i++) {
t = subs.get(i);
if (t.isApplicable(rule)) {
isApplicable = true;
if (rule.isRecursive()) {
subs.add(i, rule.subapply());
}
}
}
Expression transformed = isApplicable && rule.isRecursive() ? new Sum(subs) : this;
if (rule.matches(transformed)) {
return true;
} else if (isApplicable) {
rule.register(transformed);