# what is the equivalent function of mathematica's FullForm in Sage?

i'm trying to find the internal representation of matrices in sage. In Mathematica we can simply use FullForm, and this will show that matrices are internally lists in Mathematica. But i could not find any function that does the same in Sage!

edit retag close merge delete

Sort by » oldest newest most voted There is no single "internal representation". If a matrix is sparse, then its entries are represented by a dictionary. If not, its entries are a list. You can get either as follows:

sage: m = matrix(2,2, {(1,1): 3})
sage: m.is_sparse()
True
sage: m.dict()
{(1, 1): 3}
sage: m.list()
[0, 0, 0, 3]

sage: m = matrix(2,2, [1,2,3,4])
sage: m.is_sparse()
False
sage: m.dict()
{(0, 0): 1, (0, 1): 2, (1, 0): 3, (1, 1): 4}
sage: m.list()
[1, 2, 3, 4]


Is there something particular you are trying to do?

more

I have a homework assignment, where i'm asked to find how certain objects (e.g. matrices) are represented in a CAS. The question is of course a general question and can be solved in other CASs, but since i'm already comfortable with Sage i tried to solve this question using Sage. To make the question clear i will give an example for the internal structure of x - y + z, where x,y,z are all variables, i.e var(x y z).

etb = ExpressionTreeBuilder(vars=('x','y','z')
x = etb.var('x')
y = etb.var('y')
z = etb.var('z')

v = x - y + z

print(v)


for this code you get something like: add(sub(v_0,v_1),v_2). This shows how a symbolic expression like x -y +z is represented in Sage, and i'm trying to do the same for matrices, but it did not work so far.

If you use the FullForm function in Mathematica, for example on the matrix {{1, 1},{2, 3}} you will get: List[List[1,1],List[2,3]]

As I said, there is no single internal representation: it depends on whether the matrix is dense or sparse. So what are you hoping for? Probably the best way to understand internal representations for Sage matrices is to read the source code: https://git.sagemath.org/sage.git/tre..., and for example https://git.sagemath.org/sage.git/tre...