The Clear command

An important feature of Mathematica is that it remembers the values of variables
and definitions of functions throughout the session. This can be a problem when the
same names are used again, because Mathematica will use the old values. You can
remove the values and names from Mathematica's memory by using the Clear command.
It is important to do this, as Mathematica will not compute a new value for a function
that is stored in memory. Not clearing names is the most frequent source of erroneous
results in Mathematica programs. Consider the following example.

Suppose f is a function for which f[2]=4 is already defined.

Let us redefine f and compute f[3];

In[53]:=

  f[3]=8;
  f[x_]:=x^3;
  f[3]

Out[53]=

  8


Let us redefine f to a new function and see what happens.

In[54]:=

  
  f[a_]:= a+2;
  f[3]

Out[54]=

  8

In[55]:=

  f[2]

Out[55]=

  8

In[56]:=

  f[5]

Out[56]=

  125

The redefinition does not effect the values of the function. For this, it is necessary to clear
all the values if the function. It is best to place the clear statement before the definition
of a function. This way, if you make changes to the function, then the function is cleared
before the changes are entered and all values will be computed again.

In[57]:=

  Clear[f]
  f[a_]:= a+2;
  f[3]

Out[57]=

  5

Up to Tutorial