Introduction to Programming with Mathematica, Third Edition

A computer program is a set of instructions (a recipe) for carrying out a computation. When a program is evaluated with appropriate inputs the computation is performed and the result is returned. In this sense, a program is a mathematical function and the inputs to a program are the arguments of the function. Executing a program is equivalent to applying a function to its arguments or, as it is often referred making a function call.
While there are a great many built-in functions in Mathematica that can be used to carry out computations, we invariably find ourselves needing customized functions. For example, once we have written a program to compute some values for some particular inputs, we might want to perform the same set of operations on different inputs. We would therefore like to create our own user-defined functions that we could then apply in the same way as we call a built-in function by entering the function name and specific argument values. We will start with the proper syntax (or grammar) to use when writing a function definition.
The function definition looks very much like a mathematical equation: a left-hand side and a right-hand side separated by a colon-equal sign.
<i class="emphasis">name[arg</i><sub1</sub>_, <i class="emphasis">arg</i><sub2</sub>_]:= <i class="emphasis">body</i>
The left-hand side starts with a symbol. This symbol is referred to as the function name (or sometimes just as the function, as in "the sine function"). The function name is...