User:Addemf/sandbox/Technical Reasoning/Naive Set Theory

Every branch of modern mathematics is touched by set theory in some way. The various fields of logic, analysis, algebra, and geometry, just to name a few, simply cannot be discussed with depth, if we don't have the language of set theory to help.

Therefore a prerequisite before we return to the core goals of this course will be a basic familiarity with set theory.

Introduction
A set is way of expressing some kind of grouping or collecting together (if only in one's mind) various objects. For example, the set


 * $$ \{-2, 10, 13\}$$

represents the collection of the numbers $$-2, 10, 13$$. In general, if we are to list the members of a set, we begin by writing an open curly-brace, then proceed to list the elements, then write a close curly-brace.

If an element is in a set then we write, for example,


 * $$-2\in\{-2,10,13\}$$

If an element is not in a set then we write, for example,


 * $$0\notin \{-2,10,13\}$$

Sets need not contain numbers. In general we will allow sets to contain just about anything.

There are some things which we will not permit to be called "sets", but they are very weird things that we will not currently discuss.

For example, we may consider the set of North American presidents in the year 2000.


 * {Echeverría, Shaw, Pérez, Arzú, Préval, Flores, ...}

These former presidents are listed in no particular order and it is not a complete list, as suggested by the ellipsis.

Much more relevant to our interests will be sets of other kinds of mathematical objects. For instance, consider the line in the plane defined by the equation $$y = 2x+1$$. Call this line $$\ell$$.

We can regard $$\ell$$ as the set of all of points on the line. The point $$(1,3)$$ has x-coordinate $$x=1$$ and y-coordinate $$y=3$$. Because these satisfy the equation $$y = 2x+1$$ then therefore the point (1,3) is on the line $$\ell$$.

Therefore $$(1,3)\in\ell$$.

Any pair of numbers which satisfy the equation, like (0,1) or (2.1,3.2), will also be elements of $$\ell$$. So this may come as a bit of a revelation: A line is a certain kind of a set!

Short-hand for Many Elements
Technically, to express every element of the set $$\{-2,10,13\}$$ we should write
 * $$-2\in\{-2,10,13\}, \text{ and } 10\in\{-2,10,13\}, \text{ and } 13\in\{-2,10,13\}$$

But we will frequently use the shorthand,
 * $$-2,10,13\in \{-2,10,13\}$$

to express multiple element statements all at the same time.

Definition
A set is defined only by its members. As such, it is not defined by the order in which the members are listed in the set.

Therefore the sets $$\{-2,10,13\}$$ and $$\{13,10,-2\}$$ are the same set. Therefore we write


 * $$\{-2,10,13\} = \{13,10,-2\}$$

Not only this, but also sets are not defined by how many times a given element is listed. If the element is in, then it is in, and that's all there is to it. Therefore also


 * $$\{-2,10,13\} = \{-2,10,10,13,13,13\}$$

On the other hand, the sets $$\{-2,10,13\}$$ and $$\{-2,10\}$$ are not equal. This is exhibited by the fact that $$13\in\{-2,10,13\}$$ while $$13\notin \{-2,10\}$$.

We can construct a set in SymPy by writing, for example,

Check in SymPy that $$\{-2,10,13\} = \{13,10,-2\}$$.

Subsets


Although the sets $$\{-2,10,13\}$$ and $$\{-2,10\}$$ are not equal, we can say that the second is a subset of the first. This is because all of the elements of $$\{-2,10\}$$ are contained in $$\{-2,10,13\}$$.

If we prefer to say this in notation, then X is a subset of Y if for every $$e\in X$$ we have $$e\in Y$$.

It is immediate from our definitions that $$X = Y$$ if and only if $$X\subseteq Y$$ and $$Y\subseteq X$$.

Consider the sets
 * $$\begin{aligned}

A & = \{1,2,3\}, & B &= \{2,3,4\}, & C & = \{1,2\} \end{aligned}$$ Of the three sets, decide if any of them is a subset of another.

Suppose X, Y, and Z are sets, with $$ X\subseteq Y$$ and $$Y\subseteq Z$$. Show that $$X\subseteq Z$$.

What is the difference between "being an element of" and "being a subset of"? That is to say, when should we write $$a\in X$$ instead of $$a\subseteq X$$?

Suppose that $$X = \{1,2,3\}$$. Then


 * $$1\in \{1,2,3\}$$

but


 * $$1\not\subseteq \{1,2,3\}$$

because 1 is not a set!

In order for something to be a subset, it must first be a set. Then moreover, every element in it must be in the other set.

However, the following subset relation is true.


 * $$\{1\}\subseteq \{1,2,3\}$$

Also,


 * $$\{1\}\not\in\{1,2,3\}$$

because the set $$\{1\}$$ is not found among the elements 1, 2, 3.

For each of the following,
 * $$\{ 1, 2, 3\}$$
 * 1
 * $$\{1\}$$
 * $$\{ \{1\}, 2, 3\}$$

If any one of them is a subset of another, state it.

If any one of them is an element of another, state it.

How many elements are in the set $$A = \{\{1,2,3\},4,5\}$$?

Hint: We can say $$\{1,2,3\}\in A$$. But it would not be true to say $$1\in A$$.

Roster Notation
How can we write down a set which is infinite? Although we cannot write every element, we can sometimes write a pattern which the reader can easily understand. For example, if we want to write all positive even natural numbers, we could write this as


 * $$\{2, 4, 6, \dots\}$$

When we define a set, like $$\{2,4,6,...\}$$, by listing its elements, perhaps with an ellipsis to suggest that the pattern continues, we call this "roster notation".

How can we represent such a set in SymPy? There is no direct way, which is perhaps obvious because a computer is finite and the set is infinite.

But SymPy does have a representation of all natural numbers. This is the set $$\{1,2,3,\dots\}$$, and its representation in SymPy is named.

Moreover, SymPy can form a set from another set, by means of a function. This is called an "ImageSet".

In the code below, starting from the set $$\Bbb N = \{1,2,3,\dots\}$$ we transform it into $$\{2,4,6,\dots\}$$ by applying the function $$f(x)=2x$$. To represent this function, we write, which says that each   is mapped to.

Build the set of all "square numbers" in SymPy. This is the set
 * $$\{1,4,9,\dots\}$$

Then check that 0 is not in the set, but 100 is.

Set Builder Notation
But some patterns are so complex, that it is not reasonable to simply list the elements and hope that the reader picks up the pattern. Consider, for example, the set
 * $$\{1, -4, 9, \dots\}$$

Or perhaps more challenging,
 * $$\{-1, 5, -7, \dots\}$$

The first sequence of the two above, is the alternating sequence of squares. They can be constructed by computing $$(-1)^x x^2$$ for $$x=1,2,3,\dots$$

The second sequence is $$(-1)^x x^2 + x - 1$$ for $$x=1,2,3,\dots$$

Instead of indicating a pattern, we can simply say the property which defines the set. This is called "set builder notation", demonstrated below.
 * $$\{1,4,9,\dots\} = \{x^2 : x\text{ is a natural number}\}$$

and
 * $$\{-1,5,-7,\dots\} = \{(-1)^xx^2+x-1 : x\text{ is a natural number}\}$$

Set builder notation has the general form
 * $$\{\langle \text{expression for elements}\rangle : \langle \text{property of the elements}\rangle\}$$

Just to give a taste of sets which do not contain numbers, we could also define the set of all polynomials with degree equal to 2, and with coefficients equal to 1 or 2.

This is a finite set and therefore it is possible to write it in roster notation.
 * $$\begin{aligned}

\{x^2+x+1, &\quad x^2+x+2, \\ x^2+2x+1, &\quad x^2+2x+2, \\ 2x^2+x+1, &\quad 2x^2+x+2, \\ 2x^2+2x+1, &\quad 2x^2+2x+2\} \end{aligned}$$

But it is more efficient and attractive to write it in set builder notation.
 * $$\{ax^2+bx+c : a,b,c\in\{1,2\}\}$$

In order to produce this set in SymPy we need several parameters, one for a, one for b, one for c. As of writing this, SymPy does not have a convenient way of doing so, but later on we will see a way to use other SymPy features which can allow us to construct this set.

However, we are currently able to display each element of the set with the following script.

The Empty Set
We allow a set to contain no elements.

This is not to say that $$\emptyset$$ "is nothing". After all, it is a set! So it is something. It's just that it contains nothing.

There is a parallel to objects in Python. For example, one may have an empty list. But it is still a list, and has list properties!

If an empty list were truly "nothing" then  should cause an error because you are giving nothing to the   function. However, this gives no error.

Therefore the empty list truly is a list, it just has no elements.

By analogy, the empty set is a set with no elements.

Note that, in a trivial sort of way, $$\emptyset$$ is a subset of every set. That is to say, if X is any set, then we always have
 * $$\emptyset\subseteq X$$.

This can be a little counter-intuitive. You may just want to accept this without too much fuss, if you are trying to make quick progress through the course.

If you prefer to spend a little more time thinking about why this is true, it may be helpful to think of it this way:

Is $$\{1,6,7\}\subseteq \{1,2,3,4\}$$? No.

Is $$\{1,6\}\subseteq \{1,2,3,4\}$$? No.

Is $$\{1\}\subseteq \{1,2,3,4\}$$? Yes!

In general, when you eliminate elements from the left set, you only make it "easier" for the set on the left to be a subset of the one on the right.

You are removing objects which now must be in the right set, in order for the subset relation to hold.

Each time you remove an element, you are in a sense removing a "condition" for being a subset.

Well what happens when you remove all the elements? You have then removed all of the conditions! So $$\emptyset$$ becomes a subset unconditionally.

Confirm that SymPy agrees that $$\emptyset$$ is a subset of every set.

Do so by running the following code, after you have replaced the string. You should replace it with any set you choose to construct. (Note: It is common in programming to place a comment or string containing "TODO" to indicate that a portion of the code has yet to be completed.)

When you have replaced "TODO" with any set, and run the code, it should print, reflecting the fact that   is a subset of whatever you put in.

Natural Numbers
There are a few sets of numbers that we will end up using again and again throughout this course. Therefore it is convenient to give them names and symbols for easy reference.

We have already seen the set of natural numbers, $$\{1,2,3,\dots\}$$.

We have already seen that, in SymPy, this is represented by.

Some mathematicians actually define the natural numbers to include zero. The choice is arbitrary, so there is no right way to define the natural numbers. Including zero is just better for some applications and not for other applications.

SymPy also supports the natural numbers with zero, and it is represented by.

Check that  is in.

In order to follow suit we will use the symbol $$\Bbb N^{\ge 0}$$ to represent the naturals numbers including zero.

Show that the numbers 1234 and
 * $$1\cdot 10^3+2\cdot 10^2 + 3\cdot 10^1+4\cdot 10^0$$

are equal.

If n is any nonnegative natural number, how many numbers are in $$[n]$$?

If moreover m is any natural number and $$n \le m$$, how many numbers are in $$[m]$$ but not $$[n]$$?

The way that we standardly write natural numbers is just to write the digits of its expansion.

For example, consider 1234. The digit expansion is $$1\cdot 10^3+2\cdot 10^2+3\cdot 10^1+4\cdot 10^0$$, which has digits 1, 2, 3, 4.

So in effect, we are all used to use the digit expansion in everyday life. Expressing it the way we have, is just a new expression of exactly what we are doing when we write a number this way.

Write the number 5010 in its digit expansion.

When aligning the formal definition above with this particular example, what is the value of m?

We can also define digit expansions in other bases, and we will do so later. For now, we focus only on base 10.

Integers
The integers can be thought of as the "non-negative natural numbers and their negatives".

In SymPy they are represented by.

The sets
 * $$\{x^2:x\in \Bbb N\}$$

and
 * $$\{x^2:x\in \Bbb Z\}$$

are different by only one element. Which one?

Rationals
The rational numbers are the numbers which are a ratio (or "fraction") of two integers. They are denoted by the symbol $$\Bbb Q$$.

We cannot list all rational numbers in a simple linear pattern, but we can at least exhibit a few examples.
 * $$\begin{aligned}

\frac 1 2, \frac{-5}{3}, \frac{20}{-20}\in\Bbb Q \end{aligned}$$

Of course because it is undefined to divide by zero, we cannot allow the denominator to be zero.

This is represented in SymPy as.

Note that  would cause an error if you run this code. is a float and therefore not of the appropriate type, and one should instead check whether.

Predict the result of the code

Suppose that r is a rational number. Show that $$r+1$$ is also a rational number.

Hint: First, write r as a ratio of integers.

Second, write 1 as a ratio of integers, with the same denominator as r.

Third, add these rational numbers.

Fourth, argue that the result satisfies the formal definition of a rational number.

In a style that resembles the previous exercise, show that if r and s are two rational numbers, then all of the following are also rational numbers.


 * $$-r$$
 * $$r+s$$
 * $$rs$$
 * $$r/s$$

Give an example of rational numbers r and s such that $$r^s$$ is not a rational number. Hint: Recall that the "square-root is the same as a 1/2 power".

Note that the representation of a rational number by a ratio of integers is not unique.

For example $$\frac 1 2 = \frac 2 4$$. Therefore $$\frac 1 2$$ and $$\frac 2 4$$ are each different representations of the same number.

Show that $$\frac 2 4$$ is not in simplest form but that $$\frac 1 2$$ is.

Show that every rational number has a simplest form, by completing the following argument.

1. Let $$\frac p q \in \Bbb Q$$ be any rational number, with $$p,q\in\Bbb Z$$.

2. If p and q have no common factors then there is nothing to prove. (Why? Fill this in.)  Therefore assume that p and q do have a common factor, call it d.

3. Therefore there exist integers $$x,y\in\Bbb Z$$ such that $$p = dx$$ and $$q=dy$$. (Why?)

4. Therefore $$\frac p q = \frac{dx}{dy}$$.

From here, complete the rest of the argument by canceling the common factor.

Draw the conclusion that, if p and q have a common factor, then there is an equivalent expression of the same number, which does not have that factor in either the numerator or denominator.

Therefore, if one applies this result to every common factor, one may arrive at an expression with no common factors. Argue that this expression is equivalent to the original, and therefore any rational number has an equivalent expression with no common factors. (Hint: Use the fact that if expression e is equivalent to expression f, and if f is equivalent to expression g, then it follows that e is equivalent to g.)

Decimal Expansion Instincts
It is natural to try to think of rational numbers by their digits. And at least initially, this may seem very simple. For example, 1/2 is the same as 0.5. What could be the problem with that?

But even rational numbers with very small coordinates, like 1/3, require a so-to-speak "infinite decimal expansion", 0.333...

This too may initially seem un-problematic, but suppose that we compute


 * 0.333... + 0.333... + 0.333...

What should this sum be equal to? It seems appealing to say that it is


 * 0.999...

Just by adding the digits in each position. Because we did not require a "carry" in any digit, perhaps this worked? But how could we be sure?

Moreover, if we performed the same operation on the equivalent representation as ratios, we would get


 * 1/3 + 1/3 + 1/3 = 3/3 = 1

So does it follow that 0.999... = 1? Many people fine this idea quite hard to accept, and really the confusion comes from the lack of clarity about what exactly is going on with the "..." part of the infinite decimal expansion.

To take this notation really seriously, we would need to have some kind of consistent theory of handling infinite sequences of digits. We will develop precisely this later on, but for now we must simply use our intuitions.

Therefore, the the remainder of this lesson, let us reason with decimal numbers in instinctive ways, and just accept the possibility of adding digits in this way. Later we will prove rigorously that these instincts are valid.

Decimal Expansions
Show that the rational numbers $$\frac 1 2$$ and $$\frac 5{10}$$ and 0.5 are all equal.

Show that the numbers 123.456 and
 * $$1\cdot 10^2 + 2\cdot 10^3 + 3\cdot 10^0 + 4\cdot 10^{-1} + 5\cdot 10^{-2}+6\cdot 10^{-3}$$

are equal.

Show that both 0.3 and 0.33 are decimal truncations of 1/3, but 0.34 is not and 0.32 is not.

Also show that 1.4 is a decimal truncation of $$\sqrt 2$$ but 1.5 is not.

Repeating Decimals
The rational numbers can be thought of as all numbers with a "repeating decimal expansion".

For example 1/3 has decimal expansion 0.333... with repeating 3s. And 1/7 has decimal expansion 0.142857142857... which repeats the sequence "142857".

Not all patterns start to repeat right away. For example 1/12 has decimal expansion 0.083333..., in which "08" does not repeat but eventually the "3"s start to repeat.

What is the repeating pattern in the decimal expansion of 1/2?

Also, find another number which has a repeating decimal expansions, but the repeating sequence does not start in the first digit after the decimal place.

Also, notice that if we have the repeating decimal expansion then we can find its representation as a ratio of integers. For example, consider 0.142857142857...

If we multiply this by $$10^6$$ then this will shift the decimal place six times. Because the repeating pattern is six digits long, we get,
 * $$10^6 \cdot 0.142857142857 \ldots = 142857.142857142857\dots$$

Therefore if we subtract these two numbers, the decimal parts should cancel perfectly!
 * $$\begin{aligned}

142857&.142857\ldots \\ - \phantom{textte} 0&.142857\ldots \\\hline = 142857& \end{aligned}$$ For convenience let's write $$x = 0.142857\dots$$

The above therefore shows that
 * $$10^6x - x = 142857$$

Therefore, by solving for x, we find
 * $$x = \frac{142857}{10^6-1}$$

Use SymPy to simplify $$\frac{142857}{10^6-1}$$ as a rational number.

When you see the result, reflect on what this shows in the context of the topics above.

Finally, also, consider the decimal expansion 0.123123123... Find the representation of this number as a ratio of integers.

The above is almost a proof that every repeating decimal expansion is a rational number. Maybe not the most rigorous proof, but we will have to wait a few more chapters before we get extremely rigorous proofs.

Define X to be the set of all numbers with a decimal expansion which eventually has a repeating pattern.

The above demonstrates a subset relation between $$\Bbb Q$$ and X.

What is that relation?

But what about the other way around? Can we prove that every rational number has a repeating decimal expansion?

It turns out this, too, is true. However, the proof requires mathematical tools which are a bit beyond the scope of this course. We will simply take it for granted that the "other" direction of inclusion is true as well, $$\Bbb Q\subseteq X$$.

That is to say, the rational numbers are exactly the same as the set X in the exercise above.


 * $$\Bbb Q = X$$

Consider the number
 * 0.01001000100001...

Its digits are generated by increasing the number of "0"s in-between each next consecutive pair of "1"s.

Show that this number is not rational.

Reals
The real numbers are the set of all decimal expansions.

For instance, $$\sqrt{2} = 1.4142...$$ and $$\pi=3.14159...$$ are two real numbers. But their decimal expansions never encounter a repeating pattern.

We will prove this for $$\sqrt 2$$ immediately. The proof for $$\pi$$ is more trouble than it's worth for our current purposes, so we will not see it.

As before, we do not make definitions official here, and use infinite decimal expansions in an intuitive way.

√2 Is Irrational
In discussing the real numbers, we are implicitly suggesting that some real numbers are not rational. These are called the "irrational" numbers.

It is somewhat common knowledge that $$\sqrt 2$$ is irrational. Let's provide a proof of this fact.

(The numbering system used in the proof will be explained later.)

$$\sqrt 2$$ is irrational.

In order to prove that $$\sqrt 2$$ is irrational, we will use a "proof by contradiction". In this style of proof, we start by assuming "the opposite", and show that this leads to a contradiction.

In this case we start by assuming that $$\sqrt 2$$ is rational and show that this leads to a contradiction.

Because assuming "$$\sqrt 2$$ is rational" leads to a contradiction, then $$\sqrt 2$$ cannot possibly be rational.

(1.) The assumption that $$\sqrt 2$$ is rational, leads to a contradiction.

(1.1.) Assume $$\sqrt 2$$ is rational.

(1.2.) Therefore there are integers p and q such that $$\sqrt 2 = p/q$$, with $$q\ne 0$$.

(1.3.) We can assume that p and q are in simplest form.

(1.4.) Therefore
 * $$(\sqrt 2)^2 = (p/q)^2 $$

so
 * $$2 = p^2/q^2$$

so
 * $$2q^2 = p^2$$

(1.5.) So 2 divides $$2q^2$$.

(1.6.) So 2 divides $$p^2$$.

(1.7.) So 2 divides p.

(1.8.) So 4 divides $$p^2$$.

(1.9.) So 4 divides $$2q^2$$.

(1.10.) So 2 divides $$q^2$$.

(1.11.) So 2 divides q.

(1.12.) Therefore 2 is a common factor of p and q.

(1.13.) Therefore a contradiction follows: p and q have no common factor, and also have 2 as a common factor.

(2.) So $$\sqrt 2$$ is not rational.

Although this proof is rigorous, it is not always clear exactly how a given line may follow from certain lines above it. Therefore we should also pair a proof with an audit, as below.

An audit essentially restates all of the lines of a proof, but gives explicit explanations of exactly how each line follows from previous lines. It does so by referencing line numbers, and explicit rules of inference applied to those line numbers.

I have also included a "Toward" column for each line number in the audit. This is not strictly necessary, but it gives a helpful note about "why" we are writing each line. It states the goal, toward which each step is being taken.

When you write your own audits in the exercises, note that the "From" column is strictly necessary. It provides the formal verification that your argument is correct. The "Toward" column can be left blank if you like, but it will help you to think about whatever helpful notes you can put there.

Prime Numbers
The above proof relied on a fact about prime numbers, the prime divisor property.

Therefore we should take a minute to recall what prime numbers are.

Intuitively the prime natural numbers are the natural numbers which do not factor in any interesting way.

For instance, 4 factors into $$2\cdot 2$$, with both factors not equal to 4. We would regard this as an "interesting" factorization of 4. So 4 is not prime.

But the only way to factor 2 is in some uninteresting way like $$2\cdot 1$$ or $$1\cdot 2$$. This makes 2 prime.

Show that an integer $$p\in\Bbb Z$$ is prime if and only if the following two conditions hold.


 * $$2\le |p|$$
 * The only divisors of $$|p|$$ are trivial.

The first three positive primes are 2, 3, and 5.

Find the first 10 positive primes.

Consider the prime 7 and the following numbers which it divides.


 * 7, 14, 98

Consider the fact that 7 can be written as the following products.


 * $$7\cdot 1, \quad 1\cdot 7$$

Notice that in every case, 7 divides one of these factors.

Likewise 14 can be written as the following products.


 * $$14\cdot 1,\quad 7\cdot 2,\quad 2\cdot 7,\quad 1\cdot 14$$

Again, in every case, 7 divides one of these factors. (Here, respectively, the factors which 7 divides are 14, 7, 7, 14.)

Likewise write every way of factoring 98, and observe that in every factorization, 7 divides at least one of the factors. Does it sometimes divide both factors?

Prove that $$\sqrt 3$$ is irrational.

Also prove that $$\sqrt 6$$ is irrational.

The prime divisor property is the following theorem. We will not prove it until several sections from now, since the proof requires more advanced mathematics than we're currently able to discuss. Let p be any prime number which divides a product of two integers, ab. Then either p divides a, or p divides b.

Use the prime divisor property to prove that, if a prime number p divides the product $$q\cdot q$$, then it follows that p divides q.

SymPy Reals
One can list several of the elements of a set, so let's see what it looks like if we do this with the set of rationals.

You could try to guess what this displays before running it, but really, there is no one right way to list the rational numbers. (By contrast there is a natural ordering for the natural numbers.)

If you get tired of writing lines of code to do something repetitive, like listing each next rational number, that's a great reason to put it in a loop!

Try this cell next:

Note that the code  is (for our purposes) equivalent to writing. We don't really use the index  in this example, but it still has to be there. We really just want to make something happen ten times, which is the only point of the for-loop.

Ok, but what about the real numbers?

If you try to run  you will see the error message,

TypeError: 'Reals' object is not iterable

On a technical level, all this really means is that the SymPy developers never bothered to give  an implementation of the   function. They effectively did not try to iterate the real numbers.

But why?

It turns out that, in a very important sense, it is impossible to iterate all of the real numbers.

But we iterated the rational numbers, right? Why can't we do it now for the reals?

We will study precisely this later. But for now it is at least interesting and provocative, to think that in some sense this is an important "line" to draw between the rational numbers and real numbers: The former can be "enumerated" while the latter cannot.

Complex
We discussed the so-called "imaginary" number $$i=\sqrt{-1}$$ in the introductory lesson, where we wondered whether this makes any sense at all.

We'll get around to that question eventually. I guess there is no way to truly maintain the mystery. Of course we will see that this does make sense and is in fact both meaningful and important. Mathematicians do not regard this number as truly "imaginary", or at least, no more imaginary than any other number.

But for now let's simply focus on the intuitions involved. As with several of the earlier topics, we will not introduce official definitions since we are not yet ready for that.

We define the complex numbers as the set of all numbers of the form $$a+bi$$ where $$a,b\in\Bbb R$$. We denote the set of complex numbers as $$\Bbb C$$.

Here are a few examples of elements of $$\Bbb C$$, with their associated values of a and b.

For any complex number $$a+bi$$ we call a its "real part" and b its "imaginary part".

Note that the real part and the imaginary part are each real numbers.

The Algebra
We sum, multiply, and divide, just as we do with any other kinds of numbers, all while treating i as "just some number".

For examples,


 * $$(2-3i) + (-5+i) = -3-2i$$

and
 * $$(1+i)(-2+3i) = -2+3i-2i+3i^2$$

The only time we see anything different happen, is when we encounter some power of i, like $$i^2$$. This is because we already know that $$i^2=-1$$ and therefore we should write


 * $$(1+i)(-2+3i) = -2+3i-2i+ 3(-1) = -5+i$$

Find $$i^3, i^4, i^5, i^6, i^7, i^8$$, each simplified into an expression which has no exponent of i which is more than 1.

Generalize what you find in the above exercise, so that you can compute $$i^{20},i^{21}, i^{103}$$ with very little computation.

Even more generally, compute any $$i^n$$ for any nonnegative natural number n. That is to say, give a very simple procedure to simplify $$i^n$$.

What is $$i^{-1}$$, or equivalently, what is $$\frac 1 i$$? Can it be written in the standard form of $$a+bi$$?

The fundamental definition of $$\frac 1 i$$ (i.e. of any reciprocal, but in this particular case, the reciprocal of i), is that:


 * $$\frac 1 i$$ is some number which, when multiplied by i, will result in 1.

That is to say, the defining feature of this number is given by the equation


 * $$\frac 1 i \cdot i = 1$$

Use the fact that $$i\cdot i = -1$$ to argue that


 * $$ \frac 1 i = -i$$

Then use the fact that $$i^{-2}=\frac{1}{i^2}$$ and similar identities, to compute each of


 * $$i^{-2}, i^{-3}, i^{-4}$$

Confirm that SymPy agrees with your results above by running

Note that  is the SymPy representation for the imaginary number i.

String Sets
Especially in computer science, we are interested in strings and sets of strings.

For our mathematical purposes, a string is any sequence of characters. (In Python, strings are a little more than just sequences of characters, but we don't need to get too distracted by these nuances.)

For example "a bb ccc" is a string, with character set {'a','b','c', ' '}. Note that in this example, a white space is a part of the character set.

"123" is a string, with character set {'1','2','3'}.

Note that we may take the character set to be anything we choose. These are just the symbols that we permit as valid symbols to form a string.

We usually denote a string with double-quote marks and characters with single quote-marks.

Identify the character set for the string "$$\forall x P(x)$$". Hint: Don't forget the parens!

Consider the character set {'0','1'}. List all strings with this character set, which have length 2.

Hint: There should be 4 in total.

Consider the character set {'0','1','2'}. How many strings with this character set have length 5?

Hint: The number of strings of length 1 is 3, clearly. The number of strings of length 2 is 9. They are

"00", "01", "02",

"10", "11", "12",

"20", "21", "22"

The number of strings of length 3 is 27. You can see this by considering strings of length 3 which begin with 0 (there are 9 of these), and strings of length 3 which begin with 1 (there are 9 of these), and strings of length 3 which begin with 2 (there are 9 of these).