You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.
Description
Consider the following piece of code that our user has written:
classAdd' (G: Type) extends Add G
defadd' {G: Type} [Add' G] (a b: G): G := a + b
variable {G: Type}
variable [Add G]
defadd (a b: G): G := a + b
theoremadd_eq_add [Add' G] (a b: G): add a b = add' a b := by
simp [add, add']
rfl
The class Add' inherits from Add, which means that when the theorem is being formulated, two different instances of Add G are added to the context: one from the variable [Add G], used in the definition of add, and one inherited from Add' G, used in the definition of add'.
As soon as the user tries to apply the rfl tactic to solve the goal, they are met with an ambiguous error:
tactic 'rfl' failed, equality lhs
a + b
is not definitionally equal to rhs
a + b
G: Type
inst✝¹: Add G
inst✝: Add' G
ab: G
⊢ a + b = a + b
Supposing the user has already experienced issues with multiple instances of operator overloading, they go on and hover over the two version of a + b, to see if those might refer to different operations.
However, both print the same function used by +:
@HAdd.hAdd G G G instHAdd a b : G
At this point, the user has no idea that what is causing this issue are the two instances of Add G present in the context (one being hidden away behind Add' G), and that the additions are each defined on different instances of Add G.
To fix the error, the user should remove the variable [Add G] and move the instance requirement to the def add directly.
Context
I was working on porting a WIP proof of Rubin's theorem from Lean3 to Lean4, and was putting theorems in different files.
Since variable statements aren't physically close to the theorem that uses it, I pre-emptively put a few class instances that I thought were needed afterwards, namely:
variable {G α β : Type _}
variable [Group G]
variable [MulAction G α] [MulAction G β]
However, this file also defines the following class before that:
class ContinuousMulAction (G α : Type _) [Group G] [TopologicalSpace α] extends
MulAction G α where
continuous : ∀ g : G, Continuous (fun x: α => g • x)
So when a theorem also had the [ContinuousMulAction G α] requirement, I ended up having two version of the scalar multiplication operator floating around, inevitably leading to a very confusing error.
Steps to Reproduce
Have two classes A B, the second inheriting from the first, and the first having a method
Define a function fa requiring an instance of the first class
Define an equivalent function fb requiring an instance of the second class
Define a theorem that requires both an instance of AandB, such that an equality between fa and fb needs to be proven
Try to prove the theorem
Expected behavior:
When printing an error where two visually equal expressions are definitionally different,
Lean should give hints as to which instances of a function/operator within the expressions differ.
When doing this, Lean should also give a hint that two "conflicting" instances were present in the context, and point to how each instance relate to instance hypotheses in the current context.
Actual behavior:
An error stating that two visually equal expressions is given, and any inspection made by the user does not help them figure out the cause of the error.
Versions
$ lean --version
Lean (version 4.3.0-rc2, commit 8e5cf6466061, Release)
$ uname -a
Linux deskryx 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 GNU/Linux
These days we produce the following error message:
tactic 'rfl' failed, the left-hand side
@HAdd.hAdd G G G (@instHAdd G inst✝¹) a b
is not definitionally equal to the right-hand side
@HAdd.hAdd G G G (@instHAdd G Add'.toAdd) a b
G : Type
inst✝¹ : Add G
inst✝ : Add' G
a b : G
⊢ a + b = a + b
Prerequisites
Description
Consider the following piece of code that our user has written:
The class
Add'
inherits fromAdd
, which means that when the theorem is being formulated, two different instances ofAdd G
are added to the context: one from thevariable [Add G]
, used in the definition ofadd
, and one inherited fromAdd' G
, used in the definition ofadd'
.As soon as the user tries to apply the
rfl
tactic to solve the goal, they are met with an ambiguous error:Supposing the user has already experienced issues with multiple instances of operator overloading, they go on and hover over the two version of
a + b
, to see if those might refer to different operations.However, both print the same function used by
+
:At this point, the user has no idea that what is causing this issue are the two instances of
Add G
present in the context (one being hidden away behindAdd' G
), and that the additions are each defined on different instances ofAdd G
.To fix the error, the user should remove the
variable [Add G]
and move the instance requirement to thedef add
directly.Context
I was working on porting a WIP proof of Rubin's theorem from Lean3 to Lean4, and was putting theorems in different files.
Since
variable
statements aren't physically close to the theorem that uses it, I pre-emptively put a few class instances that I thought were needed afterwards, namely:However, this file also defines the following class before that:
So when a theorem also had the
[ContinuousMulAction G α]
requirement, I ended up having two version of the scalar multiplication operator floating around, inevitably leading to a very confusing error.Steps to Reproduce
A B
, the second inheriting from the first, and the first having a methodfa
requiring an instance of the first classfb
requiring an instance of the second classA
andB
, such that an equality betweenfa
andfb
needs to be provenExpected behavior:
When printing an error where two visually equal expressions are definitionally different,
Lean should give hints as to which instances of a function/operator within the expressions differ.
When doing this, Lean should also give a hint that two "conflicting" instances were present in the context, and point to how each instance relate to instance hypotheses in the current context.
Actual behavior:
An error stating that two visually equal expressions is given, and any inspection made by the user does not help them figure out the cause of the error.
Versions
Additional Information
N/A
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: