Zulip Chat Archive

Stream: Is there code for X?

Topic: Extract some element from a chained Product.


Asei Inoue (Apr 21 2024 at 12:56):

This is probably a question that has already been answered somewhere, but I could not find it.

def sample : Nat × Nat × Nat × Nat := (0, 1, 2, 3)

-- I want `2` from `(0, 1, 2, 3)`!

-- this does not work
#check_failure sample.3

-- this does not work
#check_failure sample[2]

Mario Carneiro (Apr 21 2024 at 13:31):

tuples are right-associative nested, there is no such thing as an n-ary tuple in lean

Mario Carneiro (Apr 21 2024 at 13:32):

so to get at the 2 in (0, 1, 2, 3) (which is really (0, (1, (2, 3)))) you should use sample.2.2.1

Asei Inoue (Apr 21 2024 at 14:11):

I think this API is inconvenient. Why not make it easier to access the nth in a chain of Prods?

Andrew Yang (Apr 21 2024 at 14:17):

Because we usually use Fin 4 -> Nat instead. There is the nice notation ![0, 1, 2, 3] for this.

Asei Inoue (Apr 21 2024 at 14:18):

oh thanks

Asei Inoue (Apr 21 2024 at 14:22):

where is ![]defined?

Adam Topaz (Apr 21 2024 at 14:36):

Mathlib.Data.Matrix.Notation I think

Matt Diamond (Apr 22 2024 at 01:10):

@Asei Inoue I think the ![] notation for Tuples is specifically defined in Mathlib.Data.Fin.VecNotation

Matt Diamond (Apr 22 2024 at 01:14):

there's also a lot of helper functions for Tuples in Mathlib.Data.Fin.Tuple.Basic and siblings, if you ever need to do something complex


Last updated: May 02 2025 at 03:31 UTC