Collection - Set

> (Data|State) Management and Processing > (Data Type|Data Structure) > (Collection|Container) Data Type (Array, List, Set, ...)

1 - About

A set is:

The objects element of the set have the same type.

A set is an unordered collection in which each value occurs at most once.

The mathematical concept of a set is a group of unique items, meaning that the group contains no duplicates.

Sets are one of the most fundamental concepts in mathematics. Developed at the end of the 19th century, set theory is now a ubiquitous part of mathematics, and can be used as a foundation from which nearly all of mathematics can be derived.

In mathematics education, elementary topics such as Venn diagrams are taught at a young age, while more advanced concepts are taught as part of a university degree.

The familiar Venn Diagrams is used:

  • in mathematics education to introduce elementary element of set theory such as “set intersection” and “set union”
  • illustrate simple set relationships

Sets are fundamental to logic, mathematics, and computer science, but also practical in everyday applications in business and systems.


3 - Examples

3.1 - In Programming language

Some real-world examples of sets include the following:

  • The set of uppercase letters 'A' through 'Z'
  • The set of nonnegative integers {0, 1, 2 …}
  • The set of reserved Java programming language keywords {'import', 'class', 'public', 'protected'…}
  • A set of people (friends, employees, clients, …)
  • The set of records returned by a database query
  • The set of Component objects in a Container
  • The set of all pairs
  • The empty set {}

3.2 - In Computer Science

  • The idea of a "connection pool" is a set of open connections to a database server.
  • Web servers have to manage sets of clients and connections.
  • File descriptors provide another example of a set in the operating system.

4 - Basic properties of sets

The basic properties of sets:

  • Sets contains only one instance of each item
  • Sets may be finite or infinite
  • Sets can define abstract concepts

5 - Operator

5.1 - In

<math>\in</math>: indicates that an object belongs to a set (equivalently, that the set contains the object).

For example: <math>1 \in \{1,2,3,4\}</math>

5.2 - Subset

A subset B: “A is a subset of B”. This means A and B are sets, and every element of A is also an element of B.

5.3 - Equality

A = B: Two sets are equal if they contain exactly the same elements. (There is no order among elements of a set.)

A convenient way to prove that A and B are equal is to prove that each is a subset of the other. The proof often consists of two parts:

  1. a proof that A subset B and
  2. a proof that B subset A.

6 - Property

6.1 - Cardinality

Any set has only one size (its cardinality or length)

If a set S is not infinite, delim{|}S{|} to denote the number of elements or cardinality of the set.

For example, the set delim{lbrace}{1,2,3,4}{rbrace} has a cardinality of 4.

If A and B are finite sets then |A x B| = |A| x |B|.

7 - Operation

7.1 - Cartesian Product

The cartesian product A x B is the set of all pairs (a, b) where a in A and b in B.


A = {1, 2} 
B = {a, b}
A x B = {(1,a), (1,b), ((1,c), (2,a), (2,b), (2,c)}

The cartesian product in named for Rene Descartes.

8 - Set expression

8.1 - Set of Non-negative number

In Mathese, “the set of non-negative numbers” is written like this:

delim{lbrace}{  x in bbR : x>= 0}{rbrace}


  • The colon stands for “such that”
  • the part before the colon specifies the elements of the set, and introduces a variable to be used in the second part
  • the part after the colon: defines a filter rule

The above notation can also be shortened if x is wel known :

delim{lbrace}{ x : x>= 0}{rbrace}

8.2 - Another example

Another example where the set consists of 1/2 and 1/3

delim{lbrace}{ x : x^2 - {5/6}x + {1/6} = 0}{rbrace}

8.3 - Tuple

Tuples examples in set expression:

  • The set expression of all pairs of real numbers in which the second element of the pair is

the square of the first can be written:

delim{lbrace}{(x,y) in bbR x bbR : y = x^2 }{rbrace}

of abbreviated:

delim{lbrace}{(x,y) : y = x^2 }{rbrace}

  • The set expression of triples consisting of nonnegative real numbers.

delim{lbrace}{(x,y, z) in bbR x bbR x bbR: x >= 0, y >= 0, z >=0}{rbrace}

9 - Documentation / Reference