Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
330 stars 227 forks source link

ideal of groebner basis should remember it has a groebner basis #996

Open dylanpeifer opened 4 years ago

dylanpeifer commented 4 years ago

I've had several cases where I'd like to construct an ideal from a Groebner basis and then perform some computation that needs Groebner basis information. For example, this has happened when passing a Groebner basis into a function and then needing dim or R/I.

Of course, constructing the ideal with ideal gens G makes a new ideal, and the Groebner basis has to be recomputed. For example,

i1 : R = ZZ/32003[x,y,z];

i2 : gbTrace = 3;

i3 : I1 = ideal(y-x^2, z-x^3);

o3 : Ideal of R

i4 : G1 = gb I1

   -- registering gb 0 at 0x111503700

   -- [gb]{2}(1)m{3}(1)m{4}(1)m{5}(1)onumber of (nonminimal) gb elements = 3
   -- number of monomials                = 6
   -- #reduction steps = 2
   -- #spairs done = 4
   -- ncalls = 0
   -- nloop = 0
   -- nsaved = 0
   -- 
o4 = GroebnerBasis[status: done; S-pairs encountered up to degree 4]

o4 : GroebnerBasis

i5 : I2 = ideal gens G1;

o5 : Ideal of R

i6 : gb I2  -- recomputes the Groebner basis

   -- registering gb 1 at 0x111503540

   -- [gb]{2}(3)mmm{3}(2)oonumber of (nonminimal) gb elements = 3
   -- number of monomials                = 6
   -- #reduction steps = 2
   -- #spairs done = 5
   -- ncalls = 1
   -- nloop = 0
   -- nsaved = 0
   -- 
o6 = GroebnerBasis[status: done; S-pairs encountered up to degree 2]

o6 : GroebnerBasis

I can prevent the computation by manually adjusting the ideal's cache after constructing it. For example,

i1 : R = ZZ/32003[x,y,z];

i2 : gbTrace = 3;

i3 : I1 = ideal(y-x^2, z-x^3);

o3 : Ideal of R

i4 : G1 = gb I1

   -- registering gb 0 at 0x1134f6540

   -- [gb]{2}(1)m{3}(1)m{4}(1)m{5}(1)onumber of (nonminimal) gb elements = 3
   -- number of monomials                = 6
   -- #reduction steps = 2
   -- #spairs done = 4
   -- ncalls = 0
   -- nloop = 0
   -- nsaved = 0
   -- 
o4 = GroebnerBasis[status: done; S-pairs encountered up to degree 4]

o4 : GroebnerBasis

i5 : I2 = ideal gens G1;

o5 : Ideal of R

i6 : gbOpt := new GroebnerBasisOptions from {HardDegreeLimit => null,
                                             Syzygies => false,
                             SyzygyRows => 0};

i7 : I2.generators.cache#gbOpt = G1;

i8 : gb I2  -- does not recompute the Groebner basis

o8 = GroebnerBasis[status: done; S-pairs encountered up to degree 4]

o8 : GroebnerBasis

I think ideal should be able to take in a GroebnerBasis and immediately store that as its Groebner basis, maybe using the same idea as above. I'd be happy to implement this, but I'm not really sure what is going on in the GroebnerBasisOptions object, what special cases there may be, or what the side effects are of setting the cache. Is it possible to do something like this?

DanGrayson commented 4 years ago

It might be better to make gens G, where G is a Groebner basis, return a matrix whose gb is set to G. I wonder why we don't do that already. @mikestillman ?