Skip to content

Conversation

@kim-em
Copy link
Collaborator

@kim-em kim-em commented Dec 2, 2025

This PR adds +grind and +try? options to exact? and apply? tactics.

+grind option

When +grind is enabled, grind is used as a fallback discharger for subgoals that solve_by_elim cannot close. The proof is wrapped in Grind.Marker so suggestions display (by grind) instead of the complex grind proof term.

Example:

axiom foo (x : Nat) : x < 375 < x → x.log2 < 6

/--
info: Try this:
  [apply] exact foo x (by grind) (by grind)
-/
#guard_msgs in
example (x : Nat) (h₁ : x < 30) (h₂ : 8 < x) : x.log2 < 6 := by
  exact? +grind

+try? option

When +try? is enabled, try? is used as a fallback discharger for subgoals. This is useful when subgoals require induction or other strategies that try? can find but solve_by_elim and grind cannot.

Example:

inductive MyList (α : Type _) where
  | nil : MyList α
  | cons : α → MyList α → MyList α

axiom MyListProp : MyList α → Prop
@[grind .] axiom mylist_nil : MyListProp (MyList.nil : MyList α)
@[grind .] axiom mylist_cons : ∀ (x : α) (xs : MyList α), MyListProp xs → MyListProp (MyList.cons x xs)

axiom qux (xs : MyList α) (p : MyListProp xs) : MyListProp2 xs

/--
info: Try this:
  [apply] exact qux xs (by try?)
-/
example (xs : MyList α) : MyListProp2 xs := by
  exact? +try?

🤖 Prepared with Claude Code

kim-em and others added 2 commits December 2, 2025 03:54
This PR adds a `+try?` option to `exact?` and `apply?` tactics,
similar to the existing `+grind` option.

When `+try?` is enabled, `try?` is used as a fallback discharger
for subgoals that `solve_by_elim` cannot close. The proof is
wrapped in `Try.Marker` so suggestions display `(by try?)` instead
of the complex proof term.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@kim-em kim-em requested a review from leodemoura as a code owner December 2, 2025 04:23
@kim-em kim-em added the changelog-tactics User facing tactics label Dec 2, 2025
@kim-em kim-em enabled auto-merge December 2, 2025 04:28
@kim-em kim-em added this pull request to the merge queue Dec 2, 2025
Merged via the queue into master with commit 226a90f Dec 2, 2025
14 checks passed
algebraic-dev pushed a commit that referenced this pull request Dec 8, 2025
This PR adds `+grind` and `+try?` options to `exact?` and `apply?`
tactics.

## `+grind` option

When `+grind` is enabled, `grind` is used as a fallback discharger for
subgoals that `solve_by_elim` cannot close. The proof is wrapped in
`Grind.Marker` so suggestions display `(by grind)` instead of the
complex grind proof term.

Example:
```lean
axiom foo (x : Nat) : x < 37 → 5 < x → x.log2 < 6

/--
info: Try this:
  [apply] exact foo x (by grind) (by grind)
-/
#guard_msgs in
example (x : Nat) (h₁ : x < 30) (h₂ : 8 < x) : x.log2 < 6 := by
  exact? +grind
```

## `+try?` option

When `+try?` is enabled, `try?` is used as a fallback discharger for
subgoals. This is useful when subgoals require induction or other
strategies that `try?` can find but `solve_by_elim` and `grind` cannot.

Example:
```lean
inductive MyList (α : Type _) where
  | nil : MyList α
  | cons : α → MyList α → MyList α

axiom MyListProp : MyList α → Prop
@[grind .] axiom mylist_nil : MyListProp (MyList.nil : MyList α)
@[grind .] axiom mylist_cons : ∀ (x : α) (xs : MyList α), MyListProp xs → MyListProp (MyList.cons x xs)

axiom qux (xs : MyList α) (p : MyListProp xs) : MyListProp2 xs

/--
info: Try this:
  [apply] exact qux xs (by try?)
-/
example (xs : MyList α) : MyListProp2 xs := by
  exact? +try?
```

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-tactics User facing tactics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants