sagebrush
Fast, certified engines for research mathematics, in Rust, for Python. Permissively licensed (MIT OR Apache-2.0): use them anywhere, in anything, from agents and notebooks to products. No C libraries; one abi3 wheel per platform covers Python 3.9 and later.
This is an early release of Sagebrush, which also runs in the browser at sagebrush.space.
>>> from sagebrush import nf, mf, ap, poly, linalg
>>> nf.bnf([-11, 0, 0, 1]) # Q[x]/(x^3 - 11): class group, regulator
{'cyc': [2], 'degree': 3, 'disc': -3267, 'h': 2, 'r1': 1, 'r2': 1, 'regulator': '5.5872066260609077619', 'w': 2}
>>> nf.factor_integer(2**128 + 1) # ECM
[(59649589127497217, 1), (5704689200685129054721, 1)]
>>> nf.primes_above([-11, 0, 0, 1], 5) # 5 = P_1 P_2 with residue degrees 1, 2
[{'e': 1, 'f': 1, 'p': 5, 'pi': [-1, 1, 0], 'pi_den': 1}, {'e': 1, 'f': 2, 'p': 5, 'pi': [1, 1, 1], 'pi_den': 1}]
>>> nf.lll([[1, 1, 1], [-1, 0, 2], [3, 5, 6]])
[[0, 1, 0], [1, 0, 1], [-1, 0, 2]]
>>> poly.factor([5, -1, -1, 1]) # x^3 - x^2 - x + 5 over Z
(1, [([5, -1, -1, 1], 1)])
>>> linalg.det([[2, 7, 1], [8, 2, 8], [1, 8, 2]]), linalg.charpoly([[0, 1], [-1, 0]])
(-114, [1, 0, 1])
>>> linalg.solve([[2, 1], [1, 3]], [[1], [2]]) # exact, over QQ
[[Fraction(1, 5)], [Fraction(3, 5)]]
>>> d = mf.newforms(389, 2, bound=6) # newform orbits of S_2(Gamma0(389))
>>> d["status"], [(o["letter"], o["dim"]) for o in d["newforms"]]
('proven', [('a', 1), ('b', 2), ('c', 3), ('d', 6), ('e', 20)])
Polynomials are coefficient lists, constant term first.
Sage-compatible: sagebrush.sage
For Sage users, sagebrush.sage is a namespace with Sage's names, behaviour
and printing, for what Sagebrush implements: number fields, polynomials,
matrices, modular forms and symbols, elliptic curves, Dirichlet characters,
integers, plotting.
>>> from sagebrush.sage import *
>>> factor(2026)
2 * 1013
>>> x = PolynomialRing(QQ, 'x').gen()
>>> K = NumberField(x**3 + 17*x + 1, 'a')
>>> K.class_group()
Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^3 + 17*x + 1
>>> K.regulator()
2.83341678218613
>>> K.factor(11)
(Fractional ideal (11, a + 3))^2 * (Fractional ideal (11, a + 5))
>>> Integer(2026).is_prime(), Integer(2026) / 4
(False, 1013/2)
>>> EllipticCurve('389a1').rank()
2
This is plain Python, without Sage's preparser: write x**3 (x^3 is xor
in Python, and raises an error here as in Sage), Integer(2)/3 for a
rational (2/3 is a float), and K = NumberField(f, 'a'); a = K.gen() for
K.<a> = NumberField(f). Integers from Integer(n) or ZZ(n) have Sage's
methods. The output is checked line by line against Sage itself: Sage's
own preparser turns Sagebrush's Sage test files into plain Python, and
their output under sagebrush.sage must equal Sage's.
For AI agents: sagebrush-mcp
This package installs sagebrush-mcp, a
Model Context Protocol server with no
other dependencies.
- Claude Code:
claude mcp add sagebrush -- sagebrush-mcp - Other clients:
{"mcpServers": {"sagebrush": {"command": "sagebrush-mcp"}}}
Its tools:
sage: Sage syntax in a persistent session; returns printed output, the last value and SVG plots.python: the same session, as plain Python.factor,number_field,newforms: shortcuts.guide: what is implemented.reset: clear the session.
Each call has a time limit. When it expires the computation is interrupted
and the session keeps its variables. The session also works on its own
(sagebrush.session.Session), and sagebrush.preparse.preparse turns Sage
syntax into Python.
Engines
sagebrush.nf: number fields: maximal orders, prime ideals, class groups, units and regulators (assuming GRH, with a field-specific bound for the generators), quadratic class groups to |D| ~ 10^60; integer factoring (ECM); Hermite and Smith forms, LLL; complex roots to any precision.sagebrush.mf: modular forms of weight k >= 2 with character: dimensions, exact Hecke characteristic polynomials, newform orbits, trace forms.sagebrush.modsym: weight-2 modular symbols for Gamma0(N).sagebrush.ap: traces of Frobenius a_p of elliptic curves over Q.sagebrush.poly: factoring in Z[x] and F_p[x]; products, gcds and exact division in Z[x].sagebrush.linalg: exact matrices over ZZ and QQ:det,rank,rref,solve,inverse,charpoly,kernel(multimodular and p-adic, every answer certified).
Results are checked against independent systems: PARI for class groups, Sage and Magma for the rest, and LMFDB for modular forms.
License
Copyright (c) 2026 SageMath, Inc. Licensed under either of the Apache License, Version 2.0 or the MIT license, at your option.
Metadata
Release files for sagebrush 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sagebrush-0.6.0.tar.gz | 1.0 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| sagebrush-0.6.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| sagebrush-0.6.0-cp39-abi3-manylinux_2_28_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| sagebrush-0.6.0-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| sagebrush-0.6.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| sagebrush-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 13.5 MB
Release files / sagebrush-0.6.0.tar.gz
| Download URL | sagebrush-0.6.0.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1958b4b6373065ae30fb052d805811273da220462feabdecda3c15eef1402aae
|
|
BLAKE2b-256 checksum How to use checksums |
00ee5e61fc7564aac8e876a3d4b2cdfc68d54b23364f4ddad0d62d014f9e2127
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / sagebrush-0.6.0-cp39-abi3-win_amd64.whl
| Download URL | sagebrush-0.6.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ab47dd576fe2ee2756e36b6a83859e0ec7f5c3d9d0ae462ad8202c49fa5a7962
|
|
BLAKE2b-256 checksum How to use checksums |
e04681031579aad36d0786f91e8183770f02431854a879ac97bdb18ad6fd7837
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / sagebrush-0.6.0-cp39-abi3-manylinux_2_28_x86_64.whl
| Download URL | sagebrush-0.6.0-cp39-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
abb5e9ed1ef9e370da2e800421366bd7665258e7151b2beb55cf398d9db66a97
|
|
BLAKE2b-256 checksum How to use checksums |
a828139e7bef0d8f9cd18476018dbcb12478cd25f9ddc5ece0f858e622085719
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / sagebrush-0.6.0-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | sagebrush-0.6.0-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
aaa2cdcc7ccad9301155484cd2a6b1d1e3ef566bbb68748811db1a09a2471f3e
|
|
BLAKE2b-256 checksum How to use checksums |
38ffdeaa9996612f37395877cf9da8a7bf116f3681020e0de21129d6f045f5b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / sagebrush-0.6.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | sagebrush-0.6.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f560f673b3f5a7bf45fedf7d069d22f81c7a9337dde720078b0f59559beafb45
|
|
BLAKE2b-256 checksum How to use checksums |
40d8b006f525ce9ba54b1ff138c52c3aeeec557bdd39b01e48902b3114d28239
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / sagebrush-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | sagebrush-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
9066c6381ae9614f98c3233c49fb63372275ac58f050d61222c7e330688241d8
|
|
BLAKE2b-256 checksum How to use checksums |
fd361502e83ccae7d6e13ad7f547eda915f7bacbcfb5d1394f941be8fa05cd55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency log