|1.8.0||Nov 11, 2023|
|1.7.0||Nov 3, 2023|
|1.6.3||Sep 26, 2023|
|1.5.0||Jul 12, 2023|
#25 in Math
187 downloads per month
Numbat is a statically typed programming language for scientific computations
with first class support for physical dimensions and units.
Click to learn more.
Physical dimensions as types
Numbat has a static type system where physical dimensions like
Time act as types.
Definitions of constants and functions can optionally contain type annotations that will be statically enforced.
If the types are not specified, they will be inferred (
Frequency in the screenshot).
See this article to learn more about Numbat's type system.
First-class physical units
Numbat is focused on computations with units. Units are therefore treated as first-class citizens. They can be
entered in various ways (
New units can be introduced on the spot (
Compatible units can be converted easily using the
-> operator (
30 km/h -> mph,
1 mrad -> degree,
5 in + 2 ft -> cm,
27 weeks -> days).
And unit expressions are simplified using various heuristics (
15 km/h * 30 min = 7.5 km).
Comprehensive standard library
Numbat's standard library comes with a large number of physical dimensions and units (SI, US Customary, Imperial, Nautical, Astronomical, Atomic, Nuclear, …). See this reference page for a complete overview. It also contains a lot of mathematical and physical constants as well as a large range of pre-defined functions.
Numbat's parser never tries to be "smart" on syntactically incorrect input. This means you will either get a (descriptive) error message, or you can trust the result of your calculation.
Excellent error messages
Numbat aims to provide descriptive and helpful error messages.
Numbat has been designed for an interactive use-case with small "one off" computations. Opening the
without any arguments starts a REPL with a familiar
readline interface, including all the usual features like a command history, Ctrl-R search or tab completion.
Modular and customizable
The whole system of physical dimensions and units is specified Numbat's standard library, which is
written in the Numbat language itself. It is therefore
easily extensible by providing a
init.nbt file. For example,
a single line (
unit bathtub = 150 L) is usually enough to add a new unit. Users can even choose to write their
prelude module, allowing for arbitrary modifications to the unit system.
With its static type system, Numbat already enforces correctness of your calculations on a physical dimension level.
But some checks can only be made at runtime. Numbat provides an
assert_eq procedure that allows you to check for
exact equality using
assert_eq(12 ft, 1 in) or approximate equality using
assert_eq(c, 300_000 km/s, 1% × c).
This can be useful to make sure that intermediate results do not change during a restructuring of your calculation.
Numbat is a scientific calculator. It's not a computer algebra system that solves differential equations
or computes intergrals. Try WolframAlpha instead.
There is no graphical user interface with buttons like
Qalculate! is a fantastic tool that supports both text as well as graphical
Numbat supports a huge range of physical units. If you need something even more comprehensive, please consider contributing. Or try GNU units.
See this page for details on how to install the native command-line version of Numbat.
Run Numbat CLI
cargo run -- <numbat args>
Install the CLI version
cargo install -f --path numbat-cli
Run all tests
Working on the
If you are working on Numbat's standard library, it is convenient to point
NUMBAT_MODULES_PATH environment variable to the
numbat/modules/ folder. This way,
you don't have to recompile Numbat to see your changes.
Alternatively, you can create a symlink from
~/.config/numbat/modules to the
folder in the repository (see this page
for the standard paths on other operating systems).