Sub topic 1
What is a function?
A function is a rule that assigns exactly one output to each allowed input. This chapter builds that definition carefully and shows how to test it. It also covers the mistakes learners most often make with it. Later chapters use this idea for notation, domain, and range.
Prerequisites
This chapter assumes you can do the following:
- Do arithmetic with integers, fractions, and decimals.
- Solve linear equations and simple inequalities.
- Plot points on the coordinate plane.
- Work with basic algebraic expressions, including exponents and square roots.
The Python examples are short. You only need to read basic function definitions, loops, and sets.
The core idea
A function has two ingredients:
- A collection of allowed inputs.
- A rule that, for each allowed input, produces one output.
The words "exactly one" carry the whole definition. If you give the rule an allowed input, it must give you an answer. It must also give you the same single answer every time you repeat that input. A rule that gives two different answers for one input is not a function.
Everyday examples help here:
- A vending machine takes a button code and returns one product. Press B4 and you always get the same snack. This is a function.
- A person's date of birth depends on the person. Each person has exactly one, so "person to birth date" is a function.
- The reverse, "birth date to person", is not a function. Many people share a birthday, so one input would have many outputs.
Seeing a function as a mapping
A mapping diagram draws each input on the left and each output on the right, with an arrow for each assignment. The diagram below shows the pairs (1, 2), (2, 4), and (3, 4).
Each input has exactly one arrow leaving it. That is the test. Notice that output 4 receives two arrows. This is allowed. The definition restricts arrows leaving an input, and it puts no limit on arrows arriving at an output.
The pair-based definition
A mapping diagram is one picture of a more basic object: a set of ordered pairs (x, y). Here x is an input and y is its output. A set of pairs is a function exactly when no input x appears in two pairs with different outputs.
The table below shows two sets of pairs.
| Relation | Pairs | Function? | Reason |
|---|---|---|---|
| A | (1, 2), (2, 4), (3, 4) | Yes | Each input appears once. |
| B | (1, 2), (1, 3), (2, 4) | No | Input 1 has outputs 2 and 3. |
In general, any set of pairs is called a relation. A function is a relation with the extra "one output per input" property. Every function is a relation, but not every relation is a function.
Testing a relation in code
The pair-based definition translates directly into an algorithm. Walk through the pairs and remember the output you first saw for each input. If a later pair gives the same input a different output, the relation fails.
def is_function(pairs):
seen = {}
for x, y in pairs:
if x in seen and seen[x] != y:
return False
seen[x] = y
return True
relation_a = [(1, 2), (2, 4), (3, 4)]
relation_b = [(1, 2), (1, 3), (2, 4)]
print(is_function(relation_a)) # True
print(is_function(relation_b)) # False
print(sorted({x for x, _ in relation_a})) # domain: [1, 2, 3]
print(sorted({y for _, y in relation_a})) # range: [2, 4]The check seen[x] != y matters. A list such as [(1, 2), (1, 2)] repeats an input, but it repeats the same output, so it is still a function. Only a conflicting output breaks the rule.
The last two lines preview two terms covered in their own chapters. The set of first entries is the domain, and the set of second entries is the range. For relation A, the domain is {1, 2, 3} and the range is {2, 4}.
Many inputs may share an output
Consider the rule "square the input". The following program applies it to the integers from -3 to 3.
def h(x):
return x ** 2
outputs = sorted({h(x) for x in range(-3, 4)})
print(outputs) # [0, 1, 4, 9]The inputs -3 and 3 both give 9. The inputs -2 and 2 both give 4. Seven inputs produce only four distinct outputs. This is still a function, because each single input has one output. The program also shows that no output is negative, which is a fact about the rule's range.
Compare this with the reverse question, "which input gives 9?". The answers are -3 and 3. Going backward from output to input is not a function here. That asymmetry is the root of many mistakes in later algebra, so it is worth stating plainly:
- Many-to-one (several inputs, one output) is allowed.
- One-to-many (one input, several outputs) is not allowed.
Functions do not need formulas
Beginners often think a function must be an equation. It does not. A function is defined by what it does, and many forms can express it:
- A table listing inputs and outputs.
- A mapping diagram.
- A graph.
- An equation such as y = 2x + 3.
- A plain sentence, such as "the number of letters in the word".
The next chapter covers these four forms in detail. For now, remember that the definition is independent of the form. An equation is just one convenient way to describe the rule.
The following callout covers a distinction that matters later.
An equation is a function only in a certain direction
Whether an equation defines a function depends on which variable you treat as the input. Take the equation y = 2x + 3. Pick any x and you get exactly one y. So y is a function of x.
Now take the equation x = y². If the input is x = 4, then y can be 2 or -2. One input has two outputs, so y is not a function of x here. If you treat y as the input and x as the output, the same equation is a function, because each y gives one x.
So always ask: "Is each choice of the input variable paired with exactly one output?"
Common errors
These are the mistakes that appear most often at this stage.
- Requiring distinct outputs. Some learners reject (2, 4) and (3, 4) because 4 repeats. Repeated outputs are fine.
- Confusing repeated inputs with conflicting inputs. The pairs (1, 2) and (1, 2) are one assignment written twice. Only different outputs for the same input break the rule.
- Judging by the formula alone. A formula says nothing until you know the allowed inputs. For example, 1 / x has no output at x = 0, so 0 cannot be an allowed input. The chapter on domain explains how to find such exclusions.
- Reversing the direction. Testing "is x a function of y?" when the question asked about y as a function of x gives the wrong verdict.
- Assuming every rule is a function. "The square root of x" is ambiguous unless you say you mean the non-negative root. Without that choice, one input could have two outputs.
How this connects to what follows
The definition you just learned drives every later idea in this tutorial:
- Function notation f(x) is a compact way to write "the single output for input x".
- Evaluating a function means finding that single output for a given input.
- The vertical line test applies the one-output rule to a graph.
- The domain is the collection of allowed inputs, and the range is the collection of outputs that actually occur.
Each of these is easier once the "exactly one output per allowed input" rule is clear.
Exercises
Exercise
Which of these sets of pairs is a function? (a) {(0, 1), (1, 1), (2, 1)} (b) {(3, 5), (4, 6), (3, 7)} (c) {(1, 2), (1, 2), (2, 3)}
Show answer
(a) and (c) are functions. In (a), every input is different, and all outputs are 1, which is allowed. In (b), input 3 has outputs 5 and 7, so it is not a function. In (c), input 1 appears twice, but always with output 2, so it is the same assignment repeated and the set is a function.
Exercise
A rule sends each student in a class to their first name, and a second rule sends each first name back to the student. Which rule is certain to be a function, and why might the other fail?
Show answer
The first rule is a function, because each student has exactly one first name. The second rule may fail. If two students share a first name, that single name would be paired with two students, giving one input two outputs.
Exercise
Decide whether y is a function of x in the equation y² = x. Then decide whether x is a function of y. Give a pair of values to support each answer.
Show answer
y is not a function of x. For x = 9, y can be 3 or -3, so the input 9 has two outputs. x is a function of y. For any y, the value x = y² is one number. For example, y = 3 gives x = 9, and y = -3 also gives x = 9, which is allowed because different inputs may share an output.