![Set-builder notation](https://www.english.nina.az/image-resize/1600/900/web/wikipedia.jpg)
expressed in set-builder notation.
In mathematics and more specifically in set theory, set-builder notation is a notation for specifying a set by a property that characterizes its members.
Specifying sets by member properties is allowed by the axiom of extensionality. This is also known as set comprehension and set abstraction.
Sets defined by a predicate
Set-builder notation can be used to describe a set that is defined by a predicate, that is, a logical formula that evaluates to true for an element of the set, and false otherwise. In this form, set-builder notation has three parts: a variable, a colon or vertical bar separator, and a 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 (or colon) is a separator that can be read as "such that", "for which", or "with the property that". The formula Φ(x) is said to be the rule or the predicate. All values of x for which the predicate holds (is true) belong to the set being defined. All values of x for which the predicate does not hold do not belong to the set. Thus is the set of all values of x that satisfy the formula Φ. It may be the empty set, if no value of x satisfies the formula.
Specifying the domain
A domain E 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 x that belong to some given set E for which the predicate is true (see "Set existence axiom" below). 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 of discourse, 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," though in less formal contexts where the domain can be assumed, a written mention is often unnecessary.
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(x), 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(x)".
is a notational variant for the same set of even natural numbers. It is not necessary to specify that n 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
An extension of set-builder notation replaces the single variable x with an expression. So instead of , we may have
which should be read
.
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.
When inverse functions can be explicitly stated, the expression on the left can be eliminated through simple substitution. Consider the example set . Make the substitution
, which is to say
, then replace t in the set builder notation to find
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 is
if 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 E is a set and Φ(x) is a formula in the language of set theory, then there is a set Y whose members are exactly the elements of E that satisfy Φ:
The set Y obtained from this axiom is exactly the set described in set builder notation as .
In programming languages
A similar notation available in a number of programming languages (notably Python and Haskell) is the list comprehension, which combines map and filter operations over one or more lists.
It has been suggested that parts of this page be moved into List comprehension. (Discuss) (December 2023) |
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 | {l for l in L} | {(k, x) for k in K for x in X if P(x)} |
Haskell | [l | l <- ls] | [(k, x) | k <- ks, x <- xs, p x] |
Scala | for (l <- L) yield l | for (k <- K; x <- X if P(x)) yield (k,x) |
C# | from l in L select l | from k in K from x in X where P(x) select (k,x) |
SQL | SELECT l FROM L_set | SELECT k, x FROM K_set, X_set WHERE P(x) |
Prolog | setof(L,member(L,Ls),Result) | setof((K,X),(member(K,Ks),member(X,Xs),call(P,X)),Result) |
Erlang | [L || L <- Ls] | [{K,X} || K <- Ks, X <- Xs, p(X)] |
Julia | [l for l ∈ L] | [(k, x) for k ∈ K for x ∈ X if P(x)] |
Mathematica | (l |-> l) /@ L | Cases[Tuples[{K, X}], {k_, x_} /; P[x]] |
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.
See also
- Glossary of set theory
Notes
- Rosen, Kenneth (2007). Discrete Mathematics and its Applications (6th ed.). New York, NY: McGraw-Hill. pp. 111–112. ISBN 978-0-07-288008-3.
- Michael J Cullinan, 2012, A Transition to Mathematics with Proofs, Jones & Bartlett, pp. 44ff.
- Weisstein, Eric W. "Set". mathworld.wolfram.com. Retrieved 20 August 2020.
- "Set-Builder Notation". mathsisfun.com. Retrieved 20 August 2020.
- Irvine, Andrew David; Deutsch, Harry (9 October 2016) [1995]. "Russell's Paradox". Stanford Encyclopedia of Philosophy. Retrieved 6 August 2017.
- "Sequence Comprehensions". Scala. Retrieved 6 August 2017.
n k Z n 2k displaystyle n mid exists k in mathbb Z n 2k The set of all even integers expressed in set builder notation In mathematics and more specifically in set theory set builder notation is a notation for specifying a set by a property that characterizes its members Specifying sets by member properties is allowed by the axiom of extensionality This is also known as set comprehension and set abstraction Sets defined by a predicateSet builder notation can be used to describe a set that is defined by a predicate that is a logical formula that evaluates to true for an element of the set and false otherwise In this form set builder notation has three parts a variable a colon or vertical bar separator and a 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 x F x displaystyle x mid Phi x or x F x displaystyle x Phi x The vertical bar or colon is a separator that can be read as such that for which or with the property that The formula F x is said to be the rule or the predicate All values of x for which the predicate holds is true belong to the set being defined All values of x for which the predicate does not hold do not belong to the set Thus x F x displaystyle x mid Phi x is the set of all values of x that satisfy the formula F It may be the empty set if no value of x satisfies the formula Specifying the domain A domain E can appear on the left of the vertical bar x E F x displaystyle x in E mid Phi x or by adjoining it to the predicate x x E and F x or x x E F x displaystyle x mid x in E text and Phi x quad text or quad x mid x in E land Phi x The symbol here denotes set membership while the displaystyle land symbol denotes the logical and operator known as logical conjunction This notation represents the set of all values of x that belong to some given set E for which the predicate is true see Set existence axiom below If F x displaystyle Phi x is a conjunction F1 x F2 x displaystyle Phi 1 x land Phi 2 x then x E F x displaystyle x in E mid Phi x is sometimes written x E F1 x F2 x displaystyle x in E mid Phi 1 x Phi 2 x using a comma instead of the symbol displaystyle land In general it is not a good idea to consider sets without defining a domain of discourse 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 x x x displaystyle x x not in x 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 though in less formal contexts where the domain can be assumed a written mention is often unnecessary 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 x R x gt 0 displaystyle x in mathbb R mid x gt 0 is the set of all strictly positive real numbers which can be written in interval notation as 0 displaystyle 0 infty x R x 1 displaystyle x in mathbb R mid x 1 is the set 1 1 displaystyle 1 1 This set can also be defined as x R x2 1 displaystyle x in mathbb R mid x 2 1 see equivalent predicates yield equal sets below For each integer m we can define Gm x Z x m m m 1 m 2 displaystyle G m x in mathbb Z mid x geq m m m 1 m 2 ldots As an example G3 x Z x 3 3 4 5 displaystyle G 3 x in mathbb Z mid x geq 3 3 4 5 ldots and G 2 2 1 0 displaystyle G 2 2 1 0 ldots x y R R 0 lt y lt f x displaystyle x y in mathbb R times mathbb R mid 0 lt y lt f x is the set of pairs of real numbers such that y is greater than 0 and less than f x for a given function f Here the cartesian product R R displaystyle mathbb R times mathbb R denotes the set of ordered pairs of real numbers n N k k N n 2k displaystyle n in mathbb N mid exists k k in mathbb N land n 2k is the set of all even natural numbers The displaystyle land 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 x P x displaystyle exists x P x is read as there exists an x such that P x n k N n 2k displaystyle n mid exists k in mathbb N n 2k is a notational variant for the same set of even natural numbers It is not necessary to specify that n is a natural number as this is implied by the formula on the right a R p Z q Z q 0 aq p displaystyle a in mathbb R mid exists p in mathbb Z exists q in mathbb Z q not 0 land aq p 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 notationAn extension of set builder notation replaces the single variable x with an expression So instead of x F x displaystyle x mid Phi x we may have f x F x displaystyle f x mid Phi x which should be read f x F x y x y f x F x displaystyle f x mid Phi x y mid exists x y f x wedge Phi x For example 2n n N displaystyle 2n mid n in mathbb N where N displaystyle mathbb N is the set of all natural numbers is the set of all even natural numbers p q p q Z q 0 displaystyle p q mid p q in mathbb Z q not 0 where Z displaystyle mathbb Z is the set of all integers is Q displaystyle mathbb Q the set of all rational numbers 2t 1 t Z displaystyle 2t 1 mid t in mathbb Z is the set of odd integers t 2t 1 t Z displaystyle t 2t 1 mid t in mathbb Z creates a set of pairs where each pair puts an integer into correspondence with an odd integer When inverse functions can be explicitly stated the expression on the left can be eliminated through simple substitution Consider the example set 2t 1 t Z displaystyle 2t 1 mid t in mathbb Z Make the substitution u 2t 1 displaystyle u 2t 1 which is to say t u 1 2 displaystyle t u 1 2 then replace t in the set builder notation to find 2t 1 t Z u u 1 2 Z displaystyle 2t 1 mid t in mathbb Z u mid u 1 2 in mathbb Z Equivalent predicates yield equal setsTwo 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 is x A P x x B Q x displaystyle x in A mid P x x in B mid Q x if and only if t t A P t t B Q t displaystyle forall t t in A land P t Leftrightarrow t in B land Q t 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 x R x2 1 x Q x 1 displaystyle x in mathbb R mid x 2 1 x in mathbb Q mid x 1 because the two rule predicates are logically equivalent x R x2 1 x Q x 1 displaystyle x in mathbb R land x 2 1 Leftrightarrow x in mathbb Q land x 1 This equivalence holds because for any real number x we have x2 1 displaystyle x 2 1 if and only if x is a rational number with x 1 displaystyle x 1 In particular both sets are equal to the set 1 1 displaystyle 1 1 Set existence axiomIn 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 E is a set and F x is a formula in the language of set theory then there is a set Y whose members are exactly the elements of E that satisfy F E Y x x Y x E F x displaystyle forall E exists Y forall x x in Y Leftrightarrow x in E land Phi x The set Y obtained from this axiom is exactly the set described in set builder notation as x E F x displaystyle x in E mid Phi x In programming languagesA similar notation available in a number of programming languages notably Python and Haskell is the list comprehension which combines map and filter operations over one or more lists It has been suggested that parts of this page be moved into List comprehension Discuss December 2023 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 2Set builder l l L displaystyle l l in L k x k K x X P x displaystyle k x k in K wedge x in X wedge P x Python l for l in L k x for k in K for x in X if P x Haskell l l lt ls k x k lt ks x lt xs p x Scala for l lt L yield l for k lt K x lt X if P x yield k x C from l in L select l from k in K from x in X where P x select k x SQL SELECT l FROM L set SELECT k x FROM K set X set WHERE P x Prolog setof L member L Ls Result setof K X member K Ks member X Xs call P X Result Erlang L L lt Ls K X K lt Ks X lt Xs p X Julia l for l L k x for k K for x X if P x Mathematica l gt l L Cases Tuples K X k x P x 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 See alsoGlossary of set theoryNotesRosen Kenneth 2007 Discrete Mathematics and its Applications 6th ed New York NY McGraw Hill pp 111 112 ISBN 978 0 07 288008 3 Michael J Cullinan 2012 A Transition to Mathematics with Proofs Jones amp Bartlett pp 44ff Weisstein Eric W Set mathworld wolfram com Retrieved 20 August 2020 Set Builder Notation mathsisfun com Retrieved 20 August 2020 Irvine Andrew David Deutsch Harry 9 October 2016 1995 Russell s Paradox Stanford Encyclopedia of Philosophy Retrieved 6 August 2017 Sequence Comprehensions Scala Retrieved 6 August 2017