0
$\begingroup$

I'm hoping to use Mathematica to find solutions to Diophantine equations. Below is a toy example of something I would like to try.

Consider the case of $$x^2+y^2 = 17$$

which has the solution $x=1,y=4$. Note that $x$ and $y$ are coprime.

Suppose I didn't know this, and I wanted to use Mathematica to find a solution to $x^2+y^2 = 17$ where $x$ and $y$ were coprime.

As a piece of example code, I would try something like

FindInstance[
 x^2 + y^2 == 17 && x > 0 && y > 0 && CoprimeQ[x, y], {x, y, z}, Integers]

However, this returns no solution. I'm not entirely sure what the trouble is; I suspect the trouble is that though CoprimeQ[1,4] returns True, CoprimeQ[x,y] returns False, even when I've cleared $x$ and $y$.

Is there a way to pair CoprimeQ and FindInstance to find a coprime solution to a Diophantine equation? Or is there a better method for proceeding?

$\endgroup$
1
  • $\begingroup$ You have a superfluous "z". However, I think this is a bug of "FindInstance." $\endgroup$ Commented Sep 3, 2023 at 8:19

1 Answer 1

5
$\begingroup$
Reduce[x^2 + y^2 == 17 && x > 0 && y > 0 && GCD[x, y]==1, {x, y}, Integers]

returns

(x==1&&y==4)||(x==4&&y==1)

and

FindInstance[x^2 + y^2 == 17 && x > 0 && y > 0 && GCD[x, y]==1, {x, y}, Integers]

returns

{{x->4,y->1}}

But why does FindInstance with CoprimeQ fail? Trace might give a clue.

Trace[FindInstance[x^2+y^2==17&&x>0&&y>0&&CoprimeQ[x,y],{x,y,z},Integers]]

returns

{{x^2+y^2==17&&x>0&&y>0&&CoprimeQ[x,y], 
 {CoprimeQ[x,y],False},False}, 
 FindInstance[False,{x,y,z},Integers]],{}}

so it appears it is the CoprimeQ which is making this fail

$\endgroup$
1
  • 2
    $\begingroup$ Since CoprimeQ ends in Q it always evaluates to True or False, even with symbolic arguments. $\endgroup$
    – kirma
    Commented Sep 3, 2023 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.