ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 04 Aug 2011 13:08:25 -0500using inheritance to create a new Parent classhttp://ask.sagemath.org/question/8258/using-inheritance-to-create-a-new-parent-class/I have an algebra (and a group as well) I would like to represent in Sage. In fact, the code for doing this is already written, but the structures do not inherit from any existing Sage structures, and lately I have also been finding bugs in the algebraic manipulations. I would like to make this code compatible with the larger Sage framework by correctly using inheritance. I found this article: http://flask.sagenb.org/home/pub/82/, from which I understand that there is a way to inherit from a generic "algebra" parent and thus get a lot of bug-free structure. My problem is that this article discusses only the specific example of a field, and I don't know where to begin with my algebra. In particular, the article says, "When implementing a parent in Sage, one should start with a class that inherits from :class:`sage.structure.parent.Parent`," - where can I find a list of such classes? The example inherits from the derived class "sage.rings.field.Field". I do not know where to find the class analogous to this for algebras (or groups). I also need lots of documentation explaining what the algebra (and group) parent comes with.
Thank you!Wed, 03 Aug 2011 08:44:42 -0500http://ask.sagemath.org/question/8258/using-inheritance-to-create-a-new-parent-class/Answer by John Palmieri for <p>I have an algebra (and a group as well) I would like to represent in Sage. In fact, the code for doing this is already written, but the structures do not inherit from any existing Sage structures, and lately I have also been finding bugs in the algebraic manipulations. I would like to make this code compatible with the larger Sage framework by correctly using inheritance. I found this article: <a href="http://flask.sagenb.org/home/pub/82/">http://flask.sagenb.org/home/pub/82/</a>, from which I understand that there is a way to inherit from a generic "algebra" parent and thus get a lot of bug-free structure. My problem is that this article discusses only the specific example of a field, and I don't know where to begin with my algebra. In particular, the article says, "When implementing a parent in Sage, one should start with a class that inherits from :class:<code>sage.structure.parent.Parent</code>," - where can I find a list of such classes? The example inherits from the derived class "sage.rings.field.Field". I do not know where to find the class analogous to this for algebras (or groups). I also need lots of documentation explaining what the algebra (and group) parent comes with.</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/8258/using-inheritance-to-create-a-new-parent-class/?answer=12557#post-id-12557The best thing to do is to use the source. The group algebra of a group is implemented nicely in `SAGE_ROOT/devel/sage/sage/categories/examples/hopf_algebras_with_basis.py`, in a way which works well with inheritance and the category structure in Sage. See also the patches at [http://trac.sagemath.org/sage_trac/ticket/6670](http://trac.sagemath.org/sage_trac/ticket/6670), for a very similar implementation, but one which also implements coercion.
This implementation doesn't inherit from a generic algebra structure, but instead from `CombinatorialFreeModule` (an implementation of free modules which is well suited to incorporating algebraic structures), and then sets the category appropriately, which helps to automatically implement some structure.
The patches at [http://trac.sagemath.org/sage_trac/ticket/10052](http://trac.sagemath.org/sage_trac/ticket/10052) (merged into prerelease versions of Sage 4.7.1) does something similar to implement the Steenrod algebra and its sub-Hopf algebras.Thu, 04 Aug 2011 13:08:25 -0500http://ask.sagemath.org/question/8258/using-inheritance-to-create-a-new-parent-class/?answer=12557#post-id-12557