-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(data/fintype/vector, logic/equiv/list): split (#18226)
`array` and `d_array` do not exist in Lean 4; it's easier for porting if we put the stuff about those types in separate files.
- Loading branch information
1 parent
2609ad0
commit 78314d0
Showing
6 changed files
with
75 additions
and
47 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
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,20 @@ | ||
/- | ||
Copyright (c) 2017 Mario Carneiro. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mario Carneiro | ||
-/ | ||
import data.fintype.pi | ||
import logic.equiv.array | ||
|
||
/-! | ||
# `array n α` is a fintype when `α` is. | ||
-/ | ||
|
||
variables {α : Type*} | ||
|
||
instance d_array.fintype {n : ℕ} {α : fin n → Type*} | ||
[∀ n, fintype (α n)] : fintype (d_array n α) := | ||
fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm | ||
|
||
instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) := | ||
d_array.fintype |
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,52 @@ | ||
/- | ||
Copyright (c) 2018 Mario Carneiro. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mario Carneiro | ||
-/ | ||
import data.vector.basic | ||
import logic.equiv.list | ||
import control.traversable.equiv | ||
|
||
/-! | ||
# Equivalences involving `array` | ||
We keep this separate from the file containing `list`-like equivalences as those have no future | ||
in mathlib4. | ||
-/ | ||
|
||
namespace equiv | ||
|
||
/-- The natural equivalence between length-`n` heterogeneous arrays | ||
and dependent functions from `fin n`. -/ | ||
def d_array_equiv_fin {n : ℕ} (α : fin n → Type*) : d_array n α ≃ (Π i, α i) := | ||
⟨d_array.read, d_array.mk, λ ⟨f⟩, rfl, λ f, rfl⟩ | ||
|
||
/-- The natural equivalence between length-`n` arrays and functions from `fin n`. -/ | ||
def array_equiv_fin (n : ℕ) (α : Type*) : array n α ≃ (fin n → α) := | ||
d_array_equiv_fin _ | ||
|
||
/-- The natural equivalence between length-`n` vectors and length-`n` arrays. -/ | ||
def vector_equiv_array (α : Type*) (n : ℕ) : vector α n ≃ array n α := | ||
(vector_equiv_fin _ _).trans (array_equiv_fin _ _).symm | ||
|
||
end equiv | ||
|
||
namespace array | ||
open function | ||
variable {n : ℕ} | ||
|
||
instance : traversable (array n) := | ||
@equiv.traversable (flip vector n) _ (λ α, equiv.vector_equiv_array α n) _ | ||
|
||
instance : is_lawful_traversable (array n) := | ||
@equiv.is_lawful_traversable (flip vector n) _ (λ α, equiv.vector_equiv_array α n) _ _ | ||
|
||
end array | ||
|
||
/-- If `α` is encodable, then so is `array n α`. -/ | ||
instance _root_.array.encodable {α} [encodable α] {n} : encodable (array n α) := | ||
encodable.of_equiv _ (equiv.array_equiv_fin _ _) | ||
|
||
/-- If `α` is countable, then so is `array n α`. -/ | ||
instance _root_.array.countable {α} [countable α] {n} : countable (array n α) := | ||
countable.of_equiv _ (equiv.vector_equiv_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