lean4-htt/tests/lean/run/988.lean
Kim Morrison 3a408e0e54
feat: change Array.get to take a Nat and a proof (#6032)
This PR changes the signature of `Array.get` to take a Nat and a proof,
rather than a `Fin`, for consistency with the rest of the (planned)
Array API. Note that because of bootstrapping issues we can't provide
`get_elem_tactic` as an autoparameter for the proof. As users will
mostly use the `xs[i]` notation provided by `GetElem`, this hopefully
isn't a problem.

We may restore `Fin` based versions, either here or downstream, as
needed, but they won't be the "main" functions.

---------

Co-authored-by: David Thrane Christiansen <david@davidchristiansen.dk>
2024-11-12 03:30:46 +00:00

56 lines
2.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

instance {α : Type u} : HAppend (Fin m → α) (Fin n → α) (Fin (m + n) → α) where
hAppend a b i := if h : i < m then a ⟨i, h⟩ else b ⟨i - m, sorry⟩
def empty : Fin 0 → Nat := (nomatch ·)
theorem append_empty (x : Fin i → Nat) : x ++ empty = x :=
funext fun i => dif_pos _
opaque f : (Fin 0 → Nat) → Prop
example : f (empty ++ empty) = f empty := by simp only [append_empty] -- should work
@[congr] theorem Array.get_congr (as bs : Array α) (w : as = bs) (i : Nat) (h : i < as.size) (j : Nat) (hi : i = j) :
as[i] = (bs[j]'(w ▸ hi ▸ h)) := by
subst bs; subst j; rfl
example (as : Array Nat) (h : 0 + x < as.size) :
as[0 + x] = as[x] := by
simp -- should work
example (as : Array (Nat → Nat)) (h : 0 + x < as.size) :
as[0 + x] = as[x]'(Nat.zero_add x ▸ h) := by
simp -- should also work
example (as : Array (Nat → Nat)) (h : 0 + x < as.size) :
as[0 + x] i = as[x] (0+i) := by
simp -- should also work
example [Decidable p] : decide (p ∧ True) = decide p := by simp -- should work
def Pi.single [DecidableEq ι] {f : ι → Type u} [∀ i, Inhabited (f i)] (i : ι) (x : f i) : ∀ i, f i :=
fun j => if h : j = i then h ▸ x else default
structure Set (α : Type u) where of :: mem : α → Prop
instance : CoeSort (Set α) (Type u) where coe s := Subtype s.mem
@[congr]
theorem dep_congr [DecidableEq ι] {p : ι → Set α} [∀ i, Inhabited (p i)] :
∀ {i j} (h : i = j) (x : p i) (y : α) (hx : x = y), Pi.single (f := (p ·)) i x = Pi.single (f := (p ·)) j ⟨y, hx ▸ h ▸ x.2⟩
| _, _, rfl, _, _, rfl => rfl
theorem aux {p : Nat → Set Nat} {i j y : Nat} (x : p j) (h₁ : x = y) (h₂ : i = j) : Set.mem (p i) y := by
have := x.2
subst h₁ h₂
assumption
example {p : Nat → Set Nat} [∀ i, Inhabited (p i)] (i : Nat) (x : p (0 + i)) (y : Nat) : Pi.single (f := (p ·)) (0 + i) x = Pi.single (f := (p ·)) i ⟨x, aux x rfl (Nat.zero_add i).symm ⟩ := by
simp
def Submodule (α : Type u) [OfNat α 0] := { s : Set α // s.mem 0 }
instance [OfNat α 0] : CoeSort (Submodule α) (Type u) where coe s := s.1
instance [OfNat α 0] (p : Submodule α) : Inhabited p where default := ⟨0, p.2⟩
example (p : Nat → Submodule Nat) :
Pi.single (f := (p ·)) (x - x) ⟨0, (p ..).2⟩ = Pi.single 0 ⟨0, (p ..).2⟩ := by
simp only [Nat.sub_self] -- should work