ApasScript.

Symbolic Algebra

diff

The symbolic derivative of an expression with respect to a named variable; diff(f, x, n) the n-th derivative (n from 1 to 20). A symbolic call inside is worked out first: diff(diff(f, x), x).

expand

Expands a symbolic expression, distributing products over sums (and over sums inside sums), a power of a product factor by factor. A polynomial comes out highest degree first. Names the script has bound to numbers are put in: with k = 5, expand(k*(x + 1)) is 5x + 5. A power of a power with a whole outer exponent is one power: (x^3)^4 is x^12 and expand((x^2 + 3)^2) is x^4 + 6x^2 + 9; with any other outer exponent it stays as written, in brackets, (x^2)^(1/2).

collect

Simplifies a symbolic expression to canonical form, collecting like terms and like factors.

simplify

Reduces a rational expression in one variable: the common polynomial factor of the top and the bottom is cancelled, and the answer is written as a fraction ((x^2 - 9)/(x + 3) is x - 3; 3x^3/x^5 is 3/x^2; (x^2 - 1)/(x^2 + 2x + 1) is (x - 1)/(x + 1)). Anything else (more than one variable, a function call, a sum of fractions) comes back as collect gives it. The values where a cancelled factor is zero stay undefined in the original expression; the text of a lesson names them.

integrate

The symbolic indefinite integral of an expression with respect to a named variable, via a pattern table -- refuses (rather than guesses) outside its covered forms. A power with a letter exponent takes the power rule, the exponent taken as not -1: integrate(V^(-g), V) = V^(1 - g)/(1 - g). An odd power times e^(c x^2) goes by u = x^2: integrate(x^3*exp(-x^2), x) = -(x^2 + 1)e^(-x^2)/2; an even power has no elementary integral (see defint for its moments). The table holds sec, csc, cot, atan, asin, acos, sinh, cosh, tanh, coth, sech, csch, asinh, acosh, atanh of a linear inside: integrate(sec(x), x) = ln|sec x + tan x|, integrate(csc(x), x) = ln|csc x - cot x|. Powers go by the reduction formulas, roots by the forms of trigonometric substitution, rational functions in exact surds (1/(x^2 - 2) has sqrt(2), never a decimal). A half-angle or tan answer is an antiderivative piece by piece and jumps where tan does; defint will not cross such a jump. A refusal says which of two things it is: "has no closed form in elementary functions" only for what noClosedForm() lists, and otherwise "no method yet", since it may still have one; both name nintegrate for a number over a range. Its search for one question stops at 4000 calls or depth 64, and then says it stopped: counted, never timed, so one input gives one result.

factor

Factors a polynomial in one variable over its real (exact) roots: quadratics, rational roots of any degree, common factors and repeated factors. With whole-number coefficients the result is written as a textbook does: whole-number coefficients in each factor, linear factors first, each in descending powers (6x^2 + x - 2 is (3x + 2)(2x - 1)). With no rational root, a factor of degree 2 or 3 with whole coefficients is searched for: x^4 + 4 is (x^2 + 2x + 2)(x^2 - 2x + 2), x^6 + 2x^3 - x^2 + 1 is (x^3 + x + 1)(x^3 - x + 1). In two variables it takes out the common factor, groups terms with a common factor and factors a polynomial whose terms all have one degree (a difference of squares, a trinomial in x and y, a sum or difference of cubes): x^2 - y^2 is (x + y)(x - y). Names bound to numbers are put in first. A polynomial it cannot factor is refused. A whole number is written as its prime factors: factor(38) is 2 * 19, as factorize (any size up to 38 digits, by Miller-Rabin and Pollard's rho; factor(2^64 + 1) is 274177 * 67280421310721). A number of more than 38 digits, or one whose smallest prime factor is above about 10^12, is refused with a note rather than left running. Works up to degree 600.

expandLog

Rewrites each logarithm by the product, quotient and power rules, the variables taken as positive: ln(x^2*y/z) is 2 ln x + ln y - ln z, log(b, sqrt(u)) is 1/2 log(b, u), and a power of the base is its exponent (log(2, 8*x) is 3 + log(2, x), log(b, b) is 1).

condenseLog

Writes the logarithms of a sum as one logarithm for each base, the reverse of expandLog: 2 ln x - ln y + 1/2 ln z is ln(x^2 sqrt(z)/y), a coefficient becoming a power. Terms with no logarithm, and logarithms of other bases, are left beside it.

expandExp

Writes each exponential with a number base as a number times a power of x: b^(m x + n) is b^n (b^m)^x, b^m worked out for a whole number m. 2^(x + 3) is 8*2^x, 3^(2x - 1) is 1/3*9^x, 5*2^(3x + 1) is 10*8^x: the initial value and the growth factor read straight off.

evalAt

Substitutes named variables into a symbolic expression and evaluates the result numerically, staying exact where the result allows. Where the expression is undefined (a bottom that is zero, as `(x^2 - 9)/(x + 3)` at -3) it is an error, "division by zero", not 0; so is a value outside a function's real domain (`ln(x)` at -1). A call inside it is worked first; if it cannot be, evalAt refuses.

equivalent

Whether two expressions are the same mathematics, with the page's numbers put in: true when algebra shows it (they expand, reduce or, by the log rules, expand to the same thing) or when they agree at every one of a dozen fixed test points where both are defined (sin(x)^2 + cos(x)^2 and 1); false when a point gives them different values, or when too few points can be evaluated to say. The points are always tried, also after the algebra says equal, so a fault in the algebra shows at a point. In a template's <check> block a false line names the point and both values.

fractionForm

A product with negative powers written as one fraction: each factor with a negative whole exponent goes under the bar with its exponent made positive, and a fraction in front is split between the two, so `3*x^3*y^-5` shows as 3x^3 over y^5. A power of a product is taken apart first. Names bound to numbers are put in. It is a way of showing the expression; the value to work with further is the expression itself.