Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語 -
Справка Scilab >> 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.
-%inf There is an infinite number of solutions.
%nan p1==0, p2==0, while b <> 0 : No solution.
> 0 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))

See Also

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

History

VersionDescription
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=[]).
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:54:56 CET 2020