Mode of #cas

divisors

The divisors of a positive integer below 1012 in increasing order, with a theorem about Mathlib’s Nat.divisors.

#cas [divisors] n
lists the divisors of the positive integer n in increasing order, and proves Nat.divisors n = {d₁, …, dₖ}.

divisors lists the divisors themselves, which is what you want for checking a perfect number, an amicable pair or a claim about Nat.divisors n. The proof does not factor n. The kernel pairs each divisor d≤n with its cofactor n/d and counts the small ones with ⌊n⌋ divisions, so the time depends on the size of n and not on its factors.

Details and Options

  • n is a natural number with 1≤n<1012: a literal such as 360, or a closed integer expression such as (2^10 - 1).
  • The theorem is Nat.divisors n = {d₁, …, dₖ}, an equation in Finset ℕ about Mathlib’s Nat.divisors.
  • The proof is a counting certificate (CAS.NumberTheory.divisors_eq_of_cert). With m=⌊n⌋, the kernel checks that the listed divisors up to m divide n and are as many as the d≤m with d∣n, and that the others are their cofactors n/d. Below 1012 this takes at most a million divisions.
  • The report prints the divisors in increasing order. A number below 1012 has at most 6720 of them.
  • There are no options. divisorSigma gives the number and the sums of powers of the divisors from the same certificate, without the list.

Examples (12)#

Basic Examples (2)

The divisors of 12:

In[1]:=
#cas [divisors] 12
Out[1]=

divisors

[1, 2, 3, 4, 6, 12]
[1, 2, 3, 4, 6, 12]
Domain
ℕ
Input (natural numbers)
12

Checked by Lean’s kernel: divisors

Nat.divisors 12 = {1, 2, 3, 4, 6, 12}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 12 = {1, 2, 3, 4, 6, 12}

    Checked by Lean’s kernel


The 24 divisors of 360=23·32·5:

In[2]:=
#cas [divisors] 360
Out[2]=

divisors

[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360]
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360]
Domain
ℕ
Input (natural numbers)
360

Checked by Lean’s kernel: divisors

Nat.divisors 360 =
  {1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 360 =
      {1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360}

    Checked by Lean’s kernel

Scope (3)

A prime has only the divisors 1 and itself:

In[3]:=
#cas [divisors] 97
Out[3]=

divisors

[1, 97]
[1, 97]
Domain
ℕ
Input (natural numbers)
97

Checked by Lean’s kernel: divisors

Nat.divisors 97 = {1, 97}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 97 = {1, 97}

    Checked by Lean’s kernel


A closed expression, here the Mersenne number 210−1=3·11·31:

In[4]:=
#cas [divisors] (2^10 - 1)
Out[4]=

divisors

[1, 3, 11, 31, 33, 93, 341, 1023]
[1, 3, 11, 31, 33, 93, 341, 1023]
Domain
ℕ
Input (natural numbers)
1023

Checked by Lean’s kernel: divisors

Nat.divisors 1023 = {1, 3, 11, 31, 33, 93, 341, 1023}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 1023 = {1, 3, 11, 31, 33, 93, 341, 1023}

    Checked by Lean’s kernel


A million is 26·56, so it has 7·7=49 divisors. The kernel checks them with 1000 divisions:

In[5]:=
#cas [divisors] 1000000
Out[5]=

divisors

[1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 625, 800, 1000, 1250, 1600, 2000, 2500, 3125, 4000, 5000, 6250, 8000, 10000, 12500, 15625, 20000, 25000, 31250, 40000, 50000, 62500, 100000, 125000, 200000, 250000, 500000, 1000000]
[1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 625, 800, 1000, 1250, 1600, 2000, 2500, 3125, 4000, 5000, 6250, 8000, 10000, 12500, 15625, 20000, 25000, 31250, 40000, 50000, 62500, 100000, 125000, 200000, 250000, 500000, 1000000]
Domain
ℕ
Input (natural numbers)
1000000

Checked by Lean’s kernel: divisors

Nat.divisors 1000000 =
  {1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 625, 800, 1000,
    1250, 1600, 2000, 2500, 3125, 4000, 5000, 6250, 8000, 10000, 12500, 15625, 20000, 25000, 31250, 40000,
    50000, 62500, 100000, 125000, 200000, 250000, 500000, 1000000}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 1000000 =
      {1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 625, 800, 1000,
        1250, 1600, 2000, 2500, 3125, 4000, 5000, 6250, 8000, 10000, 12500, 15625, 20000, 25000, 31250, 40000,
        50000, 62500, 100000, 125000, 200000, 250000, 500000, 1000000}

    Checked by Lean’s kernel

Applications (2)

The theorem. Only the three standard axioms are used:

In[6]:=
theorem divisors_twelve : Nat.divisors 12 = {1, 2, 3, 4, 6, 12} := by
  cas

#print axioms divisors_twelve
Out[6]=

divisors_twelve depends on the axioms propext, Classical.choice, Quot.sound.


A number is perfect when its divisors other than itself add up to it, so that σ1(n)=2n. For 8128=26·127 the sum is 16256:

In[7]:=
#cas [divisors] 8128
Out[7]=

divisors

[1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064, 8128]
[1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064, 8128]
Domain
ℕ
Input (natural numbers)
8128

Checked by Lean’s kernel: divisors

Nat.divisors 8128 = {1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064, 8128}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 8128 = {1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064, 8128}

    Checked by Lean’s kernel

In[8]:=
#cas (divisorSigma 1 8128)
Out[8]=

divisorSigma 1

16256
Domain
ℕ
Input (natural numbers)
8128

Checked by Lean’s kernel: divisorSigma 1

(ArithmeticFunction.sigma 1) 8128 = 16256
The certificate: 1 checked step
  1. divisorSigma 1

    (ArithmeticFunction.sigma 1) 8128 = 16256

    Checked by Lean’s kernel

Properties and Relations (2)

divisorSigma gives the number of divisors, σ0(360)=24, and their sum, σ1(360)=1170, without the list:

In[9]:=
#cas (divisorSigma 0 360)
Out[9]=

divisorSigma 0

24
Domain
ℕ
Input (natural numbers)
360

Checked by Lean’s kernel: divisorSigma 0

(ArithmeticFunction.sigma 0) 360 = 24
The certificate: 1 checked step
  1. divisorSigma 0

    (ArithmeticFunction.sigma 0) 360 = 24

    Checked by Lean’s kernel

In[10]:=
#cas (divisorSigma 1 360)
Out[10]=

divisorSigma 1

1170
Domain
ℕ
Input (natural numbers)
360

Checked by Lean’s kernel: divisorSigma 1

(ArithmeticFunction.sigma 1) 360 = 1170
The certificate: 1 checked step
  1. divisorSigma 1

    (ArithmeticFunction.sigma 1) 360 = 1170

    Checked by Lean’s kernel


A square has an odd number of divisors, because its square root is its own cofactor. For 36 there are nine:

In[11]:=
#cas [divisors] 36
Out[11]=

divisors

[1, 2, 3, 4, 6, 9, 12, 18, 36]
[1, 2, 3, 4, 6, 9, 12, 18, 36]
Domain
ℕ
Input (natural numbers)
36

Checked by Lean’s kernel: divisors

Nat.divisors 36 = {1, 2, 3, 4, 6, 9, 12, 18, 36}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 36 = {1, 2, 3, 4, 6, 9, 12, 18, 36}

    Checked by Lean’s kernel

Possible Issues (2)

Mathlib’s Nat.divisors 0 is the empty set, and 0 is refused:

In[12]:=
#cas [divisors] 0
Out[12]=

Error

divisors: expected a positive natural number

The divisors are certified for n<1012 only:

In[13]:=
#cas [divisors] (10^12)
Out[13]=

Error

divisors: the divisors are certified for n < 10^12; `10^12` is beyond that bound

Neat Examples (1)

220 and 284 are the smallest amicable pair: the divisors of each, other than the number itself, add up to the other:

In[14]:=
#cas [divisors] 220
Out[14]=

divisors

[1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220]
[1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220]
Domain
ℕ
Input (natural numbers)
220

Checked by Lean’s kernel: divisors

Nat.divisors 220 = {1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 220 = {1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220}

    Checked by Lean’s kernel

In[15]:=
#cas [divisors] 284
Out[15]=

divisors

[1, 2, 4, 71, 142, 284]
[1, 2, 4, 71, 142, 284]
Domain
ℕ
Input (natural numbers)
284

Checked by Lean’s kernel: divisors

Nat.divisors 284 = {1, 2, 4, 71, 142, 284}
The certificate: 1 checked step
  1. divisors

    Nat.divisors 284 = {1, 2, 4, 71, 142, 284}

    Checked by Lean’s kernel

See Also

divisorSigma · eulerPhi · factorInteger · moebiusMu