3.1.1 structure.gens - Base class for objects with generators

Many objects in SAGE are equipped with generators, which are special elements of the object. For example, the polynomial ring $ \mathbf{Z}[x,y,z]$ is generated by $ x$ , $ y$ , and $ z$ . In SAGE the $ i$ th generator of an object X is obtained using the notation X.gen(i). From the SAGE interactive prompt, the shorthand notation X.i is also allowed.

The gens function returns a tuple of all generators, the ngens function returns the number of generators, and the assign_names, name and names functions allow one to change or obtain the way generators are printed. (They only affect printing!)

The following examples illustrate these functions in the context of multivariate polynomial rings and free modules.

sage: R = MPolynomialRing(IntegerRing(), 3)
sage: R.ngens()
3
sage: R.gen(0)
x_0
sage: R.gens()
(x_0, x_1, x_2)
sage: R.names()
('x_0', 'x_1', 'x_2')
sage: R.assign_names(['a', 'b', 'c'])
sage: R
Polynomial ring in a, b, c over Integer Ring

This example illustrates generators for a free module over $ \mathbf{Z}$ .

sage: M = FreeModule(IntegerRing(), 4)
sage: M
Ambient free module of rank 4 over the principal ideal domain Integer Ring
sage: M.ngens()
4
sage: M.gen(0)
(1, 0, 0, 0)
sage: M.gens()
((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))

The names of the generators of a free module aren't really used anywhere, but they are still defined:

sage: M.names()   
('x_0', 'x_1', 'x_2', 'x_3')

The module structure.gens defines the following classes:

class AdditiveAbelianGenerators

class Generators

class MultiplicativeAbelianGenerators



Subsections
See About this document... for information on suggesting changes.