Pure natural-number extended GCD.
The result (g, s, t) satisfies g = Nat.gcd a b and
s * a + t * b = g after coercing the inputs to Int. Use
the GMP-backed HexArith.Int.extGcd entry point for integer inputs and
HexArith.UInt64.extGcd for UInt64 inputs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bezout certificate for the pure Nat extGcd, stated on the returned
triple's projections: the cofactors s = (extGcd a b).2.1 and
t = (extGcd a b).2.2 satisfy s * a + t * b = (extGcd a b).1 after
coercing a and b to Int. The _proj form keeps the right-hand side
as the routine's own returned gcd component; see extGcd_bezout_gcd for
the variant phrased against Nat.gcd a b.
Bezout certificate for the pure Nat extGcd with the gcd resolved to
Nat.gcd a b: the returned cofactors satisfy s * a + t * b = Nat.gcd a b
over Int. Same identity as extGcd_bezout_proj, with the right-hand side
rewritten through extGcd_fst.
Pure Lean reference implementation of extended GCD over integers.
This runs the Euclidean algorithm directly on Int, carrying Bezout
coefficients through the usual quotient/remainder updates.
Equations
Instances For
Pure Lean integer extended GCD.
Hex.pureIntExtGcd is the proof reference and portable fallback for
HexArith.Int.extGcd; callers that want the project public integer API should
use HexArith.Int.extGcd instead.
Equations
- Hex.pureIntExtGcd a b = Hex.pureIntExtGcd.go a b 1 0 0 1
Instances For
The gcd component returned by the pure integer reference implementation is
Lean's Int.gcd.
Bezout certificate for the pure integer reference pureIntExtGcd, stated on
the returned triple's projections: the cofactors (pureIntExtGcd a b).2.1
and (pureIntExtGcd a b).2.2 satisfy s * a + t * b = (pureIntExtGcd a b).1.
Inputs are already Int, so no coercion is involved.
Combined correctness theorem for the pure integer reference implementation.
Use this when a proof needs both the gcd projection and the Bezout certificate without unfolding the recursive reference implementation.
Public extended GCD on integers.
Trusted runtime contract: the lean_hex_mpz_gcdext attachment may replace this
pure Lean reference with a GMP-backed implementation that returns the same
(g, s, t) triple, where g = Int.gcd a b and s * a + t * b = g.
Equations
- HexArith.Int.extGcd a b = Hex.pureIntExtGcd a b
Instances For
Projection form of the integer Bezout certificate: the coefficient components,
addressed directly as (extGcd a b).2.1 and (extGcd a b).2.2, combine to the
returned gcd component (extGcd a b).1. Lets callers rewrite a Bezout identity
without first destructuring the (g, s, t) triple.
Bezout certificate stated against Int.gcd a b directly: the coefficient
projections combine to the canonical gcd rather than the returned (extGcd a b).1
component. Lets callers rewrite a Bezout identity straight to Int.gcd, skipping
the intermediate extGcd_fst step.
Combined correctness theorem for the GMP-backed integer extended GCD surface.
The executable may run through the mpz_gcdext extern, while this theorem
characterises the same public triple used by proofs.
For a positive natural modulus, the Bezout coefficient of the zero input in
Int.extGcd 0 p is zero.
The coefficient components returned by the UInt64 extended-GCD API form a
Bezout certificate for the natural values of the input words.
Bezout certificate for the UInt64 extGcd, stated on the returned triple's
projections: the cofactors satisfy
s * a.toNat + t * b.toNat = (extGcd a b).1.toNat, with each word coerced to
Int via Int.ofNat ·.toNat. The _proj form keeps the right-hand side as
the routine's own returned gcd word; see extGcd_bezout_gcd for the variant
phrased against Nat.gcd a.toNat b.toNat.
Bezout certificate for the UInt64 extGcd with the gcd resolved to
Nat.gcd a.toNat b.toNat: the returned cofactors satisfy
s * a.toNat + t * b.toNat = Nat.gcd a.toNat b.toNat, coerced to Int via
Int.ofNat ·.toNat. Same identity as extGcd_bezout_proj, with the
right-hand side rewritten through extGcd_fst.
Combined correctness theorem for the UInt64 extended-GCD API.
The gcd component is stored as a word, so the gcd equality is stated after
toNat; the Bezout certificate is stated over the natural representatives of
the input words.