]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_element_subalgebra.py
eja: fix tests and pre-cache ranks.
[sage.d.git] / mjo / eja / eja_element_subalgebra.py
1 from sage.matrix.constructor import matrix
2
3 from mjo.eja.eja_subalgebra import FiniteDimensionalEuclideanJordanSubalgebra
4
5
6 class FiniteDimensionalEuclideanJordanElementSubalgebra(FiniteDimensionalEuclideanJordanSubalgebra):
7 def __init__(self, elt, orthonormalize_basis):
8 self._superalgebra = elt.parent()
9 category = self._superalgebra.category().Associative()
10 V = self._superalgebra.vector_space()
11 field = self._superalgebra.base_ring()
12
13 # This list is guaranteed to contain all independent powers,
14 # because it's the maximal set of powers that could possibly
15 # be independent (by a dimension argument).
16 powers = [ elt**k for k in range(V.dimension()) ]
17 power_vectors = [ p.to_vector() for p in powers ]
18 P = matrix(field, power_vectors)
19
20 if orthonormalize_basis == False:
21 # In this case, we just need to figure out which elements
22 # of the "powers" list are redundant... First compute the
23 # vector subspace spanned by the powers of the given
24 # element.
25
26 # Figure out which powers form a linearly-independent set.
27 ind_rows = P.pivot_rows()
28
29 # Pick those out of the list of all powers.
30 superalgebra_basis = tuple(map(powers.__getitem__, ind_rows))
31
32 # If our superalgebra is a subalgebra of something else, then
33 # these vectors won't have the right coordinates for
34 # V.span_of_basis() unless we use V.from_vector() on them.
35 basis_vectors = map(power_vectors.__getitem__, ind_rows)
36 else:
37 # If we're going to orthonormalize the basis anyway, we
38 # might as well just do Gram-Schmidt on the whole list of
39 # powers. The redundant ones will get zero'd out. If this
40 # looks like a roundabout way to orthonormalize, it is.
41 # But converting everything from algebra elements to vectors
42 # to matrices and then back again turns out to be about
43 # as fast as reimplementing our own Gram-Schmidt that
44 # works in an EJA.
45 G,_ = P.gram_schmidt(orthonormal=True)
46 basis_vectors = [ g for g in G.rows() if not g.is_zero() ]
47 superalgebra_basis = [ self._superalgebra.from_vector(b)
48 for b in basis_vectors ]
49
50 W = V.span_of_basis( V.from_vector(v) for v in basis_vectors )
51
52 fdeja = super(FiniteDimensionalEuclideanJordanElementSubalgebra, self)
53 fdeja.__init__(self._superalgebra,
54 superalgebra_basis,
55 category=category)
56
57 # The rank is the highest possible degree of a minimal
58 # polynomial, and is bounded above by the dimension. We know
59 # in this case that there's an element whose minimal
60 # polynomial has the same degree as the space's dimension
61 # (remember how we constructed the space?), so that must be
62 # its rank too.
63 self.rank.set_cache(W.dimension())
64
65
66 def _a_regular_element(self):
67 """
68 Override the superalgebra method to return the one
69 regular element that is sure to exist in this
70 subalgebra, namely the element that generated it.
71
72 SETUP::
73
74 sage: from mjo.eja.eja_algebra import random_eja
75
76 TESTS::
77
78 sage: set_random_seed()
79 sage: J = random_eja().random_element().subalgebra_generated_by()
80 sage: J._a_regular_element().is_regular()
81 True
82
83 """
84 if self.dimension() == 0:
85 return self.zero()
86 else:
87 return self.monomial(1)
88
89
90 def one(self):
91 """
92 Return the multiplicative identity element of this algebra.
93
94 The superclass method computes the identity element, which is
95 beyond overkill in this case: the superalgebra identity
96 restricted to this algebra is its identity. Note that we can't
97 count on the first basis element being the identity -- it migth
98 have been scaled if we orthonormalized the basis.
99
100 SETUP::
101
102 sage: from mjo.eja.eja_algebra import (HadamardEJA,
103 ....: random_eja)
104
105 EXAMPLES::
106
107 sage: J = HadamardEJA(5)
108 sage: J.one()
109 e0 + e1 + e2 + e3 + e4
110 sage: x = sum(J.gens())
111 sage: A = x.subalgebra_generated_by()
112 sage: A.one()
113 f0
114 sage: A.one().superalgebra_element()
115 e0 + e1 + e2 + e3 + e4
116
117 TESTS:
118
119 The identity element acts like the identity over the rationals::
120
121 sage: set_random_seed()
122 sage: x = random_eja(field=QQ).random_element()
123 sage: A = x.subalgebra_generated_by()
124 sage: x = A.random_element()
125 sage: A.one()*x == x and x*A.one() == x
126 True
127
128 The identity element acts like the identity over the algebraic
129 reals with an orthonormal basis::
130
131 sage: set_random_seed()
132 sage: x = random_eja().random_element()
133 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
134 sage: x = A.random_element()
135 sage: A.one()*x == x and x*A.one() == x
136 True
137
138 The matrix of the unit element's operator is the identity over
139 the rationals::
140
141 sage: set_random_seed()
142 sage: x = random_eja(field=QQ).random_element()
143 sage: A = x.subalgebra_generated_by()
144 sage: actual = A.one().operator().matrix()
145 sage: expected = matrix.identity(A.base_ring(), A.dimension())
146 sage: actual == expected
147 True
148
149 The matrix of the unit element's operator is the identity over
150 the algebraic reals with an orthonormal basis::
151
152 sage: set_random_seed()
153 sage: x = random_eja().random_element()
154 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
155 sage: actual = A.one().operator().matrix()
156 sage: expected = matrix.identity(A.base_ring(), A.dimension())
157 sage: actual == expected
158 True
159
160 """
161 if self.dimension() == 0:
162 return self.zero()
163 else:
164 sa_one = self.superalgebra().one().to_vector()
165 # The extra hackery is because foo.to_vector() might not
166 # live in foo.parent().vector_space()!
167 coords = sum( a*b for (a,b)
168 in zip(sa_one,
169 self.superalgebra().vector_space().basis()) )
170 return self.from_vector(self.vector_space().coordinate_vector(coords))
171