In this post, we introduce the concept of relations. To begin, we'll start with sets.

## What is a Set?

A set is a collection of similar things or "elements." For example:

- We can have a group of countries of the world (USA, UK, Japan, France)
- Another set would be the cities around the world (New York City, London, Tokyo, Paris).
- It can be a set of real numbers (from 0 to infinity)

The values in the set are sometimes called objects.

## What is a Relation?

Now that we know what sets are, it's easier to define a "relation" – a link between "sets."

Let's consider the set of countries and cities. Wouldn't you agree that there is a relationship between the objects of these two sets? Like New York City to the USA, Tokyo to Japan, London to the UK, Paris to France, etc. In this case, this "connection" between these two groups is what we meant by a relation.

### Notation

Usually, we express relations in ordered pairs \((x, y)\), such as:

- (New York City, USA)
- (Tokyo, Japan)
- (London, UK)
- (Paris, France)
- (0, 0)

### Domain and Range

When discussing relations, one will often encounter the terms domain and range. We start by defining what are independent and dependent sets.

#### Independent and Dependent Sets

Every relation would have at least two sets. One set would depend entirely on the other.

To clarify, let's look at the relationship between the radius of a circle \(r\) and its area \(A\). The relation between these two sets is \(A=\pi{r^2}\).

- If we input a radius (r) of 1 into the formula, we will get an area \(A\) of \(\pi\) square units. Consequently, if we enter another radius \(r\) as long as it is any value from zero to any positive actual number, we would get a new area \(A\).

With this example, area depends on radius. We can't have an area \(A\) without the radius \(r\). In this case, the radius is the independent variable (because it can stand independently), while the area is the dependent variable (because it depends on the radius).

Going back to domain and range, we call the independent set of values the domain, while the dependent set the range. In our relation \(A=\pi{r^2}\):

- The domain (independent variable) is the set of values for radius \(r\),
- The range (dependent variable) is the set of values for area \(A\).

#### Domain and Range Would Depend on the Relation

Supposedly, we transform the area formula so that we're interested in finding the radius. By transposing, we get: \(r=\sqrt{\frac{A}{\pi}}\)

In this case, you can't have a radius without giving an area. It's the reverse of the earlier example; As such, the domain and range would also be the reverse:

- The domain (independent variable) is the set of values for area \(A\),
- The range (dependent variable) is the set of values for radius \(r\).

From this, the domain and range would depend entirely on how we look at the relation.

### How Do Relations Behave?

Relations can be any of four types:

- One-to-one
- One-to-many
- Many-to-one
- Many-to-many

#### One-to-One

*An object of one set corresponds to only one element of the other set.*

- An example is a relation between people (domain) and their fingerprints (range). There are billions of people in the world, and each person has a unique pattern of fingerprints. Ideally, there can't be any two persons having the same fingerprints.

#### One-to-Many

*An object of one set corresponds to many elements of the other set.*

- A perfect example would be the square numbers (domain) and their roots (range). From mathematics, if we take the square root of a number, there are two values in the positive and negative sense. For example, if we take the square root of 4, we will have +2 and -2. There is only one entry in the domain (square numbers), but it links to two entries in the range (its roots).

#### Many-to-One

*Objects of one set correspond to only one element of the other set. *

- A good example would be the link between integers (domain) and square numbers (range). For instance, the square of -1 and +1 is 1, the square of -2 and +2 is 4, the square of -3 and +3 is 9, and so on. We can say it's the reverse of "one-to-many."

#### Many-to-Many

*Objects of one set correspond to many elements of the other set.*

- An example is the set of customers (domain) and the products they bought (range). Customers can purchase many products, while products are bought by multiple customers.

## Summary

A set is a collection of similar things or "elements."

A "relation" is a link between "sets."

We express relations in ordered pairs \((x, y)\)

Every relation would have at least two sets. One set would depend entirely on the other.

We call the independent set of values the domain, while the dependent set the range.

The domain and range depend entirely on how we look at the relation.

Relations can be any of four types: (1) one-to-one, (2) one-to-many, (3) many-to-one, and (4) many-to-many.

One-to-one relation:An object of one set corresponds to only one element of the other set.

One-to-many relation:An object of one set corresponds to many elements of the other set.

Many-to-one relation:Objects of one set correspond to only one element of the other set.

Many-to-many:Objects of one set correspond to many elements of the other set.