Set-builder notation
In set theory and its applications to logic, mathematics, and computer science, set-builder notation is a mathematical notation for describing a set by enumerating its elements or stating the properties that its members must satisfy.
Defining sets by properties is also known as set comprehension, set abstraction or as defining a set's intension.
Sets defined by enumeration
A set can be described directly by enumerating all of its elements between curly brackets, as in the following two examples:- is the set containing the four numbers 3, 7, 15, and 31, and nothing else.
- is the set containing,, and, and nothing else.
When it is desired to denote a set that contains elements from a regular sequence an ellipses notation may be employed, as shown in the next examples:
- is the set of integers between 1 and 100 inclusive.
- is the set of natural numbers.
- is the set of all integers.
In general, denotes the set of all natural numbers such that. Another notation for is the bracket notation. A subtle special case is, in which is equal to the empty set. Similarly, denotes the set of all for.
In each preceding example, each set is described by enumerating its elements. Not all sets can be described in this way, or if they can, their enumeration may be too long or too complicated to be useful. Therefore, many sets are defined by a property that characterizes their elements. This characterization may be done informally using general prose, as in the following example.
- addresses on Pine Street is the set of all addresses on Pine Street.
Sets defined by a predicate
Set-builder notation can be used to describe sets that are defined by a predicate, rather than explicitly enumerated. In this form, set-builder notation has three parts: a variable, a colon or vertical bar separator, and a logical predicate. Thus there is a variable on the left of the separator, and a rule on the right of it. These three parts are contained in curly brackets:or
The vertical bar, which can also be written as a colon, is a separator that can be read as "such that", "for which", or "with the property that". The formula is said to be the rule or the predicate. All values of x for which the predicate holds belong to the set being defined. All values of for which the predicate does not hold do not belong to the set. Thus is the set of all values of that satisfy the formula. It may be the empty set, if no value of satisfies the formula.
Specifying the domain
A domain can appear on the left of the vertical bar:or by adjoining it to the predicate:
The ∈ symbol here denotes set membership, while the symbol denotes the logical "and" operator, known as logical conjunction. This notation represents the set of all values of that belong to some given set for which the predicate is true. If is a conjunction, then is sometimes written, using a comma instead of the symbol.
In general, it is not a good idea to consider sets without defining a domain, as this would represent the subset of all possible things that may exist for which the predicate is true. This can easily lead to contradictions and paradoxes. For example, Russell's paradox shows that the expression although seemingly well formed as a set builder expression, cannot define a set without producing a contradiction.
In cases where the set E is clear from context, it may be not explicitly specified. It is common in the literature for an author to state the domain ahead of time, and then not specify it in the set-builder notation. For example, an author may say something such as, "Unless otherwise stated, variables are to be taken to be natural numbers."
Examples
The following examples illustrate particular sets defined by set-builder notation via predicates. In each case, the domain is specified on the left side of the vertical bar, while the rule is specified on the right side.- is the set of all strictly positive real numbers, which can be written in interval notation as.
- is the set. This set can also be defined as ; see [|equivalent predicates yield equal sets] below.
- For each integer m, we can define. As an example, and.
- is the set of pairs of real numbers such that y is greater than 0 and less than f, for a given function f. Here the cartesian product denotes the set of ordered pairs of real numbers.
- is the set of all even natural numbers. The sign stands for "and", which is known as logical conjunction. The ∃ sign stands for "there exists", which is known as existential quantification. So for example, is read as 'there exists an x such that P".
- is a notational variant for the same set of even natural numbers. It is not necessary to specify that is a natural number, as this is implied by the formula on the right.
- is the set of rational numbers; that is, real numbers that can be written as the ratio of two integers.
More complex expressions on the left side of the notation
For example:
- , where is the set of all natural numbers, is the set of all even natural numbers.
- , where is the set of all integers, is, the set of all rational numbers.
- is the set of odd integers.
- creates a set of pairs, where each pair puts an integer into correspondence with an odd integer.
Equivalent predicates yield equal sets
Two sets are equal if and only if they have the same elements. Sets defined by set builder notation are equal if and only if their set builder rules, including the domain specifiers, are equivalent. That isif and only if
Therefore, in order to prove the equality of two sets defined by set builder notation, it suffices to prove the equivalence of their predicates, including the domain qualifiers.
For example,
because the two rule predicates are logically equivalent:
This equivalence holds because, for any real number x, we have if and only if x is a rational number with. In particular, both sets are equal to the set.
Set existence axiom
In many formal set theories, such as Zermelo–Fraenkel set theory, set builder notation is not part of the formal syntax of the theory. Instead, there is a set existence axiom scheme, which states that if is a set and is a formula in the language of set theory, then there is a set whose members are exactly the elements of that satisfy :The set obtained from this axiom is exactly the set described in set builder notation as.
Parallels in programming languages
A similar notation available in a number of programming languages is the list comprehension, which combines map and filter operations over one or more lists.In Python, the set-builder's braces are replaced with square brackets, parentheses, or curly braces, giving list, generator, and set objects, respectively. Python uses an English-based syntax. Haskell replaces the set-builder's braces with square brackets and uses symbols, including the standard set-builder vertical bar.
The same can be achieved in Scala using Sequence Comprehensions, where the "for" keyword returns a list of the yielded variables using the "yield" keyword.
Consider these set-builder notation examples in some programming languages:
Example 1 | Example 2 | |
Set-builder | ||
Python | ||
Haskell | ||
Scala | ||
SQL |
The set builder notation and list comprehension notation are both instances of a more general notation known as monad comprehensions, which permits map/filter-like operations over any monad with a zero element.