Zulip Chat Archive

Stream: general

Topic: Formalizing Lucas' theorem


Alexander Valentino (Sep 04 2021 at 17:01):

Hi I'm a first-year mathematics undergraduate and I'd like to formalize Lucas' theorem (https://en.wikipedia.org/wiki/Lucas%27s_theorem), and I've completed everything but the inequality world in the natural number game, but I can't find how to define non-base 10 numbers, and easily be able to play around with the indices of products and sums. Where should I look to learn more about how to do such a thing? Is this a relevant thing to prove in Lean and try to get added to mathlib?

Johan Commelin (Sep 04 2021 at 17:07):

I think mathlib has docs#nat.digits which computes digits in some arbitrary base.

Alexander Valentino (Sep 04 2021 at 17:34):

Johan Commelin said:

I think mathlib has docs#nat.digits which computes digits in some arbitrary base.

Thank you, what about manipulating indicies? Or should I be asking this question elsewhere in the new members channel?

Johan Commelin (Sep 04 2021 at 18:02):

No, it's fine to ask it here

Johan Commelin (Sep 04 2021 at 18:02):

@Alexander Valentino What do you mean exactly with "manipulating indices"?

Alexander Valentino (Oct 06 2021 at 17:04):

Hi there, I'm wondering what would I need to grasp from starting with just having completed most of the natural number game to formalizing this theorem, copying the proof via generating functions from Wikipedia (https://en.wikipedia.org/wiki/Lucas%27s_theorem)?

Alex J. Best (Oct 06 2021 at 17:38):

It looks like the first half of the proof can be proved via docs#add_pow_char_pow_of_commute, other than that it would help to get a bit used to the material in https://leanprover-community.github.io/mathlib_docs/algebra/big_operators/basic.html I guess.

Yaël Dillies (Oct 06 2021 at 18:20):

I remember seeing Lucas' theorem or something very close to it... Let me dig again.

Bolton Bailey (Oct 08 2021 at 19:51):

I have been working on this in #8820
Actually, this PR is Lucas' Primality theorem. Perhaps this is what Yaël was thinking of.

Gareth Ma (Nov 24 2023 at 07:52):

Hi, it's been two years, time to fix this :) I proved it here

Gareth Ma (Nov 24 2023 at 07:53):

I only proved the weaker version (nk)(n(modp)k(modp))(n/pk/p)(modp)\binom{n}{k} \equiv \binom{n \pmod{p}}{k \pmod{p}} \binom{n / p}{k / p} \pmod{p} but the full version can be done via induction. Can someone check if my formulation of lucas' is correct, or is there a better way to do it? Johan proposed .digits above but I'm not sure if it's the correct way

Gareth Ma (Nov 24 2023 at 07:55):

And I think sum_ite_iff_eqshould be in Mathlib so that it's more convenient to rewrite sums, but I don't know how to name it

Gareth Ma (Nov 24 2023 at 07:57):

Also the proof is quite slow and I don't know why. Here's profiler trace:

typeclass inference of CoeFun took 181ms
typeclass inference of CoeT took 201ms
typeclass inference of CoeT took 193ms
typeclass inference of CoeT took 184ms
typeclass inference of CoeFun took 164ms
typeclass inference of CoeT took 193ms
typeclass inference of CoeT took 191ms
typeclass inference of CoeT took 190ms
typeclass inference of CoeFun took 169ms
typeclass inference of CoeT took 197ms

Yaël Dillies (Nov 24 2023 at 07:58):

Your second lemma is just docs#ZMod.int_cast_eq_int_cast_iff

Gareth Ma (Nov 24 2023 at 07:59):

Yep, thanks

Moritz Firsching (Nov 24 2023 at 10:19):

your sum_ite_iff_eq can be golfed a little:

lemma sum_ite_iff_eq [DecidableEq α] [AddCommMonoid β]
    {p : α  Prop} [DecidablePred p]
    {f : α  β} {a : α} {s : Finset α}
    (h :  x  s, p x  x = a) :
    ( x in s, if p x then f x else 0) = (if a  s then f a else 0) :=
  (sum_ite_eq' s a f).symm  sum_congr rfl (fun a => fun ha => if_congr (h a ha) rfl rfl)

Gareth Ma (Nov 24 2023 at 12:12):

@Moritz Firsching In that case, you can :curry: the function to fun a ha => too :) Thanks!

Gareth Ma (Nov 24 2023 at 12:14):

https://github.com/grhkm21/lean4/commit/0ec5a46d02a7d89e0e388e6c8ba856642e08304a
Here's the newest version. If someone wants to prove the full version please go ahead, as I will be travelling for the next few days :)
Though I can definitely do it when I come back

Ruben Van de Velde (Nov 24 2023 at 12:48):

Should this go into mathlib? :)

Gareth Ma (Nov 24 2023 at 12:48):

Yeah

Gareth Ma (Nov 24 2023 at 12:49):

But I think there are some other relevant theorems that’s provable

Gareth Ma (Nov 24 2023 at 12:50):

Maybe some generalisations - I remember one for mod p^2 for example, but it’s quite a lot more complicated

Ruben Van de Velde (Nov 24 2023 at 12:50):

Don't let the complete be the enemy of the good

Gareth Ma (Nov 24 2023 at 12:50):

Okay, I will start a draft PR first to force myself to progress :joy:

Gareth Ma (Nov 24 2023 at 14:06):

here we go. I will work on it afterwards, but PRs would be appreciated too :)


Last updated: Dec 20 2023 at 11:08 UTC