# Symbolic expression not scriptable in Solve

This is a follow-up to

The answer by @slelievre to that question works nicely, but I need to use indexed variables.

This variation of the code does not work for me:

D = polytopes.dodecahedron()
DH = D.Hrepresentation()
X = list(SR.var('x_%i' % i) for i in (0..2))
Ineq = [[el.A()*vector(X) >=el.b()] for el in DH]
show(Ineq[0][0])
sol = [solve(Ineq[i][0], x[1]) for i in range(len(Ineq))]


raising an error saying

'sage.symbolic.expression.Expression' object is not subscriptable


Why? the problem doesn't seem to come from Ineq[0][0] but from the variables?

edit retag close merge delete

Sort by ยป oldest newest most voted

Does changing x to X solve your problem? Namely,

sol = [solve(Ineq[i][0], X[1]) for i in range(len(Ineq))]

more

Having named X the list [x_0, x_1, x_2], use X[1] and not x[1] to get x_1.

Or, maybe even better, call that list x rather than X.

Also beware that the A and b of polytopes inequalities are for A x + b >= 0, not A x >= b.

Finally, take advantage of Python's iteration by values and change

sol = [solve(Ineq[i][0], x[1]) for i in range(len(Ineq))]


into the lighter

sol = [solve(ieq[0], x[1]) for ieq in Ineq]

more