On Jun 22, 2:53 pm, Franco Saliola <sali...@gmail.com> wrote: > Hello John, > > On Sat, Jun 19, 2010 at 11:45 PM, John H Palmieri > > <jhpalmier...@gmail.com> wrote: > > I have a simple example of a graded algebra with basis. Please take a > > look at > > > <http://trac.sagemath.org/sage_trac/ticket/9280>
> I have some comments on the interface for GradedAlgebraWithBasis. > > 1. Your choice of using ``A[n]`` to return the degree `n` piece of `A` is > not consistent with other "graded" algebras in Sage. And given the lack of formal development of graded objects in Sage, maybe now is the time to settle on a convention. > For example: > > sage: sf = SymmetricFunctions(QQ) > sage: s = sf.schur() > sage: s[3] > s[3] > > This returns an element of the algebra, and not the degree 3 homogoneous > component. I wrote "graded" because the algebra is indeed graded, but Sage > does not currently know about the grading. > > Personally, I strongly prefer the idea of using __getitem__ to access > elements of the algebra, by passing data to construct an element of the > indexing set. I really don't like to write > > sage: s.basis()(Partition([3])) > > to construct an element of the algebra. > > Instead, I suggest a method called homogeneous_component(n) that returns > the degree n component. (This should be generic and pushed up to every > GradedAlgebraWithBasis, and so you don't need to define it in your case. > It would also have the benefit of showing up in tab completion.) I would instead use _element_constructor_ to construct elements of the algebra, so you would call A(data) instead of A[data]. This is consistent with the coercion framework: you should use A(...) to construct elements of A. In mathematical notation, if I have a graded object M, then I would write M_n or M^n to get the graded pieces, so in Sage, M[n] seems like a reasonable approximation. If list[n] gives me the nth term of the list, it feels natural that M[n] should give me the nth homogeneous piece of a graded object. I happen to think that M[n] returning the nth homogeneous piece feels more natural than M[n] returning an element of M. In the case of an integer grading, there is also the possibility of implementing M[m:n] to return the sum of several graded pieces, or M[1:] or M[1:Infinity] to return the positively graded part. This notation just feels right to me. Does anyone else have an opinion? As far as tab completion goes, if we use __getitem__, then M.homogeneous_component(n) should be a synonym for M.__getitem__(n), and both usages should be discussed in the docstring. (By the way, if you want A[n] to return a element of the algebra, note that this construction doesn't show up in tab completion either.) > 2. I wonder if your method basis_in_degree should be merged with basis: if > no argument is specified, then default to the current behaviour (return a > basis of the algebra); otherwise, return a basis of the degree n component. That seems like a good idea, although the printing of bases when they're produced from infinite lazy families is perhaps less than ideal. We're overriding the basis method for a CombinatorialFreeModule, but I guess with no arguments it should return the old value, so it shouldn't break anything. > 3. Right now, you are starting with a DisjointUnionEnumeratedSets > constructed from a family: > > DisjointUnionEnumeratedSets(Family(NN, self._basis_fcn)) This choice was based on some discussions over the past few months in sage-algebra and sage-combinat-devel. I tried changing this to Family(NN, self._basis_fcn) and got some weird doctest errors about pickling, causing the TestSuite to fail. So while what you say makes sense, it causes problems for me. -- John -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-de...@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.