# Math Formal Lean Resources Server

Lean4 formal proof verification environment for NeMo Gym.

## Overview

This environment verifies Lean4 mathematical proofs generated by language models. The model receives a theorem statement and must produce a valid proof that compiles successfully.

## Verification Logic

The `/verify` endpoint:
1. Extracts Lean4 code from the model's markdown output
2. Builds a complete proof by combining header imports + theorem statement + generated proof
3. Sends the code to a Lean4 sandbox container for compilation
4. Returns `reward=1.0` if compilation succeeds, `reward=0.0` otherwise

Failure modes detected:
- Syntax errors
- Type errors
- Timeout (default 30s)
- Use of `sorry` tactic

## Data Sources

**MiniF2F Dataset**: 244 formal mathematics problems from the [MiniF2F benchmark](https://github.com/openai/miniF2F), covering:
- Algebra
- Number theory
- Geometry (formalized)

The dataset uses the [NeMo-Skills](https://github.com/NVIDIA-NeMo/Skills) prompt format aligned with deepseek-prover-v2.

## Requirements

- Lean4 sandbox container running on configurable host:port (default `127.0.0.1:6000`)
- The sandbox must expose `/execute` endpoint accepting JSON with `generated_code`, `language`, `timeout`

## Configuration

Set sandbox location via environment variables or YAML config:
```yaml
sandbox_host: ${oc.env:NEMO_SKILLS_SANDBOX_HOST,127.0.0.1}
sandbox_port: ${oc.env:NEMO_SKILLS_SANDBOX_PORT,6000}
```

## License

- **Code**: Apache-2.0
- **MiniF2F Data**: MIT License (from OpenAI MiniF2F repository)
