Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Scilab-Branch-6.1-GIT
Change language to: Français - Português - 日本語 - Русский
Scilab Help >> Polynomials > diophant

diophant

Solves the diophantine (Bezout) equation p1*x1 + p2*x2 = b

Syntax

[x1x2, err] = diophant(p1p2, b)

Arguments

p1p2, x1x2

Vectors of two numbers or polynomials p1p2 = [p1 p2] and x1x2 = [x1 x2], with the same size and type (integers, numbers, polynomials).

When there is no solution, x1x2 = []

b

single number or polynomial

err

Single real number: error flag:

0 No error. There is an infinite number of solutions. p1==0, p2==0, while b <> 0 : No solution. There is no solution. err = ||coeff(b - int(b/g)*g)|| / ||coef(b)|| where g = gcd(p1,p2).

Description

diophant solves the bezout equation p1*x1 + p2*x2 = b for polynomials, encoded integers, or numbers.

If input arguments are encoded integers, only integer solutions are searched.

If input arguments are decimal numbers or constant polynomials, there is always an infinite number of solutions.

When there is an infinite number of solutions, only one [x1 x2] solution is returned.

Examples

[X, e] = diophant(int8([4, 7]), 5)          // int8([10 -5])
[X, e] = diophant(int16([1234 5321]), 543); // int16([30533 -2339])
sum(X .* [1234 5321])

s = %s;
p = (1+s)*(s-1) + (1-s^2)*s;
[X, e] = diophant([1+s ; 1-s^2], -1+s+s^2-s^3); // [-1+2*s-s^2 ; 0]
sum(X .* [1+s ; 1-s^2])

No solution exists:

s = %s;
[X, e] = diophant([0, 0], 1)
[X, e] = diophant([s^3, s^2], s)
[X, e] = diophant([1+s ; 1-s^2], 1-s+s^2)
[X, e] = diophant(int8([2 0]), int8(1))  // No integer solution

An infinite number of solutions exists:

[X, e] = diophant([4, 7], 5)      // [0 5/7]
s = %s;
[X, e] = diophant([0, 0]*s, 0)
[X, e] = diophant([0, 1]*s, 2*s)
[X, e] = diophant([0, s]*(1-s^2), s^2*(1-s^2))

• bezout — GCD of two polynomials or two integers, by the Bezout method
• sylm — Sylvester matrix of two polynomials

History

 Version Description 6.1.0 Input encoded integers are now supported. x1x2 = [] is now returned when there is no solution. err = -%inf is now returned when there is an infinite number of solutions. size(x1x2) now matches size(p1p2) (excepted when x1x2=[]).