leanprover / leanprover/lean4

evalPropStep simproc util can use local decidable instance

Open
#7,444 5 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
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:

Description

Here are three examples:

example [inst : DecidableEq (Fin 3)] :
    (2 : Fin 3) ≠ 0 := by
  simp only [Fin.reduceNe]

example [inst : DecidableEq Int] :
    (2 : Int) ≠ 0 := by
  simp only [Int.reduceNe]

example [inst : Decidable (2 < 3)] :
    2 < 3 := by
  simp only [Nat.reduceLT]

live.lean-lang.org version, for convenience
In each of these, an error is produced when typechecking:

application type mismatch
  eq_true_of_decide (Eq.refl true)
argument has type
  true = true
but function has type
  decide ... = true → ... = True

In each, the cause appears to be decide using inst rather than the expected existing instance for each of these structures. This arises from the simprocs in question, X.reduceBinPred each using evalPropStep, which infers the instance for decide using mkAppOptM and thus picks up inst first.

While this may appear to be user error ("just don't have inst there!"), this does occur for users of mathlib, see zulip thread because of the implementation of MultilinearMap. It also appears easily solvable by adjusting the relevant simprocs to use the correct Decidable instance when they call evalPropStep, and adjusting evalPropStep itself to take an optional decidability instance rather than using typeclass inference.

Context

Lean Zulip thread where this arose

Steps to Reproduce
  1. Code as above

Expected behavior: The simp only call closes the goal with no errors.

Actual behavior: The simp only call closes the goal but errors are generated on the example during typechecking.

Versions
Lean 4.19.0-nightly-2025-03-11
Target: x86_64-unknown-linux-gnu

on live.lean-lang.org (Lean nightly without mathlib)
and

Lean 4.18.0-rc1
Target: x86_64-unknown-linux-gnu

on live.lean-lang.org (Latest Mathlib)

Additional Information

None.

Impact

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

Reproduce the three examples from the issue and inspect the X.reduceBinPred simprocs together with evalPropStep, especially their use of mkAppOptM and the decidability instance. The work is done when the examples typecheck without generated errors while preserving the expected simp behavior.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.