Registry Synced

Functions and Their Types

3079 words
15 min read

Reading compass

Now ยท ๐ŸŽฏ Learning Objectives

Functions and Their Types

๐ŸŽฏ Learning Objectives

By the end of this topic, you will be able to:
  1. Distinguish a function from a general relation using the one-input-one-output rule
  2. Identify the domain, codomain, and range of a function
  3. Determine whether a function is injective, surjective, or bijective
  4. Apply the vertical line test to graphs
  5. Compute function values, including piecewise-defined functions
  6. Perform arithmetic operations on functions

๐Ÿ“‹ Prerequisites


๐Ÿ“– Core Content

3.1 Intuition: What Is a Function?

A function is a machine that takes an input and produces exactly one output. You put a number into the "square" machine, and it spits back its square. The machine is deterministic: same input always gives same output. Think of a vending machine: you press one button (input), and exactly one item comes out (output). If pressing B3 sometimes gives chips and sometimes gives chocolate, it's not a functioning machine!
๐Ÿ’ก Why this matters: Functions are the building blocks of all mathematical modeling. In data science: every ML model is a function (features โ†’ prediction), every transformation (normalize, scale, log-transform) is a function, every database query (SQL SELECT) defines a function. (Diagram)

3.2 Formal Definition

3.2.1 Definition

Let AA and BB be non-empty sets. A function ff from AA to BB, written f:Aโ†’Bf: A \to B, is a relation fโІAร—Bf \subseteq A \times B such that:
  1. Total: For every aโˆˆAa \in A, there exists bโˆˆBb \in B with (a,b)โˆˆf(a, b) \in f.
  2. Single-valued: If (a,b1)โˆˆf(a, b_1) \in f and (a,b2)โˆˆf(a, b_2) \in f, then b1=b2b_1 = b_2. If (a,b)โˆˆf(a, b) \in f, we write f(a)=bf(a) = b.
  • Domain: The set AA (all possible inputs)
  • Codomain: The set BB (all possible outputs, declared)
  • Range (Image): {f(a)โˆฃaโˆˆA}โІB\{f(a) \mid a \in A\} \subseteq B (actual outputs)
โš ๏ธ Key point: All functions are relations, but not all relations are functions. A relation fails to be a function if some input has no output (not total) or some input has multiple outputs (not single-valued).

3.2.2 Worked Examples

Example 1.1 (Easy): Determine if f(x)=x2f(x) = x^2 is a function from R\mathbb{R} to R\mathbb{R}. Step 1 โ€” Total: For every real xx, x2x^2 is a real number. โœ“ Step 2 โ€” Single-valued: Each xx maps to exactly one x2x^2. โœ“ Domain: R\mathbb{R}, Codomain: R\mathbb{R}, Range: {yโˆˆRโˆฃyโ‰ฅ0}=[0,โˆž)\{y \in \mathbb{R} \mid y \geq 0\} = [0, \infty)
Yes,ย itโ€™sย aย function.ย Rangeย =[0,โˆž)\boxed{\text{Yes, it's a function. Range } = [0, \infty)}
Example 1.2 (Medium): Is y2=xy^2 = x a function y=f(x)y = f(x) from R\mathbb{R} to R\mathbb{R}? Step 1: For x=4x = 4, y2=4โ€…โ€ŠโŸนโ€…โ€Šy=2y^2 = 4 \implies y = 2 or y=โˆ’2y = -2. This violates the single-valued condition โ€” one input gives two outputs.
Noย โ€”ย oneย inputย givesย twoย outputs\boxed{\text{No โ€” one input gives two outputs}}
Example 1.3 (Hard): Define f:Zโ†’Zf: \mathbb{Z} \to \mathbb{Z} by f(n)=โŒŠn/2โŒ‹f(n) = \lfloor n/2 \rfloor. Is this a function? Find its range. Step 1 โ€” Total: Every integer nn divided by 2 has a floor. โœ“ Step 2 โ€” Single-valued: Floor gives exactly one integer. โœ“ Range: For n=0n = 0, f(0)=0f(0) = 0; n=1n = 1, f(1)=0f(1) = 0; n=2n = 2, f(2)=1f(2) = 1; n=3n = 3, f(3)=1f(3) = 1; negative numbers follow similarly. Range = Z\mathbb{Z} (all integers appear: f(2k)=kf(2k) = k, f(2k+1)=kf(2k+1) = k).
Yes.ย Rangeย =Z\boxed{\text{Yes. Range } = \mathbb{Z}}

3.3 Domain and Range

3.3.1 Finding Domain and Range

The domain of a function is the set of all valid inputs. The range is the set of all possible outputs. Recipe for domain:
  1. Look for "problem" operations: division by zero, square roots of negatives, log of non-positive
  2. Exclude values that cause these problems Recipe for range:
  3. Determine the set of outputs the function produces
  4. Use graphs, inequalities, or algebraic analysis

3.3.2 Worked Examples

Example 2.1: Find the domain of f(x)=1xโˆ’3f(x) = \frac{1}{x-3}. Step 1: Problem: denominator xโˆ’3=0x-3 = 0 โ†’ undefined Step 2: Exclude x=3x = 3 Domain: Rโˆ–{3}\mathbb{R} \setminus \{3\} or (โˆ’โˆž,3)โˆช(3,โˆž)(-\infty, 3) \cup (3, \infty)
Domainย =Rโˆ–{3}\boxed{\text{Domain } = \mathbb{R} \setminus \{3\}}
Example 2.2: Find the domain of g(x)=5โˆ’xg(x) = \sqrt{5 - x}. Step 1: Problem: square root of negative โ†’ undefined Step 2: Need 5โˆ’xโ‰ฅ0โ€…โ€ŠโŸนโ€…โ€Šxโ‰ค55 - x \geq 0 \implies x \leq 5 Domain: (โˆ’โˆž,5](-\infty, 5]
Domainย =(โˆ’โˆž,5]\boxed{\text{Domain } = (-\infty, 5]}
Example 2.3: Find the domain and range of h(x)=1x2+1h(x) = \frac{1}{x^2 + 1}. Step 1 โ€” Domain: Denominator x2+1โ‰ฅ1>0x^2 + 1 \geq 1 > 0 for all real xx. No problems. Domain: R\mathbb{R} Step 2 โ€” Range: x2+1โ‰ฅ1x^2 + 1 \geq 1, so 1x2+1โ‰ค1\frac{1}{x^2 + 1} \leq 1. Also always positive. 0<h(x)โ‰ค10 < h(x) \leq 1 Range: (0,1](0, 1]
Domainย =R,ย Rangeย =(0,1]\boxed{\text{Domain } = \mathbb{R},\ \text{Range } = (0, 1]}

3.4 Piecewise Functions

A piecewise function uses different rules for different parts of the domain. x^2 & \text{if } x < 0 \\ 2x + 1 & \text{if } x \geq 0 \end{cases}
**Example 3.1:** Compute $f(-2)$, $f(0)$, $f(3)$ for the function above. *Step 1:* $f(-2)$: Since $-2 < 0$, use $f(-2) = (-2)^2 = 4$ *Step 2:* $f(0)$: Since $0 \\geq 0$, use $f(0) = 2(0) + 1 = 1$ *Step 3:* $f(3)$: Since $3 \\geq 0$, use $f(3) = 2(3) + 1 = 7$ \\boxed{f(-2) = 4,\\ f(0) = 1,\\ f(3) = 7} \--- ### 3.5 Types of Functions #### 3.5.1 Injective (One-to-One) Functions **Intuition:** No two different inputs produce the same output. Like a fingerprint โ€” each person has a unique one. **Definition:** $f: A \\to B$ is **injective** (one-to-one) if for all $a_1, a_2 \\in A$: a_1 \\neq a_2 \\implies f(a_1) \\neq f(a_2) Equivalently: $f(a_1) = f(a_2) \\implies a_1 = a_2$ **Horizontal Line Test:** A function is injective if every horizontal line intersects its graph at most once. \`\`\`mermaid graph LR subgraph "Injective (One-to-One)" A1\["1"\] --> B1\["a"\] A2\["2"\] --> B2\["b"\] A3\["3"\] --> B3\["c"\] end subgraph "Not Injective" C1\["1"\] --> D1\["a"\] C2\["2"\] --> D1\["a"\] C3\["3"\] --> D2\["b"\] end \`\`\` **Examples:** - $f(x) = 3x + 5$ โ†’ injective (linear with slope โ‰  0) - $f(x) = x^2$ โ†’ NOT injective (since $f(-2) = f(2) = 4$) - $f(x) = e^x$ โ†’ injective (strictly increasing) #### 3.5.2 Surjective (Onto) Functions **Intuition:** Every possible output value is actually achieved. The range equals the codomain. Like a stadium with no empty seats โ€” every seat (codomain) has someone sitting in it (range). **Definition:** $f: A \\to B$ is **surjective** (onto) if for every $b \\in B$, there exists $a \\in A$ such that $f(a) = b$. **Equivalent:** $\\text{range}(f) = \\text{codomain}(f)$ **Examples:** - $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = 2x + 3$ โ†’ surjective (any $y = 2x + 3$ can be solved: $x = (y-3)/2$) - $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = x^2$ โ†’ NOT surjective (negative values never achieved) - $f: \\mathbb{R} \\to \\mathbb{R}^+$, $f(x) = e^x$ โ†’ surjective (range = $\\mathbb{R}^+$ = codomain) \`\`\`mermaid graph TD subgraph "Surjective (Onto)" SA\["Domain"\] --> SB\["Codomain = Range<br/>Every codomain value<br/>is hit"\] end subgraph "Not Surjective" NC\["Domain"\] --> ND\["Codomain<br/>Some codomain values<br/>never hit"\] end \`\`\` #### 3.5.3 Bijective Functions **Intuition:** The perfect pairing โ€” each input maps to a unique output, and every output is hit. Like a dance where every person has a unique partner and nobody sits out. **Definition:** $f$ is **bijective** if it is **both** injective and surjective. **Properties of bijections:** - They have **inverses** - Domain and codomain have the same cardinality ($|A| = |B|$) - For finite sets, a function from $A$ to $B$ can be bijective only if $|A| = |B|$ #### 3.5.4 Worked Examples โ€” Classifying Functions **Example 4.1:** Classify $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = 5x - 3$. *Injective:* If $f(a) = f(b)$, then $5a - 3 = 5b - 3 \\implies 5a = 5b \\implies a = b$. โ†’ **Injective** โœ“ *Surjective:* For any $y \\in \\mathbb{R}$, solve $y = 5x - 3 \\implies x = \\frac{y+3}{5} \\in \\mathbb{R}$. โ†’ **Surjective** โœ“ *Conclusion:* **Bijective** \\boxed{\\text{Bijective}} **Example 4.2:** Classify $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = x^3 - x$. *Injective:* $f(-1) = (-1)^3 - (-1) = -1 + 1 = 0$; $f(0) = 0$; $f(1) = 1 - 1 = 0$. So $f(-1) = f(0) = f(1) = 0$ but $-1 \\neq 0 \\neq 1$. โ†’ **Not injective** โœ— *Surjective:* For any $y \\in \\mathbb{R}$, $x^3 - x - y = 0$ has at least one real root (cubic always has a real root). โ†’ **Surjective** โœ“ *Conclusion:* **Surjective only** \\boxed{\\text{Surjective}} **Example 4.3:** Classify $f: \\mathbb{N} \\to \\mathbb{N}$, $f(n) = n^2$. *Injective:* If $n_1^2 = n_2^2$, since $n_1, n_2 \\in \\mathbb{N}$, $n_1 = n_2$. โ†’ **Injective** โœ“ *Surjective:* Is every natural number a perfect square? No โ€” 2, 3, 5, 6, 7, 8, 10, ... are not squares. โ†’ **Not surjective** โœ— *Conclusion:* **Injective only** \\boxed{\\text{Injective (but not surjective)}} **Example 4.4 (Exam-style):** Let $f: \\mathbb{Z} \\to \\mathbb{Z}$ be defined by $f(n) = \\begin{cases} n/2 & \\text{if } n \\text{ is even} \\\\ (n-1)/2 & \\text{if } n \\text{ is odd} \\end{cases}$. Classify $f$. *Injective:* Check: $f(0) = 0$, $f(1) = 0$. $f(0) = f(1)$ but $0 \\neq 1$. โ†’ **Not injective** โœ— *Surjective:* For any $m \\in \\mathbb{Z}$, choose $n = 2m$ (even). Then $f(2m) = (2m)/2 = m$. โ†’ **Surjective** โœ“ *Conclusion:* **Surjective only** \\boxed{\\text{Surjective}} \--- ### 3.6 Operations on Functions Functions can be combined arithmetically:
\begin{aligned} (f + g)(x) &= f(x) + g(x) \\ (f - g)(x) &= f(x) - g(x) \\ (f \cdot g)(x) &= f(x) \cdot g(x) \\ \left(\frac{f}{g}\right)(x) &= \frac{f(x)}{g(x)},\quad g(x) \neq 0 \end{aligned}
**Example 5.1:** Let $f(x) = x^2$, $g(x) = x + 1$. Find $(f+g)(3)$ and $(f/g)(2)$. *Step 1:* $(f+g)(3) = f(3) + g(3) = 9 + 4 = 13$ *Step 2:* $(f/g)(2) = f(2)/g(2) = 4/3$ \\boxed{(f+g)(3) = 13,\\ (f/g)(2) = \\frac{4}{3}} \--- ### 3.7 The Vertical Line Test **Intuition:** A simple visual check for whether a graph represents a function. **Vertical Line Test:** A graph represents a function if and only if **no vertical line** intersects the graph at more than one point. **Why:** A vertical line at $x = a$ tests the input $a$. If it hits two points, input $a$ maps to two outputs โ†’ not a function. \`\`\`mermaid graph LR subgraph "Function (Passes VLT)" A\["โ†‘"\] B\[" "\] C\[" "\] A --> B B --> C end subgraph "Not a Function (Fails VLT)" D\["โ†‘"\] E\[" "\] F\[" "\] D --> E D --> F end \`\`\` --- ## ๐Ÿ“ Key Formulas โ€” Summary Table | Concept | Formula/Definition | When to Use | |:---|:---|:---| | Function definition | $\\forall a \\in A,\\ \\exists!\\ b \\in B:\\ f(a) = b$ | Checking if a relation is a function | | Domain | Set of all valid inputs | Before evaluating a function | | Range | $\\{f(a) \\mid a \\in A\\}$ | Determining possible outputs | | Injective | $f(a_1) = f(a_2) \\implies a_1 = a_2$ | One-to-one testing | | Surjective | $\\forall b \\in B,\\ \\exists a \\in A:\\ f(a) = b$ | Onto testing | | Bijective | Injective AND surjective | Function has inverse | | Horizontal line test | No horizontal line hits graph twice | Graphical injection test | | Vertical line test | No vertical line hits graph twice | Graphical function test | | Piecewise | $f(x) = \\begin{cases} \\text{rule}_1 & \\text{condition}_1 \\\\ \\text{rule}_2 & \\text{condition}_2 \\end{cases}$ | Multi-rule functions | | Sum of functions | $(f+g)(x) = f(x) + g(x)$ | Combining functions | --- ## โš ๏ธ Common Pitfalls ### Pitfall 1: Confusing One-to-One with Onto **Mistake:** Using the terms "one-to-one" (injective) and "onto" (surjective) interchangeably. **Why they're different:** - **Injective:** No two inputs share an output (unique mapping) - **Surjective:** Every possible output is achieved (complete coverage) **Example:** $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = e^x$ is injective but not surjective (never negative). $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = x^3 - x$ is surjective but not injective. ### Pitfall 2: Forgetting the Codomain When Testing Surjectivity **Mistake:** Saying $f(x) = x^2$ is surjective because its range is $\[0,\\infty)$ without checking the codomain. **Correct:** If $f: \\mathbb{R} \\to \\mathbb{R}$ and codomain is $\\mathbb{R}$, then $x^2$ is NOT surjective (negative numbers never hit). But if $f: \\mathbb{R} \\to \[0,\\infty)$, the SAME rule IS surjective. **How to catch:** Always check the declared codomain, not just what you think it should be. ### Pitfall 3: Assuming $f(x)$ and $g(x)$ Have Same Domain for Arithmetic **Mistake:** Computing $(f+g)(x)$ without considering domain restrictions. **Correct:** The domain of $(f+g)$, $(f-g)$, and $(f \\cdot g)$ is $D_f \\cap D_g$ (intersection of domains). For $(f/g)$, also exclude points where $g(x) = 0$. **Example:** $f(x) = \\sqrt{x}$, $g(x) = 1/(x-2)$. Domain of $f$: $\[0,\\infty)$. Domain of $g$: $\\mathbb{R} \\setminus \\{2\\}$. Domain of $(f+g) = \[0,\\infty) \\setminus \\{2\\}$. ### Pitfall 4: Thinking $f(a) = f(b)$ Always Implies $a = b$ **Mistake:** Assuming every function is injective. **Correct:** Only injective functions have this property. For general functions, $f(a) = f(b)$ can happen with $a \\neq b$. Example: $f(x) = x^2$, $f(2) = f(-2) = 4$. --- ## ๐Ÿ“ Practice Questions > **Q1: Is $f(x) = \\sqrt{x}$ a function from $\\mathbb{R}$ to $\\mathbb{R}$?** > > **Strategy Hint:** Check domain (principal square root is defined only for $x \\geq 0$). > > *Step 1:* For $x = -4$, $\\sqrt{-4}$ is not a real number. โ†’ Not total on $\\mathbb{R}$. > So $f: \\mathbb{R} \\to \\mathbb{R}$ is NOT a function (fails the "total" condition). > > If we restrict to $f: \[0,\\infty) \\to \\mathbb{R}$, it IS a function. > >
\boxed{\text{No โ€” not defined for negative inputs}}
> **Q2: Find the domain of $f(x) = \\frac{2x+1}{x^2 - 4}$.** > > **Strategy Hint:** Denominator cannot be zero. > > *Step 1:* $x^2 - 4 = 0 \\implies x = 2$ or $x = -2$ > *Domain:* $\\mathbb{R} \\setminus \\{-2, 2\\}$ > >
\boxed{(-\infty, -2) \cup (-2, 2) \cup (2, \infty)}
> **Q3: Classify $f: \\mathbb{R} \\to \\mathbb{R}$, $f(x) = -2x + 7$.** > > **Strategy Hint:** Check both injective and surjective for a linear function. > > *Injective:* $f(a) = f(b) \\implies -2a + 7 = -2b + 7 \\implies a = b$. โœ“ > *Surjective:* For any $y$, $x = (7 - y)/2 \\in \\mathbb{R}$. โœ“ > >
\boxed{\text{Bijective}}
> **Q4: Does $f(x) = |x|$ pass the horizontal line test?** > > **Strategy Hint:** Consider the horizontal line $y = 1$. > > $f(-1) = 1$ and $f(1) = 1$. So the horizontal line $y=1$ hits the graph at two points โ†’ fails HLT โ†’ NOT injective. > >
\boxed{\text{No โ€” not injective}}
> **Q5: Find the range of $f(x) = \\frac{3}{x^2 + 2}$.** > > **Strategy Hint:** The denominator is always positive, so $f(x) > 0$. Find max/min. > > *Step 1:* $x^2 + 2 \\geq 2$, so $\\frac{3}{x^2 + 2} \\leq \\frac{3}{2}$ > *Step 2:* As $x \\to \\infty$, $f(x) \\to 0$ (but never reaches 0) > *Range:* $(0, \\frac{3}{2}\]$ > >
\boxed{(0, \frac{3}{2}]}
> **Q6: For $f(x) = \\begin{cases} x+1 & x < 2 \\\\ 3x - 4 & x \\geq 2 \\end{cases}$, find $f(-1)$, $f(2)$, $f(5)$.** > > **Strategy Hint:** Check which rule applies for each input. > > *Step 1:* $f(-1)$: $-1 < 2$ โ†’ $f(-1) = -1 + 1 = 0$ > *Step 2:* $f(2)$: $2 \\geq 2$ โ†’ $f(2) = 3(2) - 4 = 2$ > *Step 3:* $f(5)$: $5 \\geq 2$ โ†’ $f(5) = 3(5) - 4 = 11$ > >
\boxed{f(-1) = 0,\ f(2) = 2,\ f(5) = 11}
> **Q7: Let $f(x) = x^2 - 1$, $g(x) = \\sqrt{x}$. Find $(f \\cdot g)(4)$.** > > **Strategy Hint:** Compute each function at 4, then multiply. > > *Step 1:* $f(4) = 16 - 1 = 15$ > *Step 2:* $g(4) = \\sqrt{4} = 2$ > *Step 3:* $(f\\cdot g)(4) = 15 \\times 2 = 30$ > >
\boxed{30}
> **Q8: Prove that $f: \\mathbb{R} \\to \\mathbb{R}$ given by $f(x) = x^3$ is bijective.** > > **Strategy Hint:** Show injective (strictly increasing) and surjective (solve for x). > > *Injective:* $f(a) = f(b) \\implies a^3 = b^3 \\implies a = b$ (since cube function is strictly increasing). โœ“ > *Surjective:* For any $y \\in \\mathbb{R}$, let $x = \\sqrt\[3\]{y}$. Then $f(x) = (\\sqrt\[3\]{y})^3 = y$. โœ“ > >
\boxed{\text{Bijective}}
> **Q9: Is $f: \\mathbb{N} \\to \\mathbb{N}$, $f(n) = n+1$ surjective?** > > **Strategy Hint:** Check if every natural number appears as an output. > > $f(n) = n+1$ gives outputs $\\{2,3,4,\\ldots\\}$. The number $1 \\in \\mathbb{N}$ never appears. โ†’ NOT surjective. > >
\boxed{\text{No โ€” 1 is not in the range}}
> **Q10: Let $A = \\{1,2,3\\}$, $f: A \\to A$ be the function $f = \\{(1,2), (2,3), (3,1)\\}$. Classify $f$.** > > **Strategy Hint:** Check injective (all outputs distinct?) and surjective (all codomain values hit?). > > *Injective:* Outputs are $\\{2,3,1\\}$ โ€” all distinct โ†’ Injective โœ“ > *Surjective:* Codomain is $\\{1,2,3\\}$, range is $\\{1,2,3\\}$ โ†’ Surjective โœ“ > >
\boxed{\text{Bijective}}
> **Q11: Find the domain of $f(x) = \\frac{1}{\\sqrt{9 - x^2}}$.** > > **Strategy Hint:** Two conditions: denominator โ‰  0 (true automatically if sqrt > 0) and sqrt argument โ‰ฅ 0. Since the sqrt is in denominator, we need $9 - x^2 > 0$. > > *Step 1:* $9 - x^2 > 0 \\implies x^2 < 9 \\implies -3 < x < 3$ > >
\boxed{(-3, 3)}
> **Q12: Can a function from a set of 3 elements to a set of 2 elements be injective?** > > **Strategy Hint:** Pigeonhole principle โ€” 3 inputs must map to 2 outputs. > > If $|A| = 3$, $|B| = 2$, and $f: A \\to B$, by the pigeonhole principle, at least two elements of $A$ must map to the same element of $B$. Therefore $f$ cannot be injective. > >
\boxed{\text{No โ€” pigeonhole principle}}$$ --- ## ๐Ÿ”— Cross-References - Previous topic: [Relations](sets-relations) โ€” functions are special relations - Next topic: [Coordinate Geometry](../week02/geom-coordinate-geometry.md) โ€” plotting functions geometrically - Deep dive: [Exponential Functions](../week05/functions-exponential.md), [Composite & Inverse Functions](../week05/functions-composite-inverse.md) in Week 5 - Across courses: BSMA1002 Stats 1 (probability distributions are functions); BSMA1003 Maths 2 (linear transformations are functions) Join Discord Previous1.2 RelationsNext2.1 Coordinate Geometry
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.