Every family of solutions
A trigonometric equation has infinitely many solutions. solve returns them as families , merges families that are really one, and checks every family in the equation as written.
Using it
import { solve } from "@ratmath/symbolic";
String(solve("2sin(x) = 1")); // x = pi/6 + 2*n*pi, 5*pi/6 + 2*n*pi (n any whole number)
String(solve("sin(x)*cos(x) = 1/4")); // x = pi/12 + n*pi, 5*pi/12 + n*pi
String(solve("sin(3x) = 0")); // x = n*pi/3
String(solve("cos(x) + cos(3x) = 0")); // x = pi/4 + n*pi/2, pi/2 + n*pi
const r = solve("sin(x) = a", "x");
String(r); // x = asin(a) + 2*n*pi, pi - asin(a) + 2*n*pi, provided abs(a) <= 1
r.conditions; // ["abs(a) <= 1"]
const s = solve("2sin(x) = 1").solutions[0];
String(s.period); // "2*pi"
String(s.member(1)); // "13*pi/6"
With { range: [lo, hi] } the families are listed member by member inside the range, as on the Solving page. After solving, within(lo, hi) does the same for any interval: solve("2cos(x)^2 - cos(x) - 1 = 0").within("[0, 2*pi)") is . Write the ends as text with brackets to choose open or closed ends; each member is placed by an exact comparison with the ends.
The general solution of the basic equations
Each of the three basic equations has a principal solution from the inverse function and a rule for the others:
The first two need . When is a number the library decides that itself; when it is a letter it asks the assumptions, and if they do not settle it the condition abs(a) <= 1 is returned with the answer. At the exact angles (multiples of ) the inverse function is written as that angle, so appears as .
When the angle is instead of , each family is solved for : the period becomes .
Reducing to the basic equations
Most equations from a course become one of the basic three after a standard move. The solver tries them in turn:
- One function, polynomially. is a quadratic in : or , then each is inverted.
- Homogeneous in sine and cosine. , or : divide by a power of and solve for .
- Power reduction and double angles. A product or power of and is rewritten as sines and cosines of multiples of , through and with . If one multiple is left, that is an equation in one angle: becomes .
- Angle sums. is expanded with the double-angle formula and factored: .
- The half-angle substitution. Anything left that is a polynomial in and becomes a polynomial in , through and . The substitution misses , which is tried separately.
Families that are one family
The methods above can return several families with the same period whose starting points are evenly spaced, as gives and . Those are one family, . The library reduces each starting point modulo the period, looks for of them spaced exactly apart, and proves the spacing with the normal form before merging them. A family written twice ( and ) is listed once.
What the normal form knows
To check a family with a letter in it, the solution is put back and the difference reduced to zero. That needs a few identities, which the normal form now applies wherever the left side is defined:
The inverse functions themselves are evaluated at the standard exact values: and at , and at . The argument is matched by the normal form, so asin(1/sqrt(2)) is recognised as and simplifies to ; asin(-sqrt(3)/2) is .
The square roots are right, not just up to sign, because and take values in , where the cosine is not negative; takes values in , where the sine is not negative.
@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.