next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > ideals > extracting generators of an ideal

extracting generators of an ideal

obtain a single generator as an element

Once an ideal has been constructed it is possible to obtain individual elements using _. As always in Macaulay2, indexing starts at 0.
i1 : R = ZZ[w,x,y,z];
i2 : I = ideal(z*w-2*x*y, 3*w^3-z^3,w*x^2-4*y*z^2,x);

o2 : Ideal of R
i3 : I_0

o3 = - 2x*y + w*z

o3 : R
i4 : I_3

o4 = x

o4 : R

the generators as a matrix or list of elements

Use generators or its abbreviation generators to get the generators of an ideal I as a matrix. Applying first entries to this matrix converts it to a list.
i5 : gens I

o5 = | -2xy+wz 3w3-z3 wx2-4yz2 x |

             1       4
o5 : Matrix R  <--- R
i6 : first entries gens I

                      3    3     2       2
o6 = {- 2x*y + w*z, 3w  - z , w*x  - 4y*z , x}

o6 : List

number of generators

The command numgens gives the number of generators of an ideal I.
i7 : numgens I

o7 = 4

minimal generating set

To obtain a minimal generating set of a homogeneous ideal use mingens to get the minimal generators as a matrix and use trim to get the minimal generators as an ideal.
i8 : mingens I

o8 = | x wz 4yz2 3w3-z3 |

             1       4
o8 : Matrix R  <--- R
i9 : trim I

                        2    3    3
o9 = ideal (x, w*z, 4y*z , 3w  - z )

o9 : Ideal of R
The function mingens is only well-defined for a homogeneous ideal or in a local ring. However, one can still try to get as small a generating set as possible and when it is implemented this function will be done by trim.

obtaining the input form of an ideal

If the ideal was defined using a function like monomialCurveIdeal and the generators are desired in the usual format for input of an ideal, the function toString is very useful. (Note: We are changing rings because monomialCurveIdeal is not implemented for rings over ZZ.)
i10 : R = QQ[a..d];
i11 : I = monomialCurveIdeal(R,{1,2,3});

o11 : Ideal of R
i12 : toString I

o12 = ideal(c^2-b*d,b*c-a*d,b^2-a*c)