BRAGA

02 Writing02-02 Notes02-02-007

Equivalence

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
≡\equiv
(1)

Deep Breakdown

What it tells me (Situation Awareness): ≡\equiv (the triple bar) signals identity or equivalence: the statement is true for all values of the variable, not just some. It is also used for modular congruence in number theory (a≡b(modm)a \equiv b \pmod{m} means aa and bb have the same remainder when divided by mm). In DA/DS, you most commonly encounter ≡\equiv in algebraic identities that underpin model derivations, in formal proofs, and in hashing/indexing where modular arithmetic governs bucket assignment.

Flowchart

Algebra / trigonometry /calculusNumber theory / hashing /modular arithmeticEncounter thesymbol triple-bar(equiv)What is thecontext?Identity: true forALL values ofthe variableModularcongruence:same remaindermod mExample: sin^2theta + cos^2theta equiv 1 forany thetaExample: 17equiv 2 (mod 5)because 17 =3*5 + 2Can substitutefreely in anyderivationUsed for hashbucketassignment,cyclical indexing

Real-world use

Where it is used

In ML paper derivations where an expression is simplified by applying a known identity; in modular arithmetic for hash table indexing (assigning rows to buckets); in SQL when verifying that two expressions always produce the same result regardless of input.

Problem it solves

A plain == could mean "this happens to be true for this specific value." ≡\equiv says "this is always true, no matter what you plug in." That distinction matters in proofs: you can replace one side with the other unconditionally anywhere in a derivation.

How it solves the problem

sin⁡2θ+cos⁡2θ=1\sin^2\theta + \cos^2\theta = 1 is only an equation for specific θ\theta values... except it is actually an identity. Writing sin⁡2θ+cos⁡2θ≡1\sin^2\theta + \cos^2\theta \equiv 1 communicates: this holds for every θ∈R\theta \in \mathbb{R}. You can use it as a substitution rule.

Example in a business

Hash partitioning: assigning a customer ID to one of kk database shards using shard_id≡customer_id(modk)\text{shard\_id} \equiv \text{customer\_id} \pmod{k}. This assigns customer IDs cyclically and deterministically. Every time you compute this, the same customer gets the same shard.

The formula, piece by piece

Breaking the notation:

  • ≡\equiv: triple bar (three horizontal lines). The extra line signals "stronger than equality."
  • Two uses: **1.

Identity (all-values equality):**

f(x)≡g(x)meansf(x)=g(x) for all x in the domainf(x) \equiv g(x) \quad \text{means} \quad f(x) = g(x) \text{ for all } x \text{ in the domain}
(2)

Example: (x+1)2≡x2+2x+1(x+1)^2 \equiv x^2 + 2x + 1 is an identity. True for every xx. 2. Modular congruence:

a≡b(modm)meansm∣(a−b)(m divides a - b evenly)a \equiv b \pmod{m} \quad \text{means} \quad m \mid (a - b) \quad \text{(m divides a - b evenly)}
(3)

Equivalently: aa and bb give the same remainder when divided by mm. Example: 17≡2(mod5)17 \equiv 2 \pmod{5} because 17=3×5+217 = 3 \times 5 + 2 and 2=0×5+22 = 0 \times 5 + 2. Both leave remainder 2.

The formula in words

Identity: "f(x)≡g(x)f(x) \equiv g(x)" means "these two expressions are the same thing for every possible input. They are different ways of writing the same rule." Modular congruence: "a≡b(modm)a \equiv b \pmod{m}" means "when you divide aa by mm and divide bb by mm, you get the same remainder. They are 'the same position on a clock with mm hours.'" The clock analogy: on a 12-hour clock (m=12m = 12), 13:00 ≡\equiv 1:00 (mod12)\pmod{12} because 13−1=1213 - 1 = 12, which is divisible by 12. Both point to the same position.

Critical Concepts

  1. Identity vs. equation: an equation (==) may hold for specific values; an identity (≡\equiv) holds for all values in the domain.
  2. Trigonometric identities: sin⁡2θ+cos⁡2θ≡1\sin^2\theta + \cos^2\theta \equiv 1 is used constantly in ML derivations, particularly in normalization and probability proofs.
  3. Modular arithmetic in hashing: hash tables, partitioned databases, and consistent hashing all rely on modular congruence to distribute data evenly.
  4. Python's % operator: computes the modulo (remainder). 17%5=217 \% 5 = 2 confirms 17≡2(mod5)17 \equiv 2 \pmod{5}.
  5. == in code is NOT ≡\equiv: == tests if two values happen to be equal for specific inputs.

Mathematical ≡\equiv claims it for all inputs.

Step-by-step calculation (tiny example)

Task: verify that 17≡2(mod5)17 \equiv 2 \pmod{5}.

Step 1: Divide 17 by 5 and find the remainder 17=3×5+217 = 3 \times 5 + 2. Quotient is 3, remainder is 2.

Step 2: Divide 2 by 5 and find the remainder 2=0×5+22 = 0 \times 5 + 2. Quotient is 0, remainder is 2.

Step 3: Compare remainders Both give remainder 2. Therefore 17≡2(mod5)17 \equiv 2 \pmod{5}. Confirmed: 5∣(17−2)=15=3×55 \mid (17 - 2) = 15 = 3 \times 5.

Code examples

Beginner example (Python)

python
# Modular equivalence using Python's % operator
# Verify 17 equiv 2 (mod 5)
print(17 % 5)   # 2
print(2 % 5)   # 2
print((17 - 2) % 5 == 0)   # True: 5 divides (17-2)=15 # Practical: assign rows to one of 4 buckets
row_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
num_buckets = 4
buckets = [row_id % num_buckets for row_id in row_ids]
print(buckets)   # [0, 1, 2, 3, 0, 1, 2, 3, 0, 1] - cycles through 0,1,2,3

Beginner example (R)

r
# Modular equivalence using R's %% operator # Verify 17 equiv 2 (mod 5)
print(17 %% 5)  # 2
print(2 %% 5)  # 2
print((17 - 2) %% 5 == 0)  # TRUE # Assign rows to buckets
row_ids <- 0:9
num_buckets <- 4
buckets <- row_ids %% num_buckets
print(buckets)  # 0 1 2 3 0 1 2 3 0 1

Professional example (Python)

python
import pandas as pd
import numpy as np   # Scenario: hash-based cross-validation fold assignment
# Each customer is assigned to one of k folds deterministically
# based on their customer_id using modular congruence
np.random.seed(42)
customer_ids = np.random.randint(10_000, 99_999, size=1000)
K_FOLDS = 5   # customer_id equiv fold_id (mod k)
fold_assignments = customer_ids % K_FOLDS
df = pd.DataFrame({ "customer_id": customer_ids, "fold": fold_assignments,
})
print("Fold distribution:")
print(df["fold"].value_counts().sort_index())
# Each fold gets approximately 200 customers (balanced by modular arithmetic)
# Use fold 0 as holdout set, folds 1-4 as training
holdout = df[df["fold"] == 0]
training = df[df["fold"] != 0]
print(f"\nHoldout size: {len(holdout)}")   # ~200
print(f"Training size: {len(training)}")   # ~800
print("Deterministic: same customer always goes to same fold regardless of run order.")

Professional example (R)

r
# Scenario: hash-based cross-validation fold assignment
# customer_id equiv fold_id (mod k)
set.seed(42)
customer_ids <- sample(10000:99999, 1000, replace = TRUE)
K_FOLDS <- 5
fold_assignments <- customer_ids %% K_FOLDS
df <- data.frame( customer_id = customer_ids, fold = fold_assignments
) cat("Fold distribution:\n")
print(table(df$fold))
holdout <- df[df$fold == 0, ]
training <- df[df$fold != 0, ]
cat("\nHoldout size: ", nrow(holdout), "\n")
cat("Training size:", nrow(training), "\n")
cat("Deterministic: same customer always goes to same fold.\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