Skip to content

feat(server): add lean_minimal_hypotheses tool#190

Open
Sfgangloff wants to merge 1 commit into
oOo0oOo:mainfrom
Sfgangloff:feat/lean-minimal-hypotheses
Open

feat(server): add lean_minimal_hypotheses tool#190
Sfgangloff wants to merge 1 commit into
oOo0oOo:mainfrom
Sfgangloff:feat/lean-minimal-hypotheses

Conversation

@Sfgangloff
Copy link
Copy Markdown
Contributor

Summary

Adds lean_minimal_hypotheses: for each explicit (h : T) hypothesis of a theorem, drops it and re-elaborates via the LSP overlay (the same update_file_content + get_diagnostics pattern used by lean_verify and lean_multi_attempt). Reports load-bearing vs removable per hypothesis.

Useful for "minimum hypotheses needed" / counterfactual reasoning when sharpening a theorem statement.

Behavior

  • Skips implicit {x : α} and instance [inst : C] binders (those are inferable / always load-bearing in practice).
  • Does not rewrite the proof body. If the body names h by reference, the modified file fails to elaborate and we report load-bearing.
  • Per-hypothesis error count is compared to a pre-modification baseline, so pre-existing errors elsewhere in the file don't poison the verdict.
  • Original file content is restored in a finally block (mirrors lean_verify).
  • For each load-bearing hypothesis, the verdict includes a breaks list -- every new error (line + column + message) produced by removing that binder -- pinpointing where in the proof body the hypothesis was used.

Files

  • src/lean_lsp_mcp/minimal_hypotheses.py — pure-Python binder parser.
  • src/lean_lsp_mcp/models.pyMinimalHypothesesResult / HypothesisVerdict / HypothesisStatus.
  • src/lean_lsp_mcp/server.py — tool registration alongside lean_verify.
  • tests/unit/test_minimal_hypotheses.py — 13 unit tests for the parser helpers (no Lean install required).
  • tests/test_minimal_hypotheses.py — 5 async integration tests using mcp_client_factory, marked @pytest.mark.slow.

For each explicit `(h : T)` hypothesis of a theorem, drop it and
re-elaborate the file via the LSP overlay (`update_file_content`
+ `get_diagnostics`). Reports load-bearing vs removable per
hypothesis. Skips implicit `{x : α}` and instance `[inst : C]`
binders. Does not rewrite the proof body — a body that names `h`
fails to elaborate without the binder, which is the truthful
answer.

Useful for "minimum hypotheses needed" / counterfactual reasoning
when sharpening a theorem statement (a workflow request raised in
recent math-research workshops).

Implementation:
- `src/lean_lsp_mcp/minimal_hypotheses.py`: pure-Python binder
  parser with balanced-paren scanning; no LSP / I/O dependency.
- `models.py`: `MinimalHypothesesResult` / `HypothesisVerdict`
  / `HypothesisStatus`.
- `server.py`: `lean_minimal_hypotheses` tool. Compares per-hypothesis
  error count to a baseline so pre-existing errors elsewhere in the
  file don't poison the verdict. Original file content is restored
  in a `finally` block.
- README: documents the new tool with example output.

Tests:
- `tests/unit/test_minimal_hypotheses.py`: 13 unit tests covering
  the binder parser, explicit-binder filter, drop-binder splice,
  and offset-to-line helper. No Lean install required.
- `tests/test_minimal_hypotheses.py`: 5 async integration tests
  using the existing `mcp_client_factory` fixture against a new
  `MinimalHypothesesTest.lean` in the test project. Covers
  load-bearing/removable, no-explicit-binders, mixed binders, and
  unknown-theorem error handling. Marked `@pytest.mark.slow`.
@Sfgangloff Sfgangloff force-pushed the feat/lean-minimal-hypotheses branch 2 times, most recently from 81d4559 to d23ac1d Compare May 5, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant