Introduction to Sets

Introduction to Sets

Introduction

  • A set is a collection of elements, such as:
    • A = {1, 2, 3, 4, 5}
  • A set does not have order:
    • {1, 2, 3, 4, 5} is the same as {5, 4, 3, 2, 1}
    • It is convenient to write the elements of a set in consecutive order, but this is only for convenience.
  • Every element in a set is unique, multiples of the same element are ignored:
    • The set {1, 2, 2} has a size of 2, and is the same as {1, 2}

Notation

  • It is common for sets to be denoted by a uppercase letter, and for its elements to be wrapped in curly braces:k
    LaTeX:\mathbf{A} = \{ 1, 2, 3, 4, 5 \}
  • Sets can also be defined using set builder notation:
    • A rule is used to show which elements are members of the set:
    • The set A defined above would contain all even integers between 0 and 2000.
    • The format of the rule is: (formula: conditions) or (formula| conditions).
    • If it is not specified as a condition, then it is assumed that a is a real number.

Elements in a set

  • Elements in a set are usually represented by a lowercase letter.
  • To demonstrate that an element is part of a set, we use the set membership symbol:
    LaTeX:\mathbf{a} \in \mathbf{A}
  • This can also be done with proper elements:
    LaTeX:\1 \in \{ 1, 2, 3, 4, 5 \}
  • To show that an element is not part of a set, we use the 'not member of' symbol:
    LaTeX:6 \notin \{ 1, 2, 3, 4, 5 \}

Length of a set

  • The length of a set is defined as the number of elements it contains.
  • It is denoted by surrounding the set by a pair of vertical lines: notation for the length of a set

The Empty Set

The Empty Set (or Null Set) is a set containing no items. It is represented by the empty set symbol:

LaTeX:\varnothing = \{\}

code (Python)

A = frozenset([1, 2, 3, 4, 5])

print(1 in A) # prints 'True'
print(6 not in A) # prints 'True'