Zulip Chat Archive
Stream: new members
Topic: Casting List to Vector
Benjamin (Dec 28 2024 at 16:17):
How can I cast a term of type List α to type Vector α n?
Ilmārs Cīrulis (Dec 28 2024 at 16:22):
My approach would be this.
import Mathlib
def ListToVector {α: Type} (L: List α): Vector α L.length :=
{ toList := L, size_toArray := rfl }
Ilmārs Cīrulis (Dec 28 2024 at 16:22):
(I'm beginner.)
Ilmārs Cīrulis (Dec 28 2024 at 16:24):
Edited by simp
to rfl
.
Eric Wieser (Dec 28 2024 at 16:45):
Alternatively you could use docs#List.Vector
Benjamin (Dec 28 2024 at 16:52):
Eric Wieser said:
Alternatively you could use docs#List.Vector
Is this a different Vector than Init.Data.Vector?
Benjamin (Dec 28 2024 at 16:52):
What I'm really trying to do is transpose a vector of vectors (i.e., go from Vector (Vector α n) m
to Vector (Vector α m) n
). I thought that the easiest way to do this would be to leverage the existing List.transpose function. But that doesn't seem to give me the necessary information to prove that the resulting lists are of the desired lengths. Is there an easier approach?
Daniel Weber (Dec 28 2024 at 17:06):
I have code for that, let me find it
Daniel Weber (Dec 28 2024 at 17:08):
Matt Diamond (Dec 28 2024 at 20:26):
would it be easier to just use Matrix
to represent a vector of vectors? docs#Matrix.transpose already exists
Last updated: May 02 2025 at 03:31 UTC