feat(server): add lean_minimal_hypotheses tool#190
Open
Sfgangloff wants to merge 1 commit into
Open
Conversation
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`.
81d4559 to
d23ac1d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
lean_minimal_hypotheses: for each explicit(h : T)hypothesis of a theorem, drops it and re-elaborates via the LSP overlay (the sameupdate_file_content+get_diagnosticspattern used bylean_verifyandlean_multi_attempt). Reports load-bearing vs removable per hypothesis.Useful for "minimum hypotheses needed" / counterfactual reasoning when sharpening a theorem statement.
Behavior
{x : α}and instance[inst : C]binders (those are inferable / always load-bearing in practice).hby reference, the modified file fails to elaborate and we reportload-bearing.finallyblock (mirrorslean_verify).Files
src/lean_lsp_mcp/minimal_hypotheses.py— pure-Python binder parser.src/lean_lsp_mcp/models.py—MinimalHypothesesResult/HypothesisVerdict/HypothesisStatus.src/lean_lsp_mcp/server.py— tool registration alongsidelean_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 usingmcp_client_factory, marked@pytest.mark.slow.