Mode of #cas
divisors
The divisors of a positive integer below in increasing order, with a theorem about Mathlib’s Nat.divisors.
#cas [divisors] nNat.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 with its cofactor and counts the small ones with divisions, so the time depends on the size of n and not on its factors.
Examples (12)#
Basic Examples (2)
The divisors of 12:
#cas [divisors] 12
divisors
[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
divisors
Nat.divisors 12 = {1, 2, 3, 4, 6, 12}
The 24 divisors of :
#cas [divisors] 360
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]- 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
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}
Scope (3)
A prime has only the divisors 1 and itself:
#cas [divisors] 97
divisors
[1, 97]- Domain
ℕ- Input (natural numbers)
97
Checked by Lean’s kernel: divisors
Nat.divisors 97 = {1, 97}
The certificate: 1 checked step
divisors
Nat.divisors 97 = {1, 97}
A closed expression, here the Mersenne number :
#cas [divisors] (2^10 - 1)
divisors
[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
divisors
Nat.divisors 1023 = {1, 3, 11, 31, 33, 93, 341, 1023}
A million is , so it has divisors. The kernel checks them with 1000 divisions:
#cas [divisors] 1000000
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]- 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
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}
Applications (2)
The theorem. Only the three standard axioms are used:
theorem divisors_twelve : Nat.divisors 12 = {1, 2, 3, 4, 6, 12} := by cas #print axioms divisors_twelve
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 . For the sum is :
#cas [divisors] 8128
divisors
[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
divisors
Nat.divisors 8128 = {1, 2, 4, 8, 16, 32, 64, 127, 254, 508, 1016, 2032, 4064, 8128}
#cas (divisorSigma 1 8128)
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
divisorSigma 1
(ArithmeticFunction.sigma 1) 8128 = 16256
Properties and Relations (2)
divisorSigma gives the number of divisors, , and their sum, , without the list:
#cas (divisorSigma 0 360)
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
divisorSigma 0
(ArithmeticFunction.sigma 0) 360 = 24
#cas (divisorSigma 1 360)
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
divisorSigma 1
(ArithmeticFunction.sigma 1) 360 = 1170
A square has an odd number of divisors, because its square root is its own cofactor. For 36 there are nine:
#cas [divisors] 36
divisors
[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
divisors
Nat.divisors 36 = {1, 2, 3, 4, 6, 9, 12, 18, 36}
Possible Issues (2)
Mathlib’s Nat.divisors 0 is the empty set, and 0 is refused:
#cas [divisors] 0
Error
divisors: expected a positive natural number
The divisors are certified for only:
#cas [divisors] (10^12)
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:
#cas [divisors] 220
divisors
[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
divisors
Nat.divisors 220 = {1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220}
#cas [divisors] 284
divisors
[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
divisors
Nat.divisors 284 = {1, 2, 4, 71, 142, 284}
