is it possible to have Sage always print the parent of the object, when it's
printed, as FriCAS does it?
(1) -> 3/2
3
(1) -
2
Type: Fraction(Integer)
(2) -> x^2+1
2
(2) x + 1
Type: Polynomial(Integer)
(3) -> integrate(x^2+1,x)
1 3
(3) - x + x
3
Type: Polynomial(Fraction(Integer))
(4) -> matrix [[1,2,3],[a, b, c]]
+1 2 3+
(4) | |
+a b c+
Type: Matrix(Polynomial(Integer))
On Tue, Sep 30, 2008 at 1:18 AM, Martin Rubey <martin...@univie.ac.at> wrote:
>
> Dear all,
>
> is it possible to have Sage always print the parent of the object, when it's
> printed, as FriCAS does it?
Sure, you just have to add a hook into IPython. For example, you can
add the following to your ~/.sage/init.sage and it will be loaded up
on every startup.
from IPython import ipapi
from IPython.genutils import Term
def repr_and_parent(self, arg):
if hasattr(arg, 'parent'):
try:
print >>Term.cout, "%s\n\nParent: %s"%(repr(arg),
repr(arg.parent()))
return
except:
pass
raise ipapi.TryNext
ipapi.get().set_hook("result_display", repr_and_parent)
After that, we get the following behavior:
sage: 2/3
2/3
Parent: Rational Field
sage: matrix([[1,2],[3,4]])
[1 2]
[3 4]
Parent: Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
--Mike