Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Print symbolic variables like a_1 in A[1] style

Because of Sagemath's problem with symbolic arrays, I have defined my vectors like this:

A =[0 for j in range(4)]
for j in range(4):
    A[j]=var('a_'+str(j))

I have some symbolic variables stored in another variable. Lets say I have a subroutine that works with A[i] and in the end, L becomes something such as: L=a_1+a_2*a_3. When I print L, I want to have it printed in the original vector format. So when I type L or print(L) in a cell and press enter, my desired output is A[1]+A[2]*A[3] and not a_1+a_2*a_3. I want this type of output because I am transferring SageMath outputs to C where I employ indexed arrays. How can I achieve this?