Zulip Chat Archive

Stream: mathlib4

Topic: toFinsetFactors


Arend Mellendijk (Sep 14 2023 at 19:16):

The current idiom for "the finset of prime factors of n:Nat" is n.factors.toFinset. (n.factors is a list). @Johan Commelin pointed out that this set should probably have a name. I tend to agree. What should it be called?

Arend Mellendijk (Sep 14 2023 at 19:16):

/poll What should we call this set?

Arend Mellendijk (Sep 14 2023 at 19:18):

For reference:
@loogle Nat.factors, List.toFinset

loogle (Sep 14 2023 at 19:18):

:exclamation: <input>:1:13: expected end of input

Arend Mellendijk (Sep 14 2023 at 19:20):

@loogle Nat.factors, List.toFinset

loogle (Sep 14 2023 at 19:20):

:search: Nat.prime_divisors_eq_to_filter_divisors_prime, Nat.factors_mul_toFinset, and 13 more

Antoine Chambert-Loir (Sep 14 2023 at 19:32):

FactorsFinset

Eric Wieser (Sep 14 2023 at 19:39):

I'd be tempted to make this an abbrev so that it doesn't cost anything

Adam Topaz (Sep 14 2023 at 19:46):

I added n.support as an option, but maybe that's not too intuitive for most people.

Adam Topaz (Sep 14 2023 at 19:46):

note that support should also makes sense for (nonzero) rational numbers.

Eric Rodriguez (Sep 14 2023 at 20:02):

docs#Nat.factorization.support

Eric Rodriguez (Sep 14 2023 at 20:02):

whatever it is I think should be an abbrev of factorization.support

Eric Wieser (Sep 14 2023 at 20:03):

(docs#Nat.factorization, docs#Finsupp.support)

Arend Mellendijk (Sep 14 2023 at 20:10):

I just noticed docs#Nat.support_factorization is a simp lemma, suggesting n.factors.toFinset is currently the canonical spelling.

Arend Mellendijk (Sep 14 2023 at 20:12):

Either way, the fact that there are two very natural ways of expressing this concept makes me think this should be a def rather than an abbreviation.

Eric Rodriguez (Sep 14 2023 at 20:15):

But I think it's nice to apply stuff about finsupps - there was some good work put into the factorization stuff

Arend Mellendijk (Sep 22 2023 at 13:26):

If we're going with an abbreviation I'd like to consider what we want simp to do with p ∈ n.primeDivisors. Currently:

import Mathlib.Data.Nat.Factorization.Basic

abbrev primeDivisors (n : ) : Finset  := n.factorization.support

example (n p : ) (h : p  n.primeDivisors) : True := by
  simp at h
  /- h : p ∈ factors n -/
  trivial

/- And if we remove simp from support_factorization: -/
attribute [-simp] Nat.support_factorization
example (n p : ) (h : p  n.primeDivisors) : True := by
  simp at h
  /- h : ¬↑(factorization n) p = 0 -/
  trivial

I'd argue it would be much more natural to have a simp lemma like docs#Nat.mem_divisors that produces p.Prime ∧ p ∣ n ∧ n ≠ 0, but we can't do that with an abbreviation since simp could apply more general results like docs#List.mem_toFinset or docs#Finsupp.mem_support_iff first.

Arend Mellendijk (Oct 10 2023 at 15:25):

I've opened a #7607, which makes n.primeDivisorsan abbreviation for n.factorization.support and attempts to make it into the canonical spelling throughout mathlib. (that includes removing simp from support_factorization)


Last updated: Dec 20 2023 at 11:08 UTC