Menu

#4814 Default GCD algorithm can't handle algebraic

None
closed
nobody
5
2026-07-13
2026-07-12
No

From the manual:

To take the gcd when an algebraic is present, e.g., gcd (x^2 - 2*sqrt(2)* x + 2, x - sqrt(2)), the option variable algebraic must be true and gcd must not be ez.

This example doesn't work with the default gcd value of spmod:

(%i1) gcd (x^2 - 2*sqrt(2)* x + 2, x - sqrt(2)), algebraic;
(%o1)                             x - sqrt(2)

We should probably automatically select a different algorithm when algebraics are present.

Discussion

  • David Scherfgen

    David Scherfgen - 2026-07-12
    • status: open --> closed
     
  • David Scherfgen

    David Scherfgen - 2026-07-12

    Fixed by commit [948338].

     

    Related

    Commit: [948338]

  • Raymond Toy

    Raymond Toy - 2026-07-12

    This should probably be documented in the manual? Although you've already fixed this, maybe it should have just signaled an error if spmod can't handle it instead? Magically changing the gcd algorithm for this case mkes it difficult to know what happened if you have spmod but some other algorithm was actually used.

    Note: I didn't look at the changes you actually made.

     
    • David Scherfgen

      David Scherfgen - 2026-07-12

      Totally fair point - silent fallbacks definitely make it harder to trace exactly which algorithm is doing the job under the hood.

      I actually considered signaling an error, but decided against it for the following reason: Because '$spmod is Maxima's default $gcd setting, throwing an error would suddenly break standard user inputs. Anyone simply calling gcd on polynomials with sqrt or %i would get a hard error unless they knew to manually switch the algorithm to '$subres.

      Maybe print a warning message? I'm just afraid that it would flood the console, because lots of GCDs are taken all the time.

       
    • David Scherfgen

      David Scherfgen - 2026-07-12

      By the way, the manual doesn't even have its own entry for the gcd option variable. I'd argue that the average user doesn't know what the different algorithms mean, and actually shouldn't have to know or care.

       
      • Stavros Macrakis

        I agree that almost all of our users don't care and shouldn't care. There might be 0.1% of our users who care a lot because they know which algorithm is fastest or least likely to have a bug on their special huge case.

        Maybe we should have gcd:default mean "do what you think is best". That probably means algebraic:true as well. That way gcd(x^2-1,x-sqrt(2)) => x+sqrt(2), which I think is what most users expect.

         
        • Raymond Toy

          Raymond Toy - 2026-07-13

          Allowing gcd:default works for me. I never bothered to learn what all the different gcd algorithms do anyway. But isn't $gcd used all over? Allowing 'default would complicate things a bit, right?

           
      • Raymond Toy

        Raymond Toy - 2026-07-13

        We should document the gcd variable. gcd: default throws an error that it's not valid, of course. But doesn't say what would be valid, and there's no way a user can know what would be valid. So two things: document the variable and fix up the error message to give a hint on what's valid.

         

Log in to post a comment.

MongoDB Logo MongoDB