5B. Elementary Functions

Functions

You are familiar with functions from mathematics. For example, if f  is defined by f (x) = x + 1, then f (2) = 3 and f (7) = 8.

You use functions in expressions. For example, if f (x) = x + 1, then expression f (3+2) + 1 has value 7. Evaluate an expression from the inside out.

f (3+2) + 1 = f (5) + 1
= 6 + 1
= 7

and

f (4) + f (10) = 5 + f (10)
= 5 + 11
= 16

Calling a function

An expression that uses a function is referred to as a function call.


Nested function calls

The argument of a function can be any expression, including an expression that uses a function. For example, if f (x) = x + 1, then

f (f (10)) = f (11)
= 12

and if g(x) = 2*x + 4, then

g(g(7) + f (2)) = g(18 + f (2))
= g(18 + 3)
= g(21)
= 46

Arguments/parameters

If E is an expression and f  is a function, then we say that E is the argument of f  in expression f (E). I will use term parameter interchangeably with argument.



Exercises

  1. Suppose that g(x) = 3x - 2. What is the value of expression g(g(9) + 1)? Answer