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 variablealgebraicmust betrueandgcdmust not beez.
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.
Fixed by commit [948338].
Related
Commit: [948338]
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.
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
'$spmodis Maxima's default$gcdsetting, throwing an error would suddenly break standard user inputs. Anyone simply callinggcdon polynomials withsqrtor%iwould 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.
By the way, the manual doesn't even have its own entry for the
gcdoption 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.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:defaultmean "do what you think is best". That probably meansalgebraic:trueas well. That waygcd(x^2-1,x-sqrt(2)) => x+sqrt(2), which I think is what most users expect.Allowing
gcd:defaultworks for me. I never bothered to learn what all the different gcd algorithms do anyway. But isn't$gcdused all over? Allowing'defaultwould complicate things a bit, right?We should document the gcd variable.
gcd: defaultthrows 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.