]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/eja/eja_element_subalgebra.py
73e1cbd9ab34ce1078c6ebaeaade3cc87d3d9448
[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 check_axioms=False)
57
58 # The rank is the highest possible degree of a minimal
59 # polynomial, and is bounded above by the dimension. We know
60 # in this case that there's an element whose minimal
61 # polynomial has the same degree as the space's dimension
62 # (remember how we constructed the space?), so that must be
63 # its rank too.
64 self.rank.set_cache(W.dimension())
65
66
67 def one(self):
68 """
69 Return the multiplicative identity element of this algebra.
70
71 The superclass method computes the identity element, which is
72 beyond overkill in this case: the superalgebra identity
73 restricted to this algebra is its identity. Note that we can't
74 count on the first basis element being the identity -- it migth
75 have been scaled if we orthonormalized the basis.
76
77 SETUP::
78
79 sage: from mjo.eja.eja_algebra import (HadamardEJA,
80 ....: random_eja)
81
82 EXAMPLES::
83
84 sage: J = HadamardEJA(5)
85 sage: J.one()
86 e0 + e1 + e2 + e3 + e4
87 sage: x = sum(J.gens())
88 sage: A = x.subalgebra_generated_by()
89 sage: A.one()
90 f0
91 sage: A.one().superalgebra_element()
92 e0 + e1 + e2 + e3 + e4
93
94 TESTS:
95
96 The identity element acts like the identity over the rationals::
97
98 sage: set_random_seed()
99 sage: x = random_eja(field=QQ).random_element()
100 sage: A = x.subalgebra_generated_by()
101 sage: x = A.random_element()
102 sage: A.one()*x == x and x*A.one() == x
103 True
104
105 The identity element acts like the identity over the algebraic
106 reals with an orthonormal basis::
107
108 sage: set_random_seed()
109 sage: x = random_eja().random_element()
110 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
111 sage: x = A.random_element()
112 sage: A.one()*x == x and x*A.one() == x
113 True
114
115 The matrix of the unit element's operator is the identity over
116 the rationals::
117
118 sage: set_random_seed()
119 sage: x = random_eja(field=QQ).random_element()
120 sage: A = x.subalgebra_generated_by()
121 sage: actual = A.one().operator().matrix()
122 sage: expected = matrix.identity(A.base_ring(), A.dimension())
123 sage: actual == expected
124 True
125
126 The matrix of the unit element's operator is the identity over
127 the algebraic reals with an orthonormal basis::
128
129 sage: set_random_seed()
130 sage: x = random_eja().random_element()
131 sage: A = x.subalgebra_generated_by(orthonormalize_basis=True)
132 sage: actual = A.one().operator().matrix()
133 sage: expected = matrix.identity(A.base_ring(), A.dimension())
134 sage: actual == expected
135 True
136
137 """
138 if self.dimension() == 0:
139 return self.zero()
140 else:
141 sa_one = self.superalgebra().one().to_vector()
142 # The extra hackery is because foo.to_vector() might not
143 # live in foo.parent().vector_space()!
144 coords = sum( a*b for (a,b)
145 in zip(sa_one,
146 self.superalgebra().vector_space().basis()) )
147 return self.from_vector(self.vector_space().coordinate_vector(coords))
148