Skip to content

ER2 0.8.0

Choose a tag to compare

@EnriquePH EnriquePH released this 27 Nov 19:54
· 34 commits to main since this release

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 int and run at Python's speed (D22). / and ** are made
    exact when ER2 code is compiled (1/3 is still 1/3, 2^-1 is 1/2), instead of every
    literal being an Integer: a numeric loop goes from 13.8 times Python's time to the same time.
    type(5) is now int; / is exact also on integers that came from Python (len(x)/2 is
    3/2); 5r is still accepted and changes nothing; a .py module that receives an ER2
    integer uses Python's /. Integer is still available for code that builds one.
  • The workflows use actions that run on Node 24 (upload-artifact v7, download-artifact v8, configure-pages v6, upload-pages-artifact v5, deploy-pages v5); 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.raw starts it on demand.
  • Polynomials reach PARI faster: an expanded polynomial in one variable is read straight from
    its terms instead of through SymPy's Poly (degree 12: 221 to 84 us), which speeds up
    factor over 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_form of a 10x10 integer matrix: about
    half the time).
  • kernel of 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_form over 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 are Any, because they depend on the arguments. CI type-checks tests/typing/usage.py against the built wheel with mypy --strict. No startup cost: typing is 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 with name?.
  • Syntax highlighting for .er2 files 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=eulerphi links 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 + - * /: **, - and abs now run in about half the time of fractions.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: typing is no longer imported (explicit singledispatch registrations), and the PARI function table is read with csv.reader and its signatures without inspect.
  • Rational + - * / are faster again: a + b from about 1.7 to 1.2 times fractions.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.
  • kernel of 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's rref on random input).
  • Faster rational arithmetic: + - * / between rationals and integers are about 1.7 times
    faster (same results as fractions.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-baseline saves the benchmark times in
    benchmarks/baseline.json and make bench-compare measures 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.Z starts
    .github/workflows/release.yml. It checks the tag against the version and that the commit
    is on main, 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, and tests/test_release.py
    checks that only the approved job can publish.

Fixed

  • docs/PARI_FUNCTIONS.md showed only 59 of the 126 functions of "Programming in GP": the TeX quotes in kill's description opened inline code; the generator now escapes backticks.
  • The site's home and Get started pages described integer literals as Integer and 5r as the way to get a plain int; since D22 every integer is an int and only / and ** are exact.
  • Error messages of er2 file.er2 and of the REPL show only the program: a syntax error has no ER2 frames (as python 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(), not eulerphi()); factor(f, modulus=n) with n not prime says so instead of SymPy's "zero divisor".
  • %unload_ext er2 now undoes everything %load_ext er2 did: it also removes the .er2
    importer and the exact / and **, so 1/2 is Python's 0.5 again.
  • inverse and solve_linear report a singular matrix as NonInvertibleMatrixError only when
    it is one; other PARI errors (wrong dimensions, types) are a ValueError with 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.py fails if a relative link comes back.
  • examples/er2.xml was 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.py now 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.