Ask Your Question

Revision history [back]

The issue is that there is a difference between variables and "symbolic variables". A variable is a string of letters used to store some value. Every programming language has them. A "symbolic variable" is a Sage object that can be manipulated in certain ways. Just like other Sage objects, symbolic variables can be referenced by variable names. When you type var('beta'), Sage defines a new symbolic variable whose name is beta, and also defines a new standard variable, also named beta, and makes the standard variable reference the symbolic variable.

But here's the issue: You can later change this standard variable to refer to some other Sage object. And that's what you're doing when you write beta = 1.

When you defined eq, you were using the earlier object (that is, the symbolic variable) stored in the standard variable beta. Storing something new with the name beta doesn't change this.

Here's another example where I first use the variable B to store the value 1, then use it to define an equation, and then store a new value in that variable. Doing so doesn't change the equation.

sage: B = 1
sage: eq = x == B    
sage: eq
x == 1
sage: B = 2
sage: eq
x == 1

Incidentally, this is why the "dictionary approach" in the previous answer doesn't work: The dictionary being used in that case is equivalent to {1:1}, and it's key doesn't match any of the symbolic variables in the equation.