Exact Rational Arithmetic
The foundation of every calculator on this site is a BigInt-based rational arithmetic library. Each number is represented as an exact fraction: a pair of JavaScript BigInt values (numerator, denominator) stored in lowest terms (gcd = 1, denominator always positive).
All arithmetic operations — addition, subtraction, multiplication, division — are implemented on these rational numbers using the standard algebraic rules for fractions. The result of any operation is another exact rational number, reduced to lowest terms. No floating-point numbers are used anywhere in the computation.
This approach eliminates the class of errors that plague float-based calculators. For example: (1/3) × 3 = 1 exactly, not 0.9999999999. A pivot entry that should be 1 is exactly 1 (stored as BigInt 1/1), which means subsequent elimination steps produce exact zeros where expected.
JavaScript's built-in number type is a 64-bit IEEE 754 float, which cannot represent most fractions exactly. BigInt, by contrast, handles arbitrarily large integers with no rounding. Rational arithmetic on top of BigInt therefore handles any fraction with arbitrary precision.
The Gauss-Jordan Algorithm
The RREF, inverse, and Gauss-Jordan calculators all use the same core Gauss-Jordan elimination algorithm operating on a matrix of rational numbers. The algorithm proceeds as follows:
- Column scan. Starting from the leftmost unprocessed column, find the first non-zero entry in the current row or below.
- Row swap (if needed). If the top entry of the current column is zero, swap the current row with the first row below it that has a non-zero entry in this column. Record the swap as a step.
- Scale to get a leading 1. Multiply the current row by the multiplicative inverse of the pivot entry. This makes the pivot exactly 1 (rational 1/1). Record the scale operation.
- Column elimination. For every other row (both above and below), subtract the appropriate multiple of the pivot row to zero out that row's entry in the pivot column. Record each elimination.
- Advance. Move to the next row and next unprocessed column. Repeat from step 1 until all rows are processed or no more non-zero entries exist.
The result is RREF. By the uniqueness theorem, this is the unique RREF of the input matrix regardless of the specific pivot choices made (e.g., which row is selected when multiple candidates have non-zero entries).
Matrix Inverse Computation
The matrix inverse calculator augments the input matrix A with the identity matrix I to form [A | I], then runs the Gauss-Jordan algorithm on this augmented matrix. If A reduces to the identity on the left, the right half is exactly A⁻¹.
If at any point during elimination, a pivot position in the left half contains a zero and no row below has a non-zero entry in that column, A is singular (det = 0) and the algorithm terminates with a "no inverse" result.
Determinant Computation
The determinant calculator uses recursive cofactor expansion along the first row. For a 2×2 matrix, the formula det = ad − bc is applied directly. For larger matrices, the determinant is computed as the signed sum of first-row entries multiplied by the determinants of their (n−1)×(n−1) minors.
All arithmetic is exact. For matrices with integer entries, the result is always an exact integer. For matrices with rational entries, the result is an exact rational number.
Accuracy Guarantees
For rational inputs (integers and fractions entered as p/q), this calculator is perfectly accurate. The result is the mathematically exact RREF, inverse, determinant, etc. There is no floating-point error, no rounding, and no approximation.
For decimal inputs (e.g., entering "0.5"), the calculator converts the decimal to the nearest exact fraction (0.5 → 1/2, 0.3333 → 3333/10000). If your decimal is a repeating decimal with no exact finite representation, entering the fraction form directly (e.g., 1/3 instead of 0.3333) gives a more accurate result.
Current Limitations
- Matrix size. The UI supports matrices up to 6×6 (and the inverse/determinant calculators up to 4×4 or 5×5). Very large matrices would require a different interface, but the underlying arithmetic library has no inherent size limit.
- Complex numbers. Entries must be real rationals. Complex number support is not available in this version.
- Irrational numbers. Entries like √2 are not supported symbolically. If you need √2, you must use a rational approximation (e.g., 14142/10000), which introduces a small approximation error.
- Client-side only. All computation runs in your browser. Very large matrices or deeply nested computations could be slow on low-powered devices.
How We Test Calculator Accuracy
Every calculator on this site is verified against known correct results before release. Our testing process:
- Cross-validation against established software. We compare our RREF, inverse, and determinant outputs against results from NumPy (Python), MATLAB, and Wolfram Alpha for a suite of test matrices — including integer matrices, fraction matrices, and near-singular matrices.
- Exact fraction arithmetic verification. We test that (1/3) × 3 = 1 exactly, that row operations on fraction-entry matrices produce fraction results with no rounding, and that pivots that should be exactly 0 are stored as exactly 0 — not 1e−16.
- Edge case matrices. We test: all-zero matrix, identity matrix, rank-deficient matrices (including cases with multiple free variables), 1×1 matrices, non-square matrices (wide and tall), and augmented matrices representing the three solution types (unique, infinite, no solution).
- Algebraic identity checks. For invertible matrices, we verify A · A⁻¹ = I exactly. For determinants, we verify det(AB) = det(A) · det(B). For RREF, we verify the result satisfies all four RREF conditions programmatically.
- No server-side computation. All arithmetic runs in the browser — there is no server that could cache a wrong result. Each calculation is performed fresh from your input, which makes testing straightforward: the same input always produces the same output with no network variability.
Open Source and Transparency
The rational arithmetic library, the Gauss-Jordan algorithm, and all calculator components are implemented in TypeScript with no external math libraries. The implementation is deliberately straightforward so the algorithm matches what you would compute by hand (the same sequence of operations, represented in the same fractions you would write down).