passagemath-modules 10.6.31rc3__cp314-cp314-musllinux_1_2_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-modules might be problematic. Click here for more details.
- passagemath_modules-10.6.31rc3.dist-info/METADATA +281 -0
- passagemath_modules-10.6.31rc3.dist-info/RECORD +807 -0
- passagemath_modules-10.6.31rc3.dist-info/WHEEL +5 -0
- passagemath_modules-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_modules.libs/libgcc_s-2d945d6c.so.1 +0 -0
- passagemath_modules.libs/libgfortran-67378ab2.so.5.0.0 +0 -0
- passagemath_modules.libs/libgmp-28992bcb.so.10.5.0 +0 -0
- passagemath_modules.libs/libgsl-23768756.so.28.0.0 +0 -0
- passagemath_modules.libs/libmpc-7897025b.so.3.3.1 +0 -0
- passagemath_modules.libs/libmpfr-e34bb864.so.6.2.1 +0 -0
- passagemath_modules.libs/libopenblasp-r0-503f0c35.3.29.so +0 -0
- sage/algebras/all__sagemath_modules.py +20 -0
- sage/algebras/catalog.py +148 -0
- sage/algebras/clifford_algebra.py +3107 -0
- sage/algebras/clifford_algebra_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/algebras/clifford_algebra_element.pxd +16 -0
- sage/algebras/clifford_algebra_element.pyx +997 -0
- sage/algebras/commutative_dga.py +4252 -0
- sage/algebras/exterior_algebra_groebner.cpython-314-aarch64-linux-musl.so +0 -0
- sage/algebras/exterior_algebra_groebner.pxd +55 -0
- sage/algebras/exterior_algebra_groebner.pyx +727 -0
- sage/algebras/finite_dimensional_algebras/all.py +2 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py +1029 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pxd +12 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx +706 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py +196 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py +255 -0
- sage/algebras/finite_gca.py +528 -0
- sage/algebras/group_algebra.py +232 -0
- sage/algebras/lie_algebras/abelian.py +197 -0
- sage/algebras/lie_algebras/affine_lie_algebra.py +1213 -0
- sage/algebras/lie_algebras/all.py +25 -0
- sage/algebras/lie_algebras/all__sagemath_modules.py +1 -0
- sage/algebras/lie_algebras/bch.py +177 -0
- sage/algebras/lie_algebras/bgg_dual_module.py +1184 -0
- sage/algebras/lie_algebras/bgg_resolution.py +232 -0
- sage/algebras/lie_algebras/center_uea.py +767 -0
- sage/algebras/lie_algebras/classical_lie_algebra.py +2516 -0
- sage/algebras/lie_algebras/examples.py +683 -0
- sage/algebras/lie_algebras/free_lie_algebra.py +973 -0
- sage/algebras/lie_algebras/heisenberg.py +820 -0
- sage/algebras/lie_algebras/lie_algebra.py +1562 -0
- sage/algebras/lie_algebras/lie_algebra_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/algebras/lie_algebras/lie_algebra_element.pxd +68 -0
- sage/algebras/lie_algebras/lie_algebra_element.pyx +2122 -0
- sage/algebras/lie_algebras/morphism.py +661 -0
- sage/algebras/lie_algebras/nilpotent_lie_algebra.py +457 -0
- sage/algebras/lie_algebras/onsager.py +1324 -0
- sage/algebras/lie_algebras/poincare_birkhoff_witt.py +816 -0
- sage/algebras/lie_algebras/quotient.py +462 -0
- sage/algebras/lie_algebras/rank_two_heisenberg_virasoro.py +355 -0
- sage/algebras/lie_algebras/representation.py +1040 -0
- sage/algebras/lie_algebras/structure_coefficients.py +459 -0
- sage/algebras/lie_algebras/subalgebra.py +967 -0
- sage/algebras/lie_algebras/symplectic_derivation.py +289 -0
- sage/algebras/lie_algebras/verma_module.py +1630 -0
- sage/algebras/lie_algebras/virasoro.py +1186 -0
- sage/algebras/octonion_algebra.cpython-314-aarch64-linux-musl.so +0 -0
- sage/algebras/octonion_algebra.pxd +20 -0
- sage/algebras/octonion_algebra.pyx +987 -0
- sage/algebras/orlik_solomon.py +907 -0
- sage/algebras/orlik_terao.py +779 -0
- sage/algebras/steenrod/all.py +7 -0
- sage/algebras/steenrod/steenrod_algebra.py +4258 -0
- sage/algebras/steenrod/steenrod_algebra_bases.py +1179 -0
- sage/algebras/steenrod/steenrod_algebra_misc.py +1167 -0
- sage/algebras/steenrod/steenrod_algebra_mult.py +954 -0
- sage/algebras/weyl_algebra.py +1126 -0
- sage/all__sagemath_modules.py +62 -0
- sage/calculus/all__sagemath_modules.py +19 -0
- sage/calculus/expr.py +205 -0
- sage/calculus/integration.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/integration.pyx +698 -0
- sage/calculus/interpolation.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/interpolation.pxd +13 -0
- sage/calculus/interpolation.pyx +387 -0
- sage/calculus/interpolators.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/interpolators.pyx +326 -0
- sage/calculus/ode.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/ode.pxd +5 -0
- sage/calculus/ode.pyx +610 -0
- sage/calculus/riemann.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/riemann.pyx +1521 -0
- sage/calculus/test_sympy.py +201 -0
- sage/calculus/transforms/all.py +7 -0
- sage/calculus/transforms/dft.py +844 -0
- sage/calculus/transforms/dwt.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/transforms/dwt.pxd +7 -0
- sage/calculus/transforms/dwt.pyx +160 -0
- sage/calculus/transforms/fft.cpython-314-aarch64-linux-musl.so +0 -0
- sage/calculus/transforms/fft.pxd +12 -0
- sage/calculus/transforms/fft.pyx +487 -0
- sage/calculus/wester.py +662 -0
- sage/coding/abstract_code.py +1108 -0
- sage/coding/ag_code.py +868 -0
- sage/coding/ag_code_decoders.cpython-314-aarch64-linux-musl.so +0 -0
- sage/coding/ag_code_decoders.pyx +2639 -0
- sage/coding/all.py +15 -0
- sage/coding/bch_code.py +494 -0
- sage/coding/binary_code.cpython-314-aarch64-linux-musl.so +0 -0
- sage/coding/binary_code.pxd +124 -0
- sage/coding/binary_code.pyx +4139 -0
- sage/coding/bounds_catalog.py +43 -0
- sage/coding/channel.py +819 -0
- sage/coding/channels_catalog.py +29 -0
- sage/coding/code_bounds.py +755 -0
- sage/coding/code_constructions.py +804 -0
- sage/coding/codes_catalog.py +111 -0
- sage/coding/cyclic_code.py +1329 -0
- sage/coding/databases.py +316 -0
- sage/coding/decoder.py +373 -0
- sage/coding/decoders_catalog.py +88 -0
- sage/coding/delsarte_bounds.py +709 -0
- sage/coding/encoder.py +390 -0
- sage/coding/encoders_catalog.py +64 -0
- sage/coding/extended_code.py +468 -0
- sage/coding/gabidulin_code.py +1058 -0
- sage/coding/golay_code.py +404 -0
- sage/coding/goppa_code.py +441 -0
- sage/coding/grs_code.py +2371 -0
- sage/coding/guava.py +107 -0
- sage/coding/guruswami_sudan/all.py +1 -0
- sage/coding/guruswami_sudan/gs_decoder.py +897 -0
- sage/coding/guruswami_sudan/interpolation.py +409 -0
- sage/coding/guruswami_sudan/utils.py +176 -0
- sage/coding/hamming_code.py +176 -0
- sage/coding/information_set_decoder.py +1032 -0
- sage/coding/kasami_codes.cpython-314-aarch64-linux-musl.so +0 -0
- sage/coding/kasami_codes.pyx +351 -0
- sage/coding/linear_code.py +3067 -0
- sage/coding/linear_code_no_metric.py +1354 -0
- sage/coding/linear_rank_metric.py +961 -0
- sage/coding/parity_check_code.py +353 -0
- sage/coding/punctured_code.py +719 -0
- sage/coding/reed_muller_code.py +999 -0
- sage/coding/self_dual_codes.py +942 -0
- sage/coding/source_coding/all.py +2 -0
- sage/coding/source_coding/huffman.py +553 -0
- sage/coding/subfield_subcode.py +423 -0
- sage/coding/two_weight_db.py +399 -0
- sage/combinat/all__sagemath_modules.py +7 -0
- sage/combinat/cartesian_product.py +347 -0
- sage/combinat/family.py +11 -0
- sage/combinat/free_module.py +1977 -0
- sage/combinat/root_system/all.py +147 -0
- sage/combinat/root_system/ambient_space.py +527 -0
- sage/combinat/root_system/associahedron.py +471 -0
- sage/combinat/root_system/braid_move_calculator.py +143 -0
- sage/combinat/root_system/braid_orbit.cpython-314-aarch64-linux-musl.so +0 -0
- sage/combinat/root_system/braid_orbit.pyx +144 -0
- sage/combinat/root_system/branching_rules.py +2301 -0
- sage/combinat/root_system/cartan_matrix.py +1245 -0
- sage/combinat/root_system/cartan_type.py +3069 -0
- sage/combinat/root_system/coxeter_group.py +162 -0
- sage/combinat/root_system/coxeter_matrix.py +1261 -0
- sage/combinat/root_system/coxeter_type.py +681 -0
- sage/combinat/root_system/dynkin_diagram.py +900 -0
- sage/combinat/root_system/extended_affine_weyl_group.py +2993 -0
- sage/combinat/root_system/fundamental_group.py +795 -0
- sage/combinat/root_system/hecke_algebra_representation.py +1203 -0
- sage/combinat/root_system/integrable_representations.py +1227 -0
- sage/combinat/root_system/non_symmetric_macdonald_polynomials.py +1965 -0
- sage/combinat/root_system/pieri_factors.py +1147 -0
- sage/combinat/root_system/plot.py +1615 -0
- sage/combinat/root_system/root_lattice_realization_algebras.py +1214 -0
- sage/combinat/root_system/root_lattice_realizations.py +4628 -0
- sage/combinat/root_system/root_space.py +487 -0
- sage/combinat/root_system/root_system.py +882 -0
- sage/combinat/root_system/type_A.py +348 -0
- sage/combinat/root_system/type_A_affine.py +227 -0
- sage/combinat/root_system/type_A_infinity.py +241 -0
- sage/combinat/root_system/type_B.py +347 -0
- sage/combinat/root_system/type_BC_affine.py +287 -0
- sage/combinat/root_system/type_B_affine.py +216 -0
- sage/combinat/root_system/type_C.py +317 -0
- sage/combinat/root_system/type_C_affine.py +188 -0
- sage/combinat/root_system/type_D.py +357 -0
- sage/combinat/root_system/type_D_affine.py +208 -0
- sage/combinat/root_system/type_E.py +641 -0
- sage/combinat/root_system/type_E_affine.py +231 -0
- sage/combinat/root_system/type_F.py +387 -0
- sage/combinat/root_system/type_F_affine.py +137 -0
- sage/combinat/root_system/type_G.py +293 -0
- sage/combinat/root_system/type_G_affine.py +132 -0
- sage/combinat/root_system/type_H.py +105 -0
- sage/combinat/root_system/type_I.py +110 -0
- sage/combinat/root_system/type_Q.py +150 -0
- sage/combinat/root_system/type_affine.py +509 -0
- sage/combinat/root_system/type_dual.py +704 -0
- sage/combinat/root_system/type_folded.py +301 -0
- sage/combinat/root_system/type_marked.py +748 -0
- sage/combinat/root_system/type_reducible.py +601 -0
- sage/combinat/root_system/type_relabel.py +730 -0
- sage/combinat/root_system/type_super_A.py +837 -0
- sage/combinat/root_system/weight_lattice_realizations.py +1188 -0
- sage/combinat/root_system/weight_space.py +639 -0
- sage/combinat/root_system/weyl_characters.py +2238 -0
- sage/crypto/__init__.py +4 -0
- sage/crypto/all.py +28 -0
- sage/crypto/block_cipher/all.py +7 -0
- sage/crypto/block_cipher/des.py +1065 -0
- sage/crypto/block_cipher/miniaes.py +2171 -0
- sage/crypto/block_cipher/present.py +909 -0
- sage/crypto/block_cipher/sdes.py +1527 -0
- sage/crypto/boolean_function.cpython-314-aarch64-linux-musl.so +0 -0
- sage/crypto/boolean_function.pxd +10 -0
- sage/crypto/boolean_function.pyx +1487 -0
- sage/crypto/cipher.py +78 -0
- sage/crypto/classical.py +3668 -0
- sage/crypto/classical_cipher.py +569 -0
- sage/crypto/cryptosystem.py +387 -0
- sage/crypto/key_exchange/all.py +7 -0
- sage/crypto/key_exchange/catalog.py +24 -0
- sage/crypto/key_exchange/diffie_hellman.py +323 -0
- sage/crypto/key_exchange/key_exchange_scheme.py +107 -0
- sage/crypto/lattice.py +312 -0
- sage/crypto/lfsr.py +295 -0
- sage/crypto/lwe.py +840 -0
- sage/crypto/mq/__init__.py +4 -0
- sage/crypto/mq/mpolynomialsystemgenerator.py +204 -0
- sage/crypto/mq/rijndael_gf.py +2345 -0
- sage/crypto/mq/sbox.py +7 -0
- sage/crypto/mq/sr.py +3344 -0
- sage/crypto/public_key/all.py +5 -0
- sage/crypto/public_key/blum_goldwasser.py +776 -0
- sage/crypto/sbox.cpython-314-aarch64-linux-musl.so +0 -0
- sage/crypto/sbox.pyx +2090 -0
- sage/crypto/sboxes.py +2090 -0
- sage/crypto/stream.py +390 -0
- sage/crypto/stream_cipher.py +297 -0
- sage/crypto/util.py +519 -0
- sage/ext/all__sagemath_modules.py +1 -0
- sage/ext/interpreters/__init__.py +1 -0
- sage/ext/interpreters/all__sagemath_modules.py +2 -0
- sage/ext/interpreters/wrapper_cc.cpython-314-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_cc.pxd +30 -0
- sage/ext/interpreters/wrapper_cc.pyx +252 -0
- sage/ext/interpreters/wrapper_cdf.cpython-314-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_cdf.pxd +26 -0
- sage/ext/interpreters/wrapper_cdf.pyx +245 -0
- sage/ext/interpreters/wrapper_rdf.cpython-314-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_rdf.pxd +23 -0
- sage/ext/interpreters/wrapper_rdf.pyx +221 -0
- sage/ext/interpreters/wrapper_rr.cpython-314-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_rr.pxd +28 -0
- sage/ext/interpreters/wrapper_rr.pyx +335 -0
- sage/geometry/all__sagemath_modules.py +5 -0
- sage/geometry/toric_lattice.py +1745 -0
- sage/geometry/toric_lattice_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/geometry/toric_lattice_element.pyx +432 -0
- sage/groups/abelian_gps/abelian_group.py +1925 -0
- sage/groups/abelian_gps/abelian_group_element.py +164 -0
- sage/groups/abelian_gps/all__sagemath_modules.py +5 -0
- sage/groups/abelian_gps/dual_abelian_group.py +421 -0
- sage/groups/abelian_gps/dual_abelian_group_element.py +179 -0
- sage/groups/abelian_gps/element_base.py +341 -0
- sage/groups/abelian_gps/values.py +488 -0
- sage/groups/additive_abelian/additive_abelian_group.py +476 -0
- sage/groups/additive_abelian/additive_abelian_wrapper.py +857 -0
- sage/groups/additive_abelian/all.py +4 -0
- sage/groups/additive_abelian/qmodnz.py +231 -0
- sage/groups/additive_abelian/qmodnz_element.py +349 -0
- sage/groups/affine_gps/affine_group.py +535 -0
- sage/groups/affine_gps/all.py +1 -0
- sage/groups/affine_gps/catalog.py +17 -0
- sage/groups/affine_gps/euclidean_group.py +246 -0
- sage/groups/affine_gps/group_element.py +562 -0
- sage/groups/all__sagemath_modules.py +12 -0
- sage/groups/galois_group.py +479 -0
- sage/groups/matrix_gps/all.py +4 -0
- sage/groups/matrix_gps/all__sagemath_modules.py +13 -0
- sage/groups/matrix_gps/catalog.py +26 -0
- sage/groups/matrix_gps/coxeter_group.py +927 -0
- sage/groups/matrix_gps/finitely_generated.py +487 -0
- sage/groups/matrix_gps/group_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/groups/matrix_gps/group_element.pxd +11 -0
- sage/groups/matrix_gps/group_element.pyx +431 -0
- sage/groups/matrix_gps/linear.py +440 -0
- sage/groups/matrix_gps/matrix_group.py +617 -0
- sage/groups/matrix_gps/named_group.py +296 -0
- sage/groups/matrix_gps/orthogonal.py +544 -0
- sage/groups/matrix_gps/symplectic.py +251 -0
- sage/groups/matrix_gps/unitary.py +436 -0
- sage/groups/misc_gps/all__sagemath_modules.py +1 -0
- sage/groups/misc_gps/argument_groups.py +1905 -0
- sage/groups/misc_gps/imaginary_groups.py +479 -0
- sage/groups/perm_gps/all__sagemath_modules.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_modules.py +1 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.cpython-314-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.pxd +41 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.pyx +1167 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.cpython-314-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.pxd +31 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.pyx +385 -0
- sage/homology/algebraic_topological_model.py +595 -0
- sage/homology/all.py +2 -0
- sage/homology/all__sagemath_modules.py +8 -0
- sage/homology/chain_complex.py +2148 -0
- sage/homology/chain_complex_homspace.py +165 -0
- sage/homology/chain_complex_morphism.py +629 -0
- sage/homology/chain_homotopy.py +604 -0
- sage/homology/chains.py +653 -0
- sage/homology/free_resolution.py +923 -0
- sage/homology/graded_resolution.py +567 -0
- sage/homology/hochschild_complex.py +756 -0
- sage/homology/homology_group.py +188 -0
- sage/homology/homology_morphism.py +422 -0
- sage/homology/homology_vector_space_with_basis.py +1454 -0
- sage/homology/koszul_complex.py +169 -0
- sage/homology/matrix_utils.py +205 -0
- sage/libs/all__sagemath_modules.py +1 -0
- sage/libs/gsl/__init__.py +1 -0
- sage/libs/gsl/airy.pxd +56 -0
- sage/libs/gsl/all.pxd +66 -0
- sage/libs/gsl/array.cpython-314-aarch64-linux-musl.so +0 -0
- sage/libs/gsl/array.pxd +5 -0
- sage/libs/gsl/array.pyx +102 -0
- sage/libs/gsl/bessel.pxd +208 -0
- sage/libs/gsl/blas.pxd +116 -0
- sage/libs/gsl/blas_types.pxd +34 -0
- sage/libs/gsl/block.pxd +52 -0
- sage/libs/gsl/chebyshev.pxd +37 -0
- sage/libs/gsl/clausen.pxd +12 -0
- sage/libs/gsl/combination.pxd +47 -0
- sage/libs/gsl/complex.pxd +151 -0
- sage/libs/gsl/coulomb.pxd +30 -0
- sage/libs/gsl/coupling.pxd +21 -0
- sage/libs/gsl/dawson.pxd +12 -0
- sage/libs/gsl/debye.pxd +24 -0
- sage/libs/gsl/dilog.pxd +14 -0
- sage/libs/gsl/eigen.pxd +46 -0
- sage/libs/gsl/elementary.pxd +12 -0
- sage/libs/gsl/ellint.pxd +48 -0
- sage/libs/gsl/elljac.pxd +8 -0
- sage/libs/gsl/erf.pxd +32 -0
- sage/libs/gsl/errno.pxd +26 -0
- sage/libs/gsl/exp.pxd +44 -0
- sage/libs/gsl/expint.pxd +44 -0
- sage/libs/gsl/fermi_dirac.pxd +44 -0
- sage/libs/gsl/fft.pxd +121 -0
- sage/libs/gsl/fit.pxd +50 -0
- sage/libs/gsl/gamma.pxd +94 -0
- sage/libs/gsl/gegenbauer.pxd +26 -0
- sage/libs/gsl/histogram.pxd +176 -0
- sage/libs/gsl/hyperg.pxd +52 -0
- sage/libs/gsl/integration.pxd +69 -0
- sage/libs/gsl/interp.pxd +109 -0
- sage/libs/gsl/laguerre.pxd +24 -0
- sage/libs/gsl/lambert.pxd +16 -0
- sage/libs/gsl/legendre.pxd +90 -0
- sage/libs/gsl/linalg.pxd +185 -0
- sage/libs/gsl/log.pxd +26 -0
- sage/libs/gsl/math.pxd +43 -0
- sage/libs/gsl/matrix.pxd +143 -0
- sage/libs/gsl/matrix_complex.pxd +130 -0
- sage/libs/gsl/min.pxd +67 -0
- sage/libs/gsl/monte.pxd +56 -0
- sage/libs/gsl/ntuple.pxd +32 -0
- sage/libs/gsl/odeiv.pxd +70 -0
- sage/libs/gsl/permutation.pxd +78 -0
- sage/libs/gsl/poly.pxd +40 -0
- sage/libs/gsl/pow_int.pxd +12 -0
- sage/libs/gsl/psi.pxd +28 -0
- sage/libs/gsl/qrng.pxd +29 -0
- sage/libs/gsl/random.pxd +257 -0
- sage/libs/gsl/rng.pxd +100 -0
- sage/libs/gsl/roots.pxd +72 -0
- sage/libs/gsl/sort.pxd +36 -0
- sage/libs/gsl/statistics.pxd +59 -0
- sage/libs/gsl/sum.pxd +55 -0
- sage/libs/gsl/synchrotron.pxd +16 -0
- sage/libs/gsl/transport.pxd +24 -0
- sage/libs/gsl/trig.pxd +58 -0
- sage/libs/gsl/types.pxd +137 -0
- sage/libs/gsl/vector.pxd +101 -0
- sage/libs/gsl/vector_complex.pxd +83 -0
- sage/libs/gsl/wavelet.pxd +49 -0
- sage/libs/gsl/zeta.pxd +28 -0
- sage/libs/mpc/__init__.pxd +114 -0
- sage/libs/mpc/types.pxd +28 -0
- sage/libs/mpfr/__init__.pxd +299 -0
- sage/libs/mpfr/types.pxd +26 -0
- sage/libs/mpmath/__init__.py +1 -0
- sage/libs/mpmath/all.py +27 -0
- sage/libs/mpmath/all__sagemath_modules.py +1 -0
- sage/libs/mpmath/utils.cpython-314-aarch64-linux-musl.so +0 -0
- sage/libs/mpmath/utils.pxd +4 -0
- sage/libs/mpmath/utils.pyx +319 -0
- sage/matrix/action.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/action.pxd +26 -0
- sage/matrix/action.pyx +596 -0
- sage/matrix/all.py +9 -0
- sage/matrix/args.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/args.pxd +144 -0
- sage/matrix/args.pyx +1668 -0
- sage/matrix/benchmark.py +1258 -0
- sage/matrix/berlekamp_massey.py +95 -0
- sage/matrix/compute_J_ideal.py +926 -0
- sage/matrix/constructor.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/constructor.pyx +750 -0
- sage/matrix/docs.py +430 -0
- sage/matrix/echelon_matrix.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/echelon_matrix.pyx +155 -0
- sage/matrix/matrix.pxd +2 -0
- sage/matrix/matrix0.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix0.pxd +68 -0
- sage/matrix/matrix0.pyx +6324 -0
- sage/matrix/matrix1.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix1.pxd +8 -0
- sage/matrix/matrix1.pyx +2851 -0
- sage/matrix/matrix2.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix2.pxd +25 -0
- sage/matrix/matrix2.pyx +20181 -0
- sage/matrix/matrix_cdv.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_cdv.pxd +4 -0
- sage/matrix/matrix_cdv.pyx +93 -0
- sage/matrix/matrix_complex_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_complex_double_dense.pxd +5 -0
- sage/matrix/matrix_complex_double_dense.pyx +98 -0
- sage/matrix/matrix_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_dense.pxd +5 -0
- sage/matrix/matrix_dense.pyx +343 -0
- sage/matrix/matrix_domain_dense.pxd +5 -0
- sage/matrix/matrix_domain_sparse.pxd +5 -0
- sage/matrix/matrix_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_double_dense.pxd +7 -0
- sage/matrix/matrix_double_dense.pyx +3906 -0
- sage/matrix/matrix_double_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_double_sparse.pxd +6 -0
- sage/matrix/matrix_double_sparse.pyx +248 -0
- sage/matrix/matrix_generic_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_generic_dense.pxd +7 -0
- sage/matrix/matrix_generic_dense.pyx +354 -0
- sage/matrix/matrix_generic_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_generic_sparse.pxd +7 -0
- sage/matrix/matrix_generic_sparse.pyx +461 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.pxd +5 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.pyx +115 -0
- sage/matrix/matrix_misc.py +313 -0
- sage/matrix/matrix_numpy_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_numpy_dense.pxd +14 -0
- sage/matrix/matrix_numpy_dense.pyx +450 -0
- sage/matrix/matrix_numpy_integer_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_numpy_integer_dense.pxd +7 -0
- sage/matrix/matrix_numpy_integer_dense.pyx +59 -0
- sage/matrix/matrix_polynomial_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_polynomial_dense.pxd +5 -0
- sage/matrix/matrix_polynomial_dense.pyx +5341 -0
- sage/matrix/matrix_real_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_real_double_dense.pxd +7 -0
- sage/matrix/matrix_real_double_dense.pyx +122 -0
- sage/matrix/matrix_space.py +2848 -0
- sage/matrix/matrix_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_sparse.pxd +5 -0
- sage/matrix/matrix_sparse.pyx +1222 -0
- sage/matrix/matrix_window.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/matrix_window.pxd +37 -0
- sage/matrix/matrix_window.pyx +242 -0
- sage/matrix/misc_mpfr.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/misc_mpfr.pyx +80 -0
- sage/matrix/operation_table.py +1182 -0
- sage/matrix/special.py +3666 -0
- sage/matrix/strassen.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matrix/strassen.pyx +851 -0
- sage/matrix/symplectic_basis.py +541 -0
- sage/matrix/template.pxd +6 -0
- sage/matrix/tests.py +71 -0
- sage/matroids/advanced.py +77 -0
- sage/matroids/all.py +13 -0
- sage/matroids/basis_exchange_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/basis_exchange_matroid.pxd +96 -0
- sage/matroids/basis_exchange_matroid.pyx +2344 -0
- sage/matroids/basis_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/basis_matroid.pxd +45 -0
- sage/matroids/basis_matroid.pyx +1217 -0
- sage/matroids/catalog.py +44 -0
- sage/matroids/chow_ring.py +473 -0
- sage/matroids/chow_ring_ideal.py +849 -0
- sage/matroids/circuit_closures_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/circuit_closures_matroid.pxd +16 -0
- sage/matroids/circuit_closures_matroid.pyx +559 -0
- sage/matroids/circuits_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/circuits_matroid.pxd +38 -0
- sage/matroids/circuits_matroid.pyx +947 -0
- sage/matroids/constructor.py +1086 -0
- sage/matroids/database_collections.py +365 -0
- sage/matroids/database_matroids.py +5338 -0
- sage/matroids/dual_matroid.py +583 -0
- sage/matroids/extension.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/extension.pxd +34 -0
- sage/matroids/extension.pyx +519 -0
- sage/matroids/flats_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/flats_matroid.pxd +28 -0
- sage/matroids/flats_matroid.pyx +715 -0
- sage/matroids/gammoid.py +600 -0
- sage/matroids/graphic_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/graphic_matroid.pxd +39 -0
- sage/matroids/graphic_matroid.pyx +2024 -0
- sage/matroids/lean_matrix.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/lean_matrix.pxd +126 -0
- sage/matroids/lean_matrix.pyx +3667 -0
- sage/matroids/linear_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/linear_matroid.pxd +180 -0
- sage/matroids/linear_matroid.pyx +6649 -0
- sage/matroids/matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/matroid.pxd +243 -0
- sage/matroids/matroid.pyx +8759 -0
- sage/matroids/matroids_catalog.py +190 -0
- sage/matroids/matroids_plot_helpers.py +890 -0
- sage/matroids/minor_matroid.py +480 -0
- sage/matroids/minorfix.h +9 -0
- sage/matroids/named_matroids.py +5 -0
- sage/matroids/rank_matroid.py +268 -0
- sage/matroids/set_system.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/set_system.pxd +38 -0
- sage/matroids/set_system.pyx +800 -0
- sage/matroids/transversal_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/transversal_matroid.pxd +14 -0
- sage/matroids/transversal_matroid.pyx +893 -0
- sage/matroids/union_matroid.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/union_matroid.pxd +20 -0
- sage/matroids/union_matroid.pyx +331 -0
- sage/matroids/unpickling.cpython-314-aarch64-linux-musl.so +0 -0
- sage/matroids/unpickling.pyx +843 -0
- sage/matroids/utilities.py +809 -0
- sage/misc/all__sagemath_modules.py +20 -0
- sage/misc/c3.cpython-314-aarch64-linux-musl.so +0 -0
- sage/misc/c3.pyx +238 -0
- sage/misc/compat.py +87 -0
- sage/misc/element_with_label.py +173 -0
- sage/misc/func_persist.py +79 -0
- sage/misc/pickle_old.cpython-314-aarch64-linux-musl.so +0 -0
- sage/misc/pickle_old.pyx +19 -0
- sage/misc/proof.py +7 -0
- sage/misc/replace_dot_all.py +472 -0
- sage/misc/sagedoc_conf.py +168 -0
- sage/misc/sphinxify.py +167 -0
- sage/misc/test_class_pickling.py +85 -0
- sage/modules/all.py +42 -0
- sage/modules/complex_double_vector.py +25 -0
- sage/modules/diamond_cutting.py +380 -0
- sage/modules/fg_pid/all.py +1 -0
- sage/modules/fg_pid/fgp_element.py +456 -0
- sage/modules/fg_pid/fgp_module.py +2091 -0
- sage/modules/fg_pid/fgp_morphism.py +550 -0
- sage/modules/filtered_vector_space.py +1271 -0
- sage/modules/finite_submodule_iter.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/finite_submodule_iter.pxd +27 -0
- sage/modules/finite_submodule_iter.pyx +452 -0
- sage/modules/fp_graded/all.py +1 -0
- sage/modules/fp_graded/element.py +346 -0
- sage/modules/fp_graded/free_element.py +298 -0
- sage/modules/fp_graded/free_homspace.py +53 -0
- sage/modules/fp_graded/free_module.py +1060 -0
- sage/modules/fp_graded/free_morphism.py +217 -0
- sage/modules/fp_graded/homspace.py +563 -0
- sage/modules/fp_graded/module.py +1340 -0
- sage/modules/fp_graded/morphism.py +1990 -0
- sage/modules/fp_graded/steenrod/all.py +1 -0
- sage/modules/fp_graded/steenrod/homspace.py +65 -0
- sage/modules/fp_graded/steenrod/module.py +477 -0
- sage/modules/fp_graded/steenrod/morphism.py +404 -0
- sage/modules/fp_graded/steenrod/profile.py +241 -0
- sage/modules/free_module.py +8447 -0
- sage/modules/free_module_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/free_module_element.pxd +22 -0
- sage/modules/free_module_element.pyx +5445 -0
- sage/modules/free_module_homspace.py +369 -0
- sage/modules/free_module_integer.py +896 -0
- sage/modules/free_module_morphism.py +823 -0
- sage/modules/free_module_pseudohomspace.py +352 -0
- sage/modules/free_module_pseudomorphism.py +578 -0
- sage/modules/free_quadratic_module.py +1706 -0
- sage/modules/free_quadratic_module_integer_symmetric.py +1790 -0
- sage/modules/matrix_morphism.py +1745 -0
- sage/modules/misc.py +103 -0
- sage/modules/module_functors.py +192 -0
- sage/modules/multi_filtered_vector_space.py +719 -0
- sage/modules/ore_module.py +2208 -0
- sage/modules/ore_module_element.py +178 -0
- sage/modules/ore_module_homspace.py +147 -0
- sage/modules/ore_module_morphism.py +968 -0
- sage/modules/quotient_module.py +699 -0
- sage/modules/real_double_vector.py +22 -0
- sage/modules/submodule.py +255 -0
- sage/modules/tensor_operations.py +567 -0
- sage/modules/torsion_quadratic_module.py +1352 -0
- sage/modules/tutorial_free_modules.py +248 -0
- sage/modules/vector_complex_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_complex_double_dense.pxd +6 -0
- sage/modules/vector_complex_double_dense.pyx +117 -0
- sage/modules/vector_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_double_dense.pxd +6 -0
- sage/modules/vector_double_dense.pyx +604 -0
- sage/modules/vector_integer_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_integer_dense.pxd +15 -0
- sage/modules/vector_integer_dense.pyx +361 -0
- sage/modules/vector_integer_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_integer_sparse.pxd +29 -0
- sage/modules/vector_integer_sparse.pyx +406 -0
- sage/modules/vector_modn_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_modn_dense.pxd +12 -0
- sage/modules/vector_modn_dense.pyx +394 -0
- sage/modules/vector_modn_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_modn_sparse.pxd +21 -0
- sage/modules/vector_modn_sparse.pyx +298 -0
- sage/modules/vector_numpy_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_numpy_dense.pxd +15 -0
- sage/modules/vector_numpy_dense.pyx +304 -0
- sage/modules/vector_numpy_integer_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_numpy_integer_dense.pxd +7 -0
- sage/modules/vector_numpy_integer_dense.pyx +54 -0
- sage/modules/vector_rational_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_rational_dense.pxd +15 -0
- sage/modules/vector_rational_dense.pyx +387 -0
- sage/modules/vector_rational_sparse.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_rational_sparse.pxd +30 -0
- sage/modules/vector_rational_sparse.pyx +413 -0
- sage/modules/vector_real_double_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/vector_real_double_dense.pxd +6 -0
- sage/modules/vector_real_double_dense.pyx +126 -0
- sage/modules/vector_space_homspace.py +430 -0
- sage/modules/vector_space_morphism.py +989 -0
- sage/modules/with_basis/all.py +15 -0
- sage/modules/with_basis/cell_module.py +494 -0
- sage/modules/with_basis/indexed_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/modules/with_basis/indexed_element.pxd +13 -0
- sage/modules/with_basis/indexed_element.pyx +1058 -0
- sage/modules/with_basis/invariant.py +1075 -0
- sage/modules/with_basis/morphism.py +1636 -0
- sage/modules/with_basis/representation.py +2939 -0
- sage/modules/with_basis/subquotient.py +685 -0
- sage/numerical/all__sagemath_modules.py +6 -0
- sage/numerical/gauss_legendre.cpython-314-aarch64-linux-musl.so +0 -0
- sage/numerical/gauss_legendre.pyx +381 -0
- sage/numerical/optimize.py +910 -0
- sage/probability/all.py +10 -0
- sage/probability/probability_distribution.cpython-314-aarch64-linux-musl.so +0 -0
- sage/probability/probability_distribution.pyx +1242 -0
- sage/probability/random_variable.py +411 -0
- sage/quadratic_forms/all.py +4 -0
- sage/quadratic_forms/all__sagemath_modules.py +15 -0
- sage/quadratic_forms/binary_qf.py +2042 -0
- sage/quadratic_forms/bqf_class_group.py +748 -0
- sage/quadratic_forms/constructions.py +93 -0
- sage/quadratic_forms/count_local_2.cpython-314-aarch64-linux-musl.so +0 -0
- sage/quadratic_forms/count_local_2.pyx +365 -0
- sage/quadratic_forms/extras.py +195 -0
- sage/quadratic_forms/quadratic_form.py +1753 -0
- sage/quadratic_forms/quadratic_form__count_local_2.py +221 -0
- sage/quadratic_forms/quadratic_form__equivalence_testing.py +708 -0
- sage/quadratic_forms/quadratic_form__evaluate.cpython-314-aarch64-linux-musl.so +0 -0
- sage/quadratic_forms/quadratic_form__evaluate.pyx +139 -0
- sage/quadratic_forms/quadratic_form__local_density_congruence.py +977 -0
- sage/quadratic_forms/quadratic_form__local_field_invariants.py +1072 -0
- sage/quadratic_forms/quadratic_form__neighbors.py +424 -0
- sage/quadratic_forms/quadratic_form__reduction_theory.py +488 -0
- sage/quadratic_forms/quadratic_form__split_local_covering.py +416 -0
- sage/quadratic_forms/quadratic_form__ternary_Tornaria.py +657 -0
- sage/quadratic_forms/quadratic_form__theta.py +352 -0
- sage/quadratic_forms/quadratic_form__variable_substitutions.py +370 -0
- sage/quadratic_forms/random_quadraticform.py +209 -0
- sage/quadratic_forms/ternary.cpython-314-aarch64-linux-musl.so +0 -0
- sage/quadratic_forms/ternary.pyx +1154 -0
- sage/quadratic_forms/ternary_qf.py +2027 -0
- sage/rings/all__sagemath_modules.py +28 -0
- sage/rings/asymptotic/all__sagemath_modules.py +1 -0
- sage/rings/asymptotic/misc.py +1252 -0
- sage/rings/cc.py +4 -0
- sage/rings/cfinite_sequence.py +1306 -0
- sage/rings/complex_conversion.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/complex_conversion.pxd +8 -0
- sage/rings/complex_conversion.pyx +23 -0
- sage/rings/complex_double.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/complex_double.pxd +21 -0
- sage/rings/complex_double.pyx +2654 -0
- sage/rings/complex_mpc.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/complex_mpc.pxd +21 -0
- sage/rings/complex_mpc.pyx +2576 -0
- sage/rings/complex_mpfr.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/complex_mpfr.pxd +18 -0
- sage/rings/complex_mpfr.pyx +3602 -0
- sage/rings/derivation.py +2334 -0
- sage/rings/finite_rings/all__sagemath_modules.py +1 -0
- sage/rings/finite_rings/maps_finite_field.py +191 -0
- sage/rings/function_field/all__sagemath_modules.py +8 -0
- sage/rings/function_field/derivations.py +102 -0
- sage/rings/function_field/derivations_rational.py +132 -0
- sage/rings/function_field/differential.py +853 -0
- sage/rings/function_field/divisor.py +1107 -0
- sage/rings/function_field/drinfeld_modules/action.py +199 -0
- sage/rings/function_field/drinfeld_modules/all.py +1 -0
- sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py +673 -0
- sage/rings/function_field/drinfeld_modules/drinfeld_module.py +2087 -0
- sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +1131 -0
- sage/rings/function_field/drinfeld_modules/homset.py +420 -0
- sage/rings/function_field/drinfeld_modules/morphism.py +820 -0
- sage/rings/function_field/hermite_form_polynomial.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/function_field/hermite_form_polynomial.pyx +188 -0
- sage/rings/function_field/khuri_makdisi.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/function_field/khuri_makdisi.pyx +935 -0
- sage/rings/invariants/all.py +4 -0
- sage/rings/invariants/invariant_theory.py +4597 -0
- sage/rings/invariants/reconstruction.py +395 -0
- sage/rings/polynomial/all__sagemath_modules.py +17 -0
- sage/rings/polynomial/integer_valued_polynomials.py +1230 -0
- sage/rings/polynomial/laurent_polynomial_mpair.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/laurent_polynomial_mpair.pxd +15 -0
- sage/rings/polynomial/laurent_polynomial_mpair.pyx +2023 -0
- sage/rings/polynomial/ore_function_element.py +952 -0
- sage/rings/polynomial/ore_function_field.py +1028 -0
- sage/rings/polynomial/ore_polynomial_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/ore_polynomial_element.pxd +48 -0
- sage/rings/polynomial/ore_polynomial_element.pyx +3145 -0
- sage/rings/polynomial/ore_polynomial_ring.py +1334 -0
- sage/rings/polynomial/polynomial_real_mpfr_dense.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +788 -0
- sage/rings/polynomial/q_integer_valued_polynomials.py +1264 -0
- sage/rings/polynomial/skew_polynomial_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_element.pxd +9 -0
- sage/rings/polynomial/skew_polynomial_element.pyx +684 -0
- sage/rings/polynomial/skew_polynomial_finite_field.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_finite_field.pxd +19 -0
- sage/rings/polynomial/skew_polynomial_finite_field.pyx +1093 -0
- sage/rings/polynomial/skew_polynomial_finite_order.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_finite_order.pxd +10 -0
- sage/rings/polynomial/skew_polynomial_finite_order.pyx +567 -0
- sage/rings/polynomial/skew_polynomial_ring.py +908 -0
- sage/rings/real_double_element_gsl.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/real_double_element_gsl.pxd +8 -0
- sage/rings/real_double_element_gsl.pyx +794 -0
- sage/rings/real_field.py +58 -0
- sage/rings/real_mpfr.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/real_mpfr.pxd +29 -0
- sage/rings/real_mpfr.pyx +6122 -0
- sage/rings/ring_extension.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/ring_extension.pxd +42 -0
- sage/rings/ring_extension.pyx +2779 -0
- sage/rings/ring_extension_conversion.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/ring_extension_conversion.pxd +16 -0
- sage/rings/ring_extension_conversion.pyx +462 -0
- sage/rings/ring_extension_element.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/ring_extension_element.pxd +21 -0
- sage/rings/ring_extension_element.pyx +1635 -0
- sage/rings/ring_extension_homset.py +64 -0
- sage/rings/ring_extension_morphism.cpython-314-aarch64-linux-musl.so +0 -0
- sage/rings/ring_extension_morphism.pxd +35 -0
- sage/rings/ring_extension_morphism.pyx +920 -0
- sage/schemes/all__sagemath_modules.py +1 -0
- sage/schemes/projective/all__sagemath_modules.py +1 -0
- sage/schemes/projective/coherent_sheaf.py +300 -0
- sage/schemes/projective/cohomology.py +510 -0
- sage/stats/all.py +15 -0
- sage/stats/basic_stats.py +489 -0
- sage/stats/distributions/all.py +7 -0
- sage/stats/distributions/catalog.py +34 -0
- sage/stats/distributions/dgs.h +50 -0
- sage/stats/distributions/dgs.pxd +111 -0
- sage/stats/distributions/dgs_bern.h +400 -0
- sage/stats/distributions/dgs_gauss.h +614 -0
- sage/stats/distributions/dgs_misc.h +104 -0
- sage/stats/distributions/discrete_gaussian_integer.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/distributions/discrete_gaussian_integer.pxd +14 -0
- sage/stats/distributions/discrete_gaussian_integer.pyx +498 -0
- sage/stats/distributions/discrete_gaussian_lattice.py +908 -0
- sage/stats/distributions/discrete_gaussian_polynomial.py +141 -0
- sage/stats/hmm/all.py +15 -0
- sage/stats/hmm/chmm.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/hmm/chmm.pyx +1595 -0
- sage/stats/hmm/distributions.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/hmm/distributions.pxd +29 -0
- sage/stats/hmm/distributions.pyx +531 -0
- sage/stats/hmm/hmm.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/hmm/hmm.pxd +17 -0
- sage/stats/hmm/hmm.pyx +1388 -0
- sage/stats/hmm/util.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/hmm/util.pxd +7 -0
- sage/stats/hmm/util.pyx +165 -0
- sage/stats/intlist.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/intlist.pxd +14 -0
- sage/stats/intlist.pyx +588 -0
- sage/stats/r.py +49 -0
- sage/stats/time_series.cpython-314-aarch64-linux-musl.so +0 -0
- sage/stats/time_series.pxd +6 -0
- sage/stats/time_series.pyx +2546 -0
- sage/tensor/all.py +2 -0
- sage/tensor/modules/all.py +8 -0
- sage/tensor/modules/alternating_contr_tensor.py +761 -0
- sage/tensor/modules/comp.py +5598 -0
- sage/tensor/modules/ext_pow_free_module.py +824 -0
- sage/tensor/modules/finite_rank_free_module.py +3589 -0
- sage/tensor/modules/format_utilities.py +333 -0
- sage/tensor/modules/free_module_alt_form.py +858 -0
- sage/tensor/modules/free_module_automorphism.py +1207 -0
- sage/tensor/modules/free_module_basis.py +1074 -0
- sage/tensor/modules/free_module_element.py +284 -0
- sage/tensor/modules/free_module_homset.py +652 -0
- sage/tensor/modules/free_module_linear_group.py +564 -0
- sage/tensor/modules/free_module_morphism.py +1581 -0
- sage/tensor/modules/free_module_tensor.py +3289 -0
- sage/tensor/modules/reflexive_module.py +386 -0
- sage/tensor/modules/tensor_free_module.py +780 -0
- sage/tensor/modules/tensor_free_submodule.py +538 -0
- sage/tensor/modules/tensor_free_submodule_basis.py +140 -0
- sage/tensor/modules/tensor_with_indices.py +1043 -0
|
@@ -0,0 +1,2848 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-modules
|
|
2
|
+
r"""
|
|
3
|
+
Matrix Spaces
|
|
4
|
+
|
|
5
|
+
You can create any space `\text{Mat}_{n\times m}(R)` of
|
|
6
|
+
either dense or sparse matrices with given number of rows and
|
|
7
|
+
columns over any commutative or noncommutative ring.
|
|
8
|
+
|
|
9
|
+
EXAMPLES::
|
|
10
|
+
|
|
11
|
+
sage: MS = MatrixSpace(QQ, 6,6, sparse=True); MS
|
|
12
|
+
Full MatrixSpace of 6 by 6 sparse matrices over Rational Field
|
|
13
|
+
sage: MS.base_ring()
|
|
14
|
+
Rational Field
|
|
15
|
+
sage: MS = MatrixSpace(ZZ, 3,5, sparse=False); MS
|
|
16
|
+
Full MatrixSpace of 3 by 5 dense matrices over Integer Ring
|
|
17
|
+
|
|
18
|
+
TESTS::
|
|
19
|
+
|
|
20
|
+
sage: matrix(RR,2,2,sparse=True)
|
|
21
|
+
[0.000000000000000 0.000000000000000]
|
|
22
|
+
[0.000000000000000 0.000000000000000]
|
|
23
|
+
sage: matrix(GF(11), 2, 2, sparse=True)
|
|
24
|
+
[0 0]
|
|
25
|
+
[0 0]
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
# ****************************************************************************
|
|
29
|
+
# This program is free software: you can redistribute it and/or modify
|
|
30
|
+
# it under the terms of the GNU General Public License as published by
|
|
31
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
32
|
+
# (at your option) any later version.
|
|
33
|
+
# https://www.gnu.org/licenses/
|
|
34
|
+
# ****************************************************************************
|
|
35
|
+
|
|
36
|
+
# System imports
|
|
37
|
+
import sys
|
|
38
|
+
import operator
|
|
39
|
+
|
|
40
|
+
# Sage matrix imports see :issue:`34283`
|
|
41
|
+
|
|
42
|
+
# Sage imports
|
|
43
|
+
import sage.structure.coerce_actions
|
|
44
|
+
from sage.structure.parent import Parent
|
|
45
|
+
from sage.structure.unique_representation import UniqueRepresentation
|
|
46
|
+
import sage.rings.integer as integer
|
|
47
|
+
from sage.rings.finite_rings.finite_field_base import FiniteField
|
|
48
|
+
import sage.misc.latex as latex
|
|
49
|
+
import sage.modules.free_module
|
|
50
|
+
|
|
51
|
+
from sage.misc.lazy_attribute import lazy_attribute
|
|
52
|
+
from sage.misc.superseded import deprecated_function_alias
|
|
53
|
+
from sage.misc.persist import register_unpickle_override
|
|
54
|
+
from sage.categories.rings import Rings
|
|
55
|
+
from sage.categories.fields import Fields
|
|
56
|
+
from sage.categories.enumerated_sets import EnumeratedSets
|
|
57
|
+
|
|
58
|
+
from sage.misc.lazy_import import lazy_import
|
|
59
|
+
from sage.features.meataxe import Meataxe
|
|
60
|
+
lazy_import('sage.matrix.matrix_gfpn_dense', ['Matrix_gfpn_dense'],
|
|
61
|
+
feature=Meataxe())
|
|
62
|
+
lazy_import('sage.groups.matrix_gps.matrix_group', ['MatrixGroup_base'])
|
|
63
|
+
|
|
64
|
+
_Rings = Rings()
|
|
65
|
+
_Fields = Fields()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def is_MatrixSpace(x):
|
|
69
|
+
"""
|
|
70
|
+
Return whether ``self`` is an instance of ``MatrixSpace``.
|
|
71
|
+
|
|
72
|
+
EXAMPLES::
|
|
73
|
+
|
|
74
|
+
sage: from sage.matrix.matrix_space import is_MatrixSpace
|
|
75
|
+
sage: MS = MatrixSpace(QQ,2)
|
|
76
|
+
sage: A = MS.random_element()
|
|
77
|
+
sage: is_MatrixSpace(MS)
|
|
78
|
+
doctest:warning...
|
|
79
|
+
DeprecationWarning: the function is_MatrixSpace is deprecated;
|
|
80
|
+
use 'isinstance(..., MatrixSpace)' instead
|
|
81
|
+
See https://github.com/sagemath/sage/issues/37924 for details.
|
|
82
|
+
True
|
|
83
|
+
sage: is_MatrixSpace(A)
|
|
84
|
+
False
|
|
85
|
+
sage: is_MatrixSpace(5)
|
|
86
|
+
False
|
|
87
|
+
"""
|
|
88
|
+
from sage.misc.superseded import deprecation
|
|
89
|
+
deprecation(37924, "the function is_MatrixSpace is deprecated; use 'isinstance(..., MatrixSpace)' instead")
|
|
90
|
+
return isinstance(x, MatrixSpace)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_matrix_class(R, nrows, ncols, sparse, implementation):
|
|
94
|
+
r"""
|
|
95
|
+
Return a matrix class according to the input.
|
|
96
|
+
|
|
97
|
+
.. NOTE::
|
|
98
|
+
|
|
99
|
+
This returns the base class without the category.
|
|
100
|
+
|
|
101
|
+
INPUT:
|
|
102
|
+
|
|
103
|
+
- ``R`` -- a base ring
|
|
104
|
+
|
|
105
|
+
- ``nrows`` -- number of rows
|
|
106
|
+
|
|
107
|
+
- ``ncols`` -- number of columns
|
|
108
|
+
|
|
109
|
+
- ``sparse`` -- boolean; whether the matrix class should be sparse
|
|
110
|
+
|
|
111
|
+
- ``implementation`` -- ``None`` or string or a matrix class; a possible
|
|
112
|
+
implementation. See the documentation of the constructor of :class:`MatrixSpace`.
|
|
113
|
+
|
|
114
|
+
EXAMPLES::
|
|
115
|
+
|
|
116
|
+
sage: from sage.matrix.matrix_space import get_matrix_class
|
|
117
|
+
|
|
118
|
+
sage: get_matrix_class(ZZ, 4, 5, False, None) # needs sage.libs.linbox
|
|
119
|
+
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
|
|
120
|
+
sage: get_matrix_class(ZZ, 4, 5, True, None) # needs sage.libs.linbox
|
|
121
|
+
<class 'sage.matrix.matrix_integer_sparse.Matrix_integer_sparse'>
|
|
122
|
+
|
|
123
|
+
sage: get_matrix_class(ZZ, 3, 3, False, 'flint') # needs sage.libs.linbox
|
|
124
|
+
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
|
|
125
|
+
sage: get_matrix_class(ZZ, 3, 3, False, 'gap') # needs sage.libs.gap
|
|
126
|
+
<class 'sage.matrix.matrix_gap.Matrix_gap'>
|
|
127
|
+
sage: get_matrix_class(ZZ, 3, 3, False, 'generic')
|
|
128
|
+
<class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
|
|
129
|
+
|
|
130
|
+
sage: get_matrix_class(GF(2^15), 3, 3, False, None) # needs sage.rings.finite_rings
|
|
131
|
+
<class 'sage.matrix.matrix_gf2e_dense.Matrix_gf2e_dense'>
|
|
132
|
+
sage: get_matrix_class(GF(2^17), 3, 3, False, None) # needs sage.rings.finite_rings
|
|
133
|
+
<class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
|
|
134
|
+
|
|
135
|
+
sage: get_matrix_class(GF(2), 2, 2, False, 'm4ri') # needs sage.libs.m4ri
|
|
136
|
+
<class 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>
|
|
137
|
+
sage: get_matrix_class(GF(4), 2, 2, False, 'm4ri') # needs sage.libs.m4ri sage.rings.finite_rings
|
|
138
|
+
<class 'sage.matrix.matrix_gf2e_dense.Matrix_gf2e_dense'>
|
|
139
|
+
sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-float') # needs sage.libs.linbox
|
|
140
|
+
<class 'sage.matrix.matrix_modn_dense_float.Matrix_modn_dense_float'>
|
|
141
|
+
sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-double') # needs sage.libs.linbox
|
|
142
|
+
<class 'sage.matrix.matrix_modn_dense_double.Matrix_modn_dense_double'>
|
|
143
|
+
|
|
144
|
+
sage: get_matrix_class(RDF, 2, 2, False, 'numpy') # needs numpy
|
|
145
|
+
<class 'sage.matrix.matrix_real_double_dense.Matrix_real_double_dense'>
|
|
146
|
+
sage: get_matrix_class(CDF, 2, 3, False, 'numpy') # needs numpy sage.rings.complex_double
|
|
147
|
+
<class 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'>
|
|
148
|
+
|
|
149
|
+
sage: get_matrix_class(GF(25,'x'), 4, 4, False, 'meataxe') # optional - meataxe, needs sage.rings.finite_rings
|
|
150
|
+
<class 'sage.matrix.matrix_gfpn_dense.Matrix_gfpn_dense'>
|
|
151
|
+
sage: get_matrix_class(IntegerModRing(3), 4, 4, False, 'meataxe') # optional - meataxe
|
|
152
|
+
<class 'sage.matrix.matrix_gfpn_dense.Matrix_gfpn_dense'>
|
|
153
|
+
sage: get_matrix_class(IntegerModRing(4), 4, 4, False, 'meataxe')
|
|
154
|
+
Traceback (most recent call last):
|
|
155
|
+
...
|
|
156
|
+
ValueError: 'meataxe' matrix can only deal with finite fields of order < 256
|
|
157
|
+
sage: get_matrix_class(GF(next_prime(255)), 4, 4, False, 'meataxe') # needs sage.rings.finite_rings
|
|
158
|
+
Traceback (most recent call last):
|
|
159
|
+
...
|
|
160
|
+
ValueError: 'meataxe' matrix can only deal with finite fields of order < 256
|
|
161
|
+
|
|
162
|
+
sage: get_matrix_class(ZZ, 3, 5, False, 'crazy_matrix')
|
|
163
|
+
Traceback (most recent call last):
|
|
164
|
+
...
|
|
165
|
+
ValueError: unknown matrix implementation 'crazy_matrix' over Integer Ring
|
|
166
|
+
sage: get_matrix_class(GF(3), 2, 2, False, 'm4ri')
|
|
167
|
+
Traceback (most recent call last):
|
|
168
|
+
...
|
|
169
|
+
ValueError: 'm4ri' matrices are only available for fields of characteristic 2
|
|
170
|
+
and order <= 65536
|
|
171
|
+
sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-float') # needs sage.libs.linbox
|
|
172
|
+
Traceback (most recent call last):
|
|
173
|
+
...
|
|
174
|
+
ValueError: 'linbox-float' matrices can only deal with order < 256
|
|
175
|
+
sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-double') # needs sage.libs.linbox
|
|
176
|
+
Traceback (most recent call last):
|
|
177
|
+
...
|
|
178
|
+
ValueError: 'linbox-double' matrices can only deal with order < 94906266
|
|
179
|
+
|
|
180
|
+
sage: type(matrix(SR, 2, 2, 0)) # needs sage.symbolic
|
|
181
|
+
<class 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>
|
|
182
|
+
sage: type(matrix(SR, 2, 2, 0, sparse=True)) # needs sage.symbolic
|
|
183
|
+
<class 'sage.matrix.matrix_symbolic_sparse.Matrix_symbolic_sparse'>
|
|
184
|
+
sage: type(matrix(GF(7), 2, range(4))) # needs sage.libs.linbox
|
|
185
|
+
<class 'sage.matrix.matrix_modn_dense_float.Matrix_modn_dense_float'>
|
|
186
|
+
sage: type(matrix(GF(16007), 2, range(4))) # needs sage.libs.linbox
|
|
187
|
+
<class 'sage.matrix.matrix_modn_dense_double.Matrix_modn_dense_double'>
|
|
188
|
+
sage: type(matrix(CBF, 2, range(4))) # needs sage.libs.flint
|
|
189
|
+
<class 'sage.matrix.matrix_complex_ball_dense.Matrix_complex_ball_dense'>
|
|
190
|
+
sage: type(matrix(GF(2), 2, range(4))) # needs sage.libs.m4ri
|
|
191
|
+
<class 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>
|
|
192
|
+
sage: type(matrix(GF(64, 'z'), 2, range(4))) # needs sage.libs.m4ri sage.rings.finite_rings
|
|
193
|
+
<class 'sage.matrix.matrix_gf2e_dense.Matrix_gf2e_dense'>
|
|
194
|
+
sage: type(matrix(GF(125, 'z'), 2, range(4))) # optional - meataxe, needs sage.rings.finite_rings
|
|
195
|
+
<class 'sage.matrix.matrix_gfpn_dense.Matrix_gfpn_dense'>
|
|
196
|
+
"""
|
|
197
|
+
if isinstance(implementation, type):
|
|
198
|
+
return implementation
|
|
199
|
+
|
|
200
|
+
if not sparse:
|
|
201
|
+
if implementation is None:
|
|
202
|
+
# Choose default implementation:
|
|
203
|
+
if R is sage.rings.integer_ring.ZZ:
|
|
204
|
+
try:
|
|
205
|
+
from . import matrix_integer_dense
|
|
206
|
+
except ImportError:
|
|
207
|
+
pass
|
|
208
|
+
else:
|
|
209
|
+
return matrix_integer_dense.Matrix_integer_dense
|
|
210
|
+
|
|
211
|
+
elif R is sage.rings.rational_field.QQ:
|
|
212
|
+
try:
|
|
213
|
+
from . import matrix_rational_dense
|
|
214
|
+
except ImportError:
|
|
215
|
+
pass
|
|
216
|
+
else:
|
|
217
|
+
return matrix_rational_dense.Matrix_rational_dense
|
|
218
|
+
|
|
219
|
+
elif isinstance(R, sage.rings.abc.RealDoubleField):
|
|
220
|
+
try:
|
|
221
|
+
from . import matrix_real_double_dense
|
|
222
|
+
except ImportError:
|
|
223
|
+
pass
|
|
224
|
+
else:
|
|
225
|
+
return matrix_real_double_dense.Matrix_real_double_dense
|
|
226
|
+
|
|
227
|
+
elif isinstance(R, sage.rings.abc.ComplexDoubleField):
|
|
228
|
+
if implementation is None or implementation == 'numpy':
|
|
229
|
+
try:
|
|
230
|
+
from . import matrix_complex_double_dense
|
|
231
|
+
except ImportError:
|
|
232
|
+
pass
|
|
233
|
+
else:
|
|
234
|
+
return matrix_complex_double_dense.Matrix_complex_double_dense
|
|
235
|
+
|
|
236
|
+
elif isinstance(R, FiniteField):
|
|
237
|
+
if R.order() == 2:
|
|
238
|
+
try:
|
|
239
|
+
from . import matrix_mod2_dense
|
|
240
|
+
except ImportError:
|
|
241
|
+
pass
|
|
242
|
+
else:
|
|
243
|
+
return matrix_mod2_dense.Matrix_mod2_dense
|
|
244
|
+
|
|
245
|
+
if R.characteristic() == 2 and R.order() <= 65536: # 65536 == 2^16
|
|
246
|
+
try:
|
|
247
|
+
from . import matrix_gf2e_dense
|
|
248
|
+
except ImportError:
|
|
249
|
+
pass
|
|
250
|
+
else:
|
|
251
|
+
return matrix_gf2e_dense.Matrix_gf2e_dense
|
|
252
|
+
|
|
253
|
+
if (not R.is_prime_field()) and R.order() < 256:
|
|
254
|
+
try:
|
|
255
|
+
from . import matrix_gfpn_dense
|
|
256
|
+
return matrix_gfpn_dense.Matrix_gfpn_dense
|
|
257
|
+
except ImportError:
|
|
258
|
+
pass
|
|
259
|
+
|
|
260
|
+
if isinstance(R, sage.rings.abc.IntegerModRing):
|
|
261
|
+
try:
|
|
262
|
+
from . import matrix_modn_dense_double, matrix_modn_dense_float
|
|
263
|
+
except ImportError:
|
|
264
|
+
pass
|
|
265
|
+
else:
|
|
266
|
+
if R.order() < matrix_modn_dense_float.MAX_MODULUS:
|
|
267
|
+
return matrix_modn_dense_float.Matrix_modn_dense_float
|
|
268
|
+
if R.order() < matrix_modn_dense_double.MAX_MODULUS:
|
|
269
|
+
return matrix_modn_dense_double.Matrix_modn_dense_double
|
|
270
|
+
|
|
271
|
+
if isinstance(R, sage.rings.abc.NumberField_cyclotomic):
|
|
272
|
+
from . import matrix_cyclo_dense
|
|
273
|
+
return matrix_cyclo_dense.Matrix_cyclo_dense
|
|
274
|
+
|
|
275
|
+
try:
|
|
276
|
+
from sage.symbolic.ring import SR
|
|
277
|
+
except ImportError:
|
|
278
|
+
pass
|
|
279
|
+
else:
|
|
280
|
+
if R is SR:
|
|
281
|
+
try:
|
|
282
|
+
from . import matrix_symbolic_dense
|
|
283
|
+
except ImportError:
|
|
284
|
+
pass
|
|
285
|
+
else:
|
|
286
|
+
return matrix_symbolic_dense.Matrix_symbolic_dense
|
|
287
|
+
|
|
288
|
+
if isinstance(R, sage.rings.abc.ComplexBallField):
|
|
289
|
+
try:
|
|
290
|
+
from . import matrix_complex_ball_dense
|
|
291
|
+
except ImportError:
|
|
292
|
+
pass
|
|
293
|
+
else:
|
|
294
|
+
return matrix_complex_ball_dense.Matrix_complex_ball_dense
|
|
295
|
+
|
|
296
|
+
try:
|
|
297
|
+
from sage.rings.polynomial import polynomial_ring, multi_polynomial_ring_base
|
|
298
|
+
except ImportError:
|
|
299
|
+
pass
|
|
300
|
+
else:
|
|
301
|
+
if isinstance(R, polynomial_ring.PolynomialRing_generic) and R.base_ring() in _Fields:
|
|
302
|
+
try:
|
|
303
|
+
from . import matrix_polynomial_dense
|
|
304
|
+
except ImportError:
|
|
305
|
+
pass
|
|
306
|
+
else:
|
|
307
|
+
return matrix_polynomial_dense.Matrix_polynomial_dense
|
|
308
|
+
|
|
309
|
+
elif isinstance(R, multi_polynomial_ring_base.MPolynomialRing_base) and R.base_ring() in _Fields:
|
|
310
|
+
try:
|
|
311
|
+
from . import matrix_mpolynomial_dense
|
|
312
|
+
except ImportError:
|
|
313
|
+
pass
|
|
314
|
+
else:
|
|
315
|
+
return matrix_mpolynomial_dense.Matrix_mpolynomial_dense
|
|
316
|
+
elif isinstance(R, sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair) and R.base_ring() in _Fields:
|
|
317
|
+
try:
|
|
318
|
+
from . import matrix_laurent_mpolynomial_dense
|
|
319
|
+
except ImportError:
|
|
320
|
+
pass
|
|
321
|
+
else:
|
|
322
|
+
return matrix_laurent_mpolynomial_dense.Matrix_laurent_mpolynomial_dense
|
|
323
|
+
|
|
324
|
+
# The fallback
|
|
325
|
+
from sage.matrix.matrix_generic_dense import Matrix_generic_dense
|
|
326
|
+
return Matrix_generic_dense
|
|
327
|
+
|
|
328
|
+
# Deal with request for a specific implementation
|
|
329
|
+
if implementation == 'flint':
|
|
330
|
+
if R is sage.rings.integer_ring.ZZ:
|
|
331
|
+
from . import matrix_integer_dense
|
|
332
|
+
return matrix_integer_dense.Matrix_integer_dense
|
|
333
|
+
if R is sage.rings.rational_field.QQ:
|
|
334
|
+
from . import matrix_rational_dense
|
|
335
|
+
return matrix_rational_dense.Matrix_rational_dense
|
|
336
|
+
raise ValueError("'flint' matrices are only available over the integers or the rationals")
|
|
337
|
+
|
|
338
|
+
if implementation == 'm4ri':
|
|
339
|
+
if R.is_field() and R.characteristic() == 2 and R.order() <= 65536:
|
|
340
|
+
if R.order() == 2:
|
|
341
|
+
from . import matrix_mod2_dense
|
|
342
|
+
return matrix_mod2_dense.Matrix_mod2_dense
|
|
343
|
+
from . import matrix_gf2e_dense
|
|
344
|
+
return matrix_gf2e_dense.Matrix_gf2e_dense
|
|
345
|
+
raise ValueError("'m4ri' matrices are only available for fields of characteristic 2 and order <= 65536")
|
|
346
|
+
|
|
347
|
+
if implementation == 'meataxe':
|
|
348
|
+
if R.is_field() and R.order() < 256:
|
|
349
|
+
return Matrix_gfpn_dense
|
|
350
|
+
raise ValueError("'meataxe' matrix can only deal with finite fields of order < 256")
|
|
351
|
+
|
|
352
|
+
if implementation == 'numpy':
|
|
353
|
+
if R is sage.rings.real_double.RDF:
|
|
354
|
+
from . import matrix_real_double_dense
|
|
355
|
+
return matrix_real_double_dense.Matrix_real_double_dense
|
|
356
|
+
if R is sage.rings.complex_double.CDF:
|
|
357
|
+
from . import matrix_complex_double_dense
|
|
358
|
+
return matrix_complex_double_dense.Matrix_complex_double_dense
|
|
359
|
+
if R is sage.rings.integer_ring.ZZ:
|
|
360
|
+
from . import matrix_numpy_integer_dense
|
|
361
|
+
return matrix_numpy_integer_dense.Matrix_numpy_integer_dense
|
|
362
|
+
raise ValueError("'numpy' matrices are only available over RDF, CDF, and ZZ")
|
|
363
|
+
|
|
364
|
+
if implementation == 'rational':
|
|
365
|
+
if isinstance(R, sage.rings.abc.NumberField_cyclotomic):
|
|
366
|
+
from . import matrix_cyclo_dense
|
|
367
|
+
return matrix_cyclo_dense.Matrix_cyclo_dense
|
|
368
|
+
raise ValueError("'rational' matrices are only available over a cyclotomic field")
|
|
369
|
+
|
|
370
|
+
if implementation == 'linbox-float':
|
|
371
|
+
from . import matrix_modn_dense_float
|
|
372
|
+
if R.order() < matrix_modn_dense_float.MAX_MODULUS:
|
|
373
|
+
return matrix_modn_dense_float.Matrix_modn_dense_float
|
|
374
|
+
raise ValueError("'linbox-float' matrices can only deal with order < %s" % matrix_modn_dense_float.MAX_MODULUS)
|
|
375
|
+
|
|
376
|
+
if implementation == 'linbox-double':
|
|
377
|
+
from . import matrix_modn_dense_double
|
|
378
|
+
if R.order() < matrix_modn_dense_double.MAX_MODULUS:
|
|
379
|
+
return matrix_modn_dense_double.Matrix_modn_dense_double
|
|
380
|
+
raise ValueError("'linbox-double' matrices can only deal with order < %s" % matrix_modn_dense_double.MAX_MODULUS)
|
|
381
|
+
|
|
382
|
+
if implementation == 'generic':
|
|
383
|
+
from sage.matrix.matrix_generic_dense import Matrix_generic_dense
|
|
384
|
+
return Matrix_generic_dense
|
|
385
|
+
|
|
386
|
+
if implementation == 'gap':
|
|
387
|
+
from sage.matrix.matrix_gap import Matrix_gap
|
|
388
|
+
return Matrix_gap
|
|
389
|
+
|
|
390
|
+
raise ValueError("unknown matrix implementation %r over %r" % (implementation, R))
|
|
391
|
+
|
|
392
|
+
# By now, we are dealing with sparse matrices
|
|
393
|
+
if implementation is not None:
|
|
394
|
+
raise ValueError("cannot choose an implementation for sparse matrices")
|
|
395
|
+
|
|
396
|
+
if isinstance(R, sage.rings.abc.IntegerModRing):
|
|
397
|
+
try:
|
|
398
|
+
from . import matrix_modn_sparse
|
|
399
|
+
except ImportError:
|
|
400
|
+
pass
|
|
401
|
+
else:
|
|
402
|
+
if R.order() < matrix_modn_sparse.MAX_MODULUS:
|
|
403
|
+
return matrix_modn_sparse.Matrix_modn_sparse
|
|
404
|
+
|
|
405
|
+
if isinstance(R, sage.rings.rational_field.RationalField):
|
|
406
|
+
try:
|
|
407
|
+
from . import matrix_rational_sparse
|
|
408
|
+
except ImportError:
|
|
409
|
+
pass
|
|
410
|
+
else:
|
|
411
|
+
return matrix_rational_sparse.Matrix_rational_sparse
|
|
412
|
+
|
|
413
|
+
if isinstance(R, sage.rings.integer_ring.IntegerRing_class):
|
|
414
|
+
try:
|
|
415
|
+
from . import matrix_integer_sparse
|
|
416
|
+
except ImportError:
|
|
417
|
+
pass
|
|
418
|
+
else:
|
|
419
|
+
return matrix_integer_sparse.Matrix_integer_sparse
|
|
420
|
+
|
|
421
|
+
if isinstance(R, (sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)):
|
|
422
|
+
from . import matrix_double_sparse
|
|
423
|
+
return matrix_double_sparse.Matrix_double_sparse
|
|
424
|
+
try:
|
|
425
|
+
from sage.symbolic.ring import SR
|
|
426
|
+
except ImportError:
|
|
427
|
+
pass
|
|
428
|
+
else:
|
|
429
|
+
if R is SR:
|
|
430
|
+
try:
|
|
431
|
+
from . import matrix_symbolic_sparse
|
|
432
|
+
except ImportError:
|
|
433
|
+
pass
|
|
434
|
+
else:
|
|
435
|
+
return matrix_symbolic_sparse.Matrix_symbolic_sparse
|
|
436
|
+
|
|
437
|
+
# the fallback
|
|
438
|
+
from sage.matrix.matrix_generic_sparse import Matrix_generic_sparse
|
|
439
|
+
return Matrix_generic_sparse
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
class MatrixSpace(UniqueRepresentation, Parent):
|
|
443
|
+
"""
|
|
444
|
+
The space of matrices of given size and base ring.
|
|
445
|
+
|
|
446
|
+
INPUT:
|
|
447
|
+
|
|
448
|
+
- ``base_ring`` -- a ring
|
|
449
|
+
|
|
450
|
+
- ``nrows`` or ``row_keys`` -- nonnegative integer; the number of rows, or
|
|
451
|
+
a finite family of arbitrary objects that index the rows of the matrix
|
|
452
|
+
|
|
453
|
+
- ``ncols`` or ``column_keys`` -- nonnegative integer (default: ``nrows``);
|
|
454
|
+
the number of columns, or a finite family of arbitrary objects that index
|
|
455
|
+
the columns of the matrix
|
|
456
|
+
|
|
457
|
+
- ``sparse`` -- boolean (default: ``False``); whether or not matrices
|
|
458
|
+
are given a sparse representation
|
|
459
|
+
|
|
460
|
+
- ``implementation`` -- (optional) string or matrix class; a possible
|
|
461
|
+
implementation. Depending on the base ring, the string can be
|
|
462
|
+
|
|
463
|
+
- ``'generic'`` -- on any base rings
|
|
464
|
+
|
|
465
|
+
- ``'flint'`` -- for integers and rationals
|
|
466
|
+
|
|
467
|
+
- ``'meataxe'`` -- finite fields using the optional package :ref:`spkg_meataxe`
|
|
468
|
+
|
|
469
|
+
- ``'m4ri'`` -- for characteristic 2 using the :ref:`spkg_m4ri` library
|
|
470
|
+
|
|
471
|
+
- ``'linbox-float'`` -- for integer mod rings up to `2^8 = 256`
|
|
472
|
+
|
|
473
|
+
- ``'linbox-double'`` -- for integer mod rings up to
|
|
474
|
+
`floor(2^26*sqrt(2) + 1/2) = 94906266`
|
|
475
|
+
|
|
476
|
+
- ``'numpy'`` -- for real and complex floating point numbers
|
|
477
|
+
|
|
478
|
+
OUTPUT: a matrix space or, more generally, a homspace between free modules
|
|
479
|
+
|
|
480
|
+
This factory function creates instances of various specialized classes
|
|
481
|
+
depending on the input. Not all combinations of options are
|
|
482
|
+
implemented.
|
|
483
|
+
|
|
484
|
+
- If the parameters ``row_keys`` or ``column_keys`` are provided, they
|
|
485
|
+
must be finite families of objects. In this case, instances of
|
|
486
|
+
:class:`CombinatorialFreeModule` are created via the factory function
|
|
487
|
+
:func:`FreeModule`. Then the homspace between these modules is returned.
|
|
488
|
+
|
|
489
|
+
EXAMPLES::
|
|
490
|
+
|
|
491
|
+
sage: MatrixSpace(QQ, 2)
|
|
492
|
+
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
|
|
493
|
+
sage: MatrixSpace(ZZ, 3, 2)
|
|
494
|
+
Full MatrixSpace of 3 by 2 dense matrices over Integer Ring
|
|
495
|
+
sage: MatrixSpace(ZZ, 3, sparse=False)
|
|
496
|
+
Full MatrixSpace of 3 by 3 dense matrices over Integer Ring
|
|
497
|
+
|
|
498
|
+
sage: MatrixSpace(ZZ, 10, 5)
|
|
499
|
+
Full MatrixSpace of 10 by 5 dense matrices over Integer Ring
|
|
500
|
+
sage: MatrixSpace(ZZ, 10, 5).category()
|
|
501
|
+
Category of infinite enumerated finite dimensional modules with basis over
|
|
502
|
+
(Dedekind domains and euclidean domains
|
|
503
|
+
and noetherian rings
|
|
504
|
+
and infinite enumerated sets and metric spaces)
|
|
505
|
+
sage: MatrixSpace(ZZ, 10, 10).category()
|
|
506
|
+
Category of infinite enumerated finite dimensional algebras with basis over
|
|
507
|
+
(Dedekind domains and euclidean domains
|
|
508
|
+
and noetherian rings
|
|
509
|
+
and infinite enumerated sets and metric spaces)
|
|
510
|
+
sage: MatrixSpace(QQ, 10).category()
|
|
511
|
+
Category of infinite finite dimensional algebras with basis over
|
|
512
|
+
(number fields and quotient fields and metric spaces)
|
|
513
|
+
|
|
514
|
+
Some examples of square 2 by 2 rational matrices::
|
|
515
|
+
|
|
516
|
+
sage: MS = MatrixSpace(QQ, 2)
|
|
517
|
+
sage: MS.dimension()
|
|
518
|
+
4
|
|
519
|
+
sage: MS.dims()
|
|
520
|
+
(2, 2)
|
|
521
|
+
sage: B = MS.basis()
|
|
522
|
+
sage: list(B)
|
|
523
|
+
[
|
|
524
|
+
[1 0] [0 1] [0 0] [0 0]
|
|
525
|
+
[0 0], [0 0], [1 0], [0 1]
|
|
526
|
+
]
|
|
527
|
+
sage: B[0,0]
|
|
528
|
+
[1 0]
|
|
529
|
+
[0 0]
|
|
530
|
+
sage: B[0,1]
|
|
531
|
+
[0 1]
|
|
532
|
+
[0 0]
|
|
533
|
+
sage: B[1,0]
|
|
534
|
+
[0 0]
|
|
535
|
+
[1 0]
|
|
536
|
+
sage: B[1,1]
|
|
537
|
+
[0 0]
|
|
538
|
+
[0 1]
|
|
539
|
+
sage: A = MS.matrix([1,2,3,4]); A
|
|
540
|
+
[1 2]
|
|
541
|
+
[3 4]
|
|
542
|
+
|
|
543
|
+
The above matrix ``A`` can be multiplied by a 2 by 3 integer matrix::
|
|
544
|
+
|
|
545
|
+
sage: MS2 = MatrixSpace(ZZ, 2, 3)
|
|
546
|
+
sage: B = MS2.matrix([1,2,3,4,5,6])
|
|
547
|
+
sage: A * B
|
|
548
|
+
[ 9 12 15]
|
|
549
|
+
[19 26 33]
|
|
550
|
+
|
|
551
|
+
Using ``row_keys`` and ``column_keys``::
|
|
552
|
+
|
|
553
|
+
sage: MS = MatrixSpace(ZZ, ['u', 'v'], ['a', 'b', 'c']); MS
|
|
554
|
+
Set of Morphisms
|
|
555
|
+
from Free module generated by {'a', 'b', 'c'} over Integer Ring
|
|
556
|
+
to Free module generated by {'u', 'v'} over Integer Ring
|
|
557
|
+
in Category of finite dimensional modules with basis over Integer Ring
|
|
558
|
+
|
|
559
|
+
Check categories::
|
|
560
|
+
|
|
561
|
+
sage: MatrixSpace(ZZ, 10, 5)
|
|
562
|
+
Full MatrixSpace of 10 by 5 dense matrices over Integer Ring
|
|
563
|
+
sage: MatrixSpace(ZZ, 10, 5).category()
|
|
564
|
+
Category of infinite enumerated finite dimensional modules with basis over
|
|
565
|
+
(Dedekind domains and euclidean domains
|
|
566
|
+
and noetherian rings
|
|
567
|
+
and infinite enumerated sets and metric spaces)
|
|
568
|
+
sage: MatrixSpace(ZZ, 10, 10).category()
|
|
569
|
+
Category of infinite enumerated finite dimensional algebras with basis over
|
|
570
|
+
(Dedekind domains and euclidean domains
|
|
571
|
+
and noetherian rings
|
|
572
|
+
and infinite enumerated sets and metric spaces)
|
|
573
|
+
sage: MatrixSpace(QQ, 10).category()
|
|
574
|
+
Category of infinite finite dimensional algebras with basis over
|
|
575
|
+
(number fields and quotient fields and metric spaces)
|
|
576
|
+
|
|
577
|
+
TESTS::
|
|
578
|
+
|
|
579
|
+
sage: MatrixSpace(ZZ, 1, 2^63)
|
|
580
|
+
Traceback (most recent call last):
|
|
581
|
+
...
|
|
582
|
+
OverflowError: number of rows and columns may be at most...
|
|
583
|
+
sage: MatrixSpace(ZZ, 2^100, 10)
|
|
584
|
+
Traceback (most recent call last):
|
|
585
|
+
...
|
|
586
|
+
OverflowError: number of rows and columns may be at most...
|
|
587
|
+
|
|
588
|
+
Check that different implementations play together as expected::
|
|
589
|
+
|
|
590
|
+
sage: # needs sage.libs.linbox
|
|
591
|
+
sage: M1 = MatrixSpace(ZZ, 2, implementation='flint')
|
|
592
|
+
sage: M2 = MatrixSpace(ZZ, 2, implementation='generic')
|
|
593
|
+
sage: type(M1(range(4)))
|
|
594
|
+
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
|
|
595
|
+
sage: type(M2(range(4)))
|
|
596
|
+
<class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
|
|
597
|
+
sage: M1(M2.an_element())
|
|
598
|
+
[ 0 1]
|
|
599
|
+
[-1 2]
|
|
600
|
+
sage: M2(M1.an_element())
|
|
601
|
+
[ 0 1]
|
|
602
|
+
[-1 2]
|
|
603
|
+
sage: all((A.get_action(B) is not None) == (A is B)
|
|
604
|
+
....: for A in [M1, M2] for B in [M1, M2])
|
|
605
|
+
True
|
|
606
|
+
|
|
607
|
+
Check that libgap matrices over finite fields are working properly::
|
|
608
|
+
|
|
609
|
+
sage: # needs sage.libs.gap
|
|
610
|
+
sage: M2 = MatrixSpace(GF(2), 5, implementation='gap')
|
|
611
|
+
sage: M2.one()
|
|
612
|
+
[1 0 0 0 0]
|
|
613
|
+
[0 1 0 0 0]
|
|
614
|
+
[0 0 1 0 0]
|
|
615
|
+
[0 0 0 1 0]
|
|
616
|
+
[0 0 0 0 1]
|
|
617
|
+
sage: m = M2.random_element()
|
|
618
|
+
sage: M1 = MatrixSpace(GF(2), 5)
|
|
619
|
+
sage: M1(m * m) == M1(m) * M1(m)
|
|
620
|
+
True
|
|
621
|
+
|
|
622
|
+
Check various combinations of dimensions and row/column keys::
|
|
623
|
+
|
|
624
|
+
sage: M_ab_4 = MatrixSpace(QQ, ['a','b'], 4); M_ab_4
|
|
625
|
+
Set of Morphisms (Linear Transformations)
|
|
626
|
+
from Vector space of dimension 4 over Rational Field
|
|
627
|
+
to Free module generated by {'a', 'b'} over Rational Field
|
|
628
|
+
sage: TestSuite(M_ab_4).run() # known bug
|
|
629
|
+
sage: M_4_ab = MatrixSpace(QQ, 4, ['a','b']); M_4_ab
|
|
630
|
+
Set of Morphisms
|
|
631
|
+
from Free module generated by {'a', 'b'} over Rational Field
|
|
632
|
+
to Vector space of dimension 4 over Rational Field
|
|
633
|
+
in Category of finite dimensional vector spaces with basis
|
|
634
|
+
over (number fields and quotient fields and metric spaces)
|
|
635
|
+
sage: TestSuite(M_4_ab).run() # known bug
|
|
636
|
+
sage: M_ab_xy = MatrixSpace(QQ, ['a','b'], ['x','y'], nrows=2); M_ab_xy
|
|
637
|
+
Set of Morphisms
|
|
638
|
+
from Free module generated by {'x', 'y'} over Rational Field
|
|
639
|
+
to Free module generated by {'a', 'b'} over Rational Field
|
|
640
|
+
in Category of finite dimensional vector spaces with basis over Rational Field
|
|
641
|
+
sage: TestSuite(M_ab_xy).run() # known bug
|
|
642
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], nrows=4)
|
|
643
|
+
Traceback (most recent call last):
|
|
644
|
+
...
|
|
645
|
+
ValueError: inconsistent number of rows:
|
|
646
|
+
should be cardinality of ['a', 'b'] but got 4
|
|
647
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], ncols=2)
|
|
648
|
+
Set of Morphisms
|
|
649
|
+
from Free module generated by {'x', 'y'} over Rational Field
|
|
650
|
+
to Free module generated by {'a', 'b'} over Rational Field
|
|
651
|
+
in Category of finite dimensional vector spaces with basis over Rational Field
|
|
652
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], ncols=4)
|
|
653
|
+
Traceback (most recent call last):
|
|
654
|
+
...
|
|
655
|
+
ValueError: inconsistent number of columns:
|
|
656
|
+
should be cardinality of ['x', 'y'] but got 4
|
|
657
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], nrows=2, ncols=2)
|
|
658
|
+
Set of Morphisms
|
|
659
|
+
from Free module generated by {'x', 'y'} over Rational Field
|
|
660
|
+
to Free module generated by {'a', 'b'} over Rational Field
|
|
661
|
+
in Category of finite dimensional vector spaces with basis over Rational Field
|
|
662
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], nrows=2, ncols=4)
|
|
663
|
+
Traceback (most recent call last):
|
|
664
|
+
...
|
|
665
|
+
ValueError: inconsistent number of columns:
|
|
666
|
+
should be cardinality of ['x', 'y'] but got 4
|
|
667
|
+
sage: MatrixSpace(QQ, ['a','b'], ['x','y'], nrows=4, ncols=4)
|
|
668
|
+
Traceback (most recent call last):
|
|
669
|
+
...
|
|
670
|
+
ValueError: inconsistent number of columns:
|
|
671
|
+
should be cardinality of ['x', 'y'] but got 4
|
|
672
|
+
sage: MatrixSpace(QQ, 4, ['a','b'], nrows=4, ncols=2)
|
|
673
|
+
Traceback (most recent call last):
|
|
674
|
+
...
|
|
675
|
+
ValueError: duplicate values for nrows
|
|
676
|
+
"""
|
|
677
|
+
|
|
678
|
+
@staticmethod
|
|
679
|
+
def __classcall__(cls, base_ring,
|
|
680
|
+
nrows_or_row_keys=None, ncols_or_column_keys=None,
|
|
681
|
+
sparse=False, implementation=None, *,
|
|
682
|
+
nrows=None, ncols=None,
|
|
683
|
+
row_keys=None, column_keys=None,
|
|
684
|
+
**kwds):
|
|
685
|
+
"""
|
|
686
|
+
Normalize the arguments to call the ``__init__`` constructor or delegate to another class.
|
|
687
|
+
|
|
688
|
+
TESTS::
|
|
689
|
+
|
|
690
|
+
sage: M1 = MatrixSpace(QQ, 2)
|
|
691
|
+
sage: M2 = MatrixSpace(QQ, 2)
|
|
692
|
+
sage: M1 is M2
|
|
693
|
+
True
|
|
694
|
+
sage: M3 = MatrixSpace(QQ, 2, implementation='flint') # needs sage.libs.flint
|
|
695
|
+
sage: M1 is M3 # needs sage.libs.flint
|
|
696
|
+
True
|
|
697
|
+
|
|
698
|
+
::
|
|
699
|
+
|
|
700
|
+
sage: M = MatrixSpace(ZZ, 10, implementation='flint') # needs sage.libs.flint
|
|
701
|
+
sage: M # needs sage.libs.flint
|
|
702
|
+
Full MatrixSpace of 10 by 10 dense matrices over Integer Ring
|
|
703
|
+
sage: loads(M.dumps()) is M # needs sage.libs.flint
|
|
704
|
+
True
|
|
705
|
+
|
|
706
|
+
sage: MatrixSpace(ZZ, 10, implementation='foobar')
|
|
707
|
+
Traceback (most recent call last):
|
|
708
|
+
...
|
|
709
|
+
ValueError: unknown matrix implementation 'foobar' over Integer Ring
|
|
710
|
+
|
|
711
|
+
Check that :issue:`29466` is fixed::
|
|
712
|
+
|
|
713
|
+
sage: class MyMatrixSpace(MatrixSpace):
|
|
714
|
+
....: @staticmethod
|
|
715
|
+
....: def __classcall__(cls, base_ring, nrows, ncols=None, my_option=True, sparse=False, implementation=None):
|
|
716
|
+
....: return super().__classcall__(cls, base_ring, nrows, ncols=ncols, my_option=my_option, sparse=sparse, implementation=implementation)
|
|
717
|
+
....:
|
|
718
|
+
....: def __init__(self, base_ring, nrows, ncols, sparse, implementation, my_option=True):
|
|
719
|
+
....: super().__init__(base_ring, nrows, ncols, sparse, implementation)
|
|
720
|
+
....: self._my_option = my_option
|
|
721
|
+
|
|
722
|
+
sage: MS1 = MyMatrixSpace(ZZ, 2)
|
|
723
|
+
sage: MS1._my_option
|
|
724
|
+
True
|
|
725
|
+
sage: MS2 = MyMatrixSpace(ZZ, 2, my_option=False)
|
|
726
|
+
sage: MS2._my_option
|
|
727
|
+
False
|
|
728
|
+
"""
|
|
729
|
+
if base_ring not in _Rings:
|
|
730
|
+
raise TypeError("base_ring (=%s) must be a ring" % base_ring)
|
|
731
|
+
|
|
732
|
+
if ncols_or_column_keys is not None:
|
|
733
|
+
try:
|
|
734
|
+
n = int(ncols_or_column_keys)
|
|
735
|
+
except (TypeError, ValueError):
|
|
736
|
+
if column_keys is not None:
|
|
737
|
+
raise ValueError("duplicate values for column_keys")
|
|
738
|
+
column_keys = ncols_or_column_keys
|
|
739
|
+
else:
|
|
740
|
+
if ncols is not None:
|
|
741
|
+
raise ValueError("duplicate values for ncols")
|
|
742
|
+
ncols = n
|
|
743
|
+
if column_keys is not None and ncols is not None and ncols != len(column_keys):
|
|
744
|
+
raise ValueError(f"inconsistent number of columns: should be cardinality of {column_keys} "
|
|
745
|
+
f"but got {ncols}")
|
|
746
|
+
|
|
747
|
+
if nrows_or_row_keys is not None:
|
|
748
|
+
try:
|
|
749
|
+
n = int(nrows_or_row_keys)
|
|
750
|
+
except (TypeError, ValueError):
|
|
751
|
+
if row_keys is not None:
|
|
752
|
+
raise ValueError("duplicate values for row_keys")
|
|
753
|
+
row_keys = nrows_or_row_keys
|
|
754
|
+
else:
|
|
755
|
+
if nrows is not None:
|
|
756
|
+
raise ValueError("duplicate values for nrows")
|
|
757
|
+
nrows = n
|
|
758
|
+
if row_keys is not None and nrows is not None and nrows != len(row_keys):
|
|
759
|
+
raise ValueError(f"inconsistent number of rows: should be cardinality of {row_keys} "
|
|
760
|
+
f"but got {nrows}")
|
|
761
|
+
|
|
762
|
+
if ncols is None and column_keys is None:
|
|
763
|
+
ncols = nrows
|
|
764
|
+
column_keys = row_keys
|
|
765
|
+
|
|
766
|
+
sparse = bool(sparse)
|
|
767
|
+
|
|
768
|
+
if row_keys is not None or column_keys is not None:
|
|
769
|
+
from sage.categories.homset import Hom
|
|
770
|
+
from sage.modules.free_module import FreeModule
|
|
771
|
+
|
|
772
|
+
domain = FreeModule(base_ring, rank=ncols, basis_keys=column_keys,
|
|
773
|
+
sparse=sparse, **kwds)
|
|
774
|
+
codomain = FreeModule(base_ring, rank=nrows, basis_keys=row_keys,
|
|
775
|
+
sparse=sparse, **kwds)
|
|
776
|
+
return Hom(domain, codomain)
|
|
777
|
+
|
|
778
|
+
if nrows < 0:
|
|
779
|
+
raise ArithmeticError("nrows must be nonnegative")
|
|
780
|
+
if ncols < 0:
|
|
781
|
+
raise ArithmeticError("ncols must be nonnegative")
|
|
782
|
+
if nrows > sys.maxsize or ncols > sys.maxsize:
|
|
783
|
+
raise OverflowError("number of rows and columns may be at most %s" % sys.maxsize)
|
|
784
|
+
|
|
785
|
+
matrix_cls = get_matrix_class(base_ring, nrows, ncols, sparse, implementation)
|
|
786
|
+
return super().__classcall__(cls, base_ring, nrows,
|
|
787
|
+
ncols, sparse, matrix_cls, **kwds)
|
|
788
|
+
|
|
789
|
+
def __init__(self, base_ring, nrows, ncols, sparse, implementation):
|
|
790
|
+
r"""
|
|
791
|
+
INPUT:
|
|
792
|
+
|
|
793
|
+
- ``base_ring``
|
|
794
|
+
|
|
795
|
+
- ``nrows`` -- positive integer; the number of rows
|
|
796
|
+
|
|
797
|
+
- ``ncols`` -- positive integer (default: ``nrows``); the number of
|
|
798
|
+
columns
|
|
799
|
+
|
|
800
|
+
- ``sparse`` -- boolean (default: ``False``); whether or not matrices
|
|
801
|
+
are given a sparse representation
|
|
802
|
+
|
|
803
|
+
- ``implementation`` -- (optional) string or matrix class; a possible
|
|
804
|
+
implementation. Depending on the base ring the string can be
|
|
805
|
+
|
|
806
|
+
- ``'generic'`` -- on any base rings
|
|
807
|
+
|
|
808
|
+
- ``'flint'`` -- for integers and rationals
|
|
809
|
+
|
|
810
|
+
- ``'meataxe'`` -- finite fields, needs to install the optional package meataxe
|
|
811
|
+
|
|
812
|
+
- ``m4ri`` -- for characteristic 2 using M4RI library
|
|
813
|
+
|
|
814
|
+
- ``linbox-float`` -- for integer mod rings up to `2^8 = 256`
|
|
815
|
+
|
|
816
|
+
- ``linbox-double`` -- for integer mod rings up to
|
|
817
|
+
`floor(2^26*sqrt(2) + 1/2) = 94906266`
|
|
818
|
+
|
|
819
|
+
- ``numpy`` -- for real and complex floating point numbers
|
|
820
|
+
|
|
821
|
+
EXAMPLES::
|
|
822
|
+
|
|
823
|
+
sage: MatrixSpace(QQ, 2)
|
|
824
|
+
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
|
|
825
|
+
sage: MatrixSpace(ZZ, 3, 2)
|
|
826
|
+
Full MatrixSpace of 3 by 2 dense matrices over Integer Ring
|
|
827
|
+
sage: MatrixSpace(ZZ, 3, sparse=False)
|
|
828
|
+
Full MatrixSpace of 3 by 3 dense matrices over Integer Ring
|
|
829
|
+
|
|
830
|
+
sage: MatrixSpace(ZZ,10,5)
|
|
831
|
+
Full MatrixSpace of 10 by 5 dense matrices over Integer Ring
|
|
832
|
+
sage: MatrixSpace(ZZ,10,5).category()
|
|
833
|
+
Category of infinite enumerated finite dimensional modules with basis over
|
|
834
|
+
(Dedekind domains and euclidean domains
|
|
835
|
+
and noetherian rings
|
|
836
|
+
and infinite enumerated sets and metric spaces)
|
|
837
|
+
sage: MatrixSpace(ZZ,10,10).category()
|
|
838
|
+
Category of infinite enumerated finite dimensional algebras with basis over
|
|
839
|
+
(Dedekind domains and euclidean domains
|
|
840
|
+
and noetherian rings
|
|
841
|
+
and infinite enumerated sets and metric spaces)
|
|
842
|
+
sage: MatrixSpace(QQ,10).category()
|
|
843
|
+
Category of infinite finite dimensional algebras with basis over
|
|
844
|
+
(number fields and quotient fields and metric spaces)
|
|
845
|
+
|
|
846
|
+
TESTS:
|
|
847
|
+
|
|
848
|
+
We test that in the real or complex double dense case,
|
|
849
|
+
conversion from the base ring is done by a call morphism.
|
|
850
|
+
Note that by :issue:`9138`, other algebras usually
|
|
851
|
+
get a conversion map by multiplication with the one element.
|
|
852
|
+
::
|
|
853
|
+
|
|
854
|
+
sage: MS = MatrixSpace(RDF, 2, 2)
|
|
855
|
+
sage: MS.convert_map_from(RDF)
|
|
856
|
+
Coercion map:
|
|
857
|
+
From: Real Double Field
|
|
858
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Real Double Field
|
|
859
|
+
sage: MS = MatrixSpace(CDF, 2, 2)
|
|
860
|
+
sage: MS.convert_map_from(CDF)
|
|
861
|
+
Coercion map:
|
|
862
|
+
From: Complex Double Field
|
|
863
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Complex Double Field
|
|
864
|
+
|
|
865
|
+
We check that :issue:`10095` is fixed::
|
|
866
|
+
|
|
867
|
+
sage: M = Matrix(QQ, [[1 for dummy in range(125)]])
|
|
868
|
+
sage: V = M.right_kernel()
|
|
869
|
+
sage: V
|
|
870
|
+
Vector space of degree 125 and dimension 124 over Rational Field
|
|
871
|
+
Basis matrix:
|
|
872
|
+
124 x 125 dense matrix over Rational Field
|
|
873
|
+
sage: MatrixSpace(ZZ,20,20)(1).solve_right(MatrixSpace(ZZ,20,1).random_element())
|
|
874
|
+
20 x 1 dense matrix over Rational Field (use the '.str()' method to see the entries)
|
|
875
|
+
sage: MatrixSpace(ZZ,200,200)(1).solve_right(MatrixSpace(ZZ,200,1).random_element())
|
|
876
|
+
200 x 1 dense matrix over Rational Field (use the '.str()' method to see the entries)
|
|
877
|
+
sage: A = MatrixSpace(RDF,1000,1000).random_element()
|
|
878
|
+
sage: B = MatrixSpace(RDF,1000,1000).random_element()
|
|
879
|
+
|
|
880
|
+
sage: # needs numpy (otherwise timeout)
|
|
881
|
+
sage: C = A * B
|
|
882
|
+
|
|
883
|
+
We check that :issue:`18186` is fixed::
|
|
884
|
+
|
|
885
|
+
sage: MatrixSpace(ZZ,0,3) in FiniteSets()
|
|
886
|
+
True
|
|
887
|
+
sage: MatrixSpace(Zmod(4),2) in FiniteSets()
|
|
888
|
+
True
|
|
889
|
+
sage: MatrixSpace(ZZ,2) in Sets().Infinite()
|
|
890
|
+
True
|
|
891
|
+
"""
|
|
892
|
+
# Checks of input data are supposed to be done in __classcall__
|
|
893
|
+
assert isinstance(implementation, type)
|
|
894
|
+
|
|
895
|
+
self.Element = implementation
|
|
896
|
+
self.__nrows = nrows
|
|
897
|
+
self.__ncols = ncols
|
|
898
|
+
self.__is_sparse = sparse
|
|
899
|
+
|
|
900
|
+
from sage.categories.modules import Modules
|
|
901
|
+
from sage.categories.algebras import Algebras
|
|
902
|
+
if nrows == ncols:
|
|
903
|
+
category = Algebras(base_ring.category())
|
|
904
|
+
else:
|
|
905
|
+
category = Modules(base_ring.category())
|
|
906
|
+
|
|
907
|
+
category = category.WithBasis().FiniteDimensional()
|
|
908
|
+
|
|
909
|
+
if not self.__nrows or not self.__ncols:
|
|
910
|
+
is_finite = True
|
|
911
|
+
else:
|
|
912
|
+
try:
|
|
913
|
+
is_finite = base_ring.is_finite()
|
|
914
|
+
except (AttributeError, NotImplementedError):
|
|
915
|
+
is_finite = None
|
|
916
|
+
|
|
917
|
+
if is_finite is True:
|
|
918
|
+
category = category.Finite()
|
|
919
|
+
elif is_finite is False:
|
|
920
|
+
category = category.Infinite()
|
|
921
|
+
|
|
922
|
+
if base_ring in EnumeratedSets():
|
|
923
|
+
category = category.Enumerated()
|
|
924
|
+
|
|
925
|
+
Parent.__init__(self, base_ring, category=category)
|
|
926
|
+
|
|
927
|
+
def cardinality(self):
|
|
928
|
+
r"""
|
|
929
|
+
Return the number of elements in ``self``.
|
|
930
|
+
|
|
931
|
+
EXAMPLES::
|
|
932
|
+
|
|
933
|
+
sage: MatrixSpace(GF(3), 2, 3).cardinality()
|
|
934
|
+
729
|
|
935
|
+
sage: MatrixSpace(ZZ, 2).cardinality()
|
|
936
|
+
+Infinity
|
|
937
|
+
sage: MatrixSpace(ZZ, 0, 3).cardinality()
|
|
938
|
+
1
|
|
939
|
+
"""
|
|
940
|
+
if not self.__nrows or not self.__ncols:
|
|
941
|
+
from sage.rings.integer_ring import ZZ
|
|
942
|
+
return ZZ.one()
|
|
943
|
+
else:
|
|
944
|
+
return self.base_ring().cardinality() ** (self.__nrows * self.__ncols)
|
|
945
|
+
|
|
946
|
+
def characteristic(self):
|
|
947
|
+
r"""
|
|
948
|
+
Return the characteristic.
|
|
949
|
+
|
|
950
|
+
EXAMPLES::
|
|
951
|
+
|
|
952
|
+
sage: MatrixSpace(ZZ, 2).characteristic()
|
|
953
|
+
0
|
|
954
|
+
sage: MatrixSpace(GF(9), 0).characteristic() # needs sage.rings.finite_rings
|
|
955
|
+
3
|
|
956
|
+
"""
|
|
957
|
+
return self.base_ring().characteristic()
|
|
958
|
+
|
|
959
|
+
def is_exact(self):
|
|
960
|
+
"""
|
|
961
|
+
Test whether elements of this matrix space are represented exactly.
|
|
962
|
+
|
|
963
|
+
OUTPUT:
|
|
964
|
+
|
|
965
|
+
Return ``True`` if elements of this matrix space are represented exactly, i.e.,
|
|
966
|
+
there is no precision loss when doing arithmetic.
|
|
967
|
+
|
|
968
|
+
EXAMPLES::
|
|
969
|
+
|
|
970
|
+
sage: MatrixSpace(ZZ, 3).is_exact()
|
|
971
|
+
True
|
|
972
|
+
sage: MatrixSpace(RR, 3).is_exact()
|
|
973
|
+
False
|
|
974
|
+
"""
|
|
975
|
+
return self._base.is_exact()
|
|
976
|
+
|
|
977
|
+
def _has_default_implementation(self):
|
|
978
|
+
r"""
|
|
979
|
+
EXAMPLES::
|
|
980
|
+
|
|
981
|
+
sage: MatrixSpace(ZZ, 2, implementation='generic')._has_default_implementation()
|
|
982
|
+
False
|
|
983
|
+
sage: MatrixSpace(ZZ, 2, implementation='flint')._has_default_implementation() # needs sage.libs.linbox
|
|
984
|
+
True
|
|
985
|
+
"""
|
|
986
|
+
default = get_matrix_class(self.base_ring(), self.nrows(), self.ncols(), self.is_sparse(), None)
|
|
987
|
+
return self.Element is default
|
|
988
|
+
|
|
989
|
+
@lazy_attribute
|
|
990
|
+
def transposed(self):
|
|
991
|
+
"""
|
|
992
|
+
The transposed matrix space, having the same base ring and sparseness,
|
|
993
|
+
but number of columns and rows is swapped.
|
|
994
|
+
|
|
995
|
+
EXAMPLES::
|
|
996
|
+
|
|
997
|
+
sage: MS = MatrixSpace(GF(3), 7, 10)
|
|
998
|
+
sage: MS.transposed
|
|
999
|
+
Full MatrixSpace of 10 by 7 dense matrices over Finite Field of size 3
|
|
1000
|
+
sage: MS = MatrixSpace(GF(3), 7, 7)
|
|
1001
|
+
sage: MS.transposed is MS
|
|
1002
|
+
True
|
|
1003
|
+
|
|
1004
|
+
sage: M = MatrixSpace(ZZ, 2, 3)
|
|
1005
|
+
sage: M.transposed
|
|
1006
|
+
Full MatrixSpace of 3 by 2 dense matrices over Integer Ring
|
|
1007
|
+
"""
|
|
1008
|
+
return MatrixSpace(self._base, self.__ncols, self.__nrows,
|
|
1009
|
+
self.__is_sparse, self.Element)
|
|
1010
|
+
|
|
1011
|
+
@lazy_attribute
|
|
1012
|
+
def _copy_zero(self):
|
|
1013
|
+
"""
|
|
1014
|
+
Is it faster to copy a zero matrix or is it faster to create a
|
|
1015
|
+
new matrix from scratch?
|
|
1016
|
+
|
|
1017
|
+
EXAMPLES::
|
|
1018
|
+
|
|
1019
|
+
sage: MS = MatrixSpace(GF(2), 20, 20)
|
|
1020
|
+
sage: MS._copy_zero
|
|
1021
|
+
False
|
|
1022
|
+
|
|
1023
|
+
sage: MS = MatrixSpace(GF(3), 20, 20)
|
|
1024
|
+
sage: MS._copy_zero
|
|
1025
|
+
True
|
|
1026
|
+
sage: MS = MatrixSpace(GF(3), 200, 200)
|
|
1027
|
+
sage: MS._copy_zero
|
|
1028
|
+
False
|
|
1029
|
+
|
|
1030
|
+
sage: MS = MatrixSpace(ZZ,200,200)
|
|
1031
|
+
sage: MS._copy_zero
|
|
1032
|
+
False
|
|
1033
|
+
sage: MS = MatrixSpace(ZZ,30,30)
|
|
1034
|
+
sage: MS._copy_zero
|
|
1035
|
+
True
|
|
1036
|
+
|
|
1037
|
+
sage: MS = MatrixSpace(QQ,200,200)
|
|
1038
|
+
sage: MS._copy_zero
|
|
1039
|
+
False
|
|
1040
|
+
sage: MS = MatrixSpace(QQ,20,20)
|
|
1041
|
+
sage: MS._copy_zero
|
|
1042
|
+
False
|
|
1043
|
+
"""
|
|
1044
|
+
if self.__is_sparse:
|
|
1045
|
+
return False
|
|
1046
|
+
elif self.Element is sage.matrix.matrix_mod2_dense.Matrix_mod2_dense:
|
|
1047
|
+
return False
|
|
1048
|
+
elif self.Element is sage.matrix.matrix_rational_dense.Matrix_rational_dense:
|
|
1049
|
+
return False
|
|
1050
|
+
elif self.__nrows > 40 and self.__ncols > 40:
|
|
1051
|
+
return False
|
|
1052
|
+
else:
|
|
1053
|
+
return True
|
|
1054
|
+
|
|
1055
|
+
def _element_constructor_(self, entries, **kwds):
|
|
1056
|
+
"""
|
|
1057
|
+
Construct an element of ``self`` from ``entries``.
|
|
1058
|
+
|
|
1059
|
+
EXAMPLES::
|
|
1060
|
+
|
|
1061
|
+
sage: k = GF(7)
|
|
1062
|
+
sage: G = MatrixGroup([matrix(k, 2, [1,1,0,1]), matrix(k, 2, [1,0,0,2])])
|
|
1063
|
+
sage: g = G.0
|
|
1064
|
+
sage: MatrixSpace(k, 2)(g)
|
|
1065
|
+
[1 1]
|
|
1066
|
+
[0 1]
|
|
1067
|
+
|
|
1068
|
+
::
|
|
1069
|
+
|
|
1070
|
+
sage: MS = MatrixSpace(ZZ,2,4)
|
|
1071
|
+
sage: M2 = MS(range(8)); M2
|
|
1072
|
+
[0 1 2 3]
|
|
1073
|
+
[4 5 6 7]
|
|
1074
|
+
sage: M2 == MS(M2.rows())
|
|
1075
|
+
True
|
|
1076
|
+
|
|
1077
|
+
::
|
|
1078
|
+
|
|
1079
|
+
sage: MS = MatrixSpace(ZZ,2,4, sparse=True)
|
|
1080
|
+
sage: M2 = MS(range(8)); M2
|
|
1081
|
+
[0 1 2 3]
|
|
1082
|
+
[4 5 6 7]
|
|
1083
|
+
sage: M2 == MS(M2.rows())
|
|
1084
|
+
True
|
|
1085
|
+
|
|
1086
|
+
::
|
|
1087
|
+
|
|
1088
|
+
sage: MS = MatrixSpace(ZZ,2,2, sparse=True)
|
|
1089
|
+
sage: MS([1,2,3,4])
|
|
1090
|
+
[1 2]
|
|
1091
|
+
[3 4]
|
|
1092
|
+
|
|
1093
|
+
sage: # needs sage.modular
|
|
1094
|
+
sage: MS = MatrixSpace(ZZ, 2)
|
|
1095
|
+
sage: g = Gamma0(5)([1,1,0,1])
|
|
1096
|
+
sage: MS(g)
|
|
1097
|
+
[1 1]
|
|
1098
|
+
[0 1]
|
|
1099
|
+
|
|
1100
|
+
::
|
|
1101
|
+
|
|
1102
|
+
sage: MS = MatrixSpace(ZZ,2,2, sparse=True)
|
|
1103
|
+
sage: mat = MS(); mat
|
|
1104
|
+
[0 0]
|
|
1105
|
+
[0 0]
|
|
1106
|
+
sage: mat.is_mutable()
|
|
1107
|
+
True
|
|
1108
|
+
sage: mat2 = mat.change_ring(QQ); mat2.is_mutable()
|
|
1109
|
+
True
|
|
1110
|
+
|
|
1111
|
+
TESTS:
|
|
1112
|
+
|
|
1113
|
+
Ensure that :issue:`12020` is fixed::
|
|
1114
|
+
|
|
1115
|
+
sage: rings = [ZZ, QQ, RDF]
|
|
1116
|
+
sage: rings.extend([RealField(100), ComplexField(100)]) # needs sage.rings.real_mpfr
|
|
1117
|
+
sage: rings.append(CDF) # needs sage.rings.complex_double
|
|
1118
|
+
sage: rings.append(PolynomialRing(QQ, 'x'))
|
|
1119
|
+
sage: rings.append(PolynomialRing(CC, 2, 'x')) # needs sage.rings.real_mpfr
|
|
1120
|
+
sage: rings.append(SR) # needs sage.symbolic
|
|
1121
|
+
sage: rings.extend([GF(2), GF(11)])
|
|
1122
|
+
sage: rings.extend([GF(2^8,'a'), GF(3^19,'a')]) # needs sage.rings.finite_rings
|
|
1123
|
+
sage: x = polygen(QQ)
|
|
1124
|
+
sage: rings.extend([NumberField(x^3 + 2, 'a'), CyclotomicField(4)]) # needs sage.rings.number_field
|
|
1125
|
+
sage: for R in rings:
|
|
1126
|
+
....: A = MatrixSpace(R, 60, 30, sparse=False)(0)
|
|
1127
|
+
....: B = A.augment(A)
|
|
1128
|
+
....: A = MatrixSpace(R, 60, 30, sparse=True)(0)
|
|
1129
|
+
....: B = A.augment(A)
|
|
1130
|
+
|
|
1131
|
+
Check that :issue:`13012` is fixed::
|
|
1132
|
+
|
|
1133
|
+
sage: m = zero_matrix(2, 3)
|
|
1134
|
+
sage: m
|
|
1135
|
+
[0 0 0]
|
|
1136
|
+
[0 0 0]
|
|
1137
|
+
sage: M = MatrixSpace(ZZ, 3, 5)
|
|
1138
|
+
sage: M.zero()
|
|
1139
|
+
[0 0 0 0 0]
|
|
1140
|
+
[0 0 0 0 0]
|
|
1141
|
+
[0 0 0 0 0]
|
|
1142
|
+
sage: M(m)
|
|
1143
|
+
Traceback (most recent call last):
|
|
1144
|
+
...
|
|
1145
|
+
ValueError: inconsistent number of rows: should be 3 but got 2
|
|
1146
|
+
sage: M.matrix(m)
|
|
1147
|
+
Traceback (most recent call last):
|
|
1148
|
+
...
|
|
1149
|
+
ValueError: inconsistent number of rows: should be 3 but got 2
|
|
1150
|
+
|
|
1151
|
+
Check that :issue:`15110` is fixed::
|
|
1152
|
+
|
|
1153
|
+
sage: S.<t> = LaurentSeriesRing(ZZ)
|
|
1154
|
+
sage: MS = MatrixSpace(S,1,1)
|
|
1155
|
+
sage: MS([[t]]) # given as a list of lists
|
|
1156
|
+
[t]
|
|
1157
|
+
sage: MS([t]) # given as a list of coefficients
|
|
1158
|
+
[t]
|
|
1159
|
+
sage: MS(t) # given as a scalar matrix
|
|
1160
|
+
[t]
|
|
1161
|
+
|
|
1162
|
+
Calling a matrix space `M` with a matrix in `M` as argument
|
|
1163
|
+
returns the original matrix unless ``copy=True`` is specified
|
|
1164
|
+
(:issue:`31078`)::
|
|
1165
|
+
|
|
1166
|
+
sage: m = Matrix([[0, 1], [2, 3]])
|
|
1167
|
+
sage: M = m.parent()
|
|
1168
|
+
sage: M(m) is m
|
|
1169
|
+
True
|
|
1170
|
+
sage: M(m, copy=True) is m
|
|
1171
|
+
False
|
|
1172
|
+
"""
|
|
1173
|
+
return self.element_class(self, entries, **kwds)
|
|
1174
|
+
|
|
1175
|
+
def change_ring(self, R):
|
|
1176
|
+
"""
|
|
1177
|
+
Return matrix space over R with otherwise same parameters as ``self``.
|
|
1178
|
+
|
|
1179
|
+
INPUT:
|
|
1180
|
+
|
|
1181
|
+
- ``R`` -- ring
|
|
1182
|
+
|
|
1183
|
+
OUTPUT: a matrix space
|
|
1184
|
+
|
|
1185
|
+
EXAMPLES::
|
|
1186
|
+
|
|
1187
|
+
sage: Mat(QQ, 3, 5).change_ring(GF(7))
|
|
1188
|
+
Full MatrixSpace of 3 by 5 dense matrices
|
|
1189
|
+
over Finite Field of size 7
|
|
1190
|
+
"""
|
|
1191
|
+
try:
|
|
1192
|
+
return self.__change_ring[R]
|
|
1193
|
+
except AttributeError:
|
|
1194
|
+
self.__change_ring = {}
|
|
1195
|
+
except KeyError:
|
|
1196
|
+
pass
|
|
1197
|
+
M = MatrixSpace(R, self.__nrows, self.__ncols, self.__is_sparse)
|
|
1198
|
+
self.__change_ring[R] = M
|
|
1199
|
+
return M
|
|
1200
|
+
|
|
1201
|
+
def base_extend(self, R):
|
|
1202
|
+
"""
|
|
1203
|
+
Return base extension of this matrix space to R.
|
|
1204
|
+
|
|
1205
|
+
INPUT:
|
|
1206
|
+
|
|
1207
|
+
- ``R`` -- ring
|
|
1208
|
+
|
|
1209
|
+
OUTPUT: a matrix space
|
|
1210
|
+
|
|
1211
|
+
EXAMPLES::
|
|
1212
|
+
|
|
1213
|
+
sage: Mat(ZZ, 3, 5).base_extend(QQ)
|
|
1214
|
+
Full MatrixSpace of 3 by 5 dense matrices over Rational Field
|
|
1215
|
+
sage: Mat(QQ, 3, 5).base_extend(GF(7))
|
|
1216
|
+
Traceback (most recent call last):
|
|
1217
|
+
...
|
|
1218
|
+
TypeError: no base extension defined
|
|
1219
|
+
"""
|
|
1220
|
+
if R.has_coerce_map_from(self.base_ring()):
|
|
1221
|
+
return self.change_ring(R)
|
|
1222
|
+
raise TypeError("no base extension defined")
|
|
1223
|
+
|
|
1224
|
+
def construction(self):
|
|
1225
|
+
"""
|
|
1226
|
+
EXAMPLES::
|
|
1227
|
+
|
|
1228
|
+
sage: A = matrix(ZZ, 2, [1..4], sparse=True)
|
|
1229
|
+
sage: A.parent().construction()
|
|
1230
|
+
(MatrixFunctor, Integer Ring)
|
|
1231
|
+
sage: A.parent().construction()[0](QQ['x'])
|
|
1232
|
+
Full MatrixSpace of 2 by 2 sparse matrices over
|
|
1233
|
+
Univariate Polynomial Ring in x over Rational Field
|
|
1234
|
+
sage: parent(A/2)
|
|
1235
|
+
Full MatrixSpace of 2 by 2 sparse matrices over Rational Field
|
|
1236
|
+
"""
|
|
1237
|
+
from sage.categories.pushout import MatrixFunctor
|
|
1238
|
+
return MatrixFunctor(self.__nrows, self.__ncols, is_sparse=self.is_sparse()), self.base_ring()
|
|
1239
|
+
|
|
1240
|
+
def _get_action_(self, S, op, self_on_left):
|
|
1241
|
+
r"""
|
|
1242
|
+
Return the action of S on ``self``.
|
|
1243
|
+
|
|
1244
|
+
INPUT:
|
|
1245
|
+
|
|
1246
|
+
- ``S`` -- a parent
|
|
1247
|
+
|
|
1248
|
+
- ``op`` -- an operator
|
|
1249
|
+
|
|
1250
|
+
- ``self_on_left`` -- whether the operation is on left or on right
|
|
1251
|
+
|
|
1252
|
+
EXAMPLES::
|
|
1253
|
+
|
|
1254
|
+
sage: V = QQ^(2,3)
|
|
1255
|
+
sage: W1 = QQ^(3,4); W2 = QQ^(2,2)
|
|
1256
|
+
sage: V.get_action(W1, operator.mul)
|
|
1257
|
+
Left action by Full MatrixSpace of 2 by 3 dense matrices over Rational Field on Full MatrixSpace of 3 by 4 dense matrices over Rational Field
|
|
1258
|
+
sage: V.get_action(W2, operator.mul)
|
|
1259
|
+
sage: V.get_action(W1, operator.mul, self_on_left=False)
|
|
1260
|
+
sage: V.get_action(W2, operator.mul, self_on_left=False)
|
|
1261
|
+
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 3 dense matrices over Rational Field
|
|
1262
|
+
|
|
1263
|
+
::
|
|
1264
|
+
|
|
1265
|
+
sage: V2 = QQ^2; V3 = QQ^3
|
|
1266
|
+
sage: V.get_action(V3, operator.mul)
|
|
1267
|
+
Left action by Full MatrixSpace of 2 by 3 dense matrices over Rational Field on Vector space of dimension 3 over Rational Field
|
|
1268
|
+
sage: V.get_action(V2, operator.mul)
|
|
1269
|
+
sage: V.get_action(V3, operator.mul, self_on_left=False)
|
|
1270
|
+
sage: V.get_action(V2, operator.mul, self_on_left=False)
|
|
1271
|
+
Right action by Full MatrixSpace of 2 by 3 dense matrices over Rational Field on Vector space of dimension 2 over Rational Field
|
|
1272
|
+
|
|
1273
|
+
::
|
|
1274
|
+
|
|
1275
|
+
sage: V.get_action(ZZ, operator.mul)
|
|
1276
|
+
Right scalar multiplication by Integer Ring on Full MatrixSpace of 2 by 3 dense matrices over Rational Field
|
|
1277
|
+
sage: V.get_action(ZZ, operator.mul, self_on_left=False)
|
|
1278
|
+
Left scalar multiplication by Integer Ring on Full MatrixSpace of 2 by 3 dense matrices over Rational Field
|
|
1279
|
+
"""
|
|
1280
|
+
try:
|
|
1281
|
+
try:
|
|
1282
|
+
from sage.schemes.generic.homset import SchemeHomset_generic
|
|
1283
|
+
from sage.schemes.generic.homset import SchemeHomset_points
|
|
1284
|
+
except ImportError:
|
|
1285
|
+
SchemeHomset_generic = SchemeHomset_points = None
|
|
1286
|
+
if op is operator.mul:
|
|
1287
|
+
from . import action as matrix_action
|
|
1288
|
+
if self_on_left:
|
|
1289
|
+
if isinstance(S, MatrixSpace):
|
|
1290
|
+
# matrix multiplications
|
|
1291
|
+
return matrix_action.MatrixMatrixAction(self, S)
|
|
1292
|
+
elif isinstance(S, sage.modules.free_module.FreeModule_generic):
|
|
1293
|
+
return matrix_action.MatrixVectorAction(self, S)
|
|
1294
|
+
elif isinstance(S, SchemeHomset_points):
|
|
1295
|
+
return matrix_action.MatrixSchemePointAction(self, S)
|
|
1296
|
+
elif isinstance(S, SchemeHomset_generic):
|
|
1297
|
+
return matrix_action.MatrixPolymapAction(self, S)
|
|
1298
|
+
else:
|
|
1299
|
+
# action of base ring
|
|
1300
|
+
return sage.structure.coerce_actions.RightModuleAction(S, self)
|
|
1301
|
+
else:
|
|
1302
|
+
if isinstance(S, MatrixSpace):
|
|
1303
|
+
# matrix multiplications
|
|
1304
|
+
return matrix_action.MatrixMatrixAction(S, self)
|
|
1305
|
+
elif isinstance(S, sage.modules.free_module.FreeModule_generic):
|
|
1306
|
+
return matrix_action.VectorMatrixAction(self, S)
|
|
1307
|
+
elif isinstance(S, SchemeHomset_generic):
|
|
1308
|
+
return matrix_action.PolymapMatrixAction(self, S)
|
|
1309
|
+
else:
|
|
1310
|
+
# action of base ring
|
|
1311
|
+
return sage.structure.coerce_actions.LeftModuleAction(S, self)
|
|
1312
|
+
except TypeError:
|
|
1313
|
+
return None
|
|
1314
|
+
|
|
1315
|
+
def _coerce_map_from_base_ring(self):
|
|
1316
|
+
"""
|
|
1317
|
+
Return a coercion map from the base ring of ``self``.
|
|
1318
|
+
|
|
1319
|
+
.. NOTE::
|
|
1320
|
+
|
|
1321
|
+
This is only called for algebras of square matrices.
|
|
1322
|
+
|
|
1323
|
+
EXAMPLES::
|
|
1324
|
+
|
|
1325
|
+
sage: MS1 = MatrixSpace(QQ, 3)
|
|
1326
|
+
sage: MS1.coerce_map_from(QQ)
|
|
1327
|
+
Coercion map:
|
|
1328
|
+
From: Rational Field
|
|
1329
|
+
To: Full MatrixSpace of 3 by 3 dense matrices over Rational Field
|
|
1330
|
+
sage: MS1.coerce_map_from(ZZ)
|
|
1331
|
+
Composite map:
|
|
1332
|
+
From: Integer Ring
|
|
1333
|
+
To: Full MatrixSpace of 3 by 3 dense matrices over Rational Field
|
|
1334
|
+
Defn: Natural morphism:
|
|
1335
|
+
From: Integer Ring
|
|
1336
|
+
To: Rational Field
|
|
1337
|
+
then
|
|
1338
|
+
Coercion map:
|
|
1339
|
+
From: Rational Field
|
|
1340
|
+
To: Full MatrixSpace of 3 by 3 dense matrices over Rational Field
|
|
1341
|
+
|
|
1342
|
+
sage: MS2 = MatrixSpace(ZZ, 3)
|
|
1343
|
+
sage: MS2.coerce_map_from(QQ)
|
|
1344
|
+
sage: MS2.coerce_map_from(ZZ)
|
|
1345
|
+
Coercion map:
|
|
1346
|
+
From: Integer Ring
|
|
1347
|
+
To: Full MatrixSpace of 3 by 3 dense matrices over Integer Ring
|
|
1348
|
+
|
|
1349
|
+
sage: MatrixSpace(QQ, 1, 3).coerce_map_from(QQ)
|
|
1350
|
+
"""
|
|
1351
|
+
return self._generic_coerce_map(self.base_ring())
|
|
1352
|
+
|
|
1353
|
+
def _coerce_map_from_(self, S):
|
|
1354
|
+
r"""
|
|
1355
|
+
Canonical coercion from ``S`` to this matrix space.
|
|
1356
|
+
|
|
1357
|
+
EXAMPLES::
|
|
1358
|
+
|
|
1359
|
+
sage: MS1 = MatrixSpace(QQ, 3)
|
|
1360
|
+
sage: MS2 = MatrixSpace(ZZ, 3)
|
|
1361
|
+
sage: MS1.coerce_map_from(MS2)
|
|
1362
|
+
Coercion map:
|
|
1363
|
+
From: Full MatrixSpace of 3 by 3 dense matrices over Integer Ring
|
|
1364
|
+
To: Full MatrixSpace of 3 by 3 dense matrices over Rational Field
|
|
1365
|
+
sage: MS2.coerce_map_from(MS1)
|
|
1366
|
+
|
|
1367
|
+
There are also coercions possible from matrix group and
|
|
1368
|
+
arithmetic subgroups::
|
|
1369
|
+
|
|
1370
|
+
sage: MS = MatrixSpace(GF(3), 2, 2)
|
|
1371
|
+
sage: MS.coerce_map_from(GL(2, 3))
|
|
1372
|
+
Coercion map:
|
|
1373
|
+
From: General Linear Group of degree 2 over Finite Field of size 3
|
|
1374
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3
|
|
1375
|
+
sage: MS.coerce_map_from(GL(2, 2))
|
|
1376
|
+
sage: MS.coerce_map_from(Gamma1(5)) # needs sage.modular
|
|
1377
|
+
Coercion map:
|
|
1378
|
+
From: Congruence Subgroup Gamma1(5)
|
|
1379
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3
|
|
1380
|
+
|
|
1381
|
+
TESTS:
|
|
1382
|
+
|
|
1383
|
+
Check that :issue:`22091` is fixed::
|
|
1384
|
+
|
|
1385
|
+
sage: A = Zmod(4)
|
|
1386
|
+
sage: R = MatrixSpace(A, 2)
|
|
1387
|
+
sage: G = GL(2, A)
|
|
1388
|
+
sage: R.coerce_map_from(G)
|
|
1389
|
+
Coercion map:
|
|
1390
|
+
From: General Linear Group of degree 2 over Ring of integers modulo 4
|
|
1391
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Ring of integers modulo 4
|
|
1392
|
+
sage: R.coerce_map_from(GL(2, ZZ))
|
|
1393
|
+
Coercion map:
|
|
1394
|
+
From: General Linear Group of degree 2 over Integer Ring
|
|
1395
|
+
To: Full MatrixSpace of 2 by 2 dense matrices over Ring of integers modulo 4
|
|
1396
|
+
|
|
1397
|
+
sage: m = R([[1, 0], [0, 1]])
|
|
1398
|
+
sage: m in G
|
|
1399
|
+
True
|
|
1400
|
+
sage: m in list(G) # needs sage.libs.gap
|
|
1401
|
+
True
|
|
1402
|
+
sage: m == G(m)
|
|
1403
|
+
True
|
|
1404
|
+
|
|
1405
|
+
sage: G = SL(3, QQ)
|
|
1406
|
+
sage: M = MatrixSpace(QQ, 3)
|
|
1407
|
+
sage: G.one() == M.identity_matrix()
|
|
1408
|
+
True
|
|
1409
|
+
sage: G.one() + M.identity_matrix()
|
|
1410
|
+
[2 0 0]
|
|
1411
|
+
[0 2 0]
|
|
1412
|
+
[0 0 2]
|
|
1413
|
+
|
|
1414
|
+
Verify which coercion maps are allowed (this should form a
|
|
1415
|
+
poset)::
|
|
1416
|
+
|
|
1417
|
+
sage: S = []
|
|
1418
|
+
sage: S += [MatrixSpace(ZZ, 3, implementation='flint')] # needs sage.libs.linbox
|
|
1419
|
+
sage: S += [MatrixSpace(ZZ, 3, implementation='generic')]
|
|
1420
|
+
sage: S += [MatrixSpace(ZZ, 3, implementation='gap')] # needs sage.libs.gap
|
|
1421
|
+
sage: S += [MatrixSpace(ZZ, 3, sparse=True)]
|
|
1422
|
+
sage: mult = ''
|
|
1423
|
+
sage: for A in S:
|
|
1424
|
+
....: for B in S:
|
|
1425
|
+
....: if A.has_coerce_map_from(B):
|
|
1426
|
+
....: mult += 'X'
|
|
1427
|
+
....: else:
|
|
1428
|
+
....: mult += ' '
|
|
1429
|
+
....: mult += '\n'
|
|
1430
|
+
sage: print(mult) # needs sage.libs.linbox sage.libs.gap
|
|
1431
|
+
XXXX
|
|
1432
|
+
X X
|
|
1433
|
+
XX
|
|
1434
|
+
X
|
|
1435
|
+
|
|
1436
|
+
Thanks to the coercion model, arithmetic is allowed between all
|
|
1437
|
+
these parents::
|
|
1438
|
+
|
|
1439
|
+
sage: for A in S:
|
|
1440
|
+
....: for B in S:
|
|
1441
|
+
....: a = A.an_element()
|
|
1442
|
+
....: b = B.an_element()
|
|
1443
|
+
....: dummy = (a * b) + (a - b)
|
|
1444
|
+
"""
|
|
1445
|
+
B = self.base()
|
|
1446
|
+
|
|
1447
|
+
if isinstance(S, MatrixSpace):
|
|
1448
|
+
# Disallow coercion if dimensions do not match
|
|
1449
|
+
if self.nrows() != S.nrows() or self.ncols() != S.ncols():
|
|
1450
|
+
return False
|
|
1451
|
+
T = S.base()
|
|
1452
|
+
if B is not T:
|
|
1453
|
+
# Matrix spaces over different base rings.
|
|
1454
|
+
# TODO: make this an actual map induced by the map
|
|
1455
|
+
# on the bases, see Issue #25540
|
|
1456
|
+
return B.has_coerce_map_from(T)
|
|
1457
|
+
|
|
1458
|
+
# Base ring and dimensions are the same. So the only
|
|
1459
|
+
# difference can be the implementation and sparseness.
|
|
1460
|
+
if self.is_sparse() != S.is_sparse():
|
|
1461
|
+
# Allow coercion sparse -> dense
|
|
1462
|
+
return S.is_sparse()
|
|
1463
|
+
|
|
1464
|
+
# Allow coercion to the default implementation.
|
|
1465
|
+
# As a consequence, the default implementation is considered
|
|
1466
|
+
# the "common parent" when mixing implementations.
|
|
1467
|
+
return self._has_default_implementation()
|
|
1468
|
+
|
|
1469
|
+
# Check for other parents whose elements are some kind of matrices
|
|
1470
|
+
try:
|
|
1471
|
+
meth_matrix_space = S.matrix_space
|
|
1472
|
+
except AttributeError:
|
|
1473
|
+
pass
|
|
1474
|
+
else:
|
|
1475
|
+
MS = meth_matrix_space()
|
|
1476
|
+
if isinstance(S, MatrixGroup_base):
|
|
1477
|
+
return self.has_coerce_map_from(MS)
|
|
1478
|
+
|
|
1479
|
+
try:
|
|
1480
|
+
from sage.modular.arithgroup.arithgroup_generic import ArithmeticSubgroup
|
|
1481
|
+
except ImportError:
|
|
1482
|
+
pass
|
|
1483
|
+
else:
|
|
1484
|
+
if isinstance(S, ArithmeticSubgroup):
|
|
1485
|
+
return self.has_coerce_map_from(MS)
|
|
1486
|
+
|
|
1487
|
+
return False
|
|
1488
|
+
|
|
1489
|
+
# The parent is not matrix-like: coerce via base ring
|
|
1490
|
+
return (self.nrows() == self.ncols()) and self._coerce_map_via([B], S)
|
|
1491
|
+
|
|
1492
|
+
def _repr_(self):
|
|
1493
|
+
"""
|
|
1494
|
+
Return the string representation of a MatrixSpace.
|
|
1495
|
+
|
|
1496
|
+
EXAMPLES::
|
|
1497
|
+
|
|
1498
|
+
sage: MS = MatrixSpace(ZZ,2,4,true)
|
|
1499
|
+
sage: repr(MS)
|
|
1500
|
+
'Full MatrixSpace of 2 by 4 sparse matrices over Integer Ring'
|
|
1501
|
+
sage: MS
|
|
1502
|
+
Full MatrixSpace of 2 by 4 sparse matrices over Integer Ring
|
|
1503
|
+
|
|
1504
|
+
sage: MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox
|
|
1505
|
+
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
|
|
1506
|
+
sage: MatrixSpace(ZZ, 2, implementation='generic')
|
|
1507
|
+
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring (using Matrix_generic_dense)
|
|
1508
|
+
"""
|
|
1509
|
+
if self.is_sparse():
|
|
1510
|
+
s = "sparse"
|
|
1511
|
+
else:
|
|
1512
|
+
s = "dense"
|
|
1513
|
+
s = "Full MatrixSpace of %s by %s %s matrices over %s" % (
|
|
1514
|
+
self.__nrows, self.__ncols, s, self.base_ring())
|
|
1515
|
+
|
|
1516
|
+
if not self._has_default_implementation():
|
|
1517
|
+
s += " (using {})".format(self.Element.__name__)
|
|
1518
|
+
|
|
1519
|
+
return s
|
|
1520
|
+
|
|
1521
|
+
def _repr_option(self, key):
|
|
1522
|
+
"""
|
|
1523
|
+
Metadata about the :meth:`_repr_` output.
|
|
1524
|
+
|
|
1525
|
+
See :meth:`sage.structure.parent._repr_option` for details.
|
|
1526
|
+
|
|
1527
|
+
EXAMPLES::
|
|
1528
|
+
|
|
1529
|
+
sage: MS = MatrixSpace(ZZ,2,4,true)
|
|
1530
|
+
sage: MS._repr_option('element_ascii_art')
|
|
1531
|
+
True
|
|
1532
|
+
"""
|
|
1533
|
+
if key == 'element_ascii_art':
|
|
1534
|
+
return self.__nrows > 1
|
|
1535
|
+
return super()._repr_option(key)
|
|
1536
|
+
|
|
1537
|
+
def _latex_(self):
|
|
1538
|
+
r"""
|
|
1539
|
+
Return the latex representation of a MatrixSpace.
|
|
1540
|
+
|
|
1541
|
+
EXAMPLES::
|
|
1542
|
+
|
|
1543
|
+
sage: MS3 = MatrixSpace(QQ,6,6,true)
|
|
1544
|
+
sage: latex(MS3)
|
|
1545
|
+
\mathrm{Mat}_{6\times 6}(\Bold{Q})
|
|
1546
|
+
"""
|
|
1547
|
+
return "\\mathrm{Mat}_{%s\\times %s}(%s)" % (self.nrows(), self.ncols(),
|
|
1548
|
+
latex.latex(self.base_ring()))
|
|
1549
|
+
|
|
1550
|
+
def __len__(self):
|
|
1551
|
+
"""
|
|
1552
|
+
Return number of elements of this matrix space if it fits in
|
|
1553
|
+
an int; raise a :exc:`TypeError` if there are infinitely many
|
|
1554
|
+
elements, and raise an :exc:`OverflowError` if there are finitely
|
|
1555
|
+
many but more than the size of an int.
|
|
1556
|
+
|
|
1557
|
+
EXAMPLES::
|
|
1558
|
+
|
|
1559
|
+
sage: len(MatrixSpace(GF(3), 3, 2))
|
|
1560
|
+
729
|
|
1561
|
+
sage: len(MatrixSpace(GF(3), 2, 3))
|
|
1562
|
+
729
|
|
1563
|
+
sage: 3^(2*3)
|
|
1564
|
+
729
|
|
1565
|
+
|
|
1566
|
+
sage: len(MatrixSpace(GF(2003), 3, 2)) # needs sage.rings.finite_rings
|
|
1567
|
+
Traceback (most recent call last):
|
|
1568
|
+
...
|
|
1569
|
+
OverflowError: cannot fit 'int' into an index-sized integer
|
|
1570
|
+
|
|
1571
|
+
sage: len(MatrixSpace(QQ,3,2))
|
|
1572
|
+
Traceback (most recent call last):
|
|
1573
|
+
...
|
|
1574
|
+
TypeError: len() of unsized object
|
|
1575
|
+
"""
|
|
1576
|
+
return len(self.base_ring())**(self.nrows() * self.ncols())
|
|
1577
|
+
|
|
1578
|
+
def __iter__(self):
|
|
1579
|
+
r"""
|
|
1580
|
+
Return a generator object which iterates through the elements of
|
|
1581
|
+
``self``. The order in which the elements are generated is based on a
|
|
1582
|
+
'weight' of a matrix which is the number of iterations on the base
|
|
1583
|
+
ring that are required to reach that matrix.
|
|
1584
|
+
|
|
1585
|
+
The ordering is similar to a degree negative lexicographic order in
|
|
1586
|
+
monomials in a multivariate polynomial ring.
|
|
1587
|
+
|
|
1588
|
+
EXAMPLES: Consider the case of 2 x 2 matrices over GF(5).
|
|
1589
|
+
|
|
1590
|
+
::
|
|
1591
|
+
|
|
1592
|
+
sage: list(GF(5))
|
|
1593
|
+
[0, 1, 2, 3, 4]
|
|
1594
|
+
sage: MS = MatrixSpace(GF(5), 2, 2)
|
|
1595
|
+
sage: l = list(MS)
|
|
1596
|
+
|
|
1597
|
+
Then, consider the following matrices::
|
|
1598
|
+
|
|
1599
|
+
sage: A = MS([2,1,0,1]); A
|
|
1600
|
+
[2 1]
|
|
1601
|
+
[0 1]
|
|
1602
|
+
sage: B = MS([1,2,1,0]); B
|
|
1603
|
+
[1 2]
|
|
1604
|
+
[1 0]
|
|
1605
|
+
sage: C = MS([1,2,0,0]); C
|
|
1606
|
+
[1 2]
|
|
1607
|
+
[0 0]
|
|
1608
|
+
|
|
1609
|
+
A appears before B since the weight of one of A's entries exceeds
|
|
1610
|
+
the weight of the corresponding entry in B earliest in the list.
|
|
1611
|
+
|
|
1612
|
+
::
|
|
1613
|
+
|
|
1614
|
+
sage: l.index(A)
|
|
1615
|
+
41
|
|
1616
|
+
sage: l.index(B)
|
|
1617
|
+
46
|
|
1618
|
+
|
|
1619
|
+
However, A would come after the matrix C since C has a lower weight
|
|
1620
|
+
than A.
|
|
1621
|
+
|
|
1622
|
+
::
|
|
1623
|
+
|
|
1624
|
+
sage: l.index(A)
|
|
1625
|
+
41
|
|
1626
|
+
sage: l.index(C)
|
|
1627
|
+
19
|
|
1628
|
+
|
|
1629
|
+
The weights of matrices over other base rings are not as obvious.
|
|
1630
|
+
For example, the weight of
|
|
1631
|
+
|
|
1632
|
+
::
|
|
1633
|
+
|
|
1634
|
+
sage: MS = MatrixSpace(ZZ, 2, 2)
|
|
1635
|
+
sage: MS([-1,0,0,0])
|
|
1636
|
+
[-1 0]
|
|
1637
|
+
[ 0 0]
|
|
1638
|
+
|
|
1639
|
+
is 2 since
|
|
1640
|
+
|
|
1641
|
+
::
|
|
1642
|
+
|
|
1643
|
+
sage: i = iter(ZZ)
|
|
1644
|
+
sage: next(i)
|
|
1645
|
+
0
|
|
1646
|
+
sage: next(i)
|
|
1647
|
+
1
|
|
1648
|
+
sage: next(i)
|
|
1649
|
+
-1
|
|
1650
|
+
|
|
1651
|
+
Some more examples::
|
|
1652
|
+
|
|
1653
|
+
sage: MS = MatrixSpace(GF(2), 2)
|
|
1654
|
+
sage: a = list(MS)
|
|
1655
|
+
sage: len(a)
|
|
1656
|
+
16
|
|
1657
|
+
sage: for m in a:
|
|
1658
|
+
....: print(m)
|
|
1659
|
+
....: print('-')
|
|
1660
|
+
[0 0]
|
|
1661
|
+
[0 0]
|
|
1662
|
+
-
|
|
1663
|
+
[1 0]
|
|
1664
|
+
[0 0]
|
|
1665
|
+
-
|
|
1666
|
+
[0 1]
|
|
1667
|
+
[0 0]
|
|
1668
|
+
-
|
|
1669
|
+
[0 0]
|
|
1670
|
+
[1 0]
|
|
1671
|
+
-
|
|
1672
|
+
[0 0]
|
|
1673
|
+
[0 1]
|
|
1674
|
+
-
|
|
1675
|
+
[1 1]
|
|
1676
|
+
[0 0]
|
|
1677
|
+
-
|
|
1678
|
+
[1 0]
|
|
1679
|
+
[1 0]
|
|
1680
|
+
-
|
|
1681
|
+
[1 0]
|
|
1682
|
+
[0 1]
|
|
1683
|
+
-
|
|
1684
|
+
[0 1]
|
|
1685
|
+
[1 0]
|
|
1686
|
+
-
|
|
1687
|
+
[0 1]
|
|
1688
|
+
[0 1]
|
|
1689
|
+
-
|
|
1690
|
+
[0 0]
|
|
1691
|
+
[1 1]
|
|
1692
|
+
-
|
|
1693
|
+
[1 1]
|
|
1694
|
+
[1 0]
|
|
1695
|
+
-
|
|
1696
|
+
[1 1]
|
|
1697
|
+
[0 1]
|
|
1698
|
+
-
|
|
1699
|
+
[1 0]
|
|
1700
|
+
[1 1]
|
|
1701
|
+
-
|
|
1702
|
+
[0 1]
|
|
1703
|
+
[1 1]
|
|
1704
|
+
-
|
|
1705
|
+
[1 1]
|
|
1706
|
+
[1 1]
|
|
1707
|
+
-
|
|
1708
|
+
|
|
1709
|
+
::
|
|
1710
|
+
|
|
1711
|
+
sage: MS = MatrixSpace(GF(2), 2, 3)
|
|
1712
|
+
sage: a = list(MS)
|
|
1713
|
+
sage: len(a)
|
|
1714
|
+
64
|
|
1715
|
+
sage: a[0]
|
|
1716
|
+
[0 0 0]
|
|
1717
|
+
[0 0 0]
|
|
1718
|
+
|
|
1719
|
+
::
|
|
1720
|
+
|
|
1721
|
+
sage: MS = MatrixSpace(ZZ, 2, 3)
|
|
1722
|
+
sage: i = iter(MS)
|
|
1723
|
+
sage: a = [ next(i) for _ in range(6) ]
|
|
1724
|
+
sage: a[0]
|
|
1725
|
+
[0 0 0]
|
|
1726
|
+
[0 0 0]
|
|
1727
|
+
sage: a[4]
|
|
1728
|
+
[0 0 0]
|
|
1729
|
+
[1 0 0]
|
|
1730
|
+
|
|
1731
|
+
For degenerate cases, where either the number of rows or columns
|
|
1732
|
+
(or both) are zero, then the single element of the space is
|
|
1733
|
+
returned.
|
|
1734
|
+
|
|
1735
|
+
::
|
|
1736
|
+
|
|
1737
|
+
sage: list(MatrixSpace(GF(2), 2, 0))
|
|
1738
|
+
[[]]
|
|
1739
|
+
sage: list(MatrixSpace(GF(2), 0, 2))
|
|
1740
|
+
[[]]
|
|
1741
|
+
sage: list(MatrixSpace(GF(2), 0, 0))
|
|
1742
|
+
[[]]
|
|
1743
|
+
|
|
1744
|
+
If the base ring does not support iteration (for example, with the
|
|
1745
|
+
reals), then the matrix space over that ring does not support
|
|
1746
|
+
iteration either.
|
|
1747
|
+
|
|
1748
|
+
::
|
|
1749
|
+
|
|
1750
|
+
sage: MS = MatrixSpace(RR, 2)
|
|
1751
|
+
sage: a = list(MS)
|
|
1752
|
+
Traceback (most recent call last):
|
|
1753
|
+
...
|
|
1754
|
+
NotImplementedError: len() of an infinite set
|
|
1755
|
+
"""
|
|
1756
|
+
# Make sure that we can iterate over the base ring
|
|
1757
|
+
base_ring = self.base_ring()
|
|
1758
|
+
base_iter = iter(base_ring)
|
|
1759
|
+
|
|
1760
|
+
number_of_entries = (self.__nrows * self.__ncols)
|
|
1761
|
+
|
|
1762
|
+
# If the number of entries is zero, then just
|
|
1763
|
+
# yield the empty matrix in that case and return
|
|
1764
|
+
if number_of_entries == 0:
|
|
1765
|
+
yield self(0)
|
|
1766
|
+
return
|
|
1767
|
+
|
|
1768
|
+
import sage.combinat.integer_vector
|
|
1769
|
+
|
|
1770
|
+
if not base_ring.is_finite():
|
|
1771
|
+
# When the base ring is not finite, then we should go
|
|
1772
|
+
# through and yield the matrices by "weight", which is
|
|
1773
|
+
# the total number of iterations that need to be done
|
|
1774
|
+
# on the base ring to reach the matrix.
|
|
1775
|
+
base_elements = [next(base_iter)]
|
|
1776
|
+
weight = 0
|
|
1777
|
+
while True:
|
|
1778
|
+
for iv in sage.combinat.integer_vector.IntegerVectors(weight, number_of_entries):
|
|
1779
|
+
yield self([base_elements[i] for i in iv])
|
|
1780
|
+
weight += 1
|
|
1781
|
+
base_elements.append(next(base_iter))
|
|
1782
|
+
else:
|
|
1783
|
+
# In the finite case, we do a similar thing except that
|
|
1784
|
+
# the "weight" of each entry is bounded by the number
|
|
1785
|
+
# of elements in the base ring
|
|
1786
|
+
order = base_ring.order()
|
|
1787
|
+
base_elements = list(base_ring)
|
|
1788
|
+
for weight in range((order - 1) * number_of_entries + 1):
|
|
1789
|
+
for iv in sage.combinat.integer_vector.IntegerVectors(weight, number_of_entries, max_part=(order - 1)):
|
|
1790
|
+
yield self([base_elements[i] for i in iv])
|
|
1791
|
+
|
|
1792
|
+
def __getitem__(self, x):
|
|
1793
|
+
"""
|
|
1794
|
+
Return a polynomial ring over this ring or the `n`-th element of this ring.
|
|
1795
|
+
|
|
1796
|
+
This method implements the syntax ``R['x']`` to define polynomial rings
|
|
1797
|
+
over matrix rings, while still allowing to get the `n`-th element of a
|
|
1798
|
+
finite matrix ring with ``R[n]`` for backward compatibility.
|
|
1799
|
+
|
|
1800
|
+
(If this behaviour proves desirable for all finite enumerated rings, it
|
|
1801
|
+
should eventually be implemented in the corresponding category rather
|
|
1802
|
+
than here.)
|
|
1803
|
+
|
|
1804
|
+
.. SEEALSO::
|
|
1805
|
+
|
|
1806
|
+
:meth:`sage.categories.rings.Rings.ParentMethod.__getitem__`,
|
|
1807
|
+
:meth:`sage.structure.parent.Parent.__getitem__`
|
|
1808
|
+
|
|
1809
|
+
EXAMPLES::
|
|
1810
|
+
|
|
1811
|
+
sage: MS = MatrixSpace(GF(3), 2, 2)
|
|
1812
|
+
sage: MS['x']
|
|
1813
|
+
Univariate Polynomial Ring in x
|
|
1814
|
+
over Full MatrixSpace of 2 by 2 dense matrices
|
|
1815
|
+
over Finite Field of size 3
|
|
1816
|
+
sage: MS[0]
|
|
1817
|
+
[0 0]
|
|
1818
|
+
[0 0]
|
|
1819
|
+
sage: MS[9]
|
|
1820
|
+
[0 2]
|
|
1821
|
+
[0 0]
|
|
1822
|
+
|
|
1823
|
+
sage: MS = MatrixSpace(QQ, 7)
|
|
1824
|
+
sage: MS['x']
|
|
1825
|
+
Univariate Polynomial Ring in x over Full MatrixSpace of 7 by 7 dense matrices over Rational Field
|
|
1826
|
+
sage: MS[2]
|
|
1827
|
+
Traceback (most recent call last):
|
|
1828
|
+
...
|
|
1829
|
+
AttributeError: 'MatrixSpace_with_category' object has no attribute 'list'...
|
|
1830
|
+
"""
|
|
1831
|
+
if isinstance(x, (integer.Integer, int)):
|
|
1832
|
+
return self.list()[x]
|
|
1833
|
+
return super().__getitem__(x)
|
|
1834
|
+
|
|
1835
|
+
def basis(self):
|
|
1836
|
+
"""
|
|
1837
|
+
Return a basis for this matrix space.
|
|
1838
|
+
|
|
1839
|
+
.. WARNING::
|
|
1840
|
+
|
|
1841
|
+
This will of course compute every generator of this matrix
|
|
1842
|
+
space. So for large dimensions, this could take a long time,
|
|
1843
|
+
waste a massive amount of memory (for dense matrices), and
|
|
1844
|
+
is likely not very useful. Don't use this on large matrix
|
|
1845
|
+
spaces.
|
|
1846
|
+
|
|
1847
|
+
EXAMPLES::
|
|
1848
|
+
|
|
1849
|
+
sage: list(Mat(ZZ,2,2).basis())
|
|
1850
|
+
[
|
|
1851
|
+
[1 0] [0 1] [0 0] [0 0]
|
|
1852
|
+
[0 0], [0 0], [1 0], [0 1]
|
|
1853
|
+
]
|
|
1854
|
+
"""
|
|
1855
|
+
v = {(r, c): self.zero_matrix().__copy__()
|
|
1856
|
+
for r in range(self.__nrows)
|
|
1857
|
+
for c in range(self.__ncols)}
|
|
1858
|
+
one = self.base_ring().one()
|
|
1859
|
+
keys = []
|
|
1860
|
+
for r in range(self.__nrows):
|
|
1861
|
+
for c in range(self.__ncols):
|
|
1862
|
+
keys.append((r, c))
|
|
1863
|
+
v[r, c][r, c] = one
|
|
1864
|
+
v[r, c].set_immutable()
|
|
1865
|
+
from sage.sets.family import Family
|
|
1866
|
+
return Family(keys, v.__getitem__)
|
|
1867
|
+
|
|
1868
|
+
def dimension(self):
|
|
1869
|
+
r"""
|
|
1870
|
+
Return (m rows) \* (n cols) of ``self`` as ``Integer``.
|
|
1871
|
+
|
|
1872
|
+
EXAMPLES::
|
|
1873
|
+
|
|
1874
|
+
sage: MS = MatrixSpace(ZZ,4,6)
|
|
1875
|
+
sage: u = MS.dimension()
|
|
1876
|
+
sage: u - 24 == 0
|
|
1877
|
+
True
|
|
1878
|
+
"""
|
|
1879
|
+
return self.__nrows * self.__ncols
|
|
1880
|
+
|
|
1881
|
+
def dims(self):
|
|
1882
|
+
"""
|
|
1883
|
+
Return (m row, n col) representation of ``self`` dimension.
|
|
1884
|
+
|
|
1885
|
+
EXAMPLES::
|
|
1886
|
+
|
|
1887
|
+
sage: MS = MatrixSpace(ZZ,4,6)
|
|
1888
|
+
sage: MS.dims()
|
|
1889
|
+
(4, 6)
|
|
1890
|
+
"""
|
|
1891
|
+
return (self.__nrows, self.__ncols)
|
|
1892
|
+
|
|
1893
|
+
def submodule(self, gens, check=True, already_echelonized=False,
|
|
1894
|
+
unitriangular=False, support_order=None, category=None,
|
|
1895
|
+
*args, **opts):
|
|
1896
|
+
r"""
|
|
1897
|
+
The submodule spanned by a finite set of matrices.
|
|
1898
|
+
|
|
1899
|
+
INPUT:
|
|
1900
|
+
|
|
1901
|
+
- ``gens`` -- list or family of elements of ``self``
|
|
1902
|
+
|
|
1903
|
+
- ``check`` -- boolean (default: ``True``); whether to verify that the
|
|
1904
|
+
elements of ``gens`` are in ``self``
|
|
1905
|
+
|
|
1906
|
+
- ``already_echelonized`` -- boolean (default: ``False``); whether
|
|
1907
|
+
the elements of ``gens`` are already in (not necessarily
|
|
1908
|
+
reduced) echelon form
|
|
1909
|
+
|
|
1910
|
+
- ``unitriangular`` -- boolean (default: ``False``); whether
|
|
1911
|
+
the lift morphism is unitriangular
|
|
1912
|
+
|
|
1913
|
+
- ``support_order`` -- (optional) either something that can
|
|
1914
|
+
be converted into a tuple or a key function
|
|
1915
|
+
|
|
1916
|
+
If ``already_echelonized`` is ``False``, then the
|
|
1917
|
+
generators are put in reduced echelon form using
|
|
1918
|
+
:meth:`echelonize`, and reindexed by `0, 1, \ldots`.
|
|
1919
|
+
|
|
1920
|
+
.. WARNING::
|
|
1921
|
+
|
|
1922
|
+
At this point, this method only works for finite
|
|
1923
|
+
dimensional submodules and if matrices can be
|
|
1924
|
+
echelonized over the base ring.
|
|
1925
|
+
|
|
1926
|
+
If in addition ``unitriangular`` is ``True``, then
|
|
1927
|
+
the generators are made such that the coefficients of
|
|
1928
|
+
the pivots are 1, so that lifting map is unitriangular.
|
|
1929
|
+
|
|
1930
|
+
The basis of the submodule uses the same index set as the
|
|
1931
|
+
generators, and the lifting map sends `y_i` to `gens[i]`.
|
|
1932
|
+
|
|
1933
|
+
.. SEEALSO::
|
|
1934
|
+
|
|
1935
|
+
:meth:`ModulesWithBasis.ParentMethods.submodule`
|
|
1936
|
+
|
|
1937
|
+
EXAMPLES::
|
|
1938
|
+
|
|
1939
|
+
sage: M = MatrixSpace(QQ, 2)
|
|
1940
|
+
sage: mat = M.matrix([[1, 2], [3, 4]])
|
|
1941
|
+
sage: X = M.submodule([mat], already_echelonized=True); X
|
|
1942
|
+
Free module generated by {0} over Rational Field
|
|
1943
|
+
|
|
1944
|
+
sage: mat2 = M.matrix([[1, 0], [-3, 2]])
|
|
1945
|
+
sage: X = M.submodule([mat, mat2])
|
|
1946
|
+
sage: [X.lift(b) for b in X.basis()]
|
|
1947
|
+
[
|
|
1948
|
+
[ 1 0] [0 1]
|
|
1949
|
+
[-3 2], [3 1]
|
|
1950
|
+
]
|
|
1951
|
+
|
|
1952
|
+
sage: A = matrix([[1, 1], [0, -1]])
|
|
1953
|
+
sage: B = matrix([[0, 1], [0, 2]])
|
|
1954
|
+
sage: X = M.submodule([A, B])
|
|
1955
|
+
sage: Xp = M.submodule([A, B], support_order=[(0,1), (1,1), (0,0)])
|
|
1956
|
+
sage: [X.lift(b) for b in X.basis()]
|
|
1957
|
+
[
|
|
1958
|
+
[ 1 0] [0 1]
|
|
1959
|
+
[ 0 -3], [0 2]
|
|
1960
|
+
]
|
|
1961
|
+
sage: [Xp.lift(b) for b in Xp.basis()]
|
|
1962
|
+
[
|
|
1963
|
+
[2/3 1] [-1/3 0]
|
|
1964
|
+
[ 0 0], [ 0 1]
|
|
1965
|
+
]
|
|
1966
|
+
"""
|
|
1967
|
+
support_order = self._compute_support_order(gens, support_order)
|
|
1968
|
+
if not already_echelonized:
|
|
1969
|
+
gens = self.echelon_form(gens, unitriangular, order=support_order)
|
|
1970
|
+
else:
|
|
1971
|
+
from copy import copy
|
|
1972
|
+
# We will be making gens immutable, so copy the mutable matrices
|
|
1973
|
+
gens = [copy(g) if g.is_mutable() else g for g in gens]
|
|
1974
|
+
|
|
1975
|
+
# We need to make sure the result immutable
|
|
1976
|
+
for g in gens:
|
|
1977
|
+
g.set_immutable()
|
|
1978
|
+
|
|
1979
|
+
from sage.modules.with_basis.subquotient import SubmoduleWithBasis
|
|
1980
|
+
return SubmoduleWithBasis(gens, ambient=self,
|
|
1981
|
+
support_order=support_order,
|
|
1982
|
+
unitriangular=unitriangular,
|
|
1983
|
+
category=category, *args, **opts)
|
|
1984
|
+
|
|
1985
|
+
from sage.misc.cachefunc import cached_method
|
|
1986
|
+
|
|
1987
|
+
@cached_method
|
|
1988
|
+
def identity_matrix(self):
|
|
1989
|
+
"""
|
|
1990
|
+
Return the identity matrix in ``self``.
|
|
1991
|
+
|
|
1992
|
+
``self`` must be a space of square
|
|
1993
|
+
matrices. The returned matrix is immutable. Please use ``copy`` if
|
|
1994
|
+
you want a modified copy.
|
|
1995
|
+
|
|
1996
|
+
EXAMPLES::
|
|
1997
|
+
|
|
1998
|
+
sage: MS1 = MatrixSpace(ZZ,4)
|
|
1999
|
+
sage: MS2 = MatrixSpace(QQ,3,4)
|
|
2000
|
+
sage: I = MS1.identity_matrix()
|
|
2001
|
+
sage: I
|
|
2002
|
+
[1 0 0 0]
|
|
2003
|
+
[0 1 0 0]
|
|
2004
|
+
[0 0 1 0]
|
|
2005
|
+
[0 0 0 1]
|
|
2006
|
+
sage: Er = MS2.identity_matrix()
|
|
2007
|
+
Traceback (most recent call last):
|
|
2008
|
+
...
|
|
2009
|
+
TypeError: identity matrix must be square
|
|
2010
|
+
|
|
2011
|
+
TESTS::
|
|
2012
|
+
|
|
2013
|
+
sage: MS1.one()[1,2] = 3
|
|
2014
|
+
Traceback (most recent call last):
|
|
2015
|
+
...
|
|
2016
|
+
ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).
|
|
2017
|
+
|
|
2018
|
+
Check different implementations::
|
|
2019
|
+
|
|
2020
|
+
sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox
|
|
2021
|
+
sage: M2 = MatrixSpace(ZZ, 2, implementation='generic')
|
|
2022
|
+
|
|
2023
|
+
sage: type(M1.identity_matrix()) # needs sage.libs.linbox
|
|
2024
|
+
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
|
|
2025
|
+
sage: type(M2.identity_matrix())
|
|
2026
|
+
<class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
|
|
2027
|
+
"""
|
|
2028
|
+
if self.__nrows != self.__ncols:
|
|
2029
|
+
raise TypeError("identity matrix must be square")
|
|
2030
|
+
A = self.zero_matrix().__copy__()
|
|
2031
|
+
for i in range(self.__nrows):
|
|
2032
|
+
A[i, i] = 1
|
|
2033
|
+
A.set_immutable()
|
|
2034
|
+
return A
|
|
2035
|
+
|
|
2036
|
+
one = identity_matrix
|
|
2037
|
+
|
|
2038
|
+
def diagonal_matrix(self, entries):
|
|
2039
|
+
"""
|
|
2040
|
+
Create a diagonal matrix in ``self`` using the specified elements.
|
|
2041
|
+
|
|
2042
|
+
INPUT:
|
|
2043
|
+
|
|
2044
|
+
- ``entries`` -- the elements to use as the diagonal entries
|
|
2045
|
+
|
|
2046
|
+
``self`` must be a space of square matrices. The length of
|
|
2047
|
+
``entries`` must be less than or equal to the matrix
|
|
2048
|
+
dimensions. If the length of ``entries`` is less than the
|
|
2049
|
+
matrix dimensions, ``entries`` is padded with zeroes at the
|
|
2050
|
+
end.
|
|
2051
|
+
|
|
2052
|
+
EXAMPLES::
|
|
2053
|
+
|
|
2054
|
+
sage: MS1 = MatrixSpace(ZZ,4)
|
|
2055
|
+
sage: MS2 = MatrixSpace(QQ,3,4)
|
|
2056
|
+
sage: I = MS1.diagonal_matrix([1, 2, 3, 4])
|
|
2057
|
+
sage: I
|
|
2058
|
+
[1 0 0 0]
|
|
2059
|
+
[0 2 0 0]
|
|
2060
|
+
[0 0 3 0]
|
|
2061
|
+
[0 0 0 4]
|
|
2062
|
+
sage: MS2.diagonal_matrix([1, 2])
|
|
2063
|
+
Traceback (most recent call last):
|
|
2064
|
+
...
|
|
2065
|
+
TypeError: diagonal matrix must be square
|
|
2066
|
+
sage: MS1.diagonal_matrix([1, 2, 3, 4, 5])
|
|
2067
|
+
Traceback (most recent call last):
|
|
2068
|
+
...
|
|
2069
|
+
ValueError: number of diagonal matrix entries (5) exceeds the matrix size (4)
|
|
2070
|
+
sage: MS1.diagonal_matrix([1/2, 2, 3, 4])
|
|
2071
|
+
Traceback (most recent call last):
|
|
2072
|
+
...
|
|
2073
|
+
TypeError: no conversion of this rational to integer
|
|
2074
|
+
|
|
2075
|
+
Check different implementations::
|
|
2076
|
+
|
|
2077
|
+
sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox
|
|
2078
|
+
sage: M2 = MatrixSpace(ZZ, 2, implementation='generic')
|
|
2079
|
+
|
|
2080
|
+
sage: type(M1.diagonal_matrix([1, 2])) # needs sage.libs.linbox
|
|
2081
|
+
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
|
|
2082
|
+
sage: type(M2.diagonal_matrix([1, 2]))
|
|
2083
|
+
<class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'>
|
|
2084
|
+
"""
|
|
2085
|
+
if self.__nrows != self.__ncols:
|
|
2086
|
+
raise TypeError("diagonal matrix must be square")
|
|
2087
|
+
if self.__nrows < len(entries):
|
|
2088
|
+
raise ValueError('number of diagonal matrix entries (%s) exceeds the matrix size (%s)' % (len(entries), self.__nrows))
|
|
2089
|
+
A = self.zero_matrix().__copy__()
|
|
2090
|
+
for i in range(len(entries)):
|
|
2091
|
+
A[i, i] = entries[i]
|
|
2092
|
+
return A
|
|
2093
|
+
|
|
2094
|
+
def is_dense(self):
|
|
2095
|
+
"""
|
|
2096
|
+
Return whether matrices in ``self`` are dense.
|
|
2097
|
+
|
|
2098
|
+
EXAMPLES::
|
|
2099
|
+
|
|
2100
|
+
sage: Mat(RDF,2,3).is_sparse()
|
|
2101
|
+
False
|
|
2102
|
+
sage: Mat(RR,123456,22,sparse=True).is_sparse()
|
|
2103
|
+
True
|
|
2104
|
+
"""
|
|
2105
|
+
return not self.__is_sparse
|
|
2106
|
+
|
|
2107
|
+
def is_sparse(self):
|
|
2108
|
+
"""
|
|
2109
|
+
Return whether matrices in ``self`` are sparse.
|
|
2110
|
+
|
|
2111
|
+
EXAMPLES::
|
|
2112
|
+
|
|
2113
|
+
sage: Mat(GF(2011), 10000).is_sparse() # needs sage.rings.finite_rings
|
|
2114
|
+
False
|
|
2115
|
+
sage: Mat(GF(2011), 10000, sparse=True).is_sparse() # needs sage.rings.finite_rings
|
|
2116
|
+
True
|
|
2117
|
+
"""
|
|
2118
|
+
return self.__is_sparse
|
|
2119
|
+
|
|
2120
|
+
def is_finite(self):
|
|
2121
|
+
"""
|
|
2122
|
+
Return whether this matrix space is finite.
|
|
2123
|
+
|
|
2124
|
+
EXAMPLES::
|
|
2125
|
+
|
|
2126
|
+
sage: MatrixSpace(GF(101), 10000).is_finite()
|
|
2127
|
+
True
|
|
2128
|
+
sage: MatrixSpace(QQ, 2).is_finite()
|
|
2129
|
+
False
|
|
2130
|
+
"""
|
|
2131
|
+
return self.base_ring().is_finite()
|
|
2132
|
+
|
|
2133
|
+
def gen(self, n):
|
|
2134
|
+
"""
|
|
2135
|
+
Return the `n`-th generator of this matrix space.
|
|
2136
|
+
|
|
2137
|
+
This does not compute all basis matrices, so it is reasonably
|
|
2138
|
+
intelligent.
|
|
2139
|
+
|
|
2140
|
+
EXAMPLES::
|
|
2141
|
+
|
|
2142
|
+
sage: M = Mat(GF(7), 10000, 5); M.ngens()
|
|
2143
|
+
50000
|
|
2144
|
+
sage: a = M.10
|
|
2145
|
+
sage: a[:4]
|
|
2146
|
+
[0 0 0 0 0]
|
|
2147
|
+
[0 0 0 0 0]
|
|
2148
|
+
[1 0 0 0 0]
|
|
2149
|
+
[0 0 0 0 0]
|
|
2150
|
+
"""
|
|
2151
|
+
if hasattr(self, '__basis'):
|
|
2152
|
+
return self.__basis[n]
|
|
2153
|
+
r = n // self.__ncols
|
|
2154
|
+
c = n - (r * self.__ncols)
|
|
2155
|
+
z = self.zero_matrix().__copy__()
|
|
2156
|
+
z[r, c] = 1
|
|
2157
|
+
return z
|
|
2158
|
+
|
|
2159
|
+
@cached_method
|
|
2160
|
+
def zero_matrix(self):
|
|
2161
|
+
"""
|
|
2162
|
+
Return the zero matrix in ``self``.
|
|
2163
|
+
|
|
2164
|
+
``self`` must be a space of square matrices. The returned matrix is
|
|
2165
|
+
immutable. Please use ``copy`` if you want a modified copy.
|
|
2166
|
+
|
|
2167
|
+
EXAMPLES::
|
|
2168
|
+
|
|
2169
|
+
sage: z = MatrixSpace(GF(7), 2, 4).zero_matrix(); z
|
|
2170
|
+
[0 0 0 0]
|
|
2171
|
+
[0 0 0 0]
|
|
2172
|
+
sage: z.is_mutable()
|
|
2173
|
+
False
|
|
2174
|
+
|
|
2175
|
+
TESTS::
|
|
2176
|
+
|
|
2177
|
+
sage: MM = MatrixSpace(RDF,1,1,sparse=False); mat = MM.zero_matrix()
|
|
2178
|
+
sage: copy(mat)
|
|
2179
|
+
[0.0]
|
|
2180
|
+
sage: MM = MatrixSpace(RDF,0,0,sparse=False); mat = MM.zero_matrix()
|
|
2181
|
+
sage: copy(mat)
|
|
2182
|
+
[]
|
|
2183
|
+
sage: mat.is_mutable()
|
|
2184
|
+
False
|
|
2185
|
+
sage: MM.zero().is_mutable()
|
|
2186
|
+
False
|
|
2187
|
+
|
|
2188
|
+
Check that :issue:`38221` is fixed::
|
|
2189
|
+
|
|
2190
|
+
sage: # needs sage.groups
|
|
2191
|
+
sage: G = CyclicPermutationGroup(7)
|
|
2192
|
+
sage: R = GF(2)
|
|
2193
|
+
sage: A = G.algebra(R)
|
|
2194
|
+
sage: S = MatrixSpace(A, 3, 3)
|
|
2195
|
+
sage: S.zero_matrix()
|
|
2196
|
+
[0 0 0]
|
|
2197
|
+
[0 0 0]
|
|
2198
|
+
[0 0 0]
|
|
2199
|
+
"""
|
|
2200
|
+
res = self.element_class(self, None, False, False)
|
|
2201
|
+
res.set_immutable()
|
|
2202
|
+
return res
|
|
2203
|
+
|
|
2204
|
+
zero = zero_matrix
|
|
2205
|
+
|
|
2206
|
+
def ngens(self):
|
|
2207
|
+
"""
|
|
2208
|
+
Return the number of generators of this matrix space.
|
|
2209
|
+
|
|
2210
|
+
This is the number of entries in the matrices in this space.
|
|
2211
|
+
|
|
2212
|
+
EXAMPLES::
|
|
2213
|
+
|
|
2214
|
+
sage: M = Mat(GF(7), 100, 200); M.ngens()
|
|
2215
|
+
20000
|
|
2216
|
+
"""
|
|
2217
|
+
return self.dimension()
|
|
2218
|
+
|
|
2219
|
+
def matrix(self, x=None, **kwds):
|
|
2220
|
+
r"""
|
|
2221
|
+
Create a matrix in ``self``.
|
|
2222
|
+
|
|
2223
|
+
INPUT:
|
|
2224
|
+
|
|
2225
|
+
- ``x`` -- data to construct a new matrix from. See :func:`matrix`
|
|
2226
|
+
|
|
2227
|
+
- ``coerce`` -- boolean (default: ``True``); if ``False``, assume
|
|
2228
|
+
without checking that the values in ``x`` lie in the base ring
|
|
2229
|
+
|
|
2230
|
+
OUTPUT: a matrix in ``self``
|
|
2231
|
+
|
|
2232
|
+
EXAMPLES::
|
|
2233
|
+
|
|
2234
|
+
sage: M = MatrixSpace(ZZ, 2)
|
|
2235
|
+
sage: M.matrix([[1,0],[0,-1]])
|
|
2236
|
+
[ 1 0]
|
|
2237
|
+
[ 0 -1]
|
|
2238
|
+
sage: M.matrix([1,0,0,-1])
|
|
2239
|
+
[ 1 0]
|
|
2240
|
+
[ 0 -1]
|
|
2241
|
+
sage: M.matrix([1,2,3,4])
|
|
2242
|
+
[1 2]
|
|
2243
|
+
[3 4]
|
|
2244
|
+
|
|
2245
|
+
Note that the last "flip" cannot be performed if ``x`` is a
|
|
2246
|
+
matrix, no matter what is ``rows`` (it used to be possible but
|
|
2247
|
+
was fixed by :issue:`10793`)::
|
|
2248
|
+
|
|
2249
|
+
sage: projection = matrix(ZZ,[[1,0,0],[0,1,0]])
|
|
2250
|
+
sage: projection
|
|
2251
|
+
[1 0 0]
|
|
2252
|
+
[0 1 0]
|
|
2253
|
+
sage: projection.parent()
|
|
2254
|
+
Full MatrixSpace of 2 by 3 dense matrices over Integer Ring
|
|
2255
|
+
sage: M = MatrixSpace(ZZ, 3 , 2)
|
|
2256
|
+
sage: M
|
|
2257
|
+
Full MatrixSpace of 3 by 2 dense matrices over Integer Ring
|
|
2258
|
+
sage: M(projection)
|
|
2259
|
+
Traceback (most recent call last):
|
|
2260
|
+
...
|
|
2261
|
+
ValueError: inconsistent number of rows: should be 3 but got 2
|
|
2262
|
+
|
|
2263
|
+
If you really want to make from a matrix another matrix of different
|
|
2264
|
+
dimensions, use either transpose method or explicit conversion to a
|
|
2265
|
+
list::
|
|
2266
|
+
|
|
2267
|
+
sage: M(projection.list())
|
|
2268
|
+
[1 0]
|
|
2269
|
+
[0 0]
|
|
2270
|
+
[1 0]
|
|
2271
|
+
|
|
2272
|
+
TESTS:
|
|
2273
|
+
|
|
2274
|
+
The following corner cases were problematic while working on
|
|
2275
|
+
:issue:`10628`::
|
|
2276
|
+
|
|
2277
|
+
sage: MS = MatrixSpace(ZZ,2,1)
|
|
2278
|
+
sage: MS([[1],[2]])
|
|
2279
|
+
[1]
|
|
2280
|
+
[2]
|
|
2281
|
+
|
|
2282
|
+
sage: # needs sage.rings.real_mpfr
|
|
2283
|
+
sage: MS = MatrixSpace(CC, 2, 1)
|
|
2284
|
+
sage: x = polygen(ZZ, 'x')
|
|
2285
|
+
sage: F = NumberField(x^2 + 1, name='x') # needs sage.rings.number_field
|
|
2286
|
+
sage: MS([F(1), F(0)]) # needs sage.rings.number_field
|
|
2287
|
+
[ 1.00000000000000]
|
|
2288
|
+
[0.000000000000000]
|
|
2289
|
+
|
|
2290
|
+
:issue:`10628` allowed to provide the data as lists of matrices, but
|
|
2291
|
+
:issue:`13012` prohibited it::
|
|
2292
|
+
|
|
2293
|
+
sage: MS = MatrixSpace(ZZ, 4,2)
|
|
2294
|
+
sage: MS0 = MatrixSpace(ZZ, 2)
|
|
2295
|
+
sage: MS.matrix([MS0([1,2,3,4]), MS0([5,6,7,8])])
|
|
2296
|
+
Traceback (most recent call last):
|
|
2297
|
+
...
|
|
2298
|
+
TypeError: unable to coerce <class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> to an integer
|
|
2299
|
+
|
|
2300
|
+
A mixed list of matrices and vectors is prohibited as well::
|
|
2301
|
+
|
|
2302
|
+
sage: MS.matrix( [MS0([1,2,3,4])] + list(MS0([5,6,7,8])) )
|
|
2303
|
+
Traceback (most recent call last):
|
|
2304
|
+
...
|
|
2305
|
+
TypeError: unable to coerce <class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> to an integer
|
|
2306
|
+
|
|
2307
|
+
Check that :issue:`13302` is fixed::
|
|
2308
|
+
|
|
2309
|
+
sage: MatrixSpace(Qp(3), 1,1)([Qp(3).zero()]) # needs sage.rings.padics
|
|
2310
|
+
[0]
|
|
2311
|
+
sage: MatrixSpace(Qp(3), 1,1)([Qp(3)(4/3)]) # needs sage.rings.padics
|
|
2312
|
+
[3^-1 + 1 + O(3^19)]
|
|
2313
|
+
|
|
2314
|
+
One-rowed matrices over combinatorial free modules used to break
|
|
2315
|
+
the constructor (:issue:`17124`). Check that this is fixed::
|
|
2316
|
+
|
|
2317
|
+
sage: # needs sage.combinat
|
|
2318
|
+
sage: Sym = SymmetricFunctions(ZZ)
|
|
2319
|
+
sage: h = Sym.h()
|
|
2320
|
+
sage: MatrixSpace(h, 1,1)([h[1]])
|
|
2321
|
+
[h[1]]
|
|
2322
|
+
sage: MatrixSpace(h, 2,1)([h[1], h[2]])
|
|
2323
|
+
[h[1]]
|
|
2324
|
+
[h[2]]
|
|
2325
|
+
|
|
2326
|
+
Converting sparse to dense matrices used to be too slow
|
|
2327
|
+
(:issue:`20470`). Check that this is fixed::
|
|
2328
|
+
|
|
2329
|
+
sage: m = identity_matrix(GF(2), 2000, sparse=True)
|
|
2330
|
+
sage: MS = MatrixSpace(GF(2), 2000, sparse=False)
|
|
2331
|
+
sage: md = MS(m)
|
|
2332
|
+
sage: md.parent() is MS
|
|
2333
|
+
True
|
|
2334
|
+
"""
|
|
2335
|
+
return self(x, **kwds)
|
|
2336
|
+
|
|
2337
|
+
def matrix_space(self, nrows=None, ncols=None, sparse=False):
|
|
2338
|
+
"""
|
|
2339
|
+
Return the matrix space with given number of rows, columns and
|
|
2340
|
+
sparsity over the same base ring as self, and defaults the same as
|
|
2341
|
+
``self``.
|
|
2342
|
+
|
|
2343
|
+
EXAMPLES::
|
|
2344
|
+
|
|
2345
|
+
sage: M = Mat(GF(7), 100, 200)
|
|
2346
|
+
sage: M.matrix_space(5000)
|
|
2347
|
+
Full MatrixSpace of 5000 by 200 dense matrices over Finite Field of size 7
|
|
2348
|
+
sage: M.matrix_space(ncols=5000)
|
|
2349
|
+
Full MatrixSpace of 100 by 5000 dense matrices over Finite Field of size 7
|
|
2350
|
+
sage: M.matrix_space(sparse=True)
|
|
2351
|
+
Full MatrixSpace of 100 by 200 sparse matrices over Finite Field of size 7
|
|
2352
|
+
"""
|
|
2353
|
+
if nrows is None:
|
|
2354
|
+
nrows = self.__nrows
|
|
2355
|
+
if ncols is None:
|
|
2356
|
+
ncols = self.__ncols
|
|
2357
|
+
base = self._base
|
|
2358
|
+
return MatrixSpace(base, nrows, ncols, sparse=sparse)
|
|
2359
|
+
|
|
2360
|
+
def ncols(self):
|
|
2361
|
+
"""
|
|
2362
|
+
Return the number of columns of matrices in this space.
|
|
2363
|
+
|
|
2364
|
+
EXAMPLES::
|
|
2365
|
+
|
|
2366
|
+
sage: M = Mat(ZZ['x'], 200000, 500000, sparse=True)
|
|
2367
|
+
sage: M.ncols()
|
|
2368
|
+
500000
|
|
2369
|
+
"""
|
|
2370
|
+
return self.__ncols
|
|
2371
|
+
|
|
2372
|
+
def nrows(self):
|
|
2373
|
+
"""
|
|
2374
|
+
Return the number of rows of matrices in this space.
|
|
2375
|
+
|
|
2376
|
+
EXAMPLES::
|
|
2377
|
+
|
|
2378
|
+
sage: M = Mat(ZZ, 200000, 500000)
|
|
2379
|
+
sage: M.nrows()
|
|
2380
|
+
200000
|
|
2381
|
+
"""
|
|
2382
|
+
return self.__nrows
|
|
2383
|
+
|
|
2384
|
+
def row_space(self):
|
|
2385
|
+
"""
|
|
2386
|
+
Return the module spanned by all rows of matrices in this matrix
|
|
2387
|
+
space. This is a free module of rank the number of rows. It will be
|
|
2388
|
+
sparse or dense as this matrix space is sparse or dense.
|
|
2389
|
+
|
|
2390
|
+
EXAMPLES::
|
|
2391
|
+
|
|
2392
|
+
sage: M = Mat(ZZ,20,5,sparse=False); M.row_space()
|
|
2393
|
+
Ambient free module of rank 5 over the principal ideal domain Integer Ring
|
|
2394
|
+
"""
|
|
2395
|
+
try:
|
|
2396
|
+
return self.__row_space
|
|
2397
|
+
except AttributeError:
|
|
2398
|
+
self.__row_space = sage.modules.free_module.FreeModule(self.base_ring(),
|
|
2399
|
+
self.ncols(), sparse=self.is_sparse())
|
|
2400
|
+
return self.__row_space
|
|
2401
|
+
|
|
2402
|
+
def column_space(self):
|
|
2403
|
+
"""
|
|
2404
|
+
Return the module spanned by all columns of matrices in this matrix
|
|
2405
|
+
space. This is a free module of rank the number of columns. It will
|
|
2406
|
+
be sparse or dense as this matrix space is sparse or dense.
|
|
2407
|
+
|
|
2408
|
+
EXAMPLES::
|
|
2409
|
+
|
|
2410
|
+
sage: M = Mat(GF(9,'a'), 20, 5, sparse=True); M.column_space() # needs sage.rings.finite_rings
|
|
2411
|
+
Sparse vector space of dimension 20 over Finite Field in a of size 3^2
|
|
2412
|
+
"""
|
|
2413
|
+
try:
|
|
2414
|
+
return self.__column_space
|
|
2415
|
+
except AttributeError:
|
|
2416
|
+
self.__column_space = sage.modules.free_module.FreeModule(self.base_ring(), self.nrows(),
|
|
2417
|
+
sparse=self.is_sparse())
|
|
2418
|
+
return self.__column_space
|
|
2419
|
+
|
|
2420
|
+
def random_element(self, density=None, *args, **kwds):
|
|
2421
|
+
"""
|
|
2422
|
+
Return a random element from this matrix space.
|
|
2423
|
+
|
|
2424
|
+
INPUT:
|
|
2425
|
+
|
|
2426
|
+
- ``density`` -- ``float`` or ``None`` (default: ``None``); rough
|
|
2427
|
+
measure of the proportion of nonzero entries in the random matrix;
|
|
2428
|
+
if set to ``None``, all entries of the matrix are randomized,
|
|
2429
|
+
allowing for any element of the underlying ring, but if set to
|
|
2430
|
+
a ``float``, a proportion of entries is selected and randomized to
|
|
2431
|
+
nonzero elements of the ring
|
|
2432
|
+
|
|
2433
|
+
- ``*args, **kwds`` -- remaining parameters, which may be passed to
|
|
2434
|
+
the random_element function of the base ring. ("may be", since this
|
|
2435
|
+
function calls the ``randomize`` function on the zero matrix, which
|
|
2436
|
+
need not call the ``random_element`` function of the base ring at
|
|
2437
|
+
all in general.)
|
|
2438
|
+
|
|
2439
|
+
OUTPUT: Matrix
|
|
2440
|
+
|
|
2441
|
+
.. NOTE::
|
|
2442
|
+
|
|
2443
|
+
This method will randomize a proportion of roughly ``density`` entries
|
|
2444
|
+
in a newly allocated zero matrix.
|
|
2445
|
+
|
|
2446
|
+
By default, if the user sets the value of ``density`` explicitly, this
|
|
2447
|
+
method will enforce that these entries are set to nonzero values.
|
|
2448
|
+
However, if the test for equality with zero in the base ring is too
|
|
2449
|
+
expensive, the user can override this behaviour by passing the
|
|
2450
|
+
argument ``nonzero=False`` to this method.
|
|
2451
|
+
|
|
2452
|
+
Otherwise, if the user does not set the value of ``density``, the
|
|
2453
|
+
default value is taken to be 1, and the option ``nonzero=False`` is
|
|
2454
|
+
passed to the ``randomize`` method.
|
|
2455
|
+
|
|
2456
|
+
EXAMPLES::
|
|
2457
|
+
|
|
2458
|
+
sage: M = Mat(ZZ, 2, 5).random_element()
|
|
2459
|
+
sage: TestSuite(M).run()
|
|
2460
|
+
|
|
2461
|
+
sage: M = Mat(QQ, 2, 5).random_element(density=0.5)
|
|
2462
|
+
sage: TestSuite(M).run()
|
|
2463
|
+
|
|
2464
|
+
sage: M = Mat(QQ, 3, sparse=True).random_element()
|
|
2465
|
+
sage: TestSuite(M).run() # needs sage.libs.pari
|
|
2466
|
+
|
|
2467
|
+
sage: M = Mat(GF(9,'a'), 3, sparse=True).random_element() # needs sage.rings.finite_rings
|
|
2468
|
+
sage: TestSuite(M).run() # needs sage.rings.finite_rings
|
|
2469
|
+
"""
|
|
2470
|
+
Z = self.zero_matrix().__copy__()
|
|
2471
|
+
if density is None:
|
|
2472
|
+
Z.randomize(density=float(1), nonzero=kwds.pop('nonzero', False),
|
|
2473
|
+
*args, **kwds)
|
|
2474
|
+
else:
|
|
2475
|
+
Z.randomize(density=density, nonzero=kwds.pop('nonzero', True),
|
|
2476
|
+
*args, **kwds)
|
|
2477
|
+
return Z
|
|
2478
|
+
|
|
2479
|
+
def _an_element_(self):
|
|
2480
|
+
"""
|
|
2481
|
+
Create a typical element of this matrix space.
|
|
2482
|
+
|
|
2483
|
+
This uses ``some_elements`` of the base ring.
|
|
2484
|
+
|
|
2485
|
+
EXAMPLES::
|
|
2486
|
+
|
|
2487
|
+
sage: MatrixSpace(QQ, 3, 3).an_element() # indirect doctest
|
|
2488
|
+
[ 1/2 -1/2 2]
|
|
2489
|
+
[ -2 0 1]
|
|
2490
|
+
[ -1 42 2/3]
|
|
2491
|
+
|
|
2492
|
+
TESTS::
|
|
2493
|
+
|
|
2494
|
+
sage: MatrixSpace(ZZ, 0, 0).an_element()
|
|
2495
|
+
[]
|
|
2496
|
+
|
|
2497
|
+
Check that this works for large matrices and that it returns a
|
|
2498
|
+
matrix which is not too trivial::
|
|
2499
|
+
|
|
2500
|
+
sage: M = MatrixSpace(GF(2), 100, 100).an_element()
|
|
2501
|
+
sage: M.rank() >= 2
|
|
2502
|
+
True
|
|
2503
|
+
|
|
2504
|
+
Check that this works for sparse matrices::
|
|
2505
|
+
|
|
2506
|
+
sage: M = MatrixSpace(ZZ, 1000, 1000, sparse=True).an_element()
|
|
2507
|
+
sage: 96 <= M.density() * 10^6 <= 99
|
|
2508
|
+
True
|
|
2509
|
+
"""
|
|
2510
|
+
from .args import MatrixArgs
|
|
2511
|
+
dim = self.dimension()
|
|
2512
|
+
if dim > 100 and self.is_sparse():
|
|
2513
|
+
# Sparse case: add 100 elements
|
|
2514
|
+
D = {}
|
|
2515
|
+
nr = self.nrows()
|
|
2516
|
+
nc = self.ncols()
|
|
2517
|
+
from random import randrange
|
|
2518
|
+
n = 0
|
|
2519
|
+
while True:
|
|
2520
|
+
for el in self.base().some_elements():
|
|
2521
|
+
if n == 100:
|
|
2522
|
+
ma = MatrixArgs(D, space=self)
|
|
2523
|
+
del D
|
|
2524
|
+
return ma.matrix()
|
|
2525
|
+
D[randrange(nr), randrange(nc)] = el
|
|
2526
|
+
n += 1
|
|
2527
|
+
assert D
|
|
2528
|
+
else:
|
|
2529
|
+
# Dense case
|
|
2530
|
+
# Keep appending to L until we have enough elements
|
|
2531
|
+
L = []
|
|
2532
|
+
while True:
|
|
2533
|
+
for el in self.base().some_elements():
|
|
2534
|
+
if len(L) == dim:
|
|
2535
|
+
ma = MatrixArgs(L, space=self)
|
|
2536
|
+
del L # for efficiency: this may avoid a copy of L
|
|
2537
|
+
return ma.matrix()
|
|
2538
|
+
L.append(el)
|
|
2539
|
+
assert L
|
|
2540
|
+
|
|
2541
|
+
def some_elements(self):
|
|
2542
|
+
r"""
|
|
2543
|
+
Return some elements of this matrix space.
|
|
2544
|
+
|
|
2545
|
+
See :class:`TestSuite` for a typical use case.
|
|
2546
|
+
|
|
2547
|
+
OUTPUT: an iterator
|
|
2548
|
+
|
|
2549
|
+
EXAMPLES::
|
|
2550
|
+
|
|
2551
|
+
sage: M = MatrixSpace(ZZ, 2, 2)
|
|
2552
|
+
sage: tuple(M.some_elements())
|
|
2553
|
+
(
|
|
2554
|
+
[ 0 1] [1 0] [0 1] [0 0] [0 0]
|
|
2555
|
+
[-1 2], [0 0], [0 0], [1 0], [0 1]
|
|
2556
|
+
)
|
|
2557
|
+
sage: M = MatrixSpace(QQ, 2, 3)
|
|
2558
|
+
sage: tuple(M.some_elements())
|
|
2559
|
+
(
|
|
2560
|
+
[ 1/2 -1/2 2] [1 0 0] [0 1 0] [0 0 1] [0 0 0] [0 0 0] [0 0 0]
|
|
2561
|
+
[ -2 0 1], [0 0 0], [0 0 0], [0 0 0], [1 0 0], [0 1 0], [0 0 1]
|
|
2562
|
+
)
|
|
2563
|
+
sage: M = MatrixSpace(SR, 2, 2) # needs sage.symbolic
|
|
2564
|
+
sage: tuple(M.some_elements()) # needs sage.symbolic
|
|
2565
|
+
(
|
|
2566
|
+
[some_variable some_variable] [1 0] [0 1] [0 0] [0 0]
|
|
2567
|
+
[some_variable some_variable], [0 0], [0 0], [1 0], [0 1]
|
|
2568
|
+
)
|
|
2569
|
+
"""
|
|
2570
|
+
yield self.an_element()
|
|
2571
|
+
yield from self.gens()
|
|
2572
|
+
|
|
2573
|
+
def _magma_init_(self, magma):
|
|
2574
|
+
r"""
|
|
2575
|
+
EXAMPLES: We first coerce a square matrix.
|
|
2576
|
+
|
|
2577
|
+
::
|
|
2578
|
+
|
|
2579
|
+
sage: magma(MatrixSpace(QQ, 3)) # optional - magma
|
|
2580
|
+
Full Matrix Algebra of degree 3 over Rational Field
|
|
2581
|
+
|
|
2582
|
+
::
|
|
2583
|
+
|
|
2584
|
+
sage: magma(MatrixSpace(Integers(8), 2, 3)) # optional - magma
|
|
2585
|
+
Full RMatrixSpace of 2 by 3 matrices over IntegerRing(8)
|
|
2586
|
+
"""
|
|
2587
|
+
K = magma(self.base_ring())
|
|
2588
|
+
if self.__nrows == self.__ncols:
|
|
2589
|
+
return 'MatrixAlgebra(%s,%s)' % (K.name(), self.__nrows)
|
|
2590
|
+
return 'RMatrixSpace(%s,%s,%s)' % (K.name(), self.__nrows, self.__ncols)
|
|
2591
|
+
|
|
2592
|
+
def _polymake_init_(self):
|
|
2593
|
+
r"""
|
|
2594
|
+
Return the polymake representation of the matrix space.
|
|
2595
|
+
|
|
2596
|
+
EXAMPLES::
|
|
2597
|
+
|
|
2598
|
+
sage: polymake(MatrixSpace(QQ, 3)) # optional - jupymake
|
|
2599
|
+
Matrix<Rational>
|
|
2600
|
+
sage: polymake(MatrixSpace(QuadraticField(5), 3)) # optional - jupymake, needs sage.rings.number_field
|
|
2601
|
+
Matrix<QuadraticExtension>
|
|
2602
|
+
"""
|
|
2603
|
+
from sage.interfaces.polymake import polymake
|
|
2604
|
+
K = polymake(self.base_ring())
|
|
2605
|
+
return '"Matrix<{}>"'.format(K)
|
|
2606
|
+
|
|
2607
|
+
def _random_nonzero_element(self, *args, **kwds):
|
|
2608
|
+
"""
|
|
2609
|
+
Return a random nonzero matrix.
|
|
2610
|
+
|
|
2611
|
+
This function repeatedly calls ``random_element`` until a nonzero
|
|
2612
|
+
matrix is obtained.
|
|
2613
|
+
|
|
2614
|
+
INPUT:
|
|
2615
|
+
|
|
2616
|
+
- ``*args``, ``**kwds`` -- parameters that can be forwarded to the
|
|
2617
|
+
``random_element`` method
|
|
2618
|
+
|
|
2619
|
+
OUTPUT: random nonzero matrix
|
|
2620
|
+
|
|
2621
|
+
EXAMPLES::
|
|
2622
|
+
|
|
2623
|
+
sage: M = MatrixSpace(ZZ, 4)
|
|
2624
|
+
sage: A = M._random_nonzero_element()
|
|
2625
|
+
sage: A.is_zero()
|
|
2626
|
+
False
|
|
2627
|
+
|
|
2628
|
+
sage: M = MatrixSpace(ZZ, 0)
|
|
2629
|
+
sage: A = M._random_nonzero_element()
|
|
2630
|
+
Traceback (most recent call last):
|
|
2631
|
+
...
|
|
2632
|
+
ValueError: Full MatrixSpace of 0 by 0 dense matrices over Integer Ring only has zero elements
|
|
2633
|
+
"""
|
|
2634
|
+
if 0 in self.dims():
|
|
2635
|
+
raise ValueError("{} only has zero elements".format(self))
|
|
2636
|
+
rand_matrix = self.random_element(*args, **kwds)
|
|
2637
|
+
while rand_matrix.is_zero():
|
|
2638
|
+
rand_matrix = self.random_element(*args, **kwds)
|
|
2639
|
+
return rand_matrix
|
|
2640
|
+
|
|
2641
|
+
def from_vector(self, vector, order=None, coerce=True):
|
|
2642
|
+
r"""
|
|
2643
|
+
Build an element of ``self`` from a vector.
|
|
2644
|
+
|
|
2645
|
+
EXAMPLES::
|
|
2646
|
+
|
|
2647
|
+
sage: A = matrix([[1,2,3], [4,5,6]])
|
|
2648
|
+
sage: v = vector(A); v
|
|
2649
|
+
(1, 2, 3, 4, 5, 6)
|
|
2650
|
+
sage: MS = A.parent()
|
|
2651
|
+
sage: MS.from_vector(v)
|
|
2652
|
+
[1 2 3]
|
|
2653
|
+
[4 5 6]
|
|
2654
|
+
sage: order = [(1,2), (1,0), (0,1), (0,2), (0,0), (1,1)]
|
|
2655
|
+
sage: MS.from_vector(v, order=order)
|
|
2656
|
+
[5 3 4]
|
|
2657
|
+
[2 6 1]
|
|
2658
|
+
"""
|
|
2659
|
+
if order is None:
|
|
2660
|
+
if self.is_dense():
|
|
2661
|
+
return self.element_class(self, vector, coerce=coerce)
|
|
2662
|
+
else:
|
|
2663
|
+
nc = self.ncols()
|
|
2664
|
+
d = {(k // nc, k % nc): c for k, c in vector.dict().items()}
|
|
2665
|
+
return self.element_class(self, d, coerce=coerce)
|
|
2666
|
+
return super().from_vector(vector, order=order, coerce=coerce)
|
|
2667
|
+
|
|
2668
|
+
def _from_dict(self, d, coerce=True, remove_zeros=True):
|
|
2669
|
+
r"""
|
|
2670
|
+
Construct an element of ``self`` from the dictionary ``d``.
|
|
2671
|
+
|
|
2672
|
+
INPUT:
|
|
2673
|
+
|
|
2674
|
+
- ``coerce`` -- boolean; coerce the coefficients to the base ring
|
|
2675
|
+
- ``remove_zeros`` -- ignored; for compatibility
|
|
2676
|
+
|
|
2677
|
+
EXAMPLES::
|
|
2678
|
+
|
|
2679
|
+
sage: MS = MatrixSpace(QQ['x'], 10, 5)
|
|
2680
|
+
sage: A = MS.random_element()
|
|
2681
|
+
sage: MS._from_dict(A.monomial_coefficients()) == A
|
|
2682
|
+
True
|
|
2683
|
+
"""
|
|
2684
|
+
return self.element_class(self, d, coerce=coerce)
|
|
2685
|
+
|
|
2686
|
+
|
|
2687
|
+
def dict_to_list(entries, nrows, ncols):
|
|
2688
|
+
r"""
|
|
2689
|
+
Given a dictionary of coordinate tuples, return the list given by
|
|
2690
|
+
reading off the nrows\*ncols matrix in row order.
|
|
2691
|
+
|
|
2692
|
+
EXAMPLES::
|
|
2693
|
+
|
|
2694
|
+
sage: from sage.matrix.matrix_space import dict_to_list
|
|
2695
|
+
sage: d = {}
|
|
2696
|
+
sage: d[(0,0)] = 1
|
|
2697
|
+
sage: d[(1,1)] = 2
|
|
2698
|
+
sage: dict_to_list(d, 2, 2)
|
|
2699
|
+
[1, 0, 0, 2]
|
|
2700
|
+
sage: dict_to_list(d, 2, 3)
|
|
2701
|
+
[1, 0, 0, 0, 2, 0]
|
|
2702
|
+
"""
|
|
2703
|
+
v = [0] * (nrows * ncols)
|
|
2704
|
+
for ij, y in entries.items():
|
|
2705
|
+
i, j = ij
|
|
2706
|
+
v[i * ncols + j] = y
|
|
2707
|
+
return v
|
|
2708
|
+
|
|
2709
|
+
|
|
2710
|
+
def _test_trivial_matrices_inverse(ring, sparse=True, implementation=None, checkrank=True):
|
|
2711
|
+
"""
|
|
2712
|
+
Test inversion, determinant and is_invertible for trivial matrices.
|
|
2713
|
+
|
|
2714
|
+
This function is a helper to check that the inversion of trivial matrices
|
|
2715
|
+
(of size 0x0, nx0, 0xn or 1x1) is handled consistently by the various
|
|
2716
|
+
implementation of matrices. The coherency is checked through a bunch of
|
|
2717
|
+
assertions. If an inconsistency is found, an :exc:`AssertionError` is
|
|
2718
|
+
raised which should make clear what is the problem.
|
|
2719
|
+
|
|
2720
|
+
INPUT:
|
|
2721
|
+
|
|
2722
|
+
- ``ring`` -- a ring
|
|
2723
|
+
- ``sparse`` -- boolean
|
|
2724
|
+
- ``checkrank`` -- boolean
|
|
2725
|
+
|
|
2726
|
+
OUTPUT: nothing if everything is correct, otherwise raise an AssertionError
|
|
2727
|
+
|
|
2728
|
+
The methods determinant, is_invertible, rank and inverse are checked for
|
|
2729
|
+
- the 0x0 empty identity matrix
|
|
2730
|
+
- the 0x3 and 3x0 matrices
|
|
2731
|
+
- the 1x1 null matrix [0]
|
|
2732
|
+
- the 1x1 identity matrix [1]
|
|
2733
|
+
|
|
2734
|
+
If ``checkrank`` is ``False`` then the rank is not checked. This is used
|
|
2735
|
+
the check matrix over ring where echelon form is not implemented.
|
|
2736
|
+
|
|
2737
|
+
.. TODO::
|
|
2738
|
+
|
|
2739
|
+
This must be adapted to category check framework when ready
|
|
2740
|
+
(see :issue:`5274`).
|
|
2741
|
+
|
|
2742
|
+
TESTS::
|
|
2743
|
+
|
|
2744
|
+
sage: from sage.matrix.matrix_space import _test_trivial_matrices_inverse as tinv
|
|
2745
|
+
sage: tinv(ZZ, sparse=True)
|
|
2746
|
+
sage: tinv(ZZ, sparse=False, implementation='flint') # needs sage.libs.linbox
|
|
2747
|
+
sage: tinv(ZZ, sparse=False, implementation='generic')
|
|
2748
|
+
sage: tinv(QQ, sparse=True)
|
|
2749
|
+
sage: tinv(QQ, sparse=False, implementation='flint') # needs sage.libs.linbox
|
|
2750
|
+
sage: tinv(QQ, sparse=False, implementation='generic')
|
|
2751
|
+
sage: tinv(GF(11), sparse=True)
|
|
2752
|
+
sage: tinv(GF(11), sparse=False)
|
|
2753
|
+
sage: tinv(GF(2), sparse=True)
|
|
2754
|
+
sage: tinv(GF(2), sparse=False)
|
|
2755
|
+
sage: tinv(SR, sparse=True) # needs sage.symbolic
|
|
2756
|
+
sage: tinv(SR, sparse=False) # needs sage.symbolic
|
|
2757
|
+
|
|
2758
|
+
sage: # needs scipy
|
|
2759
|
+
sage: tinv(RDF, sparse=True)
|
|
2760
|
+
sage: tinv(RDF, sparse=False)
|
|
2761
|
+
sage: tinv(CDF, sparse=True) # needs sage.rings.complex_double
|
|
2762
|
+
sage: tinv(CDF, sparse=False) # needs sage.rings.complex_double
|
|
2763
|
+
sage: tinv(CyclotomicField(7), sparse=True) # needs sage.rings.number_field
|
|
2764
|
+
sage: tinv(CyclotomicField(7), sparse=False) # needs sage.rings.number_field
|
|
2765
|
+
sage: tinv(QQ['x,y'], sparse=True)
|
|
2766
|
+
sage: tinv(QQ['x,y'], sparse=False)
|
|
2767
|
+
"""
|
|
2768
|
+
# Check that the empty 0x0 matrix is it's own inverse with det=1.
|
|
2769
|
+
ms00 = MatrixSpace(ring, 0, 0, sparse=sparse)
|
|
2770
|
+
m00 = ms00(0)
|
|
2771
|
+
assert m00.determinant() == ring(1)
|
|
2772
|
+
assert m00.is_invertible()
|
|
2773
|
+
assert m00.inverse() == m00
|
|
2774
|
+
if checkrank:
|
|
2775
|
+
assert m00.rank() == 0
|
|
2776
|
+
|
|
2777
|
+
# Check that the empty 0x3 and 3x0 matrices are not invertible and that
|
|
2778
|
+
# computing the determinant raise the proper exception.
|
|
2779
|
+
for ms0 in [MatrixSpace(ring, 0, 3, sparse=sparse),
|
|
2780
|
+
MatrixSpace(ring, 3, 0, sparse=sparse)]:
|
|
2781
|
+
mn0 = ms0(0)
|
|
2782
|
+
assert not mn0.is_invertible()
|
|
2783
|
+
try:
|
|
2784
|
+
d = mn0.determinant()
|
|
2785
|
+
print(d)
|
|
2786
|
+
res = False
|
|
2787
|
+
except ValueError:
|
|
2788
|
+
res = True
|
|
2789
|
+
assert res
|
|
2790
|
+
try:
|
|
2791
|
+
mn0.inverse()
|
|
2792
|
+
res = False
|
|
2793
|
+
except ArithmeticError:
|
|
2794
|
+
res = True
|
|
2795
|
+
assert res
|
|
2796
|
+
if checkrank:
|
|
2797
|
+
assert mn0.rank() == 0
|
|
2798
|
+
|
|
2799
|
+
# Check that the null 1x1 matrix is not invertible and that det=0
|
|
2800
|
+
ms1 = MatrixSpace(ring, 1, 1, sparse=sparse)
|
|
2801
|
+
m0 = ms1(0)
|
|
2802
|
+
assert not m0.is_invertible()
|
|
2803
|
+
assert m0.determinant() == ring(0)
|
|
2804
|
+
try:
|
|
2805
|
+
m0.inverse()
|
|
2806
|
+
res = False
|
|
2807
|
+
except (ZeroDivisionError, RuntimeError):
|
|
2808
|
+
# FIXME: Make pynac throw a ZeroDivisionError on division by
|
|
2809
|
+
# zero instead of a runtime Error
|
|
2810
|
+
res = True
|
|
2811
|
+
assert res
|
|
2812
|
+
if checkrank:
|
|
2813
|
+
assert m0.rank() == 0
|
|
2814
|
+
|
|
2815
|
+
# Check that the identity 1x1 matrix is its own inverse with det=1
|
|
2816
|
+
m1 = ms1(1)
|
|
2817
|
+
assert m1.is_invertible()
|
|
2818
|
+
assert m1.determinant() == ring(1)
|
|
2819
|
+
inv = m1.inverse()
|
|
2820
|
+
assert inv == m1
|
|
2821
|
+
if checkrank:
|
|
2822
|
+
assert m1.rank() == 1
|
|
2823
|
+
|
|
2824
|
+
|
|
2825
|
+
test_trivial_matrices_inverse = deprecated_function_alias(33612, _test_trivial_matrices_inverse)
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
# Fix unpickling Matrix_modn_dense and Matrix_integer_2x2
|
|
2829
|
+
lazy_import('sage.matrix.matrix_modn_dense_double', 'Matrix_modn_dense_double')
|
|
2830
|
+
lazy_import('sage.matrix.matrix_integer_dense', 'Matrix_integer_dense')
|
|
2831
|
+
|
|
2832
|
+
|
|
2833
|
+
def _MatrixSpace_ZZ_2x2():
|
|
2834
|
+
from sage.rings.integer_ring import ZZ
|
|
2835
|
+
return MatrixSpace(ZZ, 2)
|
|
2836
|
+
|
|
2837
|
+
|
|
2838
|
+
register_unpickle_override('sage.matrix.matrix_modn_dense',
|
|
2839
|
+
'Matrix_modn_dense', Matrix_modn_dense_double)
|
|
2840
|
+
register_unpickle_override('sage.matrix.matrix_integer_2x2',
|
|
2841
|
+
'Matrix_integer_2x2', Matrix_integer_dense)
|
|
2842
|
+
register_unpickle_override('sage.matrix.matrix_integer_2x2',
|
|
2843
|
+
'MatrixSpace_ZZ_2x2_class', MatrixSpace)
|
|
2844
|
+
register_unpickle_override('sage.matrix.matrix_integer_2x2',
|
|
2845
|
+
'MatrixSpace_ZZ_2x2', _MatrixSpace_ZZ_2x2)
|
|
2846
|
+
lazy_import('sage.matrix.matrix_gf2e_dense', 'unpickle_matrix_gf2e_dense_v0')
|
|
2847
|
+
register_unpickle_override('sage.matrix.matrix_mod2e_dense',
|
|
2848
|
+
'unpickle_matrix_mod2e_dense_v0', unpickle_matrix_gf2e_dense_v0)
|