Khan/KAS — pull request #2 by Merbs (2013-11-14 01:09:01+00:00)
Title: Add differentiation, options, parseArray

Most of the proposed changes are adding the functionality to differentiate. To that end, a couple helper functions (sameAs, contains, copy, ... ) were defined.

In addition, KAS's parse function got a sister parseArray, who takes in something like `["+",4.5,["sin",["*","x","y","z"]],["^","e",3]]` and makes it into KAS's internal `Add(Float(4.5), Trig("sin", Mul(Var("x"), Var("y"), Var("z"))), Pow(Const("e"), Int(3)))`, which can then be printed, tex'd, differentiated, etc. The function was inspired by the utils polynomials/calculus/expressions format, and a generateMultivariateFunction() was added to calculus.js in that fashion. To see it in use, I made the exercise exact_equations.

At the bequest of Alex's (@alopatin) comments (and my own aesthetic sanity), the simplify function got a makeover. Among the changes are adding reciprocal trig functions (e.g. `1/cos(x)` to `sec(x)`), combining unequal trig exponents, and adding a super-simplify flag (via an options object that is now passed almost everywhere). Notably it has (at least one) breaking change, in that `ln(xy)`, `|xy|` and `z^(x+y)` are no longer expanded by default. But that was by changing a true to a false, and can be changed back. Another noticeable change is that `1-x` no longer shows up as `1-1x`, which seemed to be a bug rather than a feature. And expressions are ordered [vars, powers, logs, trigs, expressions].

The allAddTermsWith and allAddTermsWithout should probably be generalized to a single function, and I didn't come up with any nice way to expose the Var node to the KAS scope (hence the extra allAddTermsWithoutX/Y functions).

Several other small fixes are proposed. This undid some linting ... sorry. For more detail regarding errors (like why the `1-1x` had a -1 in there), either ask or some detail is in the commits in https://github.com/Khan/khan-exercises/pull/114426.