A set is an unordered collection of values in which each value occurs at most once.
Notation for specifying a set
A = { 1, 2, 3, 4, 5 }
Notation for specifying a set comprehension
A = { x | x ∈ N ^ x ≥ 1 }
Sets can be defined using set comprehension. This defines the properties that a set should have.
Below is a table explaining each of the symbols in the above example.
Symbol | Explanation |
---|---|
x |
Represents the values of the set |
| |
The equation that follows this defines the value of x |
∈ |
Indicates that x is a member of N |
N |
Used to represent the natural numbers |
^ |
Used to represent 'and' |
Sets formalise the idea of grouping objects together and viewing them as a single entity. This means that sets become an abstraction.
There is a close relationship between set theory and logic. The laws governing sets form part of the basis for boolean algebra.
A set can be defined by a shorthand method read the same way as set comprehension.
Set comprehension:
S = {x | x ∈ N ^ x is even}
Compact representation:
S = {x ∈ N | x is even}
Compact representation for strings:
S = { 0n1n | n >= 1 }
The above compact representation for strings will define a set that has an strings with an equal number of 0's and 1's.