# Solving Diophantine equations: isolve

### 5.5.23 Solving Diophantine equations: isolve

The isolve command attempts to solve the given equations over the integers. Note that it automatically solves for all of the indeterminates present in the equations.

- isolve takes one mandatory argument: an equation or list of equations.
- isolve also takes the following optional arguments:
  - a (sequence or list of) symbol(s), which are used as the names for global variables present in the solution, can be passed as the second argument. These names default to _Z0,_Z1,… for general integers and to _N0,_N1,… for positive integers.
  - seq=false, which makes isolve return only particular/fundamental solution(s) found by the solver. By default, seq=true, which makes isolve return sequences (classes) of solutions whenever possible.
- isolve can solve the following types of equations:
  - (systems of) linear equation(s)
  - general quadratic equations with two indeterminates
  - equations of the type Q(x,y,z)=0, where Q is a ternary quadratic form
  - equations of the type f(x)=g(y), where f,g∈ℤ[X] are monic polynomials with degrees m and n such that gcd(m,n)>1 and f(x)−g(y) is irreducible in ℚ[X,Y]

#### Examples.

- Linear equations and systems can be solved.
  Input:
  isolve(5x+42y+8=0)
  Output:

  | ⎡ ⎣ | x=−10+42_Z0,y=1−5_Z0 | ⎤ ⎦

  Input:
  isolve([x+y-z=4,x-2y+3z=3],m)
  Output:

  | ⎡ ⎣ | x=m,y=−4 m+15,z=−3 m+11 | ⎤ ⎦

- Here we find the general solution to Pell-type equation x2−23y2=1.
  Input:
  sol:=isolve(x^2-23y^2=1,n)
  Output:

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  x=

  ⎛
  ⎜
  ⎝

  24+5

  √

  23

  ⎞
  ⎟
  ⎠

  n

  +

  ⎛
  ⎜
  ⎝

  24−5

  √

  23

  ⎞
  ⎟
  ⎠

  n

  2

  ,y=

  ⎛
  ⎜
  ⎝

  24+5

  √

  23

  ⎞
  ⎟
  ⎠

  n

  −

  ⎛
  ⎜
  ⎝

  24−5

  √

  23

  ⎞
  ⎟
  ⎠

  n

  2

  √

  23

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  To check that it is indeed the solution, enter:
  simplify(subs(x^2-23y^2-1,sol))
  Output:

  0

  Now to obtain e.g. the first four solutions, enter:
  simplify(apply(unapply(apply(rhs,sol),n),[1,2,3,4]))
  Output:

  | ⎡ ⎣ | [24,5],[1151,240],[55224,11515],[2649601,552480] | ⎤ ⎦

  To obtain only the fundamental solution, enter:
  isolve(x^2-23y^2=1,seq=false)
  Output:

  [x=24,y=5]

- The following two examples demonstrate solving quadratic equations with two indeterminates.
  Input:
  isolve(x^2-5x*y+4y^2=16)
  Output:

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  x=−4, | y=−5
  x=0, | y=−2
  x=4, | y=0
  x=10, | y=2
  x=21, | y=5
  x=4, | y=5
  x=0, | y=2
  x=−4, | y=0
  x=−10, | y=−2
  x=−21, | y=−5

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  Input:
  isolve(x^2-3x*y+y^2-x=2,n)
  Output:

  [[x

  =

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  −3

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  ⎛
  ⎜
  ⎝

  −15

  √

  5

  −33

  ⎞
  ⎟
  ⎠

  10

  +

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  −3

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  ⎛
  ⎜
  ⎝

  15

  √

  5

  −33

  ⎞
  ⎟
  ⎠

  10

  −

  2
  5

  ,

  y

  =

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  −3

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  ⎛
  ⎜
  ⎝

  −3

  √

  5

  −6

  ⎞
  ⎟
  ⎠

  5

  +

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  −3

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  ⎛
  ⎜
  ⎝

  3

  √

  5

  −6

  ⎞
  ⎟
  ⎠

  5

  −

  3
  5

  ]]

  Input:
  isolve(8x^2-24x*y+18y^2+5x+7y+16=0)
  Output:

  ⎡
  ⎢
  ⎣

  x=−174 _Z12+17_Z1−2, | y=−116 _Z12+21_Z1−2
  x=−174 _Z12+41_Z1−4, | y=−116 _Z12+37_Z1−4

  ⎤
  ⎥
  ⎦

- Integral zeros of ternary quadratic forms can be found.
  Input:
  isolve(x^2+11y^2+6x*y-3z^2=0,a,b,c)
  Output:

  ⎡ ⎣ | x=c | ⎛ ⎝ | −44 a2+12 b2 | ⎞ ⎠ | ,y=c | ⎛ ⎝ | 13 a2−3 b2−6 a b | ⎞ ⎠ | ,z=c | ⎛ ⎝ | −11 a2−3 b2+2 a b | ⎞ ⎠ | ⎤ ⎦

  The components of the above solution can be divided by the GCD of −44 a2+12 b2, 13 a2−3 b2−6 a b, and −11 a2−3 b2+2 a b, thus producing a parametrization for the pairwise-coprime solutions given c=1.
- Certain polynomial equations of the type f(x)=g(y) can be fully solved, as in the following example.
  Input:
  isolve(x^2-3x+5=y^8-y^7+9y^6-7y^5+4y^4-y^3)
  Output:

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  x=−3, | y=−1
  x=6, | y=−1
  x=0, | y=1
  x=3, | y=1
  x=660, | y=5
  x=−657, | y=5

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  The above list contains all integer solutions to the given equation.