Rational Functions
A rational function is one polynomial divided by another. Dividing introduces something polynomials never have: places where the function blows up, and lines the graph approaches but never quite reaches. This lesson shows how to find these asymptotes and holes and sketch the graph from the formula.
Definition and domain
The domain is every with . The simplest example is : it is undefined at 0, huge for near 0, and tiny for large . Simplifying algebraic fractions is covered in Reducing Fractions; here we study the graphs.
Vertical asymptotes and holes
Factor numerator and denominator completely and cancel common factors.
- A zero of the denominator that survives cancellation is a vertical asymptote : as the values grow without bound ( or ).
- A zero that cancels is a hole: a single missing point in an otherwise smooth curve.
Horizontal and slant asymptotes
What happens for large depends on the degrees (top) and (bottom), since the leading terms dominate:
| Degrees | Behaviour for large | Example |
|---|---|---|
| horizontal asymptote | ||
| horizontal asymptote | ||
| slant (oblique) asymptote: the quotient of polynomial division | ||
| grows like a polynomial, no line asymptote |
Unlike vertical asymptotes, a graph may cross a horizontal asymptote; the asymptote only describes the far ends. crosses at .
import sympy as sp
x = sp.Symbol("x")
f = (x**2 - 1) / (x**2 - 3*x + 2)
print("simplified:", sp.cancel(f))
print("hole value at x=1:", sp.limit(f, x, 1))
print("near x=2: from left", sp.limit(f, x, 2, "-"), " from right", sp.limit(f, x, 2, "+"))
print("as x → ∞:", sp.limit(f, x, sp.oo))
g = (x**2 + 1) / (x - 1)
q, r = sp.div(sp.Poly(x**2 + 1, x), sp.Poly(x - 1, x))
print("slant asymptote of (x²+1)/(x−1): y =", q.as_expr(), " remainder", r.as_expr())simplified: (x + 1)/(x - 2)
hole value at x=1: -2
near x=2: from left -oo from right oo
as x → ∞: 1
slant asymptote of (x²+1)/(x−1): y = x + 1 remainder 2
So , and the last term shrinks to 0 for large . These limits are previewed in Introduction to Limits and done properly in limits at infinity.
Sketching a rational function
A checklist for :
- Factor, cancel, note holes.
- Vertical asymptotes: zeros of the reduced denominator.
- x-intercepts: zeros of the reduced numerator. y-intercept: , if defined.
- Horizontal or slant asymptote from the degrees.
- Signs: test a point in each interval between zeros and asymptotes.
Example: . Vertical asymptotes , x-intercepts , y-intercept , horizontal asymptote . The function is even, so the picture is symmetric.
import numpy as np
import matplotlib.pyplot as plt
f = lambda x: (2 * x**2 - 2) / (x**2 - 4)
x = np.linspace(-6, 6, 2400)
y = f(x)
y[np.abs(y) > 12] = np.nan # do not join across asymptotes
plt.figure(figsize=(6, 4))
plt.plot(x, y, color="purple")
for a in (-2, 2):
plt.axvline(a, color="gray", ls=":")
plt.axhline(2, color="orange", ls="--", lw=1, label="y = 2")
plt.axhline(0, color="black", lw=0.6)
plt.ylim(-10, 10); plt.legend(); plt.grid(alpha=0.3)
plt.title("(2x² − 2)/(x² − 4)")
print("f(0) =", f(0), " f(±1) =", f(1) + 0.0, f(-1) + 0.0, " f(100) =", round(f(100), 4))f(0) = 0.5 f(±1) = 0.0 0.0 f(100) = 2.0006
In software
Rational functions appear wherever a quantity is "something per something":
- Amdahl's law. If a fraction of a program can be parallelised over cores, the speedup is . Its horizontal asymptote is the hard limit on speedup, however many cores you add.
- Tone mapping. The Reinhard operator squeezes unbounded HDR brightness into : it has asymptote 1.
- Inverse-square falloff. Light, sound and gravity weaken like , which has a vertical asymptote at ; games clamp the distance or add a constant () to avoid dividing by zero.
- Averages and rates: cost per user, frames per second from milliseconds per frame (1000/ms).
def amdahl(p, n):
return 1 / ((1 - p) + p / n)
for n in (1, 2, 4, 16, 64, 1024):
print(f"{n:>5} cores: speedup {amdahl(0.9, n):6.3f}")
print("limit for p = 0.9:", round(1 / (1 - 0.9), 6))
reinhard = lambda L: L / (1 + L)
print("tone mapped:", [round(reinhard(L), 4) for L in (0.1, 1, 4, 50)]) 1 cores: speedup 1.000
2 cores: speedup 1.818
4 cores: speedup 3.077
16 cores: speedup 6.400
64 cores: speedup 8.767
1024 cores: speedup 9.913
limit for p = 0.9: 10.0
tone mapped: [0.0909, 0.5, 0.8, 0.9804]
With 90% parallel code you can never beat a 10× speedup.
Exercises
Exercise 1: Asymptotes and holes
For , find the domain, any holes and the vertical and horizontal asymptotes.
Answer
Domain . Hole at . Vertical asymptote . Horizontal asymptote .
Solution
import sympy as sp
x = sp.Symbol("x")
f = (x**2 + x - 6) / (x**2 - 4)
print(sp.cancel(f), sp.limit(f, x, 2), sp.limit(f, x, sp.oo))(x + 3)/(x + 2) 5/4 1
Exercise 2: Slant asymptote
Find the slant asymptote of .
Answer
.
Solution
Divide: , so . The fraction tends to 0, leaving .
Exercise 3: Build a function
Write a rational function with vertical asymptotes and , an x-intercept at 2, and horizontal asymptote .
Answer
One answer: .
Solution
The denominator must vanish at 1 and , the numerator at 2. gives . Any nonzero multiple also works.
Exercise 4: Signs
Solve .
Answer
.
Solution
Critical points: (zero, included since ) and (asymptote, never included).
Exercise 5: How many cores?
With Amdahl's law and , find the smallest number of cores giving a speedup of at least 10. What is the maximum possible speedup?
Answer
19 cores (speedup ). Maximum 20.
Solution
Solve : , so and .
amdahl = lambda p, n: 1 / ((1 - p) + p / n)
n = 1
while amdahl(0.95, n) < 10 - 1e-12:
n += 1
print(n, round(amdahl(0.95, n), 4), round(1 / 0.05, 4))19 10.0 20.0
Test yourself
What is the horizontal asymptote of ?
- There is none
. What happens at ?
- Vertical asymptote
- x-intercept
- A hole
- Nothing special
Can the graph of a rational function cross its horizontal asymptote?
- Never
- Yes, the asymptote only describes behaviour for large
- Only if it has no vertical asymptotes
- Only at