s.replace(common, new Branch(Function.MINUS, a, b));
}
public static void applyChainRule(Selection s, Branch common, Branch end, KnownArguments knownArguments) {
// (derivative (f g) x) -> (times (derivative f g) (derivative g x))
Token q = new Token(new Word("q")); // knownArguments.getUnusedVariable()
Branch f = end.getParentBranch().cloneBranch();
Argument g = Argument.cloneArgument(end);
for (Argument a : new ArgumentVector(f, ArgumentVector.REVERSE_ITERATOR_ORDER)) { // exp(1+cos(x)) -> exp(q) @ q=1+cos(x)
if (a.equals(g)) {
a.replace(Argument.cloneArgument(q));