AUTHORS:
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
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:
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.
Generic element of an additive group.
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.
Most basic coercion scheme. If it doesn’t already match, throw an error.
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
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 .
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 . For example, reduction is not
implemented for
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 is eliminated. In the next example,
both
and
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 is eliminated:
sage: (x^2 + y^2 + z^2).mod( (x^3, y - z) )
x^2 + 2*z^2
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.
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,)})
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
Return True if and only if parenthesis are not required when
printing out any of ,
,
and
.
EXAMPLES:
sage: n = 5; n._is_atomic()
True
sage: n = x+1; n._is_atomic()
False
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')
INPUT:
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.
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
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:
OUTPUT:
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
This is an alias for self.subs().
INPUT:
OUTPUT:
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
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)
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
Return the greatest common divisor of self and other.
Algorithm 3.2.1 in Cohen, GTM 138.
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
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
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
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'
Return the matrix of right multiplication by the element on
the power basis for the field
extension. Thus the emph{rows} of this matrix give the images
of each of the
.
INPUT:
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))
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))'
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)
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
Return the characteristic polynomial of self as a polynomial with given variable.
INPUT:
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
Return the power of self, where
is the
characteristic of the field.
INPUT:
Note that if 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
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]
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
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
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
Returns an nth root of self.
INPUT:
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:
Return the power of self, where
is the
characteristic of the field.
INPUT:
Note that if 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
Return the root of self, where
is the characteristic
of the field.
INPUT:
Note that if 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
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
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)
Multiplication of matrix by matrix, vector, or scalar
AUTHOR:
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'
Generic element of a module.
Top-level addition operator for ModuleElements.
See extensive documentation at the top of element.pyx.
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.
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.
Generic element of a monoid.
Generic element of a multiplicative group.
Return the extended gcd of self and other, i.e., elements 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.
Top-level multiplication operator for ring elements. See extensive documentation at the top of element.pyx.
AUTHOR:
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'
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.
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
Multiplication of vector by vector, matrix, or scalar
AUTHOR:
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'
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
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])
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'
Computes , where
is an integer, and
is an object which
supports multiplication. Optionally an additional argument,
which is used in the case that n == 0:
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
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 ...>
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
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
This function is only here to support old pickles.
Pickling functionality is moved to Element.{__getstate__,__setstate__} functions.