Weird behaviour with GroebnerBasis in v7
Asked Answered
G

2

5

I came across some weird behaviour when using GroebnerBasis. In m1 below, I used a Greek letter as my variable and in m2, I used a Latin letter. Both of them have no rules associated with them. Why do I get vastly different answers depending on what variable I choose?

Image:

enter image description here

Copyable code:

Clear["Global`*"]
g = Module[{x}, 
    x /. Solve[
      z - x (1 - b - 
           b x ( (a (3 - 2 a (1 + x)))/(1 - 3 a x + 2 a^2 x^2))) == 0,
       x]][[3]];
m1 = First@GroebnerBasis[\[Kappa] - g, z]
m2 = First@GroebnerBasis[k - g, z]

EDIT:

As pointed out by belisarius, my usage of GroebnerBasis is not entirely correct as it requires a polynomial input, whereas mine is not. This error, introduced by a copy-pasta, went unnoticed until now, as I was getting the answer that I expected when I followed through with the rest of my code using m1 from above. However, I'm not fully convinced that it is an unreasonable usage. Consider the example below:

x = (-b+Sqrt[b^2-4 a c])/2a;
p = First@GroebnerBasis[k - x,{a,b,c}]; (*get relation or cover for Riemann surface*)
q = First@GroebnerBasis[{D[p,k] == 0, p == 0},{a,b,c},k,
    MonomialOrder -> EliminationOrder]; 

Solve[q==0, b] (*get condition on b for double root or branch point*) 

{{b -> -2 Sqrt[a] Sqrt[c]}, {b -> 2 Sqrt[a] Sqrt[c]}}

which is correct. So my interpretation is that it is OK to use GroebnerBasis in such cases, but I'm not all too familiar with the deep theory behind it, so I could be completely wrong here.

P.S. I heard that if you mention GroebnerBasis three times in your post, Daniel Lichtblau will answer your question :)

Gilead answered 1/6, 2011 at 5:3 Comment(9)
@yoda Sorry, deleted my previous comment. Are the solutions you get from Solve[ ] polynomials?Appraise
@yoda I thought that GroebnerBasis works only for polys ...Appraise
@yoda I have no idea, but I think you should edit your question with this info about usageAppraise
@yoda Let's wait for Daniel ... :)Appraise
It crashed my kernel twice. Something spooky going on there.Bullpen
I think there was a bug behind the crash with on ordering. Will be fixed. Not sure what will happen then (hang or new result). Difference between results, in absence of crash, probably due to internal variable ordering differences. If both results are correct, that is. Traveling right now, might get time to look more carefully next week.Sterculiaceous
@Daniel: Thanks. The two results are not correct, only the first one is. Anyway, I'm not in a hurry so I'll wait till you have time.Gilead
@yoda Not much to report. Bug got fixed. Both now run longer than I was willing to wait.Sterculiaceous
@Daniel: Oh, so will it be fixed in v9? The second runs for me in less than 30 secs. Anyway, please put that as an answer so that I can accept it. Also, while I still have v7, is there some way for me to know what variable(s) to choose to not trigger the bug?Gilead
S
4

The bug that was shown by these examples will be fixed in version 9. Offhand I do not know how to evade it in versions 8 and prior. If I recall correctly it was caused by an intermediate numeric overflow in some code that was checking whether a symbolic polynomial coefficient might be zero.

For some purposes it might be suitable to specify more variables and possibly a non-default term order. Also clearing denominators can be helpful at least in cases where that is a valid thing to do. That said, I do not know if these tactics would help in this example.

I'll look some more at this code but probably not in the near future.

Daniel Lichtblau

Sterculiaceous answered 23/6, 2011 at 13:54 Comment(1)
Thanks Daniel. This particular example doesn't matter, as I chose an example for which I knew the answer.Engird
P
3

This may be related to the fact that Mathematica does not try all variable orders in functions like Simplify. Here is an example:

ClearAll[a, b, c]
expr = (c^4 b^2)/(c^4 b^2 + a^4 b^2 + c^2 a^2 (1 - 2 b^2));
Simplify[expr]
Simplify[expr /. {a -> b, b -> a}]
   (b^2 c^4)/(a^4 b^2 + a^2 (1 - 2 b^2) c^2 + b^2 c^4)
   (a^2 c^4)/(b^2 c^2 + a^2 (b^2 - c^2)^2)

Adam Strzebonski explained that:

...one can try FullSimplify with all possible orderings of chosen variables. Of course, this multiplies the computation time by Factorial[Length[variables]]...

Poulin answered 1/6, 2011 at 11:49 Comment(1)
@yoda I don't think so; I've got the fix for that in my init.m and I still get this behavior.Poulin

© 2022 - 2024 — McMap. All rights reserved.