03 Sets, Relations, and Functions

Updated 4 Oct 2026

Set

  • อาจจะมีการไปรวมกับ 02 Method of Proofs เช่น Proof By Contradiction พวก Show that ต่าง ๆ

Two Ways of Describing Sets

Extensional Description

  1. เขียนแบบแจกแจงสมาชิก ซึ่งเป็นการเขียนแสดงสมาชิกของเซตให้เห็นออกมาเลยว่ามีอะไรบ้าง \ceA={2,4,6,8,10}\ce{A}=\{2,4,6,8,10\}

Intensional Description

  1. เขียนแบบบอกเงื่อนไข เป็นการบรรยาลักษณะ (เงื่อนไข) ของสมาชิกแล้วให้คนอ่านแปลเอาเอง ตัวอย่างเช่น เซต A ด้านบนอาจเขียนแบบบอกเงื่อนไขได้ดังนี้ \ceA={2x ∣ x∈N , 1≤x<6}\ce{A}=\{2x \ | \ x\in \mathbb{N} \ , \ 1\le x < 6\} ทั้งนี้ การเขียนเซตแบบบอกเงื่อนไข สามารถเขียนได้หลายแบบขึ้นอยู่กับเงื่อนไขของผู้เขียน

Empty Set

  • เซตว่าง คือ เซตที่ไม่มีสมาชิก เขียนแทนด้วยสัญลักษณ์ ∅\varnothing
    • เช่น เซตของเลขคู่ที่หารด้วย 2 ไม่ลงตัว

Cardinality

  • For any finite set XX, denote by ∣X∣|X| the number of (distinct) elements of XX.
    • ทำให้เป็น Set ที่ไม่มีตัวซ้ำกันก่อนนะ! อย่าลืม พลาดตลอดดดดด

Membership

  • Write a∈Xa\in X, if and only iff aa is a member of set XX
    • 1∈{1,2,3}1\in\{1,2,3\}
    • 1∉{x∣ x is a positive and even integer}1\notin\{x|\text{ }x\text{ is a positive and even integer\}}

Equality

  • Two set XX and YY are equal (X=YX=Y), if and only if they have exactly the same elements.
  • This is, X=YX=Y, if and only if
    1. Every element of XX is an element of YY
    2. Every element of YY is an element of XX

Set Inclusion

  • A set XX is a subset of a set YY, denoted by X⊆YX\subseteq Y, if and only if every element of XX is an element of YY.

Proper Subset

  • ก็คือ Subset ธรรมดานี่แหละ (แต่ไม่รวมตัวมันเอง!!) – ซับเซตแท้
  • A เป็น สับเซตแท้ (Proper subset) ของ B เมื่อ \ceA⊂\ceB\ce{A}\subset\ce{B} แต่ \ceA≠\ceB\ce{A}\ne\ce{B} (ไม่ใช่เซตตัวมันเอง)
  • จำนวนของ Proper Subset เท่ากับ 2n−12^n-1 (หักตัวมันเองทิ้งไป)

Power Set

  • The “power set” of x → The set of all subsets of x
  • If ∣X∣=n|X|=n, then ∣P(X)∣=2n|P(X)|=2^n

Union, Intersection, Difference

  • Let X,YX,Y be sets.
    • X∪YX\cup Y
      • เซตที่ได้จากการนำสมาชิกจาก A และ B มารวมเข้าด้วยกัน
    • X∩YX\cap Y
      • เซตของสมาชิกที่มีซ้ำกันทั้งใน A และ B
    • X−YX - Y
      • เซตของสมาชิกอยู่ใน A แต่ไม่อยู่ใน B
  • อันนี้ก็จินตนาการเป็น Venn diagram เอาก็ได้ ไม่น่ายากอะไร!

Disjoint Sets

  • XX and YY are set to be disjoint, if and only if X∩Y=∅X\cap Y=\varnothing
  • Clearly, if XX and YY are disjoint, then X−Y=XX-Y=X

Universal set (U)

  • A universal set (U\mathbb{U}) is a superset of all the sets we are dealing with. If U\mathbb{U} is not explicitly given, it must be inferred from the context.
    • ในการกล่าวถึงเซตใด ๆ จะมีการอ้างอิงกับเซต ๆ หนึ่ง ซึ่งตกลงกันว่าจะไม่กล่าวถึงสมาชิกตัวอื่นที่อยู่นอกเหนือจากเซตนี้ เรียกว่า เอกภพสัมพัทธ์ (Universal Set) เขียนแทนด้วยสัญลักษณ์ U\mathbb{U}
    • ในกรณีที่ไม่กำหนดเอกภพสัมพัทธ์มาให้ จะถือว่า U\mathbb{U} คือ เซตของจำนวนจริง (R\mathbb{R})

Set Complement

  • \ceA′\ce{A'} หรือว่า \ceAc\ce{A^c} คือ เซตของสมาชิกที่ไม่ได้อยู่ใน A (อยู่ข้างนอก A) แต่ยังอยู่ใน Universe อยู่ ดังแผนภาพ
    • หรือจะคิดว่าหมายถึง U−\ceA\mathbb{U} - \ce{A} ก็ได้

Laws

  • สามารถใช้ Venn Diagram พิสูจน์ Law เหล่านี้ได้!

Associative Laws (The Grouping is Not Important)

A∪(B∪C)=(A∪B)∪CA \cup (B \cup C) = (A \cup B) \cup C A∩(B∩C)=(A∩B)∩CA \cap (B \cap C) = (A \cap B) \cap C

Commutative Laws

  • Order in ∩\cap or ∪\cup operations makes no difference.
A∪B=B∪AA\cup B=B\cup A A∩B=B∩AA\cap B=B\cap A

Distributive Laws

A∩(B∪C)=(A∩B)∪(A∩C)A\cap(B\cup C)=(A\cap B)\cup(A\cap C) A∪(B∩C)=(A∪B)∩(A∪C)A\cup(B\cap C)=(A\cup B)\cap(A\cup C)

Identity Laws

A∪∅=AA\cup\varnothing=A A∩U=AA\cap U=A

Complement Laws

A∪∅=AA\cup\varnothing=A A∩U=AA\cap U=A

Idempotent Laws

A∪A=AA\cup A =A A∩A=AA\cap A =A

Bound Laws

  • ถ้าไป ∪\cup กับตัวที่ใหญ่กว่า ก็จะเป็นตัวที่ใหญ่กว่า
  • แต่ถ้าไป ∩\cap กับตัวที่เล็กกว่า (อย่างเช่น ∅\varnothing) ก็ได้เป็นตัวที่เล็กกว่าทันที
A∪U=UA\cup U=U A∩∅=∅A\cap\varnothing=\varnothing

Absorption Laws

A∪(A∩B)=AA\cup(A\cap B)= A A∩(A∪B)=AA\cap(A\cup B)= A

Involution Law

Aˉˉ=A\bar{\bar{A}}=A

De Morgan’s Law for Sets

  • อันนี้ก็คล้าย ๆ กับ Break the bar change the sign (∩\cap → ∪\cup)
A∪B‾=Aˉ∩Bˉ\overline{A\cup B}=\bar{A}\cap\bar{B} A∩B‾=Aˉ∪Bˉ\overline{A\cap B}=\bar{A}\cup\bar{B}

Cartesian Product

  • เป็นเซตของคู่อันดับทั้งหมดที่เป็นไปได้
  • จะหาว่ามีกี่คู่อันดับที่เป็นไปได้ ก็ใช้ Probability ง่าย ๆ Choices หน้า ×\times Choices หลัง
  • If X={1,2,3}X = \{1, 2, 3\} and Y={a,b}Y = \{a, b\}, then
    • X×Y=(1,a),(1,b),(2,a),(2,b),(3,a),(3,b)X \times Y = {(1, a), (1, b), (2, a), (2, b), (3, a), (3, b)}
    • Y×X=(a,1),(b,1),(a,2),(b,2),(a,3),(b,3)Y \times X = {(a, 1), (b, 1), (a, 2), (b, 2), (a, 3), (b, 3)}
    • X×X=(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)X \times X = {(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)}
    • Y×Y=(a,a),(a,b),(b,a),(b,b).Y \times Y = {(a, a), (a, b), (b, a), (b, b)}.
  • Tuple is a set of 3 elements

Relation

  • A (binary) relation is a set of links that connects elements of two sets.
  • Each link is represented as a pair
  • Therefore, relation → set of a pair (จริง ๆ ก็คล้าย ๆ Cartesian Product นะ แต่ว่าไม่ได้เอาทุก Possible combination)
    • อาจารย์พูดในห้องจริง ๆ ว่าจะ relate กับ Cartesian Product ยังไง
    • R1R_1 is the subset of X×YX \times Y

Formal Definition

A (binary) relation (RR) from a set XX to a set YY is a subset of the Cartesian product X×YX\times Y

  • ถ้าเต็ม ๆ (Cartesian product) ก็ถือว่าเป็น Relation เหมือนกัน

Notation

If (x,y)∈R(x,y) \in {R}, we write x R yx\text{ }{R}\text{ }y

  • The domain of R\mathbb{R} is the set
    • {x∈X∣(x,y)∈R\{x \in X | (x,y)\in{R} for some y∈Y}y \in Y\}
  • The range of R\mathbb{R} is the set
    • {y∈Y∣(x,y)∈R\{y \in Y | (x,y)\in{R} for some x∈X}x \in X\}

A relation from XX to XX is simply called a relation on XX

  • เวลาโจทย์ถามว่า How many relations from XX to YY are there? — คือมันถามประมาณว่า จะมีทั้งหมดกี่ Relation ซึ่ง Relation มันก็เป็น Subset ของ Cartesian product อีกที ดังนั้นก็ตอบจำนวน Subset ไปเลย =2n=2∣X∣×∣Y∣=2^n = 2^{|X|\times|Y|}

Digraph

  • Let RR be the relation on X={1,2,3,4}X = \{ 1, 2, 3, 4\} defined by (x,y)∈R(x, y)\in R if x≤y,x,y∈Xx \le y, x, y \in X. Then
    • R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}R = \{ (1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4) \}
    • An informative way to picture a relation on a set is to draw its digraph.
      • We’ll discussed in more detail in 07 Graphs
      • For now, we mention digraphs only in connection with relations.)
    • To draw the digraph of a relation on a set XX, we first draw dots or vertices to represent the elements of XX.
    • Next, if the element (x,y)(x, y) is in the relation, we draw an arrow (called a directed edge) from xx to yy.

Basic Types of Relations

Reflexive

  • RR is called reflexive, iff for each a∈X,(a,a)∈Ra \in X, (a,a) \in{R}
    • if a∈xa\in x, then (a,a)∈R(a,a)\in{R}

There’s must be a self-loop at every single element.

Symmetric

  • RR is called symmetric, iff for all a,b∈Xa,b \in X
    • if (a,b)∈R(a,b) \in {R}, then (b,a)∈R(b,a)\in{R}

Whenever you see a link, you must see reverse of that link!
(Even empty maps is considered symmetric)

Antisymmetric

  • RR is called antisymmetric, iff for all a,b∈Xa,b \in X
    • if (a,b)∈R(a,b) \in {R}, and a≠ba\ne b, then (b,a)∉R(b,a)\notin{R}
    • ที่ต้องมี a≠ba\ne b เพราะว่าจะได้ satisfy self-loop is okay

No loop containing two different elements (ทั้งไปและกลับ) → Self-loop is okay
(Even empty maps is considered antisymmetric)

Warning


Antisymmetric ≠\ne Not symmetric
ลองดู Empty maps เป็นตัวอย่าง

Transitive

  • RR is called transitive, iff for all a,b,c∈Xa,b,c \in X
    • if (a,b)∈R(a,b) \in {R}, and (b,c)∈R(b,c)\in {R}, then (a,c)∈R(a,c)\in{R}
  • มันเป็น If-then (Conditional statement) ถ้าไม่มี Link หรือว่าเป็น Empty (maps) relation ไม่ต้อง Check conclusion part แล้ว มันเป็น True เสมอ ถ้างงว่าทำไม Empty maps เป็น Transitive

If there’s a link (from a to b, b to c), there must be a link (from a to c)
(Even empty maps is considered transitive)

  • ในข้อสอบอาจจะมีให้ Proof (เวลา True), Disprove (เวลา False)

Partial Order

RAT

  • A relation RR on a set XX is called a partial order*
    • If and only if RR is reflexive, antisymmetric, and transitive
    • No cycle other than self-loop!
    • Since a partial order is reflexive, there will be self loop at every element.
  • If x,y∈Xx,y\in X and either x⪯yx \preceq y or y⪯xy \preceq x, we say that xx and yy are comparable.
    • สามารถตอบได้ว่า Element ไหนใหญ่กว่า ถ้ามีลูกศรโยงไป
      • ท้าย ๆ จะใหญ่กว่า ด้านหน้า
  • If every pair of elements in XX is comparable, we call RR a total order.

Inverse

  • Let RR be a relation from XX to YY. The inverse of R, denoted R−1R^{-1} is the relation from YY to XX defined by R−1={(y,x)∣(x,y)∈R}R^{-1}= \{(y, x) | (x, y) \in R \}
  • R={(2,4),(2,6),(3,3),(3,6),(4,4)}R =\{ (2, 4), (2, 6), (3, 3), (3, 6), (4, 4)\} (If xx divides yy)
  • R−1={(4,2),(6,2),(3,3),(6,3),(4,4)}R^{-1} =\{ (4, 2), (6, 2), (3, 3), (6, 3), (4, 4)\} (Is divisible by)

Composition

  • If we have a relation R1R_1 from XX to YY and a relation R2R_2 from YY to ZZ, we can form the composition of the relations by applying first relation R1R_1 and then relation R2R_2.
  • Composition of relations generalizes composition of functions. The formal definition follows.
    • Let R1R_1 be a relation from XX to YY and R2R_2 be a relation from YY to ZZ. The composition of R1R_1 and R2R_2 , denoted R2◦R1R_2 ◦ R_1 , is the relation from XX to ZZ defined by R2◦R1={(x,z)∣(x,y)∈R1 and (y,z)∈R2 for some y∈Y}R_2 ◦ R_1 = \{ (x, z) | (x, y) \in R_1\text{ and } (y, z) \in R_2 \text{ for some } y \in Y \}
  • อันนี้ก็คล้าย ๆ Composition ที่เคยเรียนใน Function นั่นแหละ แต่อันนี้มันอยู่ใน Terms ของ Sets เลยงงหน่อย
    • โอเค เข้าใจแล้ว — ก็ถ้าสมมติเราทำ f◦gf ◦ g ให้มอง gg ก่อน เช่น
      • g={(1,2),(1,6),(2,4),(3,4),(3,6),(3,8)}g = \{ (1, 2), (1, 6), (2, 4), (3, 4), (3, 6), (3, 8) \}
      • f={(2,u),(4,s),(4,t),(6,t),(8,u)}f = \{ (2, u), (4, s), (4, t), (6, t), (8, u) \}
    • ลองมอง gg ก่อน (1,2)(1,2) แล้ว Output คือ 2 มาดู Input ของ ff เจอ (2,u)(2,u) ดังนั้นได้ (1,u)(1,u) ทำไปเรื่อย ๆ

Pairwise Disjoint Collection of Sets

  • Let SS be a collection of sets.
    • SS is said to be pairwise disjoint, if and only for distinct sets X,YX,Y in SS, XX and YY are disjoint.

Partition

  • A partition of a set XX is a collection SS of subsets of XX such that
    1. SS is pairwise disjoint, and
    2. ∪S=X\cup S = X

Equivalence Relation

RST

  • An equivalence relation on a set is a relation that is (เหมือนการเท่ากับ เช่น 3=33=3)
    • Reflexive
    • Symmetric
    • Transitive

Equivalence Class