Skip to content

Commit e9643d8

Browse files
author
Matthias Koeppe
committed
Use more block tags, fix # needs, docstring cosmetics
1 parent 33f8c98 commit e9643d8

File tree

4 files changed

+99
-91
lines changed

4 files changed

+99
-91
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,11 @@ cdef class Matrix(Matrix1):
349349
True
350350
sage: X
351351
(-1, 2, 0, 0)
352+
353+
sage: # needs sage.libs.pari
352354
sage: A = Matrix(Zmod(128), 2, 3, [5, 29, 33, 64, 0, 7])
353355
sage: B = vector(Zmod(128), [31,39,56])
354-
sage: X = A.solve_left(B); X # needs sage.libs.pari
356+
sage: X = A.solve_left(B); X
355357
(19, 83)
356358
sage: X * A == B
357359
True
@@ -393,9 +395,10 @@ cdef class Matrix(Matrix1):
393395
The vector of constants needs to be compatible with
394396
the base ring of the coefficient matrix::
395397

396-
sage: F.<a> = FiniteField(27) # needs sage.rings.finite_rings
397-
sage: b = vector(F, [a,a,a,a,a]) # needs sage.rings.finite_rings
398-
sage: A.solve_left(b) # needs sage.rings.finite_rings
398+
sage: # needs sage.rings.finite_rings
399+
sage: F.<a> = FiniteField(27)
400+
sage: b = vector(F, [a,a,a,a,a])
401+
sage: A.solve_left(b)
399402
Traceback (most recent call last):
400403
...
401404
TypeError: no common canonical parent for objects with parents: ...
@@ -4126,12 +4129,12 @@ cdef class Matrix(Matrix1):
41264129
We check that number fields are handled by the right routine as part of
41274130
typical right kernel computation. ::
41284131

4129-
sage" # needs sage.rings.number_field
4130-
sage: Q = QuadraticField(-7) # needs sage.rings.number_field
4131-
sage: a = Q.gen(0) # needs sage.rings.number_field
4132-
sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], [2+a, a, -7 + 5*a, -3+3*a]]) # needs sage.rings.number_field
4132+
sage: # needs sage.rings.number_field
4133+
sage: Q = QuadraticField(-7)
4134+
sage: a = Q.gen(0)
4135+
sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], [2+a, a, -7 + 5*a, -3+3*a]])
41334136
sage: set_verbose(1)
4134-
sage: A.right_kernel(algorithm='default') # needs sage.rings.number_field
4137+
sage: A.right_kernel(algorithm='default')
41354138
verbose ...
41364139
verbose 1 (<module>) computing right kernel matrix over a number field for 2x4 matrix
41374140
verbose 1 (<module>) done computing right kernel matrix over a number field for 2x4 matrix
@@ -5686,33 +5689,38 @@ cdef class Matrix(Matrix1):
56865689

56875690
EXAMPLES::
56885691

5689-
i sage: # needs sage.libs.pari
5692+
sage: # needs sage.libs.pari
56905693
sage: t = matrix(QQ, 3, [3, 0, -2, 0, -2, 0, 0, 0, 0]); t
56915694
[ 3 0 -2]
56925695
[ 0 -2 0]
56935696
[ 0 0 0]
5694-
sage: t.fcp('X') # factored charpoly # needs sage.libs.pari
5697+
sage: t.fcp('X') # factored charpoly
56955698
(X - 3) * X * (X + 2)
5696-
sage: v = kernel(t*(t+2)); v # an invariant subspace
5699+
sage: v = kernel(t*(t+2)); v # an invariant subspace
56975700
Vector space of degree 3 and dimension 2 over Rational Field
56985701
Basis matrix:
56995702
[0 1 0]
57005703
[0 0 1]
5701-
sage: D = t.decomposition_of_subspace(v); D # needs sage.libs.pari
5704+
sage: D = t.decomposition_of_subspace(v); D
57025705
[ (Vector space of degree 3 and dimension 1 over Rational Field
57035706
Basis matrix: [0 0 1],
57045707
True),
57055708
(Vector space of degree 3 and dimension 1 over Rational Field
57065709
Basis matrix: [0 1 0],
57075710
True) ]
5708-
sage: t.restrict(D[0][0]) # needs sage.libs.pari
5711+
sage: t.restrict(D[0][0])
57095712
[0]
5710-
sage: t.restrict(D[1][0]) # needs sage.libs.pari
5713+
sage: t.restrict(D[1][0])
57115714
[-2]
57125715

57135716
We do a decomposition over ZZ::
57145717

5715-
sage: a = matrix(ZZ, 6, [0, 0, -2, 0, 2, 0, 2, -4, -2, 0, 2, 0, 0, 0, -2, -2, 0, 0, 2, 0, -2, -4, 2, -2, 0, 2, 0, -2, -2, 0, 0, 2, 0, -2, 0, 0])
5718+
sage: a = matrix(ZZ, 6, [0, 0, -2, 0, 2, 0,
5719+
....: 2, -4, -2, 0, 2, 0,
5720+
....: 0, 0, -2, -2, 0, 0,
5721+
....: 2, 0, -2, -4, 2, -2,
5722+
....: 0, 2, 0, -2, -2, 0,
5723+
....: 0, 2, 0, -2, 0, 0])
57165724
sage: a.decomposition_of_subspace(ZZ^6) # needs sage.libs.pari
57175725
[ (Free module of degree 6 and rank 2 over Integer Ring
57185726
Echelon basis matrix:
@@ -5730,7 +5738,7 @@ i sage: # needs sage.libs.pari
57305738
TESTS::
57315739

57325740
sage: t = matrix(QQ, 3, [3, 0, -2, 0, -2, 0, 0, 0, 0])
5733-
sage: t.decomposition_of_subspace(v, check_restrict = False) == t.decomposition_of_subspace(v) # needs sage.libs.pari
5741+
sage: t.decomposition_of_subspace(v, check_restrict=False) == t.decomposition_of_subspace(v) # needs sage.libs.pari
57345742
True
57355743
"""
57365744
if not sage.modules.free_module.is_FreeModule(M):
@@ -6041,14 +6049,14 @@ i sage: # needs sage.libs.pari
60416049

60426050
INPUT:
60436051

6044-
- ``format`` - ``None``, ``'all'`` or ``'galois'``
6052+
- ``format`` -- ``None``, ``'all'`` or ``'galois'``
60456053

60466054
OUTPUT:
60476055

60486056
Any format except ``None`` is just passed through. When the
6049-
format is ``None`` a choice is made about the style of the output.
6057+
format is ``None``, a choice is made about the style of the output.
60506058
If there is an algebraically closed field that will contain the
6051-
possible eigenvalues, then 'all" of the eigenspaces are given.
6059+
possible eigenvalues, then ``'all'`` of the eigenspaces are given.
60526060

60536061
However if this is not the case, then only one eigenspace is output
60546062
for each irreducible factor of the characteristic polynomial.
@@ -6100,48 +6108,48 @@ i sage: # needs sage.libs.pari
61006108
r"""
61016109
Compute the left eigenspaces of a matrix.
61026110

6103-
Note that ``eigenspaces_left()`` and ``left_eigenspaces()``
6111+
Note that :meth:`eigenspaces_left` and :meth:`left_eigenspaces`
61046112
are identical methods. Here "left" refers to the eigenvectors
61056113
being placed to the left of the matrix.
61066114

61076115
INPUT:
61086116

6109-
- ``self`` - a square matrix over an exact field. For inexact
6117+
- ``self`` -- a square matrix over an exact field. For inexact
61106118
matrices consult the numerical or symbolic matrix classes.
61116119

6112-
- ``format`` - default: ``None``
6120+
- ``format`` -- one of:
61136121

6114-
- ``'all'`` - attempts to create every eigenspace. This will
6122+
- ``'all'`` -- Attempts to create every eigenspace. This will
61156123
always be possible for matrices with rational entries.
6116-
- ``'galois'`` - for each irreducible factor of the characteristic
6124+
- ``'galois'`` -- For each irreducible factor of the characteristic
61176125
polynomial, a single eigenspace will be output for a
61186126
single root/eigenvalue for the irreducible factor.
6119-
- ``None`` - Uses the 'all' format if the base ring is contained
6127+
- ``None`` (default) -- Uses the ``'all'`` format if the base ring is contained
61206128
in an algebraically closed field which is implemented.
6121-
Otherwise, uses the 'galois' format.
6129+
Otherwise, uses the ``'galois'`` format.
61226130

6123-
- ``var`` - default: 'a' - variable name used to
6131+
- ``var`` -- string (default: ``'a'``); variable name used to
61246132
represent elements of the root field of each
61256133
irreducible factor of the characteristic polynomial.
6126-
If var='a', then the root fields will be in terms of
6127-
a0, a1, a2, ...., where the numbering runs across all
6134+
If ``var='a'``, then the root fields will be in terms of
6135+
``a0, a1, a2, ...``, where the numbering runs across all
61286136
the irreducible factors of the characteristic polynomial,
61296137
even for linear factors.
61306138

6131-
- ``algebraic_multiplicity`` - default: False - whether or
6132-
not to include the algebraic multiplicity of each eigenvalue
6139+
- ``algebraic_multiplicity`` -- (boolean, default: ``False``);
6140+
whether to include the algebraic multiplicity of each eigenvalue
61336141
in the output. See the discussion below.
61346142

61356143
OUTPUT:
61366144

6137-
If algebraic_multiplicity=False, return a list of pairs (e, V)
6138-
where e is an eigenvalue of the matrix, and V is the corresponding
6145+
If ``algebraic_multiplicity=False``, return a list of pairs `(e, V)`
6146+
where `e` is an eigenvalue of the matrix, and `V` is the corresponding
61396147
left eigenspace. For Galois conjugates of eigenvalues, there
61406148
may be just one representative eigenspace, depending on the
61416149
``format`` keyword.
61426150

6143-
If algebraic_multiplicity=True, return a list of triples (e, V, n)
6144-
where e and V are as above and n is the algebraic multiplicity of
6151+
If ``algebraic_multiplicity=True``, return a list of triples `(e, V, n)`
6152+
where `e` and `V` are as above and `n` is the algebraic multiplicity of
61456153
the eigenvalue.
61466154

61476155
.. warning::
@@ -6153,10 +6161,10 @@ i sage: # needs sage.libs.pari
61536161
EXAMPLES:
61546162

61556163
We compute the left eigenspaces of a `3\times 3`
6156-
rational matrix. First, we request `all` of the eigenvalues,
6157-
so the results are in the field of algebraic numbers, `QQbar`.
6164+
rational matrix. First, we request ``'all'`` of the eigenvalues,
6165+
so the results are in the field of algebraic numbers, ``QQbar``.
61586166
Then we request just one eigenspace per irreducible factor of
6159-
the characteristic polynomial with the `galois` keyword. ::
6167+
the characteristic polynomial with ``format='galois'``. ::
61606168

61616169
sage: A = matrix(QQ, 3, 3, range(9)); A
61626170
[0 1 2]
@@ -6349,15 +6357,15 @@ i sage: # needs sage.libs.pari
63496357
possible, will raise an error. Using the ``'galois'``
63506358
format option is more likely to be successful. ::
63516359

6352-
sage: F.<b> = FiniteField(11^2) # needs sage.rings.finite_rings
6353-
sage: A = matrix(F, [[b + 1, b + 1], [10*b + 4, 5*b + 4]]) # needs sage.rings.finite_rings
6354-
sage: A.eigenspaces_left(format='all') # needs sage.rings.finite_rings
6360+
sage: # needs sage.rings.finite_rings
6361+
sage: F.<b> = FiniteField(11^2)
6362+
sage: A = matrix(F, [[b + 1, b + 1], [10*b + 4, 5*b + 4]])
6363+
sage: A.eigenspaces_left(format='all')
63556364
Traceback (most recent call last):
63566365
...
63576366
NotImplementedError: unable to construct eigenspaces for eigenvalues outside the base field,
63586367
try the keyword option: format='galois'
6359-
6360-
sage: A.eigenspaces_left(format='galois') # needs sage.rings.finite_rings
6368+
sage: A.eigenspaces_left(format='galois')
63616369
[ (a0,
63626370
Vector space of degree 2 and dimension 1 over
63636371
Univariate Quotient Polynomial Ring in a0 over
@@ -6526,11 +6534,12 @@ i sage: # needs sage.libs.pari
65266534

65276535
We compute the right eigenspaces of a `3\times 3` rational matrix. ::
65286536

6537+
sage: # needs sage.rings.number_field
65296538
sage: A = matrix(QQ, 3, 3, range(9)); A
65306539
[0 1 2]
65316540
[3 4 5]
65326541
[6 7 8]
6533-
sage: A.eigenspaces_right() # needs sage.rings.number_field
6542+
sage: A.eigenspaces_right()
65346543
[ (0,
65356544
Vector space of degree 3 and dimension 1 over Rational Field
65366545
User basis matrix:
@@ -6543,7 +6552,7 @@ i sage: # needs sage.libs.pari
65436552
Vector space of degree 3 and dimension 1 over Algebraic Field
65446553
User basis matrix:
65456554
[ 1 3.069693845669907? 5.139387691339814?]) ]
6546-
sage: es = A.eigenspaces_right(format='galois'); es # needs sage.rings.number_field
6555+
sage: es = A.eigenspaces_right(format='galois'); es
65476556
[ (0,
65486557
Vector space of degree 3 and dimension 1 over Rational Field
65496558
User basis matrix:
@@ -6553,7 +6562,7 @@ i sage: # needs sage.libs.pari
65536562
Number Field in a1 with defining polynomial x^2 - 12*x - 18
65546563
User basis matrix:
65556564
[ 1 1/5*a1 + 2/5 2/5*a1 - 1/5]) ]
6556-
sage: es = A.eigenspaces_right(format='galois', # needs sage.rings.number_field
6565+
sage: es = A.eigenspaces_right(format='galois',
65576566
....: algebraic_multiplicity=True); es
65586567
[ (0,
65596568
Vector space of degree 3 and dimension 1 over Rational Field
@@ -6566,9 +6575,9 @@ i sage: # needs sage.libs.pari
65666575
User basis matrix:
65676576
[ 1 1/5*a1 + 2/5 2/5*a1 - 1/5],
65686577
1) ]
6569-
sage: e, v, n = es[0]; v = v.basis()[0] # needs sage.rings.number_field
6570-
sage: delta = v*e - A*v # needs sage.rings.number_field
6571-
sage: abs(abs(delta)) < 1e-10 # needs sage.rings.number_field
6578+
sage: e, v, n = es[0]; v = v.basis()[0]
6579+
sage: delta = v*e - A*v
6580+
sage: abs(abs(delta)) < 1e-10
65726581
True
65736582

65746583
The same computation, but with implicit base change to a field::
@@ -6600,11 +6609,12 @@ i sage: # needs sage.libs.pari
66006609
sage: B.eigenspaces_right()
66016610
Traceback (most recent call last):
66026611
...
6603-
NotImplementedError: eigenspaces cannot be computed reliably for inexact rings such as Real Field with 53 bits of precision,
6612+
NotImplementedError: eigenspaces cannot be computed reliably
6613+
for inexact rings such as Real Field with 53 bits of precision,
66046614
consult numerical or symbolic matrix classes for other options
66056615

66066616
sage: em = B.change_ring(RDF).eigenmatrix_right()
6607-
sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13
6617+
sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13
66086618
[13.348469228349522 0.0 0.0]
66096619
[ 0.0 -1.348469228349534 0.0]
66106620
[ 0.0 0.0 0.0]
@@ -6681,7 +6691,7 @@ i sage: # needs sage.libs.pari
66816691
then ``QQbar`` elements are returned that represent each separate
66826692
root.
66836693

6684-
If the option extend is set to False, only eigenvalues in the base
6694+
If the option ``extend`` is set to ``False``, only eigenvalues in the base
66856695
ring are considered.
66866696

66876697
EXAMPLES::
@@ -6734,12 +6744,12 @@ i sage: # needs sage.libs.pari
67346744

67356745
sage: e.as_number_field_element() # needs sage.rings.number_field
67366746
(Number Field in a
6737-
with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264,
6738-
a + 7,
6739-
Ring morphism:
6740-
From: Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264
6741-
To: Algebraic Real Field
6742-
Defn: a |--> -15.35066086057957?)
6747+
with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264,
6748+
a + 7,
6749+
Ring morphism:
6750+
From: Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264
6751+
To: Algebraic Real Field
6752+
Defn: a |--> -15.35066086057957?)
67436753

67446754
Notice the effect of the ``extend`` option.
67456755

@@ -6863,9 +6873,7 @@ i sage: # needs sage.libs.pari
68636873
(-1*I, [(1, -1*I, 0)], 1),
68646874
(1*I, [(1, 1*I, 0)], 1)]
68656875
sage: M.eigenvectors_left(extend=False) # needs sage.rings.number_field
6866-
[(2, [
6867-
(0, 0, 1)
6868-
], 1)]
6876+
[(2, [ (0, 0, 1) ], 1)]
68696877

68706878
TESTS::
68716879

@@ -6983,9 +6991,7 @@ i sage: # needs sage.libs.pari
69836991
(-1.348469228349535?, [(1, 0.1303061543300932?, -0.7393876913398137?)], 1),
69846992
(13.34846922834954?, [(1, 3.069693845669907?, 5.139387691339814?)], 1)]
69856993
sage: A.eigenvectors_right(extend=False)
6986-
[(0, [
6987-
(1, -2, 1)
6988-
], 1)]
6994+
[(0, [ (1, -2, 1) ], 1)]
69896995
sage: eval, [evec], mult = es[0]
69906996
sage: delta = eval*evec - A*evec
69916997
sage: abs(abs(delta)) < 1e-10
@@ -7137,7 +7143,7 @@ i sage: # needs sage.libs.pari
71377143

71387144
sage: A = matrix(QQ, 3, 3, range(9))
71397145
sage: em = A.change_ring(RDF).eigenmatrix_left()
7140-
sage: evalues = em[0]; evalues.dense_matrix() # abs tol 1e-13
7146+
sage: evalues = em[0]; evalues.dense_matrix() # abs tol 1e-13
71417147
[13.348469228349522 0.0 0.0]
71427148
[ 0.0 -1.348469228349534 0.0]
71437149
[ 0.0 0.0 0.0]
@@ -7409,8 +7415,8 @@ i sage: # needs sage.libs.pari
74097415
sage: M.eigenvalue_multiplicity(1)
74107416
0
74117417

7412-
sage: M = posets.DiamondPoset(5).coxeter_transformation() # needs sage.combinat
7413-
sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] # needs sage.combinat
7418+
sage: M = posets.DiamondPoset(5).coxeter_transformation() # needs sage.graphs
7419+
sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] # needs sage.graphs
74147420
[3, 2]
74157421

74167422
TESTS::
@@ -7517,7 +7523,8 @@ i sage: # needs sage.libs.pari
75177523
sage: C.echelon_form()
75187524
Traceback (most recent call last):
75197525
...
7520-
NotImplementedError: Ideal Ideal (2, x + 1) of Univariate Polynomial Ring in x over Integer Ring not principal
7526+
NotImplementedError: Ideal Ideal (2, x + 1) of Univariate
7527+
Polynomial Ring in x over Integer Ring not principal
75217528
Echelon form not implemented over 'Univariate Polynomial Ring in x over Integer Ring'.
75227529
sage: C = matrix(3,[2,x,x^2,x+1,3-x,-1,3,2,1/2])
75237530
sage: C.echelon_form()
@@ -7776,8 +7783,8 @@ i sage: # needs sage.libs.pari
77767783

77777784
Check that :trac:`34724` is fixed (indirect doctest)::
77787785

7779-
sage: a=6.12323399573677e-17
7780-
sage: m=matrix(RR,[[-a, -1.72508242466029], [ 0.579682446302195, a]])
7786+
sage: a = 6.12323399573677e-17
7787+
sage: m = matrix(RR,[[-a, -1.72508242466029], [ 0.579682446302195, a]])
77817788
sage: (~m*m).norm()
77827789
1.0
77837790
"""
@@ -18014,7 +18021,7 @@ def _generic_clear_column(m):
1801418021
sage: OL = L.ring_of_integers(); w = OL(w)
1801518022
sage: m = matrix(OL, 8, 4, [2*w - 2, 2*w + 1, -2, w, 2, -2, -2*w - 2, -2*w + 2, -w + 2, 2*w + 1, -w + 2, -w - 2, -2*w,
1801618023
....: 2*w, -w+ 2, w - 1, -2*w + 2, 2*w + 2, 2*w - 1, -w, 2*w + 2, -w + 2, 2, 2*w -1, w - 4, -2*w - 2, 2*w - 1, 0, 6, 7, 2*w + 1, 14])
18017-
sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest
18024+
sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest
1801818025
True
1801918026
sage: s[0]
1802018027
(w, 0, 0, 0)

0 commit comments

Comments
 (0)