Zulip Chat Archive

Stream: Is there code for X?

Topic: List of consequtive Fin like List.Ico


Naruyoko (Jun 30 2024 at 15:25):

docs#List.Ico gives a list of consecutive naturals. Given a ≤ b ≤ c, is there an equivalent to List.Ico a b but with type List (Fin c)?

Eric Wieser (Jun 30 2024 at 15:28):

You can use Finset.Ico, but obviously that won't be a list:

import Mathlib

-- {1, 2, 3}
#eval Finset.Ico (1 : Fin 5) (9 : Fin 5)

Edward van de Meent (Jun 30 2024 at 15:35):

docs#List.finRange is a thing, you can probably start looking there...

Edward van de Meent (Jun 30 2024 at 15:37):

@loogle |- List (Fin ?_)

loogle (Jun 30 2024 at 15:37):

:search: Fin.list, List.finRange

Edward van de Meent (Jun 30 2024 at 15:37):

it would appear that's about everything we have...

Edward van de Meent (Jun 30 2024 at 15:38):

but you could certainly take inspiration from their definitions to make what you need

Eric Wieser (Jun 30 2024 at 15:45):

I guess you also need to watch out for the case when b = c, since then (b : Fin c) = 0

Naruyoko (Jun 30 2024 at 15:56):

The definition of docs#List.finRange looks promising.

Naruyoko (Jun 30 2024 at 16:25):

I got the following:

import Mathlib.Data.List.Intervals

def finIco {k : } (m n : Fin (k + 1)) : List (Fin k) :=
  (List.Ico m n).pmap Fin.mk fun _ h =>
    Nat.lt_of_lt_of_le (List.Ico.mem.mp h).right (Nat.le_of_lt_succ n.isLt)

#reduce finIco (k := 3) 0 2
#reduce finIco (k := 3) 1 3
#reduce finIco (k := 3) 2 2
#reduce finIco (k := 3) 3 2

Last updated: May 02 2025 at 03:31 UTC