Sage 9.2 Reference Manual: Matrices And Spaces Of Matrices

2y ago
30 Views
2 Downloads
1.61 MB
614 Pages
Last View : 7d ago
Last Download : 3m ago
Upload by : Mya Leung
Transcription

Sage 9.2 Reference Manual: Matricesand Spaces of MatricesRelease 9.2The Sage Development TeamOct 25, 2020

CONTENTS1Matrix Spaces32General matrix Constructor173Constructors for special matrices254Helpers for creating matrices635Matrices over an arbitrary ring5.1 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73746Base class for matrices, part 0817Base class for matrices, part 11198Base class for matrices, part 21419Generic Asymptotically Fast Strassen Algorithms31110 Minimal Polynomials of Linear Recurrence Sequences31511 Base class for dense matrices31712 Base class for sparse matrices31913 Dense Matrices over a general ring32514 Sparse Matrices over a general ring32715 Dense matrices over the integer ring33116 Sparse integer matrices35717 Modular algorithm to compute Hermite normal forms of integer matrices36318 Saturation over ZZ37519 Dense matrices over the rational field37920 Sparse rational matrices39121 Dense matrices using a NumPy backend395i

22 Dense matrices over the Real Double Field using NumPy43523 Dense matrices over GF(2) using the M4RI library43724 Dense matrices over F2𝑒 for 2 𝑒 16 using the M4RIE library44725 Dense matrices over Z/𝑛Z for 𝑛 223 using LinBox’s Modular double 45526 Dense matrices over Z/𝑛Z for 𝑛 211 using LinBox’s Modular float 46927 Sparse matrices over Z/𝑛Z for 𝑛 small48328 Symbolic matrices48729 Dense matrices over the Complex Double Field using NumPy49930 Arbitrary precision complex ball matrices using Arb50131 Dense matrices over univariate polynomials over fields50732 Dense matrices over multivariate polynomials over fields52733 Matrices over Cyclotomic Fields53134 Operation Tables53735 Actions used by the coercion model for matrix and vector multiplications54536 Functions for changing the base ring of matrices quickly54937 Echelon matrices over finite fields.55138 Miscellaneous matrix functions55339 Matrix windows55740 Misc matrix algorithms55941 Calculate symplectic bases for matrices over fields and the integers.56342 𝐽-ideals of matrices56942.1 Classes and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57043 Benchmarks for matrices57944 Indices and Tables589Python Module Index591Index593ii

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2Sage provides native support for working with matrices over any commutative or noncommutative ring. The parentobject for a matrix is a matrix space MatrixSpace(R, n, m) of all 𝑛 𝑚 matrices over a ring 𝑅.To create a matrix, either use the matrix(.) function or create a matrix space using the MatrixSpace command and coerce an object into it.Matrices also act on row vectors, which you create using the vector(.) command or by making aVectorSpace and coercing lists into it. The natural action of matrices on row vectors is from the right. Sagecurrently does not have a column vector class (on which matrices would act from the left), but this is planned.In addition to native Sage matrices, Sage also includes the following additional ways to compute with matrices: Several math software systems included with Sage have their own native matrix support, which can be usedfrom Sage. E.g., PARI, GAP, Maxima, and Singular all have a notion of matrices. The GSL C-library is included with Sage, and can be used via Cython. The scipy module provides support for sparse numerical linear algebra, among many other things. The numpy module, which you load by typing import numpy is included standard with Sage. It contains avery sophisticated and well developed array class, plus optimized support for numerical linear algebra. Sage’smatrices over RDF and CDF (native floating-point real and complex numbers) use numpy.Finally, this module contains some data-structures for matrix-like objects like operation tables (e.g. the multiplicationtable of a group).CONTENTS1

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.22CONTENTS

CHAPTERONEMATRIX SPACESYou can create any space Mat𝑛 𝑚 (𝑅) of either dense or sparse matrices with given number of rows and columns overany commutative or noncommutative ring.EXAMPLES:sage: MS MatrixSpace(QQ,6,6,sparse True); MSFull MatrixSpace of 6 by 6 sparse matrices over Rational Fieldsage: MS.base ring()Rational Fieldsage: MS MatrixSpace(ZZ,3,5,sparse False); MSFull MatrixSpace of 3 by 5 dense matrices over Integer Ringclass sage.matrix.matrix space.MatrixSpace(base ring, nrows, ncols, sparse, implementation)Bases:sage.structure.unique .parent.ParentThe space of matrices of given size and base ringEXAMPLES:Some examples of square 2 by 2 rational matrices:sage: MS MatrixSpace(QQ, 2)sage: MS.dimension()4sage: MS.dims()(2, 2)sage: B MS.basis()sage: list(B)[[1 0] [0 1] [0 0] [0 0][0 0], [0 0], [1 0], [0 1]]sage: B[0,0][1 0][0 0]sage: B[0,1][0 1][0 0]sage: B[1,0][0 0][1 0]sage: B[1,1][0 0](continues on next page)3

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2(continued from previous page)[0 1]sage: A MS.matrix([1,2,3,4])sage: A[1 2][3 4]The above matrix A can be multiplied by a 2 by 3 integer matrix:sage: MS2 MatrixSpace(ZZ, 2, 3)sage: B MS2.matrix([1,2,3,4,5,6])sage: A * B[ 9 12 15][19 26 33]Check categories:sage: MatrixSpace(ZZ,10,5)Full MatrixSpace of 10 by 5 dense matrices over Integer Ringsage: MatrixSpace(ZZ,10,5).category()Category of infinite enumerated finite dimensional modules with basis over(euclidean domains and infinite enumerated sets and metric spaces)sage: MatrixSpace(ZZ,10,10).category()Category of infinite enumerated finite dimensional algebras with basis over(euclidean domains and infinite enumerated sets and metric spaces)sage: MatrixSpace(QQ,10).category()Category of infinite finite dimensional algebras with basis over(number fields and quotient fields and metric spaces)base extend(R)Return base extension of this matrix space to R.INPUT: R - ringOUTPUT: a matrix spaceEXAMPLES:sage: Mat(ZZ,3,5).base extend(QQ)Full MatrixSpace of 3 by 5 dense matrices over Rational Fieldsage: Mat(QQ,3,5).base extend(GF(7))Traceback (most recent call last):.TypeError: no base extension definedbasis()Return a basis for this matrix space.Warning: This will of course compute every generator of this matrix space. So for large dimensions,this could take a long time, waste a massive amount of memory (for dense matrices), and is likely notvery useful. Don’t use this on large matrix spaces.EXAMPLES:4Chapter 1. Matrix Spaces

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2sage: list(Mat(ZZ,2,2).basis())[[1 0] [0 1] [0 0] [0 0][0 0], [0 0], [1 0], [0 1]]cached method(f, name None, key None, do pickle None)A decorator for cached methods.EXAMPLES:In the following examples, one can see how a cached method works in application. Below, we demonstratewhat is done behind the scenes:sage: class C:.:@cached method.:def hash (self):.:print("compute hash").:return int(5).:@cached method.:def f(self, x):.:print("computing cached method").:return x*2sage: c C()sage: type(C. hash ) type 'sage.misc.cachefunc.CachedMethodCallerNoArgs' sage: hash(c)compute hash5When calling a cached method for the second time with the same arguments, the value is gotten from thecache, so that a new computation is not needed:sage: hash(c)5sage: c.f(4)computing cached method8sage: c.f(4) is c.f(4)TrueDifferent instances have distinct caches:sage: d C()sage: d.f(4) is c.f(4)computing cached methodFalsesage: d.f.clear cache()sage: c.f(4)8sage: d.f(4)computing cached method8Using cached methods for the hash and other special methods was implemented in trac ticket #12601, bymeans of CachedSpecialMethod. We show that it is used behind the scenes:5

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2sage: cached method(c. hash ) sage.misc.cachefunc.CachedSpecialMethod object at . sage: cached method(c.f) sage.misc.cachefunc.CachedMethod object at . The parameter do pickle can be used if the contents of the cache should be stored in a pickle of thecached method. This can be dangerous with special methods such as hash :sage: class C:.:@cached method(do pickle True).:def hash (self):.:return id(self)sage:sage:sage:sage:sage:sage:Trueimport mainmain .C Cc C()hash(c) # random outputd loads(dumps(c))hash(d) hash(c)However, the contents of a method’s cache are not pickled unless do pickle is set:sage: class C:.:@cached method.:def hash (self):.:return id(self)sage:sage:sage:sage:sage:Falsemain .C Cc C()hash(c) # random outputd loads(dumps(c))hash(d) hash(c)cardinality()Return the number of elements in self.EXAMPLES:sage: MatrixSpace(GF(3), 2, 3).cardinality()729sage: MatrixSpace(ZZ, 2).cardinality() Infinitysage: MatrixSpace(ZZ, 0, 3).cardinality()1change ring(R)Return matrix space over R with otherwise same parameters as self.INPUT: R - ringOUTPUT: a matrix spaceEXAMPLES:6Chapter 1. Matrix Spaces

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2sage: Mat(QQ,3,5).change ring(GF(7))Full MatrixSpace of 3 by 5 dense matrices over Finite Field of size 7characteristic()Return the characteristic.EXAMPLES:sage: MatrixSpace(ZZ, 2).characteristic()0sage: MatrixSpace(GF(9), 0).characteristic()3column space()Return the module spanned by all columns of matrices in this matrix space. This is a free module of rankthe number of columns. It will be sparse or dense as this matrix space is sparse or dense.EXAMPLES:sage: M Mat(GF(9,'a'),20,5,sparse True); M.column space()Sparse vector space of dimension 20 over Finite Field in a of size 3 2construction()EXAMPLES:sage: A matrix(ZZ, 2, [1.4], sparse True)sage: A.parent().construction()(MatrixFunctor, Integer Ring)sage: A.parent().construction()[0](QQ['x'])Full MatrixSpace of 2 by 2 sparse matrices over Univariate Polynomial Ring in x over Rational Fieldsage: parent(A/2)Full MatrixSpace of 2 by 2 sparse matrices over Rational Fielddiagonal matrix(entries)Create a diagonal matrix in self using the specified elementsINPUT: entries – the elements to use as the diagonal entriesself must be a space of square matrices. The length of entries must be less than or equal to the matrixdimensions. If the length of entries is less than the matrix dimensions, entries is padded with zeroesat the end.EXAMPLES:sage: MS1 MatrixSpace(ZZ,4)sage: MS2 MatrixSpace(QQ,3,4)sage: I MS1.diagonal matrix([1, 2, 3, 4])sage: I[1 0 0 0][0 2 0 0][0 0 3 0][0 0 0 4]sage: MS2.diagonal matrix([1, 2])Traceback (most recent call last):.TypeError: diagonal matrix must be square(continues on next page)7

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2(continued from previous page)sage: MS1.diagonal matrix([1, 2, 3, 4, 5])Traceback (most recent call last):.ValueError: number of diagonal matrix entries (5) exceeds the matrix size (4)sage: MS1.diagonal matrix([1/2, 2, 3, 4])Traceback (most recent call last):.TypeError: no conversion of this rational to integerCheck different implementations:sage: M1 MatrixSpace(ZZ, 2, implementation 'flint')sage: M2 MatrixSpace(ZZ, 2, implementation 'generic')sage: typesage: typetype(M1.diagonal matrix([1, 2]))'sage.matrix.matrix integer dense.Matrix integer dense' type(M2.diagonal matrix([1, 2]))'sage.matrix.matrix generic dense.Matrix generic dense' dimension()Return (m rows) * (n cols) of self as Integer.EXAMPLES:sage: MS MatrixSpace(ZZ,4,6)sage: u MS.dimension()sage: u - 24 0Truedims()Return (m row, n col) representation of self dimension.EXAMPLES:sage: MS MatrixSpace(ZZ,4,6)sage: MS.dims()(4, 6)gen(n)Return the n-th generator of this matrix space.This does not compute all basis matrices, so it is reasonably intelligent.EXAMPLES:sage: M Mat(GF(7),10000,5); M.ngens()50000sage: a M.10sage: a[:4][0 0 0 0 0][0 0 0 0 0][1 0 0 0 0][0 0 0 0 0]identity matrix()Return the identity matrix in self.self must be a space of square matrices. The returned matrix is immutable. Please use copy if you wanta modified copy.8Chapter 1. Matrix Spaces

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2EXAMPLES:sage: MS1 MatrixSpace(ZZ,4)sage: MS2 MatrixSpace(QQ,3,4)sage: I MS1.identity matrix()sage: I[1 0 0 0][0 1 0 0][0 0 1 0][0 0 0 1]sage: Er MS2.identity matrix()Traceback (most recent call last):.TypeError: identity matrix must be squareis dense()Return whether matrices in self are dense.EXAMPLES:sage: Mat(RDF,2,3).is sparse()Falsesage: Mat(RR,123456,22,sparse True).is sparse()Trueis finite()Return whether this matrix space is finite.EXAMPLES:sage: MatrixSpace(GF(101), 10000).is finite()Truesage: MatrixSpace(QQ, 2).is finite()Falseis sparse()Return whether matrices in self are sparse.EXAMPLES:sage: Mat(GF(2011),10000).is sparse()Falsesage: Mat(GF(2011),10000,sparse True).is sparse()Truematrix(x None, **kwds)Create a matrix in self.INPUT: x – data to construct a new matrix from. See matrix() coerce – (default: True) if False, assume without checking that the values in x lie in the base ringOUTPUT: a matrix in self.EXAMPLES:9

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2sage: M MatrixSpace(ZZ, 2)sage: M.matrix([[1,0],[0,-1]])[ 1 0][ 0 -1]sage: M.matrix([1,0,0,-1])[ 1 0][ 0 -1]sage: M.matrix([1,2,3,4])[1 2][3 4]Note that the last “flip” cannot be performed if x is a matrix, no matter what is rows (it used to be possiblebut was fixed by trac ticket #10793):sage: projection matrix(ZZ,[[1,0,0],[0,1,0]])sage: projection[1 0 0][0 1 0]sage: projection.parent()Full MatrixSpace of 2 by 3 dense matrices over Integer Ringsage: M MatrixSpace(ZZ, 3 , 2)sage: MFull MatrixSpace of 3 by 2 dense matrices over Integer Ringsage: M(projection)Traceback (most recent call last):.ValueError: inconsistent number of rows: should be 3 but got 2If you really want to make from a matrix another matrix of different dimensions, use either transposemethod or explicit conversion to a list:sage: M(projection.list())[1 0][0 0][1 0]matrix space(nrows None, ncols None, sparse False)Return the matrix space with given number of rows, columns and sparsity over the same base ring as self,and defaults the same as self.EXAMPLES:sage: M Mat(GF(7),100,200)sage: M.matrix space(5000)Full MatrixSpace of 5000 by 200 dense matrices over Finite Field of size 7sage: M.matrix space(ncols 5000)Full MatrixSpace of 100 by 5000 dense matrices over Finite Field of size 7sage: M.matrix space(sparse True)Full MatrixSpace of 100 by 200 sparse matrices over Finite Field of size 7ncols()Return the number of columns of matrices in this space.EXAMPLES:sage: M Mat(ZZ['x'],200000,500000,sparse True)sage: M.ncols()50000010Chapter 1. Matrix Spaces

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2ngens()Return the number of generators of this matrix space.This is the number of entries in the matrices in this space.EXAMPLES:sage: M Mat(GF(7),100,200); M.ngens()20000nrows()Return the number of rows of matrices in this space.EXAMPLES:sage: M Mat(ZZ,200000,500000)sage: M.nrows()200000one()Return the identity matrix in self.self must be a space of square matrices. The returned matrix is immutable. Please use copy if you wanta modified copy.EXAMPLES:sage: MS1 MatrixSpace(ZZ,4)sage: MS2 MatrixSpace(QQ,3,4)sage: I MS1.identity matrix()sage: I[1 0 0 0][0 1 0 0][0 0 1 0][0 0 0 1]sage: Er MS2.identity matrix()Traceback (most recent call last):.TypeError: identity matrix must be squarerandom element(density None, *args, **kwds)Return a random element from this matrix space.INPUT: density - float or None (default: None); rough measure of the proportion of nonzero entries inthe random matrix; if set to None, all entries of the matrix are randomized, allowing for any elementof the underlying ring, but if set to a float, a proportion of entries is selected and randomized tonon-zero elements of the ring *args, **kwds - remaining parameters, which may be passed to the random element function ofthe base ring. (“may be”, since this function calls the randomize function on the zero matrix, whichneed not call the random element function of the base ring at all in general.)OUTPUT: MatrixNote: This method will randomize a proportion of roughly density entries in a newly allocated zeromatrix.11

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2By default, if the user sets the value of density explicitly, this method will enforce that these entries areset to non-zero values. However, if the test for equality with zero in the base ring is too expensive, the usercan override this behaviour by passing the argument nonzero False to this method.Otherwise, if the user does not set the value of density, the default value is taken to be 1, and the optionnonzero False is passed to the randomize method.EXAMPLES:sage: Mat(ZZ,2,5).random element()[ -82001][ -121 -95 -1]sage: Mat(QQ,2,5).random element(density 0.5)[ 20001][ 000 1/20]sage: Mat(QQ,3,sparse True).random element()[ -1 1/31][0-10][ -11 -1/4]sage: Mat(GF(9,'a'),3,sparse True).random element()[121][ a 22 *a2][2 2*a 21]row space()Return the module spanned by all rows of matrices in this matrix space. This is a free module of rank thenumber of rows. It will be sparse or dense as this matrix space is sparse or dense.EXAMPLES:sage: M Mat(ZZ,20,5,sparse False); M.row space()Ambient free module of rank 5 over the principal ideal domain Integer Ringsome elements()Return some elements of this matrix space.See TestSuite for a typical use case.OUTPUT:An iterator.EXAMPLES:sage: M MatrixSpace(ZZ, 2, 2)sage: tuple(M.some elements())([ 0 1] [1 0] [0 1] [0 0] [0 0][-1 2], [0 0], [0 0], [1 0], [0 1])sage: M MatrixSpace(QQ, 2, 3)sage: tuple(M.some elements())([ 1/2 -1/22] [1 0 0] [0 1 0] [0 0 1] [0 0 0] [0 0 0] [0 0 0][ -201], [0 0 0], [0 0 0], [0 0 0], [1 0 0], [0 1 0], [0 0 1])sage: M MatrixSpace(SR, 2, 2)sage: tuple(M.some elements())((continues on next page)12Chapter 1. Matrix Spaces

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2(continued from previous page)[some variable some variable] [1 0] [0 1] [0 0] [0 0][some variable some variable], [0 0], [0 0], [1 0], [0 1])transposed()The transposed matrix space, having the same base ring and sparseness, but number of columns and rowsis swapped.EXAMPLES:sage: MS MatrixSpace(GF(3), 7, 10)sage: MS.transposedFull MatrixSpace of 10 by 7 dense matrices over Finite Field of size 3sage: MS MatrixSpace(GF(3), 7, 7)sage: MS.transposed is MSTruesage: M MatrixSpace(ZZ, 2, 3)sage: M.transposedFull MatrixSpace of 3 by 2 dense matrices over Integer Ringzero()Return the zero matrix in self.self must be a space of square matrices. The returned matrix is immutable. Please use copy if you wanta modified copy.EXAMPLES:sage: z MatrixSpace(GF(7),2,4).zero matrix(); z[0 0 0 0][0 0 0 0]sage: z.is mutable()Falsezero matrix()Return the zero matrix in self.self must be a space of square matrices. The returned matrix is immutable. Please use copy if you wanta modified copy.EXAMPLES:sage: z MatrixSpace(GF(7),2,4).zero matrix(); z[0 0 0 0][0 0 0 0]sage: z.is mutable()Falsesage.matrix.matrix space.dict to list(entries, nrows, ncols)Given a dictionary of coordinate tuples, return the list given by reading off the nrows*ncols matrix in row order.EXAMPLES:sage:sage:sage:sage:from sage.matrix.matrix space import dict to listd {}d[(0,0)] 1d[(1,1)] 2(continues on next page)13

Sage 9.2 Reference Manual: Matrices and Spaces of Matrices, Release 9.2(continued from previous page)sage: dict to list(d, 2, 2)[1, 0, 0, 2]sage: dict to list(d, 2, 3)[1, 0, 0, 0, 2, 0]sage.matrix.matrix space.get matrix class(R, nrows, ncols, sparse, implementation)Return a matrix class according to the input.Note: This returns the base class without the category.

22 Dense matrices over the Real Double Field using NumPy435 23 Dense matrices over GF(2) using the M4RI library437 24 Dense matrices over F 2 for 2 16 using the M4RIE library447 25 Dense matrices over Z/ Z for 223 using LinBox’s Modular double 455 26 Dense matrices over Z/ Z for 211 using LinBox’s Modular&l

Related Documents:

Integrate Sage CRM with Sage 300 Use Sage CRM features that are added during integration How to Use this Guide The first five chapters of this guide are for Sage CRM implementers. Chapter 6, "Using Sage CRM with Sage 300," is for Sage CRM users. We assume that implementers: Have experience implementing and troubleshooting Sage CRM

Sage.CRM.WebObjectNamespace 11-7 Sage.CRM.ControlsNamespace 11-7 DeveloperGuide Contents-ix. Contents Sage.CRM.DataNamespace 11-7 Sage.CRM.UtilsNamespace 11-7 Sage.CRM.BlocksNamespace 11-8 Sage.CRM.HTMLNamespace 11-8 Sage.CRM.UINamespace 11-8 Installingthe.NETSDK 11-8

Sage 50 Sage 100 Sage 300 HRMS Construction Modernization—bridging the past to the future Leveraging modern technology to . Sage 300 2016 February 2016 Sage 300 2016.1 May 2016 New Direct Deposit service for US payroll August 2016 Sage 300 2017.

Sage Abra Workforce Connections, the web-based employee self-service solution for Sage HRMS. It consists of: Abra Employee Self-Service Abra Benefits Enrollment Abra eRecruiter Sage Accpac HRMS Payroll Link, for transferring employee data and earnings, deductions, and benefits information from Sage HRMS to Sage Accpac Payroll.

ERP MAS 90, Sage ERP MAS 200, and Sage ERP MAS 200 SQL. This manual also contains information and troubleshooting tips on the configuration of the various operating systems and environments in which the Sage ERP MAS software is supported. The instructions contain detailed technical information on the configuration ofFile Size: 1MB

Installation Guide. Where To Now? Installation and Administration Guide 1 –5 : Sage 300 Integrated with Sage CRM : Similar to Sage 300, Sage CRM can be installed locally, or on a server, or be deployed on the Web. In the illustration below, we’ve shown the Sage 300 Web server and the

Sage HRMS or Sage ABRA Suite G/L Link using General Ledger Exchange or VI import Sage HRMS Product Version Sage 100 Standard and Advanced . 2016.1 X X Requires Sage 100 2016.1 (Update 1) or higher Remote access; cannot be

If you are using Sage Fixed Assets-Depreciation Premier, see page 4-1. Unlike some of the other Sage Fixed Assets link programs, you do not need to run the link in the Sage Fixed Assets application to post depreciation to Sage 100You need only . calculate depreciation for the desired period and group of assets. Then, in the Sage 100