BS Artificial Intelligence · Semester 1 · Week 05

Discrete Mathematics for BSAI

Sets, Functions and Mappings

Dr. Hira Benish
Associate Professor & HoD, Mathematics
PMAI Lab, Mathematics Behind AI

Week 5 · Dr. Hira BenishBegin reading  

01 · Opening Scenario: Select, Label, Reverse

A student-support desk has two lists. Support contains students who requested a consultation; Available contains students who can attend on Friday. Which students belong on a Friday invitation list? After inviting them, a system assigns each student one time-slot label. Can the label alone tell us which student received it?

Predict: A Friday invitation needs a student in both lists. Reversing a label depends on whether any two students share it. These are two different mathematical questions: selecting from collections and mapping inputs to outputs.

The questions for this week

What do the sets contain? Which ordered pairs are possible? Does every input have exactly one output? When can we combine mappings or reverse one?

02 · Learning Objectives and Three-Hour Guide

By the end of Week 5, you should be able to read membership and subset notation; interpret a small Venn diagram; find union, intersection and difference; form a small Cartesian product; test whether an assignment is a function; identify domain, codomain and range; recognize one-to-one and onto mappings; compute a simple composition; and decide whether an inverse exists for stated domain and codomain.

Class timeEssential work
60 minSets, Venn sorting and ordered pairs
55 minFunctions, arrow diagrams and mapping cards
40 minComposition, inverse and a guided relay
25 minPractice, explanations and exit check

Classroom essentials Sections 01–11 and Problems 1–5. Optional self-study Colab and the extended problems. The interactive cards and checks give feedback without marks.

03 · Collections Before Symbols

A set is a collection in which we can tell whether an object belongs. Repeating an object does not add a new member, and order does not change the set. Write U={Amina, Bilal, Chen, Diya, Eman} for the students in this small example. This universal set states the scope of our discussion.

Let S={Amina, Chen, Diya} be the support-request list and F={Chen, Diya, Eman} the Friday-availability list. Thus Chen∈S means Chen is a member, while Bilal∉S means Bilal is not. The empty set ∅ has no members.

Subset is a claim about two sets

Let T={Chen, Diya}. Every member of T is in S, so T⊆S. But S⊄T, since Amina belongs to S and not T. The symbols ∈ and ⊆ ask different questions: “is this object a member?” versus “is every member of this set inside the other?”

Venn diagram: Amina is in S only, Chen and Diya are in both S and F, Eman is in F only, and Bilal is outside both S F Amina Chen Diya Eman Bilal U
Figure 1. Read the overlapping region first: Chen and Diya appear in both lists.

04 · Combining and Filtering Sets

The intersection contains items in both sets. The union contains items in either set or both. The difference keeps items in the first set but removes those in the second.

QuestionNotationResult in the diagram
In both lists?S∩F{Chen, Diya}
In at least one list?S∪F{Amina, Chen, Diya, Eman}
In S but not F?S∖F{Amina}
In U but not S?U∖S{Bilal, Eman}

The Friday invitation list is S∩F={Chen, Diya}. Always name the starting set for a difference: S∖F and F∖S are usually different.

Quick check: Is Eman in S∪F? Yes. Is Eman in S∩F? No. “Or” in union includes people in both lists.

05 · Pair Each Choice with Another

Suppose the invited students are I={Chen, Diya} and possible slot labels are L={M, A} for morning and afternoon. An ordered pair (student, slot) records one possible assignment. Its first and second positions have different meanings.

I×L={(Chen,M), (Chen,A), (Diya,M), (Diya,A)}.

The Cartesian product contains every possible ordered pair, not only assignments already made. Here there are 2×2=4 possibilities. By comparison, L×I contains pairs such as (M,Chen); changing order changes the kind of pair.

From possibilities to an actual assignment

If Chen receives M and Diya receives A, the selected pairs are {(Chen,M),(Diya,A)}, a subset of I×L. We have not selected the other two possibilities.

06 · A Function Gives Each Input One Output

An assignment becomes a function when every allowed input has exactly one assigned output. Two different inputs may share an output. An input with no output, or with two outputs, breaks the function rule.

For a mapping f:A→B, A is the domain (allowed inputs), B the codomain (declared possible outputs), and the range the outputs actually produced. Range is a subset of the codomain.

Worked mapping

Let A={a,b,c} and B={1,2,3}. Define f(a)=1, f(b)=1, f(c)=3. This is a function: each input has exactly one output. Its range is {1,3}, while the codomain is {1,2,3}. The value 2 is allowed but unused.

Assignment from A={a,b,c}Function?Reason
a→1, b→1, c→3YesEach input has one output; sharing is allowed.
a→1 and a→2, b→2, c→3Noa has two outputs.
a→1, b→2Noc has no output.

07 · One-to-One and Onto

A function is one-to-one when different inputs never share an output. It is onto when every element of the stated codomain is reached. These tests ask different questions.

Mapping from A={a,b,c} to B={1,2,3}One-to-one?Onto?
a→1, b→2, c→3Yes: no output repeatsYes: 1, 2, 3 all appear
a→1, b→1, c→3No: a and b share 1No: 2 is missing

Onto depends on the codomain. For A={a,b,c}, define h(a)=1, h(b)=1, h(c)=2. If the codomain is {1,2}, this function is onto but not one-to-one. If we instead declare the codomain {1,2,3} with the same outputs, it is not onto because 3 is unused.

Misconception warning: A function may send many inputs to one output. “One output per input” does not mean “one input per output.”

08 · Two Mappings in Sequence

A first mapping produces an output, and a second mapping accepts that output as its input. Let A={1,2,3}, B={2,3,4}, and C={4,6,8}. Define f:A→B by f(x)=x+1, and g:B→C by g(y)=2y.

Thus (g∘f)(2)=g(f(2))=g(3)=6. Read g∘f as “do f first, then g.” More generally, for the stated domain, (g∘f)(x)=2(x+1). The outputs of the first function must be valid inputs to the second.

Quick check: What is (g∘f)(3)? First f(3)=4, then g(4)=8. Reversing the order may not even be defined on the same inputs.

09 · When Can We Map Back?

If f:A→B reaches every output in B and no two inputs share an output, each b∈B has exactly one original input. We can then define an inverse function f⁻¹:B→A.

Reverse a mapping that is one-to-one and onto

For f:A={1,2,3}→B={2,3,4} with f(x)=x+1, the inverse sends 2→1, 3→2 and 4→3. In rule form f⁻¹(y)=y−1 for y∈B. Check: f⁻¹(f(2))=f⁻¹(3)=2.

If two students receive the same slot label, that label does not identify a unique student. If an output label in the codomain is never used, there is no input to send it back to. An inverse on the stated whole codomain needs both one-to-one and onto.

Notation warning: f⁻¹ here means the inverse mapping, not the reciprocal 1/f.

10 · Function Inspector

Classroom activity · 15 minutes Inspect each set of arrows. First decide whether every input has exactly one output. If it is a function, decide whether it has an inverse on the stated codomain. Predict, test your verdict and explain the result.

Card 1 of 4

Which verdict is justified?

Choose a verdict to reveal the reasoning.

11 · Interpret the System Carefully

In the opening scenario, the invitation filter uses S∩F. A label assignment is a function only if every invited student gets one label. If two students share a label, the assignment can still be a function, but a label cannot identify one student uniquely.

These statements describe a specified data model. A student might change availability, or a recorded list might be incomplete. The mathematics identifies what follows from the lists and mapping supplied; a real system must also keep its data current.

Explain aloud: Why does “each student has one label” fail to guarantee “each label names one student”? Give two students the same label to construct your example.

12 · Optional Colab: Check the Set Work

Self-study · mathematics first Predict the three sets from the Venn diagram, then run this cell. Braces create Python sets; & finds members in both, | finds members in either, and - keeps members of the first set only. A set may print its members in a different order; that does not change the mathematical set.

support = {"Amina", "Chen", "Diya"}
available = {"Chen", "Diya", "Eman"}
print(support & available)
print(support | available)
print(support - available)

After understanding f(x)=x+1, this one-line function definition performs the same mapping. x is the input, and return supplies the output. For this course example, use only x∈{1,2,3}.

def next_value(x): return x + 1
print(next_value(2))

Explain: The output 3 agrees with f(2)=3. Running a few inputs checks examples; it does not replace specifying the domain and reasoning about the mapping.

13 · Practice

Work by hand first. Selected solutions appear at the end.

  1. Using S={Amina,Chen,Diya}, F={Chen,Diya,Eman}, and U={Amina,Bilal,Chen,Diya,Eman}, find F∖S, S∩F, and U∖(S∪F). Is S∩F⊆S?
  2. Let X={p,q} and Y={0,1,2}. List X×Y. How many pairs are there? Is (0,p) in X×Y?
  3. From A={a,b,c} to B={1,2}, test each assignment: (i) a→1,b→2,c→2; (ii) a→1,b→2; (iii) a→1,a→2,b→2,c→1. Explain each verdict.
  4. For h:A={a,b,c}→B={1,2,3} with h(a)=1,h(b)=1,h(c)=2, give the range. Is h one-to-one? Onto? Would it become onto if the codomain were {1,2}?
  5. For f(x)=x+1 on A={1,2,3} to B={2,3,4}, and g(y)=2y from B to C={4,6,8}, find (g∘f)(1) and (g∘f)(3). State f⁻¹(4).
  6. Can you invert m:{a,b,c}→{M,A} with m(a)=M,m(b)=M,m(c)=A on its stated whole codomain? Explain why or why not.
  7. A student says: “The range and codomain are always the same because both are outputs.” Give a small counterexample using a function from this chapter.
Exit check: Give one sentence each for the difference between ∈ and ⊆, and between “function” and “one-to-one function.”

14 · Common Mistakes

Tempting statementCorrection
Union means exactly one of the two sets.Union includes the overlap as well.
S∖F and F∖S mean the same thing.Difference depends on which set comes first.
(x,y) and (y,x) are interchangeable.Order identifies the input and output roles.
Two inputs sharing an output break a function.Sharing is allowed; it breaks one-to-one.
Every function has an inverse on its codomain.An inverse on the whole codomain needs one-to-one and onto.
In g∘f, perform g first.Evaluate the inner function f first.

15 · Summary

  • Sets describe membership. Union, intersection and difference answer different filtering questions.
  • A Cartesian product lists all ordered input-output possibilities.
  • A function assigns every domain input exactly one output; its range may be smaller than its codomain.
  • One-to-one prevents shared outputs; onto reaches every codomain element.
  • Composition applies the inner function first. An inverse on the stated whole codomain exists when a function is both one-to-one and onto.

16 · Visual Concept Map

Sets lead to ordered pairs, which can form a function; composition and inverse build on functions Setsmembers Productordered pairs Functionone output/input Propertiesone-to-one, onto Compositioncombine two maps Inverserecover the input
A function selects exactly one output for each input; further properties decide what can be combined or reversed.

17 · Key Terms

Set; subset
A collection; a set whose every member is in another set.
Cartesian product
All ordered pairs formed from two sets.
Function
A mapping giving each domain input exactly one output.
Domain; codomain; range
Allowed inputs; declared possible outputs; outputs actually produced.
One-to-one; onto
No two inputs share an output; every codomain element is reached.
Composition; inverse
Apply functions in sequence; reverse a one-to-one and onto mapping on its stated domain and codomain.

18 · Looking Ahead

Next week we study relations, which also use ordered pairs but need not assign exactly one output to each input. We will compare two kinds of relationship in an intelligent learning system: grouping learners and ordering modules by prerequisites.

Selected Solutions

Function Inspector cards

Card 1 is a function with inverse: all three inputs have one output, outputs differ, and all of B is reached. Card 2 is a function without inverse: a and b share 1, and 2 is unused. Card 3 is not a function: a has two outputs. Card 4 is a function without inverse: it reaches both values in B={1,2}, so it is onto, but a and b share 1, so it is not one-to-one. Card 4 has a smaller codomain than Card 2.

1 · Set operations

F∖S={Eman}, S∩F={Chen,Diya}, and U∖(S∪F)={Bilal}. Yes, S∩F⊆S.

2 · Product

X×Y={(p,0),(p,1),(p,2),(q,0),(q,1),(q,2)}; six pairs. (0,p)∉X×Y because 0 is not an element of X.

3 · Function test

(i) Yes, each of a, b and c has exactly one output, though b and c share 2. (ii) No: c has none. (iii) No: a has two outputs.

4 · Range and codomain

Range ={1,2}. Not one-to-one because a and b share 1. Not onto {1,2,3} because 3 is unused; onto if the codomain is {1,2}.

5 · Composition and inverse

(g∘f)(1)=g(2)=4, (g∘f)(3)=g(4)=8, and f⁻¹(4)=3.

6 · Reversing a label

No inverse function on {M,A}: M could have come from a or b, so it has no unique original input.

7 · Unused codomain value

The function h:{a,b,c}→{1,2,3} with outputs 1,1,2 has range {1,2}, smaller than codomain {1,2,3}.