Ask Your Question

anto's profile - activity

2024-02-11 06:51:11 +0100 received badge  Notable Question (source)
2024-02-11 06:51:11 +0100 received badge  Popular Question (source)
2021-03-24 17:28:47 +0100 received badge  Famous Question (source)
2016-08-06 16:42:16 +0100 received badge  Good Question (source)
2016-08-06 16:42:08 +0100 received badge  Notable Question (source)
2014-09-23 12:10:00 +0100 received badge  Nice Question (source)
2014-09-22 20:01:59 +0100 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):
      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?

2014-04-25 00:15:11 +0100 received badge  Popular Question (source)
2013-02-25 07:43:13 +0100 received badge  Nice Question (source)
2013-02-24 22:02:17 +0100 received badge  Student (source)
2013-02-24 12:10:28 +0100 received badge  Editor (source)
2013-02-24 12:03:22 +0100 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?