Solve and other functions such as FindInstance, NSolve, and NDSolve return a list of rules. In the Wolfram Language, rules associate symbols with values. For example, consider the output of:
The output is a list of lists of rules. Each sublist represents a possible value of x. To look at the first solution as a rule, we can run:
The symbol is
x, and its value is
- 2 - Sqrt. The ReplaceAll command ( /. ) replaces every instance of the symbol with a value according to a rule. For example, if we want to replace all instances of
x in the polynomial
x^2 + 4 x - 1 with the first root of the polynomial above, we could write:
This results in an expression that is equal to zero.
If we want to get the second root of the polynomial and assign it to a new variable called secondRoot, we could evaluate:
Please see the tutorial on using rules for more examples and information on how to use them.
For some functions, such as NDSolve, an equivalent “Value” function exists (e.g., NDSolveValue) that returns a value or function instead of rules.