[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"g6GIRdk3b9":3},"# LegalLean — Verified Legal Reasoning in Lean 4\n\n[![Verify](https://github.com/edu-ap/legal-lean/actions/workflows/verify.yml/badge.svg)](https://github.com/edu-ap/legal-lean/actions/workflows/verify.yml)\n\n**Monograph:** *Verified Legal Reasoning: From Natural Language to Formal Proof*\n\n## Architecture\n\nThree-layer architecture where the process of writing the monograph validates its own thesis:\n\n```\nLayer 1: Lean 4 (LegalLean/)     — Verified types and proofs (invariant verifier)\nLayer 2: JSON (arguments/)        — Claim-evidence graph with defeat relations (Legal IR)\nLayer 3: Prose (monograph/)       — Published monograph (generated from both layers)\n```\n\n**Core thesis:** Legal reasoning can be partially formalised in dependent type theory, and the boundary between formalisable and non-formalisable elements can itself be encoded within the type system (`FormalisationBoundary`).\n\n**Signature framing (Gemini):** LLMs are heuristic transducers; Lean 4 is the invariant verifier.\n\n## Key Types\n\n| Type | Purpose |\n|------|---------|\n| `Deontic` | Permitted / prohibited / obligatory |\n| `LegalRule` | Rule with defeasibility metadata |\n| `EvidenceFor` | Propositions-as-types for legal evidence |\n| `DefeasiblyHolds` | Non-monotonic entailment (holds unless defeated) |\n| `FormalisationBoundary` | Hart's open texture as a first-class type |\n| `RequiresHumanDetermination` | Typeclass marking where formal verification yields to human judgment |\n| `Vague` | Core/penumbra distinction (subclass of RequiresHumanDetermination) |\n| `Discretionary` | Authority discretion (subclass of RequiresHumanDetermination) |\n\n## Case Studies\n\n1. **IRC §163(h)** — Mortgage interest deduction (Lawsky's gold standard). COMPLETE.\n2. **O-1 Visa** — \"3 of 8\" criteria as dependent types. Stub + research.\n3. **Australian TCP Code** — Regulatory compliance (Governatori comparison). Stub + research.\n\n## Automated Pipeline\n\n### Research (Perplexity)\n\nExtracts `sorry`/TODO stubs from Lean 4 files, generates structured prompts shaped to match LegalLean types, and calls Perplexity API with model council.\n\n```bash\n# Dry run (preview prompts)\npython3 scripts/research_pipeline.py --all --dry-run\n\n# Research specific case study\npython3 scripts/research_pipeline.py --file IRC163h --models sonar-pro\n\n# Model council (multiple models)\npython3 scripts/research_pipeline.py --all --models sonar sonar-pro sonar-reasoning\n\n# 8-dimension comparison table\npython3 scripts/research_pipeline.py --comparisons --models sonar-pro\n```\n\n**Prompt engineering:** Questions are shaped so answers map to LegalLean types:\n- Conditions -> `LegalRule.conclusion`\n- Exceptions -> `Defeats`\n- Vague terms -> `FormalisationBoundary` / `Vague`\n- Authorities -> `Discretionary`\n- Case law -> `EvidenceFor` sources\n\n### Theorem Proving (Aristotle by Harmonic)\n\nAutomated sorry-stub resolution using Aristotle (aristotle.harmonic.fun). IMO gold-medal-level engine that fills `sorry` stubs with verified Lean 4 proofs.\n\n```bash\n# List sorry stubs (no API call)\npython3 scripts/aristotle_prover.py --all --dry-run\n\n# Prove sorries in specific file\npython3 scripts/aristotle_prover.py --file LegalLean/CaseStudies/IRC163h.lean\n\n# Prove all files (parallel, max 5 concurrent)\npython3 scripts/aristotle_prover.py --all\n\n# Sequential mode (if hitting rate limits)\npython3 scripts/aristotle_prover.py --all --sequential --timeout 20\n```\n\n**Architecture:** Monte Carlo Graph Search with 200B+ parameter transformer. Every solution verified by Lean 4 type checker before delivery (hallucination-free by design).\n\n**SDK:** `pip install aristotlelib`\n\n**API key:** `ARISTOTLE_HARMONIC_API_KEY` in `.env` (mapped to `ARISTOTLE_API_KEY` for SDK).\n\n### Full Pipeline\n\n```\nsorry in Lean 4\n    |\n    v\nresearch_pipeline.py (Perplexity) --> structured legal knowledge (JSON)\n    |\n    v\nHuman translates to Lean 4 types + sorry stubs\n    |\n    v\naristotle_prover.py (Harmonic) --> verified proofs replacing sorry\n    |\n    v\nLean 4 type checker confirms (deterministic, hallucination-free)\n    |\n    v\nHuman reviews proof for legal correctness\n    |\n    v\narguments/thesis.json updated with verified claims\n    |\n    v\nmonograph/ prose generated from verified claims\n```\n\n## Comparison Table (7 dimensions)\n\nScores from Perplexity research (note: may reflect prompt bias for LegalLean):\n\n| Dimension | DDL | Catala | L4L | LegalLean | LegalRuleML |\n|-----------|-----|--------|-----|-----------|-------------|\n| Compositional semantics | 4 | 4 | 3 | 5 | 2 |\n| Deontic modalities | 5 | 2 | 4 | 5 | 4 |\n| Dependent types | 1 | 1 | 5 | 5 | 1 |\n| Machine-checkable guarantees | 3 | 4 | 3 | 5 | 1 |\n| Open texture encoding | 4 | 2 | 3 | 5 | 2 |\n| Provenance tracking | 4 | 3 | 5 | 5 | 4 |\n| Temporal reasoning | 4 | 3 | 3 | 5 | 4 |\n| **Total** | **25** | **19** | **26** | **35** | **18** |\n\n## Target Audience\n\n**Tier 1 (must impress):** Sarah Lawsky, Monica Palmirani, Jeremy Avigad, Leonardo de Moura, Guido Governatori, Zhe Hou.\n\n**Tier 2 (should engage):** Henry Prakken, Trevor Bench-Capon, Daniel Martin Katz, Scott Shapiro.\n\n**Target venue:** JURIX 2026 or ICAIL 2027.\n\n## Dependencies\n\n- Lean 4 v4.16.0+\n- Python 3.12+ (for research and proving scripts)\n- `aristotlelib` (Aristotle SDK)\n- `requests` (Perplexity API)\n- API keys: `PERPLEXITY_API_KEY`, `ARISTOTLE_HARMONIC_API_KEY`\n\n## Key References\n\n- Lawsky, \"A Logic for Statutes\", Florida Tax Review (2017)\n- Hart, *The Concept of Law* (1961) — open texture\n- Governatori, \"Computing Contracts with Defeasible Deontic Logic\"\n- Merigoux et al., \"Catala: A Programming Language for the Law\"\n- Hou et al., \"L4L: Towards Trustworthy Legal AI through LLM Agents and Formal Reasoning\"\n- Palmirani et al., \"LegalRuleML Core Specification v1.0\"\n\n\n---\n\n> **🤖 Coding Agent?** Read [`AGENT_BOOTSTRAP.md`](https://github.com/edu-ap/stack-audit/blob/main/AGENT_BOOTSTRAP.md) — the single-document entrypoint for the full 10-system stack. It tells you how to build, test, contribute, and file issues. Every agent that uses this stack should contribute back.\n",1792350350846]