Repository navigation
ER2 0.8.0
Speed and usability, measured against Python, SymPy and PARI/GP (docs/PERFORMANCE.md). Breaking: integers are plain int (D22), so type(5) is int; everything else is compatible.
Changed
- Integers are plain Python
intand run at Python's speed (D22)./and**are made
exact when ER2 code is compiled (1/3is still1/3,2^-1is1/2), instead of every
literal being anInteger: a numeric loop goes from 13.8 times Python's time to the same time.
type(5)is nowint;/is exact also on integers that came from Python (len(x)/2is
3/2);5ris still accepted and changes nothing; a.pymodule that receives an ER2
integer uses Python's/.Integeris still available for code that builds one. - The workflows use actions that run on Node 24 (
upload-artifactv7,download-artifactv8,configure-pagesv6,upload-pages-artifactv5,deploy-pagesv5); Node 20 is no longer supported on GitHub's runners. - PARI is loaded only when a program uses it (D24): a program with only integers, rationals or SymPy starts in about 68 ms instead of 90 (×2.7 of Python, under the ×3 target);
pari.rawstarts it on demand. - Polynomials reach PARI faster: an expanded polynomial in one variable is read straight from
its terms instead of through SymPy'sPoly(degree 12: 221 to 84 us), which speeds up
factorover Q and modulo p (degree 12 mod 7: from 20 to 14 times a bare PARI call). - New benchmark group: the SymPy <-> PARI conversions alone, each against the PARI
computation it serves. - Matrix results come back faster: an integer or rational matrix from PARI is read from its
text in one step instead of entry by entry (hermite_formof a 10x10 integer matrix: about
half the time). kernelof an invertible matrix is faster: the empty result no longer goes through SymPy's
general matrix constructor.- Integer matrix calls are faster (
det,kernel,hermite_form,smith_formover Z): the matrix
reaches PARI in one step instead of entry by entry. - ER2 programs start faster: 93 ms instead of 145 ms for a program without symbols. PARI starts
with a smaller table of small primes (no result changes, and factoring is no slower), the
version is read only when asked for, and the REPL's modules load only for the REPL. factor(f, modulus=p)is about 2 times faster: the polynomial is converted once per call
instead of four times (degree 12: from 53 to 20 times the time of a bare PARI call).- The site no longer loads Google Fonts.
Added
- Type hints (
er2/py.typed): what Python code imports from ER2 (er2.preparse,latex,show,Rational,er2.prelude.namespace,er2.session.run_file, ...) is annotated, so mypy and editors read it; the results of the mathematical functions areAny, because they depend on the arguments. CI type-checkstests/typing/usage.pyagainst the built wheel withmypy --strict. No startup cost:typingis never imported at run time. - The REPL keeps its history between sessions (
~/.local/state/er2/history), completes names with Tab, and shows a function's help withname?. - Syntax highlighting for
.er2files in VS Code, in the sibling repository ER2-VSCODE. - Property-based tests (
tests/test_properties.py, with Hypothesis as a development dependency only): factorization,phi,mu, exact division and powers,Mod, polynomial factorization and determinants checked on generated input. - CI builds the wheel and runs it in a clean environment on Python 3.12, 3.13 and 3.14 on every push; the release workflow does the same on all three versions (it tested 3.12 only).
- The site's PARI reference can be searched: by PARI or ER2 name or by a word of the description, optionally only what ER2 exposes;
reference.html?find=eulerphilinks to a search. docs/OVERVIEW.md: ER2 in two pages for contributors (the pipeline, which module does what, where a change goes), linked from CONTRIBUTING and the README.docs/COMPARISON.md(site page Compared, linked from the README): ER2 against Python, SymPy, SageMath and PARI/GP, with what ER2 gives over each, what each is for, the measured costs and where ER2 stops.- Ten programs in ER2 (
examples/ten/): Mersenne primes, factorization,phi,mu, algebra, calculus, a matrix, finite fields, power series and a number field, each golden-tested. - Get started has a table of the same lines in Python and in ER2, with what each prints.
- Rational
**with an integer exponent, unary-,abs,//and%take the same direct route as+ - * /:**,-andabsnow run in about half the time offractions.Fraction,//from 2.5 to 1.6 times (same results, checked on random input). - CI runs the quick benchmarks on every push and pull request and shows the report in the job summary; a timing never fails the build.
- Startup is about 6 ms shorter:
typingis no longer imported (explicitsingledispatchregistrations), and the PARI function table is read withcsv.readerand its signatures withoutinspect. - Rational
+ - * /are faster again:a + bfrom about 1.7 to 1.2 timesfractions.Fraction,a * b / (a - b)from 1.55 to 1.1 (the result is built from its two slots, the operand read inline; same results). - The REPL and the Jupyter kernel import SymPy in the background as soon as they open, so the first symbolic command does not wait for it (about 330 ms); programs run from a file are unchanged.
kernelof a rational matrix is about 40 % faster: the echelon basis is computed on fractions and the columns are read straight from PARI (same basis as before, checked against SymPy'srrefon random input).- Faster rational arithmetic:
+ - * /between rationals and integers are about 1.7 times
faster (same results asfractions.Fraction, checked on random input). - Performance history:
make bench-record NOTE="…"keeps every benchmark run in
benchmarks/history/(all the times, the commit and the machine) and redraws
docs/PERFORMANCE.md, one graph per section of ER2 against its reference, run after run; it
is also the site's new Performance page. - Speed baseline for improvements:
make bench-baselinesaves the benchmark times in
benchmarks/baseline.jsonandmake bench-comparemeasures again and shows the change of each
one. New benchmark groups: calculus and series, and exact rationals and large integers. er2 --info: the versions of ER2, Python, the platform, SymPy, cypari2 and libpari in
one place, for bug reports (the issue template asks for it). It does not load SymPy.- macOS is supported, on Apple Silicon and Intel: CI now runs the whole test suite on both
as well as on Linux, for Python 3.12–3.14, and the package declares
Operating System :: MacOS. - The release workflow can be run by hand (
gh workflow run release.yml) as a rehearsal: it checks and builds but never publishes. - Releases through a trusted publisher (M8). Pushing a tag
vX.Y.Zstarts
.github/workflows/release.yml. It checks the tag against the version and that the commit
is onmain, runs the suite, builds, and runs the built wheel in a clean environment. It then
waits for a maintainer to approve the upload to PyPI. No token is stored anywhere: PyPI trusts
that workflow in that environment and nothing else. The manual route in
docs/RELEASING.md remains as the fallback, andtests/test_release.py
checks that only the approved job can publish.
Fixed
docs/PARI_FUNCTIONS.mdshowed only 59 of the 126 functions of "Programming in GP": the TeX quotes inkill's description opened inline code; the generator now escapes backticks.- The site's home and Get started pages described integer literals as
Integerand5ras the way to get a plainint; since D22 every integer is anintand only/and**are exact. - Error messages of
er2 file.er2and of the REPL show only the program: a syntax error has no ER2 frames (aspython file.py); an unclosed bracket or string is reported where it opens ("'(' was never closed"); a runtime error stops at the user's last line, without ER2, SymPy or cypari2 frames; PARI argument errors use the ER2 name (phi(), noteulerphi());factor(f, modulus=n)withnnot prime says so instead of SymPy's "zero divisor". %unload_ext er2now undoes everything%load_ext er2did: it also removes the.er2
importer and the exact/and**, so1/2is Python's0.5again.inverseandsolve_linearreport a singular matrix asNonInvertibleMatrixErroronly when
it is one; other PARI errors (wrong dimensions, types) are aValueErrorwith PARI's message.- The README's logo and five of its badges used relative paths, which are dead on the PyPI
project page, since the README is the PyPI description. They are now absolute, and
tests/test_release.pyfails if a relative link comes back. examples/er2.xmlwas not well-formed XML: its header comment contained--, which XML
forbids. Pandoc accepted it, so highlighting worked, but a strict XML parser rejected it,
and so did any tool that read the file other than Pandoc.tests/test_site.pynow parses it.- The package declared
Operating System :: OS Independent, but cypari2 has no Windows build,
so ER2 cannot be installed on Windows (WSL works). The classifiers now declare Linux and
macOS, the two platforms CI tests, and the README's Quick start has a platform table.
Not on PyPI yet: install from this release's wheel, or from source.