Zulip Chat Archive
Stream: Is there code for X?
Topic: factors lemma
Ines Wright (Jul 27 2021 at 17:58):
Is there a lemma that says the list of factors of a prime to a power is the prime, n times?
import data.nat.prime
example {p y : ℕ} [p.prime] : (p ^ y).factors = list.repeat p y :=
begin
sorry,
end
Eric Rodriguez (Jul 27 2021 at 17:59):
this should be in another thread - Zulip can be confusing! but no, should be pretty straightforward though
Eric Rodriguez (Jul 27 2021 at 17:59):
this is docs#nat.factors, right?
Johan Commelin (Jul 27 2021 at 17:59):
@Ines Wright Hi! Would you mind editing your message to change it's topic to a new thread name?
Johan Commelin (Jul 27 2021 at 18:01):
There is docs#nat.factors_prime, but I couldn't find nat.factors_mul
.
Kevin Buzzard (Jul 27 2021 at 18:03):
The problem with nat.factors_mul
is that nat.factors
is a list not a multiset, presumably for CS reasons.
Kevin Buzzard (Jul 27 2021 at 18:04):
So you'd have to state it with ~
rather than =
. I could imagine trying to use FTA to prove it by saying "list.repeat p y has the property that its prod
is p^y so done by FTA" but then you have to prove that if list.repeat p y ~ L
then list.repeat p y = L
. Is this in mathlib?
Kevin Buzzard (Jul 27 2021 at 18:06):
Eric Wieser (Jul 27 2021 at 18:09):
Yakov Pechersky (Jul 27 2021 at 18:10):
Kevin, nat.factors is a list gives you the additional nice property that it is in increasing order.
Kevin Buzzard (Jul 27 2021 at 18:15):
yeah but given a multiset I'm sure any CS person can put it into increasing order if they _want_...
Kevin Buzzard (Jul 27 2021 at 18:16):
and you can see that it screws up nat.factors_mul
;-)
Kevin Buzzard (Jul 27 2021 at 18:17):
More seriously, to a mathematician the "canonical" way of expressing the factors of a natural is as a multiset, because this is precisely the kind of data which can be canonically associated to the natural. When thinking of the factors there's no conceptual reason to include the ordering.
Eric Wieser (Jul 27 2021 at 18:36):
There's also docs#pnat.factor_multiset
Eric Wieser (Jul 27 2021 at 18:37):
Which also fixes the weirdness where factors 1 = factors 0
despite it not being the case that 1 = 0
Eric Rodriguez (Jul 27 2021 at 18:43):
pnat factor multiset is a PITA
Eric Rodriguez (Jul 27 2021 at 18:47):
from having looked at this bit of mathlib lately the best rn is definitely docs#nat.factors_subset_right, but that's miles off
Yaël Dillies (Jul 27 2021 at 18:58):
All this pnat
part of mathlib has been written a few years and is never used anywhere. Parts of it are poorly written and others are redundant with more general stuff. That's my take. But yeah I guess you can use it and give it some love.
Yaël Dillies (Jul 27 2021 at 19:00):
See #7960 for a more thorough explanation of mine.
Yakov Pechersky (Jul 27 2021 at 19:17):
We can redefine factors as the multiset via quotient.mk, and retain the original as factors_list
Yakov Pechersky (Jul 27 2021 at 19:18):
We don't have a multiset.repeat?
Eric Rodriguez (Jul 27 2021 at 19:24):
i think the smul
is repeat, basically
Eric Rodriguez (Jul 27 2021 at 19:24):
no clue where it's defined, though
Eric Rodriguez (Jul 27 2021 at 19:28):
yep:
import data.multiset
def asdg : multiset ℕ := 4 • (quotient.mk $ [1,2,3,4])
#reduce asdg
-- quot.mk list.perm [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
Eric Rodriguez (Jul 27 2021 at 19:36):
it's just the default smul, which makes a lot of sense as add is just appending two multisets
Ruben Van de Velde (Jul 27 2021 at 19:44):
There's also docs#multiset.repeat
Eric Rodriguez (Jul 27 2021 at 19:56):
sadly they're not defeq, but probably a lemma that should be in mathlib
:
lemma asda {α : Type*} (a : α) : ∀ n, multiset.repeat a n = n • {a}
| 0 := rfl
| (n + 1) := by simp [asda n, succ_nsmul]
Kevin Buzzard (Jul 30 2021 at 18:02):
lemma foo (p y : ℕ) [hp : p.prime] : (p ^ y).factors = list.repeat p y := sorry
I have a proof -- but did we yet decide on whether this lemmas is called factors_pow_prime
or prime_pow_factors
or what?
Adam Topaz (Jul 30 2021 at 18:35):
prime_pow_factors
sounds good to me!
Mario Carneiro (Jul 30 2021 at 18:36):
I would go with prime.factors_pow
where hp
is explicit
Last updated: Dec 20 2023 at 11:08 UTC