Guide
Number theory
Divisors, congruences, digits and continued fractions, each with a theorem about Mathlib’s definitions.
In number theory the answers quickly get too big to check by hand, and that’s when I’m most tempted to trust a computer algebra system blindly. Here you don’t have to. You can work with divisors, congruences, digits, continued fractions and the usual combinatorial numbers, and each answer is a theorem about Mathlib’s definitions, such as Nat.divisors, Nat.ModEq or Nat.digits. Its proof checks the answer instead of trusting the search that found it.
Divisors and arithmetic functions
divisorsThe divisors of a positive integer below in increasing order, with a theorem about Mathlib’sNat.divisors.divisorSigmaThe sum of the -th powers of the divisors of , with a theorem about Mathlib’sArithmeticFunction.sigma.eulerPhiEuler’s totient , the number of residues modulo coprime to , with a theorem about Mathlib’sNat.totient.
Modular arithmetic
powerModThe remainder of modulo by repeated squaring, for exponents with hundreds of digits, with a theorem inℕ.modularInverseThe inverse of an integer modulo inZMod m, or a proof that there is none.chineseRemainderAll solutions of a system of congruences , as one residue modulo the lcm, or a proof that there are none.extendedGCDThe gcd of two natural numbers with Bézout coefficients and , and a theorem that .jacobiSymbolThe Jacobi symbol of an integer and an odd natural number, with a theorem about Mathlib’sjacobiSym.
Digits and continued fractions
integerDigitsThe digits of a natural number in any base , with a theorem about Mathlib’sNat.digits.continuedFractionThe continued fraction of a rational number, with a theorem that it equals the number.fromContinuedFractionThe rational value of a finite continued fraction , with a theorem in .
Combinatorial numbers
The Sunzi Suanjing asks for a number with the remainders 2, 3 and 2 on division by 3, 5 and 7. The answer is complete. The theorem says more than that 23 works: the solutions are exactly the numbers :
#cas [chineseRemainder] ([2, 3, 2], [3, 5, 7])
all solutions
23 mod 105- Domain
ℕ- Input (natural numbers)
x ≡ 2 mod 3, x ≡ 3 mod 5, x ≡ 2 mod 7
Checked by Lean’s kernel: all solutions
23 < 105 ∧ ∀ (y : ℕ), (∀ p ∈ [(3, 2), (5, 3), (7, 2)], y ≡ p.2 [MOD p.1]) ↔ y ≡ 23 [MOD 105]
The certificate: 1 checked step
all solutions
23 < 105 ∧ ∀ (y : ℕ), (∀ p ∈ [(3, 2), (5, 3), (7, 2)], y ≡ p.2 [MOD p.1]) ↔ y ≡ 23 [MOD 105]
A modular power with an exponent of 27 digits. The proof is repeated squaring, so it never builds the full power, and its size grows with the number of digits of the exponent:
#cas (powerMod 2 123456789123456789123456789 1000000007)
modular power
612059118- Domain
ℕ- Input (natural numbers)
2^123456789123456789123456789 mod 1000000007
Checked by Lean’s kernel: modular power
2 ^ 123456789123456789123456789 % 1000000007 = 612059118
The certificate: 1 checked step
modular power
2 ^ 123456789123456789123456789 % 1000000007 = 612059118
The divisor commands certify , eulerPhi counts up to , and binomial, factorial and fibonacci compute values of at most 10000 digits. continuedFraction takes rational numbers only, since an irrational number has an infinite expansion.
