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

NameWhat 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, equalsExact arithmetic, immediate.
toArray, toStrings, toNumbersRationals, strings like "3/4", or nearest doubles.

Solving and elimination

NameExact value
det(A) RRational
rank(A) Rinteger
rref(A) R{ matrix, pivots }
solve(A, b) R{ status: unique | infinite | none, x, basis }
inverse(A) RMatrix or null
nullspace(A) Rbasis vectors
spaces(A)rank, nullity, column-space and row-space bases
trace(A), multiply(A, B)immediate

Spectral and structure

NameExact value
charpoly(A) Rcoefficients of det(xI − A), constant first
eigenvalues(A) Rreal ones as AlgebraicReal, complex ones as certified ComplexAlgebraic boxes, with multiplicities
eigenvectors(A) Rfor 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) Rcertified singular values; U and V in floats
similarity(A), jordan(A) Rinvariant 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) Rexact algebraic numbers for p = 1, "inf", "fro" or 2; cond is Infinity for a singular matrix
expm(A, { bits }) Revery entry of exp(A) as a certified interval
sinm, cosm, sinhm, coshm(A, { bits }) Rthe same for sin, cos, sinh and cosh of a matrix
sqrtm(A), logm(A) Rthe 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) RA to a rational power t, as exp(t·log A)

Factorizations and least squares

NameExact value
lu(A) R{ perm, L, U }, PA = LU
ldl(A) R{ L, D, positiveDefinite } or null
qr(A), gramSchmidt(A) Rsquare-root-free: orthogonal Q, unit upper R, squared norms
power(A, k) RAᵏ for any integer k
pseudoinverse(A) RMoore–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

NameExact value
certifyRoot({ f, jacobian, guess }) Ra box proven to hold exactly one zero
solveIntervals(A, b) Ran enclosure of every solution when entries are ranges
interval.*interval arithmetic, krawczykStep, krawczyk

Other fields

NameWhat it does
field.rref, det, inverse, multiplyelimination over any field object (see Other number systems)
field.rationalField, intervalFieldCore rationals; rational intervals (zero tests may be undecided)
field.primeField(p)integers mod a prime, with from(rational)
field.algebraicFieldreal 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

ClassMethods
AlgebraicRealrefine(bits), interval(bits), rational, isRational, toNumber(), toString(digits)
ComplexAlgebraicrefine(bits), box(bits), conjugate(), toNumbers()
algebraic.*add, sub, mul, div, inv, pow, sqrt, sign, compare, realRoots, fromRational: exact arithmetic on AlgebraicReals
AlgebraicVectortoStrings() (entries as polynomials in λ), approximate(bits), toNumbers()

Running it

NameWhat it does
Refinementquick, 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/workerserveLinalg(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.

Try itEdit the code and run it with @ratmath/linalg and Core's Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs