Skip to main content

No project description provided

Project description

Narrate Lean

A Python CLI tool that converts Lean 4 proof files into human-readable Markdown documents with natural language explanations.

Features

  • Parse Lean 4 proofs: Extracts theorem statements, definitions, hypotheses, and proof steps
  • Natural language narration: Uses LLMs to generate clear explanations of mathematical proofs
  • LaTeX support: Preserves mathematical notation using LaTeX syntax
  • Flexible output: Output to file or stdout
  • Customizable: Skip definitions or proof details as needed

Installation

# Install dependencies
uv sync

# Or with pip
pip install -e .

Configuration

Create a .env file with your LLM API configuration:

# For LiteLLM proxy
LITELLM_API_KEY=your-api-key
LITELLM_BASE_URL=http://your-litellm-server:4000
LLM_MODEL=gpt-4.1

# Or for direct OpenAI API
OPENAI_API_KEY=your-openai-key
LLM_MODEL=gpt-4.1

Usage

Basic Usage

Convert a Lean proof file to Markdown:

narratelean narrate input.lean -o output.md

Output to stdout:

narratelean narrate example.lean

Options

  • -o, --output PATH: Specify output file (default: stdout)
  • --no-definitions: Skip narrating definitions
  • --no-proofs: Skip detailed proof narration (only include theorem statements)
  • --explain-lean: Include explanations of Lean tactics and syntax in the proof (default: pure math only)

Examples

# Narrate the example proof (pure math, no Lean explanations)
uv run narratelean narrate example.lean -o example_output.md

# Include Lean tactics explanations
uv run narratelean narrate example.lean --explain-lean -o example_with_lean.md

# Skip definitions, only narrate theorems
uv run narratelean narrate example.lean --no-definitions -o output.md

# Just theorem statements, no detailed proofs
uv run narratelean narrate example.lean --no-proofs -o statements_only.md

Example Files

This repository includes a complete example demonstrating the tool's capabilities:

  • example.lean - A Lean 4 proof of the Sequence Squeeze Theorem using Mathlib
  • example_output.md - The generated human-readable mathematical proof in Markdown format

The example showcases:

  • Custom definition (seq_converges_to) with natural language explanation
  • Formal theorem statement with hypotheses and conclusion
  • Step-by-step proof narrative in mathematical paper style
  • Proper LaTeX notation compatible with KaTeX rendering

Development

Running Tests

make test

Code Quality

# Format code
make format

# Lint code
make lint

# Type check
make type

# Run all checks
make all

Project Structure

  • src/narratelean/parser.py - Lean 4 file parser
  • src/narratelean/narrator.py - LLM-based proof narration engine
  • src/narratelean/markdown.py - Markdown document generator
  • src/narratelean/cli.py - Command-line interface

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

narratelean-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file narratelean-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: narratelean-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for narratelean-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ef37402b312320ac4786446b55b910786362647b82a1902b22402e17ff4e3b4
MD5 3843f3ebca24b1ab14da14e56dc454f6
BLAKE2b-256 fbbd41569a84fa933d59464eba0b6f2708ef8a51f574a0ba0b39b43e6b015fba

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