Function of #cas
modularInverse
The inverse of an integer modulo in ZMod m, or a proof that there is none.
#cas (modularInverse a m)ZMod m, or proves that there is none.modularInverse finds the inverse of a modulo , the with . We get it from the extended Euclidean algorithm, and the theorem is about ZMod m, where the kernel checks that the product of a and the answer is 1. When a and have a common factor there is no inverse, and the theorem you get says so instead.
Examples (7)#
Basic Examples (1)
, and the theorem states both the product and the inverse:
#cas (modularInverse 3 11)
modular inverse
4- Domain
ZMod 11- Input (integer and modulus)
3 mod 11
Checked by Lean’s kernel: modular inverse
3 * 4 = 1 ∧ 3⁻¹ = 4
The certificate: 1 checked step
modular inverse
3 * 4 = 1 ∧ 3⁻¹ = 4
Scope (3)
The integer may be negative, and :
#cas (modularInverse (-3) 7)
modular inverse
2- Domain
ZMod 7- Input (integer and modulus)
-3 mod 7
Checked by Lean’s kernel: modular inverse
-3 * 2 = 1 ∧ (-3)⁻¹ = 2
The certificate: 1 checked step
modular inverse
-3 * 2 = 1 ∧ (-3)⁻¹ = 2
The private exponent of a small RSA key, the inverse of modulo :
#cas (modularInverse 17 3120)
modular inverse
2753- Domain
ZMod 3120- Input (integer and modulus)
17 mod 3120
Checked by Lean’s kernel: modular inverse
17 * 2753 = 1 ∧ 17⁻¹ = 2753
The certificate: 1 checked step
modular inverse
17 * 2753 = 1 ∧ 17⁻¹ = 2753
When there is no inverse, and the theorem says so:
#cas (modularInverse 6 9)
no inverse
none: gcd = 3- Domain
ZMod 9- Input (integer and modulus)
6 mod 9
Checked by Lean’s kernel: no inverse
Nat.gcd 6 9 = 3 ∧ ¬IsUnit 6
The certificate: 1 checked step
no inverse
Nat.gcd 6 9 = 3 ∧ ¬IsUnit 6
Applications (1)
Properties and Relations (1)
extendedGCD prints the Bézout coefficients, . Modulo 3120 the coefficient is , the inverse above:
#cas [extendedGCD] (17, 3120)
gcd and Bézout coefficients
1, [-367, 2]- Domain
ℕ- Input (natural numbers)
(17, 3120)
Checked by Lean’s kernel: gcd and Bézout coefficients
Nat.gcd 17 3120 = 1 ∧ 17 * -367 + 3120 * 2 = 1
The certificate: 1 checked step
gcd and Bézout coefficients
Nat.gcd 17 3120 = 1 ∧ 17 * -367 + 3120 * 2 = 1
Possible Issues (1)
ZMod 1 is the zero ring, where every element is its own inverse, and the call asks for :
#cas (modularInverse 3 1)
Error
modularInverse: the modulus must be at least 2
