Skip to content

feat: make try? find induction proofs for forall-quantified goals#12316

Draft
kim-em wants to merge 2 commits intomasterfrom
try_forall_induction
Draft

feat: make try? find induction proofs for forall-quantified goals#12316
kim-em wants to merge 2 commits intomasterfrom
try_forall_induction

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Feb 4, 2026

This PR enables try? to find induction-based proofs for goals with leading foralls (e.g., ∀ n, n ≤ fib n + 1) by collecting candidates after temporarily stripping the foralls and generating tactics prefixed with intro.

Previously, try? could find fun_induction fib for (n : Nat) : n ≤ fib n + 1 but not for ∀ n, n ≤ fib n + 1 because the candidate collector skipped expressions with loose bound variables. Rather than modifying the collector, this change uses forallTelescope during tactic generation to collect under the foralls and wraps the resulting tactics with intro <names>;.

Example:

def fib : Nat → Nat
  | 0 => 0
  | 1 => 1
  | n + 2 => fib n + fib (n + 1)

-- Previously worked:
example (n : Nat) : n ≤ fib n + 1 := by try?

-- Now also works:
example : ∀ n, n ≤ fib n + 1 := by try?
-- Suggests: intro n; fun_induction fib <;> grind [= fib]

🤖 Prepared with Claude Code and OpenAI Codex

This test demonstrates the current behavior where `try?` fails to find
induction-based proofs for goals with leading foralls.

The tests show:
- Baseline: `(n : Nat) : n ≤ fib n + 1` works (try? finds fun_induction)
- Bug: `∀ n, n ≤ fib n + 1` fails (try? doesn't collect candidates under forall)

After the fix, these tests should pass with try? finding suggestions like
`intro n; fun_induction fib <;> grind`.

Also adds guidance to .claude/CLAUDE.md about writing tests that demonstrate
bugs rather than working around them.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Feb 5, 2026
@kim-em kim-em force-pushed the try_forall_induction branch 2 times, most recently from ec0ca3c to 8bfbee0 Compare February 5, 2026 01:08
This PR enables `try?` to find induction-based proofs for goals with leading
foralls (e.g., `∀ n, n ≤ fib n + 1`) by collecting candidates after temporarily
stripping the foralls and generating tactics prefixed with `intro`.

Previously, `try?` could find `fun_induction fib` for `(n : Nat) : n ≤ fib n + 1`
but not for `∀ n, n ≤ fib n + 1` because the candidate collector skipped
expressions with loose bound variables. Rather than modifying the collector,
this change uses `forallTelescope` during tactic generation to collect under
the foralls and wraps the resulting tactics with `intro <names>;`.

For regular induction (not function induction), the code generates tactic syntax
using the intro names directly rather than FVarIds, since the FVarIds from the
temporary forallTelescope context are invalid outside that scope.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kim-em kim-em force-pushed the try_forall_induction branch from 8bfbee0 to 5e15ae9 Compare February 5, 2026 01:18
@kim-em kim-em marked this pull request as ready for review February 5, 2026 05:47
@kim-em kim-em marked this pull request as draft February 5, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant