You might want to read

http://doc.sagemath.org/html/en/thematic_tutorials/coercion_and_categories.html#coercion-and-categories

I answer to your specific questions below.

On 19/06/16 21:08, Arpit Merchant wrote:


1 class MyElement(Element):
2       ...
3
4 class MyParent(Parent):
5        Element = MyElement
6
7        def __init__(self, ...):
8             ...
9             Parent.__init__(self, ...)

I'm not sure I understand what you mean. Could you please elaborate
a little?


The attribute `element_class` of parents is created during the parent
constructor, i.e. the __init__. It creates with dynamical inheritance a
new class "element_class" which will inherits new methods depending of
the category of your parent.

In order to work, there should be an attribute "Element" available (line 5
in the above snippet). Your
class `CenterSkewPolynomialRing` is a parent that modelizes a set. It
either inherits from Parent, or Ring or something similar. And the objects
that belong to it should inherit from Element or RingElement or something
similar.


Just to restate, MyParent here is CenterSkewPolynomialRing which inherits
from class PolynomialRing_general which inherits from
sage.algebras.algebra.Algebra. Indeed, the constructor of
CenterSkewPolynomialRing takes `element_class` as input (which by default,
is None).

What are you doing with this element_class from the input? The only reasonable thing would be

def __init__(self, element_class, ...):
     self.Element = element_class
     Algebra.__init__(self, ...)

But the name "element_class" is confusing because of the category/parent/element logic that takes the attribute Element to build a new attribute named element_class.

What does MyElement represent in your example? What is its connection to
MyParent?

In the context of PolynomialRing (as a parent) it would be Polynomial.

And since Element is itself a class, won't writing Element = MyElement give
a syntax error?

No. These belong to very different things. There is the Element class and here you are creating an attribute of a class named Element.

Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to