Contents
Deep Breakdown
What it tells me (Situation Awareness): An open interval contains all real numbers strictly between and , excluding both endpoints. The parentheses signal that the boundaries are open, like a door that is left ajar: you can get arbitrarily close but never quite touch the edge. In DA/DS you encounter open intervals in mathematical proofs (where dividing by a quantity requires it to be strictly nonzero), in strict inequality filters, in the domain of functions like which require (not ), and in gradient descent convergence proofs.
Flowchart
Real-world use
Where it is used
Strict inequality filters, defining the valid domain of functions (e.g., requires ), probability density function supports (the Uniform distribution on excludes 0 and 1), and proofs where dividing by a quantity requires it to be strictly nonzero.
Problem it solves
The function is undefined at and for . Its domain is the open interval : you can get as close to 0 as you like, but itself is forbidden. A closed interval would be incorrect because is undefined (). The open interval specifies the true domain precisely.
How it solves the problem
uses parentheses to signal strict inequalities: . The endpoint values are excluded. This is exactly the condition you need when equality would cause a mathematical problem (undefined, division by zero, etc.).
Example in a business
The logistic function maps any real to the open interval . It never outputs exactly 0 or exactly 1 (only approaches them asymptotically). When computing cross-entropy loss , this matters: if could equal 0, you would have and the loss would be infinite. The open interval guarantees this never happens for finite inputs.
The formula, piece by piece
Breaking the notation:
- (open parenthesis on left): "open at the lower bound" — exclude .
- : the lower bound (not included in the interval).
- : the upper bound (not included in the interval).
- (close parenthesis on right): "open at the upper bound" — exclude .
- : "such that." Full set-builder definition:
Read: "The open interval from to is the set of all real numbers such that is strictly greater than AND strictly less than . Neither nor itself is included." Interval comparison summary:
| Notation | Meaning | included? | included? |
|---|---|---|---|
| Open | No | No | |
| Closed | Yes | Yes | |
| Left-closed, right-open | Yes | No | |
| Left-open, right-closed | No | Yes |
Note: in some countries and older textbooks, is used for the open interval. The parenthesis convention is now standard in most modern math and CS literature.
The formula in words
" means: is strictly greater than (cannot equal ) AND strictly less than (cannot equal ). Both conditions must hold. The boundary values themselves are forbidden." Think of a rope stretched between two poles: the closed interval includes the poles; the open interval includes only the rope between the poles, not the poles themselves.
Critical Concepts
- Parenthesis = exclude: and always mean the endpoint is NOT part of the set.
- Critical for domains: many functions (log, square root, reciprocal) have natural open-interval domains. is defined on , is defined on , is defined on .
- Probability distributions: the Uniform distribution on is technically open. The distinction rarely matters in practice, but it prevents for a continuous variable.
- Python's
range(a, b)is half-open: : includes , excludes . Parentheses vs. brackets map directly to this. - Numerical epsilon clipping: in code, to avoid , you clip values to for some small , which is an open interval approximated numerically.
Step-by-step calculation (tiny example)
Input: interval . Determine which of are members.
Step 1: Write the strict membership condition requires . Both strict inequalities must hold.
Step 2: Test each value
- : ? No. Not in the interval (boundary excluded).
- : ? Yes. In the interval.
- : ? Yes. In the interval.
- : ? No. Not in the interval (boundary excluded).
- : ? Yes. In the interval.
Step 3: Contrast with the closed version In , both and would be included. In they are not.
Code examples
Beginner example (Python)
# Check strict membership in an open interval (a, b)
a = 2
b = 5
test_values = [2.0, 2.001, 3.7, 5.0, 4.999]
for x in test_values:
in_interval = a < x < b # strict: both < (not <=) print(f"x = {x}: in ({a}, {b}) ? {in_interval}") # x = 2.0: in (2, 5) ? False (boundary excluded)
# x = 2.001: in (2, 5) ? True
# x = 3.7: in (2, 5) ? True
# x = 5.0: in (2, 5) ? False (boundary excluded)
# x = 4.999: in (2, 5) ? TrueBeginner example (R)
a <- 2
b <- 5
test_values <- c(2.0, 2.001, 3.7, 5.0, 4.999) # Strict inequalities: both > and <
in_interval <- test_values > a & test_values < b
names(in_interval) <- test_values
print(in_interval)
# 2 2.001 3.7 5 4.999
# FALSE TRUE TRUE FALSE TRUEProfessional example (Python)
import numpy as np
# Scenario: safe computation of cross-entropy loss
# Predictions must be in (0, 1) - open interval - to avoid log(0) = -infinity
def safe_cross_entropy(y_true: np.ndarray, y_pred: np.ndarray, epsilon: float = 1e-12) -> float:
"""
Binary cross-entropy loss with numerical safety clipping.
Clips y_pred to the open interval (epsilon, 1-epsilon) to ensure we never
compute log(0), which would be -infinity.
L = -mean(y * log(p) + (1-y) * log(1-p))
Parameters
----------
y_true : true binary labels (0 or 1)
y_pred : predicted probabilities (should be in (0, 1))
epsilon : small value defining the open interval lower/upper bound
Returns
-------
float: mean cross-entropy loss
"""
# Clip to open interval (epsilon, 1-epsilon)
# Without this, log(0) = -inf and log(1) = 0 which can cause issues
p = np.clip(y_pred, epsilon, 1 - epsilon)
return -np.mean(y_true * np.log(p) + (1 - y_true) * np.log(1 - p))
y_true = np.array([1, 0, 1, 1, 0])
y_pred_good = np.array([0.9, 0.1, 0.8, 0.7, 0.2])
y_pred_extreme = np.array([1.0, 0.0, 0.9, 0.8, 0.1]) # has exact 0 and 1
print(f"Good predictions loss: {safe_cross_entropy(y_true, y_pred_good):.4f}")
print(f"Extreme predictions loss: {safe_cross_entropy(y_true, y_pred_extreme):.4f}")
# Without clipping, y_pred_extreme would produce log(0) = -inf => loss = infProfessional example (R)
# Safe cross-entropy: clip predictions to (epsilon, 1-epsilon) to avoid log(0)
safe_cross_entropy <- function(y_true, y_pred, epsilon = 1e-12) {
p <- pmin(pmax(y_pred, epsilon), 1 - epsilon)
-mean(y_true * log(p) + (1 - y_true) * log(1 - p))
}
y_true <- c(1, 0, 1, 1, 0)
y_pred_good <- c(0.9, 0.1, 0.8, 0.7, 0.2)
y_pred_extreme <- c(1.0, 0.0, 0.9, 0.8, 0.1)
cat(sprintf("Good predictions loss: %.4f\n", safe_cross_entropy(y_true, y_pred_good)))
cat(sprintf("Extreme predictions loss: %.4f\n", safe_cross_entropy(y_true, y_pred_extreme)))Source: 1300 p. 13