Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offset unification unifies non-defeq terms #755

Closed
gebner opened this issue Nov 1, 2021 · 0 comments
Closed

Offset unification unifies non-defeq terms #755

gebner opened this issue Nov 1, 2021 · 0 comments

Comments

@gebner
Copy link
Member

gebner commented Nov 1, 2021

Description

First reported at leanprover-community/mathlib3#9805 as a bug in the (mathlib) convert tactic. In mathlib we use an Additive type tag that turns e.g. a multiplicative group into an additive group by defining + as * and 0 as 1, etc. This is very useful to reuse theorems from multiplicative structures for additive ones.

It turns out that rfl is accepted by the elaborator as a proof for (0 : Nat) = (0 : Additive Nat) (which is defeq to 0 = 1 and should not be provable). The incorrect proof is of course caught by the kernel.

The root cause for this issue seems to be the offset unification module, which evaluates arithmetic expressions like 3+3 without checking that the type-class instances are the expected ones. (That is, isDefEq normalZero additiveZero returns true even though they are not defeq.)

Steps to Reproduce

def Additive (α : Type) := α

instance [OfNat α 1] : OfNat (Additive α) (nat_lit 0) := ⟨(1 : α)⟩

example : (0 : Nat) = (0 : Additive Nat) := rfl

Expected behavior: A type error should be produced when elaborating rfl.

Actual behavior: The term elaborates and produces a type-incorrect term, which is then caught by the kernel.

Versions

Nightly from Oct 30.

Anderssorby pushed a commit to argumentcomputer/lean4 that referenced this issue Nov 10, 2021
Offset equalities should not assume default `Nat` instances for
numerals, `+`, `*`, and `-` have been used.

fixes leanprover#755
ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this issue Dec 2, 2022
ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this issue Dec 2, 2022
mathlib git sha: 8350c34a64b9bc3fc64335df8006bffcadc7baa6

Also ports the reassoc attribute.

- [x] depends on: leanprover#755 

Co-authored-by: Scott Morrison <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant