# Revision history [back]

As far as I can tell, this error message has nothing to do with solve. (See below for that issue, though.)

sage: R = PolynomialRing(RR,['a','b','c','d'])
sage: S = matrix(R,2,R.gens())
sage: S
[a b]
[c d]
sage: a
---------------------------------------------------------------------------
NameError: name 'a' is not defined


If you do PolynomialRing? then you'll see

      Use the diamond brackets notation to make the variable ready for
use after you define the ring:


So it looks like instead that this is just unsupported behavior that you are trying to do. I'm not sure exactly why it's not supported, but it's not.

sage: PolynomialRing(QQ, 'w')
Univariate Polynomial Ring in w over Rational Field
sage: w
---------------------------------------------------------------------------
NameError: name 'w' is not defined
sage:              sage: R.<w> = PolynomialRing(QQ)
sage: w
w


Now, we still run into problems even after we do the "right" thing.

sage: R.<a,b,c,d> = PolynomialRing(RR)
sage: R
Multivariate Polynomial Ring in a, b, c, d over Real Field with 53 bits of precision
sage: a
a
sage: S = matrix(R,2,R.gens())
sage: S
[a b]
[c d]
sage: solve([S[0][0]==S[0][1],S[1][0]==S[1][1]],[a,b])
---------------------------------------------------------------------------
TypeError: a is not a valid variable.


This is a workaround:

sage: solve([SR(S[0][0]==S[0][1]),SR(S[1][0]==S[1][1])],[SR(a),SR(b)])
[[a == r2, b == r1]]


But the code in the error above pretty clearly shows that we need symbolic variables. To make this code more concise for more complicated situations, you could do

sage: list1 = [S[0][0]==S[0][1],S[1][0]==S[1][1]]
sage: list2 = [a,b]
sage: solve( [ SR(w) for w in list1], [ SR(z) for z in list2])
[[a == r4, b == r3]]


and that preserves the type of a and friends...

As far as I can tell, this error message has nothing to do with solve. (See below for that issue, though.)

sage: R = PolynomialRing(RR,['a','b','c','d'])
sage: S = matrix(R,2,R.gens())
sage: S
[a b]
[c d]
sage: a
---------------------------------------------------------------------------
NameError: name 'a' is not defined


If you do PolynomialRing? (see also the official doc) then you'll see

      Use the diamond brackets notation to make the variable ready for
use after you define the ring:


So it looks like instead that this is just unsupported behavior that you are trying to do. I'm not sure exactly why it's not supported, but it's not.

sage: PolynomialRing(QQ, 'w')
Univariate Polynomial Ring in w over Rational Field
sage: w
---------------------------------------------------------------------------
NameError: name 'w' is not defined
sage:              sage: R.<w> = PolynomialRing(QQ)
sage: w
w


Now, we still run into problems even after we do the "right" thing.

sage: R.<a,b,c,d> = PolynomialRing(RR)
sage: R
Multivariate Polynomial Ring in a, b, c, d over Real Field with 53 bits of precision
sage: a
a
sage: S = matrix(R,2,R.gens())
sage: S
[a b]
[c d]
sage: solve([S[0][0]==S[0][1],S[1][0]==S[1][1]],[a,b])
---------------------------------------------------------------------------
TypeError: a is not a valid variable.


This is a workaround:

sage: solve([SR(S[0][0]==S[0][1]),SR(S[1][0]==S[1][1])],[SR(a),SR(b)])
[[a == r2, b == r1]]


But the code in the error above pretty clearly shows that we need symbolic variables. To make this code more concise for more complicated situations, you could do

sage: list1 = [S[0][0]==S[0][1],S[1][0]==S[1][1]]
sage: list2 = [a,b]
sage: solve( [ SR(w) for w in list1], [ SR(z) for z in list2])
[[a == r4, b == r3]]


and that preserves the type of a and friends...