Sub topic 7
Greatest-Integer and Ceiling Functions
This chapter assumes you can solve linear inequalities, plot points on the coordinate plane, and read function notation. It builds on the earlier chapters on function definition and graphs. It covers the floor and ceiling functions, their staircase graphs, the identities that CAT questions rely on, and the usual ways to go wrong.
The definitions
The greatest-integer function, also called the floor function, is written ⌊x⌋ or [x]. It gives the largest integer that is less than or equal to x.
The ceiling function, written ⌈x⌉, gives the smallest integer that is greater than or equal to x.
CAT papers usually write the floor as [x]. If a problem uses brackets, check whether the question means the greatest integer or just grouping.
| x | ⌊x⌋ | ⌈x⌉ |
|---|---|---|
| 2.7 | 2 | 3 |
| 5 | 5 | 5 |
| -2.3 | -3 | -2 |
| -0.5 | -1 | 0 |
| 0.0 | 0 | 0 |
The most common error is with negative numbers. The floor moves toward negative infinity, so ⌊-2.3⌋ is -3, not -2. Truncating the decimal part gives -2, which is the wrong answer.
import math
print(math.floor(2.7), math.floor(-2.3), math.ceil(-2.3))
print(math.floor(-0.5), math.ceil(-0.5))This prints 2 -3 -2 and then -1 0.
Fractional part
Every real number x splits into an integer part and a fractional part:
x = ⌊x⌋ + {x}, where 0 ≤ {x} < 1.
The fractional part {x} is never negative and never reaches 1. For x = -2.3, we have ⌊x⌋ = -3 and {x} = 0.7, because -3 + 0.7 = -2.3.
This identity is the main tool for equations that mix x with ⌊x⌋. Replace x by n + f, where n is an integer and 0 ≤ f < 1, and then solve for each part.
Core properties
These facts hold for all real x and integer n.
- ⌊x⌋ ≤ x < ⌊x⌋ + 1.
- ⌈x⌉ - 1 < x ≤ ⌈x⌉.
- ⌊x + n⌋ = ⌊x⌋ + n. Adding an integer shifts the output by that integer.
- ⌈x + n⌉ = ⌈x⌉ + n.
- ⌈x⌉ = ⌊x⌋ when x is an integer. Otherwise ⌈x⌉ = ⌊x⌋ + 1.
- ⌈x⌉ = -⌊-x⌋. This converts a ceiling into a floor.
- ⌊x⌋ + ⌊-x⌋ = 0 if x is an integer, and -1 otherwise.
- ⌊x⌋ = n exactly when n ≤ x < n + 1.
Property 8 is the one you will use most. It turns an equation about ⌊x⌋ into an inequality about x.
Note what is not true. ⌊x + y⌋ does not equal ⌊x⌋ + ⌊y⌋ in general. The correct relation is ⌊x⌋ + ⌊y⌋ ≤ ⌊x + y⌋ ≤ ⌊x⌋ + ⌊y⌋ + 1. For x = 0.6 and y = 0.7, the left side is 1 and the sum of floors is 0.
The staircase graph
The graph of y = ⌊x⌋ is a staircase. On each interval [n, n + 1), the value is the constant n. The graph is a horizontal segment at height n, with a closed (filled) dot at x = n and an open dot at x = n + 1.
The graph of y = ⌈x⌉ is also a staircase, but each step is on (n, n + 1]. The open dot is at the left end and the closed dot is at the right end.
The chart samples the function at half-integers, so it shows the plateaus but not the open and closed dots. Always draw the dots yourself on paper, because they decide which endpoint belongs to which step.
Key features of the floor graph:
- The function has jumps of size 1 at every integer. It is discontinuous at each integer.
- The function is non-decreasing but never strictly increasing.
- The domain is all real numbers, and the range is the set of integers.
- The graph lies on or below the line y = x. The gap y = x - ⌊x⌋ is the fractional part, which forms a sawtooth rising from 0 to just under 1.
The ceiling graph lies on or above the line y = x.
Worked example: solving with the interval rule
Solve ⌊2x - 1⌋ = 3.
By property 8, 3 ≤ 2x - 1 < 4. Add 1 to each part: 4 ≤ 2x < 5. Divide by 2: 2 ≤ x < 2.5.
The solution is the whole interval, not a single value. Many learners stop after finding one value that works.
Worked example: mixing x and its floor
Solve x² - 3⌊x⌋ = 4... first by substitution. Let n = ⌊x⌋, so n ≤ x < n + 1 and x² = 3n + 4.
Since x² ≥ 0, we need 3n + 4 ≥ 0, so n ≥ -1. Now test integer values of n.
- n = -1: x² = 1, so x = ±1. We need -1 ≤ x < 0, so x = -1 works.
- n = 0: x² = 4, x = ±2. We need 0 ≤ x < 1. Neither works.
- n = 1: x² = 7, x ≈ 2.65. We need 1 ≤ x < 2. It fails.
- n = 2: x² = 10, x ≈ 3.16. We need 2 ≤ x < 3. It fails.
- n = 3: x² = 13, x ≈ 3.61. We need 3 ≤ x < 4. It works.
- n = 4: x² = 16, x = 4. We need 4 ≤ x < 5. It works.
- n = 5: x² = 19, x ≈ 4.36. We need 5 ≤ x < 6. It fails, and larger n fail too because x² grows more slowly than the floor bound requires.
The solutions are x = -1, √13 and 4. Always check each candidate against its own interval, since the fixed n fixes which interval x must lie in.
import math
for x in [-1, math.sqrt(13), 4]:
print(x, x ** 2 - 3 * math.floor(x))Each line prints a value of 4 for the expression (up to floating-point rounding for √13).
Counting with the graph
Equations with floors can be counted by intersecting graphs. To count solutions of ⌊x⌋ = x/2, draw the staircase and the line y = x/2. The line passes through the origin with slope 1/2.
Because ⌊x⌋ = n requires x = 2n, we need n ≤ 2n < n + 1. This gives n ≥ 0 from the left side and n < 1 from the right side. So n = 0 and x = 0 is the only solution. Check with the graph: for x > 0 the line rises more slowly than 1 per unit, but it begins at the same height as the first step and then falls below the steps only after leaving them, so only the origin touches.
When counting, check each step separately. On each step the staircase is a horizontal segment, and a line with nonzero slope hits a horizontal segment at most once.
Applications with divisibility and counting
Floors appear in counting problems. The number of multiples of k that are at most N is ⌊N/k⌋. The number of integers between 1 and N inclusive that are divisible by 4 or 6 uses inclusion and exclusion with ⌊N/4⌋, ⌊N/6⌋ and ⌊N/12⌋.
The highest power of a prime p that divides N! is ⌊N/p⌋ + ⌊N/p²⌋ + ⌊N/p³⌋ + ... . For 100! and p = 5, this is 20 + 4 = 24, so 100! ends in 24 zeros.
The ceiling function appears when you round up a quantity such as the number of buses needed for N people with capacity c. That number is ⌈N/c⌉.
import math
N = 100
print(sum(N // 5 ** k for k in range(1, 4)))
print(math.ceil(130 / 40))This prints 24 and then 4.
Common errors
- Treating the floor of a negative decimal as truncation. ⌊-3.2⌋ is -4.
- Splitting ⌊x + y⌋ into ⌊x⌋ + ⌊y⌋.
- Giving a single value as the answer to an equation in ⌊x⌋ when the answer is an interval.
- Drawing a closed dot on the wrong end of a step. Floor steps are closed on the left, and ceiling steps are closed on the right.
- Forgetting to check that a candidate x lies in the interval [n, n + 1) that you assumed for n.
- Confusing the bracket [x] with ordinary grouping in a problem statement.
Exercise
Find all real x that satisfy ⌊x⌋ + ⌈x⌉ = 7, and give the value of ⌊3.5⌋ + ⌈-3.5⌉ as a check on your handling of negatives.
Show answer
If x is an integer, then ⌊x⌋ = ⌈x⌉ = x, so 2x = 7, which has no integer solution. So x is not an integer, and ⌈x⌉ = ⌊x⌋ + 1. Then 2⌊x⌋ + 1 = 7, so ⌊x⌋ = 3, which means 3 < x < 4 (x is not an integer). The solution set is 3 < x < 4. For the check, ⌊3.5⌋ = 3 and ⌈-3.5⌉ = -3, so the sum is 0.
Exercise
How many trailing zeros does 200! have?
Show answer
Trailing zeros equal the exponent of 5 in 200!, because factors of 2 are more plentiful. Compute ⌊200/5⌋ + ⌊200/25⌋ + ⌊200/125⌋ = 40 + 8 + 1 = 49. So 200! has 49 trailing zeros.