Many objects in SAGE are equipped with generators, which are special
elements of the object. For example, the polynomial ring
is generated by
,
, and
. In SAGE the
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
.
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: