gmp_lib.mpz_gcdext Method

GMP Native Interface for .NET

gmp_libmpz_gcdext Method
Set g to the greatest common divisor of a and b, and in addition set s and t to coefficients satisfying a * s + b * t = g.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_gcdext(
	mpz_t g,
	mpz_t s,
	mpz_t t,
	mpz_t a,
	mpz_t b
)
Public Shared Sub mpz_gcdext ( 
	g As mpz_t,
	s As mpz_t,
	t As mpz_t,
	a As mpz_t,
	b As mpz_t
)
public:
static void mpz_gcdext(
	mpz_t^ g, 
	mpz_t^ s, 
	mpz_t^ t, 
	mpz_t^ a, 
	mpz_t^ b
)
static member mpz_gcdext : 
        g : mpz_t * 
        s : mpz_t * 
        t : mpz_t * 
        a : mpz_t * 
        b : mpz_t -> unit 

Parameters

g
Type: Math.Gmp.Nativempz_t
The greateast common divisor.
s
Type: Math.Gmp.Nativempz_t
The first result coefficient.
t
Type: Math.Gmp.Nativempz_t
The second result coefficient.
a
Type: Math.Gmp.Nativempz_t
The first operand integer.
b
Type: Math.Gmp.Nativempz_t
The second operand integer.
Remarks

The value in g is always positive, even if one or both of a and b are negative (or zero if both inputs are zero). The values in s and t are chosen such that normally, | s | < | b | / (2 g) and | t | < | a | / (2 g), and these relations define s and t uniquely. There are a few exceptional cases:

If | a | = | b |, then s = 0, t = sgn(b).

Otherwise, s = sgn(a) if b = 0 or | b | = 2 g, and t = sgn(b) if a = 0 or | a | = 2 g.

In all cases, s = 0 if and only if g = | b |, i.e., if b divides a or a = b = 0.

If t is null then that value is not computed.

Examples
// Create, initialize, and set the value of op1 to 63.
mpz_t a = new mpz_t();
gmp_lib.mpz_init_set_ui(a, 63U);

// Create, initialize, and set the value of op2 to 70.
mpz_t b = new mpz_t();
gmp_lib.mpz_init_set_ui(b, 70U);

// Create, initialize, and set the values of g, s, and t to 0.
mpz_t g = new mpz_t();
mpz_t s = new mpz_t();
mpz_t t = new mpz_t();
gmp_lib.mpz_inits(g, s, t, null);

// Set g to the the greatest common divisor of a and b, and set s and t such that a * s + b * t = g.
gmp_lib.mpz_gcdext(g, s, t, a, b);

// Assert that g is 7, and that s and t are respectively -1 and 1.
Assert.IsTrue(gmp_lib.mpz_get_si(g) == 7);
Assert.IsTrue(gmp_lib.mpz_get_si(s) == -1);
Assert.IsTrue(gmp_lib.mpz_get_si(t) == 1);

// Release unmanaged memory allocated for g, s, t, a, and b.
gmp_lib.mpz_clears(g, s, t, a, b, null);
' Create, initialize, and set the value of op1 to 63.
Dim a As New mpz_t()
gmp_lib.mpz_init_set_ui(a, 63UI)

' Create, initialize, and set the value of op2 to 70.
Dim b As New mpz_t()
gmp_lib.mpz_init_set_ui(b, 70UI)

' Create, initialize, and set the values of g, s, and t to 0.
Dim g As New mpz_t()
Dim s As New mpz_t()
Dim t As New mpz_t()
gmp_lib.mpz_inits(g, s, t, Nothing)

' Set g to the the greatest common divisor of a and b, and set s and t such that a * s + b * t = g.
gmp_lib.mpz_gcdext(g, s, t, a, b)

' Assert that g is 7, and that s and t are respectively -1 and 1.
Assert.IsTrue(gmp_lib.mpz_get_si(g) = 7)
Assert.IsTrue(gmp_lib.mpz_get_si(s) = -1)
Assert.IsTrue(gmp_lib.mpz_get_si(t) = 1)

' Release unmanaged memory allocated for g, s, t, a, and b.
gmp_lib.mpz_clears(g, s, t, a, b, Nothing)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also