How lmcrc/newclid works
Project type and purpose
• Newclid is an open-source Python library and CLI tool (with optional web interface) for solving Olympiad‐style geometry problems. It provides both a command‐line front end (“newclid”), a Python API (GeometricSolverBuilder/GeometricSolver), and a minimal webapp. Internally it implements multiple reasoning engines (algebraic, numerical), an agent framework, dependency graph builders, and proof writers.
File structure
• Top-level files: packaging (pyproject.toml, setup.py, requirements.txt), CI/config (GitHub workflows, .pre-commit, devcontainer).
• docs/: Sphinx source for online documentation and static assets.
• scripts/: utilities for profiling and build checks.
• problems_datasets/: plain-text problem definitions.
• src/newclid/:
– __main__.py / api.py: CLI entrypoint and user API.
– configs.py + default_configs/: global configuration and fallback rule sets.
– agent/: agent interfaces and implementations (ddarn, human).
– algebraic_reasoning/: algebraic manipulator and tables.
– dependencies/: building and traversing the dependency graph and symbols graph.
– formulations/: converting text definitions to internal problem, clause, rule, definition objects.
– numerical/: numerical checkers, figure sketching, geometry primitives.
– predicates/: geometric predicates (collinearity, perpendicularity, etc.).
– proof & proof_writing: assembling and formatting proof steps.
– run_loop.py: orchestrates the solver loop.
– webapp.py: minimal web server exposing the solver over HTTP.
• tests/ & tests-perfs/: unit tests for agents, reasoning engines, CLI, geogebra loader, and performance benchmarks.
README for additional insights
• Describes two main usage modes: CLI (newclid --problem-name …) and Python interface (GeometricSolverBuilder → .build() → run()).
• Mentions nature of the agentic support, plug-in of different agents.
• Points to web documentation and examples in “examples” (folder in repo).
• References external reliance on Geogebra exports and optional uv packaging.
a. Main components
• CLI / Command‐line Front End
• Python API Layer (GeometricSolverBuilder, GeometricSolver)
• Core Orchestrator (run_loop.py)
• Formulation Engine (parsing problem text → internal Problem, Clause, Rule objects)
• Dependency Graph Builder (dependency_graph.py, symbols_graph.py)
• Reasoning Engines:
– Algebraic Reasoner
– Numerical Reasoner
• Agent Layer (agents_interface.py → ddarn, human_agent)
• Proof Writer (proof_writing.py)
• Configuration & Rule Store (configs.py, default_configs)
• Data Store (problems_datasets/)
• Optional Web Interface (webapp.py)
• External Service: Geogebra integration (load_geogebra.py)
b. Relationships & data flow
1. CLI/API → Formulation Engine (input text or file)
2. Formulation → Dependency Graph Builder → Graph structures
3. Core Orchestrator calls Agent Layer → selects next reasoning action
4. Agent Layer invokes one of the Reasoning Engines → returns new clauses or proof steps
5. Proof Writer accumulates steps → final proof output
6. Orchestrator loops until solve or timeout
7. Web Interface wraps API calls behind HTTP endpoints
8. Configuration & default rules feed into Formulation and Reasoning Engines
9. Profiling scripts and CI pipeline hook into test modules and scripts
c. Architectural patterns & principles
• Layered architecture (presentation → API → orchestrator → domain engines → data)
• Builder pattern for solver construction (GeometricSolverBuilder)
• Plugin/strategy pattern for agents and reasoning engines
• Separation of concerns: parsing, graph construction, reasoning, proof writing
• Declarative problem specification → imperative solve loop
d. Technologies & frameworks
• Python 3.9+ package managed via pyproject.toml / setuptools (setup.py)
• GitHub Actions for CI (tests, coverage, PyPI publishing)
• Sphinx for documentation
• optional uv for dev-dependency management
• Geogebra file parsing (load_geogebra.py)
• pre-commit, ruff for linting
– Green: Presentation layer (CLI, API, Webapp)
– Blue: Core orchestrator & domain logic (run_loop, formulation, dependency)
– Orange: Reasoning engines & agents
– Gray: Configuration & data
Detail
• Every sub-component, even if nested. For instance, show “default_configs” as part of Config Store.
• Distinguish between the two agent types (ddarn vs. human) under the Agent Layer.
• Testing and profiling pipelines branching off the core modules.