leanprover / leanprover/lean4

Bug: grind linarith crashes in the presence of conflicting `hAdd` instances

Open
#13,214 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

The existence of overlapping instances of hAdd lead to a crash in grind linarith.

Steps to Reproduce

Minimal reproducer:

@[reducible] def Poly := Vector (Fin 7) 4
 
-- Add and HAdd already exist for Vector
-- Redefining Add here creates another instance of HAdd (derived from Add)
@[reducible]
instance myAdd : Add Poly where -- an instance of HAdd is 
   add f g := Vector.map (fun i => f[i]! + g[i]!) (Vector.range 4)
 
 example (n : Nat) (p q : Poly) (hp : p + q = p) : n = n := by
   grind  -- ERROR: expected instHAdd to be defeq to instHAdd

Small variant (we directly redefine HAdd)

@[reducible] def Poly := Vector (Fin 7) 4
 
 instance myHAdd : HAdd Poly Poly Poly where
   hAdd f g := Vector.map (fun i => f[i]! + g[i]!) (Vector.range 4)
 
 example (n : Nat) (p q : Poly) (hp : p + q = p) : n = n := by
   grind  -- ERROR: expected myHAdd to be defeq to instHAdd

Expected behavior: grind doesn't crash

Actual behavior: grind crashes

Versions

Tested on Lean 4.29.0

Impact

Minor on my side as the fix is straightforward.

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal reproducer with Lean nightly and tracing the grind linarith path involved in resolving the conflicting hAdd instances. Use both reproducer variants to isolate the crash, then add a regression test showing that grind completes without crashing and preserves the expected behavior.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.