2.7.5 Dummy Variables in Mathematics
When you set up mathematical formulas, you often have to introduce various kinds of local objects or "dummy variables". You can treat such dummy variables using modules and other Mathematica scoping constructs.
Integration variables are a common example of dummy variables in mathematics. When you write down a formal integral, conventional notation requires you to introduce an integration variable with a definite name. This variable is essentially "local" to the integral, and its name, while arbitrary, must not conflict with any other names in your mathematical expression.
Here is a function for evaluating an integral.
In[1]:= p[n_] := Integrate[f[s] s^n, {s, 0, 1}]
The s here conflicts with the integration variable.
In[2]:= p[s + 1]
Out[2]=
Here is a definition with the integration variable specified as local to a module.
In[3]:= pm[n_] := Module[{s}, Integrate[f[s] s^n, {s, 0, 1}]]
Since you have used a module, Mathematica automatically renames the integration variable to avoid a conflict.
In[4]:= pm[s + 1]
Out[4]=
In many cases, the most important issue is that dummy variables should be kept local, and should not interfere with other variables in your mathematical expression. In some cases, however, what is instead important is that different uses of the same dummy variable should not conflict.
Repeated dummy variables often appear in products of vectors and tensors. With the "summation convention", any vector or tensor index that appears exactly twice is summed over all its possible values. The actual name of the repeated index never matters, but if there are two separate repeated indices, it is essential that their names do not conflict.
This sets up the repeated index j as a dummy variable.
In[5]:= q[i_] := Module[{j}, a[i, j] b[j]]
The module gives different instances of the dummy variable different names.
In[6]:= q[i1] q[i2]
Out[6]=
There are many situations in mathematics where you need to have variables with unique names. One example is in representing solutions to equations. With an equation like , there are an infinite number of solutions, each of the form , where is a dummy variable that can be equal to any integer. If you generate solutions to the equation on two separate occasions, there is no guarantee that the value of should be the same in both cases. As a result, you must set up the solution so that the object is different every time.
This defines a value for sinsol, with n as a dummy variable.
In[7]:= sinsol := Module[{n}, n Pi]
Different occurrences of the dummy variable are distinguished.
In[8]:= sinsol  sinsol
Out[8]=
Another place where unique objects are needed is in representing "constants of integration". When you do an integral, you are effectively solving an equation for a derivative. In general, there are many possible solutions to the equation, differing by additive "constants of integration". The standard Mathematica Integrate function always returns a solution with no constant of integration. But if you were to introduce constants of integration, you would need to use modules to make sure that they are always unique.
