# TypeError: 'sage.symbolic.expression.Expression' object is not subscriptable

I obtain the error "TypeError: 'sage.symbolic.expression.Expression' object is not subscriptable" when using the following script:

var('L, eta, theta, w')
assume(0<L, L<1, 1 <= eta, eta<4,  0 <= theta, theta <= pi/2)
assume(-2<= w, w<= 2)
a = L*(eta-1/eta)^2*sin(theta)^2;
b = -(eta+1/eta)^2 * sin(theta)^2 + 2*eta^2 + 4*sqrt(eta^2-sin(theta)^2)*cos(theta)+2
c = 2*(1-L)*sqrt(eta^2-sin(theta)^2)*cos(theta)*sin(theta)^2;
d = 2*( 1 - cos(theta)^2)^2 -(eta^2+1)*sin(theta)^2 + eta^2
ss = a/b - c/d
solve(ss == w, theta, solution_dict = True, to_poly_solve=True)


And I obtain the following traceback (whatever the values of to_poly_solve and solution_dict are):

File ~/anaconda3/lib/python3.11/site-packages/sage/symbolic/relation.py:1068, in solve(f, *args, **kwds)
1063         raise TypeError("The first argument to solve() should be a "
1064                         "symbolic expression or a list of symbolic "
1065                         "expressions.")
1067 if isinstance(f, Expression):  # f is a single expression
-> 1068     return _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
1070 if not isinstance(f, (list, tuple)):
1071     raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")

File ~/anaconda3/lib/python3.11/site-packages/sage/symbolic/relation.py:1392, in _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
1390     s = m.to_poly_solve(x, options='algexact:true')
1391     T = string_to_list_of_solutions(repr(s))
-> 1392     X.extend([t[0] for t in T])
1393 except TypeError as mess:
1394     if ignore_exceptions:

File ~/anaconda3/lib/python3.11/site-packages/sage/symbolic/relation.py:1392, in <listcomp>(.0)
1390     s = m.to_poly_solve(x, options='algexact:true')
1391     T = string_to_list_of_solutions(repr(s))
-> 1392     X.extend([t[0] for t in T])
1393 except TypeError as mess:
1394     if ignore_exceptions:

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


If anyone has some input on the matter, it will be greatly appreciated.

edit retag close merge delete

On 10.4.beta9, I don't get your error ; Sage returns a pair of implicit solution, unless you pass to_poly_solve=="force", which returns an empty list.