File size: 3,208 Bytes
8ca48d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/-
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.Algebra.Order.Ring.Nat
public import Mathlib.Algebra.Order.Star.Basic
public import Mathlib.Data.Nat.PrimeFin
public meta import Mathlib.Data.Nat.PrimeFin

@[expose] public section

namespace Nat

/--
A natural number $n$ is said to be $k$-full (or $k$-powerful) if for every prime factor $p$ of $n$,
the $k$-th power $p^k$ also divides $n$.
-/
def Full (k : ℕ) (n : ℕ) : Prop := ∀ p ∈ n.primeFactors, p^k ∣ n

instance Full.decide : ∀ k n, Decidable (Full k n) := by
  intro k n
  dsimp [Full]
  infer_instance

/-- Every natural number is $0$-full. -/
theorem Full.zero_left (n : ℕ) : (0 : ℕ).Full n := by
  simp [Nat.Full]

/-- Every natural number is $1$-full. -/
theorem Full.one_left (n : ℕ) : (1 : ℕ).Full n := by
  aesop (add simp [Nat.Full])

/-- $0$ is always $k$-full. -/
theorem Full.zero_right (k : ℕ) : k.Full 0 := by
  simp [Nat.Full]

/-- $1$ is always $k$-full. -/
theorem Full.one_right (k : ℕ) : k.Full 1 := by
  simp [Nat.Full]

/--
A [Powerful number](https://en.wikipedia.org/wiki/Powerful_number) is a natural number $n$ where
for every prime divisor $p$, $p^2$ divides $n$.
Powerful numbers are also known as "squareful", "square-full", or "$2$-full".
-/
abbrev Powerful : ℕ → Prop := (2).Full

instance Powerful.decide : ∀ n, Decidable (Powerful n) := by
  intro n
  dsimp [Powerful, Full]
  apply Finset.decidableDforallFinset

theorem full_of_le_full (k : ℕ) (n : ℕ) {m : ℕ} (hk : k ≤ m) (h : m.Full n) : k.Full n :=
  fun p a ↦ pow_dvd_of_le_of_pow_dvd hk (h p a)

/-- If $n \equiv p \pmod{p ^ (k + 1)}$, for a prime $p$ then $n$ is not $(k + 1)$-full. -/
theorem not_full_of_prime_mod_prime_sq (n : ℕ) (k : ℕ) {p : ℕ} (hp : p.Prime)
    (h : n % p ^ (k + 1) = p) : ¬ (k + 1).Full n := by
  rw [Full]
  push Not
  use p
  simp [mem_primeFactors, hp, ne_eq, true_and]
  constructor
  · rw [←Nat.div_add_mod n (p ^ (k + 1)), h]
    have : p ∣ p ^ (k + 1) := by exact Dvd.intro_left (p.pow k) rfl
    simp
    exact ⟨Dvd.dvd.mul_right this (n / p ^ (k + 1)), fun a ↦ Prime.ne_zero hp⟩
  · intro h
    simp_all [Nat.dvd_iff_mod_eq_zero.mp h]
    aesop


open Lean Meta Qq in
/-- Simproc to compute the set `Nat.primeFactors`. -/
dsimproc primeFactorsEq (Nat.primeFactors _) := fun e ↦ do
  unless e.isAppOfArity `Nat.primeFactors 1 do return .continue
  let some n ← Lean.Nat.fromExpr? e.appArg! | return .continue
  let outAsList : List Q(ℕ) := (unsafe n.primeFactors.val.unquot).map mkNatLit
  let outAsFinset : Q(Finset ℕ) := outAsList.foldl (fun s n ↦ q(insert $n $s)) q({})
  return .done outAsFinset