2
$\begingroup$

We can Solve for expressions that match _Symbol, as in Solve[x^2+1 == 0, x]—but we can also solve for more general expressions, such as x[1] (Solve[x[1]^2+1 == 0, x[1]]) and Subscripts (Solve[Subscript[x, 1]^2+1 == 0, Subscript[x, 1]]). However, not every expression can be a variable for Solve: Solve["a"^2+1 == 0, "a"] returns the Solve::ivar error message, saying that "a" is not a valid variable.

So, what makes an expression a "valid variable" in the sense of Solve internally?

Is it related to what expressions can hold definitions, or is that a separate question?

A workaround can be obtained, in a similar manner to this question, by testing a simple Solve for the error message directly:

VariableQ[expr_] := 
 Quiet[Check[Solve[True, expr]; True, False, {Solve::ivar}], {Solve::ivar}]

but I'd like to understand the logic behind what is or isn't a valid variable.

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.