lean4-htt/tests/lean/run/1293.lean
Eric Wieser ae1ab94992
fix: replace bad simp lemmas for Id (#7352)
This PR reworks the `simp` set around the `Id` monad, to not elide or
unfold `pure` and `Id.run`

In particular, it stops encoding the "defeq abuse" of `Id X = X` in the
statements of theorems, instead using `Id.run` and `pure` to pass back
and forth between these two spellings. Often when writing these with
`pure`, they generalize to other lawful monads; though such changes were
split off to other PRs.

This fixes the problem with the current simp set where `Id.run (pure x)`
is simplified to `Id.run x`, instead of the desirable `x`.
This is particularly bad because the` x` is sometimes inferred with type
`Id X` instead of `X`, which prevents other `simp` lemmas about `X` from
firing.

Making `Id` reducible instead is not an option, as then the `Monad`
instances would have nothing to key on.

---------

Co-authored-by: Sebastian Graf <sg@lean-fro.org>
Co-authored-by: Kim Morrison <kim@tqft.net>
Co-authored-by: Paul Reichert <6992158+datokrat@users.noreply.github.com>
2025-05-22 22:45:35 +00:00

25 lines
749 B
Text

theorem modifySize {A : Type u} (as : Array A) (f : A → A) (n : Nat) : (as.modify n f).size = as.size := by
simp [Array.modify, Array.modifyM]; split <;> simp
structure Idx (p : Array String) where
n : Fin p.size
structure Store where
arr : Array String
-- integer pointers into `arr`, type-indexed by `arr`
ids : Array (Idx arr)
instance {arr : Array String} {f : String → String} {n : Nat} : Coe (Array (Idx arr)) (Array (Idx (arr.modify n f))) where
coe xs :=
xs.map (fun x => Idx.mk ((modifySize arr f n) ▸ x.n))
def store1 : Store := {
arr := #["a", "b", "c", "d", "e"]
ids := #[⟨2, by decide⟩]
}
def tryCoeStore := {
store1 with
-- using a lambda here hangs
arr := store1.arr.modify 2 (fun _ => "Z")
}