A lightweight Computer Algebra System for polynomial computations over finite fields
- Polynomial operations: +, -, *, /, %, gcd
- Supports polynomials over field of characteristic > 0 (A field of characteristic
$$p > 0$$ is one where arithmetic behaves like modulo$$p$$ , meaning$$p$$ copies of 1 add up to 0). - Supports multi-variable polynomials
- Numerical solutions for single-variable polynomials
- Numerical solutions for systems of polynomials
- Support for constructing finite fields with polynomials
- Can find Gröbner basis for polynomial Ideals
PolynomialCalculator provides a powerful command-line interface with the following commands:
finite_field: Create finite fields and display Zech logarithm informationrandom_monic: Generate random monic polynomials over finite fieldsfind_irreducible: Find irreducible polynomials of specified degreegcd: Compute greatest common divisor of polynomialssolve: Solve univariate polynomial equations over rationalsgroebner: Compute Gröbner basis for polynomial ideals
Global options:
--numeric-output {float,rational}to control numeric display (default:float)- Convenience flags:
--float,--rational - Logging:
--verbosefor debug logs,--quietto show errors only - Machine-readable:
--jsonto emit JSON forsolveandsolve-system(also supported forgroebner)
Use polycalc --help or polycalc <command> --help for detailed usage information.
Alternative Usage: If you haven't installed the package, you can substitute:
python polycalc.py(using the wrapper script)python -m polynomials.cli(running as a module)
polycalc finite_field -p 2 3Created GF(2^3) with irreducible polynomial: x^3 + x + 1
Primitive element table size: 7 elements
polycalc random_monic -p 5 4Random monic polynomial over F_5 of degree 4: x^4 + 3x^3 + x^2 + 2x + 2
polycalc find_irreducible -p 3 3Irreducible polynomial over F_3 of degree 3: x^3 + 2x^2 + x + 1
polycalc gcd "x^3+x+1" "x^2+1" -p 2gcd(x^3 + x + 1, x^2 + 1) = 1
polycalc solve "x^2-2" xSolutions to x^2-2 = 0:
1.4142135623730951
-1.4142135623730951
polycalc groebner "x^2+y^2-1" "x-y"Groebner basis:
x - y
2y^2 - 1
You can choose the monomial order with --order {lex,grlex,grevlex}:
polycalc groebner "x^2+y^2-1" "x-y" --order grevlexDefault is float mode. Use --rational to prefer exact-looking output when possible.
Environment variable:
- Set
POLYCALC_NUMERIC_OUTPUTtofloatorrationalto control the default mode.
polycalc --rational solve-system "x-1" "y-2"1 solutions:
[ x = 1, y = 2 ]
polycalc --float solve-system "x-1" "y-2"1 solutions:
[ x = 1.0, y = 2.0 ]
Add --json to solve, solve-system, or groebner for structured output.
Examples:
polycalc --json solve "x^2-2" xOutputs:
{ "command": "solve", "poly": "x^2-2", "var": "x", "solutions": [1.4142135623730951, -1.4142135623730951], "count": 2, "status": "ok" }polycalc --json solve-system "x-1" "y-2"Outputs:
{ "command": "solve-system", "polys": ["x-1", "y-2"], "status": "ok", "solutions": [{"x": 1.0, "y": 2.0}], "count": 1 }On errors, JSON mode returns:
{ "status": "error", "error": "<message>" }Groebner example:
polycalc --json groebner "x^2+y^2-1" "x-y" --order grevlexOutputs:
{ "command": "groebner", "polys": ["x^2+y^2-1","x-y"], "order": "grevlex", "status": "ok", "basis": ["x - y", "2y^2 - 1"], "count": 2 }- CLI logging:
--verboseenables debug-level logs for core polynomial and algebra operations.--quietsuppresses non-error output (only errors are shown).
- Core debug tracing:
- Set environment variable
POLYCALC_DEBUG=1to enable additional debug traces in some core algorithms (e.g., division algorithm and gcd). - This is off by default and only emits when combined with a suitable logging level.
- Set environment variable
- implement faster gcd algorithm
- implement lookup tables for primitive field elements
- implement 'factor' algorithm to factor over polynomials over finite fields
- option to plot single-variable polynomials
- create a GUI with Python
- web GUI
- Mobile app
git clone https://github.com/mike006322/PolynomialCalculator.git
cd PolynomialCalculator
pip install -e .After installation, you can use the polycalc command directly:
polycalc solve "x^2-2" xIf you prefer not to install the package, you can use the provided wrapper script:
git clone https://github.com/mike006322/PolynomialCalculator.git
cd PolynomialCalculator
python polycalc.py solve "x^2-2" xSome features depend on optional scientific libraries. Install with extras:
pip install "PolynomialCalculator[algebra]"This pulls in numpy and scipy for algebra/finite field operations.
python -m polynomials.cli solve "x^2-2" xPull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.
Please make sure to update tests as appropriate.
Developer tooling:
- Lint/format: ruff and black (configured via pyproject.toml)
- Pre-commit hooks: install with
pip install pre-committhenpre-commit install - CI: GitHub Actions runs tests on Python 3.10–3.12 across Windows/Linux/macOS
Performance benchmarking:
- See docs/SPEED_GUIDE.md for how we document speed changes.
- Benchmarks live in benchmarks/ and use pytest-benchmark.