|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| In [[set theory]] and its applications to [[logic]], [[mathematics]], and [[computer science]], '''set-builder notation''' is a [[mathematical notation]] for describing a [[Set (mathematics)|set]] by stating the properties that its members must satisfy.<ref>{{cite book | last=Rosen| first=Kenneth| year=2007 | title=[[Discrete Mathematics and its Applications]] | edition=6th | publisher=McGraw-Hill | location=New York, NY | isbn=978-0-07-288008-3| pages=111–112}}</ref> Forming sets in this manner is also known as '''set comprehension''', '''set abstraction''' or as defining a set's '''[[intension]]'''. Although some simply refer to it as ''set notation,'' that label may be better reserved for [[set notation|the broader class of means of denoting sets]].
| | Their author is known via name of Gabrielle Lattimer though she [http://Answers.Yahoo.com/search/search_result?p=doesn%27t+tremendously&submit-go=Search+Y!+Answers doesn't tremendously] like being called like this. To bake is something that jane is been doing for growth cycles. Her job would be a cashier but rather quickly her husband and the actual will start their own business. She's always loved living into South Carolina. She is running and exercising a blog here: http://prometeu.net<br><br>Here is my weblog: [http://prometeu.net hack clash of clans gems] |
| | |
| == Building sets ==
| |
| Let Φ(''x'') be a [[well-formed formula|formula]] in which the variable ''x'' appears [[free variable|free]]. Set builder notation has the form {''x'' : Φ(''x'')} or {''x'' | Φ(''x'')}, denoting the set of all individuals in the [[universe of discourse]] satisfying the [[Predicate (logic)|formula]] Φ(''x''), that is, the set whose members are every individual x such that Φ(x) is true: formally, the [[Extension (predicate logic)|extension]] of the predicate. Φ(''x'') is here referred to as the rule. Sometimes the universe of discourse is established within the notation; writing <math>\{x \in \mathrm{U} | \Phi(x)\}</math>, <math>\{x | x \in \mathrm{U} \land \Phi(x)\}</math> or <math>\{x \in \mathrm{U} : \Phi(x)\}</math> establishes that the universe of discourse is <math>\mathrm{U}</math> for purposes of the set being built. Set builder notation [[bound variable|binds]] the variable ''x'' and must be used with the same care applied to variables bound by [[quantifier]]s. Unless specifically stated the variable is universally quantified over the rule, which means we include in the set all possible values for the variable for which the rule is true.
| |
| | |
| Examples:
| |
| * <math>\{ 3, 7, 15, 31\}</math> is a set holding the four numbers 3, 7, 15, and 31.
| |
| * <math>\{ 0, 1, 2, \ldots\}</math> is the set of [[natural numbers]].
| |
| * <math>\{ 1, 2, 3, \ldots, 100 \}</math> is the set of integers between 1 and 100 inclusive.
| |
| * <math>\{a, b, c\}</math> is the set containing 'a','b', and 'c'.
| |
| * <math>\{ x ~|~ x \in \mathbf R \land x = x^2 \} \,\!</math> is the set <math>\{0, 1\}</math>,
| |
| * <math>\{ x ~|~ x \in \mathbf R \land x > 0\}</math> is the set of all [[positive number|positive]] [[real numbers]].
| |
| * <math>\{ (x,y) ~|~ 0 < y < f(x) \}</math> is the set of (x,y) such that y is greater than 0 and less than f(x).
| |
| * <math>\{k ~|~ (\exists n \in \mathbf{N}) \land (k = 2n)\}</math> is the set of all [[even number|even]] [[natural numbers]],
| |
| * <math>\{a ~|~ (\exists p, q \in \mathbf{Z}) \land (q \not = 0 \land aq=p) \}</math> is the set of [[rational number]]s; that is, numbers that can be written as the ratio of two [[integers]].
| |
| * <math>\mathbf{N}_m = \{ x ~|~ x \in \mathbf{Z} \land x \ge m \} = \{ m, m + 1, m + 2, \ldots\}.</math> Thus, e.g., <math>x_1 = m,\ x_2 = m + 1</math>, etc. ([[Nota bene|n.b.]]: in the case of sets, the order is not important; <math>x_1 = m + 2</math> could be used). As an example, <math>\mathbf{N}_3 = \{x ~|~ x \in \mathbf{Z} \land x \ge 3 \} = \{ 3, 4, 5, \ldots\}.</math>
| |
| | |
| The [[ellipsis|ellipses]] means 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.
| |
| | |
| The vertical bar or colon is read as "such that", and it separates the variables list on the left from the rule for assigning values to those variables on the right. Oftentimes the rule on the right is a formal logic predicate. However it can be anything that is clear to readers including simple prose. When the meaning is clear the <math>~|~</math> and the rule may be omitted.
| |
| | |
| When the rule is a predicate then [[formal logic]] connectors may be used within the rule. For example, the <math>\and</math> sign stands for ''and'', requiring both clauses to the left of it and to the right of it to be 'true'. As another example, The <math>\exists</math> sign stands for "there exists" and is formally known as [[existential quantification]]. Sometimes multiple rules are given separated by a comma (,) or semicolon (;), in this case we take the rules in conjunction, i.e. we interpret the comma or semicolon to mean the same as <math>\and</math>.
| |
| | |
| The <math>\in</math> sign denotes set [[Set (mathematics)#Membership|membership]], and can be read as "member of" or informally as "in". In a predicate a clause of the form <math> x \in \{1, 2, 3\} </math> is either true or false, or when used as a constraint means that <math> x </math> can only be one of the values 1, 2, or 3.
| |
| | |
| When the domain over which the set is defined is already clear it is not necessary to provide it within the rule clause. One could say something such as, "The universe of discourse can be taken to be the set of [[real number]]s, where not specified inside the notation:" and then write:
| |
| | |
| * <math>\{ x ~|~ x = x^2 \} \,\!</math> is the set <math>\{0, 1\}</math>
| |
| | |
| Rather than the fuller form as shown in the original example given above.
| |
| | |
| One can also use an expression in the variable list. For example:
| |
| | |
| * <math>\{ 2 t + 1 ~|~ t \in \mathbf Z\}</math> is the set of odd integers.
| |
| * <math>\{ (t, 2 t + 1) ~|~ t \in \mathbf Z\}</math> creates a set of pairs, where each pair puts an integer into correspondence with an odd integer.
| |
| * <math>\{ 2 x + 1 = 5 ~|~ x \in \mathbf N \}</math> is the set <math>\{ true, false \} </math> because the expression <math> 2 x + 1 = 5 </math> evaluates to either true or false given the various natural numbers.
| |
| | |
| It is common in the literature to place the domain qualifiers with the variable expression.
| |
| | |
| * <math>\{ x \in \mathbf R ~|~ x = x^2 \} \,\!</math> is the set <math>\{0, 1\}</math>,
| |
| | |
| == Equivalent Builder Predicates means Equivalent Sets ==
| |
| | |
| Two sets are equal if and only if their set builder rules, including the domain specifiers, are [[logically equivalent]]. For example, <math> \{ x \in \mathbf{R} | x^2 = 1 \} = \{ x \in \mathbf{R} | \ |x| = 1 \} </math> because, for any real number ''x'', ''x''<sup>2</sup> = 1 if and only if |''x''| = 1. Note, had the domain specifiers in the rule stipulated complex numbers, mixed complex and real domains, or a number of other possibilities, the two sets in this example would not be equal.
| |
| | |
| We can state this result more formally by considering two generic sets, namely, the set of elements created from set builder predicate ''P'',
| |
| *<math> A = \{ x | P(x) \} </math>,
| |
| and the set of elements created by set builder predicate ''Q'', | |
| *<math> B = \{ x | Q(x) \} </math>.
| |
| Then sets A and B will be equal if
| |
| *<math> \forall t: P(t) = Q(t) </math>.
| |
| | |
| == Russell's paradox ==
| |
| Let <math>R = \{S ~|~ S \notin S\}</math> denote the set ''R'' of all sets ''S'' that do not contain themselves. Now lets ask a question about ''R''. Does this set contain itself? I.e. can it be one of the elements ''S''? If ''R'' does not contain itself, then according to the set builder rule it fits the criteria for being an ''S'' element, so it should be in ''R''; however, if it is in ''R'' then it contains itself! We arrive at a contradiction. Lets take the opposite case, that ''R'' contains itself, then by definition it should not be in the set ''R''. Another contradiction! According to the constructs of Whitehead's set theory, all elements are either in a set, or not in a set, but here using the same theory, [[Bertrand Russell]] shows an example of element, ''R'' which can not be either. The inconsistency in the existence of this set is known as [[Russell's paradox]].
| |
| | |
| It is possible to avoid this paradox by restricting the richness in expressive power of the original set theory. To illustrate this in terms of our notation, let ''X'' = {''x'' ∈ ''A'' | ''P''(''x'')} denote the set of every element of ''A'' satisfying the predicate ''P''(''x''). The canonical restriction on set builder notation asserts that ''X'' is a set only if ''A'' is already known to be a set. This restriction is codified in the [[axiom schema of separation]] present in standard [[axiomatic set theory]]. Note that this [[axiom schema]] excludes ''R'' from sethood.
| |
| | |
| == Variations ==
| |
| | |
| === Terms more complicated than a single variable ===
| |
| Another variation on set-builder notation replaces the single variable ''x'' with a [[First order logic#Terms|term]] ''T'' which may include one or more variables, combined with functions acting on them. So instead of {{nowrap|{''x'' : Φ(''x'')}}}, we would have {{nowrap|{''T'' : Φ(''x''<sub>1</sub> ... ''x''<sub>n</sub>)}}}, where ''T'' is a term involving variables ''x''<sub>1</sub> through ''x''<sub>n</sub>.
| |
| For example:
| |
| * {2''n'' : ''n'' ∈ '''N'''}, where '''N''' is the set of all natural numbers, is the set of all even natural numbers.
| |
| * {''p''/''q'' : ''p'',''q'' ∈ '''Z''', ''q''≠0}, where '''Z''' is the set of all integers, is the set of all rational numbers ('''Q''').
| |
| | |
| === Z notation ===
| |
| {{Main|Z notation}}
| |
| In [[Z notation]], the set of all ''x'' (in a universe of discourse ''A'') satisfying the condition ''P''(''x'') would be written <math>\{x : A \ |\ P(x)\}</math>. In Z, an element x's [[Element (mathematics)|set membership]] is written as <math>(x : A)</math> instead of <math>(x \in A)</math>; the vertical bar is used to indicate a predicate. Versions of set builder notation are also available in Z which allow for terms more complicated than a single variable, using a bullet to indicate the form of members of the set. So <math>\{x : A \ |\ P(x) \bullet F(x)\}</math> denotes the set of all values ''F''(''x''), where ''x'' is in ''A'' and ''P''(''x'') holds.
| |
| | |
| === Parallels in programming languages ===
| |
| {{main|List comprehension}}
| |
| A similar notation available in a number of [[programming languages]] (notably [[Python (programming language)|Python]] and [[Haskell (programming language)|Haskell]]) is the [[list comprehension]], which combines [[map (higher-order function)|map]] and [[filter (higher-order function)|filter]] operations over one or more [[list (computing)|lists]].
| |
| | |
| In Python, the set-builder's braces are replaced with square brackets, parentheses, or curly braces, giving list, [[generator (computer science)|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. Consider these examples given in set-builder notation, Python, and Haskell:
| |
| {| class="wikitable"
| |
| |-
| |
| ! !! Example 1 !! Example 2
| |
| |-
| |
| ! Set-builder
| |
| | <center><math>\{l\ |\ l \in L\}</math></center> || <center><math>\{(k, x)\ |\ k \in K \wedge x \in X \wedge P(x) \}</math></center>
| |
| |-
| |
| ! scope="row" | [[Python (programming language)|Python]]
| |
| | <source lang="python">{l for l in L}</source> || <source lang="python">{(k, x) for k in K for x in X if P(x)}</source>
| |
| |-
| |
| ! scope="row" | [[Haskell (programming language)|Haskell]]
| |
| | <source lang="haskell">[l | l <- ls]</source> || <source lang="haskell">[(k, x) | k <- ks, x <- xs, p x]</source>
| |
| |}
| |
| | |
| 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 (functional programming)|monad]] with a [[zero element]].<ref>{{cite web|url=http://blog.n-sch.de/2010/11/27/fun-with-monad-comprehensions/|title=Fun with monad comprehensions|author=Nils Schweinsberg|date=27 Nov 2010|accessdate=4 July 2011}}</ref>
| |
| | |
| == References ==
| |
| <references/>
| |
| {{Use dmy dates|date=July 2011}}
| |
| | |
| [[Category:Set theory]]
| |
| [[Category:Mathematical notation]]
| |
| [[Category:Articles with example Haskell code]]
| |
| [[Category:Articles with example Python code]]
| |
| | |
| [[is:Mengjaskilgreiningarritháttur]]
| |