A = {1, 2, 3}
B = {3, 4}
A | B, A & B, A - B, A ^ B({1, 2, 3, 4}, {3}, {1, 2}, {1, 2, 4})
A set is a collection of distinct objects. Sets are used in probability, databases, logic, graph theory, and almost every area of mathematics.
After this lesson you should be able to:
A set is a collection where order and repetition do not matter.
{1, 2, 3} = {3, 2, 1} = {1, 1, 2, 3}
The objects in a set are called elements.
2 in {1,2,3} is true.5 in {1,2,3} is false.The statement x in A means x is an element of A. The statement A subset B means every element of A is also in B.
If A = {1,2,3}, then 2 in A is true and {2} subset A is also true. But 2 and {2} are different objects.
Let A={1,2,3} and B={3,4}.
| Operation | Meaning | Result |
|---|---|---|
A union B |
in A or B or both | {1,2,3,4} |
A intersection B |
in both A and B | {3} |
A - B |
in A but not B | {1,2} |
B - A |
in B but not A | {4} |
A symmetric_difference B |
in exactly one set | {1,2,4} |
A complement depends on a universe. If the universe is U={1,2,3,4,5} and A={1,2,3}, then
A complement = {4,5}
Without a universe, the complement is not well defined.
The power set of A is the set of all subsets of A.
For A={a,b}, the power set is
{ {}, {a}, {b}, {a,b} }
A set with n elements has 2^n subsets.
The Cartesian product A x B is the set of ordered pairs whose first coordinate comes from A and second coordinate comes from B.
If A={1,2} and B={x,y}, then
A x B = {(1,x), (1,y), (2,x), (2,y)}
Order matters: usually A x B is not the same as B x A.
Let A={1,2,3}, B={3,4,5}, and universe U={1,2,3,4,5,6}.
A: {1,2};B: {4,5};{3};{6}.In probability, events are sets. If A is “roll an even number” and B is “roll a number greater than 4” on a six-sided die, then
A = {2,4,6}
B = {5,6}
A intersection B = {6}
The intersection means both events happen.
in with subset.A - B equals B - A.{1,2,3} union {3,4}.{1,2,3} intersection {3,4}.{2,3} a subset of {1,2,3,4}?{x,y}.{1,2} x {a}.{1,2,3,4}.{3}.2 and 3 are in the larger set.{ {}, {x}, {y}, {x,y} }.{(1,a), (2,a)}.Set problems become easier when you decide membership one element at a time.
Guess first. If A = {1, 2, 3}, which statement is correct: 2 in A or {2} in A?
Guided exercise.
2 in A is true because 2 is an element of A. The set {2} is not listed as an element of A, so {2} in A is false. However, {2} subset A is true because every element of {2} is in A.
Checkpoint. For B = {a, {b}, c}, decide whether b in B, {b} in B, and {b} subset B are true. Say which question is about membership and which is about subsets.
Guess first. For A = {1, 2, 3} and B = {3, 4, 5}, which elements are in both sets?
Guided exercise.
Check each possible element:
1 is in A only
2 is in A only
3 is in both A and B
4 is in B only
5 is in B only
Therefore:
A union B = {1, 2, 3, 4, 5}
A intersection B = {3}
A - B = {1, 2}
B - A = {4, 5}
Checkpoint. Let A = {red, blue, green} and B = {green, yellow}. Compute A union B, A intersection B, and A - B.
Guess first. Can you find A complement if no universe is given?
Guided exercise.
Let U = {1, 2, 3, 4, 5, 6} and A = {2, 4, 6}. The complement of A is everything in U that is not in A:
A complement = {1, 3, 5}
If the universe changed to all positive integers, the complement would be much larger. That is why the universe must be declared.
Checkpoint. If U = {a, b, c, d, e} and C = {b, d}, find C complement. Then explain why the answer would change if the universe changed.
Guess first. How many subsets should a two-element set have?
Guided exercise.
For A = {x, y}, each element has two choices: include it or leave it out. That gives four subsets:
{} choose neither
{x} choose x only
{y} choose y only
{x, y} choose both
For A = {1, 2} and B = {a, b}:
A x B = {(1, a), (1, b), (2, a), (2, b)}
Checkpoint. List the power set of {p, q} and the Cartesian product {0, 1} x {L, R}.
B = {a, {b}, c}, b in B is false, {b} in B is true, and {b} subset B is false because the element b itself is not in B.A union B = {red, blue, green, yellow}, A intersection B = {green}, and A - B = {red, blue}.C complement = {a, c, e} relative to U = {a, b, c, d, e}.{p, q} is { {}, {p}, {q}, {p, q} }. The Cartesian product is {(0, L), (0, R), (1, L), (1, R)}.Python has built-in set operators.
Use edumath for a named table of operations.
{'union': {1, 2, 3, 4},
'intersection': {3},
'a_minus_b': {1, 2},
'b_minus_a': {4},
'symmetric_difference': {1, 2, 4}}
((frozenset(), frozenset({'a'}), frozenset({'b'}), frozenset({'a', 'b'})),
((1, 'y'), (1, 'x'), (2, 'y'), (2, 'x')))
SymPy also has finite-set objects.