The gcd and the two Bézout coefficients returned by Nat.extendedGcd.
- gcd : Nat
The greatest common divisor of the inputs.
- coeffA : Int
The signed coefficient of the first input.
- coeffB : Int
The signed coefficient of the second input.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Computes the greatest common divisor of a and b together with signed Bézout coefficients in
one pass of the extended Euclidean algorithm. The result r satisfies r.gcd = Nat.gcd a b and
(r.gcd : Int) = a * r.coeffA + b * r.coeffB.
For a zero first input, the result is ⟨b, 0, 1⟩, including ⟨0, 0, 1⟩ when both inputs are zero.
For a nonzero first input and a zero second input, the result is ⟨a, 1, 0⟩.
The coefficients are not unique; no minimality or symmetry of the returned coefficients is
specified.
Examples:
Nat.extendedGcd 240 46 = ⟨2, -9, 47⟩Nat.extendedGcd 0 19 = ⟨19, 0, 1⟩Nat.extendedGcd 19 0 = ⟨19, 1, 0⟩
Equations
- a.extendedGcd b = Nat.extendedGcd.go a 1 0 b 0 1
Instances For
Implementation detail of Nat.extendedGcd: the two rows represent the remainders as
linear combinations of the original inputs.
Equations
Instances For
The gcd component of Nat.extendedGcd a b is Nat.gcd a b.
The coefficients returned by Nat.extendedGcd satisfy Bézout's identity.
The gcd returned by Nat.extendedGcd a b divides a.
The gcd returned by Nat.extendedGcd a b divides b.