Elements

AUTHORS:

  • David Harvey (2006-10-16): changed CommutativeAlgebraElement to derive from CommutativeRingElement instead of AlgebraElement
  • David Harvey (2006-10-29): implementation and documentation of new arithmetic architecture
  • William Stein (2006-11): arithmetic architecture – pushing it through to completion.
  • Gonzalo Tornaria (2007-06): recursive base extend for coercion – lots of tests

The Abstract Element Class Hierarchy

This is the abstract class hierarchy, i.e., these are all abstract base classes.

SageObject
    Element
        ModuleElement
            RingElement
                CommutativeRingElement
                    IntegralDomainElement
                        DedekindDomainElement
                            PrincipalIdealDomainElement
                                EuclideanDomainElement
                    FieldElement
                        FiniteFieldElement
                    CommutativeAlgebraElement
                AlgebraElement   (note -- can't derive from module, since no multiple inheritance)
                    CommutativeAlgebra ??? (should be removed from element.pxd)
                    Matrix
                InfinityElement
                    PlusInfinityElement
                    MinusInfinityElement
            AdditiveGroupElement
            Vector

        MonoidElement
            MultiplicativeGroupElement

How to Define a New Element Class

Elements typically define a method _new_c, e.g.,

cdef _new_c(self, defining data):
    cdef FreeModuleElement_generic_dense x
    x = PY_NEW(FreeModuleElement_generic_dense)
    x._parent = self._parent
    x._entries = v

that creates a new sibling very quickly from defining data with assumed properties.

Sage has a special system in place for handling arithmetic operations for all Element subclasses. There are various rules that must be followed by both arithmetic implementers and callers.

A quick summary for the impatient:

  • To implement addition for any Element class, override def _add_().
  • If you want to add x and y, whose parents you know are IDENTICAL, you may call _add_(x, y). This will be the fastest way to guarantee that the correct implementation gets called. Of course you can still always use “x + y”.

Now in more detail. The aims of this system are to provide (1) an efficient calling protocol from both Python and Cython, (2) uniform coercion semantics across Sage, (3) ease of use, (4) readability of code.

We will take addition of RingElements as an example; all other operators and classes are similar. There are four relevant functions.

  • def RingElement.__add__

    This function is called by Python or Pyrex when the binary “+” operator is encountered. It ASSUMES that at least one of its arguments is a RingElement; only a really twisted programmer would violate this condition. It has a fast pathway to deal with the most common case where the arguments have the same parent. Otherwise, it uses the coercion module to work out how to make them have the same parent. After any necessary coercions have been performed, it calls _add_ to dispatch to the correct underlying addition implementation.

    Note that although this function is declared as def, it doesn’t have the usual overheads associated with python functions (either for the caller or for __add__ itself). This is because python has optimised calling protocols for such special functions.

  • def RingElement._add_

    This is the function you should override to implement addition in a python subclass of RingElement.

    Warning

    if you override this in a Cython class, it won’t get called. You should override _add_ instead. It is especially important to keep this in mind whenever you move a class down from Python to Cython.

    The two arguments to this function are guaranteed to have the SAME PARENT. Its return value MUST have the SAME PARENT as its arguments.

    If you want to add two objects from python, and you know that their parents are the same object, you are encouraged to call this function directly, instead of using “x + y”.

    The default implementation of this function is to call _add_, so if no-one has defined a python implementation, the correct Pyrex implementation will get called.

  • cpdef RingElement._add_

    This is the function you should override to implement addition in a Pyrex subclass of RingElement.

    The two arguments to this function are guaranteed to have the SAME PARENT. Its return value MUST have the SAME PARENT as its arguments.

    The default implementation of this function is to raise a NotImplementedError, which will happen if no-one has supplied implementations of either _add_.

For speed, there are also inplace version of the arithmetic commands. DD NOT call them directly, they may mutate the object and will be called when and only when it has been determined that the old object will no longer be accessible from the calling function after this operation.

  • def RingElement._iadd_

    This is the function you should override to inplace implement addition in a Python subclass of RingElement.

    The two arguments to this function are guaranteed to have the SAME PARENT. Its return value MUST have the SAME PARENT as its arguments.

    The default implementation of this function is to call _add_, so if no-one has defined a Python implementation, the correct Cython implementation will get called.

class sage.structure.element.AdditiveGroupElement

Generic element of an additive group.

__invert__()
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_lmul_()

Default module left scalar multiplication, which is to try to canonically coerce the scalar to the integers and do that multiplication, which is always defined.

The coercion model will catch this error and create the appropriate action.

_rmul_()
order()
Return additive order of element
class sage.structure.element.AlgebraElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.CoercionModel

Most basic coercion scheme. If it doesn’t already match, throw an error.

static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
bin_op()
canonical_coercion()
class sage.structure.element.CommutativeAlgebra
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.CommutativeAlgebraElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.CommutativeRingElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_im_gens_()
divides()

Return True if self divides x.

EXAMPLES:

sage: P.<x> = PolynomialRing(QQ)
sage: x.divides(x^2)
True
sage: x.divides(x^2+2)
False
sage: (x^2+2).divides(x)
False
sage: P.<x> = PolynomialRing(ZZ)
sage: x.divides(x^2)
True
sage: x.divides(x^2+2)
False
sage: (x^2+2).divides(x)
False
inverse_mod()
Return an inverse of self modulo the ideal $I$, if defined, i.e., if I and self together generate the unit ideal.
mod()

Return a representative for self modulo the ideal I (or the ideal generated by the elements of I if I is not an ideal.)

EXAMPLE: Integers Reduction of 5 modulo an ideal:

sage: n = 5
sage: n.mod(3*ZZ)
2

Reduction of 5 modulo the ideal generated by 3:

sage: n.mod(3)
2

Reduction of 5 modulo the ideal generated by 15 and 6, which is (3).

sage: n.mod([15,6])
2

EXAMPLE: Univariate polynomials

sage: R.<x> = PolynomialRing(QQ)
sage: f = x^3 + x + 1
sage: f.mod(x + 1)
-1

When little is implemented about a given ring, then mod may return simply return f. For example, reduction is not implemented for \ZZ[x] yet. (TODO!)

sage: R.<x> = PolynomialRing(ZZ) sage: f = x^3 + x + 1 sage: f.mod(x + 1) x^3 + x + 1

EXAMPLE: Multivariate polynomials We reduce a polynomial in two variables modulo a polynomial and an ideal:

sage: R.<x,y,z> = PolynomialRing(QQ, 3)
sage: (x^2 + y^2 + z^2).mod(x+y+z)
2*y^2 + 2*y*z + 2*z^2

Notice above that x is eliminated. In the next example, both y and z are eliminated:

sage: (x^2 + y^2 + z^2).mod( (x - y, y - z) )
3*z^2
sage: f = (x^2 + y^2 + z^2)^2; f
x^4 + 2*x^2*y^2 + y^4 + 2*x^2*z^2 + 2*y^2*z^2 + z^4
sage: f.mod( (x - y, y - z) )
9*z^4

In this example y is eliminated:

sage: (x^2 + y^2 + z^2).mod( (x^3, y - z) )
x^2 + 2*z^2
class sage.structure.element.DedekindDomainElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.Element

Generic element of a structure. All other types of elements (RingElement, ModuleElement, etc) derive from this type.

Subtypes must either call __init__() to set _parent, or may set _parent themselves if that would be more efficient.

__cmp__()
x.__cmp__(y) <==> cmp(x,y)
__eq__()
x.__eq__(y) <==> x==y
__ge__()
x.__ge__(y) <==> x>=y
__getstate__()

Returns a tuple describing the state of your object.

This should return all information that will be required to unpickle the object. The functionality for unpickling is implemented in __setstate__().

TESTS:

sage: R.<x,y> = QQ[]
sage: i = ideal(x^2 - y^2 + 1)
sage: i.__getstate__()
(Monoid of ideals of Multivariate Polynomial Ring in x, y over Rational Field, {'_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Rational Field, '_Ideal_generic__gens': (x^2 - y^2 + 1,)})
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__le__()
x.__le__(y) <==> x<=y
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pos__()
__rxor__()
x.__rxor__(y) <==> y^x
__setstate__()

Initializes the state of the object from data saved in a pickle.

During unpickling __init__ methods of classes are not called, the saved data is passed to the class via this function instead.

TESTS:

sage: R.<x,y> = QQ[]
sage: i = ideal(x); i
Ideal (x) of Multivariate Polynomial Ring in x, y over Rational Field
sage: S.<y,z> = ZZ[]
sage: i.__setstate__((R,{'_Ideal_generic__ring':S,'_Ideal_generic__gens': (x^2 - y^2 + 1,)}))
sage: i
Ideal (x^2 - y^2 + 1) of Multivariate Polynomial Ring in y, z over Integer Ring
__xor__()
_cmp_()
_coeff_repr()
_im_gens_()
Return the image of self in codomain under the map that sends the images of the generators of the parent of self to the tuple of elements of im_gens.
_is_atomic()

Return True if and only if parenthesis are not required when printing out any of x - s, x + s, x^s and x/s.

EXAMPLES:

sage: n = 5; n._is_atomic()
True
sage: n = x+1; n._is_atomic()
False
_latex_coeff_repr()
_make_new_with_parent_c()
_mpmath_()

Evaluates numerically and returns an mpmath number. Used as fallback for conversion by mpmath.mpmathify().

Note

Currently, the rounding mode is ignored.

EXAMPLES:

sage: from sage.libs.mpmath.all import mp, mpmathify
sage: mp.dps = 30
sage: 25._mpmath_(53)
mpf('25.0')
sage: mpmathify(3+4*I)
mpc(real='3.0', imag='4.0')
sage: mpmathify(1+pi)
mpf('4.14159265358979323846264338327933')
sage: (1+pi)._mpmath_(10)
mpf('4.140625')
sage: (1+pi)._mpmath_(mp.prec)
mpf('4.14159265358979323846264338327933')
_repr_()
_richcmp_()
_set_parent()

INPUT:

  • parent - a SageObject
base_extend()
base_ring()
Returns the base ring of this element’s parent (if that makes sense).
category()
is_zero()

Return True if self equals self.parent()(0). The default implementation is to fall back to ‘not self.__nonzero__’.

Warning

Do not re-implement this method in your subclass but implement __nonzero__ instead.

n()

Return a numerical approximation of x with at least prec bits of precision.

EXAMPLES:

sage: (2/3).n()
0.666666666666667
sage: a = 2/3
sage: pi.n(digits=10)
3.141592654
sage: pi.n(prec=20)   # 20 bits
3.1416
parent()
Returns parent of this element; or, if the optional argument x is supplied, the result of coercing x into the parent of this element.
subs()

Substitutes given generators with given values while not touching other generators. This is a generic wrapper around __call__. The syntax is meant to be compatible with the corresponding method for symbolic expressions.

INPUT:

  • in_dict - (optional) dictionary of inputs
  • **kwds - named parameters

OUTPUT:

  • new object if substitution is possible, otherwise self.

EXAMPLES:

sage: x, y = PolynomialRing(ZZ,2,'xy').gens()  
sage: f = x^2 + y + x^2*y^2 + 5
sage: f((5,y))
25*y^2 + y + 30
sage: f.subs({x:5})
25*y^2 + y + 30
sage: f.subs(x=5)
25*y^2 + y + 30
sage: (1/f).subs(x=5)
1/(25*y^2 + y + 30)
sage: Integer(5).subs(x=4)
5
substitute()

This is an alias for self.subs().

INPUT:

  • in_dict - (optional) dictionary of inputs
  • **kwds - named parameters

OUTPUT:

  • new object if substitution is possible, otherwise self.

EXAMPLES:

sage: x, y = PolynomialRing(ZZ,2,'xy').gens()  
sage: f = x^2 + y + x^2*y^2 + 5
sage: f((5,y))
25*y^2 + y + 30
sage: f.substitute({x:5})
25*y^2 + y + 30
sage: f.substitute(x=5)
25*y^2 + y + 30
sage: (1/f).substitute(x=5)
1/(25*y^2 + y + 30)
sage: Integer(5).substitute(x=4)
5
class sage.structure.element.EuclideanDomainElement
__divmod__()

Return the quotient and remainder of self divided by other.

EXAMPLES:

sage: divmod(5,3)
(1, 2)
sage: divmod(25r,12) 
(2, 1)
sage: divmod(25,12r)
(2, 1)
__floordiv__()
Quotient of division of self by other. This is denoted //.
__mod__()

Remainder of division of self by other.

EXAMPLES:

sage: R.<x> = ZZ[]
sage: x % (x+1)
-1
sage: (x**3 + x - 1) % (x**2 - 1)
2*x - 1
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__rdivmod__()
x.__rdivmod__(y) <==> divmod(y, x)
__rfloordiv__()
x.__rfloordiv__(y) <==> y//x
__rmod__()
x.__rmod__(y) <==> y%x
_gcd()

Return the greatest common divisor of self and other.

Algorithm 3.2.1 in Cohen, GTM 138.

degree()
leading_coefficient()
quo_rem()
class sage.structure.element.FieldElement
__floordiv__()
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__rfloordiv__()
x.__rfloordiv__(y) <==> y//x
_gcd()
Return the greatest common divisor of self and other.
_lcm()
Return the least common multiple of self and other.
_xgcd()
divides()

Check whether self divides other, for field elements.

Since this is a field, all values divide all other values, except that zero does not divide any non-zero values.

EXAMPLES:

sage: K.<rt3> = QQ[sqrt(3)]
sage: K(0).divides(rt3)
False
sage: rt3.divides(K(17))
True
sage: K(0).divides(K(0))
True
sage: rt3.divides(K(0))            
True
is_unit()

Return True if self is a unit in its parent ring.

EXAMPLES:

sage: a = 2/3; a.is_unit()
True

On the other hand, 2 is not a unit, since its parent is ZZ.

sage: a = 2; a.is_unit()
False
sage: parent(a)
Integer Ring

However, a is a unit when viewed as an element of QQ:

sage: a = QQ(2); a.is_unit()
True
quo_rem()
class sage.structure.element.FiniteFieldElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_im_gens_()

Used for applying homomorphisms of finite fields.

EXAMPLES:

sage: k.<a> = FiniteField(73^2, 'a')
sage: K.<b> = FiniteField(73^4, 'b')
sage: phi = k.hom([ b^(73*73+1) ])
sage: phi(0)
0
sage: phi(a)
7*b^3 + 13*b^2 + 65*b + 71

sage: phi(a+3)
7*b^3 + 13*b^2 + 65*b + 1
_latex_()

Return the latex representation of self, which is just the latex representation of the polynomial representation of self.

EXAMPLES:

sage: k.<b> = GF(5^2); k
Finite Field in b of size 5^2
sage: b._latex_()
'b'
sage: (b^2+1)._latex_()
'b + 4'
_matrix_()

Return the matrix of right multiplication by the element on the power basis 1, x, x^2, \ldots, x^{d-1} for the field extension. Thus the emph{rows} of this matrix give the images of each of the x^i.

INPUT:

  • reverse - if True act on vectors in reversed order

EXAMPLE:

sage: k.<a> = GF(2^4)
sage: a._vector_(reverse=True), a._matrix_(reverse=True) * a._vector_(reverse=True)
((0, 0, 1, 0), (0, 1, 0, 0))
sage: vector(a), matrix(a) * vector(a)
((0, 1, 0, 0), (0, 0, 1, 0))
_pari_init_()

Return string that when evaluated in PARI defines this element.

EXAMPLES:

sage: S.<b> = GF(5^2); S
Finite Field in b of size 5^2
sage: b._pari_init_()
'Mod(b, Mod(1, 5)*b^2 + Mod(4, 5)*b + Mod(2, 5))'
sage: (2*b+3)._pari_init_()
'Mod(2*b + 3, Mod(1, 5)*b^2 + Mod(4, 5)*b + Mod(2, 5))'        
_vector_()

Return a vector in self.parent().vector_space() matching self. The most significant bit is to the right.

INPUT:

- ``reverse`` -- reverse the order of the bits
from little endian to big endian.

EXAMPLES:

sage: k.<a> = GF(2^16)
sage: e = a^2 + 1
sage: v = vector(e)
sage: v
(1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
sage: k(v)
a^2 + 1

sage: k.<a> = GF(3^16)
sage: e = 2*a^2 + 1
sage: v = vector(e)
sage: v
(1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
sage: k(v)
2*a^2 + 1

You can also compute the vector in the other order:

sage: e._vector_(reverse=True)
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1)
additive_order()

Return the additive order of this finite field element.

EXAMPLES:

sage: k.<a> = FiniteField(2^12, 'a')
sage: b = a^3 + a + 1
sage: b.additive_order()
2
sage: k(0).additive_order()
1
charpoly()

Return the characteristic polynomial of self as a polynomial with given variable.

INPUT:

  • var - string (default: ‘x’)
  • algorithm - string (default: ‘matrix’)
    • ‘matrix’ - return the charpoly computed from the matrix of left multiplication by self
    • ‘pari’ – use pari’s charpoly routine on polymods, which is not very good except in small cases

The result is not cached.

EXAMPLES:

sage: k.<a> = GF(19^2)
sage: parent(a)
Finite Field in a of size 19^2
sage: a.charpoly('X')
X^2 + 18*X + 2
sage: a^2 + 18*a + 2
0            
sage: a.charpoly('X', algorithm='pari')
X^2 + 18*X + 2
frobenius()

Return the (p^k)^{th} power of self, where p is the characteristic of the field.

INPUT:

  • k - integer (default: 1, must fit in C int type)

Note that if k is negative, then this computes the appropriate root.

EXAMPLES:

sage: F.<a> = GF(29^2)
sage: z = a^2 + 5*a + 1
sage: z.pth_power()
19*a + 20
sage: z.pth_power(10)
10*a + 28
sage: z.pth_power(-10) == z
True
sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_power(-3))^(2^3)
True
sage: y.pth_power(2)
b^7 + b^6 + b^5 + b^4 + b^3 + b
matrix()

See _matrix_().

EXAMPLE:

sage: k.<a> = GF(2^16)
sage: e = a^2 + 1
sage: e.matrix() # random-ish error message
doctest:1: DeprecationWarning:The function matrix is replaced by _matrix_.
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
[1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0]
[0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1]
[0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1]
[0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0]
[0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1]
[0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1]
minimal_polynomial()

Returns the minimal polynomial of this element (over the corresponding prime subfield).

EXAMPLES:

sage: k.<a> = FiniteField(3^4)
sage: parent(a)
Finite Field in a of size 3^4
sage: b=a**20;p=charpoly(b,"y");p
y^4 + 2*y^2 + 1 
sage: factor(p)
(y^2 + 1)^2
sage: b.minimal_polynomial('y')
y^2 + 1
minpoly()

Returns the minimal polynomial of this element (over the corresponding prime subfield).

EXAMPLES:

sage: k.<a> = FiniteField(19^2)
sage: parent(a)
Finite Field in a of size 19^2
sage: b=a**20;p=b.charpoly("x");p
x^2 + 15*x + 4
sage: factor(p)
(x + 17)^2
sage: b.minpoly('x')
x + 17
multiplicative_order()
Return the multiplicative order of this field element.
norm()

Return the norm of self down to the prime subfield.

This is the product of the Galois conjugates of self.

EXAMPLES:

sage: S.<b> = GF(5^2); S
Finite Field in b of size 5^2
sage: b.norm()
2
sage: b.charpoly('t')
t^2 + 4*t + 2

Next we consider a cubic extension:

sage: S.<a> = GF(5^3); S
Finite Field in a of size 5^3
sage: a.norm()
2
sage: a.charpoly('t')
t^3 + 3*t + 3
sage: a * a^5 * (a^25)
2            
nth_root()

Returns an nth root of self.

INPUT:

  • n - integer >= 1 (must fit in C int type)
  • extend - bool (default: True); if True, return an nth root in an extension ring, if necessary. Otherwise, raise a ValueError if the root is not in the base ring. Warning: this option is not implemented!
  • all - bool (default: False); if True, return all nth roots of self, instead of just one.

OUTPUT:

If self has an nth root, returns one (if all == False) or a list of all of them (if all == True). Otherwise, raises a ValueError (if extend = False) or a NotImplementedError (if extend = True).

Warning

The ‘extend’ option is not implemented (yet).

AUTHOR:

  • David Roe (2007-10-3)
pth_power()

Return the (p^k)^{th} power of self, where p is the characteristic of the field.

INPUT:

  • k - integer (default: 1, must fit in C int type)

Note that if k is negative, then this computes the appropriate root.

EXAMPLES:

sage: F.<a> = GF(29^2)
sage: z = a^2 + 5*a + 1
sage: z.pth_power()
19*a + 20
sage: z.pth_power(10)
10*a + 28
sage: z.pth_power(-10) == z
True
sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_power(-3))^(2^3)
True
sage: y.pth_power(2)
b^7 + b^6 + b^5 + b^4 + b^3 + b
pth_root()

Return the (p^k)^{th} root of self, where p is the characteristic of the field.

INPUT:

  • k - integer (default: 1, must fit in C int type)

Note that if k is negative, then this computes the appropriate power.

EXAMPLES:

sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_root(3))^(2^3)
True
sage: y.pth_root(2)
b^11 + b^10 + b^9 + b^7 + b^5 + b^4 + b^2 + b
trace()

Return the trace of this element, which is the sum of the Galois conjugates.

EXAMPLES:

sage: S.<a> = GF(5^3); S
Finite Field in a of size 5^3
sage: a.trace()
0
sage: a.charpoly('t')
t^3 + 3*t + 3
sage: a + a^5 + a^25
0
sage: z = a^2 + a + 1
sage: z.trace()
2
sage: z.charpoly('t')
t^3 + 3*t^2 + 2*t + 2
sage: z + z^5 + z^25
2        
vector()

See _vector_().

EXAMPLE:

sage: k.<a> = GF(2^16)
sage: e = a^2 + 1
sage: e.vector() # random-ish error message
doctest:1: DeprecationWarning:The function vector is replaced by _vector_.
(1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
class sage.structure.element.InfinityElement
__invert__()
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.IntegralDomainElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
is_nilpotent()
class sage.structure.element.Matrix
__imul__()
__mul__()

Multiplication of matrix by matrix, vector, or scalar

AUTHOR:

  • Gonzalo Tornaria (2007-06-25) - write test cases and fix them

Note

scalar * matrix is implemented (and tested) in class RingElement vector * matrix is implemented (and tested) in class Vector

TESTS:

Here we test (matrix * matrix) multiplication:

sage: x, y = var('x, y')

sage: parent(matrix(ZZ,2,2,[1,2,3,4])*matrix(ZZ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(matrix(ZZ,2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ[x],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*matrix(QQ[x],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[y],2,2,[1,2,3,4])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*matrix(QQ[y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'

Here we test (matrix * vector) multiplication:

sage: parent(matrix(ZZ,2,2,[1,2,3,4])*vector(ZZ,[1,2]))
Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ,[1,2]))
Vector space of dimension 2 over Rational Field
sage: parent(matrix(ZZ,2,2,[1,2,3,4])*vector(QQ,[1,2]))
Vector space of dimension 2 over Rational Field
sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(QQ,[1,2]))
Vector space of dimension 2 over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ[x],[1,2]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*vector(QQ,[1,2]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*vector(QQ,[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*vector(QQ[x],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[y],2,2,[1,2,3,4])*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*vector(QQ[y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*vector(ZZ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*vector(QQ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*vector(ZZ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*vector(QQ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'

Here we test (matrix * scalar) multiplication:

sage: parent(matrix(ZZ,2,2,[1,2,3,4])*ZZ(1))
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ(1))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(matrix(ZZ,2,2,[1,2,3,4])*QQ(1))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(matrix(QQ,2,2,[1,2,3,4])*QQ(1))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ[x](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*QQ(1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ[x][y](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*QQ(1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*ZZ[x][y](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*QQ[x](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(QQ[y],2,2,[1,2,3,4])*ZZ[x][y](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(matrix(ZZ[x][y],2,2,[1,2,3,4])*QQ[y](1))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*ZZ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(ZZ[x],2,2,[1,2,3,4])*QQ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Rational Field'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*ZZ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Integer Ring'
sage: parent(matrix(QQ[x],2,2,[1,2,3,4])*QQ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field'
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__rmul__()
x.__rmul__(y) <==> y*x
class sage.structure.element.MinusInfinityElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.ModuleElement

Generic element of a module.

__add__()

Top-level addition operator for ModuleElements.

See extensive documentation at the top of element.pyx.

__iadd__()
__imul__()
__isub__()
__mul__()
__neg__()
Top-level negation operator for ModuleElements, which may choose to implement _neg_ rather than __neg__ for consistency.
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__radd__()
x.__radd__(y) <==> y+x
__rmul__()
x.__rmul__(y) <==> y*x
__rsub__()
x.__rsub__(y) <==> y-x
__sub__()
Top-level subtraction operator for ModuleElements. See extensive documentation at the top of element.pyx.
_add_()
_iadd_()
_ilmul_()
_isub_()
_lmul_()

Default module left scalar multiplication, which is to try to canonically coerce the scalar to the integers and do that multiplication, which is always defined.

The coercion model will catch this error and create the appropriate action.

_neg_()
_rmul_()

Default module left scalar multiplication, which is to try to canonically coerce the scalar to the integers and do that multiplication, which is always defined.

The coercion model will catch this error and create the appropriate action.

_sub_()
additive_order()
Return the additive order of self.
order()
Return the additive order of self.
class sage.structure.element.MonoidElement

Generic element of a monoid.

__mul__()
Top-level multiplication operator for monoid elements. See extensive documentation at the top of element.pyx.
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__rmul__()
x.__rmul__(y) <==> y*x
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
_mul_()
Cython classes should override this function to implement multiplication. See extensive documentation at the top of element.pyx.
multiplicative_order()
Return the multiplicative order of self.
order()
Return the multiplicative order of self.
class sage.structure.element.MultiplicativeGroupElement

Generic element of a multiplicative group.

__div__()
__invert__()
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__rdiv__()
x.__rdiv__(y) <==> y/x
_add_()
_div_()
Cython classes should override this function to implement division. See extensive documentation at the top of element.pyx.
order()
Return the multiplicative order of self.
class sage.structure.element.PlusInfinityElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
class sage.structure.element.PrincipalIdealDomainElement
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
gcd()
Returns the gcd of self and right, or 0 if both are 0.
lcm()
Returns the least common multiple of self and right.
xgcd()

Return the extended gcd of self and other, i.e., elements r, s, t such that .. math:

r = s \cdot self + t \cdot other.

Note

There is no guarantee on minimality of the cofactors. In the integer case, see documentation for Integer._xgcd() to obtain minimal cofactors.

class sage.structure.element.RingElement
__div__()
Top-level multiplication operator for ring elements. See extensive documentation at the top of element.pyx.
__idiv__()
Top-level division operator for ring elements. See extensive documentation at the top of element.pyx.
__imul__()
__invert__()
__mul__()

Top-level multiplication operator for ring elements. See extensive documentation at the top of element.pyx.

AUTHOR:

  • Gonzalo Tornaria (2007-06-25) - write base-extending test cases and fix them

TESTS:

Here we test (scalar * vector) multiplication:

sage: x, y = var('x, y')

sage: parent(ZZ(1)*vector(ZZ,[1,2]))
Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: parent(QQ(1)*vector(ZZ,[1,2]))
Vector space of dimension 2 over Rational Field
sage: parent(ZZ(1)*vector(QQ,[1,2]))
Vector space of dimension 2 over Rational Field
sage: parent(QQ(1)*vector(QQ,[1,2]))
Vector space of dimension 2 over Rational Field

sage: parent(QQ(1)*vector(ZZ[x],[1,2]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x](1)*vector(QQ,[1,2]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ(1)*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*vector(QQ,[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ[x](1)*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*vector(QQ[x],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ[y](1)*vector(ZZ[x][y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*vector(QQ[y],[1,2]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(ZZ[x](1)*vector(ZZ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(ZZ[x](1)*vector(QQ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'
sage: parent(QQ[x](1)*vector(ZZ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(QQ[x](1)*vector(QQ[y],[1,2]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'

Here we test (scalar * matrix) multiplication:

sage: parent(ZZ(1)*matrix(ZZ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
sage: parent(QQ(1)*matrix(ZZ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(ZZ(1)*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: parent(QQ(1)*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

sage: parent(QQ(1)*matrix(ZZ[x],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x](1)*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ(1)*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*matrix(QQ,2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ[x](1)*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*matrix(QQ[x],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(QQ[y](1)*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(ZZ[x][y](1)*matrix(QQ[y],2,2,[1,2,3,4]))
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(ZZ[x](1)*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(ZZ[x](1)*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'
sage: parent(QQ[x](1)*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(QQ[x](1)*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__rdiv__()
x.__rdiv__(y) <==> y/x
__rmul__()
x.__rmul__(y) <==> y*x
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
__rtruediv__()
x.__rtruediv__(y) <==> y/x
__truediv__()
_div_()
Cython classes should override this function to implement division. See extensive documentation at the top of element.pyx.
_idiv_()
_imul_()
_lmul_()
_mul_()
Cython classes should override this function to implement multiplication. See extensive documentation at the top of element.pyx.
_rmul_()
abs()

Return the absolute value of self. (This just calls the __abs__ method, so it is equivalent to the abs() built-in function.)

EXAMPLES:

sage: RR(-1).abs()
1.00000000000000
sage: ZZ(-1).abs()
1
sage: CC(I).abs()
1.00000000000000
sage: Mod(-15, 37).abs()
...
ArithmeticError: absolute valued not defined on integers modulo n.
additive_order()
Return the additive order of self.
is_nilpotent()
Return True if self is nilpotent, i.e., some power of self is 0.
is_one()
is_unit()
multiplicative_order()
Return the multiplicative order of self, if self is a unit, or raise ArithmeticError otherwise.
order()

Return the additive order of self.

This is deprecated; use additive_order instead.

EXAMPLES:

sage: a = Integers(12)(5)
sage: a.order()
doctest... DeprecationWarning: The function order is deprecated for ring elements; use additive_order or multiplicative_order instead.
12
class sage.structure.element.Vector
__div__()
__imul__()
__mul__()

Multiplication of vector by vector, matrix, or scalar

AUTHOR:

  • Gonzalo Tornaria (2007-06-21) - write test cases and fix them

Note

scalar * vector is implemented (and tested) in class RingElement matrix * vector is implemented (and tested) in class Matrix

TESTS:

Here we test (vector * vector) multiplication:

sage: x, y = var('x, y')

sage: parent(vector(ZZ,[1,2])*vector(ZZ,[1,2]))
Integer Ring
sage: parent(vector(ZZ,[1,2])*vector(QQ,[1,2]))
Rational Field
sage: parent(vector(QQ,[1,2])*vector(ZZ,[1,2]))
Rational Field
sage: parent(vector(QQ,[1,2])*vector(QQ,[1,2]))
Rational Field

sage: parent(vector(QQ,[1,2,3,4])*vector(ZZ[x],[1,2,3,4]))
Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x],[1,2,3,4])*vector(QQ,[1,2,3,4]))
Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ,[1,2,3,4])*vector(ZZ[x][y],[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2,3,4])*vector(QQ,[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[x],[1,2,3,4])*vector(ZZ[x][y],[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2,3,4])*vector(QQ[x],[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[y],[1,2,3,4])*vector(ZZ[x][y],[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2,3,4])*vector(QQ[y],[1,2,3,4]))
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(ZZ[x],[1,2,3,4])*vector(ZZ[y],[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(ZZ[x],[1,2,3,4])*vector(QQ[y],[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'
sage: parent(vector(QQ[x],[1,2,3,4])*vector(ZZ[y],[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(QQ[x],[1,2,3,4])*vector(QQ[y],[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field'

Here we test (vector * matrix) multiplication:

sage: parent(vector(ZZ,[1,2])*matrix(ZZ,2,2,[1,2,3,4]))
Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: parent(vector(QQ,[1,2])*matrix(ZZ,2,2,[1,2,3,4]))
Vector space of dimension 2 over Rational Field
sage: parent(vector(ZZ,[1,2])*matrix(QQ,2,2,[1,2,3,4]))
Vector space of dimension 2 over Rational Field
sage: parent(vector(QQ,[1,2])*matrix(QQ,2,2,[1,2,3,4]))
Vector space of dimension 2 over Rational Field

sage: parent(vector(QQ,[1,2])*matrix(ZZ[x],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x],[1,2])*matrix(QQ,2,2,[1,2,3,4]))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ,[1,2])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*matrix(QQ,2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[x],[1,2])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*matrix(QQ[x],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[y],[1,2])*matrix(ZZ[x][y],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*matrix(QQ[y],2,2,[1,2,3,4]))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(ZZ[x],[1,2])*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(ZZ[x],[1,2])*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'
sage: parent(vector(QQ[x],[1,2])*matrix(ZZ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(QQ[x],[1,2])*matrix(QQ[y],2,2,[1,2,3,4]))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field'

Here we test (vector * scalar) multiplication:

sage: parent(vector(ZZ,[1,2])*ZZ(1))
Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: parent(vector(QQ,[1,2])*ZZ(1))
Vector space of dimension 2 over Rational Field
sage: parent(vector(ZZ,[1,2])*QQ(1))
Vector space of dimension 2 over Rational Field
sage: parent(vector(QQ,[1,2])*QQ(1))
Vector space of dimension 2 over Rational Field

sage: parent(vector(QQ,[1,2])*ZZ[x](1))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x],[1,2])*QQ(1))
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ,[1,2])*ZZ[x][y](1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*QQ(1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[x],[1,2])*ZZ[x][y](1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*QQ[x](1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(QQ[y],[1,2])*ZZ[x][y](1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
sage: parent(vector(ZZ[x][y],[1,2])*QQ[y](1))
Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field

sage: parent(vector(ZZ[x],[1,2])*ZZ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(ZZ[x],[1,2])*QQ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Rational Field'
sage: parent(vector(QQ[x],[1,2])*ZZ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Integer Ring'
sage: parent(vector(QQ[x],[1,2])*QQ[y](1))
...
TypeError: unsupported operand parent(s) for '*': 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field'
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__rdiv__()
x.__rdiv__(y) <==> y/x
__rmul__()
x.__rmul__(y) <==> y*x
_dot_product_()
_magma_init_()

Return string that evaluates in Magma to something equivalent to this vector.

EXAMPLES:

sage: v = vector([1,2,3])
sage: v._magma_init_(magma)                 # optional - magma
'_sage_[...]![1,2,3]'
sage: mv = magma(v); mv                     # optional - magma
(1 2 3)
sage: mv.Type()                             # optional - magma
ModTupRngElt
sage: mv.Parent()                           # optional - magma 
Full RSpace of degree 3 over Integer Ring

sage: v = vector(QQ, [1/2, 3/4, 5/6])
sage: mv = magma(v); mv                     # optional - magma 
(1/2 3/4 5/6)
sage: mv.Type()                             # optional - magma 
ModTupFldElt
sage: mv.Parent()                           # optional - magma 
Full Vector space of degree 3 over Rational Field

A more demanding example:

sage: R.<x,y,z> = QQ[]
sage: v = vector([x^3, y, 2/3*z + x/y])
sage: magma(v)                              # optional - magma 
(            x^3               y (2/3*y*z + x)/y)
sage: magma(v).Parent()                     # optional - magma 
Full Vector space of degree 3 over Multivariate rational function field of rank 3 over Rational Field
_pairwise_product_()
sage.structure.element.bin_op()
sage.structure.element.canonical_coercion()

canonical_coercion(x,y) is what is called before doing an arithmetic operation between x and y. It returns a pair (z,w) such that z is got from x and w from y via canonical coercion and the parents of z and w are identical.

EXAMPLES:

sage: A = Matrix([[0,1],[1,0]])
sage: canonical_coercion(A,1)
([0 1]
[1 0], [1 0]
[0 1])
sage.structure.element.coerce_cmp()
sage.structure.element.coercion_traceback()

This function is very helpful in debugging coercion errors. It prints the tracebacks of all the errors caught in the coercion detection. Note that failure is cached, so some errors may be omitted the second time around (as it remembers not to retry failed paths for speed reasons.

EXAMPLES:

sage: 1 + 1/5
6/5
sage: coercion_traceback()  # Should be empty, as all went well.
sage: 1/5 + GF(5).gen()
...
TypeError: unsupported operand parent(s) for '+': 'Rational Field' and 'Finite Field of size 5'
sage: coercion_traceback()
...
TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 5'
sage.structure.element.gcd()
sage.structure.element.generic_power()

Computes a^n, where n is an integer, and a is an object which supports multiplication. Optionally an additional argument, which is used in the case that n == 0:

  • one - the “unit” element, returned directly (can be anything)

If this is not supplied, int(1) is returned.

EXAMPLES:

sage: from sage.structure.element import generic_power
sage: generic_power(int(12),int(0))
1
sage: generic_power(int(0),int(100))
0
sage: generic_power(Integer(10),Integer(0))
1
sage: generic_power(Integer(0),Integer(23))
0
sage: sum([generic_power(2,i) for i in range(17)]) #test all 4-bit combinations
131071
sage: F = Zmod(5)
sage: a = generic_power(F(2), 5); a
2
sage: a.parent() is F
True
sage: a = generic_power(F(1), 2)
sage: a.parent() is F
True

sage: generic_power(int(5), 0)
1
sage.structure.element.get_coercion_model()

Return the global coercion model.

EXAMPLES:

sage: import sage.structure.element as e
sage: cm = e.get_coercion_model()
sage: cm
<sage.structure.coerce.CoercionModel_cache_maps object at ...>
sage.structure.element.is_AdditiveGroupElement()
Return True if x is of type AdditiveGroupElement.
sage.structure.element.is_AlgebraElement()
Return True if x is of type AlgebraElement.
sage.structure.element.is_CommutativeAlgebraElement()
Return True if x is of type CommutativeAlgebraElement.
sage.structure.element.is_CommutativeRingElement()
Return True if x is of type CommutativeRingElement.
sage.structure.element.is_DedekindDomainElement()
Return True if x is of type DedekindDomainElement.
sage.structure.element.is_Element()

Return True if x is of type Element.

EXAMPLES:

sage: from sage.structure.element import is_Element
sage: is_Element(2/3)
True
sage: is_Element(QQ^3)
False
sage.structure.element.is_EuclideanDomainElement()
Return True if x is of type EuclideanDomainElement.
sage.structure.element.is_FieldElement()
Return True if x is of type FieldElement.
sage.structure.element.is_InfinityElement()
Return True if x is of type InfinityElement.
sage.structure.element.is_IntegralDomainElement()
Return True if x is of type IntegralDomainElement.
sage.structure.element.is_Matrix()
sage.structure.element.is_ModuleElement()

Return True if x is of type ModuleElement.

This is even faster than using isinstance inline.

EXAMPLES:

sage: from sage.structure.element import is_ModuleElement
sage: is_ModuleElement(2/3)
True
sage: is_ModuleElement((QQ^3).0)
True
sage: is_ModuleElement('a')
False
sage.structure.element.is_MonoidElement()
Return True if x is of type MonoidElement.
sage.structure.element.is_MultiplicativeGroupElement()
Return True if x is of type MultiplicativeGroupElement.
sage.structure.element.is_PrincipalIdealDomainElement()
Return True if x is of type PrincipalIdealDomainElement.
sage.structure.element.is_RingElement()
Return True if x is of type RingElement.
sage.structure.element.is_Vector()
sage.structure.element.lcm()
sage.structure.element.make_element()

This function is only here to support old pickles.

Pickling functionality is moved to Element.{__getstate__,__setstate__} functions.

sage.structure.element.parent()
sage.structure.element.py_scalar_to_element()
sage.structure.element.set_coercion_model()
sage.structure.element.xgcd()

Table Of Contents

Previous topic

Factorizations

Next topic

UniqueRepresentation

This Page