ApasScript.

Equations

solve

Solves an equation written as it is on paper, choosing the method itself. One unknown: a linear or quadratic equation is solved exactly, and so is a polynomial of any degree whose roots are rational or come from a quadratic factor: solve(x^3 - 3*x^2 + 2 = 0, x) is [1 - sqrt(3), 1, 1 + sqrt(3)] (a factor with no real root is left out). A polynomial of degree 3 or more with no rational root gives its real roots as decimals: solve(x^3 - 2 = 0, x) is 1.25992105, solve(x^4 - 5*x^2 + 6 = 0, x) the four decimals. When some roots are exact and a factor of degree 3 or more has none, the answer is a solution-set record, {1} ∪ {x : x^3 - x - 1 = 0}, with fields kind, roots (each with value and multiplicity) and unresolved (the factor left over); a range after the unknown solves it numerically instead. An exponential equation, the unknown in an exponent of a number (2^x = 32, 4^x = 8^(x - 1)), is solved by logarithms: exactly when the answer is rational, else as a decimal; with the last argument "exact" the logarithm is kept, solve(2^x = 3, x, "exact") is log(2, 3) and solve(e^x = 5, x, "exact") is ln(5), which decimal() works out. A literal equation, linear in the unknown with other names left unbound, is solved for it as an expression: solve(P = 2*l + 2*w, w) is (P - 2l)/2. A logarithmic equation, the unknown inside logarithms of one base, is solved by combining them, and an answer is kept only when every logarithm is defined there: solve(log(x) + log(x - 3) = 1, x) is 5 (-2 is dropped). An equation that is not a polynomial is solved numerically when a range (lo, hi) or one starting value follows the unknown: in a range whose ends differ in sign, Brent's method gives one root; with the last argument "all", or when the ends have the same sign, every root in the range is given, exactly where a fraction p/q or p/q*pi (q <= 12) fits: solve(sin(x) = 1/2, x, 0, 2*pi) is [pi/6, 5pi/6], solve(2*cos(x)^2 - cos(x) - 1 = 0, x, 0, 2*pi, "all") is [0, 2pi/3, 4pi/3, 2pi]. With "all" the answer is always a list, [] for no root and [r] for one, so len() counts the solutions: solve(x^2 = 4, x, -5, 5, "all") is [-2, 2], solve(x^2 = -4, x, -5, 5, "all") is []. Several equations: a linear system in two or three unknowns, or two equations of any kind from a starting point (x0, y0). Other names in the equation take the values the script has bound, so solve(v = u + a*t, t) uses the script's u, a and v; with quantities (Apas Cloud) each answer has its unit. The unknown may stand alone under a division (1/f = 1/v - 1/u), or under a sum: a rational equation, solve(6/(x - 2) = 3, x) is 4. The bottoms are cleared, those with a root in them too (solve(1/(x - sqrt(2)) = 1, x) is 1 + sqrt(2)), and a root that makes a bottom zero is no answer (solve(x/(x - 1) = 1/(x - 1), x) is no solution; an identity such as 1/(x - 1) = 1/(x - 1) is "all x except 1"). An absolute-value equation is solved in two cases, abs(g) read as g and as -g, and an answer is kept only if it fits the equation as written: solve(abs(x - 2) = 3, x) is [-1, 5], solve(abs(x - 2) = -x, x) is no solution; an irrational root of a case is kept, solve(abs(x^2 + 4*x + 3) + 2*x + 5 = 0, x) is [-4, -1 - sqrt(3)]. An equation that is a polynomial in one exponential is solved through it: solve(4^x - 3*2^x - 4 = 0, x) is 2 (u = 2^x, u^2 - 3u - 4 = 0), solve(e^(2*x) - 5*e^(x) + 6 = 0, x, "exact") is [ln(2), ln(3)]. An equation with the unknown once under functions that can be undone, an inverse trigonometric function among them, is undone and the answer checked: solve(3*acos(2*x - 1) = pi, x) is 3/4. An inequality, with <, <=, > or >= in place of the = sign, is solved when it is linear or quadratic in the unknown: solve(3*x + 4 > 22, x) is x > 6, the relation turned for a negative factor (solve(-2*x > 6, x) is x < -3), and solve(x^2 - 5*x + 6 < 0, x) is 2 < x < 3; any other inequality by a sign chart, from where its two sides are equal and where it stops being defined: solve(2^x > 8, x) is x > 3, solve(log(x - 1) < 1, x) is 1 < x < 11, and on a range lo, hi after the unknown, solve(sin(x) > 1/2, x, 0, 2*pi) is pi/6 < x < 5pi/6; the last argument "interval" gives the interval form, (6, oo) and (2, 3), with a union of intervals where the answer is in two pieces. An end with pi or e in it stays exact, in a single or a double inequality: solve(0 < pi*x < 1, x) is 0 < x < 1/pi. An expression with no = sign is that expression = 0, and the unknown of a single equation may be left out when it is the only unbound name. One answer is a number, several are a list; "no solution", "no real solution" and "infinitely many solutions" are said in words.

excludedValues

The values of the unknown at which an expression is undefined, because a bottom is zero: the roots of the least common multiple of its bottoms. One is a number, several are a list, and "none" says there is no such value. The unknown may be left out when the expression has only one name. These are the values a lesson names (x ≠ 2) and the ones solve drops from a rational equation. A common factor that cancels first (x/x) is not seen.

inverseFunction

The inverse of a one-to-one function of one variable, as an expression in the same variable, with its domain (the range of f) as text. A function linear in x once its bottoms are cleared is solved for x: (2x + 1)/(x - 3) gives (3x + 1)/(x - 2), domain x != 2. Otherwise f is undone layer by layer when x is in it once: numbers added and factors, a reciprocal, an odd power, a square root, b^u and e^u, ln, log and log(b, u), sin, cos and tan (asin, acos, atan: the principal inverses). 3 + 2sqrt(x - 1) gives (x - 3)^2/4 + 1, domain x >= 3. A function under an even power, (x - 2)^2, is not one-to-one and is refused. The record's fields are inverse and domain.