ratmath

All of RatMath in one import

Each library on the shelf is its own small package, @ratmath/linalg, @ratmath/stats and so on, so a program can take only what it needs. The package ratmath gathers them in one place: install one name and every library is there, under its own name, with Core's numbers at the top.

What is in this release

The first releases hold RatMath Core only. Each Shelf library joins as soon as it is published on npm, as Ratmath.linalg, Ratmath.stats and so on. Ratmath.shelf lists all fourteen and says which ones this release includes.

Install

npm install ratmath      # or: bun add ratmath, pnpm add ratmath

The package is ES modules only and needs Node 22 or later, Bun, Deno, or a current browser.

Three ways to import

One object, still lean. This is the form to start with. Ratmath holds everything, and a bundler can still see which parts a program uses and leave the rest out.

import * as Ratmath from "ratmath";

Ratmath.R`1/3 + 1/6`;                 // 1/2, exactly
new Ratmath.Rational(22, 7).subtract(new Ratmath.Rational(355, 113));
// Ratmath.linalg.Matrix, Ratmath.stats, ... as the libraries join

Just the names you use.

import { R, Rational, core } from "ratmath";

R`1:2 + 3:4`;                          // the interval 4:6
core.Integer;                          // Core is also there as one name

A plain object. The default export is the same contents as an ordinary frozen object. It is the shortest to write in a script, a notebook or a lesson, but a bundler keeps all of it, so a web app is better served by one of the forms above.

import Ratmath from "ratmath";

Ratmath.R`2^10`;                       // 1024

One library only. A subpath gives one library and nothing else: ratmath/core now, and ratmath/linalg and the others as they join. This is the same as importing @ratmath/core directly; the objects are identical, never copies.

import { Rational } from "ratmath/core";

In a web page, with no build step

The package carries one file for a plain script tag. It sets a global Ratmath with the same contents as the default export.

<script src="https://cdn.jsdelivr.net/npm/ratmath/dist/ratmath.global.js"></script>
<script>
  console.log(String(Ratmath.R`1/3 + 1/6`));   // "1/2"
</script>

Pin a version in the address (ratmath@0.11) for a page that should not change under you.

How the versions fit together

The libraries keep their own version numbers. A new release of Core does not force a release of every library, and a library's number says how far that library has come.

Core is shared, never copied. The libraries list Core as a peer dependency: they need it, but they use the one copy the program already has instead of bringing their own. Two copies of Core in one program would quietly break things, because a Rational made by one copy is not a Rational to the other. Each library states the range of Core versions it works with, for example "@ratmath/core": ">=0.10.0 <0.12.0".

ratmath follows Core. Version 0.11 of ratmath is Core 0.11 together with a set of library versions that have been tested with it. Installing ratmath is the easy way to get a set that works together.

Where to go next

The Shelf lists every library with its topics and what is planned. Each library's own site has an overview, an explorer, a reference and a page per topic, each ending in a box like the one below.

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