Ask Your Question

anto's profile - activity

2021-03-24 17:28:47 +0200 received badge  Famous Question (source)
2016-08-06 16:42:16 +0200 received badge  Good Question (source)
2016-08-06 16:42:08 +0200 received badge  Notable Question (source)
2014-09-23 12:10:00 +0200 received badge  Nice Question (source)
2014-09-22 20:01:59 +0200 asked a question Create new structure class and define its element

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):

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

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'>


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

Why isn't the element x of type MyElement?

2014-04-25 00:15:11 +0200 received badge  Popular Question (source)
2013-02-25 07:43:13 +0200 received badge  Nice Question (source)
2013-02-24 22:02:17 +0200 received badge  Student (source)
2013-02-24 12:10:28 +0200 received badge  Editor (source)
2013-02-24 12:03:22 +0200 asked a question How are list of matrices printed by sage?

If I construct a list of matrices and let sage print it, the matrices are (correctly) aligned on the top:

sage: A=matrix([[1,2],[3,4]])
sage: [A,A]
[1 2]  [1 2]
[3 4], [3 4]

Howewer, this is not the output of the __repr__ function of a list: compare:

sage: print [A,A].__repr__()
[[1 2]
[3 4], [1 2]
[3 4]]

I would like to construct an object whose output is on more than one lines (like a matrix), and I would like a list of these objects to be printed aligned on the top (like with the matrices in the first example above). How can I do that?