Zulip Chat Archive

Stream: new members

Topic: upcast `Finset (Fin n)` to `Finset (Fin n.succ)`


Becker A. (Dec 17 2025 at 20:34):

how would I fill this out?

import Mathlib.Data.Finset.Defs

def Finset_Fin_succ
  {n : }
  (s : Finset (Fin n))
  : Finset (Fin (n + 1))
  := by sorry

Riccardo Brasca (Dec 17 2025 at 20:36):

You can use Fin.castSucc and Finset.image

Riccardo Brasca (Dec 17 2025 at 20:36):

(assuming that what you want to do is the "obvious" construction")

Becker A. (Dec 17 2025 at 20:40):

great, I got this:

def Finset_Fin_succ
  {n : }
  (s : Finset (Fin n))
  : Finset (Fin (n + 1))
  := by exact Finset.image Fin.castSucc s

thanks!

Kevin Buzzard (Dec 17 2025 at 20:52):

@Becker A. FWIW typically in Lean files : and := are on the end of the line, not the beginning, and the usual style is indent 4 not 2 before :=, so e.g.

def Finset_Fin_succ
    {n : }
    (s : Finset (Fin n)) :
    Finset (Fin (n + 1)) := by
  exact Finset.image Fin.castSucc s

although in mathlib we would probably write

def Finset_Fin_succ {n : } (s : Finset (Fin n)) : Finset (Fin (n + 1)) :=
  Finset.image Fin.castSucc s

Becker A. (Dec 17 2025 at 20:54):

thanks. speaking of, do you know if there's an autoformatter for Lean4 in VSCode?

Kevin Buzzard (Dec 17 2025 at 20:57):

This is a great question and I think that right now the answer is "not yet". You could ask about the status in #lean4 . (or just search this Zulip)

Eric Wieser (Dec 17 2025 at 21:03):

You could also use docs#Finset.map to get a faster implementation

Becker A. (Dec 17 2025 at 21:09):

okay. tried it, getting errors. how do I compose an embedding?

def Finset_Fin_succ
  {n : }
  (s : Finset (Fin n))
  : Finset (Fin (n + 1))
  := by
  apply Finset.map ?_ s
  sorry

Becker A. (Dec 17 2025 at 21:11):

edit: got it I think:

def Finset_Fin_succ
  {n : }
  (s : Finset (Fin n))
  : Finset (Fin (n + 1))
  := by
  apply Finset.map ?_ s
  exact Fin.castAddEmb 1

-> how is this better again, it compiles faster?

Eric Wieser (Dec 17 2025 at 21:13):

It #evals faster

Eric Wieser (Dec 17 2025 at 21:13):

map is O(n)O(n), image is O(n2)O(n^2)

Eric Wieser (Dec 17 2025 at 21:14):

Of course really you want this to be O(1) since this is a no-op computationally


Last updated: Dec 20 2025 at 21:32 UTC