Ask Your Question

Revision history [back]

The function sage_input (sometimes) alows to get the Sage code to reconstruct an object you like.

sage: m = random_matrix(ZZ,3)
sage: m
[-1  1 -1]
[-2 -2 -1]
[ 1 -5  0]

The function sage_input (sometimes) alows to get the Sage code to reconstruct an object you like.

sage: m = random_matrix(ZZ,3)
sage: m
[-1  1 -1]
[-2 -2 -1]
[ 1 -5  0]

I like that one, how could i reconstruct it ?

sage: sage_input(m)
matrix(ZZ, [[-1, 1, -1], [-2, -2, -1], [1, -5, 0]])

sage: m == eval(str(sage_input(m)))
True

Another example:

sage: e = m.eigenvalues()[0]
sage: sage_input(e)

R.<x> = QQbar[]
QQbar.polynomial_root(AA.common_polynomial(x^3 + 3*x^2 + 8), CIF(RIF(-RR(3.6128878647175449), -RR(3.6128878647175444)), RIF(RR(0))))
sage: sage_input(e, preparse=False)

R = QQbar['x']
x = R.gen()
QQbar.polynomial_root(AA.common_polynomial(x**3 + 3*x**2 + 8), CIF(RIF(-RR(3.6128878647175449), -RR(3.6128878647175444)), RIF(RR(0))))