Re: What’s the equivalen t of Mathematica’s Solve[] Function in Pari/Gp ?

Karim Belabas <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
Hi Laël,

  Bill's question was about the algorithm used, not the result.

To solve a*x + b*y = c in {x,y} integers (given a,b,c integers) in GP:

Solve(a,b,c) =
{ my([u, v, d] = gcdext(a, b));

  if (c % d, return ([]));  \\ no solution
  my(x = c/d * u % (b/d));
  [x, (c - a*x) / b];
}

? Solve(300001,4139891237,5)
%1 = [1952821586, -141513]
? 1952821586 * 300001 - 141513*4139891237
%2 = 5

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/

* Laël Cellier [2025-01-12 11:46]:
> No,
> 
> it stops after finding the first solution instead of returning every
> possible values and that’s what I’m needing. And even if gcdext was the
> solution, how would I be able to use it since the equation contains a ==
> sign ?
> 
> Cordialement,
> 
> Le 12/01/2025 à 00:01, Bill Allombert a écrit :
> > On Sat, Jan 11, 2025 at 10:59:38PM +0100, Laël Cellier wrote:
> > > Bonjour,
> > > 
> > > simple question, in mathematica, I can write something like this :
> > > Solve[((25)^2 + x RSA260)/(y) == (Floor[RSA260^(1/2)] + 1)^2, {x, y},
> > > Integers]
> > > where RSA260 is variable, and it returns me a value of x and y for which the
> > > equation is true.
> > Does it just try every couple (x,y) ?
> > You can solve that in GP using gcdext.
> > 
> > Cheers,
> > Bill.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.