Zulip Chat Archive

Stream: mathlib4

Topic: a noncomputable def of Fintype


Yongle Hu (Oct 22 2024 at 07:16):

I found that FiniteDimensional.fintypeOfFintype is a noncomputable def of Fintype. My understanding is that Fintype should only be used in cases where it is computable in the reduction or #eval sense, so this definition might be bad. Should we deprecate this definition?

Yongle Hu (Oct 22 2024 at 07:25):

For example, FiniteDimensional.fintypeOfFintype is used to prove that GaloisField is Fintype, but we cannot calculate the number of elements in GaloisField 3 3 using #eval.

import Mathlib

#eval Fintype.card (GaloisField 3 3)

Eric Wieser (Oct 22 2024 at 07:47):

It's definitely tempting to change it to Finite

Eric Wieser (Oct 22 2024 at 07:48):

But I think that Fintype.card (GaloisField 3 3) should remain legal, and the fact it doesn't #eval is unfortunate but not a reason to disable the Fintype instance.

Edward van de Meent (Oct 22 2024 at 07:53):

The fact that it doesn't fin_cases might be?

Ruben Van de Velde (Oct 22 2024 at 08:27):

Why not Nat.card?

Yongle Hu (Oct 22 2024 at 10:27):

I think it is better to replace Fintype.card with Nat.card in the theorems about GaloisField (for example, GaloisField.algEquivGaloisField).

Eric Wieser (Oct 22 2024 at 10:45):

Edward van de Meent said:

The fact that it doesn't fin_cases might be?

fin_cases behaves poorly with many types

Kyle Miller (Oct 22 2024 at 17:27):

I think it makes sense turning these into theorems that prove Finite.

At least FiniteDimensional.fintypeOfFintype isn't an instance. Noncomputable fintype instances are bad because they can cause things to become noncomputable. The point of Fintype over Finite is that you can (at least in theory) compute with it.

I'd strongly suggested turning the noncomputable GaloisField Fintype instance into a Finite one because of this. If somehow a Fintype instance is still useful, at least it should be scoped.

Yongle Hu (Oct 23 2024 at 05:05):

I find it is a little difficult to replace Fintype.card with Nat.card in the theorems related to GaloisField, because many theorems used in the proof (such as FiniteField.roots_X_pow_card_sub_X, Polynomial.card_rootSet_eq_natDegree, Module.card_fintype) only have versions for Fintype.card and do not have versions for Nat.card.

Kyle Miller (Oct 23 2024 at 05:09):

Can you use something like docs#Fintype.ofFinite to connect up the theories? You can do things like have := Fintype.ofFinite ty to temporarily introduce Fintype instances.

Yongle Hu (Oct 23 2024 at 05:17):

I think I can temporarily write a private instance of Fintype (GaloisField p n), and then use Nat.card_eq_fintype_card to relate Nat.card and Fintype.card. But I think it may be necessary to add Nat.card versions of those theorems in the future.

Yongle Hu (Oct 23 2024 at 09:43):

Opened #18106.


Last updated: May 02 2025 at 03:31 UTC