# Introduction

Calculus is a branch of mathematics that gives tools to study rate of change of functions trough two main areas: derivatives and integrals.

In the context of machine learning and data science, you can for instance use derivatives to optimize the parameters of a model with gradient descent. You might use integrals to calculate area under the curve.

## Functions

A function is a rule that takes one or more inputs and produces a single output. For example, the function \(f(x) = x + 1\) takes a single input \(x\), adds one to it, and produces a single output.
In algebra, functions are written using symbols and formulas. For example, the function \(f(x) = x + 1\) can be written as \(f:x \rightarrow x + 1\).
The input to a function is called the **argument** or **input variable**. The output is called the **value** or **output variable**.

Functions are often written using the following notation:

The notation above is read as “\(y\) equals \(f\) of \(x\)” or “\(y\) is a function of \(x\)”. The notation above is useful because it allows us to define a function without specifying its name. For example, we can define a function \(f\) as follows:

We can then use the function \(f\) to compute the square of any number. For example, \(f(2) = 2^2 = 4\) and \(f(3) = 3^2 = 9\).

### Domain and Range of a Function

The **domain** of a function is the set of all possible inputs to the function. The **range** of a function is the set of all possible outputs of the function.
For example, the function \(f(x) = x^2\) has a domain of all real numbers and a range of all non-negative real numbers.
The domain of a function is often written as \(D(f)\) and the range is often written as \(R(f)\).

```
import seaborn as sb
func = lambda x: x ** 2
x = [-1,-2,-3, -4, 1, 2, 3, 4]
y = [func(i) for i in x]
sb.lineplot(x=x, y=y)
```

```
/home/docs/checkouts/readthedocs.org/user_builds/ml-math/envs/latest/lib/python3.10/site-packages/seaborn/_oldcore.py:1498: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if pd.api.types.is_categorical_dtype(vector):
/home/docs/checkouts/readthedocs.org/user_builds/ml-math/envs/latest/lib/python3.10/site-packages/seaborn/_oldcore.py:1498: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
if pd.api.types.is_categorical_dtype(vector):
/home/docs/checkouts/readthedocs.org/user_builds/ml-math/envs/latest/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.
with pd.option_context('mode.use_inf_as_na', True):
/home/docs/checkouts/readthedocs.org/user_builds/ml-math/envs/latest/lib/python3.10/site-packages/seaborn/_oldcore.py:1119: FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version. Convert inf values to NaN before operating instead.
with pd.option_context('mode.use_inf_as_na', True):
```

```
<Axes: >
```

### Piecewise Functions

A piecewise function is a function that is defined by multiple sub-functions, each sub-function applying to a different interval of the main function’s domain. For example, the function \(f(x) = |x|\) is defined by two sub-functions:

## Expoents

An exponent is a number that indicates how many times a base number is multiplied by itself.
For example, \(2^3\) is the same as \(2 \times 2 \times 2\) and \(2^4\) is the same as \(2 \times 2 \times 2 \times 2\).
The number \(2\) is called the **base** and the number \(3\) is called the **exponent**.
Exponents are often written using the following notation:

The notation above is read as “two to the power of three” or “two cubed”.

### Negative Exponents

A negative exponent indicates that the base number should be divided by itself a certain number of times.
For example, \(2^{-3}\) is the same as \(\frac{1}{2^3}\) and \(2^{-4}\) is the same as \(\frac{1}{2^4}\).
The number \(2\) is called the **base** and the number \(-3\) is called the **exponent**.
Negative exponents are often written using the following notation:

The notation above is read as “two to the power of negative three” or “two to the power of minus three”.

### Fractional Exponents

A fractional exponent indicates that the base number should be multiplied by itself a certain number of times.
For example, \(2^{\frac{1}{2}}\) is the same as \(\sqrt{2}\) and \(2^{\frac{1}{3}}\) is the same as \(\sqrt[3]{2}\).
The number \(2\) is called the **base** and the number \(\frac{1}{2}\) is called the **exponent**.
Fractional exponents are often written using the following notation:

The notation above is read as “two to the power of one half” or “two to the power of one over two”.

## Logarithms

A logarithm is the inverse of an exponent. For example, the logarithm of \(2^3\) is \(3\). The logarithm of a number \(x\) to the base \(b\) is written as \(\log_b(x)\). For example, \(\log_2(8) = 3\) because \(2^3 = 8\).

### Common Logarithms

The common logarithm of a number \(x\) is the logarithm of \(x\) to the base \(10\). The common logarithm of \(x\) is written as \(\log(x)\). For example, \(\log(100) = 2\) because \(10^2 = 100\).

### Natural Logarithms

The natural logarithm of a number \(x\) is the logarithm of \(x\) to the base \(e\). The natural logarithm of \(x\) is written as \(\ln(x)\). For example, \(\ln(100) = 4.60517\) because \(e^{4.60517} = 100\).

## Polynomials

A polynomial is an expression consisting of variables and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponents.

For example, \(x^2 + 2x + 1\) is a polynomial because it consists of the variables \(x\) and the coefficients \(1\) and \(2\).

The degree of a polynomial is the highest degree of its terms. For example, the polynomial \(x^2 + 2x + 1\) has a degree of \(2\) because its highest degree term is \(x^2\).