Let's break down the concepts of sets, relations, and functions with examples in JavaScript.
Sets, Relations, and Functions:
1. Sets:
A set is a collection of well-defined objects or elements. These objects can be anything like numbers, letters, or even other sets. Sets are usually denoted by curly braces {}
.
Example of a Set:
Operations on Sets:
Union (A ∪ B): Combines elements from both sets.
Intersection (A ∩ B): Finds elements common to both sets.
Difference (A - B): Elements in A that are not in B.
2. Relations:
A relation between two sets is a collection of ordered pairs where the first element is from the first set, and the second element is from the second set. In JavaScript, a relation can be represented as a set of pairs.
Example of a Relation:
Consider two sets:
- Set A = {1, 2, 3}
- Set B = {a, b, c}
A relation R
from A
to B
can be represented as a set of ordered pairs:
Types of Relations:
Reflexive Relation: A relation
R
is reflexive if every element of setA
is related to itself. For example, ifA = {1, 2, 3}
, thenR = {(1, 1), (2, 2), (3, 3)}
is reflexive.Symmetric Relation: A relation
R
is symmetric if for every pair(a, b)
inR
, the pair(b, a)
is also inR
. Example: If(1, 2)
is inR
, then(2, 1)
must also be inR
.Transitive Relation: A relation
R
is transitive if for alla, b, c ∈ A
, whenever(a, b)
and(b, c)
are inR
, then(a, c)
must also be inR
.
3. Functions:
A function is a special type of relation where each element in the domain (the first set) is related to exactly one element in the codomain (the second set). A function can be denoted as f: A → B
, where A
is the domain, and B
is the codomain.
Example of a Function:
Let’s say:
- Set A = {1, 2, 3}
- Set B = {a, b, c}
A function f: A → B
could be:
Types of Functions:
One-to-One (Injective): A function is one-to-one if different elements of the domain map to different elements of the codomain. In our example,
f
is one-to-one because no two elements inA
map to the same element inB
.Onto (Surjective): A function is onto if every element of the codomain has at least one element from the domain mapping to it. For instance, if
B = {a, b, c}
andf = {1 → a, 2 → b, 3 → c}
, the function is onto because every element inB
has a corresponding element inA
.One-to-One Correspondence (Bijective): A function is bijective if it is both one-to-one and onto, meaning there is a perfect pairing between the elements of the domain and codomain.
Example of a Bijective Function:
Let’s say:
- Set A = {1, 2, 3}
- Set B = {a, b, c}
A bijective function f: A → B
could be:
In this case, the function is both injective and surjective, making it bijective.
Summary of Examples:
- Set Operations (Union, Intersection, Difference)
- Relation (Set of ordered pairs)
- Function (Mapping of domain to codomain)
![]() |
Sets, Relations, and Functions |
No comments:
Post a Comment