Why This Matters
Vending machine logic:
– Input: $2 + button B3
– Output: Snickers bar
Same input → same output. Always.
This is a function: A rule that transforms inputs to outputs consistently.
Functions aren’t just math abstractions—they’re the foundation of computation, data transformation, and scientific modeling.
What You’ll Learn
- What makes something a function (single output per input)
- Different ways to represent functions (equations, tables, graphs, code)
- Function composition (chaining transformations)
- When functions break (undefined inputs, non-determinism)
The Core Idea: Reliable Transformation
Definition
Function = A rule that assigns exactly one output to each input.
Notation:
f(x) = 2x + 3
Read as: "f of x equals 2x plus 3"
Example:
f(1) = 2(1) + 3 = 5
f(2) = 2(2) + 3 = 7
f(5) = 2(5) + 3 = 13
Key property: Same input always gives same output.
def f(x):
return 2*x + 3
assert f(1) == 5
assert f(1) == 5 # Call again - same result
assert f(2) == 7
What Disqualifies Something as a Function?
Non-Function Example 1: Multiple Outputs
“Function”: Take a number, return its square roots.
g(4) = +2 and -2 # Two outputs!
Problem: Not a function. Must return exactly one output.
Fix: Restrict to positive root only:
g(4) = +2 ✓
Non-Function Example 2: Undefined for Some Inputs
h(x) = 1 / x
Problem: h(0) = undefined (division by zero).
Solutions:
– Exclude 0 from domain: “h(x) for x ≠ 0”
– Handle explicitly: Return None or raise error
def h(x):
if x == 0:
return None # or raise ValueError
return 1 / x
Representing Functions: Four Views
1. Equation
f(x) = x²
Pro: Compact, works for any x
Con: Not all functions have simple equations
2. Table
| x | f(x) |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
Pro: Easy to read specific values
Con: Only shows sampled points, not intermediate values
3. Graph
f(x)
|
9 | •
4 | •
1 | •
0 | •
+———————————— x
0 1 2 3
Pro: Visual pattern recognition
Con: Approximate, not precise for calculations
4. Code
def f(x):
return x ** 2
Pro: Executable, handles edge cases
Con: Requires programming knowledge
All four represent the same function!
Function Composition: Chaining Transformations
Concept
Apply functions in sequence:
h(x) = g(f(x))
Read as: "h of x equals g of f of x"
Example
def f(x):
return 2*x # Double it
def g(x):
return x + 5 # Add 5
def h(x):
return g(f(x)) # Double, then add 5
print(h(3)) # f(3)=6, then g(6)=11
Output: 11
Notation: h = g ∘ f (read: “g composed with f”)
Order Matters!
h1(x) = g(f(x)) = (2x) + 5 = 2x + 5
h2(x) = f(g(x)) = 2(x + 5) = 2x + 10
h1(3) = 11
h2(3) = 16 # Different!
Composition is not commutative: g∘f ≠ f∘g (usually).
Inverse Functions: Undoing Transformations
Concept
f⁻¹ (read: “f inverse”) undoes what f does.
If f(x) = y, then f⁻¹(y) = x
Example
def f(x):
return 2*x + 3
def f_inverse(y):
return (y - 3) / 2
# Test:
x = 5
y = f(x) # y = 13
x_recovered = f_inverse(y) # Should get 5 back
assert x_recovered == x # ✓
Property: f⁻¹(f(x)) = x
When Inverses Don’t Exist
def g(x):
return x ** 2 # Square function
# Try to invert:
# g(2) = 4
# g(-2) = 4 # Also 4!
# g_inverse(4) = ??? (2 or -2?)
Problem: g maps multiple inputs to same output → can’t uniquely invert.
Solution: Restrict domain (e.g., g(x)=x² for x≥0 only).
Functions in the Real World
Data Transformation
# Temperature conversion
def celsius_to_fahrenheit(c):
return (9/5) * c + 32
celsius_to_fahrenheit(100) # 212 (boiling point)
Data Pipeline
# Clean → Transform → Aggregate
result = aggregate(transform(clean(raw_data)))
# Function composition!
Machine Learning
# Neural network layer
def layer(x, weights, bias):
return activation(weights @ x + bias)
# Deep network = function composition
y = layer4(layer3(layer2(layer1(x))))
From AI-100.1: Why Deep? — depth = composed transformations.
Pattern Passport
Pattern Observed: TRANSFORMATION
How It Appears Here:
– Function = Consistent transformation rule
– Composition = Chaining transformations
– Inverse = Reversing transformation
– Domain/Range = Valid inputs and possible outputs
Representation:
– Equation: f(x) = 2x + 3
– Table: Input-output pairs
– Graph: Visual curve
– Code: Executable procedure
Transformation Rules:
– Composition: (g ∘ f)(x) = g(f(x))
– Inverse: f⁻¹(f(x)) = x
– Identity: f(f⁻¹(x)) = x
Assumptions:
– Single output per input
– Deterministic (same input → same output)
– Well-defined on entire domain
Failure Conditions:
1. Multiple outputs: Not a function
2. Undefined inputs: Domain restrictions needed
3. Non-determinism: Random outputs violate function definition
4. Non-invertible: Multiple inputs map to same output
Related Disciplines:
– Code CODE-100.3: Functions as procedures
– AI AI-100.1: Composition creates depth
– Data DATA-200.3: Transformation pipelines
Next Learning Steps:
1. MATH-100.4: Linear Functions — Specific function family
2. MATH-200.1: Exponential Functions — Non-linear transformations
3. MATH-300.2: Optimization — Finding best inputs
Summary: Functions = Reliable Transformations
Function = rule that consistently transforms inputs to outputs.
Three key insights:
- Consistency: Same input always gives same output
- Composition: Chain functions to build complex transformations
- Invertibility: Some functions can be reversed
What makes a function:
– Exactly one output per input
– Defined on specified domain
– Deterministic (no randomness)
What breaks functions:
– Multiple outputs for one input
– Undefined on some inputs (unless explicitly excluded)
– Non-deterministic behavior
The value: Functions are the mathematical abstraction of transformation—foundation of calculus, programming, and data science.
Exercises
-
Test function: Is y² = x a function? Why or why not?
-
Compose: f(x) = x + 2, g(x) = 3x. Calculate (f ∘ g)(5) and (g ∘ f)(5).
-
Invert: f(x) = 3x – 7. Find f⁻¹(x). Verify f⁻¹(f(10)) = 10.
-
Code it: Write temperature_to_kelvin(c) and its inverse kelvin_to_celsius(k). Test round-trip.
Revision History
2026-07-30: Substantially revised to include code examples, composition demonstrations, failure modes.
2024-05-15: Originally published.
Reproducible Code
Available at:
– Code/function_examples.py
– validation/test_functions.py
cd Categories/01-Mathematics/100.3-Functions
python validation/test_functions.py