1 from sage
.matrix
.constructor
import matrix
2 from sage
.rings
.all
import QQ
4 from mjo
.eja
.eja_subalgebra
import FiniteDimensionalEuclideanJordanSubalgebra
7 class FiniteDimensionalEuclideanJordanElementSubalgebra(FiniteDimensionalEuclideanJordanSubalgebra
):
8 def __init__(self
, elt
, orthonormalize_basis
):
9 self
._superalgebra
= elt
.parent()
10 category
= self
._superalgebra
.category().Associative()
11 V
= self
._superalgebra
.vector_space()
12 field
= self
._superalgebra
.base_ring()
14 # This list is guaranteed to contain all independent powers,
15 # because it's the maximal set of powers that could possibly
16 # be independent (by a dimension argument).
17 powers
= [ elt
**k
for k
in range(V
.dimension()) ]
18 power_vectors
= [ p
.to_vector() for p
in powers
]
19 P
= matrix(field
, power_vectors
)
21 if orthonormalize_basis
== False:
22 # Echelonize the matrix ourselves, because otherwise the
23 # call to P.pivot_rows() below can choose a non-optimal
24 # row-reduction algorithm. In particular, scaling can
25 # help over AA because it avoids the RecursionError that
26 # gets thrown when we have to look too hard for a root.
28 # Beware: QQ supports an entirely different set of "algorithm"
29 # keywords than do AA and RR.
32 algo
= "scaled_partial_pivoting"
33 P
.echelonize(algorithm
=algo
)
35 # In this case, we just need to figure out which elements
36 # of the "powers" list are redundant... First compute the
37 # vector subspace spanned by the powers of the given
40 # Figure out which powers form a linearly-independent set.
41 ind_rows
= P
.pivot_rows()
43 # Pick those out of the list of all powers.
44 superalgebra_basis
= tuple(map(powers
.__getitem
__, ind_rows
))
45 basis_vectors
= map(power_vectors
.__getitem
__, ind_rows
)
47 # If we're going to orthonormalize the basis anyway, we
48 # might as well just do Gram-Schmidt on the whole list of
49 # powers. The redundant ones will get zero'd out. If this
50 # looks like a roundabout way to orthonormalize, it is.
51 # But converting everything from algebra elements to vectors
52 # to matrices and then back again turns out to be about
53 # as fast as reimplementing our own Gram-Schmidt that
55 G
,_
= P
.gram_schmidt(orthonormal
=True)
56 basis_vectors
= [ g
for g
in G
.rows() if not g
.is_zero() ]
57 superalgebra_basis
= [ self
._superalgebra
.from_vector(b
)
58 for b
in basis_vectors
]
60 fdeja
= super(FiniteDimensionalEuclideanJordanElementSubalgebra
, self
)
61 fdeja
.__init
__(self
._superalgebra
,
66 # The rank is the highest possible degree of a minimal
67 # polynomial, and is bounded above by the dimension. We know
68 # in this case that there's an element whose minimal
69 # polynomial has the same degree as the space's dimension
70 # (remember how we constructed the space?), so that must be
72 self
.rank
.set_cache(self
.dimension())
77 Return the multiplicative identity element of this algebra.
79 The superclass method computes the identity element, which is
80 beyond overkill in this case: the superalgebra identity
81 restricted to this algebra is its identity. Note that we can't
82 count on the first basis element being the identity -- it migth
83 have been scaled if we orthonormalized the basis.
87 sage: from mjo.eja.eja_algebra import (HadamardEJA,
92 sage: J = HadamardEJA(5)
94 e0 + e1 + e2 + e3 + e4
95 sage: x = sum(J.gens())
96 sage: A = x.subalgebra_generated_by()
99 sage: A.one().superalgebra_element()
100 e0 + e1 + e2 + e3 + e4
104 The identity element acts like the identity over the rationals::
106 sage: set_random_seed()
107 sage: x = random_eja(field=QQ).random_element()
108 sage: A = x.subalgebra_generated_by()
109 sage: x = A.random_element()
110 sage: A.one()*x == x and x*A.one() == x
113 The identity element acts like the identity over the algebraic
114 reals with an orthonormal basis::
116 sage: set_random_seed()
117 sage: x = random_eja().random_element()
118 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
119 sage: x = A.random_element()
120 sage: A.one()*x == x and x*A.one() == x
123 The matrix of the unit element's operator is the identity over
126 sage: set_random_seed()
127 sage: x = random_eja(field=QQ).random_element()
128 sage: A = x.subalgebra_generated_by()
129 sage: actual = A.one().operator().matrix()
130 sage: expected = matrix.identity(A.base_ring(), A.dimension())
131 sage: actual == expected
134 The matrix of the unit element's operator is the identity over
135 the algebraic reals with an orthonormal basis::
137 sage: set_random_seed()
138 sage: x = random_eja().random_element()
139 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
140 sage: actual = A.one().operator().matrix()
141 sage: expected = matrix.identity(A.base_ring(), A.dimension())
142 sage: actual == expected
146 if self
.dimension() == 0:
149 sa_one
= self
.superalgebra().one().to_vector()
150 # The extra hackery is because foo.to_vector() might not
151 # live in foo.parent().vector_space()!
152 coords
= sum( a
*b
for (a
,b
)
154 self
.superalgebra().vector_space().basis()) )
155 return self
.from_vector(self
.vector_space().coordinate_vector(coords
))