Day 18 — Functions
Day 18 — Functions
Stage II · concept day
Goal: Define functions as rules and as sets of pairs; determine domain and range; apply the vertical line test; work with piecewise definitions; read graphs; identify even/odd functions; understand when inverses exist.
Why this matters
Functions are the central abstraction of mathematics and programming: input → unique output. Graphs, APIs, hash maps (partial functions), and complexity \(T(n)\) are all functions. Inverse existence is bijectivity—undoable computation on a domain.
Theory
Definition
A function \(f\) from set \(A\) to set \(B\), written \(f:A\to B\), assigns to each \(a\in A\) exactly one element \(f(a)\in B\).
- \(A\) is the domain.
- \(B\) is the codomain.
- The range (image) is \(\{f(a):a\in A\}\subseteq B\).
As a set of pairs: \(f\subseteq A\times B\) such that for every \(a\in A\) there is unique \(b\) with \((a,b)\in f\), and we write \(b=f(a)\).
Not a function
A rule that assigns two outputs to one input fails.
Vertical line test (for graphs in the plane): a graph is a function \(y=f(x)\) iff every vertical line hits the graph at most once.
Common real functions
Polynomials, rationals (on their domains), \(x\mapsto |x|\), \(\sqrt{x}\) (domain \(x\ge 0\)), exponential, log.
Piecewise definitions
\[ f(x)=\begin{cases} x^2 & x<0\\ 2x & x\ge 0. \end{cases} \]
Evaluate by selecting the piece whose condition holds. Check consistency at boundaries if claimed continuous later.
Evaluating and algebra of functions
\((f+g)(x)=f(x)+g(x)\), \((fg)(x)=f(x)g(x)\), \((cf)(x)=c\,f(x)\) on common domain.
Composition: \((f\circ g)(x)=f(g(x))\) when \(g(x)\) in domain of \(f\).
Composition is not commutative in general: \(f\circ g\neq g\circ f\).
Even and odd functions
- Even: \(f(-x)=f(x)\) for all \(x\) in domain (symmetric about \(y\)-axis). Example: \(x^2\), \(\cos\) (later).
- Odd: \(f(-x)=-f(x)\) (rotational symmetry \(180^\circ\) about origin). Example: \(x^3\), \(x\).
Domain must be symmetric about \(0\) for the definitions to make sense globally.
Injective, surjective, bijective (for inverses)
- Injective (one-to-one): \(f(a)=f(b)\Rightarrow a=b\). Horizontal line test: each horizontal line hits graph at most once.
- Surjective (onto) \(A\to B\): range \(=B\).
- Bijective: both → invertible.
Inverse functions
If \(f:A\to B\) is bijective, the inverse \(f^{-1}:B\to A\) satisfies \[f^{-1}(f(a))=a,\qquad f(f^{-1}(b))=b.\]
Graph of \(f^{-1}\) is reflection of graph of \(f\) across \(y=x\).
Finding formulas: set \(y=f(x)\), solve for \(x\) in terms of \(y\), swap names.
Not every function has an inverse on its full domain: \(f(x)=x^2\) on \(\mathbb{R}\) is not injective; restrict to \([0,\infty)\) to invert with \(\sqrt{\cdot}\).
Graph reading
From a graph: estimate \(f(a)\), solve \(f(x)=c\) as intersection with \(y=c\), read domain/range as projections on axes, identify increasing/decreasing intervals.
Operations and domains (detail)
Domains of sums/products: \(\mathrm{dom}(f+g)=\mathrm{dom}(f)\cap\mathrm{dom}(g)\).
Domain of quotient \(f/g\): same intersection minus zeros of \(g\).
Domain of \(f\circ g\): \(\{x\in\mathrm{dom}(g): g(x)\in\mathrm{dom}(f)\}\).
Inverse criterion (summary)
\(f:A\to B\) has inverse function \(B\to A\) iff \(f\) is bijective.
On intervals, continuous strictly monotonic \(\Rightarrow\) injective \(\Rightarrow\) invertible onto its image.
Finding \(f^{-1}\) algebraically: \(y=f(x)\) solve for \(x\); swap labels; state new domain = old range.
Even/odd decomposition (theorem)
If \(\mathrm{dom}(f)\) is symmetric about \(0\), define \[f_e(x)=\frac{f(x)+f(-x)}{2},\qquad f_o(x)=\frac{f(x)-f(-x)}{2}.\] Then \(f_e\) is even, \(f_o\) is odd, and \(f=f_e+f_o\). Unique such decomposition.
Worked examples
Example 1 — Function check
\(\{(1,2),(2,2),(3,4)\}\) is a function. \(\{(1,2),(1,3)\}\) is not.
Example 2 — Domain
\(f(x)=\sqrt{x-1}+\frac{1}{x-3}\): \(x\ge 1\) and \(x\neq 3\), so \([1,3)\cup(3,\infty)\).
Example 3 — Piecewise eval
\(f(x)=\begin{cases}-x&x<1\\ x^2&x\ge 1\end{cases}\): \(f(0)=0\), \(f(1)=1\), \(f(2)=4\).
Example 4 — Composition
\(f(x)=x+1\), \(g(x)=x^2\). \((f\circ g)(x)=x^2+1\), \((g\circ f)(x)=(x+1)^2\).
Example 5 — Even/odd
\(f(x)=x^4-2x^2\) even. \(g(x)=x^3-x\) odd. \(h(x)=x^2+x\) neither.
Example 6 — Inverse
\(f(x)=2x-3\) on \(\mathbb{R}\). \(y=2x-3\), \(x=\frac{y+3}{2}\), so \(f^{-1}(y)=\frac{y+3}{2}\).
Example 7 — Restrict for inverse
\(f(x)=x^2\) on \([0,\infty)\): \(f^{-1}(x)=\sqrt{x}\). On \(\mathbb{R}\) no inverse function.
Example 8 — Range
\(f(x)=x^2\) on \(\mathbb{R}\): range \([0,\infty)\). \(f(x)=\frac{1}{x}\) on \(\mathbb{R}\setminus\{0\}\): range \(\mathbb{R}\setminus\{0\}\).
Example 9 — Horizontal line
\(y=x^3\) passes horizontal line test (strictly increasing). Inverse \(\sqrt[3]{x}\).
Example 10 — API analogy
abs: R → R is a function, not injective. sqrt: [0,∞) → [0,∞) inverse of square on that domain.
Example 11 — Graph features
If graph passes through \((2,5)\), then \(f(2)=5\). If horizontal line \(y=5\) hits three times, three solutions to \(f(x)=5\), not injective.
Example 12 — Algebra of functions
\(f(x)=x+1\), \(g(x)=x-1\): \((fg)(x)=x^2-1\), \((f+g)(x)=2x\).
Example 13 — Codomain vs range
\(f:\mathbb{R}\to\mathbb{R}\), \(f(x)=e^x\) has range \((0,\infty)\neq\mathbb{R}\), so not surjective onto \(\mathbb{R}\). As \(f:\mathbb{R}\to(0,\infty)\) it is bijective.
Example 14 — Difference quotient idea
\(\frac{f(x+h)-f(x)}{h}\) for \(f(x)=x^2\): \(\frac{2xh+h^2}{h}=2x+h\) (\(h\neq 0\))—slope preview.
Example 15 — Domain of composition carefully
\(g(x)=\sqrt{x-1}\), \(f(x)=\ln x\) (or \(\log\) later): \((f\circ g)(x)=\log\sqrt{x-1}\) needs \(x\ge 1\) and \(\sqrt{x-1}>0\) so \(x>1\) if log domain is \((0,\infty)\). With only algebraic tools today: \(f(x)=1/x\), \((f\circ g)\) needs \(\sqrt{x-1}\neq 0\) so \(x>1\) and \(x\ge 1\) ⇒ \(x>1\).
Example 16 — Prove injectivity from strictly increasing
If \(x_1<x_2\Rightarrow f(x_1)<f(x_2)\), then \(f(a)=f(b)\) forces \(a=b\) (else order contradicts). Hence injective. Example: \(f(x)=2x+1\).
Example 17 — Preimage vs inverse
\(f(x)=x^2\) on \(\mathbb{R}\). Preimage \(f^{-1}(\{4\})=\{-2,2\}\)—a set, not a single value. Inverse function does not exist on full \(\mathbb{R}\).
Example 18 — Piecewise inverse
\(f(x)=\begin{cases}x+1&x<0\\ 2x&x\ge 0\end{cases}\). Check injectivity: may fail or need care at pieces—\(f(-0.5)=0.5\), \(f(0.25)=0.5\) collision! Not injective, no inverse.
Example 19 — Even + odd = general
\(f(x)=e^x\) (preview): \(f_e=\cosh\) shape, \(f_o=\sinh\) shape—culture names later. Algebraically: \(f_e(x)=\frac{e^x+e^{-x}}{2}\).
Example 20 — Surjective by codomain choice
\(f:\mathbb{R}\to\mathbb{R}\), \(f(x)=x^2\) not surjective. Same rule \(f:\mathbb{R}\to[0,\infty)\) is surjective. Codomain is part of the function specification in typed mathematics.
Exercises
Easy
- Which are functions of \(x\)? \(y=x^2\), \(x=y^2\), \(y=\pm\sqrt{x}\).
- Domain of \(\dfrac{1}{x^2-1}\).
- If \(f(x)=3x-2\), find \(f(0)\), \(f(-1)\), \(f(a+1)\).
- Is \(f(x)=|x|\) even, odd, or neither?
- Evaluate piecewise: \(f(x)=1\) if \(x\ge 0\), else \(-1\) (sign-like); \(f(-2)\), \(f(0)\).
Medium
- Domain and range of \(f(x)=\sqrt{4-x^2}\) (think circle semicircle).
- Compute \(f\circ g\) and \(g\circ f\) for \(f(x)=1/x\), \(g(x)=x+1\) (note domains).
- Show \(f(x)=x^3+x\) is odd; is it injective on \(\mathbb{R}\)?
- Find inverse of \(f(x)=\frac{x-1}{x+1}\) (\(x\neq -1\)); give domain of inverse.
- Vertical line test: explain why a circle \(x^2+y^2=1\) is not \(y=f(x)\) as a whole.
- For \(f(x)=x^2-4x\), complete the square idea later—find vertex form optional; compute \(f(2)\).
- Graph reading (describe): if \(f\) increasing on \(\mathbb{R}\), can it have \(f(1)=f(2)\)?
- Codomain \(\{0,1\}\): give a surjective function from \(\mathbb{Z}\) (e.g. parity).
Hard / proof
- Prove: composition of two injective functions is injective.
- Prove: if \(f\) is invertible, its inverse is unique.
- Show \(f(x)=x^2\) is not injective on \(\mathbb{R}\) but is on \([0,\infty)\).
- Prove that if \(f\) is even and odd, then \(f(x)=0\) for all \(x\) in the (symmetric) domain.
- Define \(f:\{1,2,3\}\to\{a,b\}\) with \(f(1)=f(2)=a\), \(f(3)=b\). Image? Injective? Surjective?
- For \(f(x)=mx+b\) with \(m\neq 0\), prove bijective \(\mathbb{R}\to\mathbb{R}\) and find inverse.
- Explain horizontal line test from the definition of injectivity.
Challenge / CS-flavored
- Map
dictkeys to values: when is it a function? When injective? - Hash function \(h:U\to\{0,\ldots,m-1\}\): typically not injective—collisions.
clamp(x,a,b)piecewise; is it idempotent: \(\mathrm{clamp}(\mathrm{clamp}(x))=\)?
- Inverse of Celsius↔︎Fahrenheit functions—compose to identity.
- Complexity \(T(n)=n\log n\) as function \(\mathbb{Z}_{>0}\to\mathbb{R}\)—domain discrete.
Image and preimage
Image of \(S\subseteq A\): \(f(S)=\{f(s):s\in S\}\).
Preimage of \(T\subseteq B\): \(f^{-1}(T)=\{a\in A: f(a)\in T\}\) (defined even when \(f\) not invertible!).
Notation clash: \(f^{-1}\) for inverse function vs preimage—context decides.
Monotonicity
\(f\) increasing if \(x_1<x_2\Rightarrow f(x_1)\le f(x_2)\); strictly increasing with \(<\).
Strictly monotonic continuous functions on intervals are injective and invertible onto their images.
Piecewise continuity notes
Pieces may disagree at boundaries if not carefully defined—specify value at breakpoints. Example: \(f(x)=0\) for \(x<0\) and \(1\) for \(x\ge 0\) (Heaviside-like).
Composition associativity
\((f\circ g)\circ h=f\circ(g\circ h)\) when domains allow. Parentheses for order of application still read right-to-left inside \(\circ\) chains.
Extra exercises
- Prove: if \(f\) and \(g\) are surjective, so is \(f\circ g\) (when composable).
- Domain of \(\sqrt{1-x^{2}}+\log(x+2)\) (real).
- Is \(f(x)=x|x|\) even, odd, or neither?
- Find inverse of \(f(x)=\frac{2x+1}{x-3}\) (\(x\neq 3\)).
- Give a bijection from \(\mathbb{N}\) to \(\mathbb{Z}\) (formula or description).
CS connection
Pure functions, type signatures \(A\to B\), and partial functions (exceptions) match domain issues. Injectivity relates to uniqueness of decoding; surjectivity to covering all codes. Piecewise functions are if/else. Composition is pipelines.
Common pitfalls
| Pitfall | What to do instead |
|---|---|
| Confusing range and codomain | Range = actual outputs |
| Inverse of \(x^2\) as \(\pm\sqrt{x}\) multi-valued | Restrict domain for a function inverse |
| \(f^{-1}\) means \(1/f\) | Reciprocal is \(1/f\); inverse is undo |
| Composition order | \(f\circ g\) means apply \(g\) first |
| Even/odd without domain check | Need \(x\) and \(-x\) in domain |
| Graph is “the function” | Graph is a representation of the set of pairs |
Fully worked extra examples
E15 — Inverse computation carefully.
\(f(x)=\frac{2x-3}{x+1}\), \(x\neq -1\). Set \(y=\frac{2x-3}{x+1}\). \(y(x+1)=2x-3\), \(yx+y=2x-3\), \(yx-2x=-3-y\), \(x(y-2)=-(3+y)\), \(x=\frac{3+y}{2-y}\) for \(y\neq 2\). So \(f^{-1}(y)=\frac{y+3}{2-y}\). Domain of inverse: \(y\neq 2\) (range of \(f\) excludes \(2\) because \(2x-3=2(x+1)\Rightarrow -3=2\) impossible).
E16 — Even/odd decomposition idea.
Any \(f\) defined on symmetric domain: \(f_{e}(x)=\frac{f(x)+f(-x)}{2}\) even, \(f_{o}(x)=\frac{f(x)-f(-x)}{2}\) odd, and \(f=f_e+f_o\).
E17 — Piecewise absolute value.
\(|x-2|=\begin{cases}2-x&x<2\\ x-2&x\ge 2\end{cases}\). Graph V-shape vertex \((2,0)\).
E18 — Composition domain.
\(g(x)=\sqrt{x}\), \(f(x)=\frac{1}{x-1}\). \((f\circ g)(x)=\frac{1}{\sqrt{x}-1}\) needs \(x\ge 0\) and \(\sqrt{x}\neq 1\) so \(x\neq 1\).
End-of-day synthesis problems
S1. Domain of \(f(x)=\dfrac{\sqrt{x+2}}{x-1}\).
S2. Piecewise \(f(x)=x^{2}\) (\(x<1\)), \(3x\) (\(x\ge 1\)): evaluate \(f(0),f(1),f(2)\); is \(f\) a function?
S3. \(f(x)=2x+1\), \(g(x)=x^{2}\): compute \(f\circ g\), \(g\circ f\), and \((f\circ g)(3)\).
S4. Show \(f(x)=x^{3}-x\) is odd; determine injectivity on \(\mathbb{R}\) by testing values or derivative monotony idea.
S5. Inverse of \(f(x)=\frac{x+2}{3x-1}\) (\(x\neq\frac13\)); domain of inverse.
S6. Why \(y^{2}=x\) fails vertical line test as \(y\) in terms of \(x\)?
S7. Range of \(f(x)=1-x^{2}\) on \(\mathbb{R}\).
S8. Prove composition of injectives is injective.
Deep dive — Functions as APIs
| Math | Programming |
|---|---|
| Domain | Valid inputs (preconditions) |
| Codomain | Declared return type |
| Range | Values actually returned |
| Injectivity | Distinct inputs → distinct outputs (invertible encoding) |
| Surjectivity | Every codomain value hit |
| Composition | Pipeline / middleware |
| Partial function | Throws / Optional / partial map |
Hash maps are partial functions from keys to values. Partial application and currying are composition patterns. Type checkers enforce codomain contracts; runtime asserts enforce domain.
Synthesis
A function is a single-valued assignment—set of pairs with unique second components per first. Domain, codomain, and range are three different sets. Invertibility is bijectivity; graphs give vertical/horizontal line tests. Composition is apply-inner-first; even/odd probe symmetry. Everything later in analysis and CS types builds on this vocabulary.
S9. Prove: composition of two surjections (when composable) is surjective.
S10. Domain of \(\sqrt{x-2}+\frac{1}{x-5}\).
S11. Find inverse of \(f(x)=\frac{3x-1}{x+2}\) (\(x\neq -2\)); state domain of inverse.
S12. Decompose \(f(x)=x^3+x^2\) into even and odd parts.
Checkpoint
- Define function, domain, codomain, range
- Apply vertical line test; evaluate piecewise
- Compose functions; test even/odd
- Find inverse formulas when bijective
- Explain injectivity via horizontal line test
- S5 fully worked with domain
Write two takeaways in your own words.
Quick reference card
| Concept | Test / meaning |
|---|---|
| Function | unique output per input |
| Vertical line | graph test for \(y=f(x)\) |
| Horizontal line | injectivity on graph |
| Even / odd | \(f(-x)=\pm f(x)\) |
| Inverse | undo; needs bijective |
| Composition | \((f\circ g)(x)=f(g(x))\) |
| Domain of compose | \(g(x)\) in domain of \(f\) |
Tomorrow
Day 19 — Linear & quadratic functions. Slope-intercept, point-slope, parallel/perp; quadratic vertex form, discriminant, graphs, completing the square.