/-
Copyright 2026 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.Nth
public import Mathlib.NumberTheory.Divisors@[expose] public sectionThe increasing enumeration of the divisors of a natural number
Basic facts about Nat.nth (· ∈ n.divisors), the increasing enumeration of the divisors of n.
namespace Nat
The smallest divisor of a positive number is 1, i.e. the 0th entry of the increasing
enumeration of its divisors.
n:ℕhn:n ≠ 0⊢ sInf {x | x ∈ n.divisors} = 1
exact IsLeast.csInf_eq ⟨Nat.one_mem_divisors.mpr hn, fun y hy => Nat.pos_of_mem_divisors hy⟩ All goals completed! 🐙
Every divisor enumerated after index 0 is at least 2.
lemma two_le_nth_divisors {n : ℕ} (hn : n ≠ 0) {i : ℕ} (hi : i ≠ 0)
(h : Nat.nth (· ∈ n.divisors) i ≠ 0) : 2 ≤ Nat.nth (· ∈ n.divisors) i := by n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i
have hfin : (Set.ofPred (· ∈ n.divisors)).Finite := n.divisors.finite_toSet n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finite⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i
have hpos : 1 ≤ Nat.nth (· ∈ n.divisors) i := Nat.pos_of_mem_divisors (Nat.nth_mem_of_ne_zero h) n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) i⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i
rcases hpos.lt_or_eq with h2 | h1 inl n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih2:1 < nth (fun x ↦ x ∈ n.divisors) i⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) iinr n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i
· inl n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih2:1 < nth (fun x ↦ x ∈ n.divisors) i⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i omega All goals completed! 🐙
· inr n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i exact absurd (Nat.nth_injOn hfin
(Set.mem_Iio.mpr (Nat.lt_card_toFinset_of_nth_ne_zero h hfin))
(Set.mem_Iio.mpr (Nat.lt_card_toFinset_of_nth_ne_zero
(show Nat.nth (· ∈ n.divisors) 0 ≠ 0 by n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0⊢ 2 ≤ nth (fun x ↦ x ∈ n.divisors) i rw [nth_divisors_zero hn n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ 1 ≠ 0 n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ 1 ≠ 0] n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ 1 ≠ 0; omega All goals completed! 🐙) hfin))
(by n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ nth (fun x ↦ x ∈ n.divisors) i = nth (fun x ↦ x ∈ n.divisors) 0 rw [nth_divisors_zero hn n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ nth (fun x ↦ x ∈ n.divisors) i = 1 n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ nth (fun x ↦ x ∈ n.divisors) i = 1] n:ℕhn:n ≠ 0i:ℕhi:i ≠ 0h:nth (fun x ↦ x ∈ n.divisors) i ≠ 0hfin:{x | x ∈ n.divisors}.Finitehpos:1 ≤ nth (fun x ↦ x ∈ n.divisors) ih1:1 = nth (fun x ↦ x ∈ n.divisors) i⊢ nth (fun x ↦ x ∈ n.divisors) i = 1; omega All goals completed! 🐙)) hiend Nat