Expression derive(String toVar)

Derives this expression with respect to the given variable.

Source

Expression derive(String toVar) {
  MathFunction gDF;
  Expression gD = g.derive(toVar);

  if (!(gD is MathFunction)) {
  // Build function again..
    gDF = new CustomFunction('d${g.name}', g.args, gD);
  } else {
    gDF = (gD as MathFunction);
  }

  // Chain rule.
  return new CompositeFunction(f, gDF) * f.derive(toVar);
}