Pattern Matching to Arrays of Variables

The purpose of a pattern match is to bind an expression to a variable. There are several advanced ways that variables can be used in this process.

The basic pattern matching process lets you bind values to simple variables (zero parameters). There are cases where we might want to binding several expressions to an indexed list of variables. For example, if we have a polynomial expression, we might want to bind the coefficients to variables c(0), c(1), etc.

If the polynomial is 3x^2 + 1, then we want is to be able to write a match like:

{ 3 => c(2) } and {1 => c(0) }

and then be able to write expressions like c(2)x^2 on the right-hand side of an Assert to return 3x^2, for example.

But the standard pattern matching won't let us do this. The only thing that would normally match to a pattern like c(0) is a one parameter object with zero in the parameter. So | 0 | would match with "c" bound to Abs for example.

To allow the pattern matching that is intended here, we introduce a namespace called VariableArrays. If c(0) is in the VariableArrays namespace, then a match like { a + b => c[0] } will bind "a + b" to c(0). If "c" is in the Variables namespace, this match would fail.

You can move objects into the VariableArrays namespace using the Namespace command ("n"). Note that the VariableArrays namespace is only one of the results for this command if the object starts out in the variables namespace and has at least one parameter.