Sub topic 7
The identity function as the do-nothing function
This chapter assumes you can read function notation such as f(x), state a domain and range, and evaluate a composite like (f∘g)(x). Those are the ideas from the previous chapters. Here you meet a function that changes nothing. It looks trivial, but the definition of an inverse function is built on it.
What the identity function is
The identity function returns whatever you give it. It is usually written id, or sometimes I:
id(x) = x
Its graph is the line y = x, a straight line through the origin with slope 1. The output always equals the input, so every point on the graph has equal coordinates, such as (−3, −3), (0, 0) and (7.5, 7.5).
def identity(x):
return x
print(identity(4)) # 4
print(identity("text")) # text
print(identity([1, 2])) # [1, 2]In algebra the inputs are numbers. The code shows that the rule works on any input, because it does nothing to the value.
Identity is tied to a domain
A function is more than a rule. It is a rule plus a domain. So there is a separate identity function for each set of inputs:
- id on all real numbers, written id_ℝ.
- id on the numbers x ≥ 0.
- id on the set {1, 2, 3}.
These have the same rule but are different functions, because their domains differ. This matters later. When we say "f⁻¹ undoes f", the identity we get back lives on a specific set, not on every number.
Identity in a composition
Composition feeds one function's output into another. Put the identity on either side and nothing changes:
- (f∘id)(x) = f(id(x)) = f(x)
- (id∘f)(x) = id(f(x)) = f(x)
So f∘id = f and id∘f = f. In the first case the identity hands x to f unchanged. In the second it receives f's output and passes it along unchanged.
This is the same job that 0 does for addition (a + 0 = a) and that 1 does for multiplication (a · 1 = a). Mathematicians call such an element a neutral element, or identity element, for the operation. For function composition, id is that element.
def identity(x):
return x
def compose(outer, inner):
return lambda x: outer(inner(x))
def f(x):
return 2 * x + 3
samples = [-2, 0, 5, 10]
for x in samples:
assert compose(f, identity)(x) == f(x)
assert compose(identity, f)(x) == f(x)
print("identity is neutral on", samples)Order does not matter here
Composition usually depends on order, as the earlier chapter on order showed. Composing with the identity is the exception. Both orders give f, so id commutes with every function (on matching domains).
The identity is also unique. Suppose another function e also satisfied e∘f = f for every f. Take f = id. Then e∘id = id. But e∘id = e, because id is neutral, so e = id. No second "do-nothing" function exists on a given domain.
Identity is not the same as other simple functions
Learners sometimes confuse the identity with functions that look similar. This table separates them.
| Function | Rule | Behaviour | Is it the identity? | Column | Column |
|---|---|---|---|---|---|
| Identity | id(x) = x | Output equals input for every x | Yes | ||
| Constant | c(x) = 5 | Same output for every input | No | ||
| Negation | n(x) = −x | Flips the sign | No, but n∘n = id | ||
| Squaring | s(x) = x² | Equals x only at x = 0 and x = 1 | No | ||
| Absolute value | a(x) = \ | x\ | Equals x only when x ≥ 0 | Only on the restricted domain x ≥ 0 |
Two functions are equal only if they agree on the same domain for every input. Agreeing at a few points is not enough. The function x² matches x at 0 and 1, yet it is clearly not the identity.
Fixed points are not the identity
A fixed point of a function f is an input x where f(x) = x. The identity has every point fixed. Other functions have only some. To find fixed points of f(x) = 2x + 3, solve 2x + 3 = x. This gives x = −3. Check: f(−3) = −6 + 3 = −3. This is where the graph of f crosses the line y = x.
This is a useful picture to keep. The line y = x is the graph of the identity, and any function's graph meets it exactly at that function's fixed points. The same line appears later as the mirror for inverse graphs.
Where the identity does its main work: inverses
An inverse function is defined using the identity. A function g is the inverse of f if composing them in either order gives the identity:
- g(f(x)) = x for every x in the domain of f.
- f(g(y)) = y for every y in the domain of g.
In compact form, g∘f = id and f∘g = id. This is the formal meaning of "undo". Applying f and then g takes you back to where you started, as though nothing had happened.
Here is the check for f(x) = 2x + 3, whose inverse is f⁻¹(y) = (y − 3)/2.
- f⁻¹(f(x)) = (2x + 3 − 3)/2 = 2x/2 = x.
- f(f⁻¹(y)) = 2 · (y − 3)/2 + 3 = (y − 3) + 3 = y.
Both compositions simplify to the input. The next chapters develop this check fully. The point here is that it is a test against the identity.
def f(x):
return 2 * x + 3
def f_inv(y):
return (y - 3) / 2
for x in [-4, 0, 1, 9]:
assert f_inv(f(x)) == x
assert f(f_inv(x)) == x
print("both compositions behave like id on the samples")Two identities, two domains
The two conditions use different identity functions:
- g∘f = id on the domain of f (the inputs of f).
- f∘g = id on the domain of g, which is the range of f (the outputs of f).
For f(x) = 2x + 3 on all real numbers, the domain and the range are both ℝ, so the two identities coincide. For other functions they differ. Take f(x) = x² restricted to x ≥ 0. Its range is y ≥ 0, and its inverse is √y.
- √(x²) = x for x ≥ 0. This is the identity on the domain of f.
- (√y)² = y for y ≥ 0. This is the identity on the range of f.
Outside those sets, the statement can fail. A common slip is writing √(x²) = x without a condition:
import math
for x in [3, 0, -3]:
print(x, math.sqrt(x ** 2))
# 3 3.0
# 0 0.0
# -3 3.0At x = −3 the result is 3, not −3. The composition equals the identity only on the restricted domain. Outside it, √(x²) = |x|.
Functions that undo themselves
Some functions are their own inverse. Applying them twice gives the identity: h∘h = id. These are called involutions. Three standard examples:
- Negation: −(−x) = x.
- Reciprocal: 1/(1/x) = x, for x ≠ 0.
- Subtraction from a constant: 1 − (1 − x) = x.
from fractions import Fraction
involutions = {
"negate": lambda x: -x,
"reciprocal": lambda x: 1 / x,
"one minus": lambda x: 1 - x,
}
for name, h in involutions.items():
for x in [Fraction(1, 2), Fraction(3), Fraction(-5, 4)]:
assert h(h(x)) == x
print(name, "undoes itself")The code uses exact fractions so that rounding error cannot hide a mistake. For an involution, h⁻¹ = h, so you never need to solve for an inverse. Look at the graph of any involution: it is symmetric across the line y = x. This is the reflection property that the later chapter on inverse graphs explains.
Common errors
- Confusing id with a constant. A constant function sends everything to one value. The identity sends each input to itself.
- Forgetting the domain. "id" without a domain is incomplete. When a problem restricts x, the identity is restricted too.
- Claiming g∘f = id after checking only one order. For functions on infinite domains, both compositions must be checked. Each one tests a different domain, as shown above.
- Treating "equals x at a few points" as "equals x". A single failing input, such as x = −3 for √(x²), is enough to show that a composite is not the identity there.
- Mixing up the identity with the multiplicative identity 1. The function id(x) = x is not the function 1(x) = 1. The second is a constant.
Summary of the role of the identity
- The identity function id(x) = x leaves every input unchanged, and its graph is the line y = x.
- It is the neutral element of composition: f∘id = id∘f = f.
- It is unique on a given domain.
- It defines inverses: g is the inverse of f exactly when g∘f and f∘g are both the identity on the right sets.
- Its graph, the line y = x, is the mirror used for inverse graphs and the place where a function's fixed points sit.
Exercise
Let f(x) = 3x − 6 and g(x) = (x + 6)/3, both on all real numbers. (a) Compute (g∘f)(x) and (f∘g)(x), simplifying fully. (b) What do your results say about g? (c) Is the function k(x) = √(x²) equal to id on all real numbers? State where it equals id.
Show answer
(a) (g∘f)(x) = (3x − 6 + 6)/3 = 3x/3 = x. (f∘g)(x) = 3 · (x + 6)/3 − 6 = (x + 6) − 6 = x. (b) Both compositions equal the identity, so g is the inverse of f, that is, g = f⁻¹. Because both domains and ranges are all real numbers, the identity holds everywhere. (c) No. √(x²) = |x|, which equals x only when x ≥ 0. For example, √((−3)²) = 3, not −3. So k equals id only on the restricted domain x ≥ 0.
Exercise
Show that f(x) = 5 − x is its own inverse, and name the kind of function this makes it.
Show answer
Compute f(f(x)) = 5 − (5 − x) = x. Since f∘f = id, f is its own inverse, f⁻¹ = f. A function with this property is called an involution. Its graph is symmetric across the line y = x.