Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a Frequently Asked Question, under very various guises...

The problem is bound to the ambiguity in the uses of the word "variable" :

  • A Python variable is a label (technically some form of pointer) attached to some Python object.

  • A symbolic variable is a Python object behaving in Sage according to the properties of a mathematical variable in a symbolic expression.

Your first statement, u,t,x = var('u t x'), is, ultimately, a shortcut for:

u=SR.var("u")
t=SR.var("t")
x=SR.var("x")

The first statement is itself a shortcut for:

  • create a Python object representing a symbolic variable named "u"
  • create a label (a Python variable) named "u" attached to this Python object.

Your second statement, u[1]=x means "Assuming that the Python object pointed to by u is a list, store whatever the Python variable x points to in u's second element". Since the assumption that u is a list does not hold, the expression u[1] has no meaning, hence the Python interpreter's complaint...

This is explained in detail in ยง1.2 of this excellent book, whose reading and perusal is currently the best shortcut to Sage I'm aware of.