by? generates sorryAX instead of reporting proof
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
(by? ...) should report the type of the proof generated, but is generating sorryAX instead.
Context
I'm a beginner. In the Zulip thread, @kmill explained how to use rewrite to prove an equality needed for the tail-recursive vector reverse I was trying to define. I wanted to understand what the (by ...) expression was doing, and he suggested using (by? ...) to see by's return type.
(My example probably isn't as minimal as possible, but I don't understand the problem well enough to know how to simplify the example without just randomly changing things. This is the best I can do at this point. Also, this could very well be the same as an existing issue--I can see some that might be the same, for all I know--but I can't tell.)
Steps to Reproduce
inductive Vect (a : Type u) : Nat -> Type u where
| nil : Vect a 0
| cons : a -> Vect a n -> Vect a (n + 1)
deriving Repr
def Vect.cast {m n : Nat} (h : m = n) (v : Vect α m) : Vect α n :=
h ▸ v
def Vect.revHelper (xs : Vect a n) (acc : Vect a m) : Vect a (m + n) :=
match xs with
| .nil => acc
| .cons y ys =>
(revHelper ys (.cons y acc)).cast (by? rw [Nat.succ_add]; rfl)
Lean underlines by?, and reports:
lean-nightly.lean:13:40
Tactic state
1 goal
a : Type ?u.1396
n m : Nat
xs : Vect a n
acc : Vect a m
n✝ : Nat
y : a
ys : Vect a n✝
⊢ ?m.1648 = m + (n✝ + 1)
Suggestions
Try this: sorryAx (?_ = m + (n✝ + 1)) true
Messages (2)
lean-nightly.lean:13:40
Try this: sorryAx (?m.1648 = m + (n✝ + 1)) true
lean-nightly.lean:13:48
tactic 'rewrite' failed, did not find instance of the pattern in the target expression
?n.succ + ?m
a : Type ?u.1396
n m : Nat
xs : Vect a n
acc : Vect a m
n✝ : Nat
y : a
ys : Vect a n✝
⊢ ?m.1648 = m + (n✝ + 1)
Expected behavior: [Clear and concise description of what you expect to happen]
@kmill said in this Zulip thread that the (by? ...) expression should cause display of the type of the return value of the application of the tactics in the expression. (I haven't figured out how to get more than minimal documentation on by? yet.)
Note that if by? is replaced by by, Vect.revHelper typechecks, and if I assign the result of the by expression to a variable using have or let, I can see the equality proof:
def Vect.revHelper' (xs : Vect a n) (acc : Vect a m) : Vect a (m + n) :=
match xs with
| .nil => acc
| .cons y ys =>
have prf := (by rw [Nat.succ_add]; rfl)
(revHelper' ys (.cons y acc)).cast prf
Putting the cursor on the last line shows the type of prf:
prf : m + 1 + n✝ = m + (n✝ + 1)
Actual behavior: [Clear and concise description of what actually happens]
The Infoview window reports with sorryAX, and shows only the rhs of the equality type returned by the tactics. In addition, there's an error on the first tactic, even though it worked fine with by.
Versions
Lean (version 4.13.0-rc3, x86_64-apple-darwin22.6.0, commit 01d414ac36dc, Release)
MacOS 14.7
Additional Information
Nothing.
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Vect.revHelper example and the (by? rw [Nat.succ_add]; rfl) entry point described in the issue. Trace how by? reports tactic suggestions and proof types, comparing it with by and the have prf workaround. Done means the suggestion reports the equality proof rather than sorryAx and does not emit the erroneous rewrite failure.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100