1The language of mathematics and prompting

1.1 The art of prompting

As of August 2024, there is a multitude of chatbots available on the internet. Some of them, like ChatGPT, Claude and Gemini (and Llama 3.1, Mistral, ... the list goes on)
have quite impressive reasoning capabilities. These models are now multimodal i.e., they even accept non-textual input, such as images, sound and video. In principle you can upload a picture of a math exercise and the chatbot will provide a solution. Well, that is, on a good day and for a not too difficult exercise.
The use of chatbots is encouraged throughout this course. In fact, they are even allowed during the exam. It is my hope that you will learn mathematics on a deeper level by communicating with the machine using carefully designed prompts - see the OpenAI guide on prompt engineering.
In some places in the notes, you may see quite specific prompts, such as
💬

Always answer in the context described below.
Context: I am taking a first semester college level course in introductory mathematics and optimization. Emphasis is on precision and small proofs in mathematics. Please give some conrete examples with mathematics involved. 

- Tell me what a good and precise prompt is.
- Show me two examples of good prompts.
- What is a good prompt if I want to know about code written in Sage or python?
- What is a good prompt if I want to know how to enter some specific mathematics in LaTeX?

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
A click on a chatbot link copies the prompt to the clipboard and takes you to the chatbot, where you can paste the prompt and get feedback.
The prompt may also be hidden in a button as below.
LLM
💬

Please solve the equation $x^2 - x - 1 = 0$. Guide me through the steps. Make sure that the underlying logic in your arguments is correct.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
There is a lot of wisdom baked into those weights! In this first chapter I will show a lot of prompts. In the following chapters less so. Here you are expected to prompt the chatbots on your own.
Be careful! Prompting without any knowledge of the mathematics can be disastrous. I have seen exams written by generative AI spanning many pages with little or no relevant mathematical content. This is known as GIGO or garbage in garbage out. Good prompting comes from an understanding of the mathematics and often resembles concise and beautifully written instructions.
Study the OpenAI guide on prompt engineering.
Then come up with prompts that make a chatbot act like a mathematics tutor for you. Here is a small example that you may extend.
💬

Please act like a friendly tutor and teach me about the derivatives of simple functions. Test my understanding after each concept you explain.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Start your LaTeX\LaTeX journey using the prompt below.
💬

I am doing weekly exercises in mathematics at the college level. Please suggest a very simple template in
LaTeX for hand in of these exercises. Also, show me how to typeset an equation in LaTeX.

There seems to be a web interface to LaTeX called Overleaf. Please tell me how to access this so that I can
enter a weekly exercise.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Come up with your own prompt for a question related to software.
Below I ask for feedback from the chatbot on some dubious chunk of mathematics.
💬

Please give feedback on the mathematics contained in the $\LaTeX$ below in triple quotes. Emphasize logic and precision.
"""
$$
x^2 = 1 \implies x = 1
$$
From this it follows that $1 + 1 = 3$.
"""

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Insert your own mathematics in LaTeX\LaTeX notation and ask for feedback in a prompt.

1.2 Black box warnings

Modern mathematics is perhaps not like anything you have encountered so far. It calls for a lot of focus and precision, especially when writing down solutions to problems. It is a bit like programming a computer. There is no room for imprecision and half-baked sentences.
This course amounts to 1010 ECTS or approximately 280280 hours. Suppose that you spend a week studying for the exam, say 4040 hours. Lectures, exercise classes, and MatLab amount to 14(4+2+3)14\cdot (4 + 2 + 3) hours =126= 126 hours. This leaves around 114114 hours for your own study and immersion. Put in other terms, you are supposed to work around 88 hours per week outside classes for this course. With classes, each week calls for 1717 hours of work. There is a very close relationship between the amount of hours you log each week and your result at the exam. To state the obvious: numbers don't lie. If you put in the time, you will almost certainly do well. Try to allocate time for IMO in your weekly schedule and please (ab)use all the help that is provided.
💬

I am taking a first semester college level mathematics course spanning 14 weeks and 10 ECTS. One ECTS
amounts to 28 hours. The teaching activities every week amount to 4 hours of lectures,
2 hours of exercise sessions and 3 hours of study cafe. I expect that final exam will take 40 hours
of the 10 ECTS. Please schedule a weekly study plan for me along with a plan for the final exam.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |

1.3 Computer algebra (and python)

Computers are exceptionally fun, but be careful! Nothing really beats a clear thinking human mind. To wit, I asked WolframAlpha to solve a certain optimization problem and it came up with the answer
Prompt a chatbot with
💬

What is 
$$
-\sqrt{\frac{1}{2} (1 - \sqrt{2} + \sqrt{3 - 2\sqrt{2}})}
$$

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
and explain why the output from WolframAlpha is weird. Use prompting to make it explain the mathematics input notation.
Finally use your own mental powers (and feedback from the chatbot) to explain what the proper output should have been.
322=(21)2. 3 - 2 \sqrt{2} = (\sqrt{2} - 1)^2.
We will use the computer algebra system Sage in exploring and experimenting with mathematics. This means that you will have to write small commands and code snippets.
Sage is built on top of the very wide spread language python and you can in fact enter Python code One may also enter code in several other languages in the Sage input windows in the interactive notes. First adjust the prompt below according to your needs and get feedback from an LLM.
💬

I am taking a mathematics course that uses the computer algebra system Sage.
The course uses the browser, where I can enter and run small snippets of code in Sage and python.
I have no/some/extensive prior programming experience.
Give me a brief introduction to Sage and explain how it relates to python.
Finish your reply with a small exercise I can do. 
If no/some/extensive is present above in this prompt, remark this and only reply with
Please select your programming experience.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Below is an example of a basic graphics command in Sage. Push the Compute button to evaluate.
You can install Sage on your own computer following the instructions on https://www.sagemath.org/.
Did you notice that you can edit and enter new commands in the Sage window? Do the following problems using Sage based on the Sage guided tour.
  1. Consider f(x)=xsin(1/x)f(x) = x \sin(1/x). Plot the graph of ff from 00 to 0.10.1. Computing f(0)f(0) does not make sense. Do you see a way of assigning a natural value to f(0)f(0) using the graph?
  2. Find an approximate solution with four decimals to the equation cos(x)=x\cos(x) = x.
    This is an example of an equation, that can only be solved numerically. Try first plotting the graph of f(x)=xcos(x)f(x) = x - \cos(x) from 00 to 11. Then use a suitable function from the Sage guide.
  3. Compute π\pi with 100100 decimals.
LLM
💬

Give me the sage code to compute pi with 100 decimals. I want a one line command.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Compute the sum
11+2+12+3+13+4. \frac{1}{\sqrt{1} + \sqrt{2}} + \frac{1}{\sqrt{2} + \sqrt{3}} + \frac{1}{\sqrt{3} + \sqrt{4}}.
What is the elegant answer? Explain!
Bonus question
Generalize your answer/method to computing the sum
11+2+12+3+13+4++1N1+N, \frac{1}{\sqrt{1} + \sqrt{2}} + \frac{1}{\sqrt{2} + \sqrt{3}} + \frac{1}{\sqrt{3} + \sqrt{4}} + \cdots + \frac{1}{\sqrt{N-1} + \sqrt{N}},
for N=5,6,7,N = 5, 6, 7, \dots.
We need a precise setup for communicating mathematics. This involves the introduction of propositional logic, predicates and sets. Let me emphasize, that this is an introductory course and not a rigorous introduction to mathematics. As such it is an organic approach, where I hope that you will return and fill out the gaps instead of getting overwhelmed by formal details already from the beginning.
However, the underlying goal is to show that mathematical precision and proofs are similar to constructing correct computer programs. In fact, this whole first chapter may be viewed as the beginning of a computer program, where we state the exact definitions for use in the following chapters. We begin by introducing sets and numbers.

1.4 Numbers

A set is a collection of (mathematical) objects or elements. When defining a set we use the symbols {\{ and }\} to denote the beginning and end of its definition. For example, {N, i, e, l, s}\{\text{N, i, e, l, s}\} is the set of characters in my first name and {8,0}\{8, 0\} are the digits in the postal code for Aarhus C. The ordering in the listing of the elements is unimportant so that
{N, i, e, l, s}={l, e, i, s, N}{8,0}={0,8}\begin{aligned} \{\text{N, i, e, l, s}\} &= \{\text{l, e, i, s, N}\}\\ \{8, 0\} &= \{0, 8\} \end{aligned}
are identical sets. If SS is a set, we will use the notation xSx\in S to denote that xx is an element in SS. For example, e{N, i, e, l, s}\in \{\text{N, i, e, l, s}\}.
Later, we will introduce much more detail about sets. For now, we just need the basic notation for defining them.
Our fundamental mathematical objects in this course are numbers and we introduce them right away.

1.4.1 The natural numbers N\mathbb{N} and the integers Z\mathbb{Z}

The set of natural numbers is
N={1,2,3,}.(1.1) \mathbb{N} = \{1, 2, 3, \dots\}. \tag{1.1}
The set of integers is
Z={,3,2,1,0,1,2,3,}.(1.2) \mathbb{Z} = \{\dots, -3, -2, -1, 0, 1, 2, 3, \dots\}. \tag{1.2}
These are infinite sets, since they contain infinitely many elements as indicated by the dots \dots
It makes sense to add and multiply two integers aa and bb. We will denote their addition or sum as a+ba + b and their multiplication or product as aba b. A fundamental fact is that addition and multiplication are commutative i.e., a+b=b+aa + b = b + a and ab=baa b = b a.
Please notice right away that expressions like a+b+ca + b + c and abca b c are complete nonsense for three integers a,ba, b and cc. We only know how to add and multiply two integers, not three. A wonderful fact comes to our rescue:
(a+b)+c=a+(b+c)(ab)c=a(bc).(1.3)\begin{aligned} (a + b) + c &= a + (b + c)\\ (a b) c &= a ( b c). \end{aligned}\tag{1.3}
You get the same result no matter if you start adding (multiplying) aa and bb or bb and cc and then adding (multiplying) cc or aa. So we may write a+b+ca + b + c and abca b c as a placeholder for one of the two ways of computing this expression in (1.3)
(a+b)+c=a+(b+c)(ab)c=a(bc).(1.3)\begin{aligned} (a + b) + c &= a + (b + c)\\ (a b) c &= a ( b c). \end{aligned}\tag{1.3}
.
As you can see we use the symbol ++ for addition, but no symbol for multiplication. This is the convention in (clean) mathematics as opposed to the aba * b coming from computer algebra (except perhaps in Mathematica or Wolfram language, where space is allowed for multiplication). However, when one of the factors is an actual number, we will use \cdot, so that for example 77 times 99 is written as 797\cdot 9 and aa times 33 is written a3a\cdot 3.

1.4.2 The rational numbers Q\mathbb{Q}

The natural numbers N\mathbb{N} and the integers Z\mathbb{Z} are well defined by their representations in (1.1)
N={1,2,3,}.(1.1) \mathbb{N} = \{1, 2, 3, \dots\}. \tag{1.1}
and (1.2)
Z={,3,2,1,0,1,2,3,}.(1.2) \mathbb{Z} = \{\dots, -3, -2, -1, 0, 1, 2, 3, \dots\}. \tag{1.2}
.
A rational number a/bQa/b\in \mathbb{Q} consists of a numerator aZa\in \mathbb{Z} and a denominator bNb\in \mathbb{N}.
If a,cZa, c\in \mathbb{Z} and b,dNb, d\in \mathbb{N}. Then a/ba/b and c/dc/d are considered equal i.e.,
ab=cd \frac{a}{b} = \frac{c}{d}
if and only if ad=bca d = b c.
So there are many different ways of representing a rational number, such as
37=614=921. \frac{3}{7} = \frac{6}{14} = \frac{9}{21}.
Here
37=921since321=79. \frac{3}{7} = \frac{9}{21}\qquad\text{since}\qquad 3\cdot 21 = 7\cdot 9.
In fact, a fraction stays the same when its numerator and denominator are multiplied by the same natural number.
I will assume that you know how to add and multiply fractions, and that you do not make mistakes like
12+23=1+22+3=35. \color{red} \frac{1}{2} + \frac{2}{3} = \frac{1+2}{2+3}=\frac{3}{5}.
In fact, if you temporarily forgot how to add fractions, you can use the wisdom in Definition 1.7
A rational number a/bQa/b\in \mathbb{Q} consists of a numerator aZa\in \mathbb{Z} and a denominator bNb\in \mathbb{N}.
If a,cZa, c\in \mathbb{Z} and b,dNb, d\in \mathbb{N}. Then a/ba/b and c/dc/d are considered equal i.e.,
ab=cd \frac{a}{b} = \frac{c}{d}
if and only if ad=bca d = b c.
. You can replace 12\frac{1}{2} by 36\frac{3}{6} and 23\frac{2}{3} by 46\frac{4}{6} and then add the numerators as in
12+23=36+46=3+46=76. \frac{1}{2} + \frac{2}{3} = \frac{3}{6} + \frac{4}{6} = \frac{3 + 4}{6} = \frac{7}{6}.
The computation above says that it is straightforward to add pizza slices of the same size (one sixth), but that you need to think a bit when adding one half pizza slice and two pizza slices of size one third. In general,
ab+cd=ad+bcbdandabcd=acbd. \frac{a}{b} + \frac{c}{d} = \frac{a d + b c}{b d} \qquad\text{and}\qquad \frac{a}{b} \frac{c}{d} = \frac{a c}{b d}.
Click on the right equalities below. Do not use Sage (or any computer)!
15+17=135 \frac{1}{5} + \frac{1}{7} = \frac{1}{35}
37+47=1 \frac{3}{7} + \frac{4}{7} = 1
23+322=16 \frac{2}{3} + \frac{3}{2} - 2 = \frac{1}{6}
13+2=83. \frac{1}{3} + 2 = \frac{8}{3}.

1.4.3 The real numbers R\mathbb{R}

A real number is defined by
d0.d1d2,(1.4) d_0.d_1 d_2 \dots, \tag{1.4}
where d0Zd_0\in \mathbb{Z} and d1,d2,d_1, d_2, \dots is an infinite sequence of integers (digits) in {0,1,2,3,4,5,6,7,8,9}\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9\}.
Informally (1.4)
d0.d1d2,(1.4) d_0.d_1 d_2 \dots, \tag{1.4}
represents the real number
d0+d110+d2100+=d0+d1101+d2102+ d_0 + \frac{d_1}{10} + \frac{d_2}{100} + \cdots = d_0 + d_1 \cdot 10^{-1} + d_2 \cdot 10^{-2} + \cdots
given by an infinite set of digits as opposed to a rational number, which is given finitely by an integer (numerator) and a natural number (denominator). The format in (1.4)
d0.d1d2,(1.4) d_0.d_1 d_2 \dots, \tag{1.4}
is the usual (floating point) output from your pocket calculator or computer algebra system. For example,
13=0.33337=0.42857142857314=0.21428571428571428571227=3.14285714285714285714285714355113=3.14159292035398230088495575π=3.14159265358979323846264338\begin{aligned} \frac{1}{3} &= 0.333\dots\\ \frac{3}{7} &= 0.42857142857\dots\\ \frac{3}{14} &= 0.21428571428571428571\dots\\ \frac{22}{7} &= 3.14285714285714285714285714\dots\\ \frac{355}{113} &= 3.14159292035398230088495575\dots\\ \pi &= 3.14159265358979323846264338\dots \end{aligned}
The decimal expansion of 355/113355/113 above looks chaotic, but it eventually repeats itself after 112112 digits. In fact the decimal expansion of every rational number is periodic i.e., it repeats itself from a certain point.
In the definition (1.4)
d0.d1d2,(1.4) d_0.d_1 d_2 \dots, \tag{1.4}
of a real number, we are forced to make identifications as in the definition of a rational number. I will not go into details here, but just notice that the identification
0.99999=1.000 0.99999\dots = 1.000\dots
is forced upon us: if
x=9101+9102+. x = 9\cdot 10^{-1} + 9\cdot 10^{-2} + \cdots.
Then
10x=9+9101+9102+=9+x. 10 x = 9 + 9\cdot 10^{-1} + 9\cdot 10^{-2} + \cdots = 9 + x.
Therefore we must have x=1x = 1.
A real number that is not rational is called irrational. There are many more irrational numbers than rational ones. Famous ones are 2,π\sqrt{2}, \pi and ee. The irrational number 2\sqrt{2} is a root in the polynomial x22x^2-2 with integer coefficients (it is an algebraic number). The numbers ee and π\pi are not even algebraic (they are transcendental).
Explore using prompting the history of numbers in mathematics. Also make a chatbot explain why a rational number must have a periodic decimal expansion.

1.4.4 Arithmetic rules for numbers

Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
Argue precisely that (xy)=yx-(x-y) = y-x for x,yAx, y\in A using Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
.
The long list of arithmetic rules above may seem complicated at first, but they are just a formal version of what you already know, such as for example, π+0=π\pi + 0 = \pi, 2+y=02 + y = 0 if y=2y = -2 and 3z=13 z = 1 for z=13=31z = \frac{1}{3} = 3^{-1}. Beware however, that the precision in Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
is necessary when programming a computer.
The rules (ⅳ) and (ⅴ) are called the associative laws for addition and multiplication respectively. The rule (ⅵ) is called the distributive law. It connects multiplication with addition.
We know that zero times any number is zero. Deduce this from the rules in Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
starting with 0+0=00 + 0 = 0.
Verify that (ⅵ) is true for some specific non-zero numbers. Also convince yourself that WolframAlpha actually accepts space (between numbers and variables) as multiplication.
Suppose that x,y,zQx, y, z\in \mathbb{Q} and w=xy+xzw = x y + x z. It seems that computing ww involves two multiplications and one addition. Multiplications are expensive operations on a computer. Is there a way of computing ww with only one multiplication and one addition?
Suppose that nNn\in \mathbb{N}. Use the distributive law to show that
n2+n=n(n+1). n^2 + n = n(n+1).
We now move on to the (formal) language involved in reasoning about mathematics in general.

1.5 Propositional logic

A proposition is a (mathematical) statement that is true (tt) or false (ff). This could be a boolean expression in a computer program, like 1<21 < 2.
Sage
Later we will see propositions with variables in them like x<2x < 2. These are called predicates.
Propositions can be combined into new (compound) propositions. Take for example the propositions
p:it rainsq:it is cloudy.\begin{aligned} &p: \text{it rains}\\ &q: \text{it is cloudy}. \end{aligned}
Then (pp and qq) is a perfectly good new proposition reading it rains and it is cloudy. The same goes for (if pp then qq), which reads if it rains then it is cloudy. The proposition (if qq then pp) reads if it is cloudy then it rains. This proposition is (clearly) false.
We need some notation to describe these compound propositions:
pqp and qpqp or qp    qif p then q¬pnot p \begin{array}{ll} p \land q\qquad\qquad & \qquad\qquad p \text{ and } q\\ \\ p \lor q\qquad\qquad & \qquad\qquad p \text{ or } q\\ \\ p\implies q\qquad\qquad & \qquad\qquad \text{if } p \text{ then } q\\ \\ \neg p\qquad\qquad & \qquad\qquad \text{not } p \end{array}
The compound propositions are either true(tt) or false (ff) depending on pp and qq. The dependencies are displayed in the truth tables below.
pqpqttttffftffffpqpqttttftfttfffpqp    qttttfffttfftp¬ptfft \def\arraystretch{1.2} \begin{array}{c|c|c} p & q & p\land q \\ \hline t & t & t \\ t & f & f\\ f & t & f\\ f & f & f \end{array}\qquad \begin{array}{c|c|c} p & q & p\lor q \\ \hline t & t & t \\ t & f & t\\ f & t & t\\ f & f & f \end{array} \qquad \begin{array}{c|c|c} p & q & p\implies q \\ \hline t & t & t \\ t & f & f\\ f & t & t\\ f & f & t \end{array}\qquad \begin{array}{c|c} p & \neg p \\ \hline t & f\\ f & t \end{array}
The tables for the compound propositions pq,pqp\land q, p\lor q and also ¬p\neg p are not too hard to grasp. The table for p    qp\implies q raises a few more questions. Why is f    tf\implies t true? I will not go into this at this point (see Example 1.31
Here is a statement about real numbers
x2=1    (x1)(x+1)(x2)=0(1.8) x^2 = 1 \qquad \implies (x-1)(x+1)(x-2) = 0 \tag{1.8}
This statement reads: no matter which real number xx you pick, if x2=1x^2 = 1, then (x1)(x+1)(x2)=0(x-1)(x+1)(x-2) = 0. We definitely want this to be true. Being true means that (1.8) must hold for all numbers xx, also x=2x = 2, which reads
22=4=1    (21)(2+1)(22)=0=0 2^2 = 4 = 1 \qquad \implies \qquad (2-1)(2+1)(2-2) = 0 = 0
The above statement is an example of a false implies true statement, which we want to be true.
In general terms, in proving the statement that p(x)    q(x)p(x) \implies q(x) holds for every xx in some set SS, we are really only interested in xSx\in S for which p(x)p(x) is true, since p(x)p(x) is our assumption. We still need p(x)    q(x)p(x)\implies q(x) to be true for xSx\in S for which p(x)p(x) is false. This is assured by the truth table for     \implies, since f    tf \implies t and f    ff\implies f are both true.
), but just point out that there are many explanations available online and, perhaps more importantly, refer you to Exercise 1.19
Suppose that we are presented with four cards
3344(1.5) \boxed{3}\qquad \fcolorbox{black}{red}{\phantom{3}} \qquad\boxed{4}\qquad \fcolorbox{black}{blue}{\phantom{4}} \tag{1.5}
with a (natural) number on the front and the color blue or red on the back. In (1.5) , the first and third cards are shown with their fronts facing up and the second and fourth cards are shown with their backs facing up.
A claim (proposition) is made that if a card has an even number on the front, then it must have the color blue on the back.
Your task is to verify this for the cards above. Of course you can do this by turning all four cards, but is there a way of checking this by turning less than four cards?
What if we add the claim, that if a card has the color blue on the back, then it must have an even number on the front?
Find two propositions pp and qq so that the claim reads p    qp\implies q.
.
Suppose that we are presented with four cards
3344(1.5) \boxed{3}\qquad \fcolorbox{black}{red}{\phantom{3}} \qquad\boxed{4}\qquad \fcolorbox{black}{blue}{\phantom{4}} \tag{1.5}
with a (natural) number on the front and the color blue or red on the back. In (1.5)
3344(1.5) \boxed{3}\qquad \fcolorbox{black}{red}{\phantom{3}} \qquad\boxed{4}\qquad \fcolorbox{black}{blue}{\phantom{4}} \tag{1.5}
, the first and third cards are shown with their fronts facing up and the second and fourth cards are shown with their backs facing up.
A claim (proposition) is made that if a card has an even number on the front, then it must have the color blue on the back.
Your task is to verify this for the cards above. Of course you can do this by turning all four cards, but is there a way of checking this by turning less than four cards?
What if we add the claim, that if a card has the color blue on the back, then it must have an even number on the front?
Find two propositions pp and qq so that the claim reads p    qp\implies q.
A prosecutor says to the defendant: "If you committed this crime you did not act alone". Explain why the defendant should not answer "no, that is not true" here.
Explain why Python/Sage thinks that the value Thanks to Gerth Brodal for pointing this out to me of
is False! Notice that you are dividing one by zero in the last "integer" above.

1.5.1 Propositional logic as a formal language

The entities pp and qq above may have real world interpretations like it rains or it is cloudy, but we will view them as variables that can be assigned the values true or false. Independent of this assignment we define a proposition as follows.
A proposition in the variables x1,,xrx_1, \dots, x_r is an expression involving the symbols x1,,xr,(,),¬,,,    x_1, \dots, x_r, (, ), \neg, \land, \lor, \implies that can be generated using the rules below
  1. The variables x1,,xrx_1, \dots, x_r are (atomic) propositions.
  2. If PP is a proposition, then (¬P)(\neg P) is a proposition.
  3. If PP and QQ are propositions, then (PQ)(P \land Q), (PQ)(P \lor Q) and (P    Q)(P \implies Q) are propositions.
The expression (x1    ((¬x2)x3))(x_1 \implies ((\neg x_2) \lor x_3)) is a proposition. Let us see how it is generated using the rules in Definition 1.22
A proposition in the variables x1,,xrx_1, \dots, x_r is an expression involving the symbols x1,,xr,(,),¬,,,    x_1, \dots, x_r, (, ), \neg, \land, \lor, \implies that can be generated using the rules below
  1. The variables x1,,xrx_1, \dots, x_r are (atomic) propositions.
  2. If PP is a proposition, then (¬P)(\neg P) is a proposition.
  3. If PP and QQ are propositions, then (PQ)(P \land Q), (PQ)(P \lor Q) and (P    Q)(P \implies Q) are propositions.
.
  1. First, x2x_2 is a proposition using (ⅰ) .
  2. Then (¬x2)(\neg x_2) is a proposition by using (ⅱ) with P=x2P = x_2, since we know by (1) that PP is a proposition.
  3. Since x3x_3 is a proposition by (ⅰ) , it follows that ((¬x2)x3)((\neg x_2) \lor x_3) is a proposition using (ⅲ) with P=(¬x2)P = (\neg x_2) and Q=x3Q = x_3, since we know by (2) that PP is a proposition.
  4. Finally, since x1x_1 is a proposition by (ⅰ) it follows by (ⅲ) with P=x1P = x_1 and Q=((¬x2)x3)Q = ((\neg x_2)\lor x_3) that
    (x1    ((¬x2)x3)) (x_1 \implies ((\neg x_2) \lor x_3))
    is a proposition, since we know by (3) that QQ is a proposition.
According the generating rules in Definition 1.22
A proposition in the variables x1,,xrx_1, \dots, x_r is an expression involving the symbols x1,,xr,(,),¬,,,    x_1, \dots, x_r, (, ), \neg, \land, \lor, \implies that can be generated using the rules below
  1. The variables x1,,xrx_1, \dots, x_r are (atomic) propositions.
  2. If PP is a proposition, then (¬P)(\neg P) is a proposition.
  3. If PP and QQ are propositions, then (PQ)(P \land Q), (PQ)(P \lor Q) and (P    Q)(P \implies Q) are propositions.
, which of the following expressions are propositions in the variables x1,x2,x3x_1, x_2, x_3.
(x1)(x_1)
x1    x2x_1 \implies x_2
(x1    x2)(x_1 \implies x_2)
x1(x2x3)x_1 \land (x_2 \lor x_3)
¬x1    x2\neg x_1 \implies x_2
((¬x1)    x2)((\neg x_1) \implies x_2)

1.5.2 Truth tables and equivalent propositions

Given a proposition, it makes sense to substitute values (tt or ff) for the variables and evaluate it using the rules in Definition 1.18
pqpqttttffftffffpqpqttttftfttfffpqp    qttttfffttfftp¬ptfft \def\arraystretch{1.2} \begin{array}{c|c|c} p & q & p\land q \\ \hline t & t & t \\ t & f & f\\ f & t & f\\ f & f & f \end{array}\qquad \begin{array}{c|c|c} p & q & p\lor q \\ \hline t & t & t \\ t & f & t\\ f & t & t\\ f & f & f \end{array} \qquad \begin{array}{c|c|c} p & q & p\implies q \\ \hline t & t & t \\ t & f & f\\ f & t & t\\ f & f & t \end{array}\qquad \begin{array}{c|c} p & \neg p \\ \hline t & f\\ f & t \end{array}
, since the parentheses leave no ambiguity as to how the evaluation must take place. For a given proposition in the variables x1,,xrx_1, \dots, x_r, there are 2r2^r ways of assignments to the set of variables. Each of these assignments results in the value true or false after evaluation. This is conveniently recorded in the truth table of the proposition as illustrated in the example below, where r=3r = 3 so that the truth table has 23=82^3 = 8 rows.
The truth tables corresponding to the propositions (x1(x2x3))(x_1 \land (x_2 \lor x_3)) and ((x1x2)(x1x3))((x_1\land x_2) \lor (x_1\land x_3)) are given below.
x1x2x3(x1(x2x3))fffffftfftfffttftffftfttttftttttx1x2x3((x1x2)(x1x3))fffffftfftfffttftffftfttttfttttt \def\arraystretch{1.2} \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & (x_1 \land (x_2 \lor x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}\qquad\qquad \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & ((x_1\land x_2) \lor (x_1\land x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}
For example, if x1=t,x2=fx_1 = t, x_2 = f and x3=tx_3 = t, then
(x1(x2x3))=(t(ft))=(tt)=t (x_1 \land (x_2 \lor x_3)) = (t \land (f \lor t)) = (t \land t) = t
and
((x1x2)(x1x3))=((tf)(tt))=(ft)=t. ((x_1\land x_2) \lor (x_1\land x_3)) = ((t \land f) \lor (t \land t)) = (f \lor t) = t.
The two propositions in Example 1.25
The truth tables corresponding to the propositions (x1(x2x3))(x_1 \land (x_2 \lor x_3)) and ((x1x2)(x1x3))((x_1\land x_2) \lor (x_1\land x_3)) are given below.
x1x2x3(x1(x2x3))fffffftfftfffttftffftfttttftttttx1x2x3((x1x2)(x1x3))fffffftfftfffttftffftfttttfttttt \def\arraystretch{1.2} \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & (x_1 \land (x_2 \lor x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}\qquad\qquad \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & ((x_1\land x_2) \lor (x_1\land x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}
For example, if x1=t,x2=fx_1 = t, x_2 = f and x3=tx_3 = t, then
(x1(x2x3))=(t(ft))=(tt)=t (x_1 \land (x_2 \lor x_3)) = (t \land (f \lor t)) = (t \land t) = t
and
((x1x2)(x1x3))=((tf)(tt))=(ft)=t. ((x_1\land x_2) \lor (x_1\land x_3)) = ((t \land f) \lor (t \land t)) = (f \lor t) = t.
have identical truth tables. In general, if two propositions PP and QQ have identical truth tables we call them equivalent and write
PQ. P \equiv Q.
In Example 1.25
The truth tables corresponding to the propositions (x1(x2x3))(x_1 \land (x_2 \lor x_3)) and ((x1x2)(x1x3))((x_1\land x_2) \lor (x_1\land x_3)) are given below.
x1x2x3(x1(x2x3))fffffftfftfffttftffftfttttftttttx1x2x3((x1x2)(x1x3))fffffftfftfffttftffftfttttfttttt \def\arraystretch{1.2} \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & (x_1 \land (x_2 \lor x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}\qquad\qquad \begin{array}{c|c|c|c} x_1 & x_2 & x_3 & ((x_1\land x_2) \lor (x_1\land x_3)) \\ \hline f & f & f & f \\ f & f & t & f \\ f & t & f & f \\ f & t & t & f \\ t & f & f & f \\ t & f & t & t \\ t & t & f & t \\ t & t & t & t \end{array}
For example, if x1=t,x2=fx_1 = t, x_2 = f and x3=tx_3 = t, then
(x1(x2x3))=(t(ft))=(tt)=t (x_1 \land (x_2 \lor x_3)) = (t \land (f \lor t)) = (t \land t) = t
and
((x1x2)(x1x3))=((tf)(tt))=(ft)=t. ((x_1\land x_2) \lor (x_1\land x_3)) = ((t \land f) \lor (t \land t)) = (f \lor t) = t.
we saw that
(x1(x2x3))((x1x2)(x1x3)). (x_1 \land (x_2 \lor x_3)) \equiv ((x_1\land x_2) \lor (x_1\land x_3)).
The definition below is very important too keep in mind.
The notation p    qp \iff q is used frequently. It means that both p    qp\implies q and q    pq\implies p are true i.e.,
p    q(p    q)(q    p). p \iff q \equiv (p\implies q) \land (q\implies p).

1.5.3 Using Sage to compute truth tables

Sage may be used to compute truth tables for propositions using the propositional calculus in Sage. Below is an example. Be sure to check how to enter ,,    \land, \lor, \implies and ¬\neg.
Construct by hand the truth table for the proposition (pq)(¬r)(p\land q) \lor (\neg r).
Convince yourself either using Sage or by writing out truth tables that
  1. (x1    x2)((¬x2)    (¬x1))(x_1 \implies x_2) \equiv ((\neg x_2)\implies (\neg x_1))
  2. (¬(x1x2))((¬x1)(¬x2))(\neg (x_1 \lor x_2)) \equiv ((\neg x_1) \land (\neg x_2))
  3. ¬(x1x2)(¬x1)(¬x2)\neg (x_1 \land x_2) \equiv (\neg x_1) \lor (\neg x_2)
  4. x1    x2(¬x1)x2x_1 \implies x_2 \equiv (\neg x_1)\lor x_2

1.5.4 Variables, predicates and quantification

A predicate is a proposition depending on one or more variables.
Variables are fundamental in computer programs. In the predicate x=1x = 1, xx appears as a variable. Depending on what you substitute for xx, the resulting proposition could be true or false or even meaningless. As an example, the latter case appears if xx is replaced by the character 'a'. This is what computer scientists call a type error. You cannot compare a character with a digit.
If p(n)=n is a prime numberp(n) = n\ \text{is a prime number}, then p(3)p(3) is true, whereas p(6)p(6) is false.
q(m,n)=p(m)(¬p(n)) q(m, n) = p(m) \land (\neg p(n))
is a predicate in two variables mm and nn. Here q(3,4)q(3, 4) is true, whereas q(5,7)q(5, 7) is false.

For every \forall and there exists \exists

Suppose that we have a predicate p(x)p(x), such that p(x)p(x) is a proposition for xSx\in S, where SS is some set. Then we define the proposition
xS:p(x)(1.6) \exists x\in S: p(x) \tag{1.6}
to be true if there exists xSx\in S, such that p(x)p(x) is true. We let
xS:p(x)(1.7) \forall x\in S: p(x) \tag{1.7}
be the proposition defined by
¬(xS:¬p(x)). \neg (\exists x\in S: \neg p(x)).
In other words, (1.7)
xS:p(x)(1.7) \forall x\in S: p(x) \tag{1.7}
says that p(x)p(x) is true for every xSx\in S, since there does not exist xSx\in S making p(x)p(x) false. Le me be absolutely clear. To show that xS:p(x)\forall x\in S: p(x) is false, it is enough to find just a single xSx\in S so that p(x)p(x) is false.
Here is a statement about real numbers
x2=1    (x1)(x+1)(x2)=0(1.8) x^2 = 1 \qquad \implies (x-1)(x+1)(x-2) = 0 \tag{1.8}
This statement reads: no matter which real number xx you pick, if x2=1x^2 = 1, then (x1)(x+1)(x2)=0(x-1)(x+1)(x-2) = 0. We definitely want this to be true. Being true means that (1.8)
x2=1    (x1)(x+1)(x2)=0(1.8) x^2 = 1 \qquad \implies (x-1)(x+1)(x-2) = 0 \tag{1.8}
must hold for all numbers xx, also x=2x = 2, which reads
22=4=1    (21)(2+1)(22)=0=0 2^2 = 4 = 1 \qquad \implies \qquad (2-1)(2+1)(2-2) = 0 = 0
The above statement is an example of a false implies true statement, which we want to be true.
In general terms, in proving the statement that p(x)    q(x)p(x) \implies q(x) holds for every xx in some set SS, we are really only interested in xSx\in S for which p(x)p(x) is true, since p(x)p(x) is our assumption. We still need p(x)    q(x)p(x)\implies q(x) to be true for xSx\in S for which p(x)p(x) is false. This is assured by the truth table for     \implies, since f    tf \implies t and f    ff\implies f are both true.
The following is an excerpt from the infamous Beredskabsprøve Datalogi.
Which of the following are true?
xN:x>2\forall x\in \mathbb{N}: x > 2
xN:x>2\exists x\in \mathbb{N}: x > 2
x:x=7\forall x\in \emptyset: x = 7
x:x=7\exists x\in \emptyset: x = 7

1.5.5 Proofs and inference rules

A proof begins with an assumption PP and proceeds with a sequence of logical steps called inference rules leading to a conclusion QQ.
You have been taught how to solve equations in steps leading to a solution. Each step turns out to be an inference rule and the conclusion is the solution. Let us see how for the simple equation x+1=2x + 1 = 2. Formally we want to prove
xR:x+1=2    x=1. \forall x\in \mathbb{R}: x + 1 = 2 \implies x = 1.
The first inference rule is a=b    a+c=b+ca = b \implies a + c = b + c i.e., we are allowed to add the same number to both sides of an equality. This implies
x+1=2    (x+1)1=21=1. x + 1 = 2 \implies (x+1)-1 = 2 - 1 = 1.
To be very precise we now use Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
(ⅳ) as an inference rule i.e.,
(x+1)1=1    x+(11)=1. (x + 1) - 1 = 1 \implies x + (1 - 1) = 1.
Then we use Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
(ⅷ) to conclude
x+(11)=1    x+0=1 x + (1 - 1) = 1 \implies x + 0 = 1
and then finally, we get by Proposition 1.12
Suppose that AA is one of the sets N,Z,Q\mathbb{N}, \mathbb{Z}, \mathbb{Q} or R\mathbb{R}. Then for numbers x,y,zx, y, z all in AA we have
  1. 1x=x1\cdot x = x
  2. xy=yxx y = y x
  3. x+y=y+xx + y = y + x
  4. (x+y)+z=x+(y+z)(x + y) + z = x + (y + z)
  5. (xy)z=x(yz)(x y) z = x (y z)
  6. x(y+z)=xy+xzx(y + z) = x y + x z
If AA is one of Z,Q\mathbb{Z}, \mathbb{Q} or R\mathbb{R}, then 0A0\in A and for every xAx\in A,
  1. x+0=xx + 0 = x
  2. x+y=0x + y = 0 for some number yAy \in A.
Finally if AA is Q\mathbb{Q} or R\mathbb{R} and xAx\in A is not 00,then
  1. xz=1x z = 1 for some number zAz\in A.
The number zz above is called the inverse of xx and is usually denoted x1x^{-1}. The number yy above is called the negative of xx and is usually denoted x-x. We will also the symbol - (minus) defined as an operation on two numbers x,yAx, y\in A as
xy:=x+(y). x - y := x + (-y).
(ⅶ) that
x+0=1    x=1. x + 0 = 1 \implies x = 1.
So to solve the equation x+1=2x + 1 = 2, we are actually using four (!) inference rules along the way.

1.5.6 The use of implication (    \implies) and bi-implication (    \iff)

As you have seen,     \implies and     \iff are applied to link propositions in a logical argument. For example,
x+1=2    x=1orxZ:x+1=2    x=1. x + 1 = 2 \iff x = 1\qquad\text{or}\qquad \forall x\in \mathbb{Z}: x + 1 = 2 \iff x = 1.
However, for x0    x20x \geq 0 \implies x^2 \geq 0 we cannot link the two propositions by     \iff, simply because xZ;x20    x0\forall x\in \mathbb{Z}; x^2 \geq 0 \implies x \geq 0 is false (for x=1x= -1).
Prove that
(x<y)((y+3)<(z+10))    (x+37)<(z+44) (x < y) \land ((y+3) < (z+10)) \implies (x+37) < (z+44)
for every x,y,zZx, y, z\in \mathbb{Z} (see Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
with A=ZA = \mathbb{Z} for the precise definition of <<). Write out every inference rule!
You need to be very precise here. What does x<yx < y mean precisely if x,yZx, y\in \mathbb{Z}? In Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
you will see that it means that yxNy - x\in \mathbb{N}. From this you need to deduce
  1. (x<y)(y<z)    x<z(x < y) \land (y < z) \implies x < z
  2. x<y    x+z<y+zx < y \implies x + z < y + z
for every x,y,zZx, y, z\in \mathbb{Z}
Try out
💬

Is 
$$
x \geq 0 \iff x^2 \geq 0
$$
a true statement? Give me 3 carefully crafted exercises
training me in distuishing $\implies$ and $\iff$.
Only use basic mathematics involving
numbers and arithmetic operations.
After each exercise stop, ask for the
answer and give valueable feedback and guidance.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
and go through the exercises given to you.

1.5.7 More on mathematical proofs

Most professional mathematicians rarely think about the precise definition of a proof and would probably feel uncomfortable defining a proof precisely. During many years of training they have assimilated knowledge by experience. Therefore many proofs seem born out of witchcraft containing several magical devices.
However, many proofs appearing in respected mathematical journals, submitted by respected mathematicians, have turned out to contain errors. Recent developments in automated proof systems like Coq and LEAN show promise in checking proofs like for example the famous four color theorem. These automated proof systems build on dependent type theory, which we will not go into.
Informally a proof of a proposition qq, consists in arguing that an implication p    qp\implies q is true by first assuming pp. Usually this is done not only through one implication p    qp\implies q, but through a series of intermediate implications
p    q1    q2    q3        qN, p\implies q_1 \implies q_2 \implies q_3 \implies \cdots \implies q_N,
where the last proposition qNq_N is qq. If pp is true, this will constitute a proof that qN=qq_N = q is true. Just like in (1.14)
<3<2<1<0<1<2<(1.14) \cdots < -3 < -2 < -1 < 0 < 1 < 2 < \cdots \tag{1.14}
, there is an imprecision here. Can you tell what it is?
An integer is called even if it is divisible by 22. So the even integers are
{,4,2,0,2,4,}. \{\dots, -4, -2, 0, 2, 4, \dots\}.
An integer is called odd if it is not even. So the odd integers are
{,5,3,1,1,3,}. \{\dots, -5, -3, -1, 1, 3, \dots\}.
Consider the proposition:
nZ:p(n)    p(n2),(1.9) \forall n\in \mathbb{Z}: p(n)\implies p(n^2), \tag{1.9}
where p(n)=(n is odd)p(n) = (n\text{ is odd}) i.e., the square of an odd integer is odd. This seems true for a first selection of examples: 32=9,52=25,3^2=9, 5^2=25, \dots.
What does it mean exactly for a number to be odd? This means that it is not divisible by 22 or that there exists another integer aa, such that n=2a+1n = 2 a + 1. So
p(n)=aZ:n=2a+1. p(n) = \exists a\in \mathbb{Z}: n = 2 a + 1.
Therefore we need to show that
(aZ:n=2a+1)    (bZ:n2=2b+1). \left(\exists a\in \mathbb{Z}: n = 2 a + 1\right) \implies \left(\exists b\in \mathbb{Z}: n^2 = 2 b + 1\right).
Notice that I had to change aa into bb in the second proposition above. The two variables are not the same: aa is associated with nn and bb is associated with n2n^2.
Let us assume that n=2a+1n = 2 a + 1. Now we need to argue that n2=2b+1n^2 = 2 b + 1 for some bZb\in \mathbb{Z}. You stare at this for a while and notice that we should use the assumption n=2a+1n=2 a + 1 in computing n2n^2:
n2=(2a+1)2=(2a)2+2(2a)+12=4a2+4a+1=2(2a2+2a)+1. n^2 = (2 a + 1)^2 = (2 a)^2 + 2 (2 a) + 1^2 = 4 a^2 + 4 a + 1 = 2(2 a^2 + 2 a) + 1.
Thus, using our assumption we may conclude that if n=2a+1n = 2 a + 1, then
n2=2b+1, n^2 = 2 b + 1,
where b=2a2+2ab=2a^2+ 2 a. This completes the proof.
The beauty here is that we have verified for all odd natural numbers that their square is odd. Not just a finite selection like 3,7,11,133, 7, 11, 13.
In many ways a proof is like a detailed argument in a court case, except that the rules of mathematics are universal. You need the absolute truth in the court of mathematics (or science).
Consider the proposition q(n)=n is evenq(n) = n \text{ is even}. Prove that
nZ:q(n2)    q(n). \forall n\in \mathbb{Z}: q(n^2)\implies q(n).
Use that q(n)=¬p(n)q(n) = \neg p(n), where p(n)p(n) is defined in Example 1.35
An integer is called even if it is divisible by 22. So the even integers are
{,4,2,0,2,4,}. \{\dots, -4, -2, 0, 2, 4, \dots\}.
An integer is called odd if it is not even. So the odd integers are
{,5,3,1,1,3,}. \{\dots, -5, -3, -1, 1, 3, \dots\}.
Consider the proposition:
nZ:p(n)    p(n2),(1.9) \forall n\in \mathbb{Z}: p(n)\implies p(n^2), \tag{1.9}
where p(n)=(n is odd)p(n) = (n\text{ is odd}) i.e., the square of an odd integer is odd. This seems true for a first selection of examples: 32=9,52=25,3^2=9, 5^2=25, \dots.
What does it mean exactly for a number to be odd? This means that it is not divisible by 22 or that there exists another integer aa, such that n=2a+1n = 2 a + 1. So
p(n)=aZ:n=2a+1. p(n) = \exists a\in \mathbb{Z}: n = 2 a + 1.
Therefore we need to show that
(aZ:n=2a+1)    (bZ:n2=2b+1). \left(\exists a\in \mathbb{Z}: n = 2 a + 1\right) \implies \left(\exists b\in \mathbb{Z}: n^2 = 2 b + 1\right).
Notice that I had to change aa into bb in the second proposition above. The two variables are not the same: aa is associated with nn and bb is associated with n2n^2.
Let us assume that n=2a+1n = 2 a + 1. Now we need to argue that n2=2b+1n^2 = 2 b + 1 for some bZb\in \mathbb{Z}. You stare at this for a while and notice that we should use the assumption n=2a+1n=2 a + 1 in computing n2n^2:
n2=(2a+1)2=(2a)2+2(2a)+12=4a2+4a+1=2(2a2+2a)+1. n^2 = (2 a + 1)^2 = (2 a)^2 + 2 (2 a) + 1^2 = 4 a^2 + 4 a + 1 = 2(2 a^2 + 2 a) + 1.
Thus, using our assumption we may conclude that if n=2a+1n = 2 a + 1, then
n2=2b+1, n^2 = 2 b + 1,
where b=2a2+2ab=2a^2+ 2 a. This completes the proof.
.

1.5.8 Proof by contradiction

A proposition pp is either true or false. This seemingly obvious statement goes by the name of the law of excluded middle and dates back to the writings of Aristotle. The law of excluded middle is key in the example below, where you are left with the feeling that you have been deprived of a fair and genuine proof.
An irrational number is a (real) number that is not rational. It is a startling fact that such numbers exist, but they do! The square root 2\sqrt{2} of two is an example. We will prove that there exists two irrational numbers α,β\alpha, \beta, such that αβ\alpha^\beta is rational.
Consider the proposition pp given by
γ=22is rational. \gamma = \sqrt{2}^{\sqrt{2}}\text{is rational.}
Either pp is true or false. If pp is true we are done putting α=β=2\alpha = \beta = \sqrt{2}. If not, then pp must be false and γ\gamma is irrational. But then
γ2=(22)2=(2)22=22=2 \gamma^{\sqrt{2}} = \left(\sqrt{2}^{\sqrt{2}}\right)^{\sqrt{2}} = (\sqrt{2})^{\sqrt{2}\cdot \sqrt{2}} = \sqrt{2}^2 = 2
and we are done putting α=γ\alpha = \gamma and β=2\beta = \sqrt{2}.
So which one is it? Is
22 \sqrt{2}^{\sqrt{2}}
rational or irrational? This is really advanced mathematics based on the Gelfond-Schneider theorem.
The law of excluded middle can be turned into a powerful proof technique called proof by contradiction.
Suppose we wish to establish that pp is true. Then we turn things upside down by assuming that pp is false i.e., that ¬p\neg p is true. If we then by logical deduction can show that
¬p    q, \neg p \implies q,
for some proposition qq, which is demonstrably false, then ¬p\neg p cannot be true (since true     \implies false is false). Therefore ¬p\neg p must be false and pp must be true by the law of the excluded middle. This technique is used all the time!
Let us use proof by contradiction to show that the proposition p:p: (2\sqrt{2} is an irrational number) is true. Assuming that pp is false, we must have that ¬p\neg p is true. But ¬p\neg p is the proposition p1p_1 (that 2\sqrt{2} is a rational number)
m,nN:2=mn. \exists m, n\in \mathbb{N}: \sqrt{2} = \frac{m}{n}.
Here p1    p2p_1 \iff p_2, where p2p_2 is the proposition
m,nN:(2=mn)((m is odd)(n is odd)), \exists m, n\in \mathbb{N}: \left(\sqrt{2} = \frac{m}{n}\right) \land ((m \text{ is odd}) \lor (n \text{ is odd})),
since we can assume that 22 is not a common divisor of mm and nn by Definition 1.7
A rational number a/bQa/b\in \mathbb{Q} consists of a numerator aZa\in \mathbb{Z} and a denominator bNb\in \mathbb{N}.
If a,cZa, c\in \mathbb{Z} and b,dNb, d\in \mathbb{N}. Then a/ba/b and c/dc/d are considered equal i.e.,
ab=cd \frac{a}{b} = \frac{c}{d}
if and only if ad=bca d = b c.
. However,
2=mn    2n=m    2n2=m2    m is even. \sqrt{2} = \frac{m}{n} \iff \sqrt{2} n = m \iff 2 n^2 = m^2 \implies m\text{ is even}.
The last implication above follows from Exercise 1.36
Consider the proposition q(n)=n is evenq(n) = n \text{ is even}. Prove that
nZ:q(n2)    q(n). \forall n\in \mathbb{Z}: q(n^2)\implies q(n).
Use that q(n)=¬p(n)q(n) = \neg p(n), where p(n)p(n) is defined in Example 1.35
An integer is called even if it is divisible by 22. So the even integers are
{,4,2,0,2,4,}. \{\dots, -4, -2, 0, 2, 4, \dots\}.
An integer is called odd if it is not even. So the odd integers are
{,5,3,1,1,3,}. \{\dots, -5, -3, -1, 1, 3, \dots\}.
Consider the proposition:
nZ:p(n)    p(n2),(1.9) \forall n\in \mathbb{Z}: p(n)\implies p(n^2), \tag{1.9}
where p(n)=(n is odd)p(n) = (n\text{ is odd}) i.e., the square of an odd integer is odd. This seems true for a first selection of examples: 32=9,52=25,3^2=9, 5^2=25, \dots.
What does it mean exactly for a number to be odd? This means that it is not divisible by 22 or that there exists another integer aa, such that n=2a+1n = 2 a + 1. So
p(n)=aZ:n=2a+1. p(n) = \exists a\in \mathbb{Z}: n = 2 a + 1.
Therefore we need to show that
(aZ:n=2a+1)    (bZ:n2=2b+1). \left(\exists a\in \mathbb{Z}: n = 2 a + 1\right) \implies \left(\exists b\in \mathbb{Z}: n^2 = 2 b + 1\right).
Notice that I had to change aa into bb in the second proposition above. The two variables are not the same: aa is associated with nn and bb is associated with n2n^2.
Let us assume that n=2a+1n = 2 a + 1. Now we need to argue that n2=2b+1n^2 = 2 b + 1 for some bZb\in \mathbb{Z}. You stare at this for a while and notice that we should use the assumption n=2a+1n=2 a + 1 in computing n2n^2:
n2=(2a+1)2=(2a)2+2(2a)+12=4a2+4a+1=2(2a2+2a)+1. n^2 = (2 a + 1)^2 = (2 a)^2 + 2 (2 a) + 1^2 = 4 a^2 + 4 a + 1 = 2(2 a^2 + 2 a) + 1.
Thus, using our assumption we may conclude that if n=2a+1n = 2 a + 1, then
n2=2b+1, n^2 = 2 b + 1,
where b=2a2+2ab=2a^2+ 2 a. This completes the proof.
.
. If mm is even, then m=2km = 2 k for some kNk\in \mathbb{N}. Therefore m2=4k2m^2 = 4 k^2 and
2n2=4k2    n2=2k2 2 n^2 = 4 k^2 \iff n^2 = 2 k^2
so that nn is also even. We have proved that p2p_2 implies the proposition p3p_3 given by
(m is even)(n is even). (m \text{ is even}) \land (n \text{ is even}).
Since we are assuming that p2p_2 is true, we must have that p3p_3 is false. However we have shown that p2    p3p_2\implies p_3 is true. But t    ft\implies f is a false. Therefore we must have that p2p_2 is false and therefore that p1p_1 is false. But then according to the law of the excluded middle, we must have that p=¬p1p = \neg p_1 is true.
Consider the first nn prime numbers
p1=2,p2=3,p3=5,,pn. p_1 = 2, p_2 = 3, p_3 = 5, \dots, p_n.
Check that
p1p1p2+1p1p2p3+1p1p2p3p4+1\begin{aligned} &p_1\\ &p_1\, p_2 + 1\\ &p_1\, p_2\, p_3 + 1\\ &p_1\, p_2\, p_3\, p_4 + 1 \end{aligned}
are prime numbers by using the Sage window below (factor gives the prime factorization of a natural number).
Is it true in general that
p1p2pn+1 p_1\, p_2\, \cdots \, p_n + 1
is a prime number?
Assume that we know that every natural number must be divisible by a prime number. Prove that there are infinitely many prime numbers using proof by contradiction.
Show how the assumption that there are only finitely many prime numbers say
p1,p2,,pn p_1, p_2, \dots, p_n
leads to a contradiction by using that the natural number
p1p2pn+1 p_1\, p_2\, \dots\, p_n + 1
must be divisible by a prime number.

1.6 More on sets

Propositions are important, but are confined by the binary values of true and false. We would like to work mathematically with objects like integers, floating point numbers, neural networks, computer programs and so on.

1.6.1 Objects and equality

One of the cornerstones of modern mathematics is deciding when two objects are the same i.e., given two objects AA and BB, deciding whether the proposition A=BA=B is true of false. Oftentimes an algorithm for evaluating A=BA=B is needed.
You may laugh here, but this is not always that easy. Even though objects appear different they are the same as in, for example the propositions
105189=3563andsin(π2)=1. \frac{105}{189} = \frac{35}{63}\qquad\text{and}\qquad \sin\left(\frac{\pi}{2}\right) = 1.
The first proposition above is an identity of fractions (rational numbers). The second is an identity, which calls for knowledge of the sine function and real numbers. Each of these identities calls for some rather advanced mathematics. The first proposition is true in a very precise way, since 10563=18935105\cdot 63 = 189 \cdot 35.
Use the Sage window above to reason about equality in the quiz below. In each case describe the objects i.e., are they numbers, symbols, etc.? Also, please check your computations by hand with the old fashioned paper and pencil, especially (a+b)(ab)(a+b)(a-b).
Click on the right equalities below.
a+b2b=aba + b - 2 b = a - b
(a+b)2=a2+b2(a+b)^2 = a^2 + b^2
(a+b)(ab)=a2b2(a + b)(a - b) = a^2 - b^2
(a+b)2=a2+2ab+b2(a + b)^2 = a^2 + 2 a b + b^2
(a+b)3=a3+2a2b+2ab2+b3(a+b)^3 = a^3 + 2 a^2 b + 2 a b^2 + b^3
38=513\frac{3}{8} = \frac{5}{13}
π=227 \pi = \frac{22}{7}
cos2(π)+sin2(π)=1 \cos^2(\pi) + \sin^2(\pi) = 1
You know that (a+b)2=a2+2ab+b2(a+ b)^2 = a^2 + 2 a b + b^2. Use Sage to find a similar identities for (a+b)3(a + b)^3 and (a+b)4(a + b)^4.
Go back and look at (the beginning of) Exercise 1.40
Use the Sage window above to reason about equality in the quiz below. In each case describe the objects i.e., are they numbers, symbols, etc.? Also, please check your computations by hand with the old fashioned paper and pencil, especially (a+b)(ab)(a+b)(a-b).
Click on the right equalities below.
a+b2b=aba + b - 2 b = a - b
(a+b)2=a2+b2(a+b)^2 = a^2 + b^2
(a+b)(ab)=a2b2(a + b)(a - b) = a^2 - b^2
(a+b)2=a2+2ab+b2(a + b)^2 = a^2 + 2 a b + b^2
(a+b)3=a3+2a2b+2ab2+b3(a+b)^3 = a^3 + 2 a^2 b + 2 a b^2 + b^3
38=513\frac{3}{8} = \frac{5}{13}
π=227 \pi = \frac{22}{7}
cos2(π)+sin2(π)=1 \cos^2(\pi) + \sin^2(\pi) = 1
.
For two objects AA and BB we will use the notation ABA \neq B for the proposition ¬(A=B)\neg (A = B).
We have already defined a set (informally) as a collection of distinct objects or elements. We introduce some more set theory here. A set is also an object as described in section 1.6.1 and it makes sense to ask when two sets are equal.
Two sets AA and BB are equal i.e., A=BA = B if they contain the same elements.
An example of a set could be the set {1,2,3}\{1,2,3\} of natural numbers between 00 and 44. Notice again that we use the symbol "{\{" to start the listing of elements in a set and the symbol "}\}" to denote the end of the listing. Notice also that (by our definition of equality between sets), the order of the elements in the listing does not matter i.e.,
{1,2,3}={2,3,1}. \{1, 2, 3\} = \{2, 3, 1\}.
We are also not allowing duplicates like for example in the listing {1,2,2,3,3,3}\{1, 2, 2, 3, 3, 3\} (such a thing is called a multiset).
An example of a set not involving numbers could be the set of letters
S={A,n,e,x,a,m,p,l,c,o,u,d,b,t,h,s,r,i} S=\{A, n, e, x, a, m, p, l, c, o, u, d, b, t, h, s, r, i\}
used in this sentence. The number of elements in a set SS is called the cardinality of the set. We will denote it by S|S|.
To convince someone beyond a doubt (we will talk about this formally later in this chapter) that two sets AA and BB are equal, one needs to argue that if xx is an element of AA, then xx is an element of BB and the other way round, if yy is an element of BB, then yy is an element of AA. If this is true, then AA and BB must contain the same elements.
Give a precise reason as to why the two sets {1,2,3}\{1, 2, 3\} and {1,2,4}\{1, 2, 4\} are not equal. Is it possible for a set with 55 elements to be equal to a set with 77 elements?
Sets may be explored using (only) python. This is illustrated in the snippet below.
Come up with three lines of Sage code that verifies {1,2,3}{1,2,4}\{1, 2, 3\} \neq \{1, 2, 4\}. Try it out.

The empty set

There is a unique set containing no or zero elements. This set is called the empty set and is denoted \emptyset i.e.,
={}and=0. \emptyset = \{\}\qquad\text{and}\qquad |\emptyset| = 0.
For some reason (perhaps a good one) python does not accept {}\{\} as input for the empty set. Why is this? Evaluate the python snippet below and explain.

1.6.2 The symbols \in and \notin

The symbol \in is ubiquitous in set theory (and mathematics). If AA is a set, then
xA(1.10) x\in A \tag{1.10}
is a proposition. It is true if xx is an element of or belongs to AA. The notation
xA x\notin A
is defined by the proposition ¬(xA)\neg (x\in A). Also, as a bit of short hand notation, we will write
a1,a2,,anAfor the proposition(a1A)(a2A)(anA). a_1, a_2, \dots, a_n\in A\qquad\text{for the proposition}\qquad (a_1\in A)\land (a_2\in A)\land \cdots \land (a_n\in A).
Belongs to (\in) is straightforward in python.
\in
, but
∉\not\in
. This exercise actually has
possible correct solutions if {1,2,3}\{1, 2, 3\} is in the second empty box and {4,5,6}\{4, 5, 6\} in the fourth empty box.
{1,2,3}\{1, 2, 3\}
{4,5,6}\{4, 5, 6\}
00
11
33
66
77

1.6.3 Subsets

If AA and BB are sets, then ABA\subseteq B At times, the symbol \subset is used instead of \subseteq. In our context these two symbols mean the same. However, the notation ABA\subsetneq B means that ABA\subseteq B and ABA\neq B. For example, {1,2,3}{1,2,3}\{1, 2, 3\} \subseteq \{1, 2, 3\} and {1,2,3}{1,2,3}\{1, 2, 3\} \subset \{1, 2, 3\}. means that every element of AA is an element of BB. So ABA\subseteq B is a placeholder for the proposition
xA:xB \forall x\in A : x\in B
In this case we say that AA is a subset of BB. We also use the notation ABA\subsetneq B to indicate that ABA\subseteq B and ABA\neq B. In this case we say that AA is a strict subset of BB.
List the subsets of {1,2}\{1, 2\}. How many are there?
It turns out that the empty set \emptyset is a subset of any set.
Explain why this is so using the definition of \subseteq.
LLM
💬

Explain precisely in terms of propositions and logic why the empty set is a subset of any given set.

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Below Sage (not python) will list all subsets of the set {1,2,3}\{1, 2, 3\}. Before pressing the Compute button, try to write them down on your own.
List all the subsets of a set with five elements. In general, how many subsets does a set with nn elements have?
The set
is not a subset of A=A=
, simply because
does not belong to AA. This exercise actually has
possible correct solutions.
{1,2,3}\{1, 2, 3\}
{1,1,2,3,4}\{-1, 1, 2, 3, 4\}
{1,0,1,2,4}\{-1, 0, 1, 2, 4\}
33
1-1
55
66
00
The empty set has
elements. A set with
elements has
subsets. In general a set with nn elements has
subsets.
11
00
55
2525
3232
n2n^2
2n2^n

1.6.4 Set-builder notation

If SS is a set and p(x)p(x) a predicate for xSx\in S, then we build the subset
{xSp(x)}S(1.11) \{x\in S \mid p(x)\}\subseteq S \tag{1.11}
of xSx\in S such that p(x)p(x) is true.
Suppose that S={2,1,2,3}S = \{-2, -1, 2, 3\} and
p(x)=x is positive. p(x) = x \text{\ is positive.}
Then
{xSp(x)}={2,3}S. \{x\in S\mid p(x)\} = \{2, 3\} \subseteq S.
Python
This notation has found its way to several programming languages like list comprehension in python.
Suppose that p1(x),,pn(x)p_1(x), \dots, p_n(x) are predicates with a variable xx taking values in SS, then we often use the notation (using ,, instead of \land)
{xSp1(x),,pn(x)}for{xSp1(x)pn(x)}. \{x\in S \mid p_1(x), \dots, p_n(x)\}\quad\text{for}\quad \{x\in S \mid p_1(x)\land \dots\land p_n(x)\}.
In the exercises below we have sloppily used the ordering << before it is formally defined. We apologize to the reader and refer to Section 1.7 .
List the elements in the following subsets.
  1. {xZx2<10}. \{x\in \mathbb{Z} \mid x^2 < 10\}.
  2. {(x,y)Z2x2+y2<5}. \{(x, y)\in \mathbb{Z}^2 \mid x^2 + y^2 < 5\}.
Consider the predicate q(n)q(n)
n and n+2 are both prime numbers. n\text{ and }n+2\text{ are both prime numbers}.
Write down the elements in
{nN×Nq(n)n50}. \{n\in \mathbb{N}\times \mathbb{N} \mid q(n) \land n \leq 50\}.
Is
{nN×Nq(n)} \{n\in \mathbb{N}\times \mathbb{N}\mid q(n)\}
an infinite set?
Explore the fascinating world of prime numbers and learn about twin primes.
You have previously encountered systems of linear equations like
x+y=33xy=5.(1.12)\begin{aligned} x + y &= 3\\ 3x - y &= 5. \end{aligned}\tag{1.12}
The solutions to (1.12)
x+y=33xy=5.(1.12)\begin{aligned} x + y &= 3\\ 3x - y &= 5. \end{aligned}\tag{1.12}
can be identified with a subset of R2\mathbb{R}^2. Define this subset precisely i.e., write the subset as
{(x,y)R2p(x,y)}, \{(x, y)\in \mathbb{R}^2 \mid p(x, y)\},
where p(x,y)p(x, y) is a predicate in the variables x,yRx, y\in \mathbb{R}.
Suppose that X=RX = \mathbb{R} and
Y={xRx>0,x<2}. Y = \{x\in \mathbb{R} \mid x > 0,\, x < 2\}.
Then write down precisely what XY={xXx∉Y}X\setminus Y = \{x\in X\mid x\not\in Y\} is i.e., find suitable predicates q1,q2q_1, q_2 in the variable xx, such that q(x)=q1(x)q2(x)q(x) = q_1(x) \lor q_2(x) and
XY={xRq(x)}. X\setminus Y = \{x\in \mathbb{R} \mid q(x)\}.
Consider the subset SS of R2\mathbb{R}^2 pictured in the drawing below
Express SS as
S={(x,y)R2p1(x,y),p2(x,y),p3(x,y)}, S = \{(x, y)\in \mathbb{R}^2 \mid p_1(x, y), p_2(x, y), p_3(x, y)\},
where p1,p2,p3p_1, p_2, p_3 are predicates in the variables x,yx, y.
Hint
A predicate in the variables x,yx, y could be something like
xy17. x -y \geq 17.
Express R2S\mathbb{R}^2\setminus S as
{(x,y)R2p(x,y)}, \{(x, y)\in \mathbb{R}^2 \mid p(x, y)\},
where
p(x,y)=q1(x,y)q2(x,y)q3(x,y) p(x, y) = q_1(x, y) \lor q_2(x, y) \lor q_3(x, y)
and q1,q2q_1, q_2 and q2q_2 are suitable predicates in the variables x,yx, y.

1.6.5 Intersections, unions and the symbols ,  \cap,\,\, \cup and \setminus

Suppose that we have two sets AA and BB. Then the intersection ABA\cap B is the set consisting of the elements in both AA and BB i.e.,
AB={x(xA)(xB)}. A\cap B = \{x \mid (x\in A) \land (x\in B)\}.
This is illustrated in the socalled Venn diagram below.
The union ABA\cup B is the set consisting of the elements in AA or BB i.e.,
AB={x(xA)(xB)}. A\cup B = \{x \mid (x\in A) \lor (x\in B)\}.
This is illustrated in the Venn diagram below.
Lastly, the difference ABA\setminus B (between AA and BB) consists of the elements in AA not contained in BB i.e.,
AB={x(xA)(xB)}. A\setminus B = \{x \mid (x\in A) \land (x\notin B)\}.
This is illustrated in the Venn diagram below.
Python
You should experiment using the python window below to get a feeling for these three operations.
Suppose that A={1,2,3,4,5}A=\{1, 2, 3,4, 5\}, B={1,3,4,7}B = \{-1, 3, 4, 7\} and {2,3,8,9}\{2, 3, 8, 9\}. What is ((AB)C)B((A\cup B)\setminus C)\setminus B?
Let A={1,2,3}A = \{1, 2, 3\}, B={3,4,5}B = \{3, 4, 5\} and C={0,1,5}C = \{0, 1, 5\}. Verify by hand (no computer) that
  1. AB={1,2,3,4,5}A\cup B = \{1, 2, 3, 4, 5\}.
  2. AB={3}A\cap B = \{3\}.
  3. A(BC)=A\cap (B\cap C) = \emptyset.
  4. BA={4,5}B\setminus A = \{4, 5\}.
  5. A(BC)=(AB)(AC). A \cap (B\cup C) = (A\cap B) \cup (A \cap C).
Given two sets AA and BB, is it true that AB=BAA \cap B = B \cap A and AB=BAA\cup B = B\cup A?
What about AB=BAA\setminus B = B\setminus A?
Suppose that AA and BB are two finite sets. Is it true that
AB=AB? |A\setminus B| = |A| - |B|?
What about
AB=A+B? |A\cup B| = |A| + |B|?
Seriously, both formulas are wrong. Can you come up with the correct version of the formula for AB|A \cup B|?
Use your correct formula to find a formula for
ABC |A\cup B \cup C|
viewing ABA\cup B as the first set and CC as the second set. Here you need the formula
(AB)C=(AC)(BC). (A\cup B)\cap C = (A\cap C) \cup (B\cap C).
Why is this formula true? Finally, explain why
C(AB)=(CA)(CB). C \setminus (A\cap B) = (C\setminus A) \cup (C\setminus B).
Hint
If you are attacking the last part of this exercise using Exercise UNDEFINED: logictt , you may find it useful to notice that two sets S1,S2S_1, S_2 are equal i.e, S1=S2S_1 = S_2 if and only if
xS1    xS2. x\in S_1 \iff x\in S_2.
Also,
xS1S2    xS1xS2xS1S2    xS1xS2xS1S2    xS1x∉S2x∉S1    ¬(xS1).\begin{aligned} x &\in S_1 \cup S_2 \iff x\in S_1 \lor x\in S_2\\ x &\in S_1 \cap S_2 \iff x\in S_1 \land x\in S_2\\ x &\in S_1 \setminus S_2 \iff x\in S_1 \land x\not\in S_2\\ x &\not\in S_1 \iff \neg (x\in S_1). \end{aligned}
There is one more operation called the symmetric difference between two sets AA and BB. It is denoted AΔBA\, \Delta\, B. Experiment in the python window below to find out exactly what it does. Is it true that AΔB=BΔAA\, \Delta\, B = B\, \Delta\, A?
The following is an excerpt from the infamous Beredskabsprøve Datalogi.
Let XX and YY denote sets. Which of the following are true?
XX=XX \cup X = X
XX=XX\cap X = X
XX=XX\setminus X = X
XXXX\subseteq X\cap X
X\emptyset \subseteq X
For some sets XX and YY we can have
XY=XY. X\cap Y = X\cup Y.

1.6.6 Pairs, triples and tuples

Oftentimes we want to consider more than one variable as input to a predicate. It is convenient to group the variables into one object consisting of the variables. This is done using tuples.
Given two sets AA and BB, we combine two elements aAa\in A and bBb\in B into a pair (a,b)(a, b), which is an element of the Cartesian product
A×B={(a,b)aA,bB}. A \times B = \{(a, b) \mid a\in A, b\in B\}.
of AA and BB. This is a new set built from AA and BB.
If A={1,2}A = \{1, 2\} and B={1,2,3}B = \{1, 2, 3\}, then
A×B={(1,1),(1,2),(1,3),(2,1),(2,2),(2,3)}. A\times B = \{(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)\}.
Consider two pairs (a,b)(a, b) and (c,d)(c, d) each from in A×BA\times B. When is (a,b)=(c,d)(a, b) = (c, d)?
Python
The Cartesian product can be computed in python as shown below.
There is no need to restrict ourselves to pairs. We might as well consider triples A×B×CA\times B\times C i.e., the set of all (a,b,c)(a, b, c), where AA, BB and CC are sets, or for that matter general tuples
(a1,a2,,an)A1×A2××An(1.13) (a_1, a_2, \dots, a_n)\in A_1\times A_2\times \cdots \times A_n \tag{1.13}
of any length nNn\in \mathbb{N}, where a1A1,a2A2,,anAna_1\in A_1, a_2\in A_2, \dots, a_n\in A_n. Based on the above example with tuples we have,
{0}×{1,2}×{1,2,3}={(0,1,1),(0,1,2),(0,1,3),(0,2,1),(0,2,2),(0,2,3)}.\begin{aligned} &\{0\}\times\{1, 2\}\times \{1, 2, 3\} = \\ &\{(0, 1, 1), (0, 1, 2), (0, 1, 3), (0, 2, 1), (0, 2, 2), (0, 2, 3)\}. \end{aligned}
You may check this using the python snippet below.
For a given set AA and nNn\in \mathbb{N} we define the nn-fold cartesian product of AA as
An=A×A××An times. A^n = \underbrace{A\times A\times \cdots \times A}_{n\text{ times}}.
Formally R2\mathbb{R}^2 is the set of pairs (a,b)(a, b), where a,bRa, b\in \mathbb{R}. Is there a natural way of drawing elements in R2\mathbb{R}^2?
Let AA and BB be two sets. Is A×B=B×AA\times B = B \times A?
Let XX be any set. What is ×X\emptyset \times X?
Let A,B,CA, B, C and DD be four sets. Is
(A×B)(C×D)=(AC)×(BD)? (A\times B)\cap (C\times D) = (A\cap C)\times (B\cap D)?
Is
(A×B)(C×D)=(AC)×(BD)? (A\times B)\setminus (C\times D) = (A\setminus C)\times (B\setminus D)?
See Exercise 1.68
Use python to solve Exercise 1.67 by playing with (and extending) the code below.
.
Use python to solve Exercise 1.67
Let AA and BB be two sets. Is A×B=B×AA\times B = B \times A?
Let XX be any set. What is ×X\emptyset \times X?
Let A,B,CA, B, C and DD be four sets. Is
(A×B)(C×D)=(AC)×(BD)? (A\times B)\cap (C\times D) = (A\cap C)\times (B\cap D)?
Is
(A×B)(C×D)=(AC)×(BD)? (A\times B)\setminus (C\times D) = (A\setminus C)\times (B\setminus D)?
See Exercise 1.68
Use python to solve Exercise 1.67 by playing with (and extending) the code below.
.
by playing with (and extending) the code below.

1.7 Ordering numbers

Let us be a little rigorous and introduce the (usual) ordering on our numbers with addition and multiplication using almost full blown mathematical formalities. The natural order << on the natural numbers N\mathbb{N} is
1<2<3< 1 < 2 < 3 < \cdots
For the numbers Q\mathbb{Q} and R\mathbb{R} it is less obvious how to define an order. Mathematical simplicity comes to the rescue here. It is enough to define what (the) positive numbers are! We want (the) positive numbers to satisfy the conditions below.
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
Notice that we only use arithmetic operations to define orders on numbers in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. This is also how computers compare numbers algorithmically. Also if A=ZA = \mathbb{Z}, putting A+=NA_+ = \mathbb{N} makes all of the conditions in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
hold. If you are given an integer, it is 00, positive or negative. This is the content of (ⅰ) in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. Also given two natural numbers, their product and sum are also natural numbers. This is the content of (ⅱ) in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
.
Suppose that a,x,yAa, x, y\in A, where AA is a set of numbers and << given by a subset of positive numbers A+A_+ as in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. Prove that
  1. (x<y)(y<z)    x<z(x < y) \land (y < z) \implies x < z
  2. (a>0)(x<y)    ax<ay(a > 0) \land (x < y) \implies a x < a y
  3. (a<0)(x<y)    ay<ax(a < 0) \land (x < y) \implies a y < a x

1.7.1 Ordering Z\mathbb{Z}

As we saw in Remark 1.70
Notice that we only use arithmetic operations to define orders on numbers in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. This is also how computers compare numbers algorithmically. Also if A=ZA = \mathbb{Z}, putting A+=NA_+ = \mathbb{N} makes all of the conditions in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
hold. If you are given an integer, it is 00, positive or negative. This is the content of (ⅰ) in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. Also given two natural numbers, their product and sum are also natural numbers. This is the content of (ⅱ) in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
.
, the natural order on Z\mathbb{Z} is defined by Z+=N\mathbb{Z}_+ = \mathbb{N}, so that x<yx < y if yxNy-x\in \mathbb{N} for x,yZx, y\in \mathbb{Z}. This completely agrees with our preconception that
<3<2<1<0<1<2<(1.14) \cdots < -3 < -2 < -1 < 0 < 1 < 2 < \cdots \tag{1.14}
To be precise, writing <3<2<1<0<1<2<\cdots < -3 < -2 < -1 < 0 < 1 < 2 < \cdots is nonsense, since << is only defined for two integers.
How is one supposed to interpret 0<1<20 < 1 < 2 for example? Go ahead and formulate (1.14)
<3<2<1<0<1<2<(1.14) \cdots < -3 < -2 < -1 < 0 < 1 < 2 < \cdots \tag{1.14}
correctly comparing only two integers at a time. How does Python/Sage interpret 3<2<1<0<1<2-3 < -2 < -1< 0 < 1 < 2? Find out using the Sage snippet below.
What about 1<5>3<41 < 5 > 3 < 4? What about 0<1>20 < 1 > 2?
Assume that x,y,zZx, y, z\in \mathbb{Z} and that xyx \leq y. Then drag and drop the elements from the left to the right below to explain that x+zy+zx + z \leq y + z.
By assumption xyx\leq y.
This means that zx+yNz - x + y\in \mathbb{N}
This means that yxNy - x\in \mathbb{N}
To show that x+zy+zx + z \leq y + z, we need to show that (y+z)(x+z)N(y + z) - (x + z) \in \mathbb{N}.
But (y+z)(x+z)=y+zx+z(y + z) - (x + z) = y + z - x + z. Therefore,
But (y+z)(x+z)=y+zxz=yx(y + z) - (x + z) = y + z - x - z = y - x. Therefore,
(y+z)(x+z)N(y + z) - (x + z)\in \mathbb{N}, since
yxNy - x \in \mathbb{N}

1.7.2 Ordering Q\mathbb{Q}

We define the positive rational numbers as
Q+={mnQ|m>0}={1,12,13,23,14,34,}. \mathbb{Q}_+ = \left\{\frac{m}{n} \in \mathbb{Q} \middle| m > 0\right\} = \left\{1, \frac{1}{2}, \frac{1}{3}, \frac{2}{3}, \frac{1}{4}, \frac{3}{4}, \dots \right\}.
One can check that Q+\mathbb{Q}_+ satisfies the conditions in Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
. So formally we get
For ab,   cdQ\cfrac{a}{b},\,\,\, \cfrac{c}{d}\in \mathbb{Q},
ab<cd    ad<bc(in Z). \frac{a}{b}\, < \frac{c}{d}\qquad \iff\qquad a d < b c\qquad (\text{in }\mathbb{Z}).
We must check when
cdab=bcadbdQ+. \frac{c}{d} - \frac{a}{b} = \frac{b c - a d}{b d} \in \mathbb{Q}_+.
This happens precisely when the numerator bcadNb c - a d\in \mathbb{N} or bcad>0b c - a d > 0. Therefore the condition in the proposition is satsified.
Use proof by contradiction (see section 1.5.8 ) to show precisely that there does not exist a smallest positive rational number.
Suppose that a/bQa/b\in \mathbb{Q}.
  1. Is it true in general that
    aba+1b+1? \frac{a}{b} \leq \frac{a+1}{b+1}?
  2. Is it true in some cases?
  3. Suppose that nNn\in \mathbb{N}. Prove that
    1a+nb+n=bab+n. 1 - \frac{a + n}{b+n} = \frac{b-a}{b+n}.
  4. What happens to the rational number
    a+nb+n \frac{a+n}{b+n}
    when nNn\in \mathbb{N} grows and becomes very big?
Using Definition 1.74
For ab,   cdQ\cfrac{a}{b},\,\,\, \cfrac{c}{d}\in \mathbb{Q},
ab<cd    ad<bc(in Z). \frac{a}{b}\, < \frac{c}{d}\qquad \iff\qquad a d < b c\qquad (\text{in }\mathbb{Z}).
, you can check that 23<57\frac{2}{3} < \frac{5}{7}, since
27<35. 2\cdot 7 < 3 \cdot 5.
An easy, but surprising, way of finding a rational number strictly between these two is adding their numerators and denominators:
23<2+53+7<57. \frac{2}{3} < \frac{2 + 5}{3 + 7} < \frac{5}{7}.
We wil try to explain the first inequality in mathematical general terms going through a rather formal proof consisting of five steps. These steps are given in the quiz below. Your task is to drag from the left and drop them to the right in an order, so that the proof makes sense.
After that you are supposed, on your own, to write down a precise proof of the second inequality.
Order the arguments below so that they constitute a coherent explanation of the statement that if
ab<cd, \frac{a}{b} < \frac{c}{d},
then
ab<a+cb+d \frac{a}{b} < \frac{a + c}{b + d}
By definition this means that ad<bca d < b c.
We are assuming that ab<cd\frac{a}{b} < \frac{c}{d}.
For integers x,y,zx, y, z we know that the rule x(y+z)=xy+xz x ( y + z) = x y + x z holds. Therefore
we need to show that ab+cd<ba+bca b + c d < b a + b c.
Since ab=baa b = b a and ab+ad<ab+bca b + a d < a b + b c is a consequence of ad<bca d < b c, we are done if we know this is true.
However, this is a consequence of our assumption ab<cd\frac{a}{b} < \frac{c}{d}.
To show that ab<a+cb+d, \frac{a}{b} < \frac{a+c}{b + d}, we need to argue that a(b+d)<b(a+c)a (b + d) < b (a + c).
we need to show that ab+ad<ba+bca b + a d < b a + b c.
Similarly to the quiz above, assume that
ab<cd. \frac{a}{b} < \frac{c}{d}.
Write down a precise argument showing that
a+cb+d<cd. \frac{a + c}{b + d} < \frac{c}{d}.
On Twitter, Raman Gupta posted the note below
\begin{excluderag}
\end{excluderag}
For a natural number mNm\in \mathbb{N},
m!=m(m1)(m2)21. m! = m (m-1) (m-2)\cdot \dots \cdot 2\cdot 1.
For example, 3!=63! = 6 and 5!=1205! = 120. What is the answer for the question in the note?
Experiment a bit with Sage: define a function f(n)f(n), which computes
2n!2n! 2^{n!} - 2^n!
Then look at
f(1),f(2),f(3),f(4),f(5), f(1), f(2), f(3), f(4), f(5), \dots
The exercise below shows that our trick for finding rational numbers in between two given rational numbers can be made into a machine for generating all positive rational numbers!
Can you spot the system in the fractions in the diagram below?
Once you see the system, extend the diagram with the next level downwards. Is every positive fraction present in this diagram if one keeps adding levels?
Suppose that
pq<rs \frac{p}{q} < \frac{r}{s}
and qrsp=1q r - s p = 1. Then for
pq<p+rq+s<rs, \frac{p}{q} < \frac{p+r}{q+s} < \frac{r}{s},
we have q(p+r)(q+s)p=1q (p+r) - (q+s) p = 1 and (q+s)r(p+r)s=1(q+s) r - (p + r) s = 1. If ab\frac{a}{b} is a positive fraction, such that
pq<ab<rs, \frac{p}{q} < \frac{a}{b} < \frac{r}{s},
show that
a+b=(r+s)(qabp)+(p+q)(bras)p+q+r+s. a + b = (r+s)(q a - b p)+(p+q)(b r - a s)\geq p+q+r+s.

1.7.3 Ordering R\mathbb{R}

For the real numbers we define the positive numbers as
R+={xRx=d0.d1d2,d00,x0}. \mathbb{R}_+ = \{x\in \mathbb{R} \mid x = d_0.d_1 d_2 \dots, d_0 \geq 0, x \neq 0\}.
Even though we have not precisely defined addition and multiplication of the real numbers, we claim that this definition of R+\mathbb{R}_+ satisfies the conditions of Definition 1.69
A subset A+A_+ of positive numbers in a set AA of numbers must satisfy
  1. For every xAx\in A one and only one of the following conditions must hold
    1. xA+-x\in A_+
    2. x=0x = 0
    3. xA+x\in A_+
  2. If x,yA+x, y\in A_+, then x+yA+x + y\in A_+ and xyA+x y\in A_+.
For a set A+A_+ of positive numbers in AA, we define
x<y    yxA+ x < y \iff y - x\in A_+
and
xy    (x=y)(x<y). x\leq y \iff (x = y) \lor (x < y).
We will write x>0x > 0 if xA+x\in A_+ and x<0x < 0 if xA+-x\in A_+.
.
One may prove that for every x,yR+x, y\in \mathbb{R}_+, there exists NNN\in \mathbb{N}, such that Nx>yN x > y. This is the archimedean property of the real numbers.
Given two distinct real numbers ξ1<ξ2\xi_1 < \xi_2. Prove that there exists a rational number rQr\in \mathbb{Q}, such that
ξ1<r<ξ2. \xi_1 < r < \xi_2.
One other crucial property is the completeness of R\mathbb{R}. It says that a non-empty subset SRS\subseteq \mathbb{R} with an upper bound BB i.e., xS:xB\forall x\in S: x\leq B, always has a smallest upper bound. The rational numbers do not share this property, since for example
S={xQx2<2} S = \{x\in \mathbb{Q} \mid x^2 < 2\}
does not have a smallest upper bound inside Q\mathbb{Q}.

1.8 Proof by induction

A precocious Gauss See the article Gauss's Day of Reckoning for some history of this anecdote. proved the formula
1+2++n=n(n+1)2(1.15) 1 + 2 + \cdots + n = \frac{n(n+1)}{2} \tag{1.15}
at the age of seven displaying remarkable ingenuity for his age. Lesser mortals usually use induction to prove this formula. Gauss was asked along with his classmates to compute the sum of all natural numbers 1,2,,1001, 2, \dots, 100. Using his formula he quickly came up with the correct answer 50505050. His classmates had to work for the entire lesson.
Suppose that the formula in (1.15)
1+2++n=n(n+1)2(1.15) 1 + 2 + \cdots + n = \frac{n(n+1)}{2} \tag{1.15}
is viewed as a proposition p(n)p(n). To prove the formula we need to prove it for all natural numbers (you can easily see that p(1)p(1) and p(2)p(2) are true) i.e., we need to prove
nN:p(n). \forall n\in \mathbb{N}: p(n).
An induction proof is a way of proving this statement by showing two things:
  1. p(1)p(1)
  2. nN:p(n)    p(n+1)\forall n\in \mathbb{N}: p(n)\implies p(n+1)
These two statements ensure that p(1)    p(2)p(1) \implies p(2). Therefore p(2)p(2) must be true, since we assumed p(1)p(1) true from the beginning. Similarly p(2)    p(3)p(2)\implies p(3) ensures that p(3)p(3) is true and so on. In fact we have proved p(n)p(n) for every nNn\in \mathbb{N} using this technique. One can prove this using proof by contradiction and that every non-empty subset of N\mathbb{N} has a first element. In general if SS is a subset of set with an order \leq, then sSs\in S is called a first element if
xS:sx. \forall x\in S: s \leq x.
A crucial rule (or axiom) is that every non-empty subset of N\mathbb{N} has a first element! Notice that this is false for Z\mathbb{Z}.
Suppose that p(n)p(n) are infinitely many propositions given by nNn\in \mathbb{N}. Then
nN:p(n) \forall n\in \mathbb{N}: p(n)
is true if
  1. p(1)p(1) is true.
  2. (nN:p(n)    p(n+1))\left(\forall n\in \mathbb{N}: p(n)\implies p(n+1)\right) is true.
Suppose by contradiction that there exists nNn\in \mathbb{N}, such that p(n)p(n) is false. Then the subset
S={nN¬p(n)}N S = \{n\in \mathbb{N} \mid \neg p(n)\}\subseteq \mathbb{N}
is non-empty. Therefore it has a first element n0Sn_0\in S. Here n0>1n_0 > 1, since p(1)p(1) is assumed to be true. So we know that p(n01)p(n_0-1) is true and that p(n01)    p(n0)p(n_0-1)\implies p(n_0) is true. But the latter implication is a contradiction, since true implies false is false.
Let us see how an induction proof plays out in the above example with the statement p(n)p(n) that
1+2++n=n(n+1)2.(1.16) 1 + 2 + \cdots + n = \frac{n(n+1)}{2}. \tag{1.16}
Clearly p(1)p(1) is true. We need to prove p(n)    p(n+1)p(n)\implies p(n+1), so we assume that p(n)p(n) holds i.e., that (1.16)
1+2++n=n(n+1)2.(1.16) 1 + 2 + \cdots + n = \frac{n(n+1)}{2}. \tag{1.16}
is true. Then we may add n+1n+1 to both sides of (1.16)
1+2++n=n(n+1)2.(1.16) 1 + 2 + \cdots + n = \frac{n(n+1)}{2}. \tag{1.16}
to get
1+2++n+(n+1)=n(n+1)2+(n+1). 1 + 2 + \cdots + n + (n+1) = \frac{n(n+1)}{2} + (n+1).
Here the right hand side can be rewritten as
n(n+1)+2(n+1)2=(n+1)(n+2)2, \frac{n(n+1) + 2(n+1)}{2} = \frac{(n+1)(n+2)}{2},
which is exactly what we want. This is the conjectured formula for the sum of the numbers 1,2,,n,n+11, 2, \dots, n, n+1. Therefore we have proved that p(n)    p(n+1)p(n)\implies p(n+1) and the induction proof is complete.
For a real number r1r\neq 1, the extremely useful formula
1+r++rn=1rn+11r(1.17) 1 + r + \cdots + r^n = \frac{1 - r^{n+1}}{1-r} \tag{1.17}
holds. Let us prove this formula by induction. For n=1n=1 this amounts to the identity
1+r=1r21r, 1 + r = \frac{1-r^2}{1-r},
which is true since 1r2=(1+r)(1r)1-r^2 = (1+r)(1-r). We let p(n)p(n) denote the identity in (1.17)
1+r++rn=1rn+11r(1.17) 1 + r + \cdots + r^n = \frac{1 - r^{n+1}}{1-r} \tag{1.17}
. We have seen that p(1)p(1) is true. The induction step consists in proving p(n)    p(n+1)p(n)\implies p(n+1). We can prove this by adding rn+1r^{n+1} to the right hand side in (1.17)
1+r++rn=1rn+11r(1.17) 1 + r + \cdots + r^n = \frac{1 - r^{n+1}}{1-r} \tag{1.17}
:
1rn+11r+rn+1=1rn+1+(1r)rn+11r=1rn+21r.(1.18) \frac{1 - r^{n+1}}{1-r} + r^{n+1} = \frac{1 - r^{n+1} + (1-r) r^{n+1}}{1-r} = \frac{1 - r^{n+2}}{1-r}. \tag{1.18}
Real life application
In order to pay for a house you borrow PP DKK at an interest of rr per year. You want to pay off your debt over NN years by paying a fixed amount each year. How much is the fixed yearly amount you need to pay?
Let us analyze the setup: suppose that the fixed yearly amount is YY. We will find an equation giving us YY in terms of P,NP, N and rr. Put q=1+rq = 1+ r.
After one year you owe
qPY. q P - Y.
After two years you owe
q(qPY)Y. q(q P - Y) - Y.
After three years you owe
q(q(qPY)Y)Y. q ( q ( q P - Y) - Y) - Y.
In general after nn years you owe
qnPY(1+q++qn1). q^n P - Y (1 + q + \cdots + q^{n-1}).
Since we want to be debt free after NN years, the yearly payment will have to satisfy
qNP=Y(1+q++qN1). q^N P = Y ( 1 + q + \cdots + q^{N-1}).
By the formula (1.17)
1+r++rn=1rn+11r(1.17) 1 + r + \cdots + r^n = \frac{1 - r^{n+1}}{1-r} \tag{1.17}
, we get
qNP=Y1qN1q. q^N P = Y \frac{1-q^N}{1-q}.
Here YY can be isolated giving the formula
Y=rP1(11+r)N. Y = \frac{r P}{1 - \left(\frac{1}{1+r}\right)^N}.
With the current (August 2024) interest rate around four percent, you pay a fixed monthly amount of around 4770 DKK (down from 5420 DKK in 2023, when the interest rate was five percent) for borrowing one million DKK over 3030 years.
Verify the computation (induction step) in (1.18)
1rn+11r+rn+1=1rn+1+(1r)rn+11r=1rn+21r.(1.18) \frac{1 - r^{n+1}}{1-r} + r^{n+1} = \frac{1 - r^{n+1} + (1-r) r^{n+1}}{1-r} = \frac{1 - r^{n+2}}{1-r}. \tag{1.18}
i.e., explain the operations used to go from the left to the right of the two equalities.
Locate the mistake in the following fake induction proof of the curious fact that 2n=22^n = 2 for every nNn\in \mathbb{N}.
Let p(n)p(n) be the proposition 2n=22^n = 2. Then p(1)p(1) is true.
We wish to prove that p(n)    p(n+1)p(n) \implies p(n+1) assuming that p(1),,p(n)p(1), \dots, p(n) are true:
2n+1=2n2=2n2n2n1=222  (by p(n) and p(n1))=2.\begin{aligned} 2^{n+1} &= 2^n \cdot 2\\ &= 2^n \cdot \frac{2^n}{2^{n-1}}\\ &= 2 \cdot \frac{2}{2}\,\,\text{(by }p(n)\text{ and }p(n-1)\text{)}\\ &= 2. \end{aligned}
This shows that p(n)    p(n+1)p(n) \implies p(n+1) and therefore that 2n=22^n = 2 for every nN{0}n\in \mathbb{N}\setminus\{0\}.
Prove by induction that the sum of the first nn odd numbers is given by the formula
1+3++(2n1)=n2, 1 + 3 + \cdots + (2 n - 1) = n^2,
i.e., for n=5n=5 we have
1+3+5+7+9=25. 1 + 3 + 5 + 7 + 9 = 25.
Prove by induction that
12+22+32++n2=n(n+1)(2n+1)6. 1^2 + 2^2 + 3^2 + \cdots + n^2 = \frac{n(n+1)(2n + 1)}{6}.
Prove using the idea of induction that
2n<n! 2^n < n!
for n4n\geq 4.
The last exercise related to induction concerns the famous pigeonhole principle. The statement itself looks innocent, well almost ridiculous, but it is very powerful. Even the go-to website mathoverflow for research mathematicians has a quite nice thread about this.
Prove the following by induction on mm: if nn items are put into mm containers and n>mn > m, then at least one container must contain more than one item.

1.9 The concept of a function

A function is a crucial concept in mathematics. In Sage (actually python here) a simple function can be programmed like
The code above seems to take a number and returns the number plus one. This (f) is in fact a function taking as input a number and returning as output the number plus one. Notice that we do not even know which numbers we are talking about here. In mathematics we need to have a more precise notion of a function.
The above python function could more formally be denoted as f:ZZf: \mathbb{Z}\rightarrow \mathbb{Z} with f(n)=n+1f(n) = n+1 if we are dealing with the integers, but we cannot tell from the code.
Well, to be fair ...
To be completely fair, it is possible from Python 3.5 to add type annotations to functions, so that we could write

def f(n: int) -> int: return(n+1)

in the Python code to state that the function should take values in the integers and return integers.
The precise mathematical definition of a function in terms of sets is the following. A function f:STf: S\rightarrow T is a subset fS×Tf\subseteq S\times T, such that (s,t1)f(s,t2)f    t1=t2(s, t_1)\in f \land (s, t_2)\in f \implies t_1 = t_2. In words it states that a function f:STf: S\rightarrow T is a subset ff of S×TS\times T, containing pairs having only one second coordinate for every first coordinate.
The everyday working definition of a function is more intuitive: a machine taking input from some set SS and giving output in some set TT. The uniqueness of the output is encoded in the mathematical definition of a function.
Mathematically a function ff takes values from a set SS and returns values in a set TT. In details, it is denoted f:STf: S\rightarrow T and the value associated with sSs\in S is denoted f(s)Tf(s)\in T. Here SS is called the domain of ff and TT is called the codomain of ff. Less, formally SS is called the input set and TT the output set for ff.
Please notice that a function is a very, very general concept. It is not just something that you draw as a graph on a piece of paper. Of course, you can draw a function f:RRf:\mathbb{R}\rightarrow \mathbb{R} like f(x)=x2f(x) = x^2:
Generally, a function f:STf: S\rightarrow T is given by a machine, formula or algorithm that computes f(x)Tf(x)\in T for every xSx\in S. Nothing more, nothing less. It really has nothing to do with a graph (even though graphs can sometimes be useful for visualizing certain functions like f(x)=x2f(x) = x^2).
Good examples of functions can be found in the cryptographic hash functions. They are examples of complicated functions f:STf:S \rightarrow T, where SS is infinite and TT finite. Here SS could be data like plain text files and TT could be a 256256 bit number. This is the setup for the widely used sha-256 cryptographic hash function. The whole point of a cryptographic hash function is that it must be humanly impossible to compute yy with f(y)=f(x)f(y) = f(x) given f(x)f(x) A pair xyx\neq y with f(x)=f(y)f(x) = f(y) is called a collision . In fact, sha-256 is used in the Bitcoin block chain. The precise definition of sha-256 can be found in FIPS PUB 180-4 approved by the Secretary of Commerce.
Other interesting functions output a bounded size digital footprint (checksum) of a file (like md5). This is very useful for checking data integrity of downloads over the internet. The md5 hash is a 128128 bit number.
Instead of listing 256256 or 128128 bits for the hash value one uses hexadecimal notation with digits in 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , a, b, c, d, e, f. A pair of hexadecimal digits then represents a byte or 88 bits. Output from sha-256 and md5 consist of 6464 and 3232 hexadecimal digits respectively. You are welcome to experiment with these two hash functions in the Sage window below.
What is the sha-256 hash of your name? Change a few letters and recompute. Do you see any system? What about the md5 hash function? Can you find two different strings with the same md5 hash using your computer?
I have not answered the last question myself, but I am told that it is possible to find a collision for md5 using a garden variety home computer. Browsing the internet, it seems that the two strings s1s_1 and s2s_2 given in hexadecimal notation This notation represents a sequence of bytes given by pairs of hexadecimal digits by

d131dd02c5e6eec4693d9a0698aff95c2fcab58712467eab4004583eb8fb7f89 
55ad340609f4b30283e488832571415a085125e8f7cdc99fd91dbdf280373c5b 
d8823e3156348f5bae6dacd436c919c6dd53e2b487da03fd02396306d248cda0 
e99f33420f577ee8ce54b67080a80d1ec69821bcb6a8839396f9652b6ff72a70

and

d131dd02c5e6eec4693d9a0698aff95c2fcab50712467eab4004583eb8fb7f89 
55ad340609f4b30283e4888325f1415a085125e8f7cdc99fd91dbd7280373c5b 
d8823e3156348f5bae6dacd436c919c6dd53e23487da03fd02396306d248cda0 
e99f33420f577ee8ce54b67080280d1ec69821bcb6a8839396f965ab6ff72a70 

give a collision for md5. Verify that s1s2s_1\neq s_2 and that they give the same md5 hash. If you find a collision for sha-256 you will become world famous.

1.9.1 When are two functions the same?

Suppose that f(x)=x+1f(x) = x + 1. This way of defining a function is a bit sploppy. The domain and codomain is not defined. The correct way of defining a function also includes defining its domain and codomain as in Definition 1.90
Mathematically a function ff takes values from a set SS and returns values in a set TT. In details, it is denoted f:STf: S\rightarrow T and the value associated with sSs\in S is denoted f(s)Tf(s)\in T. Here SS is called the domain of ff and TT is called the codomain of ff. Less, formally SS is called the input set and TT the output set for ff.
. Two functions f,gf, g are the same when they have the same domain SS and codomain TT and f(x)=g(x)f(x) = g(x) for every xSx\in S.
The functions f1:RRf_1: \mathbb{R} \rightarrow \mathbb{R} and f2:{xRx0}Rf_2: \{x\in \mathbb{R} \mid x\geq 0\}\rightarrow \mathbb{R} given by f1(x)=x2f_1(x) = x^2 and f2(x)=x2f_2(x) = x^2 are not the same! Their domains are different.

1.9.2 Notations for defining a function

If f:STf: S\rightarrow T is a function and SS is a finite set, then you can define ff using a simple table. This is best illustrated using an example. Suppose that S={1,2,3},T=RS = \{1, 2, 3\}, T = \mathbb{R} and
f(1)=2f(2)=πf(3)=1.\begin{aligned} f(1) &= \sqrt{2}\\ f(2) &= \pi\\ f(3) &= -1. \end{aligned}
Then ff is expressed in table form as
x123f(x)2π1 \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f(x) & \sqrt{2} & \pi & -1 \end{array}
Very often the bracket (or Tuborg in Danish) notation is used. It is similar to if-then-else statements in programming:
f(x)={0if x0x2if x>0(1.19) f(x) = \begin{cases} 0 &\text{if } x\leq 0\\ x^2 &\text{if } x > 0 \end{cases} \tag{1.19}
defines the function f:RRf:\mathbb{R} \rightarrow \mathbb{R} that outputs 00 if the input x0x\leq 0 and x2x^2 if x>0x>0. In python we may express this as
What is f(17)f(-17) and f(17)f(17) for the function defined in (1.19)
f(x)={0if x0x2if x>0(1.19) f(x) = \begin{cases} 0 &\text{if } x\leq 0\\ x^2 &\text{if } x > 0 \end{cases} \tag{1.19}
. Draw the graph of ff. Come up with a function f:STf:S\rightarrow T, where it does not make sense to draw a graph.

1.9.3 Composition of functions

Given two functions f:STf: S\rightarrow T and g:UVg: U\rightarrow V, where VSV\subseteq S, we define a new function fg:UTf\circ g: U \rightarrow T by
(fg)(u)=f(g(u)). (f\circ g)(u) = f(g(u)).
This notion calls for some reflection. We have a total of four sets in this definition: U,V,SU, V, S and TT and, not to forget, the condition that VSV\subseteq S. If this last condition was not satisfied it would be meaningless to apply the function ff to g(u)g(u). I hope the diagram below helps the understanding.
The concept of a function is powerful and underlies functional programming in computer science: every computation can be realized as applying a composition of functions to an argument. This is exemplified in the computer language Haskell.
Suppose that
U={1,2,3},S={1,2,3,4}andT={7,8,9} U = \{1, 2, 3\},\qquad S = \{1, 2, 3, 4\}\qquad\text{and}\qquad T = \{7, 8, 9\}
and that g:USg: U \rightarrow S and f:STf: S\rightarrow T are given by the tables
x123g(x)134andx1234f(x)7897 \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline g(x) & 1 & 3 & 4 \end{array}\qquad\text{and}\qquad \begin{array}{c|ccccccc} x & 1 & 2 & 3 & 4\\ \hline f(x) & 7 & 8 & 9 & 7 \end{array}
Compute the table for (fg):UT(f\circ g): U\rightarrow T. Show that fgf\circ g is not injective. Adjust the table for ff so that fgf\circ g becomes bijective.
Consider f:RR2f: \mathbb{R}\rightarrow \mathbb{R}^2 and g:R2Rg: \mathbb{R}^2\rightarrow \mathbb{R} given by
f(t)=(t2,t3)g((x,y))=cos(xy)+xsin(x+y).\begin{aligned} f(t) &= (t^2, t^3)\\ g((x, y)) &= \cos(x y) + x \sin(x + y). \end{aligned}
What is (gf)(t)(g\circ f)(t) as a function from R\mathbb{R} to R\mathbb{R} in terms of tt?

1.9.4 Functions from and into products

Suppose that
B=A1×A2××An B = A_1 \times A_2 \times \cdots \times A_n
as in (1.13)
(a1,a2,,an)A1×A2××An(1.13) (a_1, a_2, \dots, a_n)\in A_1\times A_2\times \cdots \times A_n \tag{1.13}
. Then the function πi:BAi\pi_i:B\rightarrow A_i given by
πi(a1,,ai,,an)=ai \pi_i(a_1, \dots, a_i, \dots, a_n) = a_i
is called the projection on the ii-th coordinate.
If f:ABf: A\rightarrow B is a function, then
f(a)=(f1(a),,fn(a)), f(a) = (f_1(a), \dots, f_n(a)),
where fi=πiff_i = \pi_i\circ f.
Suppose that B=R×R=R2B = \mathbb{R}\times \mathbb{R} = \mathbb{R}^2 and (x,y)B(x, y) \in B. Then
π1((1,2))=1π2((1,2))=2.\begin{aligned} \pi_1((1, 2)) &= 1\\ \pi_2((1, 2)) &= 2. \end{aligned}
Now suppose that A=R3A = \mathbb{R}^3 and that f:ABf: A\rightarrow B is given by
f((x,y,z))=(x2+y,xy,z3). f((x, y, z)) = (x^2 + y, x y , z^3).
Then
f1((1,2,3))=3f2((1,2,3))=2f3((1,2,3))=27.\begin{aligned} f_1((1, 2, 3)) &= 3\\ f_2((1, 2, 3)) &= 2\\ f_3((1, 2, 3)) &= 27. \end{aligned}

1.9.5 Injective and surjective functions

We now define three very important notions related to functions.
Let f:STf: S\rightarrow T be a function. Then ff is called
  1. injective, if f(x)=f(y)    x=yf(x) = f(y) \implies x = y for every x,ySx, y\in S.
  2. surjective, if for every yTy\in T, there exists xSx\in S, such that f(x)=yf(x) = y.
  3. bijective, if it is both injective and surjective.
Is a cryptographic hash-function as defined in Example 1.92
Good examples of functions can be found in the cryptographic hash functions. They are examples of complicated functions f:STf:S \rightarrow T, where SS is infinite and TT finite. Here SS could be data like plain text files and TT could be a 256256 bit number. This is the setup for the widely used sha-256 cryptographic hash function. The whole point of a cryptographic hash function is that it must be humanly impossible to compute yy with f(y)=f(x)f(y) = f(x) given f(x)f(x) A pair xyx\neq y with f(x)=f(y)f(x) = f(y) is called a collision . In fact, sha-256 is used in the Bitcoin block chain. The precise definition of sha-256 can be found in FIPS PUB 180-4 approved by the Secretary of Commerce.
Other interesting functions output a bounded size digital footprint (checksum) of a file (like md5). This is very useful for checking data integrity of downloads over the internet. The md5 hash is a 128128 bit number.
Instead of listing 256256 or 128128 bits for the hash value one uses hexadecimal notation with digits in 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , a, b, c, d, e, f. A pair of hexadecimal digits then represents a byte or 88 bits. Output from sha-256 and md5 consist of 6464 and 3232 hexadecimal digits respectively. You are welcome to experiment with these two hash functions in the Sage window below.
injective?
Suppose that
S={1,2,3}andT={1,2,3,4} S = \{1, 2, 3\}\qquad\text{and}\qquad T = \{1, 2, 3, 4\}
and that the function f:STf: S\rightarrow T is defined by the table
x123f(x)124 \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f(x) & 1 & 2 & 4 \end{array}
Is ff injective? Is it surjective? Is it possible to adjust the table so that ff becomes injective? Is it possible to adjust the table so that ff becomes surjective?
Consider the function f:STf:S \rightarrow T given by
f(x)=x2, f(x) = x^2,
where S=T=RS = T = \mathbb{R}. Is ff injective? Is ff surjective? Suggest how to change SS and TT so that f:STf:S\rightarrow T becomes bijective.
Consider the function f:ZZf:\mathbb{Z} \rightarrow \mathbb{Z} given by
f(x)=x+1 f(x) = x + 1
Show that ff is bijective.
Write down precisely how the truth table for p    qp\implies q may be expressed in terms of a function f:STf: S\rightarrow T. What are the sets SS and TT in this case?

1.9.6 The inverse function

If f:STf:S\rightarrow T is bijective, then we may define a function g:TSg: T\rightarrow S, so that (fg)(y)=y(f\circ g)(y) = y for every yTy\in T and (gf)(x)(g\circ f)(x) for every xSx\in S. This function is denoted f1f^{-1}.
How do we define f1(y)f^{-1}(y) for yTy\in T? Well, since ff is surjective, we may find xSx\in S so that y=f(x)y = f(x). Now, we simply define
f1(y)=x.(1.20) f^{-1}(y) = x. \tag{1.20}
We cannot have x1x2x_1 \neq x_2 in SS with f(x1)=f(x2)=yf(x_1) = f(x_2) = y, since ff is injective. We only have one choice for xx in (1.20)
f1(y)=x.(1.20) f^{-1}(y) = x. \tag{1.20}
. Therefore (1.20)
f1(y)=x.(1.20) f^{-1}(y) = x. \tag{1.20}
really is a good and sound definition.
Let f:SSf: S\rightarrow S, where S={1,2,3}S = \{1, 2, 3\} be given by the table
x123f(x)312. \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f(x) & 3 & 1 & 2 \end{array}.
Then f1f^{-1}is given by the table
x123f1(x)231. \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f^{-1}(x) & 2 & 3 & 1 \end{array}.
What if the definition of ff in Example 1.107
Let f:SSf: S\rightarrow S, where S={1,2,3}S = \{1, 2, 3\} be given by the table
x123f(x)312. \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f(x) & 3 & 1 & 2 \end{array}.
Then f1f^{-1}is given by the table
x123f1(x)231. \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f^{-1}(x) & 2 & 3 & 1 \end{array}.
is changed to
x123f(x)322. \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3\\ \hline f(x) & 3 & 2 & 2 \end{array}.
Does f1f^{-1} make sense here?
What is the inverse function of f:ZZf:\mathbb{Z}\rightarrow \mathbb{Z} given by f(x)=x+1f(x) = x + 1? What is the inverse function of g:SSg: S \rightarrow S, where g(x)=xg(x) = \sqrt{x} and S={xRx0}S = \{x\in \mathbb{R}\mid x\geq 0\}?

1.9.7 The preimage

Consider a function
f:AB, f: A \rightarrow B,
where AA and BB are sets. If CBC\subseteq B, then the preimage of CC under ff is defined by
f1(C)={xAf(x)C}. f^{-1}(C) = \{x\in A \mid f(x)\in C\}.
Definition 1.110
Consider a function
f:AB, f: A \rightarrow B,
where AA and BB are sets. If CBC\subseteq B, then the preimage of CC under ff is defined by
f1(C)={xAf(x)C}. f^{-1}(C) = \{x\in A \mid f(x)\in C\}.
is short and sweet. Here is a first example of the preimage.
Consider the function f:ABf: A\rightarrow B, where A={1,2,3,4,5}A = \{1, 2, 3, 4, 5\} and B={a,b,c,d}B = \{a, b, c, d\} given by
x12345f(x)abcad \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3 & 4 & 5\\ \hline f(x) & a & b & c & a & d \end{array}
For C={a,c}C = \{a, c\}, f1(C)={1,3,4}f^{-1}(C) = \{1, 3, 4\} as illustrated below.
What is f1(C)f^{-1}(C) when A=R,B=R,f(x)=x25x+6A = \mathbb{R}, B = \mathbb{R}, f(x) = x^2 - 5 x + 6 and C=(,0]C = (-\infty, 0]?
Consider the function f:{1,2,3,4,5}Rf:\{1, 2, 3, 4, 5\}\rightarrow \mathbb{R} given by
x12345f(x)1241π \def\arraystretch{1.5} \begin{array}{c|ccccccc} x & 1 & 2 & 3 & 4 & 5\\ \hline f(x) & 1 & 2 & 4 & -1 & \pi \end{array}
and let C=[3,)C = [3, \infty). What is true about f1(C)f^{-1}(C)?
1f1(C) 1\in f^{-1}(C)
{3,5}f1(C) \{3, 5\}\subseteq f^{-1}(C)
{3,4,5}f1(C) \{3, 4, 5\}\subseteq f^{-1}(C)
f1(RC)f1(C)={1,2,3,4,5}. f^{-1}(\mathbb{R}\setminus C) \cup f^{-1}(C) = \{1, 2, 3, 4, 5\}.

1.9.8 Neural networks

Having defined functions and composition of functions, we can deflate the term (deep) neural network, which is often clouded in magic and mystery.
A neural network is a special case of a function
f:AB,(1.21) f: A\rightarrow B, \tag{1.21}
where ARmA\subseteq \mathbb{R}^m and BRnB\subseteq \mathbb{R}^n. Neural networks are often compositions of many intermediate functions called (hidden) layers.
Recall from Definition 1.99
Suppose that
B=A1×A2××An B = A_1 \times A_2 \times \cdots \times A_n
as in (1.13)
(a1,a2,,an)A1×A2××An(1.13) (a_1, a_2, \dots, a_n)\in A_1\times A_2\times \cdots \times A_n \tag{1.13}
. Then the function πi:BAi\pi_i:B\rightarrow A_i given by
πi(a1,,ai,,an)=ai \pi_i(a_1, \dots, a_i, \dots, a_n) = a_i
is called the projection on the ii-th coordinate.
If f:ABf: A\rightarrow B is a function, then
f(a)=(f1(a),,fn(a)), f(a) = (f_1(a), \dots, f_n(a)),
where fi=πiff_i = \pi_i\circ f.
that a function such as (1.21)
f:AB,(1.21) f: A\rightarrow B, \tag{1.21}
can be written
f(x1,,xm)=(f1(x1,,xm),,fn(x1,,xm)),(1.22) f(x_1, \dots, x_m) = \left( f_1(x_1, \dots, x_m), \dots, f_n(x_1, \dots, x_m)\right), \tag{1.22}
where f1,,fnf_1, \dots, f_n are functions ARA\rightarrow \mathbb{R}. Check out Example 1.100
Suppose that B=R×R=R2B = \mathbb{R}\times \mathbb{R} = \mathbb{R}^2 and (x,y)B(x, y) \in B. Then
π1((1,2))=1π2((1,2))=2.\begin{aligned} \pi_1((1, 2)) &= 1\\ \pi_2((1, 2)) &= 2. \end{aligned}
Now suppose that A=R3A = \mathbb{R}^3 and that f:ABf: A\rightarrow B is given by
f((x,y,z))=(x2+y,xy,z3). f((x, y, z)) = (x^2 + y, x y , z^3).
Then
f1((1,2,3))=3f2((1,2,3))=2f3((1,2,3))=27.\begin{aligned} f_1((1, 2, 3)) &= 3\\ f_2((1, 2, 3)) &= 2\\ f_3((1, 2, 3)) &= 27. \end{aligned}
.
In a neural network the functions f1,f2,,fnf_1, f_2, \dots, f_n are viewed as neurons To be precise, the functions should be viewed as synapses . Depending on their input they either fire or do not fire a signal. Classically this is modelled by the perceptron, which is a function p:RnRp:\mathbb{R}^n\rightarrow \mathbb{R} of the form
p(x1,,xn)={1if w1x1++wnxn>b0if w1x1++wnxnb(1.23) p(x_1, \dots, x_n) = \begin{cases} 1 &\text{if } w_1 x_1 + \cdots + w_n x_n > b\\ 0 &\text{if } w_1 x_1 + \cdots + w_n x_n \leq b \end{cases} \tag{1.23}
for fixed numbers w1,,wnw_1, \dots, w_n (called weights) and a number bb (called the threshold). If the weighted sum w1x1++wnxnw_1 x_1 + \cdots + w_n x_n is above the threshold, the neuron fires (returns the value 11). If not it does not fire (returns the value 00).
Consider the three perceptrons p1,p2,p3:R2Rp_1, p_2, p_3: \mathbb{R}^2\rightarrow \mathbb{R}, where
p1(x,y)={1if xy>320if xy32,p2(x,y)={1if x+y>120if x+y12, p_1(x, y) = \begin{cases} 1 &\text{if } -x-y > -\frac{3}{2}\\ 0 &\text{if } -x-y \leq -\frac{3}{2} \end{cases}, \qquad p_2(x, y) = \begin{cases} 1 &\text{if } x + y > \frac{1}{2}\\ 0 &\text{if } x + y \leq \frac{1}{2} \end{cases},
and
p3(x,y)={1if x+y>320if x+y32. p_3(x, y) = \begin{cases} 1 &\text{if } x + y > \frac{3}{2}\\ 0 &\text{if } x + y \leq \frac{3}{2} \end{cases}.
Let f(x,y)=p3(p1(x,y),p2(x,y))f(x, y) = p_3 (p_1(x, y), p_2(x, y)). Then ff is a composite function f=ghf = g\circ h of two functions h:R2R2h: \mathbb{R}^2\rightarrow \mathbb{R}^2 and g:R2Rg: \mathbb{R}^2\rightarrow \mathbb{R}. Write down these functions.
Hint
Have a closer look at (1.22)
f(x1,,xm)=(f1(x1,,xm),,fn(x1,,xm)),(1.22) f(x_1, \dots, x_m) = \left( f_1(x_1, \dots, x_m), \dots, f_n(x_1, \dots, x_m)\right), \tag{1.22}
in order to understand how functions from R2\mathbb{R}^2 to R2\mathbb{R}^2 are expressed. Notice that our notation is a bit inconsistent when it comes to types. For example, the function p1:R2Rp_1:\mathbb{R}^2 \rightarrow \mathbb{R} should really be denoted p1((x,y))p_1((x, y)) instead of p1(x,y)p_1(x, y), since it takes input from R2=R×R\mathbb{R}^2 = \mathbb{R}\times \mathbb{R}. This is remedied in the (hopefully easy to understand) python code below.
LLM
💬

Explain the python code below to me.

def p1(v):
    (x, y) = v
    if -x-y > -3/2:
        return 1
    else:
        return 0

def p2(v):
    (x, y) = v
    if x + y > 1/2:
        return 1
    else:
        return 0

def p3(v):
    (x, y) = v
    if x+y > 3/2:
        return 1
    else:
        return 0

def h(v):
    return (p1(v), p2(v))

def g(v):
    return p3(v)

def f(v):
    return g(h(v))

| ChatGPT | Claude | Copilot | Gemini | HuggingChat | Mistral |
Compute f(0,0),f(1,0),f(0,1)f(0, 0), f(1, 0), f(0, 1) and f(1,1)f(1, 1).
Relate the perceptrons p1 p_1 and p2 p_2 to the illustration below. What do you think the red and blue line illustrate? What does it mean that a dot is solid compared to hollow? What is special about points between the red and blue lines? Try to relate f(0,0),f(1,0),f(0,1)f(0,0), f(1,0), f(0,1) and f(1,1)f(1,1) to the illustration.
\begin{excluderag}
(Illustration courtesy of William Heyman Krill). \end{excluderag}
Give weights w1,w2w_1, w_2 and a threshold bb for a perceptron p:R2Rp:\mathbb{R}^2\rightarrow \mathbb{R} that computes the logical and function \land i.e, pp must satisfy
p(0,0)=0p(1,0)=0p(0,1)=0p(1,1)=1.\begin{aligned} p(0,0) &= 0\\ p(1, 0) &= 0\\ p(0,1) &= 0\\ p(1, 1) &= 1. \end{aligned}
Do the same for the logical or function \lor.
The output of one neuron can be used as input for other neurons in a potentially extremely complicated network:
The diagram above represents a neural network, which is a function R8R4\mathbb{R}^8\rightarrow \mathbb{R}^4. This function is actually a composition (represented by the hidden layers 11, 22, 33 and the output layer):
R8R9R9R9R4. \mathbb{R}^8\rightarrow \mathbb{R}^9 \rightarrow \mathbb{R}^9 \rightarrow \mathbb{R}^9 \rightarrow \mathbb{R}^4.
All of the nodes above, except the ones in the input layer, represent perceptrons.
Is it possible to find a perceptron p:R2Rp:\mathbb{R}^2\rightarrow \mathbb{R}, such that
p(0,0)=0p(1,0)=1p(0,1)=1p(1,1)=0?\begin{aligned} p(0,0) &= 0\\ p(1, 0) &= 1\\ p(0,1) &= 1\\ p(1, 1) &= 0? \end{aligned}
What if you are allowed to use a neural network composed as R2R2R\mathbb{R}^2\rightarrow \mathbb{R}^2\rightarrow \mathbb{R} (one hidden layer)
?
Mathematically there is no reason to use special functions such as perceptrons in each node. One also uses a (smooth) version of the perceptron employing the sigmoid function. With the notation above, this function is given as
σ(x1,,xn)=11+e(w1x1++wnxn)b. \sigma(x_1, \dots, x_n) = \frac{1}{1 + e^{-(w_1 x_1 + \cdots + w_n x_n) - b}}.
However, around 2011 it was observed that the perceptron activation function (ReLU) as defined in (1.23)
p(x1,,xn)={1if w1x1++wnxn>b0if w1x1++wnxnb(1.23) p(x_1, \dots, x_n) = \begin{cases} 1 &\text{if } w_1 x_1 + \cdots + w_n x_n > b\\ 0 &\text{if } w_1 x_1 + \cdots + w_n x_n \leq b \end{cases} \tag{1.23}
led to better training of deep neural networks.