Zulip Chat Archive

Stream: new members

Topic: Fintype (X → Y) from Fintype X and Fintype Y?


Yannick Seurin (Oct 13 2025 at 11:33):

It does not seem possible to infer Fintype (X → Y) from Fintype X and Fintype Y but I'm struggling to see why and what extra assumptions I would need...

import Mathlib

variable (X Y : Type*) [Fintype X] [Fintype Y]

instance : Fintype (X × Y) := inferInstance -- works

instance : Fintype (Bool  Fin 5) := inferInstance -- works

instance : Fintype (X  Y) := inferInstance -- failed to synthesize Fintype (X → Y)

Kenny Lau (Oct 13 2025 at 11:34):

@Yannick Seurin you're looking for Pi.instFintype, and you need X to be discrete

Kenny Lau (Oct 13 2025 at 11:35):

but actually i don't see why you would need that...

Yannick Seurin (Oct 13 2025 at 11:39):

I'd like to define the uniform distribution on the space of functions from X to Y using PMF.uniformOfFintype

Kenny Lau (Oct 13 2025 at 11:39):

@Yannick Seurin well, do you care about making things computable, and why?

Kenny Lau (Oct 13 2025 at 11:40):

because classically you can just assume that every type is discrete

Kenny Lau (Oct 13 2025 at 11:41):

Kenny Lau said:

but actually i don't see why you would need that...

actually I think I see it now, let's say you have X = {a1, a2} and Y = {b1, b2}, now you want to build 4 functions X -> Y, so let's say the first function sends a1 to b1 and a2 to b2... oh wait, how do you decide if the given input is a1 or a2?

Kenny Lau (Oct 13 2025 at 11:42):

@Yannick Seurin but all this detail is unnecessary, we've decided long ago in mathlib that we don't care about computability, we would just classically assume everything is decidable and move on with our lives

Yannick Seurin (Oct 13 2025 at 11:42):

Hm, no I don't care about computability. Does that mean I can work with [Finite X] and [Finite Y]?

Riccardo Brasca (Oct 13 2025 at 11:42):

@Yannick Seurin if your goal is to do mathematics you may prefer to use Finite instead of Fintype

Kenny Lau (Oct 13 2025 at 11:42):

and Nat.card instead of Fintype.card

Kenny Lau (Oct 13 2025 at 11:43):

and put have := Classical.propDecidable everywhere

Yannick Seurin (Oct 13 2025 at 11:43):

I see thanks! (I'm still a bit confused about using Finset vs. Finite)

Kenny Lau (Oct 13 2025 at 11:43):

Finset X is the type of finite sets on X

Kenny Lau (Oct 13 2025 at 11:43):

Finite X is the prop saying that X is a finite type

Kenny Lau (Oct 13 2025 at 11:44):

so e.g. {5, 7, 10} : Finset Nat

Kenny Lau (Oct 13 2025 at 11:44):

and there's nothing in Finite Nat because that's not a true statement

Yannick Seurin (Oct 13 2025 at 11:44):

Sorry, I meant "I'm still a bit confused about using Fintype vs. Finite"

Kenny Lau (Oct 13 2025 at 11:45):

some functions in the library require Fintype because they were set up differently

Kenny Lau (Oct 13 2025 at 11:45):

but we're slowly getting rid of them and replacing them all with Finite

Kenny Lau (Oct 13 2025 at 11:45):

but if you do need to use one then you can either 1. assume Fintype anyway, or 2. make that instance classically using FIntype.ofFinite

Yannick Seurin (Oct 13 2025 at 11:47):

I'll go with Finite then! Thanks!

Aaron Liu (Oct 13 2025 at 12:08):

Kenny Lau said:

but actually i don't see why you would need that...

why not

Aaron Liu (Oct 13 2025 at 12:09):

Kenny Lau said:

but we're slowly getting rid of them and replacing them all with Finite

I would hope not

Robert Maxton (Oct 15 2025 at 05:52):

It's still nice to be able to prove things by exhaustive checking sometimes!


Last updated: Dec 20 2025 at 21:32 UTC