Documentation

HexArith.Nat.ExtendedGcd

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
    • 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
        @[extern lean_hex_nat_extended_gcd]

        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:

        Equations
        Instances For
          @[irreducible]
          def Nat.extendedGcd.go (r : Nat) (s t : Int) (r' : Nat) (s' t' : Int) :

          Implementation detail of Nat.extendedGcd: the two rows represent the remainders as linear combinations of the original inputs.

          Equations
          Instances For
            @[simp]
            theorem Nat.extendedGcd_zero_left (b : Nat) :
            extendedGcd 0 b = { gcd := b, coeffA := 0, coeffB := 1 }
            @[simp]
            theorem Nat.extendedGcd_zero_right {a : Nat} (h : a ≠ 0) :
            a.extendedGcd 0 = { gcd := a, coeffA := 1, coeffB := 0 }
            @[simp]
            theorem Nat.extendedGcd_self {a : Nat} (h : a ≠ 0) :
            a.extendedGcd a = { gcd := a, coeffA := 1, coeffB := 0 }
            @[simp]
            theorem Nat.extendedGcd_gcd (a b : Nat) :
            (a.extendedGcd b).gcd = a.gcd b

            The gcd component of Nat.extendedGcd a b is Nat.gcd a b.

            theorem Nat.extendedGcd_bezout (a b : Nat) :
            ↑(a.gcd b) = ↑a * (a.extendedGcd b).coeffA + ↑b * (a.extendedGcd b).coeffB

            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.