Jump to content

Set-builder notation

From Wikipedia, the free encyclopedia
(Redirected fromSet builder notation)

The set of alleven integers,
expressed in set-builder notation.

Inset theoryand its applications tologic,mathematics,andcomputer science,set-builder notationis amathematical notationfor describing asetby enumerating itselements,or stating the properties that its members must satisfy.[1]

Defining sets by properties is also known asset comprehension,set abstractionor as defining a set'sintension.

Sets defined by enumeration

[edit]

Asetcan 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 containinga,b,andc,and nothing else (there is no order among the elements of a set).

This is sometimes called the "roster method" for specifying a set.[2]

When it is desired to denote a set that contains elements from a regular sequence, anellipsisnotation may be employed, as shown in the next examples:

  • is the set of integers between 1 and 100 inclusive.
  • is the set ofnatural numbers.
  • is the set of all integers.

There is no order among the elements of a set (this explains and validates the equality of the last example), but with the ellipses notation, we use an ordered sequence before (or after) the ellipsis as a convenient notational vehicle for explaining which elements are in a set. The first few elements of the sequence are shown, then the ellipses indicate that the simplest interpretation should be applied for continuing the sequence. Should no terminating value appear to the right of the ellipses, then the sequence is considered to be unbounded.

In general,denotes the set of all natural numberssuch that.Another notation foris the bracket notation.A subtle special case is,in whichis equal to theempty set.Similarly,denotes the set of allfor.

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 Streetis the set of all addresses on Pine Street.

However, the prose approach may lack accuracy or be ambiguous. Thus, set-builder notation is often used with a predicate characterizing the elements of the set being defined, as described in the following section.

Sets defined by a predicate

[edit]

Set-builder notation can be used to describe a set that is defined by apredicate,that is, a logical formula that evaluates totruefor an element of the set, andfalseotherwise.[3]In this form, set-builder notation has three parts: a variable, acolonorvertical barseparator, 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 theruleor thepredicate.All values ofxfor which the predicate holds (is true) belong to the set being defined. All values ofxfor which the predicate does not hold do not belong to the set. Thusis the set of all values ofxthat satisfy the formulaΦ.[4]It may be theempty set,if no value ofxsatisfies the formula.

Specifying the domain

[edit]

A domainEcan appear on the left of the vertical bar:[5]

or by adjoining it to the predicate:

The ∈ symbol here denotesset membership,while thesymbol denotes the logical "and" operator, known aslogical conjunction.This notation represents the set of all values ofxthat belong to some given setEfor which the predicate is true (see "Set existence axiom"below). Ifis a conjunction,thenis sometimes written,using a comma instead of the symbol.

In general, it is not a good idea to consider sets without defining adomain of discourse,as this would represent thesubsetofall possible things that may existfor which the predicate is true. This can easily lead to contradictions and paradoxes. For example,Russell's paradoxshows that the expressionalthough seemingly well formed as a set builder expression, cannot define a set without producing a contradiction.[6]

In cases where the setEis 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

[edit]

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 strictlypositivereal numbers,which can be written ininterval notationas.
  • is the set.This set can also be defined as;seeequivalent predicates yield equal setsbelow.
  • For each integerm,we can define.As an example,and.
  • is the set of pairs of real numbers such thatyis greater than 0 and less thanf(x),for a givenfunctionf.Here thecartesian productdenotes the set of ordered pairs of real numbers.
  • is the set of allevennatural numbers.Thesign stands for "and", which is known aslogical conjunction.The ∃ sign stands for "there exists", which is known asexistential quantification.So for example,is read as "there exists anxsuch thatP(x)".
  • is a notational variant for the same set of even natural numbers. It is not necessary to specify thatnis a natural number, as this is implied by the formula on the right.
  • is the set ofrational numbers;that is, real numbers that can be written as the ratio of twointegers.

More complex expressions on the left side of the notation

[edit]

An extension of set-builder notation replaces the single variablexwith anexpression.So instead of,we may havewhich should be read

.

For example:

  • ,whereis the set of all natural numbers, is the set of all even natural numbers.
  • ,whereis the set of all integers, isthe 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 replacetin the set builder notation to find

Equivalent predicates yield equal sets

[edit]

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 numberx,we haveif and only ifxis a rational number with.In particular, both sets are equal to the set.

Set existence axiom

[edit]

In many formal set theories, such asZermelo–Fraenkel set theory,set builder notation is not part of the formal syntax of the theory. Instead, there is aset existence axiom scheme,which states that ifEis a set andΦ(x)is a formula in the language of set theory, then there is a setYwhose members are exactly the elements ofEthat satisfyΦ:

The setYobtained from this axiom is exactly the set described in set builder notation as.

In programming languages

[edit]

A similar notation available in a number ofprogramming languages(notablyPythonandHaskell) is thelist comprehension,which combinesmapandfilteroperations over one or morelists.

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 inScalausing Sequence Comprehensions, where the "for" keyword returns a list of the yielded variables using the "yield" keyword.[7]

Consider these set-builder notation examples in some programming languages:

Example 1 Example 2
Set-builder
Python
{lforlinL}
{(k,x)forkinKforxinXifP(x)}
Haskell
[l|l<-ls]
[(k,x)|k<-ks,x<-xs,px]
Scala
for(l<-L)yieldl
for(k<-K;x<-XifP(x))yield(k,x)
C#
fromlinLselectl
fromkinKfromxinXwhereP(x)select(k,x)
SQL
SELECTlFROML_set
SELECTk,xFROMK_set,X_setWHEREP(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
[lforlL]
[(k,x)forkKforxXifP(x)]

The set builder notation and list comprehension notation are both instances of a more general notation known asmonad comprehensions,which permits map/filter-like operations over anymonadwith azero element.

See also

[edit]

Notes

[edit]
  1. ^Rosen, Kenneth (2007).Discrete Mathematics and its Applications(6th ed.). New York, NY: McGraw-Hill. pp. 111–112.ISBN978-0-07-288008-3.
  2. ^ Richard Aufmann, Vernon C. Barker, and Joanne Lockwood, 2007,Intermediate Algebra with Applications,Brooks Cole, p. 6.
  3. ^Michael J Cullinan, 2012,A Transition to Mathematics with Proofs,Jones & Bartlett, pp. 44ff.
  4. ^Weisstein, Eric W."Set".mathworld.wolfram.com.Retrieved20 August2020.
  5. ^"Set-Builder Notation".mathsisfun.com.Retrieved20 August2020.
  6. ^Irvine, Andrew David; Deutsch, Harry (9 October 2016) [1995]."Russell's Paradox".Stanford Encyclopedia of Philosophy.Retrieved6 August2017.
  7. ^"Sequence Comprehensions".Scala.Retrieved6 August2017.