Ask Your Question
0

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

asked 2020-05-27 22:11:13 +0100

sal gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-28 05:20:16 +0100

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?

edit flag offensive delete link more

Comments

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.

sal gravatar imagesal ( 2020-05-28 12:13:11 +0100 )edit

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

sal gravatar imagesal ( 2020-05-28 12:15:35 +0100 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2020-05-30 06:27:12 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-05-27 22:11:13 +0100

Seen: 387 times

Last updated: May 28 '20