Textbook
The expression $B:=\{x\in A\mid P(x)\}$ defines the set of elements of $A$ for which the predicate $P(x)$ is true. A predicate is a condition whose truth is determined after choosing its argument. The bar means “such that”; a colon is also used.
The set $A$ supplies the candidate domain, and the condition decides whether to retain each candidate. Thus $\{x\in\{2,4,6\}\mid x>2\}=\{4,6\}$. The result is a set, with neither duplicates nor listing order. The notation does not specify a program or an iteration order.
For any object $y$, membership in the result requires both $y\in A$ and truth of $P(y)$. A consistently renamed bound variable changes nothing: $\{x\in A\mid P(x)\}=\{t\in A\mid P(t)\}$. Renaming the variable must not alter the condition itself. If no candidate satisfies it, the result is empty; if every candidate does, the result is $A$. Both are ordinary outcomes of the same selection rule.
Definitions and further reading: Mathematics for Computer Science.
In plain language
Set-builder notation resembles a filter over a specified box: the domain supplies candidates, and the rule retains those that qualify. A red ball on the next table cannot enter a selection of red pencils, even with the right colour. The condition creates no new elements, so the result is a subset of $A$; without a stated domain, an inventory turns into an expedition. Iteration pictures a finite box, but the notation itself does not promise a finished inspection in finite time.
Example
The example selects numbers greater than 2 from the illustrative set $A=\{2,4,6\}$. The accumulated result grows while the candidate domain stays fixed.
Set-Builder Notation: Filtering Elements
Testing 2
The inequality is strict: equality does not qualify.
Step 1 of 3: Testing 2
Read all steps
Testing 2
The inequality is strict: equality does not qualify.
- State
- 2excluded46
Testing 4
Four passes the filter.
- State
- 2excluded4included6
Testing 6
Six also passes; the result contains 4 and 6.
- State
- 2excluded4included6included
Two is rejected because the comparison is strict, not because it appears first. Four and six survive because they belong to the original set and exceed two. Five also exceeds two, but is absent from $A$ and cannot be added. Checking the result requires both directions: every retained element passes the filter, and every qualifying element from the original domain has been retained.
Related concepts: Predicates.