Function of #cas
powerMod
The remainder of modulo by repeated squaring, for exponents with hundreds of digits, with a theorem in ℕ.
#cas (powerMod a b m)a ^ b % m = r.powerMod computes modulo without ever building the integer , which for a large exponent would be far too big to write down. The proof is repeated squaring, so its size grows with the number of digits of the exponent and not with the exponent itself. Exponents with hundreds of digits are fine.
Examples (7)#
Basic Examples (1)
The remainder of modulo 7:
#cas (powerMod 3 1000 7)
modular power
4- Domain
ℕ- Input (natural numbers)
3^1000 mod 7
Checked by Lean’s kernel: modular power
3 ^ 1000 % 7 = 4
The certificate: 1 checked step
modular power
3 ^ 1000 % 7 = 4
Scope (1)
An exponent with 27 digits, modulo the prime , with the theorem that the kernel checked:
#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
Applications (1)
Properties and Relations (2)
Fermat’s little theorem gives for a prime that does not divide . Here and , so :
#cas (powerMod 2 100 7)
modular power
2- Domain
ℕ- Input (natural numbers)
2^100 mod 7
Checked by Lean’s kernel: modular power
2 ^ 100 % 7 = 2
The certificate: 1 checked step
modular power
2 ^ 100 % 7 = 2
For an odd prime , Euler’s criterion relates the remainder to the symbol of jacobiSymbol. For and the power is , and the symbol is 1:
#cas (jacobiSymbol 2 7)
Jacobi symbol
1- Domain
ℤ × ℕ- Input (an integer and an odd natural number)
(2 / 7)
Checked by Lean’s kernel: Jacobi symbol
jacobiSym 2 7 = 1
The certificate: 1 checked step
Jacobi symbol
jacobiSym 2 7 = 1
Possible Issues (2)
See Also
modularInverse · jacobiSymbol · extendedGCD · chineseRemainder · integerDigits
