Ask Your Question
2

Create new structure class and define its element

asked 2014-09-22 20:01:59 +0100

anto gravatar image

Hello. I have a problem with the Element class of a new structure. In detail, I am defining a new subclass of Polynomial Ring via

class MyElement(sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict):
      pass

class MyAlgebra(sage.structure.unique_representation.UniqueRepresentation, sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict):
         Element=MyElement

Now, I have:

sage: A=MyAlgebra(QQ,1,'x',order="lex")
sage: (x,)=A.gens()
sage: type(x)
<class 'sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict'>

While:

sage: a=MyElement(A,{(1,):1})
sage: type(a)
<class '__main__.MyElement'>

Why isn't the element x of type MyElement?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-09-24 12:58:40 +0100

Volker Braun gravatar image

The rule in Sage is to always use A.element_class, and never the original element class MyElement. In fact, they are not the same:

sage: a = A.element_class(A,{(1,):1})
sage: a
x
sage: type(a)
<class '__main__.MyAlgebra_with_category.element_class'>

This is how the category framework operates. Polynomial algebra is also optimized a lot, so its not the easiest part in Sage to understand (sorry). To construct the correct kind of polynomials you also need to override

class MyAlgebra(sage.structure.unique_representation.UniqueRepresentation, sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict):
         Element=MyElement
         def _poly_class(self):
             return self.element_class
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-09-22 20:01:59 +0100

Seen: 618 times

Last updated: Sep 24 '14