# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import matplotlib.pyplot as plt
# %matplotlib inline

# One of the basic things we have to do in math is to express numbers. Numbers are the basic particles of essence so it makes sense to start with them first. We'll start with the *natural numbers* and work our way up through the whole spectrum of numbers finally arriving at the *complex numbers*.
#
# We'll see that every type of number has a use. These numbers are not just cooked up because somebody figured that would be cool. No, every number serves a definite purpose and even though we might not always understand completely what that purpose is that does not mean we shouldn't use them in order to try a greater understanding.
#
# Take for example the number $\sqrt{2}$ which is a perfectly fine number nowadays. However, how hard we might try, there's really no other way to write down this number. We could try for an approximation like $1.4142135\ldots$ but that's really just being sloppy. There *are* other ways to write this number but we will never get a *real* number out of it. Only approximations.
#
# ### natural numbers
# Some people like to include the number zero in this set but we'll stick with with the numbers $1, 2, 3, \ldots, n$ where $n \gt 0$. They are basically all the whole numbers.
#
# $$\mathbb{N} = {1, 2, 3, \ldots}$$
#
# If we want to be really unambiguous about what we mean we could be extra explicit.
#
# $$
# \begin{align}
# \mathbb{N^0} = \mathbb{N_0} & = {0, 1, 2, 3, \ldots}\\
# \mathbb{N^*} = \mathbb{N^+} = \mathbb{N_1} = \mathbb{N_{\gt 0}} & = {1, 2, 3, \ldots}
# \end{align}
# $$
#
# If we really want to include zero in this text we'll use a different set though.
#
# ### whole numbers
# This is all of the numbers in $\mathbb{N}$ and the number zero. We don't have any cool letter for this though but we can say it's all the whole numbers $0, 1, 2, \ldots, n$ where $n \ge 0$.
#
# ### integers
# Now this is an interesting set. If only because it's so prevalent in almost all math that we do. For example, computers love integers because they can be so easily represented by a sequence of bits. 
#
# Integers is the set of *whole numbers* but it also includes all the negatives of the *natural numbers*. So now were talking about $-n, \ldots, -2, -1, 0, 1, 2, \ldots, n$. This set is important enough to get its own symbol:
#
# $$\mathbb{Z} = {-n, \ldots, -2, -1, 0, 1, 2, \ldots, n}$$
#
# ### interlude: integers
# Even though we are not even half-way up our ladder of number systems those integers are already getting a bit interesting. Why do we like them so much in computing? Well, because they can easily be represented as a sequence of one and zero. How does this work though?
#
# If we look at any integer, let's take for example $321$ and analyze what it means we can come to the insight that:
#
# $$321 = (3 \times 100) + (2 \times 10) + (1 \times 1)$$
#
# If we look a little deeper we can also see that $100 = 10^2$, $10 = 10^1$ and $1 = 10^0$ so in other words:
#
# $$321 = (3 \times 10^2) + (2 \times 10^1) + (1 \times 10^0)$$
#
# Our number system is called the *decimal* system and that's because we have base `10` numbers. There other number systems. Other sytems that are in commonly in use are *binary*, *hexadecimal* and sometimes *octal*. The binary system is popular because it aligns with electronic switches that can be either on or off. There are only two possibilities and that is what binary means. The octal system is sometimes used because it aligns nicely with the *byte* memory unit in computers but you don't see it much these days. However, the hexadecimal system is still prevalent and you'll see a lot, for example in color codes.
#
# So how does the binary system work? Well remember that the decimal system operates on *powers* of ten so the binary system operates on power of two.
#
# $$
# \begin{align}
# 0 = 0 \times 2^0 & = 0\\
# 1 = 1 \times 2^0 & = 1 \\
# 2 = (1 \times 2^1) + (0 \times 2^0) & = 10 \\
# 3 = (1 \times 2^1) + (1 \times 2^0) & = 11 \\
# 4 = (1 \times 2^2) + (0 \times 2^1) + (0 \times 2^0) & = 100 \\
# 5 = (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0) & = 101 \\
# 6 = (1 \times 2^2) + (1 \times 2^1) + (0 \times 2^0) & = 110 \\
# 7 = (1 \times 2^2) + (1 \times 2^1) + (1 \times 2^1) & = 111
# \end{align}
# $$
#
# ### rational numbers
# We get rational numbers when we need to express one integer as some part of another. When people started doing real math this problem soon cropped up. The easier way to deal with it is to kind of *not* deal with it and just say well it's this number expressed as some ratio of another. This might be a bit abstract so let's take an example.
#
# When we first started doing divisions we took stuff like $\frac{3}{3} = 1$ and the world was good. As people started doing more fancy stuff with math and numbers things got a bit out of hand though. At some point we found ourselfs in the need to express something else than *integers*. As always, when math runs into a wall we'll just invent something to get over it. And as such we got *rational numbers* which are basically just *fractions* like $\frac{1}{3}$ or $\frac{1}{\pi}$.
#
# At this point note that in order to get better numbers we just take some existing numbers we know and combine them in some way that makes sense but is somewhat unexpected. I mean, people are still drawing out proplems with triangles and such and now you're starting to abstract some of this stuff away. And it makes sense too because you don't want to lose any information. By keeping that number in its exact *ratio* $\frac{1}{3}$ you will have a clean number to calculate with.
#
# Which leads us to the unfortunately necessary...
#
# ### real numbers
# Let me start by saying that *real numbers* are unfortunately named because most of them are anything but real. Real numbers are supposed to be plotted along a line (usually the x-axis) and they are but when we *do have* to work with them they are usually just an approximation of a rational number.
#
# We like to be pure as long as we can so we'll use rational numbers over real numbers but sometimes (especially dealing with computers) we'll *have* to convert our rational number to some *real* approximation. For most purposes you can just think of a *real* number as an *approximation* of some rational number that is to be used for real-life purposes.
#
# ### irrational numbers
# These are interesting numbers because they are so called *real* numbers but we cannot express them as a rational number. As always, when we encounter such a thing in math we tend to give it a name or a convenient notation. Examples are $\pi$, our friend $\sqrt{2}$ and $e$.
#
# Irrational numbers are awkward and in order to stay pure we sometimes can do no better than express something as a fraction of an irrational unit. Of course we could try to get a *real* number out but we have to remember that this will always be an approximiation. This might be fine though depending on our purposes.
#
# ### imaginary numbers
# This is where things start to get really interesting (and strange). After hundreds of years of working on math puzzles mathematicians where getting annoyed by the fact that this $\sqrt{-1}$ kept popping up in their would-be solutions. And (at that time) there was no possible way to calculate a negative *square root* so they just gave up... Mostly. Finally they just decided to go with it and complete the calculations involving the negative square root $\sqrt{-1}$ and things turned out beautifully. 
#
# After a few more hundred years it has become so useful that we gave it a special notation and even a special algebra so it all makes sense as a number as well.
#
# So the first thing we have to consider is that we have this new number now called $i$ which is defined as $i^2 = -1$ so $i = \sqrt{-1}$. Now we can just use regular algebra to express any negative root, for example if we need $\sqrt{-5}$ I could just go ${i \times \sqrt{5}}$ and this simple transformation allows us to actually calculate with those things.
#
# Note that the name *imaginary* is actually a bad name. These numbers *are* real in the normal sense of that word. The fact that we describe them this way is just byproduct of the way we write math in general. It's better to look at any number and imagine it to have a so-called *imaginary* component. In a lot of cases this will just be $0 \times i$ (no imaginary component) but sometimes they do.
#
# ### complex numbers
# In some sense, this is the best way to describe a number. This form of numbers is called *complex* buty they are not really that complex though. Again, this is kind of a misnomer and actually complex numbers are very easy. In fact, they are just numbers.
#
# It's just so many numbers we deal with are on the x-axis of the *complex plane* that we don't even notice we are dealing with complex numbers at all. Thanks to a lot of evolution and schooling we can now reasonably *feel* how most numbers work up to and including rational numbers. However, *imaginary* and *complex numbers* are still a bit weird.
#
# One of the best ways to show how complex numbers enter math is to show an innocent looking equation like: $y = x^2 + 1$. If we try to solve this for $y = 0$ we get $0 = x^2 + 1$. And going further we get $-1 = x^2 \implies x = \sqrt{-1}$. Before complex numbers there was no such thing as $\sqrt{-1}$ and we would have simply given up.
#
# Nowadays we can say that the solution is $i$ (and $-i$ is a valid solution too).



StarcoderdataJupyterScriptsDedupFiltered