Skip to main content

PyEuclid: A Versatile Formal Plane Geometry System in Python

Project description

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.

PyEuclid architecture diagram

Documentation: https://kellyjdavis.github.io/PyEuclid/

Quick Start (PyPI)

  1. Install from PyPI
pip install pyeuclid
  1. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyeuclid-1.0.2.tar.gz (488.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyeuclid-1.0.2-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file pyeuclid-1.0.2.tar.gz.

File metadata

  • Download URL: pyeuclid-1.0.2.tar.gz
  • Upload date:
  • Size: 488.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for pyeuclid-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1eef56973efd6a77f6299cee4d85a2450451e7c1af4ac1e782331c2f2b529af6
MD5 81e8c04fb43c0b24dc17c1e1213806c3
BLAKE2b-256 b0254b1c5c0946e9459d798b631ed21648ee3f58cae340fc509d01c1382b8dee

See more details on using hashes here.

File details

Details for the file pyeuclid-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyeuclid-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 51.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for pyeuclid-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8b617bc1642922f6109fcba504af72d1d2373bf23b934e9a6d5d2dd4bbe33c
MD5 04638e6fac2cabff3f811f4515c979e2
BLAKE2b-256 3f7048d8a2822e034a770c48e36760989b6ccd74fb73d081cdcf12fd8311cd38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page