-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finish aligning List/Array/Vector.ofFn lemmas (#6838)
This PR completes aligning the (limited) verification API for `List/Array/Vector.ofFn`.
- Loading branch information
Showing
7 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/- | ||
Copyright (c) 2025 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
prelude | ||
import Init.Data.Array.Lemmas | ||
import Init.Data.List.OfFn | ||
|
||
/-! | ||
# Theorems about `Array.ofFn` | ||
-/ | ||
|
||
namespace Array | ||
|
||
@[simp] | ||
theorem ofFn_eq_empty_iff {f : Fin n → α} : ofFn f = #[] ↔ n = 0 := by | ||
rw [← Array.toList_inj] | ||
simp | ||
|
||
@[simp 500] | ||
theorem mem_ofFn {n} (f : Fin n → α) (a : α) : a ∈ ofFn f ↔ ∃ i, f i = a := by | ||
constructor | ||
· intro w | ||
obtain ⟨i, h, rfl⟩ := getElem_of_mem w | ||
exact ⟨⟨i, by simpa using h⟩, by simp⟩ | ||
· rintro ⟨i, rfl⟩ | ||
apply mem_of_getElem (i := i) <;> simp | ||
|
||
end Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/- | ||
Copyright (c) 2025 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
prelude | ||
import Init.Data.Vector.Lemmas | ||
import Init.Data.Array.OfFn | ||
|
||
/-! | ||
# Theorems about `Vector.ofFn` | ||
-/ | ||
|
||
namespace Vector | ||
|
||
@[simp] theorem getElem_ofFn {α n} (f : Fin n → α) (i : Nat) (h : i < n) : | ||
(Vector.ofFn f)[i] = f ⟨i, by simpa using h⟩ := by | ||
simp [ofFn] | ||
|
||
theorem getElem?_ofFn (f : Fin n → α) (i : Nat) : | ||
(ofFn f)[i]? = if h : i < n then some (f ⟨i, h⟩) else none := by | ||
simp [getElem?_def] | ||
|
||
@[simp 500] | ||
theorem mem_ofFn {n} (f : Fin n → α) (a : α) : a ∈ ofFn f ↔ ∃ i, f i = a := by | ||
constructor | ||
· intro w | ||
obtain ⟨i, h, rfl⟩ := getElem_of_mem w | ||
exact ⟨⟨i, by simpa using h⟩, by simp⟩ | ||
· rintro ⟨i, rfl⟩ | ||
apply mem_of_getElem (i := i) <;> simp | ||
|
||
theorem back_ofFn {n} [NeZero n](f : Fin n → α) : | ||
(ofFn f).back = f ⟨n - 1, by have := NeZero.ne n; omega⟩ := by | ||
simp [back] | ||
|
||
end Vector |