BRAGA

02 Writing02-02 Notes02-02-003

Ceiling brackets

Published 16 Apr 20266 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
⌈x⌉\lceil x \rceil
(1)

Deep Breakdown

What it tells me (Situation Awareness): The ceiling function ⌈x⌉\lceil x \rceil rounds a number up to the nearest integer, always toward positive infinity. You use it any time you need the "minimum whole number that covers a quantity." Classic real-world examples: how many server instances do you need to handle nn requests if each handles kk? How many pages does a report have if each page fits kk rows and there are nn rows? You cannot have half a server. You round up.

Flowchart

YesNoInput: x (realnumber)Is x already aninteger?Output: x (nochange needed)Find floor of x:the largestinteger <= xAdd 1: ceiling =floor(x) + 1Output: smallestinteger = xResult: alwaysan integer,always = x

Real-world use

Where it is used

Resource allocation (batches, trucks, servers, API pages), computing pagination (how many pages for nn rows at kk per page), splitting datasets into chunks, and any time you divide items into groups and need to round up to avoid leaving items behind.

Problem it solves

You have 103 rows of data. You process them in batches of 10. 103/10=10.3103 / 10 = 10.3. You cannot send a partial batch. You need to know: how many full or partial batches do you need? The answer is 11, not 10. Direct rounding gives you the wrong answer (10.3 rounds to 10, losing the last 3 rows). Ceiling always gives the safe upper bound.

How it solves the problem

⌈10.3⌉=11\lceil 10.3 \rceil = 11. Always rounds toward +∞+\infty. The result covers every item: 10 full batches of 10, plus 1 partial batch of 3 = 11 total. Nothing is missed.

Example in a business

Computing how many API pages to fetch when paginating through a REST API response. If the endpoint returns k=100k = 100 records per page and the total is n=347n = 347, you need ⌈347/100⌉=⌈3.47⌉=4\lceil 347 / 100 \rceil = \lceil 3.47 \rceil = 4 requests. This is the standard formula in any data pipeline that fetches paginated data.

The formula, piece by piece

Breaking the notation:

  • ⌈\lceil and ⌉\rceil: the ceiling brackets. They look like square brackets with only the top bar (pointing upward). The visual hint is "round up."
  • xx: any real number.
  • Full definition: ⌈x⌉=min⁡{n∈Z∣n≥x}\lceil x \rceil = \min\{n \in \mathbb{Z} \mid n \geq x\} Read: "the ceiling of xx is the smallest integer nn that is greater than or equal to xx." Contrast with the floor function: ⌊x⌋=max⁡{n∈Z∣n≤x}\lfloor x \rfloor = \max\{n \in \mathbb{Z} \mid n \leq x\} (largest integer ≤x\leq x, i.e., round down).

Relationship: ⌊x⌋≤x≤⌈x⌉\lfloor x \rfloor \leq x \leq \lceil x \rceil always holds.

The formula in words

"Walk along the number line starting at xx, heading right (toward +∞+\infty). The first integer you hit is the ceiling of xx." Examples at a glance:

  • ⌈3.2⌉=4\lceil 3.2 \rceil = 4 (next integer to the right of 3.2 is 4)
  • ⌈7.0⌉=7\lceil 7.0 \rceil = 7 (already an integer, no movement needed)
  • ⌈−2.3⌉=−2\lceil -2.3 \rceil = -2 (heading right from −2.3-2.3, the first integer is −2-2, not −3-3)
  • ⌈−7.0⌉=−7\lceil -7.0 \rceil = -7 (already an integer) Watch the negative case: for negatives, ceiling is the one closer to zero.

Critical Concepts

  1. Direction is always toward +∞+\infty: ceiling never rounds toward zero or toward −∞-\infty. It always rounds up on the number line.
  2. Integers are unchanged: ⌈n⌉=n\lceil n \rceil = n for any integer nn.
  3. Negative numbers behave counterintuitively: ⌈−2.7⌉=−2\lceil -2.7 \rceil = -2, not −3-3. "Up" for a negative number means less negative (closer to zero).
  4. Ceiling vs. floor vs. round: round(10.3) = 10 (banker's rounding), floor(10.3) = 10, ceil(10.3) = 11. They are different functions for different needs.
  5. Batch count formula: num_batches=⌈n/k⌉\text{num\_batches} = \lceil n / k \rceil is the canonical way to compute how many complete-or-partial batches of size kk cover nn items.

Step-by-step calculation (tiny example)

Input: x=10.3x = 10.3, compute ⌈10.3⌉\lceil 10.3 \rceil.

Step 1: Check if x is already an integer 10.310.3 has a decimal part (0.3≠00.3 \neq 0), so it is not an integer. We need to round up.

Step 2: Find the floor (round down) ⌊10.3⌋=10\lfloor 10.3 \rfloor = 10. The largest integer that does not exceed 10.310.3 is 1010.

Step 3: Add 1 to get the ceiling ⌈10.3⌉=10+1=11\lceil 10.3 \rceil = 10 + 1 = 11. Verify: Is 1111 the smallest integer ≥10.3\geq 10.3? Yes. Is 10≥10.310 \geq 10.3? No. So 1111 is correct.

Code examples

Beginner example (Python)

python
import math   # math.ceil() is the ceiling function in Python
print(math.ceil(10.3))   # 11
print(math.ceil(7.0))   # 7 (already integer)
print(math.ceil(-2.3))   # -2 (negative: rounds toward zero = upward)
print(math.ceil(-7.0))   # -7 # Batch count formula
total_rows = 103
batch_size = 10
num_batches = math.ceil(total_rows / batch_size)
print(f"Batches needed: {num_batches}")   # 11

Beginner example (R)

r
library(base)  # ceiling() is base R, no import needed
print(ceiling(10.3))  # 11
print(ceiling(7.0))  # 7
print(ceiling(-2.3))  # -2 # Batch count formula in R
total_rows <- 103
batch_size <- 10
num_batches <- ceiling(total_rows / batch_size)
print(num_batches)  # 11

Professional example (Python)

python
import math
import pandas as pd   # Scenario: paginating through a REST API to fetch all customer records
RECORDS_PER_PAGE = 100
total_records = 347   # obtained from API metadata response
num_pages = math.ceil(total_records / RECORDS_PER_PAGE)
print(f"Total records: {total_records}")
print(f"Records per page: {RECORDS_PER_PAGE}")
print(f"Pages to fetch: {num_pages}")   # 4 # Simulate the page sizes (last page may be partial)
page_sizes = []
for page in range(1, num_pages + 1):
    records_fetched = min(RECORDS_PER_PAGE, total_records - (page - 1) * RECORDS_PER_PAGE)
page_sizes.append({"page": page, "records_on_page": records_fetched})
df_pages = pd.DataFrame(page_sizes)
print(df_pages)
# Page 1: 100, Page 2: 100, Page 3: 100, Page 4: 47
# Batch processing in a DataFrame
df = pd.DataFrame({"row_id": range(1, total_records + 1)})
df["batch"] = ((df["row_id"] - 1) // RECORDS_PER_PAGE) + 1
print(f"Unique batches: {df['batch'].nunique()}")   # 4

Professional example (R)

r
# Scenario: paginating through a REST API to fetch all customer records
RECORDS_PER_PAGE <- 100
total_records <- 347
num_pages <- ceiling(total_records / RECORDS_PER_PAGE)
cat("Total records: ", total_records, "\n")
cat("Records per page:", RECORDS_PER_PAGE, "\n")
cat("Pages to fetch: ", num_pages, "\n")  # Simulate page sizes (last page may be partial)
page_sizes <- data.frame( page = seq_len(num_pages), records_on_page = sapply(seq_len(num_pages), function(p) { min(RECORDS_PER_PAGE, total_records - (p - 1) * RECORDS_PER_PAGE) })
)
print(page_sizes)  # Batch processing in a data.frame
df <- data.frame(row_id = seq_len(total_records))
df$batch <- ((df$row_id - 1) %/% RECORDS_PER_PAGE) + 1
cat("Unique batches:", length(unique(df$batch)), "\n")

Source: AIO p. 30 of 286

#foundations#maths-symbols#algebra

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close