PyEuclid: A Versatile Formal Plane Geometry System in Python
PyEuclid is a formal plane geometry system that combines symbolic inference rules with algebraic reasoning to generate and check geometric proofs. Use it to experiment with benchmark datasets, extend inference rules, or integrate interactive proof steps for human/LLM collaboration.
Documentation: https://kellyjdavis.github.io/PyEuclid/
Quick Start (PyPI)
- Install from PyPI
pip install pyeuclid
- Verify your install
python - <<'PY'
import sympy as sp
from pyeuclid.formalization.relation import Point, Length, Variable
print("PyEuclid version:", __import__("pyeuclid").__version__)
# Mini example inspired by Geometry3K/2820
pi = sp.pi
conditions = [
Length(Point("A"), Point("B")) - sp.Integer(4),
Length(Point("A"), Point("B")) - Variable("radius_A"),
]
goal = (pi * Variable("radius_A")) * Variable("radius_A")
print("Conditions:", conditions)
print("Goal:", goal)
PY
Developer Setup (from source)
Use this path if you need the benchmark datasets, cached diagrams, or want to extend PyEuclid.
Install from source:
git clone https://github.com/KellyJDavis/PyEuclid.git
cd PyEuclid
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install .
tar -xvzf cache.tar.gz
Project layout:
.
├── cache/ # Cached diagrams sampled from JGEX-AG-231
├── data/ # Benchmark datasets (JGEX-AG-231, Geometry3K)
├── pyeuclid/
│ ├── engine/ # Core reasoning components: inference rules, deductive database, algebraic system, proof generator
│ └── formalization/ # Problem formalization: relations, construction rules, state management, diagram handling
├── Dockerfile # Docker configuration for containerized setup
├── requirements.txt # List of required Python packages
├── setup.py # Setup script to build and install PyEuclid
└── test.py # Run experiments on test datasets
After installation, verify everything works:
python test_single.py --help
python test_single.py --show-proof
Docker (optional for dev parity):
You can either build the Docker image locally or pull it from Docker Hub:
# Build the Docker image locally
docker build -t pyeuclid .
# Alternatively, pull the image from Docker Hub
docker pull dahubao/pyeuclid
# After obtaining the image, run
docker run -it pyeuclid bash
Note: PyEuclid uses Gurobi as a component of its proof generator. To solve more complex problems, you may need a Gurobi academic license, as the free version has a limit of 2000 variables and constraints.
Evaluation
We provide both sequential and parallel methods to run experiments on the JGEX-AG-231 and Geometry3K datasets:
python test.py # Run sequentially on a single machine
sbatch slurm.sh # Run in parallel on a compute cluster via SLURM
Extension
If you would like to improve the reasoning ability of PyEuclid, one straightforward way is to add more complex inference rule at pyeuclid/engine/inference_rule.py. Here is an example:
@register('complex')
class AreaHeronFormula(InferenceRule):
def __init__(self, a: Point, b: Point, c: Point):
super().__init__()
self.a = a
self.b = b
self.c = c
def condition(self):
return [NotCollinear(self.a, self.b, self.c), Different(self.a, self.b, self.c), Lt(self.a, self.b), Lt(self.b, self.c)]
def conclusion(self):
s = (Length(self.a, self.b)+Length(self.a, self.c)+Length(self.b, self.c))/2
return [Area(self.a, self.b, self.c)**2-(s*(s-Length(self.a, self.b))*(s-Length(self.a, self.c))*(s-Length(self.b, self.c)))]
You need to specify the condition and conclusion of the inference rule. The Lt relation defines a partial order on the names of the points to reduce equivalent permutations of the inference rule.
We also provide an interactive interface that allows PyEuclid to collaborate with a human user or a Large-Language-Model (LLM) agent. You can explicitly trigger a reasoning step by calling:
engine.step(conditions, conclusions)
PyEuclid will verify both the conditions and the desired conclusions, and automatically apply the appropriate theorems or algebraic equations to derive the conclusions from the given conditions.
License
PyEuclid is licensed under the MIT License.
Metadata
Release files for pyeuclid 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyeuclid-1.0.3.tar.gz | 488.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyeuclid-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 540.6 kB
Release files / pyeuclid-1.0.3.tar.gz
| Download URL | pyeuclid-1.0.3.tar.gz |
|---|---|
| Size | 488.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8345e3d9c6c69b0828a4ce1820c75e620a6547d94e6d92099cd3cc132a471d7d
|
|
BLAKE2b-256 checksum How to use checksums |
ffee55cb6df7897d4546278c4d6408cc6ee21418ebb20ef7d6cd384ffa3e4955
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / pyeuclid-1.0.3-py3-none-any.whl
| Download URL | pyeuclid-1.0.3-py3-none-any.whl |
|---|---|
| Size | 51.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ed834ef54505f99b0564897cfabaa85664067321fe8297f14d8f1f5fa46f6ea
|
|
BLAKE2b-256 checksum How to use checksums |
443b4ffc645fc1eb3e86c82fbf963f1351b62ba321fcaf4af17aa1cfe04030d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for pyeuclid 1.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.