Zulip Chat Archive

Stream: mathlib4

Topic: Computing `Nat.primeFactors`


Jeremy Tan (Feb 14 2026 at 00:18):

Why can't I use decide or norm_num to compute Nat.primeFactors?

import Mathlib.RingTheory.Radical

/-- The radical of a natural number is the product of its prime factors.
This is computable, unlike `UniqueFactorizationMonoid.radical`. -/
def Nat.radical (n : ) :  :=
   p  n.primeFactors, p

lemma radical_899 : Nat.radical 899 = 899 := by
  decide -- fails

Julian Berman (Feb 14 2026 at 00:19):

I think #Is there code for X? > Compute Nat.primeFactors has some prior discussion

Jeremy Tan (Feb 14 2026 at 00:23):

Ah, yes

import Mathlib.RingTheory.Radical
import Mathlib.Tactic.Simproc.Factors

/-- The radical of a natural number is the product of its prime factors.
This is computable, unlike `UniqueFactorizationMonoid.radical`. -/
def Nat.radical (n : ) :  :=
   p  n.primeFactors, p

lemma yyy : Nat.radical 899 = 899 := by
  simp only [Nat.radical, Nat.primeFactors, Nat.primeFactorsList_ofNat]
  norm_num

Miyahara Kō (Feb 14 2026 at 03:59):

It's because Nat.primeFactorsList & Nat.minFacAux are irreducible.
with_unfolding_all resolves this:

lemma radical_899 : Nat.radical 899 = 899 := by
  with_unfolding_all decide

Joachim Breitner (Feb 14 2026 at 10:40):

Since https://github.com/leanprover/lean4/pull/7965 has landed, it would be reasonable for Mathlib to make Nat.primeFactorsList and Nat.minFacAux to be reducible again, so that decide works fine.


Last updated: Feb 28 2026 at 14:05 UTC