Reference
Everything in the library
Entries can be numbers, bigints, strings such as "3/4", "1.25" or "0.#3" (Core's literal grammar), or Core Rationals. A decimal JS number is read by its shortest spelling, so 0.1 means 1/10. Functions marked R return a Refinement: read .quick for the preview and call .exact() or await .settle() for the exact value.
The shape of every call
import { det } from "@ratmath/linalg";
const r = det([[0.1, 0.2], [0.3, 0.4]]);
r.quick.value; // -0.019999999999999993, the float preview
r.quick.trust; // "good"
r.exact().toString(); // "-1/50"
await r.settle({ onStage: (s) => console.log(s.stage, s.value) }); // the same, without blocking the page
Matrices
| Name | What it does |
| Matrix.from(rows) | Immutable matrix of exact rationals. A flat array is a column. |
| Matrix.identity(n), zeros(r, c) | Standard matrices. |
| get(i, j) | Entry as a Core Rational. |
| add, subtract, scale, multiply, transpose, augment, column, equals | Exact arithmetic, immediate. |
| toArray, toStrings, toNumbers | Rationals, strings like "3/4", or nearest doubles. |
Solving and elimination
| Name | Exact value |
| det(A) R | Rational |
| rank(A) R | integer |
| rref(A) R | { matrix, pivots } |
| solve(A, b) R | { status: unique | infinite | none, x, basis } |
| inverse(A) R | Matrix or null |
| nullspace(A) R | basis vectors |
| spaces(A) | rank, nullity, column-space and row-space bases |
| trace(A), multiply(A, B) | immediate |
Spectral and structure
| Name | Exact value |
| charpoly(A) R | coefficients of det(xI − A), constant first |
| eigenvalues(A) R | real ones as AlgebraicReal, complex ones as certified ComplexAlgebraic boxes, with multiplicities |
| eigenvectors(A) R | for each eigenvalue, basis: a full exact basis of its eigenspace, rational vectors for rational λ and AlgebraicVectors over Q(λ) otherwise |
| symmetricEigen(A) R | { values, Q } with A = Q·diag(values)·Qᵀ and QᵀQ = I, as exact algebraic numbers |
| definiteness(A) R | { kind, positive, negative, zero } for a symmetric matrix |
| singularValues(A), svd(A) R | certified singular values; U and V in floats |
| similarity(A), jordan(A) R | invariant factors, minimal polynomial, rational canonical form, Jordan block sizes for every eigenvalue, and J, P with A = PJP⁻¹ when the eigenvalues are rational; algebraicForm() gives J and P as exact algebraic numbers for any eigenvalues |
| norm(A, p), cond(A, p) R | exact algebraic numbers for p = 1, "inf", "fro" or 2; cond is Infinity for a singular matrix |
| expm(A, { bits }) R | every entry of exp(A) as a certified interval |
| sinm, cosm, sinhm, coshm(A, { bits }) R | the same for sin, cos, sinh and cosh of a matrix |
| sqrtm(A), logm(A) R | the principal square root and logarithm as certified intervals (single points when the root is rational); a RangeError when A has an eigenvalue on the negative real axis or at 0 |
| powm(A, t) R | A to a rational power t, as exp(t·log A) |
Factorizations and least squares
| Name | Exact value |
| lu(A) R | { perm, L, U }, PA = LU |
| ldl(A) R | { L, D, positiveDefinite } or null |
| qr(A), gramSchmidt(A) R | square-root-free: orthogonal Q, unit upper R, squared norms |
| power(A, k) R | Aᵏ for any integer k |
| pseudoinverse(A) R | Moore–Penrose A⁺ |
| leastSquares(A, b) R | { x, residual } |
| cholesky(A) R | { L } with A = L·Lᵀ and exact square roots, or null |
| hermite(A), smith(A) | integer normal forms with unimodular transforms |
| integerKernel(A), integerImage(A) | bases, over the integers, of the integer solutions of Ax = 0 and of the lattice the columns span |
| lllReduce(A) | a short, nearly orthogonal basis of the lattice spanned by the rows |
Nonlinear support
| Name | Exact value |
| certifyRoot({ f, jacobian, guess }) R | a box proven to hold exactly one zero |
| solveIntervals(A, b) R | an enclosure of every solution when entries are ranges |
| interval.* | interval arithmetic, krawczykStep, krawczyk |
Other fields
| Name | What it does |
| field.rref, det, inverse, multiply | elimination over any field object (see Other number systems) |
| field.rationalField, intervalField | Core rationals; rational intervals (zero tests may be undecided) |
| field.primeField(p) | integers mod a prime, with from(rational) |
| field.algebraicField | real algebraic numbers with exact zero tests |
| complexField, algebraicMatrix(rows) | real and complex algebraic numbers as a field, and rows of them built from rationals and algebraic numbers |
| numberFieldOps(K) | the field Q(λ) of an @ratmath/algebraic NumberField, for the same functions |
Exact numbers that are not rational
| Class | Methods |
| AlgebraicReal | refine(bits), interval(bits), rational, isRational, toNumber(), toString(digits) |
| ComplexAlgebraic | refine(bits), box(bits), conjugate(), toNumbers() |
| algebraic.* | add, sub, mul, div, inv, pow, sqrt, sign, compare, realRoots, fromRational: exact arithmetic on AlgebraicReals |
| AlgebraicVector | toStrings() (entries as polynomials in λ), approximate(bits), toNumbers() |
Running it
| Name | What it does |
| Refinement | quick, exact(), exactStage(), settle({ signal, sliceMs, onStage, onProgress }), stages(), settled |
| live(compute, onStage, { idleMs }) | wire a computation to a slider; stale work is cancelled |
| @ratmath/linalg/worker | serveLinalg(self) in a worker, workerClient(worker) on the page |
Teaching forms
teach.* returns { title, summary, steps, result }; each step is plain data (title, text, the matrix with highlights, tables). Available: gaussJordan, solveSystem, inverse, determinantByElimination, cofactorExpansion, bareiss, modularDeterminant, guessAndCheck, gramSchmidt, lu, leastSquares, eigen, sturmWalk, jordanBlocks, powerBySquaring, exponentialSeries, newtonKrawczyk, fourSubspaces, dixonLifting, and the interactive RowReducer.
Numerical methods
methods.* runs a classical method in doubles beside exact arithmetic. Each row has error, methodError and rounding. Available: jacobi, gaussSeidel, sor ({ omega }), conjugateGradient, powerMethod, inverseIteration ({ shift }), qrAlgorithm, pivoting and exactDouble. See Iterative and eigenvalue methods.