Random Events
A random event is an outcome of a random experiment (a replicable procedure performed under the same conditions). For example, in an experiment of Flipping a Coin, one of the two events will occur: "Heads" or "Tails". When Rolling a Die, one can define numerous events such as getting: "an odd number", "a number greater than 2", "one or six", etc. In Measuring MPG (Miles per Gallon), events like "MPG below 20", "MPG between 20 and 30" or "MPG above 30" may occur.
Although one defines an event that can be satisfied by many different outcomes of an experiment, what actually comes out from the experiment is a simple event. For example, an event of getting an odd number in a Single Roll of a Die can materialize as 1, 3, or 5. Getting any number in this experiment can be satisfied by one of the numbers 1 through 6. Each of the outcomes (1, 2, 3, 4, 5, 6) is referred to as a simple or elementary event.
Any event can be thought of as a combination of zero, one, many, or all simple events.
An event that has nothing to do with any of the simple events is called an impossible event (). For example, in a Single Roll of a Die, getting a number that is even and odd is impossible. Any number (outcome) must be either even or odd but not both. Using a set notation we can formulate such an event as {2,4,6} ∩ {1,3,5} = ∅. On the other hand, an event that can be satisfied by any of the simple events is called a certain event (S). For example getting an odd or even number, in the same experiment, is certain since there are no other numbers (only even or odd). Using a set notation we can formulate such an event as {2,4,6} ∪ {1,3,5} = S. show
Notice that in the two preceding statements, two set operators are used: ∩, ∪. Operator ∩ is used to construct an intersection of events and operator ∪ is used
to formulate a union of events. Upper case letter S stands for a certain event which is a collection of all simple event, also referred to as a Sample Space.
There is an interesting and useful analogy between events and sets. One can think of a simple event as of an element of a set. The sample space and certain event would then be equivalent to the [whole] set, S. An impossible event could be represented by an empty set, . An event, X, that can be satisfied by more than one simple event is interpreted as a subset of set S, X ⊆ S. Such an event is also referred to as a compound event. More importantly, all basic set operations can also be applied to events. Set notations are frequently used to represent and manipulate events. Simple events are symbolized by lower-case letters and a compound events—by capital letters. A capital letter S usually stands for the sample space (certain event). Using the set notations one can conveniently defined more complex events and their properties.

Union of Events
An event Z is a union of events X or Y, Z = X ∪ Y, if Z consists of events that satisfy X or Y. (Notice that, in plain English, we could say Z is a union of events X and Y. However, conjunctive word and may be misleading here as it is used logically to formulate intersections. This is why this union is expressed as "X or Y" even so it may not sound well "language-wise".)
For example, when Rolling a Die, let X = {1, 2, 3} and Y={3, 4}. Union X or Y = {1, 2, 3, 4}. This union includes all events (elements) that satisfy (belong to) X plus (or) those that belong to Y. Notice that event {3} belongs to both X and Y. However, in a union, each element appears only once. The following are common properties of the union:
X ∪ Y = Y ∪ X
X ∪ ∅ = X
X ∪ X = X
X ∪ S = S
X ∪ (Y ∪ Z) = X ∪ Y ∪ Z = (X ∪ Y) ∪ Z
A ⊆ B ⇔ A ∪ B = B (where stands for "if and only if")
If A is contained in B then A does not add anything
to B (all elements of A are already in B)
.
This picture (a Venn diagram) shows this
relation graphically (both A and B are part of sample space S).

Intersection of Events
An event Z is an intersection of events X and Y, Z = X ∩ Y, if Z consists of events that simultaneously satisfy X and Y. As mentioned, the common notation for this operation is X ∩ Y. For example, when Rolling a Die, let X = {2, 4, 6} and
Y = {3, 4, 5}. Intersection X ∩ Y = {4}. This intersection includes all events (here event) that satisfy (belong to) both X and Y. It is simply an overlap of these events. The following are common properties of the intersection:
X ∩ Y = Y ∩ X
X ∩ ∅ = ∅
X ∩ X = X
X ∩ S = X
X ∩ (Y ∩ Z) = X ∩ Y ∩ Z = (X ∩ Y) ∩ Z
X ∩ (Y ∪ Z) = X ∩ Y ∪ X ∩ Z
This is the Distributivity of Intersection over Union law.
It is similar to an algebraic expression: x*(y+z) = x*y+x*z
governed by the Distributive property.
Notice that an intersection has a higher priority than a union
as, in algebra, a multiplication has the higher priority than an addition.
A ⊆ B ⇔ A ∩ B = A
If A is contained in B
then A must fully overlap B
This picture (a Venn diagram)
shows this relation graphically
(both A and B are part of S).

Complement of an Event
Event Xc is said be a complement of event X if it satisfies those simple events from the sample space, S, that do not satisfy event X. Other common notations for Xc are X', ¬X, or not X. More explicit definition shows that the complement of event X is the difference between the sample space, S, and the event: Xc = S \ X (where \ stands for set-operator minus).
For example, when Rolling a Die, let X = {2, 4, 6}. Recall that sample space, S, consists of elements (simple events)
{1, 2, 3, 4, 5, 6}. Complement of X, Xc = {1,3,5}. Notice that Xc is just the difference between S and X, {1, 3, 5} = {1, 2, 3, 4, 5, 6} \ {2, 4, 6}. It includes those events from S that are not in X. One can also say that Xc is a negation of X with respect of space S. The following are common properties of the complement:
X ∪ Xc = S
This is a very important property that is frequently applied to calculate probabilities.
It simply states that a union of an event and its complement covers the entire sample space. For example (in Rolling a Die):
If X = {1,2} then Xc = {3,4,5,6},
{1,2} ∪ {3,4,5,6} = {1,2,3,4,5,6}
X or Xc = S
X ∩ Xc = ∅
An event and its complement do not overlap
Their intersection is impossible. For example (in Rolling a Die):
If X = {1,2} then Xc = {3,4,5,6},
{1,2} ∩ {3,4,5,6} = {}
X ∩ Xc=∅ /
Sc = ∅
A complement of a certain event is an impossible event.
Similar to: Not true is false.
c = S
A complement of an impossible event is a certain event.
Similar to: Not false is true.
 

De Morgan's Laws:
There are interesting relationships between the three basic event (set) operations: union, interaction and complement. They are captured by two famous De Morgan's Laws::
1. The complement of an intersection of two events is equivalent (≡) to the union of the complements of the events.
(X ∩ Y)c ≡ Xc ∪ Yc
2. The complement of a union of two events is equivalent (≡) to the intersection of the complements of the events.
(X ∪ Y)c ≡ Xc ∩ Yc
 
Examples:
Let X = {1,2,3,4}, Y = {3,4,5,6} in a sample space S = {1,2,3,4,5,6}.
1. Show that L = (X ∩ Y) c ≡ Xc ∪ Yc = R (here L stands for the left size, and R stands for the right side).
X ∩ Y = {1,2,3,4} ∩ {3,4,5,6} = {3,4}
L = (X ∩ Y) c = {1,2,5,6}
Xc = {1,2,3,4}c = {5,6}
Yc = {3,4,5,6}c = {1,2}
Xc ∪ Yc = {5,6} ∪ {1,2} = {1,2,5,6) = R
Thus L = R
2. Let's show that L = (X ∪ Y) c ≡ Xc ∩ Yc = R
X ∪ Y = {1,2,3,4} ∪ {3,4,5,6} = {1,2,3,4,5,6} = S
L = (X ∪ Y)c = Sc = ∅
Xc ∩ Yc = {5,6} ∩ {1,2} = ∅ = R
Thus L = R

Exercises:
1. Consider an experiment of Flipping Two Fair Coins. What is the sample space (the set of all simple events), S, of this experiment?
S = {HH,HT,TH,TT}
2. In Flipping Two Fair Coins, event X = {HT,TH}. What is the complement of this event, Xc?
Xc = {HH,TT}. Given sample space, S = {HH,HT,TH,TT},
the simple events that do not exist in X={HT,TH} are {HH,TT}.
3. For an experiment of Rolling a Die, assume event A = {1, 3, 5} (an odd number), B = {2, 4, 6} (an event number), and
C = {1, 4, 6}. Find out the following compound events:
  a) A ∩ B =
Here A ∩ B = {1, 3, 5} ∩ {2, 4, 6} = ∅.
Events A and B have no common
elements (simple events).
Their overlap is empty!
  b) Ac =
Ac = B
B statisfies events in S that are not in A.
{1, 3, 5}c = {2,4,6}
  c) A ∪ C =
A ∪ C = {1, 3, 5} ∪ {1, 4, 6} = {1, 3, 4, 5, 6}
  {1,  3,  5  }

  {1,    4,  6}
=
  {1,  3, 4, 5, 6}
  d) A ∩ C =
A ∩ C = {1, 3, 5} ∩ {1, 4, 6} = {1}
  {1,  3,  5  }

  {1,    4,  6}
=
  {1          }
Only {1} is the common (ovelapping) simple event!
  e) C ∩ A ∪ B =
C ∩ A ∪ B = {1, 4, 6} ∩ {1, 3, 5} ∪ {2, 4, 6} = {1} ∪ {2, 4, 6} = {1, 2, 4, 6}
Notice that intersection C ∩ A is performed first. Its result {1}
is then combined with B={2, 4, 6}, returning union {1, 2, 4, 6}.
  f) C ∩ (A ∪ B) =
C ∩ (A∪ B) = {1, 4, 6} ∩ ({1, 3, 5} ∪ {2, 4, 6}) = {1, 4, 6} ∪ {1, 2, 3, 4, 5, 6} = {1, 4, 6} ∪ S = {1, 4, 6} = C
Because of parenthesis, union A ∪ B is performed first. Notice that the union results in the sample space, S
(it includes all simple events). Intersecting C with S results in C. As mentioned, an intersection of an event and
the sample space is equivalent to the event itself, C ∩ S = C.
4. In an experiment of Measuring Miles Per Gallon, group A of cars accomplished results of at least 20 mpg and group B made up to 30 mpg.

Given event A includes all the results of group A, A = {MPG≥20}, and event B includes the results of group B,
B ={MPG≤30}, evaluate the following compound events:
  a) A ∩ B =
To be concurrently at least 20 and up to 30 means to be between 20 and 30, inclusively.
A ∩ B = {MPG ≥ 20} ∩ {MPG ≤ 30} = {20 ≤ MPG ≤ 30}:

Notice that event {20 ≤ MPG ≤ 30} can also be expresses as {|MPG-25| ≤ 5}, where
|MPG-25| is the absolute difference between MPG and 25. In order for MPG to be
between 20 and 30, its distance from 25 must be less than or equal to 5.
This is a useful representation of an interval as many applications of Statistics focus on
the distance of random data from certain measures, for example—from the mean.
  b) A ∪ B =
To be [alternatively] at least 20 or up to 30 means to be any number (i.e. between -∞ and +∞).
A ∪ B = {MPG ≥ 20} ∪ {MPG ≤30} = {-∞≤MPG≤+∞}:
  c) Ac =
Not at least 20 means less than 20. {MPG ≥ 20}c = {MPG < 20}.
  d) Ac ∪ Bc =
Not at least 20 or not up to 30 means below 20 or above 30.
{MPG ≥ 20}c ∪ {MPG ≤ 30}c = {MPG < 20} ∪ {MPG > 30}.

Using the first De Morgan`s law, this event can also be expressed as
Ac ∪ Bc = (A ∩ B)c = {20 ≤ MPG ≤ 30}c = {MPG < 20} ∪ {MPG > 30}
  e) Ac ∩ Bc =
Events Ac={MPG<20}, Bc={MPG>30} are disjoint. Thus their intersection is empty,
Ac ∩ Bc = ∅

Also in this case, one can apply the De Morgan's law, Ac ∩ Bc = (A ∪ B)c.
Since union A ∪ B = S = {-∞ < MPG < +∞}, its complement is impossible
(A ∪ B)c=∅
 
Implementation
Examples and Exercises for Random Events Implemented as R Sets
R can handle set operations, using the following functions:
Examples
1. Sample space for expriment "Rolling a Die" expressed as a set.
S = 1:6 # same as, in Math, S = {1,2,3,4,5,6}
print(S)
   [1] 1 2 3 4 5 6
  
2. A Union of events.
Asume the following sets: A = {1,3,5}, B = {3,4}
A = c(1,3,5)# c() is an R function used to construct simple collections.
B = c(3,4)  # Here such a collection is called a vector.
AorB = union(A, B)
print(AorB) # Notice that element 3 is accounted for one time.
   [1] 1 3 5 4
  
3. An Intersection of events.
Let A = {1,3,5} and B = {3,4}.
A = c(1,3,5)
B = c(3,4)
AandB = intersect( A, B)
print(AandB)
   [1] 3
  
4. A difference between events.
Let A = {1,3,5} and B = {3,4}
A = c(1,3,5)
B = c(3,4)
AminusB = setdiff(A, B)
cat(AminusB) # Notice a slight difference between the previous print() result and this cat() outcome.
   1 5
  
5. A complement of an event.
S = {1,2,3,4,5,6}, A = {1,3,5}
Show the complement of event (set) A in space S.
S = 1:6 # The sample space in "Rolling a Die"
A = c(1,3,5)
ComplementOfA = setdiff(S, A)
# A more descriptive printout:

cat('Complement of A in S is {',ComplementOfA,'}\n')
cat('Notice:\n')
cat(' S = {',S,'}\n')
cat(' A = {',A,'}\n')
    Complement of A in S is {2 4 6}
    Notice:
      S = {1 2 3 4 5 6}
      A = {1 3 5}
  
6. Maintaining uniqueness of the set elements.
Let A = {1,1,1,4,4,6} and B = {2,2,2}
Get the union of sets A, B.
A = c(1,1,1,4,4,6)
B = c(2,2,2)
AorB = union(A, B)
cat('Union of A, B = {'); cat(AorB); cat('}\n')
cat('Notice:\n')
cat(' A = {'); cat(A); cat('}\n')
cat(' B = {'); cat(B); cat('}\n')
    Union of A, B is {1 4 6 2}
    Notice:
     A = {1 1 1 4 4 6}
     B = {2 2 2}
  
Notice that the order of elements is sets is irrelevant. Since sets are stored in R vectors, one can sort also the sets. For example:
print(sort(setAorB))
    [1] 1 2 4 6
  

Exercises
1. Consider an experiment of Flipping Two Fair Coins. What is the sample space (the set of all simple events), S, of this experiment?
S = 1:6
print(S)
      [1] 1 2 3 4 5 6
 
2. In Flipping Two Fair Coins, event X = {HT,TH}. Find out the sample spacs, S, and the complement of event X, Xc?
S = c('HT','HH','TH','TT')
X = c('HT','TH')
comp_of_X = setdiff(S,X)
print(paste('Sample space, S = {',paste(S, collapse=', '),'}'), quote=FALSE)
print(paste('Event, X = {',paste(X, collapse=', '),'}'), quote=FALSE)
print(paste('Complement of X in S = {',paste(comp_of_X, collapse=', '),'}'), quote=FALSE)
  [1] Sample space, S = { HT, HH, TH, TT }
  [1] Event, X = { HT, TH }
  [1] Complement of X in S = { HH, TT }
 
The above exercise uses function print() that requires the print content to be combined into one object. It is accomplished by means of the paste() function that combines print items separated (by default) with a space. Some of the items are sets. The elements of the sets are concatenated also using the paste() function. They are collapsed into strings, heving individual items separated with a comma and space (', '). Thanks to argument quote=FALSE, these print operations show unquoted output.
A similar output format can be produced, using function cat().
cat('Sample space, S = { '); cat(paste(S, collapse=', ')); cat(' }\n')
cat('Event, X = { '); cat(paste(X, collapse=', ')); cat(' }\n')
cat('Complement of X in S = { '); cat(paste(comp_of_X, collapse=', ')); cat(' }')
  Sample space, S = { HT, HH, TH, TT }
  Event, X = { HT, TH }
  Complement of X in S is { HH, TT }
Notice how convenient the paste() function is when dealing with complex data structures (here—with vectors). The following example compares two methods of getting the same printout.
# Method 1
cat(paste(S, collapse=', '),'\n')
# Method 2
for (i in 1:(length(S)-1)) {
  cat(S[i],', ',sep='')
}
cat(S[length(S)])
  HT, HH, TH, TT 
  HT, HH, TH, TT
The second method uses a for loop to iterate over the elements of set (vector) S. Each element, S[i], is printed by the cat() function. Inside the loop (between { and }), the elements are followed by a comma and space (', ') with no other separator (sep=''). The last element is printed alone outside the loop. Obviously, Method 1 is much simpler and productive.
 
3. For an experiment of Rolling a Die, assume event A = {1, 3, 5} (an odd number), B = {2, 4, 6} (an event number), and C = {1, 4, 6}. Find out the following compound events:

3a:    A ∩ B =
A = as.vector(seq(1, by = 2, len = 3))
B = as.vector(seq(2, by = 2, len = 3))
A_and_B = intersect(A,B)
if ( length(A_and_B) == 0 ) A_and_B = 'Ø'
cat('A and B = ');cat(A_and_B)
      A and B = Ø
 
3b:    Ac = (with respect to the sample space)
A = as.vector(seq(1, by = 2, len = 3))
S = 1:6
complementOfA = setdiff(S,A)
cat('Complement of A in S = {'); cat(paste(complementOfA, collapse=', ')); cat('}\n')
cat('It is the same as set B: '); cat(setequal(complementOfA,B))
  Complement of A in S = {2, 4, 6}
  It is the same as set B: TRUE
 
3c:    A ∪ C =
C = c(1,4,6)
A_or_C = union(A,C)
cat('Union of A and C = {'); cat(paste(A_or_C, collapse=', ')); cat('}\n')
cat('Noice that:\n')
cat('A = '); cat(paste(A, collapse=', '))
cat('\nC = '); cat(paste(C, collapse=', '))
cat('\nBecause sets contain unique elements, 1 (an element of both A and B) is copied once!')
  Union of A and C = {1, 3, 5, 4, 6}
  Noice that:
  A = 1, 3, 5
  C = 1, 4, 6
  Because sets are expected to contain unique elements, element 1 (in both A and B) is copied once!
 
3d:    A ∩ C =
A_and_C = intersect(A, C)
if ( length(A_and_C) == 0 ) A_and_C = 'Ø'
cat('A and C = {');cat(paste(A_and_C, collapse=', '));cat('}\n')
cat('Noice that:\n')
cat('A = '); cat(paste(A, collapse=', '))
cat('\nC = '); cat(paste(C, collapse=', '))
cat('\nElement 1 is the only common element of the sets!')
  A and C = {1}
  Noice that:
    A = 1, 3, 5
    C = 1, 4, 6
  Element 1 is the only common element of the sets!
 
C_and_A_or_B = union(intersect(C,A),B)
cat('Union of B with intersection of C and A = {');cat(paste(C_and_A_or_B, collapse=', ')); cat('}\n')
cat('Noice that:\n')
cat('A = {'); cat(paste(A, collapse=', ')); cat('}\n')
cat('B = {'); cat(paste(B, collapse=', ')); cat('}\n')
cat('C = {'); cat(paste(C, collapse=', ')); cat('}\n')
cat('Intersection of C and A is done first:\n')
cat('{'); cat(intersect(C,A)); cat('}\n')
cat('Combined with B, gives the final result shown above!\n')
  Union of B with intersection of C and A = {1, 2, 4, 6}
  Noice that:
  A = {1, 3, 5}
  B = {2, 4, 6}
  C = {1, 4, 6}
  Intersection of C and A is done first:
  {1}
  Combined with B, gives the final result shown above!
 
3f:    C ∩ (A ∪ B) =
C_intersect_union_of_A_or_B = intersect(C,union(A,B))
cat('Intersection of C with union of B and A = {');cat(paste(C_intersect_union_of_A_or_B, collapse=', ')); cat('}\n')
cat('Noice that:\n')
cat('A = {'); cat(paste(A, collapse=', ')); cat('}\n')
cat('B = {'); cat(paste(B, collapse=', ')); cat('}\n')
cat('C = {'); cat(paste(C, collapse=', ')); cat('}\n')
cat('Union of A and B is done first:\n')
cat('{'); cat(union(A, B)); cat('}\n')
cat('Intersected with C, gives the final result shown above!\n')
cat('Also notice that the union of A and B is equivalent to the sample space:'); cat(setequal(S,union(A, B)))
  Intersection of C with union of B and A = {1, 4, 6}
  Noice that:
  A = {1, 3, 5}
  B = {2, 4, 6}
  C = {1, 4, 6}
  Union of A and B is done first:
  {1 3 5 2 4 6}
  Intersected with C, gives the final result shown above!
  Also notice that the union of A and B is equivalent to the sample space:TRUE
 
4. In an experiment of Measuring Miles Per Gallon, group A of cars accomplished results of at least 20 mpg and group B made up to 30 mpg. Using the interval notation the sets can be defined mathematically as A = [20,∞) and B = (-∞,30].

Standard R does not have proper functions to handle [interval] sets of continuous variables. However, library sets provides interesting functions to perform set operations on continuous intervals. While in R, first install the library (package) sets:
  install.packages('sets')
If you are installing this package for another R distribution, for example, for Anaconda, first find the installation "Home" of this installation and locate its R library folder. On the author's system, the installation's target folder (R_Library_Path) is 'C:/bisoft/anaconda/Lib/R/library'. Finally, run the installation with the path to this library:
  install.packages('sets','R_Library_Path')
Upon success, declare the library and apply its functions.

4a:  A ∩ B =
library(sets)
A = reals(20,Inf) # [20,8) - Left-Limit is inclusinve, Right-Limit is exclusive.
B = reals(-Inf,30) # (-8,30] - Left-Limit is exclusive, Right-Limit is inclusinve.
A_and_B = A & B # In the sets library, "&" is the intersection operator.
cat('A and B = ')
print(A_and_B)
cat('Notice:\n')
cat(' A = ')
print(A)
cat(' B = ')
print(B)
    A and B = [20, 30]
    Notice:
      A = [20, Inf]
      B = [-Inf, 30]
 
4b:  A ∪ B =
A_or_B = A | B # In the sets library, | is the union operator.
cat('A or B = ')
print(A_or_B)
    A or B = [-Inf, Inf]
 
4c:  Ac =
complementOfA = !A
cat('Complement of A = ')
print(complementOfA)
cat('Noice that:\n')
cat(' A = '); cat(paste(A, collapse=', ')); cat('\n')
    Complement of A = [-Inf, 20)
    Noice that:
      A = [20, Inf]
 
4d:  Ac ∪ Bc =
complementOfA = !A
complementOfB = !B
unionOfNotA_NotB = complementOfA | complementOfB
cat('Union of Complements of A, B = ')
print(unionOfNotA_NotB)
cat('Notice:\n')
cat(' Complement of A = '); print(complementOfA)
cat(' Complement of B = '); print(complementOfB)
    Union of Complements of A, B = [-Inf, 20) U (30, Inf]
    Notice:
      Complement of A = [-Inf, 20)
      Complement of B = (30, Inf]
 
4e:    Ac ∩ Bc =
intersectionOfNotA_NotB = interval_intersection(complementOfA, complementOfB)
cat('Overlap of Complements of A, B = ')
print(intersectionOfNotA_NotB)
cat('Notice:\n')
cat(' Complement of A = '); print(complementOfA)
cat(' Complement of B = '); print(complementOfB)
    Overlap of Complements of A, B = {}
    Notice:
      Complement of A = [-Inf, 20)
      Complement of B = (30, Inf]
  
 

Examples and Exercises for Random Events Implemented as Spreadsheet Sets
Spreadsheet program (e.g. Excel, Google Sheets, Apple Numbers, etc.) do not have built-in set operations (functions or procedures). Elements of sets can be stored in spreadsheet ranges of cells, resembling R vectors. The following functions can be useful in performing set operations (unions, intersections, differences).
The above functions do not perform the set operations alone. Other functions are needed in order to properly interpret the outcomes of the MATCH() and COUNTIF() functions.
Function call MATCH(e, x, 0) returns the position (index) of element (cell) e in range x or #N/A if the element does not exist. The set operations (unions, intersections, differences) require that the [tested] element or "empty" (null) set is returned which can be done by embedding the MATCH() function in other functions. Logically, one could say that if the MATCH(e, x, 0) call returns #N/A then the resulting set gets an empty element (""), otherwise the set gets element e. One can use function IF() to perform such a query. However, the function's test may not directly compare the ouctome of function MATCH() to #N/A. This can be done by function ISNA() which returns TRUE if its argument is equal to #N/A or FALSE otherwise. The final solution to this problem requires double embeddingof the MATCH() function: =IF(ISNA(MATCH(e,x,0)),"",e).
Function COUNTIF() is somewhat easier to handle. A direct call COUNTIF(x, e) returns 0 (zero) if element e does not exist in range x, or the number of times element e appears in range x (with range x containing unique values, element e may be there at most one time). Thus, in this case, the COUNTIF() function can be directly embedded in the IF() function: =IF(COUNTIF(x, e)=0,"",e).
Examples
1. Use function MATCH() to compute the Union, Intersection, and Differences for sets A and B defined in the following spreadsheet.
Set Ops with Match()
Check the solution at Set Operations, Using Google Sheets (Worksheet SetOpsWithMatch).

Formulas:
D3: =IF(ISNA(MATCH(B3,$A$3:$A$5,0)),"",B3)
D4: Copy D3 to D4
E3: =A3
E4,E5: Copy E3 to E4:E5
E6: =IF(ISNA(MATCH(B3,$A$3:$A$5,0)),B3,"")
E7: Copy E6 to E7
F3: =IF(ISNA(MATCH(A3,$B$3:$B$4,0)),A3,"")
F4,F5: Copy F3 to F4:F5
G3: =IF(ISNA(MATCH(B3,$A$3:$A$5,0)),B3,"")
G4: Copy G3 to G4
2. Use function COUNTIF() to compute the Union, Intersection, and Differences for sets A and B defined in the following spreadsheet.
Set Ops with CountIf()
Check the solution at Set Operations, Using Google Sheets (Worksheet SetOpsWithCountIf).

Formulas:
D3: =IF(COUNTIF($A$3:$A$5,B3)=1,B3,"")
D4: Copy D3 to D4
E3: =A3
E4,E5: Copy E3 to E4:E5
E6: =IF(COUNTIF($A$3:$A$5,B3)=1,"",B3)
E7: Copy E6 to E7
F3: =IF(COUNTIF($B$3:$B$4,A3)=1,"",A3)
F4,F5: Copy F3 to F4:F5
G3: =IF(COUNTIF($A$3:$A$5,B3)=1,"",B3)
G4: Copy G3 to G4
Exercises
1. Compute the Union, Intersection, and Differences for the following data sets (A, B), using function MATCH().
  A B C D E F G
1 Sets   Set Operations, using function MATCH()
2 X Y   X ∩ Y X ∪ Y X \ Y X \ Y
3 blue orange          
4 cyan black          
5 orange grey          
6 magenta red          
7 red            
8 green            
Hint: Copy the above table to a spreadsheet and use formulas similar to those shown in Example 1.
Check the solution at Set Operations, Using Google Sheets (Worksheet SetOpsWithCountIf).
 
  A B C D E F G
1 Sets   Set Operations, using function MATCH()
2 X Y   X ∩ Y X ∪ Y X \ Y X \ Y
3 blue orange   orange blue blue  
4 cyan black     cyan cyan black
5 orange grey     orange   grey
6 magenta red   red magenta magenta  
7 red       red    
8 green       green green  
9              
10         black    
11         grey    
12              

Formulas:
D3: =IF(ISNA(MATCH(B3,$A$3:$A$8,0)),"",B3) 
D4: Copy D3 to D4:D6
E3: =A3
E4:E8: Copy E3 to E4:E8
E9: =IF(ISNA(MATCH(B3,$A$3:$A$8,0)),B3,"")
E10:E12: Copy E9 to E10:E12
F3: =IF(ISNA(MATCH(A3,$B$3:$B$6,0)),A3,"")
F4:F8: Copy F3 to F4:F8
G3: =IF(ISNA(MATCH(B3,$A$3:$A$8,0)),B3,"")
G4:G6: Copy G3 to G4:G6
2. Compute the Union, Intersection, and Differences for the following data sets (A, B), using function COUNTIF().
  A B C D E F G
1 Sets   Set Operations, using function COUNTIF()
2 X Y   X ∩ Y X ∪ Y X \ Y X \ Y
3 blue orange          
4 cyan black          
5 orange grey          
6 magenta red          
7 red            
8 green            
Hint: Copy the above table (without the top row and left column) to a spreadsheet and use formulas similar to those shown in Example 2.
Check the solution at Set Operations, Using Google Sheets (Worksheet SetOpsWithCountIf).
 
  A B C D E F G
1 Sets   Set Operations, using function COUNTIF()
2 X Y   X ∩ Y X ∪ Y X \ Y X \ Y
3 blue orange   orange blue blue  
4 cyan black     cyan cyan black
5 orange grey     orange   grey
6 magenta red   red magenta magenta  
7 red       red    
8 green       green green  
9              
10         black    
11         grey    
12              

Formulas:
D3: =IF(COUNTIF($A$3:$A$8,B3)>0,B3,"") 
D4: Copy D3 to D4:D6
E3: =A3
E4:E8: Copy E3 to E4:E8
E9: =IF(COUNTIF($A$3:$A$8,B3)>0,"",B3)
E10:E12: Copy E9 to E10:E12
F3: =IF(COUNTIF($B$3:$B$6,A3)>0,"",A3)
F4:F8: Copy F3 to F4:F8
G3: =IF(COUNTIF($A$3:$A$8,B3)>0,"",B3)
G4:G6: Copy G3 to G4:G6

Glossary
Random Experiment - a replicable procedure performed under the same conditions, returning a random outcome.
Simple Event - the actual outcome of a random experiment (an element of a set).
Sample Space - the collection of all simple events (the entire set the elements, each representing one simple event).
Random Event - an outcome of a Random Experiment (a subset of the set). Also referred to as a compound event.
Certain Event - an event equivalent to the Sample Space. It is said to occur for sure.
Impossible Event - an event opposite to the Certain Event (equivalent to an empty set). It will never occur.
Union of Events - event Z is a union of events A, B, Z = A ∪ B, if Z includes simple events from A or B.
Intersection of Events - event Z is an intersection of events A, B, Z = A ∩ B, if for each simple event in Z the event exists in both A and B.
Event Complement - event A is a complement of event B, A = Bc, if for each simple event in A, the event does not exist in B.
 
References:
Wikipedia - Event
Wikipedia - Boolean Algebra
Wikipedia - Sample Space
Wikipedia - Set
Wikipedia - De Morgan's Laws
Probability Tutorials (probability.net)
Mathematical Symbols