from edumath.discrete_math import domain, is_function, range_
R = {(1, "a"), (2, "a"), (3, "b")}
domain(R), range_(R), is_function(R)({1, 2, 3}, {'a', 'b'}, True)
Relations describe connections. A relation might connect students to courses, people to friends, numbers to their squares, or web pages to links. A function is a special relation where each input has exactly one output.
After this lesson you should be able to:
An ordered pair (a,b) has a first coordinate and a second coordinate. In general,
(a,b) is not the same as (b,a)
unless a=b.
A relation from a set A to a set B is a subset of A x B. In beginner language, it is a set of ordered pairs.
Example:
R = {(1,a), (2,b), (3,b)}
The first coordinates are inputs or source elements. The second coordinates are outputs or target elements.
For R={(1,a),(2,b),(3,b)}, the domain from the pairs is {1,2,3} and the range is {a,b}.
A relation is a function when each input has exactly one output.
{(1,2), (2,3)} is a function.
{(1,2), (1,3)} is not a function.
The second relation fails because input 1 points to two different outputs.
{(1,a), (2,a)} can be a function. Two inputs may share an output. The rule is that one input cannot have two different outputs.
For a relation on a set A:
a in A satisfies aRa.aRb, then bRa.aRb and bRa, then a=b.aRb and bRc, then aRc.A relation that is reflexive, symmetric, and transitive is an equivalence relation.
Let
R = {(1,2), (2,2), (3,4)}
This is a function because each input 1, 2, and 3 appears with one output. The fact that 1 and 2 both output 2 is allowed.
Let
S = {(1,2), (1,4), (2,5)}
This is not a function because input 1 has two outputs.
On the set {1,2}, consider
R = {(1,1), (2,2), (1,2), (2,1)}
This relation is reflexive because (1,1) and (2,2) are present. It is symmetric because (1,2) and (2,1) are both present. It is transitive: every chain of two related steps has the required shortcut pair.
{(1,a), (2,a), (3,b)} a function?{(1,a), (1,b), (2,c)} a function?{(2,5), (3,5), (4,7)}.aRa for every a?aRb and bRc imply aRc?1 has two outputs.{2,3,4} and range {5,7}.Relations are sets of ordered pairs. Functions are relations with a special input rule: one input, one output.
Guess first. Is (2, 5) the same as (5, 2)?
Guided exercise.
In an ordered pair, position matters. (2, 5) has first coordinate 2 and second coordinate 5. (5, 2) reverses those roles. They are different unless the coordinates are equal.
Checkpoint. For R = {(1, a), (2, b), (2, c)}, list the first coordinates and second coordinates separately.
Guess first. In R = {(1, a), (2, b), (3, b)}, is a in the domain or in the range?
Guided exercise.
Read the first coordinates for the domain and the second coordinates for the range:
domain from pairs = {1, 2, 3}
range from pairs = {a, b}
The codomain must be declared separately. It is the set of allowed target values, while the range is the set actually used.
Checkpoint. If the codomain is {a, b, c, d} and the pairs are {(1, a), (2, a), (3, c)}, find the domain, codomain, and range.
Guess first. Does sharing an output break the function rule?
Guided exercise.
{(1, a), (2, a)} is a function because each input has one output. Shared outputs are allowed. But {(1, a), (1, b)} is not a function because input 1 has two outputs.
A quick test is to scan the first coordinates. If a first coordinate repeats with different second coordinates, the relation is not a function.
Checkpoint. Decide whether {(0, 1), (1, 1), (2, 4), (2, 5)} is a function. Explain your answer using the input rule.
Guess first. To test reflexive on {1, 2, 3}, how many self-pairs must appear?
Guided exercise.
Reflexive requires every self-pair:
(1, 1), (2, 2), and (3, 3)
Symmetric requires reversing every pair. Transitive requires checking chains: if (a, b) and (b, c) appear, then (a, c) must appear.
Checkpoint. On {1, 2}, classify R = {(1, 1), (2, 2), (1, 2)} as reflexive, symmetric, antisymmetric, and/or transitive.
{1, 2} and the second coordinates are {a, b, c}.{1, 2, 3}. Codomain: {a, b, c, d}. Range: {a, c}.{(0, 1), (1, 1), (2, 4), (2, 5)} is not a function because input 2 has two outputs.R = {(1, 1), (2, 2), (1, 2)} is reflexive, not symmetric, antisymmetric, and transitive.Represent finite relations with Python sets of tuples.
({1, 2, 3}, {'a', 'b'}, True)
Check relation properties by exhaustive finite testing.
(True, True, True)
SymPy is less central here than definitions, but Python data structures make small relations easy to test.