/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import Mathlib.Data.Nat.Squarefree public import FormalConjecturesForMathlib.Data.Nat.Factorization.Basic public meta import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic@[expose] public sectionnamespace Nat

n.squarefreePart is the unique a₀ : ℕ such that a₀ is squarefree and n = a₀ * b ^ 2, for some b : ℕ. At 0 this property is not well defined because b must be 0 and a₀ can be any squarefree number; we give the junk value 1 at n = 0 following the convention that the squarefree part of any square is 1.

def squarefreePart (n : ) : := n.factorization.prod fun (p e : ) p ^ (e % 2)example : squarefreePart 2 = 2 := squarefreePart 2 = 2 All goals completed! 🐙example : squarefreePart 5 = 5 := squarefreePart 5 = 5 All goals completed! 🐙example : squarefreePart 4 = 1 := squarefreePart 4 = 1 All goals completed! 🐙example : squarefreePart 8 = 2 := squarefreePart 8 = 2 All goals completed! 🐙example : squarefreePart 16 = 1 := squarefreePart 16 = 1 All goals completed! 🐙example : squarefreePart 24 = 6 := squarefreePart 24 = 6 All goals completed! 🐙theorem squarefreePart_ne_zero (n : ) : n.squarefreePart 0 := n:n.squarefreePart 0 All goals completed! 🐙theorem squarefreePart_zero : squarefreePart 0 = 1 := squarefreePart 0 = 1 All goals completed! 🐙

If n is squarefree, then its squarefree part is itself.

All goals completed! 🐙

The squarefree part of any square is 1.

r:h₀:¬r = 0 p (r * r).primeFactors, p ^ ((r.factorization + r.factorization) p % 2) = 1 All goals completed! 🐙

If $n = \prod_p p^{e_p}$ is the prime factorization of $n$, then $\prod_p p^{e_p \pmod{2}}$ is the prime factorization of the squarefree part of $n$.

All goals completed! 🐙theorem Prime.squarefree {p : } (hp : p.Prime) : Squarefree p := Irreducible.squarefree hptheorem squarefree_squarefreePart (n : ) : Squarefree n.squarefreePart := n:Squarefree n.squarefreePart n:p:n.squarefreePart.factorization p 1 n:p:hp:Prime pn.squarefreePart.factorization p 1n:p:hp:¬Prime pn.squarefreePart.factorization p 1 n:p:hp:Prime pn.squarefreePart.factorization p 1 All goals completed! 🐙 n:p:hp:¬Prime pn.squarefreePart.factorization p 1 All goals completed! 🐙theorem squarefreePart_dvd (n : ) : squarefreePart n n := n:n.squarefreePart n squarefreePart 0 0n:h₀:n 0n.squarefreePart n; n:h₀:n 0n.squarefreePart n All goals completed! 🐙

The square part is the value of b ^ 2 in the squarefree decomposition of n = a₀ * b ^ 2.

def squarePart (n : ) : := n / n.squarefreeParttheorem squarePart_zero : squarePart 0 = 0 := squarePart 0 = 0 All goals completed! 🐙

The squarefree decomposition of a natural number.

theorem squarefreePart_mul_squarePart (n : ) : n.squarefreePart * n.squarePart = n := Nat.mul_div_eq_iff_dvd.2 n.squarefreePart_dvdtheorem squarefree_infinite : Set.Infinite { n : | Squarefree n } := Set.Infinite.mono (fun _ hp hp.squarefree) Nat.infinite_setOfPred_primeend Nat