Timothy Morris

X
ME

timothy.morris@csus.edu
  • Bachelors in Physics
  • Ph.D. in Mathematics

Functions

What is a function?

In computer programming, a function is a block of code that looks something like:
int square(int x){
  int S = x * x;
  return S;
}
This function takes as input, an integer \(x\), and returns the value \(x^2\). Thus, if you called the function like this:
int a=square(3);
Then the number 9 would be assigned to the variable \(a\). However, this is just a little bit misleading, as we are assigning the output of square(3) to the variable \(a\). We don't need to do that at all as square(3) actually is the number 9. Thus our computer code can work with it directly. So this will check to see if some variable \(r\) is equal to 9.
if (r == square(3)){
  cout >> "r=9";
}
In fact, the code does exactly the same thing as:
if (r == 9){
  cout >> "r=9";
}
Similarly, in mathematics a function takes an input and, for each input returns exactly one output. Thus \(f:\mathbb{R}\to\mathbb{R}\) is a function that takes any real number as an input and returns a real number as output. Thus if \(f(x)=x^2\), then \(f\) is the function that returns the square of its input. So, \[f(3)=9\] This can be read as, the function \(f\) evaluated at \(3\) is \(9\), or simply \(f\) of \(3\) is \(9\). Perhaps surprisingly, \(f(3)\) is not a function, rather \(f(3)\) is the number \(9\). Thus the statement \[f(3)=f(-3)\] is not the statement \(3^2=(-3)^2\), but is simply the statement \(9=9\).