leanprover / leanprover/lean4

Conflicting `simp` lemmas `List.push_append_toArray` and `Array.append_singleton`

Open
#14,208 0 comments 1 reaction 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

#lean4 > List.push_append_toArray vs Array.push_singleton @ 💬

Simp lemmas docs#List.push_append_toArray and docs#Array.append_singleton are normalizing in opposite directions:

variable (a₁ a₂ : α) (as : Array α)

#check_tactic as.push a₁ ++ #[a₂] ~> (as.push a₁).push a₂ by simp only [Array.append_singleton]
#check_tactic as.push a₁ ++ #[a₂] ~> as ++ #[a₁, a₂] by simp only [List.push_append_toArray]

In particular this makes normalization of arrays sensitive to the context and sensitive to the number of elements of an array in the context, resulting in terms that diverge rather than converge:

variable (a₁ a₂ a₃ : α) (as : Array α)

#check_simp (as.push a₁).push a₂ ++ #[a₃] = as.push a₁ ++ #[a₂, a₃]
  ~> ((as.push a₁).push a₂).push a₃ = as ++ #[a₁, a₂, a₃]

I ran into this expecting the following to close by simp:

example (a₁ a₂ : α) (as : Array α) :
    (as.push a₁).push a₂ = as ++ #[a₁, a₂] := by simp

Should List.push_append_toArray normalize in the opposite direction (cons → push)? It would close this goal.

Versions

4.32

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

Start with the minimal reproducer and the named simp lemmas List.push_append_toArray and Array.append_singleton; compare their normalization behavior using the shown #check_tactic and #check_simp examples. Done means the conflicting directions are reconciled and the final by simp example behaves consistently without context-sensitive divergence.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.