ER2 — mathematical Python
ER2 is a superset of Python for mathematics: symbolic syntax (sym x, x^2), exact arithmetic by default, and number theory through PARI/GP. Every Python program is a valid ER2 program, and every Python library is available through a normal import.
The name honours Paul Erdős — in Spanish, “Erdős” sounds like ER-dos, that is, ER2.
It runs here
Every cell below is executed by the ER2 kernel while this page is built. The results are computed, not typed in.
sym x
f = x^4 - 1
print(factor(f))
print(diff(f, x))(x - 1)*(x + 1)*(x^2 + 1)
4*x^3
Integer division is exact, because integer literals are exact:
print(1/3)
print(1/2 + 1/3)
print(2^100)1/3
5/6
1267650600228229401496703205376
Number theory goes to PARI, and comes back as ER2 values:
print(isprime(2^521 - 1))
print(factor(360))
print(phi(123456789))True
2^3 * 3^2 * 5
82260072
Anything mathematical renders as mathematics: \[\left(x - 1\right) \left(x + 1\right) \left(x^{2} + 1\right)\], produced by $\left(x - 1\right) \left(x + 1\right) \left(x^{2} + 1\right)$ in the middle of this sentence.
The whole of the syntax
There are seven differences from Python, and the specification lists them exhaustively — that is the entire language.
| Construct | Python | ER2 |
|---|---|---|
a ^ b |
XOR | power |
a ^^ b |
syntax error | XOR |
| integer literal | int |
exact Integer, so 1/3 is the rational |
5r |
syntax error | a plain Python int |
sym x, y |
syntax error | symbol declaration |
Everything else is Python, unchanged.
Where to go next
- Get started — install it and run the first program.
- The language — the normative specification.
- PARI reference — every PARI function and its ER2 name.
- Stability — what you may rely on before and after 1.0.
- Benchmarks — where the time goes.