lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

Inconsistent substitution behavior of `cases`

Open Kha opened this issue 3 years ago • 2 comments

As noticed by @larsk21

example (h : n = 0) : n = 0 := by cases n  -- replaces all occurrences
example (h : n = 0) : n = 0 := by cases h' : n  -- replaces occurrence in target
example (h : id n = 0) : id n = 0 := by cases id n -- replaces occurrence in target
example (h : id n = 0) : id n = 0 := by cases h' : id n -- replaces occurrence in target

Kha avatar Aug 03 '22 15:08 Kha

The last three examples use generalize, and it currently only performs the generalization on the target type. We can change this, and it would be a solid solution for the second example, but not perfect for the last two since the generalization depends on kabstract.

Not sure whether we should do the change now or wait for the Mathlib port since it will impact it.

leodemoura avatar Aug 04 '22 01:08 leodemoura

The mathlib port is going to want the same behavior as lean 3, which FTR is:

example {n} (h : n = 0) : n = 0 := by cases n  -- replaces all occurrences
example {n} (h : n = 0) : n = 0 := by cases h' : n  -- replaces occurrence in target
example {n} (h : id n = 0) : id n = 0 := by cases id n -- replaces all occurrences
example {n} (h : id n = 0) : id n = 0 := by cases h' : id n -- replaces occurrence in target

So if you are considering among all the equally confusing choices, I would suggest this one.

digama0 avatar Aug 04 '22 01:08 digama0