leanprover / leanprover/lean4

`cases` can reorder equally named hypotheses

Open
#1,556 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

example (P : Nat → Prop) (a) (h : ∃ n, a = n + 1 ∧ P n) : ∃ n, P n := by
  let ⟨n', e, h⟩ := h
  cases e
  exact ⟨_, h⟩
  -- application type mismatch
  --   Exists.intro ?m.12045 h
  -- argument
  --   h
  -- has type
  --   ∃ n, n' + 1 = n + 1 ∧ P n : Prop
  -- but is expected to have type
  --   P ?m.12045 : Prop

Before the cases, the state is:

P: Nat → Prop
a: Nat
: ∃ n, a = n + 1 ∧ P n
n': Nat
e: a = n' + 1
h: P n'
⊢ ∃ n, P n

The first h: ∃ n, a = n + 1 ∧ P n argument (name elided in the display) is being shadowed by the h: P n' argument. After cases, the state is:

case refl
P: Nat → Prop
n': Nat
: P n'
h: ∃ n, n' + 1 = n + 1 ∧ P n
⊢ ∃ n, P n

Because h: P n' did not need to be rewritten but h: ∃ n, a = n + 1 ∧ P n did, h: ∃ n, a = n + 1 ∧ P n got moved to the end of the hypothesis list, meaning that now h refers to h: ∃ n, a = n + 1 ∧ P n instead of h: P n' and the exact fails.

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 Lean example in the issue and inspect the cases tactic's hypothesis reordering and name handling. The fix is complete when equally named hypotheses retain the intended bindings after cases and the shown exact ⟨_, h⟩ succeeds.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.