CoCalc Public Filestmp / 2014-10-25-170111.sagews
Authors: Harald Schilly, ℏal Snyder, William A. Stein
help(matrix)

Help on MatrixFactory in module sage.matrix.constructor object: class MatrixFactory(__builtin__.object) | Create a matrix. | | This implements the matrix constructor:: | | sage: matrix([[1,2],[3,4]]) | [1 2] | [3 4] | | It also contains methods to create special types of matrices, see | matrix.[tab] for more options. For example:: | | sage: matrix.identity(2) | [1 0] | [0 1] | | INPUT: | | The matrix command takes the entries of a matrix, optionally | preceded by a ring and the dimensions of the matrix, and returns a | matrix. | | The entries of a matrix can be specified as a flat list of | elements, a list of lists (i.e., a list of rows), a list of Sage | vectors, a callable object, or a dictionary having positions as | keys and matrix entries as values (see the examples). If you pass | in a callable object, then you must specify the number of rows and | columns. You can create a matrix of zeros by passing an empty list | or the integer zero for the entries. To construct a multiple of | the identity (cI), you can specify square dimensions and pass in | c. Calling matrix() with a Sage object may return something that | makes sense. Calling matrix() with a NumPy array will convert the | array to a matrix. | | The ring, number of rows, and number of columns of the matrix can | be specified by setting the ring, nrows, or ncols parameters or by | passing them as the first arguments to the function in the order | ring, nrows, ncols. The ring defaults to ZZ if it is not specified | or cannot be determined from the entries. If the numbers of rows | and columns are not specified and cannot be determined, then an | empty 0x0 matrix is returned. | | | - ring - the base ring for the entries of the | matrix. | | - nrows - the number of rows in the matrix. | | - ncols - the number of columns in the matrix. | | - sparse - create a sparse matrix. This defaults | to True when the entries are given as a dictionary, otherwise | defaults to False. | | | OUTPUT: | | a matrix | | EXAMPLES:: | | sage: m=matrix(2); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | | :: | | sage: m=matrix(2,3); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | | :: | | sage: m=matrix(QQ,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m = matrix(QQ, 3, 3, lambda i, j: i+j); m | [0 1 2] | [1 2 3] | [2 3 4] | sage: m = matrix(3, lambda i,j: i-j); m | [ 0 -1 -2] | [ 1 0 -1] | [ 2 1 0] | | :: | | sage: matrix(QQ,2,3,lambda x, y: x+y) | [0 1 2] | [1 2 3] | sage: matrix(QQ,3,2,lambda x, y: x+y) | [0 1] | [1 2] | [2 3] | | :: | | sage: v1=vector((1,2,3)) | sage: v2=vector((4,5,6)) | sage: m=matrix([v1,v2]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | | :: | | sage: m=matrix(QQ,2,[1,2,3,4,5,6]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m=matrix(QQ,2,3,[1,2,3,4,5,6]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m=matrix({(0,1): 2, (1,1):2/5}); m; m.parent() | [ 0 2] | [ 0 2/5] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | | :: | | sage: m=matrix(QQ,2,3,{(1,1): 2}); m; m.parent() | [0 0 0] | [0 2 0] | Full MatrixSpace of 2 by 3 sparse matrices over Rational Field | | :: | | sage: import numpy | sage: n=numpy.array([[1,2],[3,4]],float) | sage: m=matrix(n); m; m.parent() | [1.0 2.0] | [3.0 4.0] | Full MatrixSpace of 2 by 2 dense matrices over Real Double Field | | :: | | sage: v = vector(ZZ, [1, 10, 100]) | sage: m=matrix(v); m; m.parent() | [ 1 10 100] | Full MatrixSpace of 1 by 3 dense matrices over Integer Ring | sage: m=matrix(GF(7), v); m; m.parent() | [1 3 2] | Full MatrixSpace of 1 by 3 dense matrices over Finite Field of size 7 | | :: | | sage: g = graphs.PetersenGraph() | sage: m = matrix(g); m; m.parent() | [0 1 0 0 1 1 0 0 0 0] | [1 0 1 0 0 0 1 0 0 0] | [0 1 0 1 0 0 0 1 0 0] | [0 0 1 0 1 0 0 0 1 0] | [1 0 0 1 0 0 0 0 0 1] | [1 0 0 0 0 0 0 1 1 0] | [0 1 0 0 0 0 0 0 1 1] | [0 0 1 0 0 1 0 0 0 1] | [0 0 0 1 0 1 1 0 0 0] | [0 0 0 0 1 0 1 1 0 0] | Full MatrixSpace of 10 by 10 dense matrices over Integer Ring | | :: | | sage: matrix(ZZ, 10, 10, range(100), sparse=True).parent() | Full MatrixSpace of 10 by 10 sparse matrices over Integer Ring | | :: | | sage: R = PolynomialRing(QQ, 9, 'x') | sage: A = matrix(R, 3, 3, R.gens()); A | [x0 x1 x2] | [x3 x4 x5] | [x6 x7 x8] | sage: det(A) | -x2*x4*x6 + x1*x5*x6 + x2*x3*x7 - x0*x5*x7 - x1*x3*x8 + x0*x4*x8 | | TESTS:: | | sage: m=matrix(); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(QQ); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Rational Field | sage: m=matrix(QQ,2); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 dense matrices over Rational Field | sage: m=matrix(QQ,2,3); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix([]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(QQ,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Rational Field | sage: m=matrix(2,2,1); m; m.parent() | [1 0] | [0 1] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | sage: m=matrix(QQ,2,2,1); m; m.parent() | [1 0] | [0 1] | Full MatrixSpace of 2 by 2 dense matrices over Rational Field | sage: m=matrix(2,3,0); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix(QQ,2,3,0); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix([[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix(QQ,2,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix(QQ,3,[[1,2,3],[4,5,6]]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: Number of rows does not match up with specified number. | sage: m=matrix(QQ,2,3,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix(QQ,2,4,[[1,2,3],[4,5,6]]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: Number of columns does not match up with specified number. | sage: m=matrix([(1,2,3),(4,5,6)]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix([1,2,3,4,5,6]); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Integer Ring | sage: m=matrix((1,2,3,4,5,6)); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Integer Ring | sage: m=matrix(QQ,[1,2,3,4,5,6]); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Rational Field | sage: m=matrix(QQ,3,2,[1,2,3,4,5,6]); m; m.parent() | [1 2] | [3 4] | [5 6] | Full MatrixSpace of 3 by 2 dense matrices over Rational Field | sage: m=matrix(QQ,2,4,[1,2,3,4,5,6]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: entries has the wrong length | sage: m=matrix(QQ,5,[1,2,3,4,5,6]); m; m.parent() | Traceback (most recent call last): | ... | TypeError: cannot construct an element of | Full MatrixSpace of 5 by 1 dense matrices over Rational Field | from [1, 2, 3, 4, 5, 6]! | sage: m=matrix({(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring | sage: m=matrix(QQ,{(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,3,{(1,1): 2}); m; m.parent() | [0 0 0] | [0 2 0] | [0 0 0] | Full MatrixSpace of 3 by 3 sparse matrices over Rational Field | sage: m=matrix(QQ,3,4,{(1,1): 2}); m; m.parent() | [0 0 0 0] | [0 2 0 0] | [0 0 0 0] | Full MatrixSpace of 3 by 4 sparse matrices over Rational Field | sage: m=matrix(QQ,2,{(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,1,{(1,1): 2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: m=matrix({}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring | sage: m=matrix(QQ,{}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Rational Field | sage: m=matrix(QQ,2,{}); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,2,3,{}); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 sparse matrices over Rational Field | sage: m=matrix(2,{}); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring | sage: m=matrix(2,3,{}); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 sparse matrices over Integer Ring | sage: m=matrix(0); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(0,2); m; m.parent() | [] | Full MatrixSpace of 0 by 2 dense matrices over Integer Ring | sage: m=matrix(2,0); m; m.parent() | [] | Full MatrixSpace of 2 by 0 dense matrices over Integer Ring | sage: m=matrix(0,[1]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: entries has the wrong length | sage: m=matrix(1,0,[]); m; m.parent() | [] | Full MatrixSpace of 1 by 0 dense matrices over Integer Ring | sage: m=matrix(0,1,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 1 dense matrices over Integer Ring | sage: m=matrix(0,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(0,{}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring | sage: m=matrix(0,{(1,1):2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: m=matrix(2,0,{(1,1):2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: import numpy | sage: n=numpy.array([[numpy.complex(0,1),numpy.complex(0,2)],[3,4]],complex) | sage: m=matrix(n); m; m.parent() | [1.0*I 2.0*I] | [ 3.0 4.0] | Full MatrixSpace of 2 by 2 dense matrices over Complex Double Field | sage: n=numpy.array([[1,2],[3,4]],'int32') | sage: m=matrix(n); m; m.parent() | [1 2] | [3 4] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | sage: n = numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float32') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Real Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float64') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Real Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'complex64') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'complex128') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field | sage: a = matrix([[1,2],[3,4]]) | sage: b = matrix(a.numpy()); b | [1 2] | [3 4] | sage: a == b | True | sage: c = matrix(a.numpy('float32')); c | [1.0 2.0] | [3.0 4.0] | sage: matrix(numpy.array([[5]])) | [5] | sage: v = vector(ZZ, [1, 10, 100]) | sage: m=matrix(ZZ['x'], v); m; m.parent() | [ 1 10 100] | Full MatrixSpace of 1 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring | sage: matrix(ZZ, 10, 10, range(100)).parent() | Full MatrixSpace of 10 by 10 dense matrices over Integer Ring | sage: m = matrix(GF(7), [[1/3,2/3,1/2], [3/4,4/5,7]]); m; m.parent() | [5 3 4] | [6 5 0] | Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 7 | sage: m = matrix([[1,2,3], [RDF(2), CDF(1,2), 3]]); m; m.parent() | [ 1.0 2.0 3.0] | [ 2.0 1.0 + 2.0*I 3.0] | Full MatrixSpace of 2 by 3 dense matrices over Complex Double Field | sage: m=matrix(3,3,1/2); m; m.parent() | [1/2 0 0] | [ 0 1/2 0] | [ 0 0 1/2] | Full MatrixSpace of 3 by 3 dense matrices over Rational Field | sage: matrix([[1],[2,3]]) | Traceback (most recent call last): | ... | ValueError: List of rows is not valid (rows are wrong types or lengths) | sage: matrix([[1],2]) | Traceback (most recent call last): | ... | ValueError: List of rows is not valid (rows are wrong types or lengths) | sage: matrix(vector(RR,[1,2,3])).parent() | Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision | sage: matrix(ZZ, [[0] for i in range(10^5)]).is_zero() # see #10158 | True | | AUTHORS: | | - ??: Initial implementation | | - Jason Grout (2008-03): almost a complete rewrite, with bits and | pieces from the original implementation | | Static methods defined here: | | __call__ = _matrix_constructor(*args, **kwds) | Create a matrix. | | This implements the matrix constructor:: | | sage: matrix([[1,2],[3,4]]) | [1 2] | [3 4] | | It also contains methods to create special types of matrices, see | matrix.[tab] for more options. For example:: | | sage: matrix.identity(2) | [1 0] | [0 1] | | INPUT: | | The matrix command takes the entries of a matrix, optionally | preceded by a ring and the dimensions of the matrix, and returns a | matrix. | | The entries of a matrix can be specified as a flat list of | elements, a list of lists (i.e., a list of rows), a list of Sage | vectors, a callable object, or a dictionary having positions as | keys and matrix entries as values (see the examples). If you pass | in a callable object, then you must specify the number of rows and | columns. You can create a matrix of zeros by passing an empty list | or the integer zero for the entries. To construct a multiple of | the identity (cI), you can specify square dimensions and pass in | c. Calling matrix() with a Sage object may return something that | makes sense. Calling matrix() with a NumPy array will convert the | array to a matrix. | | The ring, number of rows, and number of columns of the matrix can | be specified by setting the ring, nrows, or ncols parameters or by | passing them as the first arguments to the function in the order | ring, nrows, ncols. The ring defaults to ZZ if it is not specified | or cannot be determined from the entries. If the numbers of rows | and columns are not specified and cannot be determined, then an | empty 0x0 matrix is returned. | | | - ring - the base ring for the entries of the | matrix. | | - nrows - the number of rows in the matrix. | | - ncols - the number of columns in the matrix. | | - sparse - create a sparse matrix. This defaults | to True when the entries are given as a dictionary, otherwise | defaults to False. | | | OUTPUT: | | a matrix | | EXAMPLES:: | | sage: m=matrix(2); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | | :: | | sage: m=matrix(2,3); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | | :: | | sage: m=matrix(QQ,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m = matrix(QQ, 3, 3, lambda i, j: i+j); m | [0 1 2] | [1 2 3] | [2 3 4] | sage: m = matrix(3, lambda i,j: i-j); m | [ 0 -1 -2] | [ 1 0 -1] | [ 2 1 0] | | :: | | sage: matrix(QQ,2,3,lambda x, y: x+y) | [0 1 2] | [1 2 3] | sage: matrix(QQ,3,2,lambda x, y: x+y) | [0 1] | [1 2] | [2 3] | | :: | | sage: v1=vector((1,2,3)) | sage: v2=vector((4,5,6)) | sage: m=matrix([v1,v2]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | | :: | | sage: m=matrix(QQ,2,[1,2,3,4,5,6]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m=matrix(QQ,2,3,[1,2,3,4,5,6]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | | :: | | sage: m=matrix({(0,1): 2, (1,1):2/5}); m; m.parent() | [ 0 2] | [ 0 2/5] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | | :: | | sage: m=matrix(QQ,2,3,{(1,1): 2}); m; m.parent() | [0 0 0] | [0 2 0] | Full MatrixSpace of 2 by 3 sparse matrices over Rational Field | | :: | | sage: import numpy | sage: n=numpy.array([[1,2],[3,4]],float) | sage: m=matrix(n); m; m.parent() | [1.0 2.0] | [3.0 4.0] | Full MatrixSpace of 2 by 2 dense matrices over Real Double Field | | :: | | sage: v = vector(ZZ, [1, 10, 100]) | sage: m=matrix(v); m; m.parent() | [ 1 10 100] | Full MatrixSpace of 1 by 3 dense matrices over Integer Ring | sage: m=matrix(GF(7), v); m; m.parent() | [1 3 2] | Full MatrixSpace of 1 by 3 dense matrices over Finite Field of size 7 | | :: | | sage: g = graphs.PetersenGraph() | sage: m = matrix(g); m; m.parent() | [0 1 0 0 1 1 0 0 0 0] | [1 0 1 0 0 0 1 0 0 0] | [0 1 0 1 0 0 0 1 0 0] | [0 0 1 0 1 0 0 0 1 0] | [1 0 0 1 0 0 0 0 0 1] | [1 0 0 0 0 0 0 1 1 0] | [0 1 0 0 0 0 0 0 1 1] | [0 0 1 0 0 1 0 0 0 1] | [0 0 0 1 0 1 1 0 0 0] | [0 0 0 0 1 0 1 1 0 0] | Full MatrixSpace of 10 by 10 dense matrices over Integer Ring | | :: | | sage: matrix(ZZ, 10, 10, range(100), sparse=True).parent() | Full MatrixSpace of 10 by 10 sparse matrices over Integer Ring | | :: | | sage: R = PolynomialRing(QQ, 9, 'x') | sage: A = matrix(R, 3, 3, R.gens()); A | [x0 x1 x2] | [x3 x4 x5] | [x6 x7 x8] | sage: det(A) | -x2*x4*x6 + x1*x5*x6 + x2*x3*x7 - x0*x5*x7 - x1*x3*x8 + x0*x4*x8 | | TESTS:: | | sage: m=matrix(); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(QQ); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Rational Field | sage: m=matrix(QQ,2); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 dense matrices over Rational Field | sage: m=matrix(QQ,2,3); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix([]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(QQ,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Rational Field | sage: m=matrix(2,2,1); m; m.parent() | [1 0] | [0 1] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | sage: m=matrix(QQ,2,2,1); m; m.parent() | [1 0] | [0 1] | Full MatrixSpace of 2 by 2 dense matrices over Rational Field | sage: m=matrix(2,3,0); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix(QQ,2,3,0); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix([[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix(QQ,2,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix(QQ,3,[[1,2,3],[4,5,6]]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: Number of rows does not match up with specified number. | sage: m=matrix(QQ,2,3,[[1,2,3],[4,5,6]]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Rational Field | sage: m=matrix(QQ,2,4,[[1,2,3],[4,5,6]]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: Number of columns does not match up with specified number. | sage: m=matrix([(1,2,3),(4,5,6)]); m; m.parent() | [1 2 3] | [4 5 6] | Full MatrixSpace of 2 by 3 dense matrices over Integer Ring | sage: m=matrix([1,2,3,4,5,6]); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Integer Ring | sage: m=matrix((1,2,3,4,5,6)); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Integer Ring | sage: m=matrix(QQ,[1,2,3,4,5,6]); m; m.parent() | [1 2 3 4 5 6] | Full MatrixSpace of 1 by 6 dense matrices over Rational Field | sage: m=matrix(QQ,3,2,[1,2,3,4,5,6]); m; m.parent() | [1 2] | [3 4] | [5 6] | Full MatrixSpace of 3 by 2 dense matrices over Rational Field | sage: m=matrix(QQ,2,4,[1,2,3,4,5,6]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: entries has the wrong length | sage: m=matrix(QQ,5,[1,2,3,4,5,6]); m; m.parent() | Traceback (most recent call last): | ... | TypeError: cannot construct an element of | Full MatrixSpace of 5 by 1 dense matrices over Rational Field | from [1, 2, 3, 4, 5, 6]! | sage: m=matrix({(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring | sage: m=matrix(QQ,{(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,3,{(1,1): 2}); m; m.parent() | [0 0 0] | [0 2 0] | [0 0 0] | Full MatrixSpace of 3 by 3 sparse matrices over Rational Field | sage: m=matrix(QQ,3,4,{(1,1): 2}); m; m.parent() | [0 0 0 0] | [0 2 0 0] | [0 0 0 0] | Full MatrixSpace of 3 by 4 sparse matrices over Rational Field | sage: m=matrix(QQ,2,{(1,1): 2}); m; m.parent() | [0 0] | [0 2] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,1,{(1,1): 2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: m=matrix({}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring | sage: m=matrix(QQ,{}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Rational Field | sage: m=matrix(QQ,2,{}); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 sparse matrices over Rational Field | sage: m=matrix(QQ,2,3,{}); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 sparse matrices over Rational Field | sage: m=matrix(2,{}); m; m.parent() | [0 0] | [0 0] | Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring | sage: m=matrix(2,3,{}); m; m.parent() | [0 0 0] | [0 0 0] | Full MatrixSpace of 2 by 3 sparse matrices over Integer Ring | sage: m=matrix(0); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(0,2); m; m.parent() | [] | Full MatrixSpace of 0 by 2 dense matrices over Integer Ring | sage: m=matrix(2,0); m; m.parent() | [] | Full MatrixSpace of 2 by 0 dense matrices over Integer Ring | sage: m=matrix(0,[1]); m; m.parent() | Traceback (most recent call last): | ... | ValueError: entries has the wrong length | sage: m=matrix(1,0,[]); m; m.parent() | [] | Full MatrixSpace of 1 by 0 dense matrices over Integer Ring | sage: m=matrix(0,1,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 1 dense matrices over Integer Ring | sage: m=matrix(0,[]); m; m.parent() | [] | Full MatrixSpace of 0 by 0 dense matrices over Integer Ring | sage: m=matrix(0,{}); m; m.parent() | [] | Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring | sage: m=matrix(0,{(1,1):2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: m=matrix(2,0,{(1,1):2}); m; m.parent() | Traceback (most recent call last): | ... | IndexError: invalid entries list | sage: import numpy | sage: n=numpy.array([[numpy.complex(0,1),numpy.complex(0,2)],[3,4]],complex) | sage: m=matrix(n); m; m.parent() | [1.0*I 2.0*I] | [ 3.0 4.0] | Full MatrixSpace of 2 by 2 dense matrices over Complex Double Field | sage: n=numpy.array([[1,2],[3,4]],'int32') | sage: m=matrix(n); m; m.parent() | [1 2] | [3 4] | Full MatrixSpace of 2 by 2 dense matrices over Integer Ring | sage: n = numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float32') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Real Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float64') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Real Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'complex64') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field | sage: n=numpy.array([[1,2,3],[4,5,6],[7,8,9]],'complex128') | sage: m=matrix(n); m; m.parent() | [1.0 2.0 3.0] | [4.0 5.0 6.0] | [7.0 8.0 9.0] | Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field | sage: a = matrix([[1,2],[3,4]]) | sage: b = matrix(a.numpy()); b | [1 2] | [3 4] | sage: a == b | True | sage: c = matrix(a.numpy('float32')); c | [1.0 2.0] | [3.0 4.0] | sage: matrix(numpy.array([[5]])) | [5] | sage: v = vector(ZZ, [1, 10, 100]) | sage: m=matrix(ZZ['x'], v); m; m.parent() | [ 1 10 100] | Full MatrixSpace of 1 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring | sage: matrix(ZZ, 10, 10, range(100)).parent() | Full MatrixSpace of 10 by 10 dense matrices over Integer Ring | sage: m = matrix(GF(7), [[1/3,2/3,1/2], [3/4,4/5,7]]); m; m.parent() | [5 3 4] | [6 5 0] | Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 7 | sage: m = matrix([[1,2,3], [RDF(2), CDF(1,2), 3]]); m; m.parent() | [ 1.0 2.0 3.0] | [ 2.0 1.0 + 2.0*I 3.0] | Full MatrixSpace of 2 by 3 dense matrices over Complex Double Field | sage: m=matrix(3,3,1/2); m; m.parent() | [1/2 0 0] | [ 0 1/2 0] | [ 0 0 1/2] | Full MatrixSpace of 3 by 3 dense matrices over Rational Field | sage: matrix([[1],[2,3]]) | Traceback (most recent call last): | ... | ValueError: List of rows is not valid (rows are wrong types or lengths) | sage: matrix([[1],2]) | Traceback (most recent call last): | ... | ValueError: List of rows is not valid (rows are wrong types or lengths) | sage: matrix(vector(RR,[1,2,3])).parent() | Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision | sage: matrix(ZZ, [[0] for i in range(10^5)]).is_zero() # see #10158 | True | | AUTHORS: | | - ??: Initial implementation | | - Jason Grout (2008-03): almost a complete rewrite, with bits and | pieces from the original implementation | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined)
matrix?
︠ab2026da-026a-400e-8cda-a1c0fd8e3ac5︠
factor??

   File: /usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/sage/rings/arith.py
Source:
def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds):
"""
Returns the factorization of n.  The result depends on the
type of n.

If n is an integer, returns the factorization as an object
of type Factorization.

If n is not an integer, n.factor(proof=proof, **kwds) gets called.
See n.factor?? for more documentation in this case.

.. warning::

This means that applying factor to an integer result of
a symbolic computation will not factor the integer, because it is
considered as an element of a larger symbolic ring.

EXAMPLE::

sage: f(n)=n^2
sage: is_prime(f(3))
False
sage: factor(f(3))
9

INPUT:

-  n - an nonzero integer

-  proof - bool or None (default: None)

-  int_ - bool (default: False) whether to return
answers as Python ints

-  algorithm - string

- 'pari' - (default) use the PARI c library

- 'kash' - use KASH computer algebra system (requires the
optional kash package be installed)

- 'magma' - use Magma (requires magma be installed)

-  verbose - integer (default: 0); PARI's debug
variable is set to this; e.g., set to 4 or 8 to see lots of output
during factorization.

OUTPUT:

-  factorization of n

The qsieve and ecm commands give access to highly optimized
implementations of algorithms for doing certain integer
factorization problems. These implementations are not used by the
generic factor command, which currently just calls PARI (note that
PARI also implements sieve and ecm algorithms, but they aren't as
optimized). Thus you might consider using them instead for certain
numbers.

The factorization returned is an element of the class
:class:~sage.structure.factorization.Factorization; see Factorization??
for more details, and examples below for usage. A Factorization contains
both the unit factor (+1 or -1) and a sorted list of (prime, exponent)
pairs.

The factorization displays in pretty-print format but it is easy to
obtain access to the (prime,exponent) pairs and the unit, to
recover the number from its factorization, and even to multiply two
factorizations. See examples below.

EXAMPLES::

sage: factor(500)
2^2 * 5^3
sage: factor(-20)
-1 * 2^2 * 5
sage: f=factor(-20)
sage: list(f)
[(2, 2), (5, 1)]
sage: f.unit()
-1
sage: f.value()
-20
sage: factor( -next_prime(10^2) * next_prime(10^7) )
-1 * 101 * 10000019

::

sage: factor(-500, algorithm='kash')      # optional - kash
-1 * 2^2 * 5^3

::

sage: factor(-500, algorithm='magma')     # optional - magma
-1 * 2^2 * 5^3

::

sage: factor(0)
Traceback (most recent call last):
...
ArithmeticError: Prime factorization of 0 not defined.
sage: factor(1)
1
sage: factor(-1)
-1
sage: factor(2^(2^7)+1)
59649589127497217 * 5704689200685129054721

Sage calls PARI's factor, which has proof False by default.
Sage has a global proof flag, set to True by default (see
:mod:sage.structure.proof.proof, or proof.[tab]). To override
the default, call this function with proof=False.

::

sage: factor(3^89-1, proof=False)
2 * 179 * 1611479891519807 * 5042939439565996049162197

::

sage: factor(2^197 + 1)  # long time (2s)
3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843

Any object which has a factor method can be factored like this::

sage: K.<i> = QuadraticField(-1)
sage: factor(122 - 454*i)
(-1) * (-i - 4) * (-3*i - 2) * (-i - 2)^3 * (i + 1)^3

To access the data in a factorization::

sage: f = factor(420); f
2^2 * 3 * 5 * 7
sage: [x for x in f]
[(2, 2), (3, 1), (5, 1), (7, 1)]
sage: [p for p,e in f]
[2, 3, 5, 7]
sage: [e for p,e in f]
[2, 1, 1, 1]
sage: [p^e for p,e in f]
[4, 3, 5, 7]

"""
if isinstance(n, (int, long)):
n = ZZ(n)

if isinstance(n, integer.Integer):
return n.factor(proof=proof, algorithm=algorithm,
int_ = int_, verbose=verbose)
else:
# e.g. n = x**2 + y**2 + 2*x*y
try:
return n.factor(proof=proof, **kwds)
except AttributeError:
raise TypeError("unable to factor n")
except TypeError:
# Just in case factor method doesn't have a proof option.
try:
return n.factor(**kwds)
except AttributeError:
raise TypeError("unable to factor n")


print "Russian (Русский язык)    "

Russian (Русский язык)
sin?

File: /usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/sage/functions/trig.py
Docstring:
The sine function.

EXAMPLES:

sage: sin(0)
0
sage: sin(x).subs(x==0)
0
sage: sin(2).n(100)
0.90929742682568169539601986591
sin

We can prevent evaluation using the "hold" parameter:

sage: sin(0,hold=True)
sin(0)

To then evaluate again, we currently must use Maxima via
"sage.symbolic.expression.Expression.simplify()":

sage: a = sin(0,hold=True); a.simplify()
0

TESTS:

sage: conjugate(sin(x))
sin(conjugate(x))
sage: sin(complex(1,1))     # rel tol 1e-15
(1.2984575814159773+0.6349639147847361j)


sin.__doc__