Theory
The vending machine test
A vending machine has one job: you press B4, you get the item stored at B4. Every button gives something, and never two different things on different days.
Now imagine a broken one: some buttons give nothing, one button randomly gives chips or a cold drink. You would stop trusting it.
Mathematics has a name for a machine you can trust: a function.
Theory
Input goes in, one output comes out
Every function is that reliable machine: feed it an input from a fixed set of allowed inputs, and it returns exactly one output. Same input tomorrow, same output tomorrow. The whole formal definition is just this promise written in symbols.
Theory
The definition, formally
Let A and B be sets. A function f: A → B is a rule that assigns to each element a ∈ A exactly one element of B, written f(a).
Two conditions hide in that sentence:
- each: no element of A is left without an output
- exactly one: no element of A gets two outputs
Break either condition and the rule is not a function.
Theory
Domain, codomain, range
For f: A → B:
- Domain = A, the set of allowed inputs
- Codomain = B, the set outputs are declared to come from
- Range = the outputs that actually occur
Example: f: ℤ → ℤ with f(x) = 2x. Domain and codomain are all integers, but the range is only the even integers. The range always sits inside the codomain: range ⊆ codomain.
Quiz
For f: ℤ → ℤ defined by f(x) = x², what is the range?
- All integers, same as the codomain
- The perfect squares {0, 1, 4, 9, 16, ...}
- All non-negative integers {0, 1, 2, 3, ...}
- All even integers
Show the answer
The perfect squares {0, 1, 4, 9, 16, ...}
The range is what the machine actually produces: 0, 1, 4, 9, 16 and so on. The codomain is declared as all of ℤ, but that does not make every integer an output. Options A and C are the two classic range-vs-codomain confusions.
Think first
Two rules, both mapping people to people or numbers. Decide for each: function or not?
1. Each person → their Aadhaar number
2. Each person → their parent
Show the answer
1 is a function: one person, one Aadhaar number.
2 is not: a person has two parents, so one input produces two outputs, breaking "exactly one". If some rule also left a person with no output at all, that would break "each". Those are the only two ways a rule can fail.
Theory
The rule polices inputs, not outputs
Look at f(x) = x² again: f(2) = 4 and f(−2) = 4. Two different inputs, same output.
Perfectly legal. The definition never says outputs must be different. It only says one input cannot split into two outputs.
Inputs behave like students with roll numbers: each student has exactly one roll number, but two students can share the same marks.
Quiz
Which of these IS a function from the set of your classmates to numbers?
- Each student → the marks they scored in Maths
- Each student → their siblings' ages
- Each student → the subjects they enjoy
- Each student → a number they may or may not have
Show the answer
Each student → the marks they scored in Maths
Marks give every student exactly one number. Siblings' ages can be none or many (breaks both conditions), enjoyed subjects can be several (breaks "exactly one"), and "may or may not have" breaks "each". A function permits no gaps and no doubles.
Watch out
The trap that costs marks
Students often reject valid functions because "two inputs give the same output". That is allowed! f(x) = x² is a function. Only test the two real conditions: every input covered, one output each. And never write that range equals codomain without checking; usually it does not.
Formula
The two-question exam check
Given any rule and asked "is it a function?", answer with two checks: (1) Does every element of the domain get an output? (2) Does any element get more than one? Yes to 1 and no to 2 means function. Quote both checks in your answer for full marks.
Theory
Where you will meet this again
Every function you will write in C or Python is this idea: arguments in, one return value out. A database primary key maps each key to exactly one row for the same reason. Next topics build directly on today: domain and range in detail, then types of functions.
Summary
Key takeaways
- A function f: A → B gives each element of A exactly one element of B.
- Domain = allowed inputs, codomain = declared output set, range = actual outputs, and range ⊆ codomain.
- A rule fails only two ways: an input with no output, or an input with two outputs.
- Different inputs sharing one output is allowed: f(x) = x² proves it.
- Memory hook: one input, one output, no excuses.