Functions and Relations

Ordered pairs, finite relations, functions, and relation properties.

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.

Learning objectives

After this lesson you should be able to:

  • represent relations as sets of ordered pairs;
  • find domain and range;
  • decide whether a relation is a function;
  • distinguish codomain from range;
  • classify reflexive, symmetric, antisymmetric, and transitive relations;
  • recognize the idea of an equivalence relation.

Ordered pairs

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.

Relations

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.

Domain, codomain, and range

  • Domain: allowed inputs.
  • Codomain: allowed target outputs.
  • Range: outputs actually used by the relation or function.

For R={(1,a),(2,b),(3,b)}, the domain from the pairs is {1,2,3} and the range is {a,b}.

Functions

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.

TipShared outputs are allowed

{(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.

Relation properties

For a relation on a set A:

  • Reflexive: every a in A satisfies aRa.
  • Symmetric: if aRb, then bRa.
  • Antisymmetric: if both aRb and bRa, then a=b.
  • Transitive: if aRb and bRc, then aRc.

A relation that is reflexive, symmetric, and transitive is an equivalence relation.

Worked example 1: function or not?

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.

Worked example 2: relation properties

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.

Common pitfalls

  • Forgetting that order matters in ordered pairs.
  • Thinking a relation fails to be a function because two inputs share an output.
  • Confusing codomain and range.
  • Checking relation properties using only one pair.
  • Thinking symmetric and antisymmetric are exact opposites.

Practice

  1. Is {(1,a), (2,a), (3,b)} a function?
  2. Is {(1,a), (1,b), (2,c)} a function?
  3. Find the domain and range of {(2,5), (3,5), (4,7)}.
  4. What property says that aRa for every a?
  5. What property says that aRb and bRc imply aRc?
  1. Yes. Each input has one output.
  2. No. Input 1 has two outputs.
  3. Domain {2,3,4} and range {5,7}.
  4. Reflexive.
  5. Transitive.

Subtopic guided practice and checkpoints

Relations are sets of ordered pairs. Functions are relations with a special input rule: one input, one output.

Lab 1: read ordered pairs

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.

Lab 2: find domain, codomain, and range

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.

Lab 3: test whether a relation is a function

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.

Lab 4: check relation properties carefully

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. The first coordinates are {1, 2} and the second coordinates are {a, b, c}.
  2. Domain: {1, 2, 3}. Codomain: {a, b, c, d}. Range: {a, c}.
  3. {(0, 1), (1, 1), (2, 4), (2, 5)} is not a function because input 2 has two outputs.
  4. R = {(1, 1), (2, 2), (1, 2)} is reflexive, not symmetric, antisymmetric, and transitive.

Functions and relations checkpoint

Using this lesson with edumath and SymPy

Represent finite relations with Python sets of tuples.

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)

Check relation properties by exhaustive finite testing.

from edumath.discrete_math import is_reflexive, is_symmetric, is_transitive

S = {(1, 1), (2, 2), (1, 2), (2, 1)}
is_reflexive(S, {1, 2}), is_symmetric(S), is_transitive(S)
(True, True, True)

SymPy is less central here than definitions, but Python data structures make small relations easy to test.