aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Homework/.ipynb_checkpoints/Homework4-checkpoint.ipynb172
-rw-r--r--Homework/Homework4.ipynb2
-rw-r--r--Homework/Retake1.pdfbin0 -> 134096 bytes
-rw-r--r--Lectures/.ipynb_checkpoints/7-SageAlgebra-checkpoint.ipynb1046
-rw-r--r--Lectures/7-SageAlgebra.ipynb4
-rw-r--r--README.md2
-rw-r--r--src/Lecture5/live/.ipynb_checkpoints/7-SageAlgebra-modified+solutions-checkpoint.ipynb1099
-rw-r--r--src/Lecture5/live/7-SageAlgebra-modified+solutions.ipynb4
-rw-r--r--src/Retake/Retake1.aux4
-rw-r--r--src/Retake/Retake1.log583
-rw-r--r--src/Retake/Retake1.pdfbin0 -> 134096 bytes
-rw-r--r--src/Retake/Retake1.tex208
-rw-r--r--src/Retake/bc.pngbin0 -> 6502 bytes
13 files changed, 3118 insertions, 6 deletions
diff --git a/Homework/.ipynb_checkpoints/Homework4-checkpoint.ipynb b/Homework/.ipynb_checkpoints/Homework4-checkpoint.ipynb
new file mode 100644
index 0000000..47f63cf
--- /dev/null
+++ b/Homework/.ipynb_checkpoints/Homework4-checkpoint.ipynb
@@ -0,0 +1,172 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "*For this exercise you should have received this text in .ipynb format. Complete the exercises by modifying this file, and submit the modified version*\n",
8 "\n",
9 "**Deadline:** Sunday, June 6."
10 ]
11 },
12 {
13 "cell_type": "markdown",
14 "metadata": {},
15 "source": [
16 "**Exercise 1 (6 points)**\n",
17 "\n",
18 "Use Sage to find the intersection points *in the real plane* (that is, only those points such that *both* coordinates are real numbers) of the following pairs of geometric objects:\n",
19 "\n",
20 "* The circle of equation $x^2 + y^2 = 4$ and the ellipse of equation $\\left(\\frac x2\\right)^2 + (2y)^2 = 4$.\n",
21 "* The circle of equation $x^2 + y^2 = 4$ and the ellipse of equation $\\left(\\frac x2-2\\right)^2 + (2y)^2 = 4$.\n",
22 "* The curve of equation $y^2 = x^3 -x +1$ and the horizontal line $y=10$.\n",
23 "* The $x$-axis and the graph of the function $f(x)=\\log(x) - e^{-x}$. *Hint: $f(x)$ has only one real zero.*"
24 ]
25 },
26 {
27 "cell_type": "code",
28 "execution_count": null,
29 "metadata": {},
30 "outputs": [],
31 "source": []
32 },
33 {
34 "cell_type": "markdown",
35 "metadata": {},
36 "source": [
37 "**Exercise 2 (6 points)**\n",
38 "\n",
39 "(a) Use Sage to compute\n",
40 "* the derivative\n",
41 "* a primite (i.e. integral)\n",
42 "* the power series expansion around $0$ up to order $4$\n",
43 "\n",
44 "of the following functions:\n",
45 "* $f(x) = e^x$\n",
46 "* $f(x) = \\sin(x)$\n",
47 "* $f(x) = \\cos(x)$\n",
48 "* $f(x) = \\tan(x)$\n",
49 "* $f(x) = \\log(1+x)$\n",
50 "* $f(x) = \\sqrt[3]{1+x}$\n",
51 "\n",
52 "(b) Use Sage to get the Latex code that represents the objects you computed above.\n",
53 "\n",
54 "(c) Arrange the results of the previous points in a table in Latex. The table should have 4 columns (function, derivative, integral, series) and one row for each of the functions above. *Note: when including Latex in a Markdown cell in Jupyter you will not receive any warning if you make mistakes; instead the Latex will simply not be rendered and it will appear as plain text. If you have troubles making this work you can send me a separate .tex (and .pdf) file.*"
55 ]
56 },
57 {
58 "cell_type": "code",
59 "execution_count": null,
60 "metadata": {},
61 "outputs": [],
62 "source": [
63 "# Compute derivatives etc..."
64 ]
65 },
66 {
67 "cell_type": "code",
68 "execution_count": null,
69 "metadata": {},
70 "outputs": [],
71 "source": [
72 "# Compute Latex code"
73 ]
74 },
75 {
76 "cell_type": "markdown",
77 "metadata": {},
78 "source": [
79 "(Write your table here)"
80 ]
81 },
82 {
83 "cell_type": "markdown",
84 "metadata": {},
85 "source": [
86 "**Exercise 3 (4 points)**\n",
87 "\n",
88 "The equation\n",
89 "\\begin{align*}\n",
90 "y^2+x^{16}=1\n",
91 "\\end{align*}\n",
92 "determines a closed curve in $\\mathbb R^2$ that looks like a rounded square. Determine the area of that shape, giving both an exact value (which might depend on some functions that Sage knows, but you don't) and an approximate value."
93 ]
94 },
95 {
96 "cell_type": "code",
97 "execution_count": null,
98 "metadata": {},
99 "outputs": [],
100 "source": []
101 },
102 {
103 "cell_type": "markdown",
104 "metadata": {},
105 "source": [
106 "**Exercise 4 (12 points)**\n",
107 "\n",
108 "A team of biologists is monitoring the population of river shrimps in the Alzette. At first they thought that the size $P(t)$ of their population on day $t$ would satisfy the differential equation $P'(t)=P(t)/10$. However this does not work well with the data they have collected, so they now believe that the population of shrimps follows the formula $P'(t)=P(t)/10-b$ for some value of $b$ between 1 and 100. They need your help here.\n",
109 "\n",
110 "(a) Using Sage, find a solution for the differential equation with initial conditions\n",
111 "\\begin{align*}\n",
112 "\\begin{cases}\n",
113 "P'(t)&=\\frac{P(t)}{10}-b\\\\\n",
114 "P(1)&=1000\n",
115 "\\end{cases}\n",
116 "\\end{align*}\n",
117 "where $b$ is a generic constant.\n",
118 "\n",
119 "(b) The list `data` in the cell below contains the actual number of shrimps that was measured every day from day $1$ (the $0$ at the beginning is meaningless, but it will help to keep it there). Plot in one single picture, possibly using different colors for each:\n",
120 "* The data as a bar chart.\n",
121 "* A curve that interpolates the data, using one of the methods shown in class.\n",
122 "* The solution of the differential equation for $b=0$.\n",
123 "* The solution of the differential equation for a value of $b$ of your choice ($1\\leq b\\leq 100$) that fits the data better than $b=0$. *(For this last point there is no right or wrong choice, just pick one that looks good)*"
124 ]
125 },
126 {
127 "cell_type": "code",
128 "execution_count": null,
129 "metadata": {},
130 "outputs": [],
131 "source": [
132 "data = [0, 1000, 1123, 1223, 1190, 1432, 1553, 1709, 1826, 1980, 2146, 2172, 2383, 2588, 2822, 3401, 3330, 4157, 3994, 4995, 5392, 5910, 6468, 7128, 7325, 7984, 9634, 10473, 11761, 12777]\n"
133 ]
134 },
135 {
136 "cell_type": "markdown",
137 "metadata": {},
138 "source": [
139 "**Grading**\n",
140 "\n",
141 "This homework assignment is worth $28$ ($24+4$) points, distributed as described above.\n",
142 "\n",
143 "Your final grade for the course will be the total of points you obtained (notice that the maximum is $20+20+16+28=84$) divided by $4$, rounded to the nearest integer. More precisely\n",
144 "\n",
145 "\\begin{align*}\n",
146 "\\operatorname{grade} = \\operatorname{min}\\left(20, \\left\\lfloor \\frac{\\operatorname{total}}{4} + 0.5\\right\\rfloor\\right)\n",
147 "\\end{align*}"
148 ]
149 }
150 ],
151 "metadata": {
152 "kernelspec": {
153 "display_name": "SageMath 9.2",
154 "language": "sage",
155 "name": "sagemath"
156 },
157 "language_info": {
158 "codemirror_mode": {
159 "name": "ipython",
160 "version": 3
161 },
162 "file_extension": ".py",
163 "mimetype": "text/x-python",
164 "name": "python",
165 "nbconvert_exporter": "python",
166 "pygments_lexer": "ipython3",
167 "version": "3.8.5"
168 }
169 },
170 "nbformat": 4,
171 "nbformat_minor": 4
172}
diff --git a/Homework/Homework4.ipynb b/Homework/Homework4.ipynb
index 99481b9..47f63cf 100644
--- a/Homework/Homework4.ipynb
+++ b/Homework/Homework4.ipynb
@@ -150,7 +150,7 @@
150 ], 150 ],
151 "metadata": { 151 "metadata": {
152 "kernelspec": { 152 "kernelspec": {
153 "display_name": "SageMath 9.0", 153 "display_name": "SageMath 9.2",
154 "language": "sage", 154 "language": "sage",
155 "name": "sagemath" 155 "name": "sagemath"
156 }, 156 },
diff --git a/Homework/Retake1.pdf b/Homework/Retake1.pdf
new file mode 100644
index 0000000..4f70e80
--- /dev/null
+++ b/Homework/Retake1.pdf
Binary files differ
diff --git a/Lectures/.ipynb_checkpoints/7-SageAlgebra-checkpoint.ipynb b/Lectures/.ipynb_checkpoints/7-SageAlgebra-checkpoint.ipynb
new file mode 100644
index 0000000..59ea033
--- /dev/null
+++ b/Lectures/.ipynb_checkpoints/7-SageAlgebra-checkpoint.ipynb
@@ -0,0 +1,1046 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "This lecture's notes are in a different format: the presentations for the $\\LaTeX$ part were made with $\\LaTeX$, so this one is made with Sage, or rather with the [Jupyter Notebook](https://jupyter.org/).\n",
8 "\n",
9 "# The Jupyter Notebook\n",
10 "**Reference:** [[1](https://jupyter.org/documentation)]\n",
11 "\n",
12 "The Jupyter Notebook is one of the default interfaces for SageMath, along with the command line interface. You can access it via web browser, but it is running locally on your device (notice the strange url: `http://localhost:8888/notebooks...`).\n",
13 "\n",
14 "You can create a new notebook by clicking on `New > SageMath 9.2`. You can also create a Python 3 notebook to write Python code.\n",
15 "\n",
16 "Jupyter saves and reads files in the `.ipynb` format. If you download the file for this lecture you can open it and follow the examples interactively.\n",
17 "\n",
18 "## Cells\n",
19 "\n",
20 "The notebook contains one or more *interactive cells* that you can run, like this one below:"
21 ]
22 },
23 {
24 "cell_type": "code",
25 "execution_count": 2,
26 "metadata": {},
27 "outputs": [
28 {
29 "data": {
30 "text/plain": [
31 "2/5"
32 ]
33 },
34 "execution_count": 2,
35 "metadata": {},
36 "output_type": "execute_result"
37 }
38 ],
39 "source": [
40 "# Exercise: modify this cell to use the print() command\n",
41 "2+2\n",
42 "2/5"
43 ]
44 },
45 {
46 "cell_type": "markdown",
47 "metadata": {},
48 "source": [
49 "If you are reading this from Jupyter rather than from the pdf file, you can edit the cell above and run it again. You can also add more cells by selecting `Insert` from the menu bar.\n",
50 "\n",
51 "Notice that only the last statement produces an output. You can force anything to be written as output with the `print()` command, which works like in Python. As an exercise, try to modify the cell above to provide more output!"
52 ]
53 },
54 {
55 "cell_type": "markdown",
56 "metadata": {},
57 "source": [
58 "## Markdown\n",
59 "\n",
60 "[Markdown](https://en.wikipedia.org/wiki/Markdown) is a simple markup language - think of LaTeX or html, but much simpler.\n",
61 "You can add text to your notebook with Markdown cells by selecting `Cell > Cell Type > Markdown`.\n",
62 "\n",
63 "You can also include some LaTeX code in Markdown cells, with dollar signs $ or align environments:\n",
64 "\n",
65 "\\begin{align*}\n",
66 "\\frac{(x+y)^2}{x+1} = \\frac{x^2+y^2}{x+1}\n",
67 "\\end{align*}\n",
68 "\n",
69 "When you are done writing a Markdown cell, you can run it to see the well-formatted text. To edit the text again, double-click on the cell. Try doing it now to fix the formula above!"
70 ]
71 },
72 {
73 "cell_type": "markdown",
74 "metadata": {},
75 "source": [
76 "# Symbolic expressions\n",
77 "\n",
78 "**Reference:** [[2](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html)]\n",
79 "\n",
80 "Now, let's get started with Sage. One thing you might want to do is manipulating symbolic expressions, like the following:"
81 ]
82 },
83 {
84 "cell_type": "code",
85 "execution_count": 3,
86 "metadata": {},
87 "outputs": [
88 {
89 "data": {
90 "text/plain": [
91 "[x == -sqrt(6) - 1, x == sqrt(6) - 1]"
92 ]
93 },
94 "execution_count": 3,
95 "metadata": {},
96 "output_type": "execute_result"
97 }
98 ],
99 "source": [
100 "f = x^2 + 2*x - 5 == 0\n",
101 "solve(f,x)"
102 ]
103 },
104 {
105 "cell_type": "markdown",
106 "metadata": {},
107 "source": [
108 "Notice that the single `=` is part of an assignment, as in Python: we are *assigning* to the variable `f` the value `x^2 + 2*x - 5 >= 0`, which in this case is an equation, so it contains the symbol `==`. Keep in mind the difference between the two!\n",
109 "\n",
110 "**Exercise:** change the code above to solve the corresponding inequality $x^2+2x-5\\geq 0$."
111 ]
112 },
113 {
114 "cell_type": "markdown",
115 "metadata": {},
116 "source": [
117 "## Mathematical variables\n",
118 "\n",
119 "Last time we saw what *variables* are in Python, and that they are a little bit different from the *Mathematical variables* that you use in Mathematics. In Sage, both concepts are present, but they are still distinct. For example in the cell above `f` is a variable in the sense of computer science, while `x` is a Mathematical variable.\n",
120 "\n",
121 "If you want to use Mathematical variables other than `x`, you first need to *declare* them with the `var()` command:"
122 ]
123 },
124 {
125 "cell_type": "code",
126 "execution_count": 14,
127 "metadata": {},
128 "outputs": [
129 {
130 "data": {
131 "text/plain": [
132 "[y == -1/2*x - 1/2*sqrt(x^2 + 2*x + 9) - 1/2, y == -1/2*x + 1/2*sqrt(x^2 + 2*x + 9) - 1/2]"
133 ]
134 },
135 "execution_count": 14,
136 "metadata": {},
137 "output_type": "execute_result"
138 }
139 ],
140 "source": [
141 "var('y')\n",
142 "solve(y^2 + (x+1)*y - 2 == 0, y)"
143 ]
144 },
145 {
146 "cell_type": "markdown",
147 "metadata": {},
148 "source": [
149 "Try removing the first line in the cell above and see what error you get!\n",
150 "\n",
151 "Here is another example:"
152 ]
153 },
154 {
155 "cell_type": "code",
156 "execution_count": 16,
157 "metadata": {},
158 "outputs": [
159 {
160 "data": {
161 "text/plain": [
162 "[x == -1/2*a - 1/2*sqrt(a^2 - 4*b), x == -1/2*a + 1/2*sqrt(a^2 - 4*b)]"
163 ]
164 },
165 "execution_count": 16,
166 "metadata": {},
167 "output_type": "execute_result"
168 }
169 ],
170 "source": [
171 "var('a', 'b')\n",
172 "f = x^2+a*x+b\n",
173 "solve(f,x)"
174 ]
175 },
176 {
177 "cell_type": "markdown",
178 "metadata": {},
179 "source": [
180 "Some common constants are [already defined](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html) in Sage:"
181 ]
182 },
183 {
184 "cell_type": "code",
185 "execution_count": 17,
186 "metadata": {},
187 "outputs": [
188 {
189 "data": {
190 "text/plain": [
191 "-1"
192 ]
193 },
194 "execution_count": 17,
195 "metadata": {},
196 "output_type": "execute_result"
197 }
198 ],
199 "source": [
200 "e^(pi*I)"
201 ]
202 },
203 {
204 "cell_type": "markdown",
205 "metadata": {},
206 "source": [
207 "We will study symbolic expressions more in detail next time, in the context of calculus/analysis."
208 ]
209 },
210 {
211 "cell_type": "markdown",
212 "metadata": {},
213 "source": [
214 "# Basic rings and fields\n",
215 "\n",
216 "**References:** [[3](https://doc.sagemath.org/html/en/reference/rings_standard/index.html)]\n",
217 "[[4](https://doc.sagemath.org/html/en/reference/rings_numerical/index.html)]\n",
218 "[[5](https://doc.sagemath.org/html/en/reference/finite_rings/index.html)]\n",
219 "\n",
220 "As you should know, a *field* is a Mathematical structure with two operations, addition and multiplication, which respect certain rules (distributivity, associativity, commutativity...). Some examples of fields are the Rational numbers $\\mathbb Q$, the Real numbers $\\mathbb R$ and the Complex numbers $\\mathbb C$, but there are many more. As you should also know, a *(commutative) ring* is like a field, except not all elements different from $0$ need have a multiplicative inverse. For example the integers $\\mathbb Z = \\{ \\dots, -1, 0, 1, 2, \\dots\\}$ are a ring, but not a field.\n",
221 "\n",
222 "These structures are already implemented in Sage. Some of the most common are listed in the following table:\n",
223 "\n",
224 "|Mathematical object|Math symbol|Sage name|\n",
225 "|------------------:|:---------:|:--------|\n",
226 "|Integers|$\\mathbb Z$|`ZZ`|\n",
227 "|Rational numbers|$\\mathbb Q$|`QQ`|\n",
228 "|Real numbers|$\\mathbb R$|`RR`|\n",
229 "|Complex numbers|$\\mathbb C$|`CC`|\n",
230 "|Integers modulo $n$|$\\mathbb Z/n\\mathbb Z$|`Integers(n)`|\n",
231 "|Finite fields|$\\mathbb F_p$|GF(p)|\n",
232 "|$\\dots$|$\\dots$|$\\dots$|"
233 ]
234 },
235 {
236 "cell_type": "markdown",
237 "metadata": {},
238 "source": [
239 "If you write a number or an expression, Sage will figure out where it \"lives\", choosing the most restrictive interpretation possible. For example `3` will be interpreted to be an integer, even if it is also a rational number, a real number and a complex number."
240 ]
241 },
242 {
243 "cell_type": "markdown",
244 "metadata": {},
245 "source": [
246 "## Parents and coercion\n",
247 "**Reference:** [[6](https://doc.sagemath.org/html/en/tutorial/tour_coercion.html)]\n",
248 "\n",
249 "You can check where an object \"lives\" with the `parent()` command. It works more or less like the Python command `type()`, but it gives a more Mathematically inclined answer. Check the reference link [6] above if you want more details."
250 ]
251 },
252 {
253 "cell_type": "code",
254 "execution_count": 18,
255 "metadata": {},
256 "outputs": [
257 {
258 "data": {
259 "text/plain": [
260 "Rational Field"
261 ]
262 },
263 "execution_count": 18,
264 "metadata": {},
265 "output_type": "execute_result"
266 }
267 ],
268 "source": [
269 "#Edit this cell to find out the type of other objects that we used\n",
270 "parent(3/5)"
271 ]
272 },
273 {
274 "cell_type": "markdown",
275 "metadata": {},
276 "source": [
277 "Sometimes Sage does not give you the best possible interpretation, so you can force something to be interpreted as living in a smaller ring as follows:"
278 ]
279 },
280 {
281 "cell_type": "code",
282 "execution_count": 4,
283 "metadata": {},
284 "outputs": [
285 {
286 "name": "stdout",
287 "output_type": "stream",
288 "text": [
289 "Symbolic Ring\n",
290 "Integer Ring\n"
291 ]
292 }
293 ],
294 "source": [
295 "minus_one = e^(pi*I)\n",
296 "minus_one_coerced = ZZ(e^(pi*I)) # coercion\n",
297 "print(parent(minus_one))\n",
298 "print(parent(minus_one_coerced))"
299 ]
300 },
301 {
302 "cell_type": "markdown",
303 "metadata": {},
304 "source": [
305 "**Remark.** Notice that there is a fundamental difference between the rings `RR` and `CC` and all the others in the table above: the real and complex numbers are *approximated*."
306 ]
307 },
308 {
309 "cell_type": "code",
310 "execution_count": 1,
311 "metadata": {},
312 "outputs": [
313 {
314 "name": "stdout",
315 "output_type": "stream",
316 "text": [
317 "3\n",
318 "3.00000000000000\n"
319 ]
320 }
321 ],
322 "source": [
323 "print(QQ(3))\n",
324 "print(RR(3))"
325 ]
326 },
327 {
328 "cell_type": "markdown",
329 "metadata": {},
330 "source": [
331 "You can also choose the precision of this approximation using the alternative name `RealField`."
332 ]
333 },
334 {
335 "cell_type": "code",
336 "execution_count": 4,
337 "metadata": {},
338 "outputs": [
339 {
340 "name": "stdout",
341 "output_type": "stream",
342 "text": [
343 "Real Field with 53 bits of precision\n",
344 "Real Field with 1000 bits of precision\n"
345 ]
346 }
347 ],
348 "source": [
349 "print(RR)\n",
350 "print(RealField(prec=1000))"
351 ]
352 },
353 {
354 "cell_type": "markdown",
355 "metadata": {},
356 "source": [
357 "# Polynomial rings\n",
358 "\n",
359 "**Reference:** [[7](https://doc.sagemath.org/html/en/reference/polynomial_rings/index.html)]\n",
360 "\n",
361 "If you want to work with polynomials over a certain ring it is better to use this specific construction, rather than the symbolic expressions introduced above."
362 ]
363 },
364 {
365 "cell_type": "code",
366 "execution_count": 5,
367 "metadata": {},
368 "outputs": [
369 {
370 "data": {
371 "text/plain": [
372 "Multivariate Polynomial Ring in x, y, z over Real Field with 53 bits of precision"
373 ]
374 },
375 "execution_count": 5,
376 "metadata": {},
377 "output_type": "execute_result"
378 }
379 ],
380 "source": [
381 "polring.<x,y,z> = RR[] # Alternative: polring.<x,y,z> = PolynomialRing(RR)\n",
382 "polring"
383 ]
384 },
385 {
386 "cell_type": "markdown",
387 "metadata": {},
388 "source": [
389 "You can use as many variables as you like, and you can replace `RR` with any ring. In the example above `polring` is just the name of the variable (in the computer science sense) associated with this polynomial ring.\n",
390 "\n",
391 "## Operations on polynomials\n",
392 "\n",
393 "The usual Mathematical operations are available on polynomial rings, including Euclidean division `//` and remainder `%`. There is also the single-slash division `/`, but the result may not be a polynomial anymore.\n",
394 "\n",
395 "**Exercise:** use the `parent()` command to find out what the quotient of two polynomials is.\n",
396 "\n",
397 "**Question:** what happens if you remove the first line in the cell below? What if we used the variable `y` instead of `x`?"
398 ]
399 },
400 {
401 "cell_type": "code",
402 "execution_count": 6,
403 "metadata": {},
404 "outputs": [
405 {
406 "name": "stdout",
407 "output_type": "stream",
408 "text": [
409 "x + 1\n",
410 "-4\n",
411 "(x^2 + 2*x - 3)/(x + 1)\n"
412 ]
413 }
414 ],
415 "source": [
416 "polring.<x> = QQ[]\n",
417 "p = x^2 + 2*x - 3 # Don't forget * for multiplication!\n",
418 "q = p // (x+1)\n",
419 "r = p % (x+1)\n",
420 "f = p / (x+1)\n",
421 "print(q)\n",
422 "print(r)\n",
423 "print(f)"
424 ]
425 },
426 {
427 "cell_type": "markdown",
428 "metadata": {},
429 "source": [
430 "You can do more complex operations. Try out `roots()` and `factor` in the cell below.\n",
431 "\n",
432 "**Remark.** Notice how the result can change substantially if you change the base ring.\n",
433 "\n",
434 "**Remark.** [Factorizations](https://doc.sagemath.org/html/en/reference/structure/sage/structure/factorization.html) are a particular object in Sage. They are kinda like a list, but not really. You can get a list of pairs (factor, power) with `list(factor(f))`."
435 ]
436 },
437 {
438 "cell_type": "code",
439 "execution_count": 7,
440 "metadata": {},
441 "outputs": [
442 {
443 "name": "stdout",
444 "output_type": "stream",
445 "text": [
446 "(t + 1) * (t^2 - 3) * (t^2 + 1)\n",
447 "[(-1, 1)]\n"
448 ]
449 },
450 {
451 "data": {
452 "text/plain": [
453 "(y + 1) * x"
454 ]
455 },
456 "execution_count": 7,
457 "metadata": {},
458 "output_type": "execute_result"
459 }
460 ],
461 "source": [
462 "polring_onevar.<t> = QQ[]\n",
463 "\n",
464 "f = t^5 + t^4 - 2*t^3 - 2*t^2 - 3*t - 3\n",
465 "print(factor(f))\n",
466 "print(f.roots()) # Result: list of pairs (root,multiplicity)\n",
467 "\n",
468 "polring_manyvar.<x,y,z> = QQ[]\n",
469 "factor(x*y+x)\n",
470 "\n",
471 "# The following line gives an error, because the polynomial\n",
472 "# is understood to possibly have many variables:\n",
473 "#(x^2-1).roots()"
474 ]
475 },
476 {
477 "cell_type": "markdown",
478 "metadata": {},
479 "source": [
480 "# Matrices and vectors\n",
481 "\n",
482 "**References:** [[8](https://doc.sagemath.org/html/en/reference/matrices/index.html)], but in particular the subections [[9](https://doc.sagemath.org/html/en/reference/matrices/sage/matrix/docs.html)] and [[10](https://doc.sagemath.org/html/en/reference/matrices/sage/matrix/matrix2.html)]\n",
483 "\n",
484 "In Sage you can easily manipulate matrices and vectors"
485 ]
486 },
487 {
488 "cell_type": "code",
489 "execution_count": 77,
490 "metadata": {},
491 "outputs": [
492 {
493 "name": "stdout",
494 "output_type": "stream",
495 "text": [
496 "[ 1 2 3]\n",
497 "[ 0 0 1]\n",
498 "[ 4 -3 22/7] \n",
499 "\n",
500 "[1/2 0 0]\n",
501 "[ 7 0 0]\n",
502 "[ 1 1 1] \n",
503 "\n",
504 "(3/2, 21, 6) \n",
505 "\n",
506 "[ -7/2 -10 80/7]\n",
507 "[ 17 -4 15/7]\n",
508 "[ 241/7 -18/7 869/49] \n",
509 "\n",
510 "Rank of A = 3\n",
511 "Rank of B = 2\n"
512 ]
513 }
514 ],
515 "source": [
516 "A = matrix([[1,2,3],[0,0,1],[4,-3,22/7]])\n",
517 "B = matrix([[1/2,0,0],[7,0,0],[1,1,1]])\n",
518 "v = vector([3,4,-1])\n",
519 "\n",
520 "print(A, \"\\n\") # \\n just means \"newline\"\n",
521 "print(B, \"\\n\")\n",
522 "print(B*v, \"\\n\")\n",
523 "print(A^2 + 2*B - A*B, \"\\n\")\n",
524 "\n",
525 "print(\"Rank of A =\", rank(A)) # You can also use A.rank()\n",
526 "print(\"Rank of B =\", rank(B))"
527 ]
528 },
529 {
530 "cell_type": "markdown",
531 "metadata": {},
532 "source": [
533 "**Exercise:** in the cell above, compute the determinant, inverse and characteristic polynomial of the matrix `A`. *Hint: look at the reference [10] above (the functions are listed in alphabetic order).*\n",
534 "\n",
535 "As for polynomials, you can specify where a matrix or a vector lives"
536 ]
537 },
538 {
539 "cell_type": "code",
540 "execution_count": 57,
541 "metadata": {},
542 "outputs": [
543 {
544 "data": {
545 "text/plain": [
546 "Full MatrixSpace of 2 by 2 dense matrices over Complex Field with 53 bits of precision"
547 ]
548 },
549 "execution_count": 57,
550 "metadata": {},
551 "output_type": "execute_result"
552 }
553 ],
554 "source": [
555 "M = matrix(CC, [[0,1],[1,0]])\n",
556 "parent(M)"
557 ]
558 },
559 {
560 "cell_type": "markdown",
561 "metadata": {},
562 "source": [
563 "You can also solve linear systems and compute eigenvalues and eigenvectors of a matrix\n",
564 "\n",
565 "**Warning.** In linear algebra there are distinct concepts of *left* and *right* eigenvalues (and eigenvector). The one you know is probably that of **right** eigen-{value,vector}, that is an element $\\lambda$ of the base field and a non-zero vector $\\mathbf v$ with $A\\mathbf v=\\lambda\\mathbf v$. The other concept corresponds to the equality $\\mathbf v^TA=\\lambda \\mathbf v$."
566 ]
567 },
568 {
569 "cell_type": "code",
570 "execution_count": 60,
571 "metadata": {},
572 "outputs": [
573 {
574 "data": {
575 "text/plain": [
576 "(0.289916349448506, 0.0241596957873755)"
577 ]
578 },
579 "execution_count": 60,
580 "metadata": {},
581 "output_type": "execute_result"
582 }
583 ],
584 "source": [
585 "A = Matrix(RR, [[sqrt(59),32],[-1/4,3]])\n",
586 "v = vector(RR, [3,0])\n",
587 "A.solve_right(v) # Solve Ax=v. Alternative: A \\ v"
588 ]
589 },
590 {
591 "cell_type": "code",
592 "execution_count": 64,
593 "metadata": {},
594 "outputs": [
595 {
596 "data": {
597 "text/plain": [
598 "[\n",
599 "(-0.3722813232690144?, Vector space of degree 2 and dimension 1 over Algebraic Field\n",
600 "User basis matrix:\n",
601 "[ 1 -0.6861406616345072?]),\n",
602 "(5.372281323269015?, Vector space of degree 2 and dimension 1 over Algebraic Field\n",
603 "User basis matrix:\n",
604 "[ 1 2.186140661634508?])\n",
605 "]"
606 ]
607 },
608 "execution_count": 64,
609 "metadata": {},
610 "output_type": "execute_result"
611 }
612 ],
613 "source": [
614 "A = Matrix(QQ, [[1,2],[3,4]])\n",
615 "A.eigenspaces_right() # Also: A.eigenvalues(), A.eigenvectors_right()"
616 ]
617 },
618 {
619 "cell_type": "markdown",
620 "metadata": {},
621 "source": [
622 "We can also extract a specific submatrix by selecting only some rows and columns, with a syntax similar to that of Python's lists. Check out more examples in the reference [9] above, and try them in the cell below."
623 ]
624 },
625 {
626 "cell_type": "code",
627 "execution_count": 94,
628 "metadata": {},
629 "outputs": [
630 {
631 "name": "stdout",
632 "output_type": "stream",
633 "text": [
634 "[-14 2 0 -1 1 -2 -1]\n",
635 "[ 0 -8 0 9 -2 11 1]\n",
636 "[ 0 3 1 -1 1 1 221]\n",
637 "[ -1 2 1 -25 -10 4 0]\n",
638 "[ -3 0 0 2 16 -1 -2]\n",
639 "[ 1 -3 3 -41 1 0 0]\n",
640 "[ -2 1 0 0 -6 2 12] \n",
641 "\n",
642 "[ 0 9 -2]\n",
643 "[ 1 -1 1] \n",
644 "\n",
645 "[-14 2 0 -1 1 -2 -1] \n",
646 "\n",
647 "[-14 2 0 -1 1]\n",
648 "[ 1 -3 3 -41 1]\n",
649 "[ 0 3 1 -1 1]\n"
650 ]
651 }
652 ],
653 "source": [
654 "A = MatrixSpace(ZZ, 7).random_element()\n",
655 "print(A, \"\\n\")\n",
656 "print(A[1:3,2:5], \"\\n\") # Rows from 1 to 3, columns from 2 to 5\n",
657 "print(A[0,0:], \"\\n\") # First row, all columns\n",
658 "print(A[[0,5,2],0:5]) # Rows 0, 5 and 2 (in this order) and columns 0 to 5"
659 ]
660 },
661 {
662 "cell_type": "markdown",
663 "metadata": {},
664 "source": [
665 "**Exercise:** write a sage function that computes the determinant of an $n\\times n$ matrix $A=(a_{ij})$ using Laplace's rule by the first row, that is \n",
666 "\\begin{align*}\n",
667 " \\operatorname{det}A = \\sum_{j=1}^n (-1)^ja_{0j}M_{0j}\n",
668 "\\end{align*}\n",
669 "where $M_{0j}$ is the determinant of the $(n-1)\\times(n-1)$ matrix obtained by removing the $0$-th row and the $j$-th column from $A$."
670 ]
671 },
672 {
673 "cell_type": "code",
674 "execution_count": 91,
675 "metadata": {},
676 "outputs": [],
677 "source": [
678 "def my_det(A):\n",
679 " if not A.is_square():\n",
680 " print(\"Error: matrix is not square\")\n",
681 " \n",
682 " n = A.nrows() # size of the matrix\n",
683 " \n",
684 " # Continue from here!"
685 ]
686 },
687 {
688 "cell_type": "markdown",
689 "metadata": {},
690 "source": [
691 "# Number Theory\n",
692 "\n",
693 "**Reference:** [[11](https://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/integer.html)]\n",
694 "\n",
695 "Sage includes a large library of functions for computing with the integers, see the link above."
696 ]
697 },
698 {
699 "cell_type": "code",
700 "execution_count": 8,
701 "metadata": {},
702 "outputs": [
703 {
704 "name": "stdout",
705 "output_type": "stream",
706 "text": [
707 "3^2 * 3607 * 3803\n",
708 "True\n",
709 "True\n",
710 "619703040\n",
711 "9\n",
712 "13548070123626141\n"
713 ]
714 }
715 ],
716 "source": [
717 "n = 123456789\n",
718 "m = 987654321\n",
719 "p = 3607\n",
720 "\n",
721 "print(factor(n))\n",
722 "print(is_prime(p))\n",
723 "print(p.divides(n))\n",
724 "print(euler_phi(m))\n",
725 "print(gcd(n, m))\n",
726 "print(lcm(n, m))"
727 ]
728 },
729 {
730 "cell_type": "markdown",
731 "metadata": {},
732 "source": [
733 "## Primes\n",
734 "\n",
735 "**Reference:** [[12](https://doc.sagemath.org/html/en/reference/sets/sage/sets/primes.html)]\n",
736 "\n",
737 "The set of prime numbers is called `Primes()`. It is like an infinite list: for example you can get the one-millionth prime number or you can use this list to create other lists. You can also check what the first prime number larger than a given number is."
738 ]
739 },
740 {
741 "cell_type": "code",
742 "execution_count": 9,
743 "metadata": {},
744 "outputs": [
745 {
746 "name": "stdout",
747 "output_type": "stream",
748 "text": [
749 "Set of all prime numbers: 2, 3, 5, 7, ...\n",
750 "31 15485867\n",
751 "47\n",
752 "[79, 83, 89, 97]\n"
753 ]
754 }
755 ],
756 "source": [
757 "PP = Primes()\n",
758 "print(PP)\n",
759 "print(PP[10], PP[10^6])\n",
760 "print(PP.next(44))\n",
761 "\n",
762 "First_Thousand_Primes = PP[0:1000]\n",
763 "print([p for p in First_Thousand_Primes if p < 100 and p > 75])"
764 ]
765 },
766 {
767 "cell_type": "markdown",
768 "metadata": {},
769 "source": [
770 "## The Chinese remainder theorem (CRT)\n",
771 "\n",
772 "We say that two integers $a$ and $b$ are *congruent* modulo another integer $n>0$ if they have the same remainder when divided by $n$. We denote this by $a\\equiv b\\pmod n$, or in Python/Sage syntax `a % n == b % n`.\n",
773 "\n",
774 "The Chinese remainder theorem states that if $a,b\\in\\mathbb Z$ and $n,m\\in \\mathbb Z_{>0}$ are such that $\\gcd(n,m)=1$ then the system of congruences\n",
775 "\n",
776 "\\begin{align*}\n",
777 "\\begin{cases}\n",
778 " x \\equiv a \\pmod n\\\\\n",
779 " x \\equiv b \\pmod m\n",
780 "\\end{cases}\n",
781 "\\end{align*}\n",
782 "\n",
783 "has exactly one solution modulo $mn$. This means that there is one and only one number $x$ with $0\\leq x<mn$ such that $x\\equiv a\\pmod n$ and $x\\equiv b\\pmod m$.\n",
784 "\n",
785 "The procedure to find such a number is not too hard to describe (you might see it in an algebra or number theory course), but it can be a bit long. Luckily, Sage can do this for you:"
786 ]
787 },
788 {
789 "cell_type": "code",
790 "execution_count": 10,
791 "metadata": {},
792 "outputs": [
793 {
794 "name": "stdout",
795 "output_type": "stream",
796 "text": [
797 "74306 2 798\n"
798 ]
799 }
800 ],
801 "source": [
802 "a = 2\n",
803 "b = -1\n",
804 "n = 172\n",
805 "m = 799\n",
806 "\n",
807 "if gcd(n,m) != 1:\n",
808 " print(\"The numbers are not comprime, I can't solve this!\")\n",
809 "else:\n",
810 " x = crt(a, b, n, m)\n",
811 " print(x, x%n, x%m)"
812 ]
813 },
814 {
815 "cell_type": "markdown",
816 "metadata": {},
817 "source": [
818 "**Exercise.** There is a more general version of the Chinese remainder theorem which says that if $a_0, a_1, \\dots, a_k\\in\\mathbb Z$ and $n_0, n_2, \\dots, n_k\\in\\mathbb Z_{>0}$ are such that $\\gcd(n_i, n_j)=1$ for $i\\neq j$, then the system of congruences\n",
819 "\n",
820 "\\begin{align*}\n",
821 "\\begin{cases}\n",
822 " x \\equiv a_0 \\pmod {n_0}\\\\\n",
823 " x \\equiv a_1 \\pmod {n_1}\\\\\n",
824 " \\dots \\\\\n",
825 " x \\equiv a_k \\pmod {n_k}\n",
826 "\\end{cases}\n",
827 "\\end{align*}\n",
828 "\n",
829 "has exactly one solution modulo $\\prod_{i=0}^kn_i$. Use the `crt()` function to find a solution to such a system.\n",
830 "*Hint: start by running the command `help(crt)`."
831 ]
832 },
833 {
834 "cell_type": "code",
835 "execution_count": 127,
836 "metadata": {},
837 "outputs": [],
838 "source": [
839 "#help(crt)"
840 ]
841 },
842 {
843 "cell_type": "markdown",
844 "metadata": {},
845 "source": [
846 "# Cryptography: RSA\n",
847 "\n",
848 "[Cryptography](https://en.wikipedia.org/wiki/Cryptography) is the discipline that studies methods to communicate secrets in such a way that any unauthorized listener would not be able to understand the message.\n",
849 "\n",
850 "A simple cryptographic protocol could be changing every letter of your text following a fixed scheme (or *cypher*), for example by turning every A into a B, every B into a C and so on. However this is not a very secure method, for many reasons. One of them is that at some point the people who want to communicate need to agree on what method to use, and anyone listening to that conversation would be able to decypher every subsequent conversation. A public-key cryptographic protocol solves this problem.\n",
851 "\n",
852 "## Public-key cryptography\n",
853 "\n",
854 "Public-key cryptographic protocols, such as RSA, work like this: there are two keys, a *private* key that is only known to person A (traditionally called Alice in every example), and a *public* key that does not need to be secret.\n",
855 "\n",
856 "The public key is used to *encrypt* the message (that is to \"lock\" it, or \"hyde\" it), but one needs the private key to *decrypt* it. Imagine having two keys for your door, but one can only be used to lock it, while the other only to open it.\n",
857 "\n",
858 "The message exchange works like this: suppose that person B (Bob) wants to send a secret message to Alice. Then Alice secretely generates a private and a public key and sends only the public one to Bob. Now Bob encrypts the message and sends it to Alice, who can use her private key to decrypt it. Even if Eve (short for *eavesdropper*, an unauthorized listener) listens to every message exchanged, she won't be able to decypher the secret: the private key has never left Alice's house!\n",
859 "\n",
860 "Notice that such a protocol is *asymmetric*: if Alice wanted to send a secret to Bob in reply, Bob would need to generate a pair of keys of his own.\n",
861 "\n",
862 "Let's see how we can do this in practice, using number theory!\n",
863 "\n",
864 "## RSA\n",
865 "\n",
866 "As many other cryptography protocols, RSA is based on a Mathematical process that is easy to do in one direction, but very hard to invert. In this case the hard process is integer factorization, that is decomposing an integer number as a product of primes."
867 ]
868 },
869 {
870 "cell_type": "code",
871 "execution_count": 2,
872 "metadata": {},
873 "outputs": [
874 {
875 "name": "stdout",
876 "output_type": "stream",
877 "text": [
878 "True True False\n"
879 ]
880 }
881 ],
882 "source": [
883 "p = 100003100019100043100057100069\n",
884 "q = 100144655312449572059845328443\n",
885 "n = p*q\n",
886 "print(is_prime(p), is_prime(q), is_prime(p*q))\n",
887 "\n",
888 "# Use the command below to see how long it takes\n",
889 "#timeit(\"factor(n)\", number=1, repeat=1)"
890 ]
891 },
892 {
893 "cell_type": "markdown",
894 "metadata": {},
895 "source": [
896 "In order to generate the keys, Alice picks a number $n$ which is the product of two large primes $p$ and $q$ of more or less the same size. Finding such primes is relatively easy compared to factoring the number $n$ she obtained. Then she computes the Euler totient $\\varphi(n)=(p-1)(q-1)$ of $n$, which she can do because she knows that $n=pq$ - it would be impossible otherwise!\n",
897 "\n",
898 "Then Alice can compute two integers $(d,e)$ such that $de\\equiv 1\\pmod{\\varphi(n)}$. She will send the numbers $n$ and $d$ to Bob and keep $e$ secret. In this case the public key is the pair $(n,d)$, while $e$ is the private key.\n",
899 "\n",
900 "Of course, she does all of this using Sage!"
901 ]
902 },
903 {
904 "cell_type": "code",
905 "execution_count": 105,
906 "metadata": {},
907 "outputs": [
908 {
909 "data": {
910 "text/plain": [
911 "(419199544978969, 235530823946467, 80799425863927)"
912 ]
913 },
914 "execution_count": 105,
915 "metadata": {},
916 "output_type": "execute_result"
917 }
918 ],
919 "source": [
920 "def two_large_primes():\n",
921 " p, q = 0, 0\n",
922 " # We make sure that they are different\n",
923 " while p == q:\n",
924 " p = Primes()[randint(10^6, 2*10^6)]\n",
925 " q = Primes()[randint(10^6, 2*10^6)]\n",
926 " return p, q\n",
927 "\n",
928 "def random_unit_mod(N):\n",
929 " R = Integers(N)\n",
930 " d = R(0)\n",
931 " # We make sure that it is invertible\n",
932 " while not d.is_unit():\n",
933 " d = R.random_element()\n",
934 " return d\n",
935 "\n",
936 "def Alice_generate_keys():\n",
937 " p, q = two_large_primes()\n",
938 " n = p*q\n",
939 " phi_n = (p-1)*(q-1) # euler_phi(n) is slow!\n",
940 " \n",
941 " d = random_unit_mod(phi_n)\n",
942 " e = d^-1\n",
943 " return n, d, e\n",
944 "\n",
945 "Alice_generate_keys()"
946 ]
947 },
948 {
949 "cell_type": "markdown",
950 "metadata": {},
951 "source": [
952 "Now, how does Bob encrypt his message? Let's say he wants to send to Alice the number $m$ with $1<m<n$ (In practice he would like to send her some text with emojis, or maybe a voice message; but for computers everything is a number, and there are different ways to translate any sort of information to a number. He just chooses one of the many standard methods that already exist, no cryptography is needed in this step. If the message $m$ is too long, he can split it up in some pieces and repeat the process multiple times.)\n",
953 "\n",
954 "Now he computes $m^d\\pmod n$ and sends it back to Alice."
955 ]
956 },
957 {
958 "cell_type": "code",
959 "execution_count": 3,
960 "metadata": {},
961 "outputs": [
962 {
963 "data": {
964 "text/plain": [
965 "149461597163501"
966 ]
967 },
968 "execution_count": 3,
969 "metadata": {},
970 "output_type": "execute_result"
971 }
972 ],
973 "source": [
974 "def Bob_encrypt(m, n, d):\n",
975 " R = Integers(n)\n",
976 " return R(m)^d # Assume that n is large enough\n",
977 " \n",
978 "message = 42424242\n",
979 "Bob_encrypt(message, 419199544978969, 235530823946467)"
980 ]
981 },
982 {
983 "cell_type": "markdown",
984 "metadata": {},
985 "source": [
986 "Since $de\\equiv 1\\pmod{\\varphi(n)}$, it follows that $(m^d)^e\\equiv m\\pmod n$ (see [Wikipedia: Euler's theorem](https://en.wikipedia.org/wiki/Euler%27s_theorem)). So for Alice it is very easy to get back the original message:"
987 ]
988 },
989 {
990 "cell_type": "code",
991 "execution_count": 108,
992 "metadata": {},
993 "outputs": [
994 {
995 "data": {
996 "text/plain": [
997 "42424242"
998 ]
999 },
1000 "execution_count": 108,
1001 "metadata": {},
1002 "output_type": "execute_result"
1003 }
1004 ],
1005 "source": [
1006 "def Alice_decrypt(m_encrypted, n, e):\n",
1007 " R = Integers(n)\n",
1008 " return R(m_encrypted)^e\n",
1009 "\n",
1010 "Alice_decrypt(149461597163501, 419199544978969, 80799425863927)"
1011 ]
1012 },
1013 {
1014 "cell_type": "markdown",
1015 "metadata": {},
1016 "source": [
1017 "Another assumption on which RSA relies is that even if one knows $M=m^e$ and $e$, extracting the $e$-th root of $M$ modulo $n$ (and thus obtaining $m$) is very hard. Currently the best known way to do this is by factorizing $n$ first, which is considered to be a very hard problem. However, there is no proof that faster algorithms can't be devised.\n",
1018 "\n",
1019 "Moreover, one day we will overcome the current technological difficulties and quantum computers will be available. Quantum computers are not just \"more powerful\" than classical hardware, but they work based on completely different logical foundations and they make the factorization problem much easier to solve: for example [Shor's algorithm](https://en.wikipedia.org/wiki/Shor%27s_algorithm) takes advantage of this different logic and can factorize numbers quickly, if run on a quantum computer.\n",
1020 "\n",
1021 "To this day the largest number factorized with a quantum computer is $21=3\\times 7$. Nonetheless, quantum-safe cryptography protocols (i.e. based on problems that are hard to solve also with quantum computers) have already been developed."
1022 ]
1023 }
1024 ],
1025 "metadata": {
1026 "kernelspec": {
1027 "display_name": "SageMath 9.2",
1028 "language": "sage",
1029 "name": "sagemath"
1030 },
1031 "language_info": {
1032 "codemirror_mode": {
1033 "name": "ipython",
1034 "version": 3
1035 },
1036 "file_extension": ".py",
1037 "mimetype": "text/x-python",
1038 "name": "python",
1039 "nbconvert_exporter": "python",
1040 "pygments_lexer": "ipython3",
1041 "version": "3.8.5"
1042 }
1043 },
1044 "nbformat": 4,
1045 "nbformat_minor": 4
1046}
diff --git a/Lectures/7-SageAlgebra.ipynb b/Lectures/7-SageAlgebra.ipynb
index 59ea033..512f4e0 100644
--- a/Lectures/7-SageAlgebra.ipynb
+++ b/Lectures/7-SageAlgebra.ipynb
@@ -1024,7 +1024,7 @@
1024 ], 1024 ],
1025 "metadata": { 1025 "metadata": {
1026 "kernelspec": { 1026 "kernelspec": {
1027 "display_name": "SageMath 9.2", 1027 "display_name": "SageMath 9.0",
1028 "language": "sage", 1028 "language": "sage",
1029 "name": "sagemath" 1029 "name": "sagemath"
1030 }, 1030 },
@@ -1038,7 +1038,7 @@
1038 "name": "python", 1038 "name": "python",
1039 "nbconvert_exporter": "python", 1039 "nbconvert_exporter": "python",
1040 "pygments_lexer": "ipython3", 1040 "pygments_lexer": "ipython3",
1041 "version": "3.8.5" 1041 "version": "3.8.10"
1042 } 1042 }
1043 }, 1043 },
1044 "nbformat": 4, 1044 "nbformat": 4,
diff --git a/README.md b/README.md
index d5b7d7e..0f4b0b8 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ the beginning of the course is enough.
76 76
77Moreover, you should remove or replace the university logo and my email 77Moreover, you should remove or replace the university logo and my email
78address, which you can replace with your own or with my personal address 78address, which you can replace with your own or with my personal address
79`sebastiano [dot] tronto [at] gmail [dot] com`. 79`sebastiano@tronto.net`.
80 80
81Below you can find some details on how the course was taught. 81Below you can find some details on how the course was taught.
82 82
diff --git a/src/Lecture5/live/.ipynb_checkpoints/7-SageAlgebra-modified+solutions-checkpoint.ipynb b/src/Lecture5/live/.ipynb_checkpoints/7-SageAlgebra-modified+solutions-checkpoint.ipynb
new file mode 100644
index 0000000..737e8e9
--- /dev/null
+++ b/src/Lecture5/live/.ipynb_checkpoints/7-SageAlgebra-modified+solutions-checkpoint.ipynb
@@ -0,0 +1,1099 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "This lecture's notes are in a different format: the presentations for the $\\LaTeX$ part were made with $\\LaTeX$, so this one is made with Sage, or rather with the [Jupyter Notebook](https://jupyter.org/).\n",
8 "\n",
9 "# The Jupyter Notebook\n",
10 "**Reference:** [[1](https://jupyter.org/documentation)]\n",
11 "\n",
12 "The Jupyter Notebook is one of the default interfaces for SageMath, along with the command line interface. You can access it via web browser, but it is running locally on your device (notice the strange url: `http://localhost:8888/notebooks...`).\n",
13 "\n",
14 "You can create a new notebook by clicking on `New > SageMath 9.2`. You can also create a Python 3 notebook to write Python code.\n",
15 "\n",
16 "Jupyter saves and reads files in the `.ipynb` format. If you download the file for this lecture you can open it and follow the examples interactively.\n",
17 "\n",
18 "## Cells\n",
19 "\n",
20 "The notebook contains one or more *interactive cells* that you can run, like this one below:"
21 ]
22 },
23 {
24 "cell_type": "code",
25 "execution_count": null,
26 "metadata": {},
27 "outputs": [],
28 "source": [
29 "# Exercise: modify this cell to use the print() command\n",
30 "\n",
31 "a = 34*102\n",
32 "\n",
33 "print(2+2)\n",
34 "print(\"hello\")\n",
35 "print(a-1)"
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "metadata": {},
41 "source": [
42 "If you are reading this from Jupyter rather than from the pdf file, you can edit the cell above and run it again. You can also add more cells by selecting `Insert` from the menu bar.\n",
43 "\n",
44 "Notice that only the last statement produces an output. You can force anything to be written as output with the `print()` command, which works like in Python. As an exercise, try to modify the cell above to provide more output!"
45 ]
46 },
47 {
48 "cell_type": "code",
49 "execution_count": null,
50 "metadata": {},
51 "outputs": [],
52 "source": [
53 "print(a)"
54 ]
55 },
56 {
57 "cell_type": "markdown",
58 "metadata": {},
59 "source": [
60 "text *hello*\n",
61 "* this\n",
62 "* is\n",
63 "* a list"
64 ]
65 },
66 {
67 "cell_type": "markdown",
68 "metadata": {},
69 "source": [
70 "## Markdown\n",
71 "\n",
72 "[Markdown](https://en.wikipedia.org/wiki/Markdown) is a simple markup language - think of LaTeX or html, but much simpler.\n",
73 "You can add text to your notebook with Markdown cells by selecting `Cell > Cell Type > Markdown`.\n",
74 "\n",
75 "You can also include some LaTeX code in Markdown cells, with dollar signs $ or align environments:\n",
76 "\n",
77 "\\begin{align*}\n",
78 "\\frac{(x+y)^2}{x+1} = \\frac{x^2+2xy+y^2}{x+1}\n",
79 "\\end{align*}\n",
80 "\n",
81 "When you are done writing a Markdown cell, you can run it to see the well-formatted text. To edit the text again, double-click on the cell. Try doing it now to fix the formula above!"
82 ]
83 },
84 {
85 "cell_type": "markdown",
86 "metadata": {},
87 "source": [
88 "# Symbolic expressions\n",
89 "\n",
90 "**Reference:** [[2](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html)]\n",
91 "\n",
92 "Now, let's get started with Sage. One thing you might want to do is manipulating symbolic expressions, like the following:"
93 ]
94 },
95 {
96 "cell_type": "code",
97 "execution_count": 48,
98 "metadata": {},
99 "outputs": [
100 {
101 "name": "stdout",
102 "output_type": "stream",
103 "text": [
104 "[\n",
105 "x == -1/2*(I*sqrt(3) + 1)*(1/2*I*sqrt(3) - 1/2)^(1/3) + (1/2*I*sqrt(3) - 1/2)^(2/3) - 1,\n",
106 "x == (1/2*I*sqrt(3) - 1/2)^(4/3) - 1/2*(I*sqrt(3) + 1)/(1/2*I*sqrt(3) - 1/2)^(1/3) - 1,\n",
107 "x == (1/2*I*sqrt(3) - 1/2)^(1/3) + 1/(1/2*I*sqrt(3) - 1/2)^(1/3) - 1\n",
108 "]\n"
109 ]
110 }
111 ],
112 "source": [
113 "f = (x^2 + 2*x - 5 >= 0)\n",
114 "solve(f,x)\n",
115 "\n",
116 "g = x^3 + 3*x^2-1\n",
117 "print(solve(g==0, x))\n",
118 "\n",
119 "h = x^2 +3*x -1"
120 ]
121 },
122 {
123 "cell_type": "markdown",
124 "metadata": {},
125 "source": [
126 "Notice that the single `=` is part of an assignment, as in Python: we are *assigning* to the variable `f` the value `x^2 + 2*x - 5 >= 0`, which in this case is an equation, so it contains the symbol `==`. Keep in mind the difference between the two!\n",
127 "\n",
128 "**Exercise:** change the code above to solve the corresponding inequality $x^2+2x-5\\geq 0$."
129 ]
130 },
131 {
132 "cell_type": "markdown",
133 "metadata": {},
134 "source": [
135 "## Mathematical variables\n",
136 "\n",
137 "Last time we saw what *variables* are in Python, and that they are a little bit different from the *Mathematical variables* that you use in Mathematics. In Sage, both concepts are present, but they are still distinct. For example in the cell above `f` is a variable in the sense of computer science, while `x` is a Mathematical variable.\n",
138 "\n",
139 "If you want to use Mathematical variables other than `x`, you first need to *declare* them with the `var()` command:"
140 ]
141 },
142 {
143 "cell_type": "code",
144 "execution_count": null,
145 "metadata": {},
146 "outputs": [],
147 "source": [
148 "var('z')\n",
149 "solve(z^2 + z - 2 == 0, z)"
150 ]
151 },
152 {
153 "cell_type": "markdown",
154 "metadata": {},
155 "source": [
156 "Try removing the first line in the cell above and see what error you get!\n",
157 "\n",
158 "Here is another example:"
159 ]
160 },
161 {
162 "cell_type": "code",
163 "execution_count": null,
164 "metadata": {},
165 "outputs": [],
166 "source": [
167 "var('a', 'b')\n",
168 "f = x^2+a*x+b == 0\n",
169 "solve(f,a)"
170 ]
171 },
172 {
173 "cell_type": "markdown",
174 "metadata": {},
175 "source": [
176 "Some common constants are [already defined](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html) in Sage:"
177 ]
178 },
179 {
180 "cell_type": "code",
181 "execution_count": null,
182 "metadata": {},
183 "outputs": [],
184 "source": [
185 "e^(pi*I)\n",
186 "print(N(pi), N(e))\n",
187 "e = 42\n",
188 "print(e)\n",
189 "reset('e')\n",
190 "print(N(e))"
191 ]
192 },
193 {
194 "cell_type": "markdown",
195 "metadata": {},
196 "source": [
197 "We will study symbolic expressions more in detail next time, in the context of calculus/analysis."
198 ]
199 },
200 {
201 "cell_type": "markdown",
202 "metadata": {},
203 "source": [
204 "# Basic rings and fields\n",
205 "\n",
206 "**References:** [[3](https://doc.sagemath.org/html/en/reference/rings_standard/index.html)]\n",
207 "[[4](https://doc.sagemath.org/html/en/reference/rings_numerical/index.html)]\n",
208 "[[5](https://doc.sagemath.org/html/en/reference/finite_rings/index.html)]\n",
209 "\n",
210 "As you should know, a *field* is a Mathematical structure with two operations, addition and multiplication, which respect certain rules (distributivity, associativity, commutativity...). Some examples of fields are the Rational numbers $\\mathbb Q$, the Real numbers $\\mathbb R$ and the Complex numbers $\\mathbb C$, but there are many more. As you should also know, a *(commutative) ring* is like a field, except not all elements different from $0$ need have a multiplicative inverse. For example the integers $\\mathbb Z = \\{ \\dots, -1, 0, 1, 2, \\dots\\}$ are a ring, but not a field.\n",
211 "\n",
212 "These structures are already implemented in Sage. Some of the most common are listed in the following table:\n",
213 "\n",
214 "|Mathematical object|Math symbol|Sage name|\n",
215 "|------------------:|:---------:|:--------|\n",
216 "|Integers|$\\mathbb Z$|`ZZ`|\n",
217 "|Rational numbers|$\\mathbb Q$|`QQ`|\n",
218 "|Real numbers|$\\mathbb R$|`RR`|\n",
219 "|Complex numbers|$\\mathbb C$|`CC`|\n",
220 "|Integers modulo $n$|$\\mathbb Z/n\\mathbb Z$|`Integers(n)`|\n",
221 "|Finite fields|$\\mathbb F_p$|GF(p)|\n",
222 "|$\\dots$|$\\dots$|$\\dots$|"
223 ]
224 },
225 {
226 "cell_type": "markdown",
227 "metadata": {},
228 "source": [
229 "If you write a number or an expression, Sage will figure out where it \"lives\", choosing the most restrictive interpretation possible. For example `3` will be interpreted to be an integer, even if it is also a rational number, a real number and a complex number."
230 ]
231 },
232 {
233 "cell_type": "markdown",
234 "metadata": {},
235 "source": [
236 "## Parents and coercion\n",
237 "**Reference:** [[6](https://doc.sagemath.org/html/en/tutorial/tour_coercion.html)]\n",
238 "\n",
239 "You can check where an object \"lives\" with the `parent()` command. It works more or less like the Python command `type()`, but it gives a more Mathematically inclined answer. Check the reference link [6] above if you want more details."
240 ]
241 },
242 {
243 "cell_type": "code",
244 "execution_count": null,
245 "metadata": {},
246 "outputs": [],
247 "source": [
248 "#Edit this cell to find out the type of other objects that we used\n",
249 "print(parent(3/5))\n",
250 "print(QQ)\n",
251 "print(type(3/5))"
252 ]
253 },
254 {
255 "cell_type": "markdown",
256 "metadata": {},
257 "source": [
258 "Sometimes Sage does not give you the best possible interpretation, so you can force something to be interpreted as living in a smaller ring as follows:"
259 ]
260 },
261 {
262 "cell_type": "code",
263 "execution_count": null,
264 "metadata": {},
265 "outputs": [],
266 "source": [
267 "minus_one = e^(pi*I)\n",
268 "print(minus_one)\n",
269 "minus_one_coerced = ZZ(e^(pi*I)) # coercion\n",
270 "#print(ZZ(1/2))\n",
271 "print(parent(minus_one))\n",
272 "print(parent(x^2))\n",
273 "print(parent(minus_one_coerced))\n",
274 "print(parent(5.2))\n",
275 "print(parent(QQ(5.2)))"
276 ]
277 },
278 {
279 "cell_type": "markdown",
280 "metadata": {},
281 "source": [
282 "**Remark.** Notice that there is a fundamental difference between the rings `RR` and `CC` and all the others in the table above: the real and complex numbers are *approximated*."
283 ]
284 },
285 {
286 "cell_type": "code",
287 "execution_count": null,
288 "metadata": {},
289 "outputs": [],
290 "source": [
291 "print(QQ(3))\n",
292 "print(RR(3))"
293 ]
294 },
295 {
296 "cell_type": "markdown",
297 "metadata": {},
298 "source": [
299 "You can also choose the precision of this approximation using the alternative name `RealField`."
300 ]
301 },
302 {
303 "cell_type": "code",
304 "execution_count": null,
305 "metadata": {},
306 "outputs": [],
307 "source": [
308 "print(RR)\n",
309 "print(RealField(prec=1000))"
310 ]
311 },
312 {
313 "cell_type": "markdown",
314 "metadata": {},
315 "source": [
316 "# Polynomial rings\n",
317 "\n",
318 "**Reference:** [[7](https://doc.sagemath.org/html/en/reference/polynomial_rings/index.html)]\n",
319 "\n",
320 "If you want to work with polynomials over a certain ring it is better to use this specific construction, rather than the symbolic expressions introduced above."
321 ]
322 },
323 {
324 "cell_type": "code",
325 "execution_count": 55,
326 "metadata": {},
327 "outputs": [
328 {
329 "name": "stdout",
330 "output_type": "stream",
331 "text": [
332 "Univariate Polynomial Ring in x over Rational Field\n",
333 "[]\n",
334 "[(-2, 2)]\n"
335 ]
336 }
337 ],
338 "source": [
339 "polring.<x> = QQ[] # Alternative: polring.<x,y,z> = PolynomialRing(RR)\n",
340 "polring\n",
341 "print(parent(x))\n",
342 "g = x^3 + 3*x^2-1\n",
343 "print(g.roots())\n",
344 "print((x^2+4*x+4).roots())"
345 ]
346 },
347 {
348 "cell_type": "markdown",
349 "metadata": {},
350 "source": [
351 "You can use as many variables as you like, and you can replace `RR` with any ring. In the example above `polring` is just the name of the variable (in the computer science sense) associated with this polynomial ring.\n",
352 "\n",
353 "## Operations on polynomials\n",
354 "\n",
355 "The usual Mathematical operations are available on polynomial rings, including Euclidean division `//` and remainder `%`. There is also the single-slash division `/`, but the result may not be a polynomial anymore.\n",
356 "\n",
357 "**Exercise:** use the `parent()` command to find out what the quotient of two polynomials is.\n",
358 "\n",
359 "**Question:** what happens if you remove the first line in the cell below? What if we used the variable `y` instead of `x`?"
360 ]
361 },
362 {
363 "cell_type": "code",
364 "execution_count": 60,
365 "metadata": {},
366 "outputs": [
367 {
368 "name": "stdout",
369 "output_type": "stream",
370 "text": [
371 "x + 1\n",
372 "-4\n",
373 "(x^2 + 2*x - 3)/(x + 1)\n",
374 "Fraction Field of Univariate Polynomial Ring in x over Rational Field\n"
375 ]
376 },
377 {
378 "data": {
379 "text/plain": [
380 "x^4 + 2*x^3 - 4*x^2 - 2*x + 3"
381 ]
382 },
383 "execution_count": 60,
384 "metadata": {},
385 "output_type": "execute_result"
386 }
387 ],
388 "source": [
389 "polring.<x> = QQ[]\n",
390 "p = x^2 + 2*x - 3 # Don't forget * for multiplication!\n",
391 "q = p // (x+1)\n",
392 "r = p % (x+1)\n",
393 "f = p / (x+1)\n",
394 "print(q)\n",
395 "print(r)\n",
396 "print(f)\n",
397 "print(parent(f))\n",
398 "p*(x^2-1)"
399 ]
400 },
401 {
402 "cell_type": "markdown",
403 "metadata": {},
404 "source": [
405 "You can do more complex operations. Try out `roots()` and `factor` in the cell below.\n",
406 "\n",
407 "**Remark.** Notice how the result can change substantially if you change the base ring.\n",
408 "\n",
409 "**Remark.** [Factorizations](https://doc.sagemath.org/html/en/reference/structure/sage/structure/factorization.html) are a particular object in Sage. They are kinda like a list, but not really. You can get a list of pairs (factor, power) with `list(factor(f))`."
410 ]
411 },
412 {
413 "cell_type": "code",
414 "execution_count": 76,
415 "metadata": {
416 "scrolled": true
417 },
418 "outputs": [
419 {
420 "name": "stdout",
421 "output_type": "stream",
422 "text": [
423 "(t + 1) * (t^2 - 3) * (t^2 + 1)\n",
424 "[(t + 1, 1), (t^2 - 3, 1), (t^2 + 1, 1)]\n",
425 "t^5 + t^4 - 2*t^3 - 2*t^2 - 3*t - 3\n",
426 "t^2 - 1\n",
427 "[(-1, 1)]\n",
428 "Multivariate Polynomial Ring in x, y, z over Rational Field\n"
429 ]
430 },
431 {
432 "data": {
433 "text/plain": [
434 "Multivariate Polynomial Ring in x, y, z over Rational Field"
435 ]
436 },
437 "execution_count": 76,
438 "metadata": {},
439 "output_type": "execute_result"
440 }
441 ],
442 "source": [
443 "polring_onevar.<t> = QQ[]\n",
444 "\n",
445 "f = t^5 + t^4 - 2*t^3 - 2*t^2 - 3*t - 3\n",
446 "fact = factor(f)\n",
447 "print(factor(f))\n",
448 "print(list(fact))\n",
449 "print((t + 1) * (t^2 - 3) * (t^2 + 1))\n",
450 "print((t+1)*(t-1))\n",
451 "print(f.roots()) # Result: list of pairs (root,multiplicity)\n",
452 "\n",
453 "polring_manyvar.<x,y,z> = QQ[]\n",
454 "factor(x*y+x)\n",
455 "\n",
456 "# The following line gives an error, because the polynomial\n",
457 "# is understood to possibly have many variables:\n",
458 "print(parent(x))\n",
459 "(QQ['x'](x^2-1)).roots()\n",
460 "parent(x)"
461 ]
462 },
463 {
464 "cell_type": "markdown",
465 "metadata": {},
466 "source": [
467 "# Matrices and vectors\n",
468 "\n",
469 "**References:** [[8](https://doc.sagemath.org/html/en/reference/matrices/index.html)], but in particular the subections [[9](https://doc.sagemath.org/html/en/reference/matrices/sage/matrix/docs.html)] and [[10](https://doc.sagemath.org/html/en/reference/matrices/sage/matrix/matrix2.html)]\n",
470 "\n",
471 "In Sage you can easily manipulate matrices and vectors"
472 ]
473 },
474 {
475 "cell_type": "code",
476 "execution_count": 94,
477 "metadata": {},
478 "outputs": [
479 {
480 "name": "stdout",
481 "output_type": "stream",
482 "text": [
483 "[ 1 2 3]\n",
484 "[ 0 0 1]\n",
485 "[ 4 -3 22/7] \n",
486 "\n",
487 "[1/2 0 0]\n",
488 "[ 7 0 0]\n",
489 "[ 1 1 1] \n",
490 "\n",
491 "[1 0]\n",
492 "[0 1] \n",
493 "\n",
494 "(3/2, 21, 6) \n",
495 "\n",
496 "[ -7/2 -10 80/7]\n",
497 "[ 17 -4 15/7]\n",
498 "[ 241/7 -18/7 869/49] \n",
499 "\n",
500 "Rank of A = 3\n",
501 "Rank of B = 2\n"
502 ]
503 },
504 {
505 "data": {
506 "text/plain": [
507 "11"
508 ]
509 },
510 "execution_count": 94,
511 "metadata": {},
512 "output_type": "execute_result"
513 }
514 ],
515 "source": [
516 "A = matrix([[1,2,3],[0,0,1],[4,-3,22/7]])\n",
517 "B = matrix([[1/2,0,0],[7,0,0],[1,1,1]])\n",
518 "C = matrix([[1,0],[0,1]])\n",
519 "v = vector([3,4,-1])\n",
520 "\n",
521 "print(A, \"\\n\") # \\n just means \"newline\"\n",
522 "print(B, \"\\n\")\n",
523 "print(C, \"\\n\")\n",
524 "#print(A*C) Error!\n",
525 "print(B*v, \"\\n\")\n",
526 "print(A^2 + 2*B - A*B, \"\\n\")\n",
527 "\n",
528 "print(\"Rank of A =\", rank(A)) # You can also use A.rank()\n",
529 "print(\"Rank of B =\", rank(B))\n",
530 "A.determinant()"
531 ]
532 },
533 {
534 "cell_type": "markdown",
535 "metadata": {},
536 "source": [
537 "**Exercise:** in the cell above, compute the determinant, inverse and characteristic polynomial of the matrix `A`. *Hint: look at the reference [10] above (the functions are listed in alphabetic order).*\n",
538 "\n",
539 "As for polynomials, you can specify where a matrix or a vector lives"
540 ]
541 },
542 {
543 "cell_type": "code",
544 "execution_count": 97,
545 "metadata": {},
546 "outputs": [
547 {
548 "data": {
549 "text/plain": [
550 "Full MatrixSpace of 2 by 2 dense matrices over Complex Field with 53 bits of precision"
551 ]
552 },
553 "execution_count": 97,
554 "metadata": {},
555 "output_type": "execute_result"
556 }
557 ],
558 "source": [
559 "M = matrix(CC, [[0,1/2],[1,0]])\n",
560 "parent(M)"
561 ]
562 },
563 {
564 "cell_type": "markdown",
565 "metadata": {},
566 "source": [
567 "You can also solve linear systems and compute eigenvalues and eigenvectors of a matrix\n",
568 "\n",
569 "**Warning.** In linear algebra there are distinct concepts of *left* and *right* eigenvalues (and eigenvector). The one you know is probably that of **right** eigen-{value,vector}, that is an element $\\lambda$ of the base field and a non-zero vector $\\mathbf v$ with $A\\mathbf v=\\lambda\\mathbf v$. The other concept corresponds to the equality $\\mathbf v^TA=\\lambda \\mathbf v$."
570 ]
571 },
572 {
573 "cell_type": "code",
574 "execution_count": null,
575 "metadata": {},
576 "outputs": [],
577 "source": [
578 "A = Matrix(RR, [[sqrt(59),32],[-1/4,3]])\n",
579 "v = vector(RR, [3,0])\n",
580 "A.solve_right(v) # Solve Ax=v. Alternative: A \\ v"
581 ]
582 },
583 {
584 "cell_type": "code",
585 "execution_count": 103,
586 "metadata": {},
587 "outputs": [
588 {
589 "name": "stderr",
590 "output_type": "stream",
591 "text": [
592 "<ipython-input-103-d1ccc4990851>:2: UserWarning: Using generic algorithm for an inexact ring, which will probably give incorrect results due to numerical precision issues.\n",
593 " A.eigenvalues() # Also: A.eigenvalues(), A.eigenvectors_right()\n"
594 ]
595 },
596 {
597 "data": {
598 "text/plain": [
599 "[5.37228132326901, -0.372281323269014]"
600 ]
601 },
602 "execution_count": 103,
603 "metadata": {},
604 "output_type": "execute_result"
605 }
606 ],
607 "source": [
608 "A = Matrix(RR, [[1,2],[3,4]])\n",
609 "A.eigenvalues() # Also: A.eigenvalues(), A.eigenvectors_right()"
610 ]
611 },
612 {
613 "cell_type": "markdown",
614 "metadata": {},
615 "source": [
616 "We can also extract a specific submatrix by selecting only some rows and columns, with a syntax similar to that of Python's lists. Check out more examples in the reference [9] above, and try them in the cell below."
617 ]
618 },
619 {
620 "cell_type": "code",
621 "execution_count": 105,
622 "metadata": {},
623 "outputs": [
624 {
625 "name": "stdout",
626 "output_type": "stream",
627 "text": [
628 "[ -3 -25 -5 -3 61 0 -1]\n",
629 "[ 23 0 -1 1 0 1 -1]\n",
630 "[286 2 7 0 -21 -1 0]\n",
631 "[ 2 -1 -2 0 -1 4 0]\n",
632 "[ 1 -1 1 0 2 -2 7]\n",
633 "[ 0 15 -1 0 -3 1 -1]\n",
634 "[ -1 1 -2 0 2 1 1] \n",
635 "\n",
636 "[ -1 1 0]\n",
637 "[ 7 0 -21] \n",
638 "\n",
639 "[ -3 -25 -5 -3 61 0 -1] \n",
640 "\n",
641 "[ -3 -25 -5 -3 61]\n",
642 "[ 0 15 -1 0 -3]\n",
643 "[286 2 7 0 -21]\n",
644 "-25\n"
645 ]
646 }
647 ],
648 "source": [
649 "A = MatrixSpace(ZZ, 7).random_element()\n",
650 "print(A, \"\\n\")\n",
651 "print(A[1:3,2:5], \"\\n\") # Rows from 1 to 3, columns from 2 to 5\n",
652 "print(A[0,0:], \"\\n\") # First row, all columns\n",
653 "print(A[[0,5,2],0:5]) # Rows 0, 5 and 2 (in this order) and columns 0 to 5\n",
654 "print(A[0,1])"
655 ]
656 },
657 {
658 "cell_type": "markdown",
659 "metadata": {},
660 "source": [
661 "**Exercise:** write a sage function that computes the determinant of an $n\\times n$ matrix $A=(a_{ij})$ using Laplace's rule by the first row, that is \n",
662 "\\begin{align*}\n",
663 " \\operatorname{det}A = \\sum_{j=1}^n (-1)^ja_{0j}M_{0j}\n",
664 "\\end{align*}\n",
665 "where $M_{0j}$ is the determinant of the $(n-1)\\times(n-1)$ matrix obtained by removing the $0$-th row and the $j$-th column from $A$."
666 ]
667 },
668 {
669 "cell_type": "code",
670 "execution_count": 6,
671 "metadata": {},
672 "outputs": [
673 {
674 "name": "stdout",
675 "output_type": "stream",
676 "text": [
677 "[ -1 -3 -1 11 2 -1 -5]\n",
678 "[ 1 0 0 -6 -1 0 1]\n",
679 "[ 1 0 -1 0 1 -1 0]\n",
680 "[-24 1 -2 -7 4 0 1]\n",
681 "[ -3 0 -1 0 6 -1 0]\n",
682 "[-17 -1 1 0 28 1 0]\n",
683 "[ 1 -4 1 1 -2 -6 -2]\n",
684 "Sage determinant: 13578\n",
685 "my_det: 13578\n"
686 ]
687 }
688 ],
689 "source": [
690 "def my_det(A):\n",
691 " if not A.is_square():\n",
692 " print(\"Error: matrix is not square\")\n",
693 " \n",
694 " n = A.nrows() # size of the matrix\n",
695 " \n",
696 " if n == 1:\n",
697 " return A[0,0]\n",
698 " \n",
699 " my_sum = 0\n",
700 " for j in range(0,n):\n",
701 " rows = range(1,n)\n",
702 " columns = [element for element in range(0,n) if element != j]\n",
703 " submatrix = A[rows,columns]\n",
704 " my_sum += (-1)^j * A[0,j] * my_det(submatrix)\n",
705 " \n",
706 " return my_sum\n",
707 "\n",
708 "A = MatrixSpace(ZZ, 7).random_element()\n",
709 "print(A)\n",
710 "print(\"Sage determinant: \", A.determinant())\n",
711 "print(\"my_det: \", my_det(A))"
712 ]
713 },
714 {
715 "cell_type": "markdown",
716 "metadata": {},
717 "source": [
718 "# Number Theory\n",
719 "\n",
720 "**Reference:** [[11](https://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/integer.html)]\n",
721 "\n",
722 "Sage includes a large library of functions for computing with the integers, see the link above."
723 ]
724 },
725 {
726 "cell_type": "code",
727 "execution_count": 8,
728 "metadata": {},
729 "outputs": [
730 {
731 "name": "stdout",
732 "output_type": "stream",
733 "text": [
734 "3^2 * 3607 * 3803\n",
735 "[(3, 2), (3607, 1), (3803, 1)]\n",
736 "True\n",
737 "True\n",
738 "619703040\n",
739 "9\n",
740 "13548070123626141\n"
741 ]
742 }
743 ],
744 "source": [
745 "n = 123456789\n",
746 "m = 987654321\n",
747 "p = 3607\n",
748 "\n",
749 "print(factor(n))\n",
750 "print(list(factor(n)))\n",
751 "print(is_prime(p))\n",
752 "print(p.divides(n))\n",
753 "print(euler_phi(m))\n",
754 "print(gcd(n, m))\n",
755 "print(lcm(n, m))"
756 ]
757 },
758 {
759 "cell_type": "markdown",
760 "metadata": {},
761 "source": [
762 "## Primes\n",
763 "\n",
764 "**Reference:** [[12](https://doc.sagemath.org/html/en/reference/sets/sage/sets/primes.html)]\n",
765 "\n",
766 "The set of prime numbers is called `Primes()`. It is like an infinite list: for example you can get the one-millionth prime number or you can use this list to create other lists. You can also check what the first prime number larger than a given number is."
767 ]
768 },
769 {
770 "cell_type": "code",
771 "execution_count": null,
772 "metadata": {},
773 "outputs": [
774 {
775 "name": "stdout",
776 "output_type": "stream",
777 "text": [
778 "Set of all prime numbers: 2, 3, 5, 7, ...\n",
779 "31 252097800629\n",
780 "47\n",
781 "[79, 83, 89, 97]\n"
782 ]
783 }
784 ],
785 "source": [
786 "PP = Primes()\n",
787 "print(PP)\n",
788 "print(PP[10], PP[10^10])\n",
789 "print(PP.next(44))\n",
790 "\n",
791 "First_Thousand_Primes = PP[0:1000]\n",
792 "print([p for p in First_Thousand_Primes if p < 100 and p > 75])\n",
793 "#print([p for p in PP if p < 100 and p > 75])"
794 ]
795 },
796 {
797 "cell_type": "markdown",
798 "metadata": {},
799 "source": [
800 "## The Chinese remainder theorem (CRT)\n",
801 "\n",
802 "We say that two integers $a$ and $b$ are *congruent* modulo another integer $n>0$ if they have the same remainder when divided by $n$. We denote this by $a\\equiv b\\pmod n$, or in Python/Sage syntax `a % n == b % n`.\n",
803 "\n",
804 "The Chinese remainder theorem states that if $a,b\\in\\mathbb Z$ and $n,m\\in \\mathbb Z_{>0}$ are such that $\\gcd(n,m)=1$ then the system of congruences\n",
805 "\n",
806 "\\begin{align*}\n",
807 "\\begin{cases}\n",
808 " x \\equiv a \\pmod n\\\\\n",
809 " x \\equiv b \\pmod m\n",
810 "\\end{cases}\n",
811 "\\end{align*}\n",
812 "\n",
813 "\n",
814 "has exactly one solution modulo $mn$. This means that there is one and only one number $x$ with $0\\leq x<mn$ such that $x\\equiv a\\pmod n$ and $x\\equiv b\\pmod m$.\n",
815 "\n",
816 "\n",
817 "For example:\n",
818 "\n",
819 "\\begin{align*}\n",
820 "\\begin{cases}\n",
821 " x \\equiv 1 \\pmod 3\\\\\n",
822 " x \\equiv 2 \\pmod 5\n",
823 "\\end{cases}\n",
824 "\\end{align*}\n",
825 "\n",
826 "Solution: $x=7$ (any other solution is congruent to $7$ modulo $15$; for example $22=15+7$ is also a solution).\n",
827 "\n",
828 "The procedure to find such a number is not too hard to describe (you might see it in an algebra or number theory course), but it can be a bit long. Luckily, Sage can do this for you:"
829 ]
830 },
831 {
832 "cell_type": "code",
833 "execution_count": 1,
834 "metadata": {},
835 "outputs": [
836 {
837 "name": "stdout",
838 "output_type": "stream",
839 "text": [
840 "74306 2 798\n"
841 ]
842 }
843 ],
844 "source": [
845 "a = 2\n",
846 "b = -1\n",
847 "n = 172\n",
848 "m = 799\n",
849 "\n",
850 "if gcd(n,m) != 1:\n",
851 " print(\"The numbers are not comprime, I can't solve this!\")\n",
852 "else:\n",
853 " x = crt(a, b, n, m)\n",
854 " print(x, x%n, x%m)"
855 ]
856 },
857 {
858 "cell_type": "markdown",
859 "metadata": {},
860 "source": [
861 "**Exercise.** There is a more general version of the Chinese remainder theorem which says that if $a_0, a_1, \\dots, a_k\\in\\mathbb Z$ and $n_0, n_2, \\dots, n_k\\in\\mathbb Z_{>0}$ are such that $\\gcd(n_i, n_j)=1$ for $i\\neq j$, then the system of congruences\n",
862 "\n",
863 "\\begin{align*}\n",
864 "\\begin{cases}\n",
865 " x \\equiv a_0 \\pmod {n_0}\\\\\n",
866 " x \\equiv a_1 \\pmod {n_1}\\\\\n",
867 " \\dots \\\\\n",
868 " x \\equiv a_k \\pmod {n_k}\n",
869 "\\end{cases}\n",
870 "\\end{align*}\n",
871 "\n",
872 "has exactly one solution modulo $\\prod_{i=0}^kn_i$. Use the `crt()` function to find a solution to such a system.\n",
873 "*Hint: start by running the command `help(crt)`."
874 ]
875 },
876 {
877 "cell_type": "code",
878 "execution_count": 3,
879 "metadata": {},
880 "outputs": [],
881 "source": [
882 "#help(crt)"
883 ]
884 },
885 {
886 "cell_type": "markdown",
887 "metadata": {},
888 "source": [
889 "# Cryptography: RSA\n",
890 "\n",
891 "[Cryptography](https://en.wikipedia.org/wiki/Cryptography) is the discipline that studies methods to communicate secrets in such a way that any unauthorized listener would not be able to understand the message.\n",
892 "\n",
893 "A simple cryptographic protocol could be changing every letter of your text following a fixed scheme (or *cypher*), for example by turning every A into a B, every B into a C and so on. However this is not a very secure method, for many reasons. One of them is that at some point the people who want to communicate need to agree on what method to use, and anyone listening to that conversation would be able to decypher every subsequent conversation. A public-key cryptographic protocol solves this problem.\n",
894 "\n",
895 "## Public-key cryptography\n",
896 "\n",
897 "Public-key cryptographic protocols, such as RSA, work like this: there are two keys, a *private* key that is only known to person A (traditionally called Alice in every example), and a *public* key that does not need to be secret.\n",
898 "\n",
899 "The public key is used to *encrypt* the message (that is to \"lock\" it, or \"hyde\" it), but one needs the private key to *decrypt* it. Imagine having two keys for your door, but one can only be used to lock it, while the other only to open it.\n",
900 "\n",
901 "The message exchange works like this: suppose that person B (Bob) wants to send a secret message to Alice. Then Alice secretely generates a private and a public key and sends only the public one to Bob. Now Bob encrypts the message and sends it to Alice, who can use her private key to decrypt it. Even if Eve (short for *eavesdropper*, an unauthorized listener) listens to every message exchanged, she won't be able to decypher the secret: the private key has never left Alice's house!\n",
902 "\n",
903 "Notice that such a protocol is *asymmetric*: if Alice wanted to send a secret to Bob in reply, Bob would need to generate a pair of keys of his own.\n",
904 "\n",
905 "Let's see how we can do this in practice, using number theory!\n",
906 "\n",
907 "## RSA\n",
908 "\n",
909 "As many other cryptography protocols, RSA is based on a Mathematical process that is easy to do in one direction, but very hard to invert. In this case the hard process is integer factorization, that is decomposing an integer number as a product of primes."
910 ]
911 },
912 {
913 "cell_type": "code",
914 "execution_count": 5,
915 "metadata": {},
916 "outputs": [
917 {
918 "name": "stdout",
919 "output_type": "stream",
920 "text": [
921 "True True False\n"
922 ]
923 },
924 {
925 "data": {
926 "text/plain": [
927 "1 loop, best of 1: 9.06 s per loop"
928 ]
929 },
930 "execution_count": 5,
931 "metadata": {},
932 "output_type": "execute_result"
933 }
934 ],
935 "source": [
936 "p = 100003100019100043100057100069\n",
937 "q = 100144655312449572059845328443\n",
938 "n = p*q\n",
939 "print(is_prime(p), is_prime(q), is_prime(p*q))\n",
940 "\n",
941 "# Use the command below to see how long it takes\n",
942 "timeit(\"factor(n)\", number=1, repeat=1)"
943 ]
944 },
945 {
946 "cell_type": "markdown",
947 "metadata": {},
948 "source": [
949 "In order to generate the keys, Alice picks a number $n$ which is the product of two large primes $p$ and $q$ of more or less the same size. Finding such primes is relatively easy compared to factoring the number $n$ she obtained. Then she computes the Euler totient $\\varphi(n)=(p-1)(q-1)$ of $n$, which she can do because she knows that $n=pq$ - it would be impossible otherwise!\n",
950 "\n",
951 "Then Alice can compute two integers $(d,e)$ such that $de\\equiv 1\\pmod{\\varphi(n)}$. She will send the numbers $n$ and $d$ to Bob and keep $e$ secret. In this case the public key is the pair $(n,d)$, while $e$ is the private key.\n",
952 "\n",
953 "Of course, she does all of this using Sage!"
954 ]
955 },
956 {
957 "cell_type": "code",
958 "execution_count": 6,
959 "metadata": {},
960 "outputs": [
961 {
962 "data": {
963 "text/plain": [
964 "(338547806707501, 141995674537431, 107165393087271)"
965 ]
966 },
967 "execution_count": 6,
968 "metadata": {},
969 "output_type": "execute_result"
970 }
971 ],
972 "source": [
973 "def two_large_primes():\n",
974 " p, q = 0, 0\n",
975 " # We make sure that they are different\n",
976 " while p == q:\n",
977 " p = Primes()[randint(10^6, 2*10^6)]\n",
978 " q = Primes()[randint(10^6, 2*10^6)]\n",
979 " return p, q\n",
980 "\n",
981 "def random_unit_mod(N):\n",
982 " R = Integers(N)\n",
983 " d = R(0)\n",
984 " # We make sure that it is invertible\n",
985 " while not d.is_unit():\n",
986 " d = R.random_element()\n",
987 " return d\n",
988 "\n",
989 "def Alice_generate_keys():\n",
990 " p, q = two_large_primes()\n",
991 " n = p*q\n",
992 " phi_n = (p-1)*(q-1) # euler_phi(n) is slow!\n",
993 " \n",
994 " d = random_unit_mod(phi_n)\n",
995 " e = d^-1\n",
996 " return n, d, e\n",
997 "\n",
998 "Alice_generate_keys()"
999 ]
1000 },
1001 {
1002 "cell_type": "markdown",
1003 "metadata": {},
1004 "source": [
1005 "Now, how does Bob encrypt his message? Let's say he wants to send to Alice the number $m$ with $1<m<n$ (In practice he would like to send her some text with emojis, or maybe a voice message; but for computers everything is a number, and there are different ways to translate any sort of information to a number. He just chooses one of the many standard methods that already exist, no cryptography is needed in this step. If the message $m$ is too long, he can split it up in some pieces and repeat the process multiple times.)\n",
1006 "\n",
1007 "Now he computes $m^d\\pmod n$ and sends it back to Alice."
1008 ]
1009 },
1010 {
1011 "cell_type": "code",
1012 "execution_count": 7,
1013 "metadata": {},
1014 "outputs": [
1015 {
1016 "data": {
1017 "text/plain": [
1018 "177776139844621"
1019 ]
1020 },
1021 "execution_count": 7,
1022 "metadata": {},
1023 "output_type": "execute_result"
1024 }
1025 ],
1026 "source": [
1027 "def Bob_encrypt(m, n, d):\n",
1028 " R = Integers(n)\n",
1029 " return R(m)^d # Assume that n is large enough\n",
1030 " \n",
1031 "message = 42424242\n",
1032 "Bob_encrypt(message, 338547806707501, 141995674537431)"
1033 ]
1034 },
1035 {
1036 "cell_type": "markdown",
1037 "metadata": {},
1038 "source": [
1039 "Since $de\\equiv 1\\pmod{\\varphi(n)}$, it follows that $(m^d)^e\\equiv m\\pmod n$ (see [Wikipedia: Euler's theorem](https://en.wikipedia.org/wiki/Euler%27s_theorem)). So for Alice it is very easy to get back the original message:"
1040 ]
1041 },
1042 {
1043 "cell_type": "code",
1044 "execution_count": 8,
1045 "metadata": {},
1046 "outputs": [
1047 {
1048 "data": {
1049 "text/plain": [
1050 "42424242"
1051 ]
1052 },
1053 "execution_count": 8,
1054 "metadata": {},
1055 "output_type": "execute_result"
1056 }
1057 ],
1058 "source": [
1059 "def Alice_decrypt(m_encrypted, n, e):\n",
1060 " R = Integers(n)\n",
1061 " return R(m_encrypted)^e\n",
1062 "\n",
1063 "Alice_decrypt(177776139844621, 338547806707501, 107165393087271)"
1064 ]
1065 },
1066 {
1067 "cell_type": "markdown",
1068 "metadata": {},
1069 "source": [
1070 "Another assumption on which RSA relies is that even if one knows $M=m^e$ and $e$, extracting the $e$-th root of $M$ modulo $n$ (and thus obtaining $m$) is very hard. Currently the best known way to do this is by factorizing $n$ first, which is considered to be a very hard problem. However, there is no proof that faster algorithms can't be devised.\n",
1071 "\n",
1072 "Moreover, one day we will overcome the current technological difficulties and quantum computers will be available. Quantum computers are not just \"more powerful\" than classical hardware, but they work based on completely different logical foundations and they make the factorization problem much easier to solve: for example [Shor's algorithm](https://en.wikipedia.org/wiki/Shor%27s_algorithm) takes advantage of this different logic and can factorize numbers quickly, if run on a quantum computer.\n",
1073 "\n",
1074 "To this day the largest number factorized with a quantum computer is $21=3\\times 7$. Nonetheless, quantum-safe cryptography protocols (i.e. based on problems that are hard to solve also with quantum computers) have already been developed."
1075 ]
1076 }
1077 ],
1078 "metadata": {
1079 "kernelspec": {
1080 "display_name": "SageMath 9.0",
1081 "language": "sage",
1082 "name": "sagemath"
1083 },
1084 "language_info": {
1085 "codemirror_mode": {
1086 "name": "ipython",
1087 "version": 3
1088 },
1089 "file_extension": ".py",
1090 "mimetype": "text/x-python",
1091 "name": "python",
1092 "nbconvert_exporter": "python",
1093 "pygments_lexer": "ipython3",
1094 "version": "3.8.10"
1095 }
1096 },
1097 "nbformat": 4,
1098 "nbformat_minor": 4
1099}
diff --git a/src/Lecture5/live/7-SageAlgebra-modified+solutions.ipynb b/src/Lecture5/live/7-SageAlgebra-modified+solutions.ipynb
index f4e39b2..737e8e9 100644
--- a/src/Lecture5/live/7-SageAlgebra-modified+solutions.ipynb
+++ b/src/Lecture5/live/7-SageAlgebra-modified+solutions.ipynb
@@ -1077,7 +1077,7 @@
1077 ], 1077 ],
1078 "metadata": { 1078 "metadata": {
1079 "kernelspec": { 1079 "kernelspec": {
1080 "display_name": "SageMath 9.2", 1080 "display_name": "SageMath 9.0",
1081 "language": "sage", 1081 "language": "sage",
1082 "name": "sagemath" 1082 "name": "sagemath"
1083 }, 1083 },
@@ -1091,7 +1091,7 @@
1091 "name": "python", 1091 "name": "python",
1092 "nbconvert_exporter": "python", 1092 "nbconvert_exporter": "python",
1093 "pygments_lexer": "ipython3", 1093 "pygments_lexer": "ipython3",
1094 "version": "3.8.5" 1094 "version": "3.8.10"
1095 } 1095 }
1096 }, 1096 },
1097 "nbformat": 4, 1097 "nbformat": 4,
diff --git a/src/Retake/Retake1.aux b/src/Retake/Retake1.aux
new file mode 100644
index 0000000..405f9ed
--- /dev/null
+++ b/src/Retake/Retake1.aux
@@ -0,0 +1,4 @@
1\relax
2\newlabel{prop:fta}{{1}{1}}
3\newlabel{eq:fubini}{{2}{1}}
4\gdef \@abspage@last{4}
diff --git a/src/Retake/Retake1.log b/src/Retake/Retake1.log
new file mode 100644
index 0000000..d28cd96
--- /dev/null
+++ b/src/Retake/Retake1.log
@@ -0,0 +1,583 @@
1This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021/VoidLinux) (preloaded format=pdflatex 2021.12.14) 21 DEC 2021 11:16
2entering extended mode
3 \write18 enabled.
4 %&-line parsing enabled.
5**Retake1.tex
6(./Retake1.tex
7LaTeX2e <2020-10-01> patch level 4
8L3 programming layer <2021-02-18>
9(/usr/share/texmf-dist/tex/latex/base/article.cls
10Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
11(/usr/share/texmf-dist/tex/latex/base/size12.clo
12File: size12.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
13)
14\c@part=\count179
15\c@section=\count180
16\c@subsection=\count181
17\c@subsubsection=\count182
18\c@paragraph=\count183
19\c@subparagraph=\count184
20\c@figure=\count185
21\c@table=\count186
22\abovecaptionskip=\skip47
23\belowcaptionskip=\skip48
24\bibindent=\dimen138
25)
26(/usr/share/texmf-dist/tex/latex/base/inputenc.sty
27Package: inputenc 2020/08/01 v1.3d Input encoding file
28\inpenc@prehook=\toks15
29\inpenc@posthook=\toks16
30)
31(/usr/share/texmf-dist/tex/latex/amsmath/amsmath.sty
32Package: amsmath 2020/09/23 v2.17i AMS math features
33\@mathmargin=\skip49
34
35For additional information on amsmath, use the `?' option.
36(/usr/share/texmf-dist/tex/latex/amsmath/amstext.sty
37Package: amstext 2000/06/29 v2.01 AMS text
38
39(/usr/share/texmf-dist/tex/latex/amsmath/amsgen.sty
40File: amsgen.sty 1999/11/30 v2.0 generic functions
41\@emptytoks=\toks17
42\ex@=\dimen139
43))
44(/usr/share/texmf-dist/tex/latex/amsmath/amsbsy.sty
45Package: amsbsy 1999/11/29 v1.2d Bold Symbols
46\pmbraise@=\dimen140
47)
48(/usr/share/texmf-dist/tex/latex/amsmath/amsopn.sty
49Package: amsopn 2016/03/08 v2.02 operator names
50)
51\inf@bad=\count187
52LaTeX Info: Redefining \frac on input line 234.
53\uproot@=\count188
54\leftroot@=\count189
55LaTeX Info: Redefining \overline on input line 399.
56\classnum@=\count190
57\DOTSCASE@=\count191
58LaTeX Info: Redefining \ldots on input line 496.
59LaTeX Info: Redefining \dots on input line 499.
60LaTeX Info: Redefining \cdots on input line 620.
61\Mathstrutbox@=\box47
62\strutbox@=\box48
63\big@size=\dimen141
64LaTeX Font Info: Redeclaring font encoding OML on input line 743.
65LaTeX Font Info: Redeclaring font encoding OMS on input line 744.
66\macc@depth=\count192
67\c@MaxMatrixCols=\count193
68\dotsspace@=\muskip16
69\c@parentequation=\count194
70\dspbrk@lvl=\count195
71\tag@help=\toks18
72\row@=\count196
73\column@=\count197
74\maxfields@=\count198
75\andhelp@=\toks19
76\eqnshift@=\dimen142
77\alignsep@=\dimen143
78\tagshift@=\dimen144
79\tagwidth@=\dimen145
80\totwidth@=\dimen146
81\lineht@=\dimen147
82\@envbody=\toks20
83\multlinegap=\skip50
84\multlinetaggap=\skip51
85\mathdisplay@stack=\toks21
86LaTeX Info: Redefining \[ on input line 2923.
87LaTeX Info: Redefining \] on input line 2924.
88)
89(/usr/share/texmf-dist/tex/latex/amsfonts/amsfonts.sty
90Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
91\symAMSa=\mathgroup4
92\symAMSb=\mathgroup5
93LaTeX Font Info: Redeclaring math symbol \hbar on input line 98.
94LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold'
95(Font) U/euf/m/n --> U/euf/b/n on input line 106.
96)
97(/usr/share/texmf-dist/tex/latex/amsfonts/amssymb.sty
98Package: amssymb 2013/01/14 v3.01 AMS font symbols
99)
100(/usr/share/texmf-dist/tex/latex/amscls/amsthm.sty
101Package: amsthm 2020/05/29 v2.20.6
102\thm@style=\toks22
103\thm@bodyfont=\toks23
104\thm@headfont=\toks24
105\thm@notefont=\toks25
106\thm@headpunct=\toks26
107\thm@preskip=\skip52
108\thm@postskip=\skip53
109\thm@headsep=\skip54
110\dth@everypar=\toks27
111)
112(/usr/share/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
113(/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
114(/usr/share/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
115(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.tex
116\pgfutil@everybye=\toks28
117\pgfutil@tempdima=\dimen148
118\pgfutil@tempdimb=\dimen149
119
120(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex))
121(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-latex.def
122\pgfutil@abb=\box49
123)
124(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex
125(/usr/share/texmf-dist/tex/generic/pgf/pgf.revision.tex)
126Package: pgfrcs 2020/12/27 v3.1.8b (3.1.8b)
127))
128Package: pgf 2020/12/27 v3.1.8b (3.1.8b)
129
130(/usr/share/texmf-dist/tex/latex/pgf/basiclayer/pgfcore.sty
131(/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty
132Package: graphicx 2020/09/09 v1.2b Enhanced LaTeX Graphics (DPC,SPQR)
133
134(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty
135Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
136\KV@toks@=\toks29
137)
138(/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
139Package: graphics 2020/08/30 v1.4c Standard LaTeX Graphics (DPC,SPQR)
140
141(/usr/share/texmf-dist/tex/latex/graphics/trig.sty
142Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
143)
144(/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
145File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
146)
147Package graphics Info: Driver file: pdftex.def on input line 105.
148
149(/usr/share/texmf-dist/tex/latex/graphics-def/pdftex.def
150File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex
151))
152\Gin@req@height=\dimen150
153\Gin@req@width=\dimen151
154)
155(/usr/share/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty
156(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
157Package: pgfsys 2020/12/27 v3.1.8b (3.1.8b)
158
159(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
160\pgfkeys@pathtoks=\toks30
161\pgfkeys@temptoks=\toks31
162
163(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex
164\pgfkeys@tmptoks=\toks32
165))
166\pgf@x=\dimen152
167\pgf@y=\dimen153
168\pgf@xa=\dimen154
169\pgf@ya=\dimen155
170\pgf@xb=\dimen156
171\pgf@yb=\dimen157
172\pgf@xc=\dimen158
173\pgf@yc=\dimen159
174\pgf@xd=\dimen160
175\pgf@yd=\dimen161
176\w@pgf@writea=\write3
177\r@pgf@reada=\read2
178\c@pgf@counta=\count199
179\c@pgf@countb=\count266
180\c@pgf@countc=\count267
181\c@pgf@countd=\count268
182\t@pgf@toka=\toks33
183\t@pgf@tokb=\toks34
184\t@pgf@tokc=\toks35
185\pgf@sys@id@count=\count269
186
187(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgf.cfg
188File: pgf.cfg 2020/12/27 v3.1.8b (3.1.8b)
189)
190Driver file for pgf: pgfsys-pdftex.def
191
192(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.def
193File: pgfsys-pdftex.def 2020/12/27 v3.1.8b (3.1.8b)
194
195(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-pdf.def
196File: pgfsys-common-pdf.def 2020/12/27 v3.1.8b (3.1.8b)
197)))
198(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex
199File: pgfsyssoftpath.code.tex 2020/12/27 v3.1.8b (3.1.8b)
200\pgfsyssoftpath@smallbuffer@items=\count270
201\pgfsyssoftpath@bigbuffer@items=\count271
202)
203(/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex
204File: pgfsysprotocol.code.tex 2020/12/27 v3.1.8b (3.1.8b)
205))
206(/usr/share/texmf-dist/tex/latex/xcolor/xcolor.sty
207Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)
208
209(/usr/share/texmf-dist/tex/latex/graphics-cfg/color.cfg
210File: color.cfg 2016/01/02 v1.6 sample color configuration
211)
212Package xcolor Info: Driver file: pdftex.def on input line 225.
213Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
214Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
215Package xcolor Info: Model `RGB' extended on input line 1364.
216Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
217Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
218Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
219Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
220Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
221Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
222)
223(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcore.code.tex
224Package: pgfcore 2020/12/27 v3.1.8b (3.1.8b)
225
226(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex
227(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex
228(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)
229(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex
230\pgfmath@dimen=\dimen162
231\pgfmath@count=\count272
232\pgfmath@box=\box50
233\pgfmath@toks=\toks36
234\pgfmath@stack@operand=\toks37
235\pgfmath@stack@operation=\toks38
236)
237(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex
238(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex)
239(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code
240.tex)
241(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex)
242(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.te
243x) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.code.tex)
244(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex)
245(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex)
246(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integerarithmetics
247.code.tex))) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex
248\c@pgfmathroundto@lastzeros=\count273
249)) (/usr/share/texmf-dist/tex/generic/pgf/math/pgfint.code.tex)
250(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepoints.code.tex
251File: pgfcorepoints.code.tex 2020/12/27 v3.1.8b (3.1.8b)
252\pgf@picminx=\dimen163
253\pgf@picmaxx=\dimen164
254\pgf@picminy=\dimen165
255\pgf@picmaxy=\dimen166
256\pgf@pathminx=\dimen167
257\pgf@pathmaxx=\dimen168
258\pgf@pathminy=\dimen169
259\pgf@pathmaxy=\dimen170
260\pgf@xx=\dimen171
261\pgf@xy=\dimen172
262\pgf@yx=\dimen173
263\pgf@yy=\dimen174
264\pgf@zx=\dimen175
265\pgf@zy=\dimen176
266)
267(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex
268File: pgfcorepathconstruct.code.tex 2020/12/27 v3.1.8b (3.1.8b)
269\pgf@path@lastx=\dimen177
270\pgf@path@lasty=\dimen178
271) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathusage.code.tex
272File: pgfcorepathusage.code.tex 2020/12/27 v3.1.8b (3.1.8b)
273\pgf@shorten@end@additional=\dimen179
274\pgf@shorten@start@additional=\dimen180
275)
276(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex
277File: pgfcorescopes.code.tex 2020/12/27 v3.1.8b (3.1.8b)
278\pgfpic=\box51
279\pgf@hbox=\box52
280\pgf@layerbox@main=\box53
281\pgf@picture@serial@count=\count274
282)
283(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex
284File: pgfcoregraphicstate.code.tex 2020/12/27 v3.1.8b (3.1.8b)
285\pgflinewidth=\dimen181
286)
287(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransformations.code.t
288ex
289File: pgfcoretransformations.code.tex 2020/12/27 v3.1.8b (3.1.8b)
290\pgf@pt@x=\dimen182
291\pgf@pt@y=\dimen183
292\pgf@pt@temp=\dimen184
293) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorequick.code.tex
294File: pgfcorequick.code.tex 2020/12/27 v3.1.8b (3.1.8b)
295)
296(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreobjects.code.tex
297File: pgfcoreobjects.code.tex 2020/12/27 v3.1.8b (3.1.8b)
298)
299(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepathprocessing.code.te
300x
301File: pgfcorepathprocessing.code.tex 2020/12/27 v3.1.8b (3.1.8b)
302) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex
303File: pgfcorearrows.code.tex 2020/12/27 v3.1.8b (3.1.8b)
304\pgfarrowsep=\dimen185
305)
306(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex
307File: pgfcoreshade.code.tex 2020/12/27 v3.1.8b (3.1.8b)
308\pgf@max=\dimen186
309\pgf@sys@shading@range@num=\count275
310\pgf@shadingcount=\count276
311)
312(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreimage.code.tex
313File: pgfcoreimage.code.tex 2020/12/27 v3.1.8b (3.1.8b)
314
315(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoreexternal.code.tex
316File: pgfcoreexternal.code.tex 2020/12/27 v3.1.8b (3.1.8b)
317\pgfexternal@startupbox=\box54
318))
319(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorelayers.code.tex
320File: pgfcorelayers.code.tex 2020/12/27 v3.1.8b (3.1.8b)
321)
322(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex
323File: pgfcoretransparency.code.tex 2020/12/27 v3.1.8b (3.1.8b)
324) (/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorepatterns.code.tex
325File: pgfcorepatterns.code.tex 2020/12/27 v3.1.8b (3.1.8b)
326)
327(/usr/share/texmf-dist/tex/generic/pgf/basiclayer/pgfcorerdf.code.tex
328File: pgfcorerdf.code.tex 2020/12/27 v3.1.8b (3.1.8b)
329)))
330(/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex
331File: pgfmoduleshapes.code.tex 2020/12/27 v3.1.8b (3.1.8b)
332\pgfnodeparttextbox=\box55
333)
334(/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex
335File: pgfmoduleplot.code.tex 2020/12/27 v3.1.8b (3.1.8b)
336)
337(/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-0-65.sty
338Package: pgfcomp-version-0-65 2020/12/27 v3.1.8b (3.1.8b)
339\pgf@nodesepstart=\dimen187
340\pgf@nodesepend=\dimen188
341)
342(/usr/share/texmf-dist/tex/latex/pgf/compatibility/pgfcomp-version-1-18.sty
343Package: pgfcomp-version-1-18 2020/12/27 v3.1.8b (3.1.8b)
344))
345(/usr/share/texmf-dist/tex/latex/pgf/utilities/pgffor.sty
346(/usr/share/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
347(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex))
348(/usr/share/texmf-dist/tex/latex/pgf/math/pgfmath.sty
349(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex))
350(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex
351Package: pgffor 2020/12/27 v3.1.8b (3.1.8b)
352
353(/usr/share/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex)
354\pgffor@iter=\dimen189
355\pgffor@skip=\dimen190
356\pgffor@stack=\toks39
357\pgffor@toks=\toks40
358))
359(/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
360Package: tikz 2020/12/27 v3.1.8b (3.1.8b)
361
362(/usr/share/texmf-dist/tex/generic/pgf/libraries/pgflibraryplothandlers.code.te
363x
364File: pgflibraryplothandlers.code.tex 2020/12/27 v3.1.8b (3.1.8b)
365\pgf@plot@mark@count=\count277
366\pgfplotmarksize=\dimen191
367)
368\tikz@lastx=\dimen192
369\tikz@lasty=\dimen193
370\tikz@lastxsaved=\dimen194
371\tikz@lastysaved=\dimen195
372\tikz@lastmovetox=\dimen196
373\tikz@lastmovetoy=\dimen197
374\tikzleveldistance=\dimen198
375\tikzsiblingdistance=\dimen199
376\tikz@figbox=\box56
377\tikz@figbox@bg=\box57
378\tikz@tempbox=\box58
379\tikz@tempbox@bg=\box59
380\tikztreelevel=\count278
381\tikznumberofchildren=\count279
382\tikznumberofcurrentchild=\count280
383\tikz@fig@count=\count281
384 (/usr/share/texmf-dist/tex/generic/pgf/modules/pgfmodulematrix.code.tex
385File: pgfmodulematrix.code.tex 2020/12/27 v3.1.8b (3.1.8b)
386\pgfmatrixcurrentrow=\count282
387\pgfmatrixcurrentcolumn=\count283
388\pgf@matrix@numberofcolumns=\count284
389)
390\tikz@expandcount=\count285
391
392(/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrary
393topaths.code.tex
394File: tikzlibrarytopaths.code.tex 2020/12/27 v3.1.8b (3.1.8b)
395))) (/usr/share/texmf-dist/tex/latex/tikz-cd/tikz-cd.sty
396Package: tikz-cd 2018/11/19 v0.9f Commutative diagrams with TikZ
397
398(/usr/share/texmf-dist/tex/generic/tikz-cd/tikzlibrarycd.code.tex
399(/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrary
400matrix.code.tex
401File: tikzlibrarymatrix.code.tex 2020/12/27 v3.1.8b (3.1.8b)
402)
403(/usr/share/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrary
404quotes.code.tex
405File: tikzlibraryquotes.code.tex 2020/12/27 v3.1.8b (3.1.8b)
406)
407(/usr/share/texmf-dist/tex/generic/pgf/libraries/pgflibraryarrows.meta.code.tex
408File: pgflibraryarrows.meta.code.tex 2020/12/27 v3.1.8b (3.1.8b)
409\pgfarrowinset=\dimen256
410\pgfarrowlength=\dimen257
411\pgfarrowwidth=\dimen258
412\pgfarrowlinewidth=\dimen259
413))) (/usr/share/texmf-dist/tex/latex/enumitem/enumitem.sty
414Package: enumitem 2019/06/20 v3.9 Customized lists
415\labelindent=\skip55
416\enit@outerparindent=\dimen260
417\enit@toks=\toks41
418\enit@inbox=\box60
419\enit@count@id=\count286
420\enitdp@description=\count287
421)
422(/usr/share/texmf-dist/tex/latex/geometry/geometry.sty
423Package: geometry 2020/01/02 v5.9 Page Geometry
424
425(/usr/share/texmf-dist/tex/generic/iftex/ifvtex.sty
426Package: ifvtex 2019/10/25 v1.7 ifvtex legacy package. Use iftex instead.
427
428(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty
429Package: iftex 2020/03/06 v1.0d TeX engine tests
430))
431\Gm@cnth=\count288
432\Gm@cntv=\count289
433\c@Gm@tempcnt=\count290
434\Gm@bindingoffset=\dimen261
435\Gm@wd@mp=\dimen262
436\Gm@odd@mp=\dimen263
437\Gm@even@mp=\dimen264
438\Gm@layoutwidth=\dimen265
439\Gm@layoutheight=\dimen266
440\Gm@layouthoffset=\dimen267
441\Gm@layoutvoffset=\dimen268
442\Gm@dimlist=\toks42
443)
444\c@prop=\count291
445\c@ex=\count292
446\c@remark=\count293
447
448(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def
449File: l3backend-pdftex.def 2021-03-18 L3 backend support: PDF output (pdfTeX)
450\l__color_backend_stack_int=\count294
451\l__pdf_internal_box=\box61
452) (./Retake1.aux)
453\openout1 = `Retake1.aux'.
454
455LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 23.
456LaTeX Font Info: ... okay on input line 23.
457LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 23.
458LaTeX Font Info: ... okay on input line 23.
459LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 23.
460LaTeX Font Info: ... okay on input line 23.
461LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 23.
462LaTeX Font Info: ... okay on input line 23.
463LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 23.
464LaTeX Font Info: ... okay on input line 23.
465LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 23.
466LaTeX Font Info: ... okay on input line 23.
467LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 23.
468LaTeX Font Info: ... okay on input line 23.
469 (/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
470[Loading MPS to PDF converter (version 2006.09.02).]
471\scratchcounter=\count295
472\scratchdimen=\dimen269
473\scratchbox=\box62
474\nofMPsegments=\count296
475\nofMParguments=\count297
476\everyMPshowfont=\toks43
477\MPscratchCnt=\count298
478\MPscratchDim=\dimen270
479\MPnumerator=\count299
480\makeMPintoPDFobject=\count300
481\everyMPtoPDFconversion=\toks44
482) (/usr/share/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
483Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf
484Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
48585.
486
487(/usr/share/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
488File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
489e
490))
491*geometry* driver: auto-detecting
492*geometry* detected driver: pdftex
493*geometry* verbose mode - [ preamble ] result:
494* driver: pdftex
495* paper: a4paper
496* layout: <same size as paper>
497* layoutoffset:(h,v)=(0.0pt,0.0pt)
498* modes:
499* h-part:(L,W,R)=(56.9055pt, 483.69687pt, 56.9055pt)
500* v-part:(T,H,B)=(56.9055pt, 731.23584pt, 56.9055pt)
501* \paperwidth=597.50787pt
502* \paperheight=845.04684pt
503* \textwidth=483.69687pt
504* \textheight=731.23584pt
505* \oddsidemargin=-15.36449pt
506* \evensidemargin=-15.36449pt
507* \topmargin=-52.36449pt
508* \headheight=12.0pt
509* \headsep=25.0pt
510* \topskip=12.0pt
511* \footskip=30.0pt
512* \marginparwidth=35.0pt
513* \marginparsep=10.0pt
514* \columnsep=10.0pt
515* \skip\footins=10.8pt plus 4.0pt minus 2.0pt
516* \hoffset=0.0pt
517* \voffset=0.0pt
518* \mag=1000
519* \@twocolumnfalse
520* \@twosidefalse
521* \@mparswitchfalse
522* \@reversemarginfalse
523* (1in=72.27pt=25.4mm, 1cm=28.453pt)
524
525LaTeX Font Info: Trying to load font information for U+msa on input line 33.
526
527(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd
528File: umsa.fd 2013/01/14 v3.01 AMS symbols A
529)
530LaTeX Font Info: Trying to load font information for U+msb on input line 33.
531
532
533(/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd
534File: umsb.fd 2013/01/14 v3.01 AMS symbols B
535)
536LaTeX Font Info: Trying to load font information for OMS+cmtt on input line
53751.
538LaTeX Font Info: No file OMScmtt.fd. on input line 51.
539
540
541LaTeX Font Warning: Font shape `OMS/cmtt/m/n' undefined
542(Font) using `OMS/cmsy/m/n' instead
543(Font) for symbol `textbackslash' on input line 51.
544
545[1
546
547{/usr/share/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2]
548<bc.png, id=23, 453.1329pt x 338.2236pt>
549File: bc.png Graphic file (type png)
550<use bc.png>
551Package pdftex.def Info: bc.png used on input line 171.
552(pdftex.def) Requested size: 226.56589pt x 169.11139pt.
553 [3 <./bc.png>] [4] (./Retake1.aux)
554
555LaTeX Font Warning: Some font shapes were not available, defaults substituted.
556
557 )
558Here is how much of TeX's memory you used:
559 14663 strings out of 478994
560 296548 string characters out of 5864718
561 572498 words of memory out of 5000000
562 31890 multiletter control sequences out of 15000+600000
563 411415 words of font info for 56 fonts, out of 8000000 for 9000
564 1141 hyphenation exceptions out of 8191
565 113i,14n,116p,409b,1111s stack positions out of 5000i,500n,10000p,200000b,80000s
566{/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc}</usr/share/
567texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/share/texmf-dist/fon
568ts/type1/public/amsfonts/cm/cmex10.pfb></usr/share/texmf-dist/fonts/type1/publi
569c/amsfonts/cm/cmmi12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/
570cmmi8.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr
571/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr8.pfb></usr/share/texmf-dis
572t/fonts/type1/public/amsfonts/cm/cmsy10.pfb></usr/share/texmf-dist/fonts/type1/
573public/amsfonts/cm/cmsy8.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts
574/cm/cmti12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt12.pfb
575></usr/share/texmf-dist/fonts/type1/public/amsfonts/symbols/msbm10.pfb></usr/sh
576are/texmf-dist/fonts/type1/public/cm-super/sfrm1200.pfb>
577Output written on Retake1.pdf (4 pages, 134096 bytes).
578PDF statistics:
579 72 PDF objects out of 1000 (max. 8388607)
580 51 compressed objects within 1 object stream
581 0 named destinations out of 1000 (max. 500000)
582 18 words of extra memory for PDF output out of 10000 (max. 10000000)
583
diff --git a/src/Retake/Retake1.pdf b/src/Retake/Retake1.pdf
new file mode 100644
index 0000000..4f70e80
--- /dev/null
+++ b/src/Retake/Retake1.pdf
Binary files differ
diff --git a/src/Retake/Retake1.tex b/src/Retake/Retake1.tex
new file mode 100644
index 0000000..bbff371
--- /dev/null
+++ b/src/Retake/Retake1.tex
@@ -0,0 +1,208 @@
1\documentclass[12pt,a4paper]{article}
2\usepackage[utf8]{inputenc}
3\usepackage{amsmath}
4\usepackage{amsfonts}
5\usepackage{amssymb}
6\usepackage{amsthm}
7\usepackage{tikz,tikz-cd}
8\usepackage{enumitem}
9\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
10
11\title{Mathematical software - homework 1}
12\author{Sebastiano Tronto}
13
14\newtheorem*{thm}{Theorem}
15\newtheorem{prop}{Proposition}
16
17\theoremstyle{definition}
18\newtheorem{ex}{Exercise}
19
20\theoremstyle{definition}
21\newtheorem{remark}{Remark}
22
23\begin{document}
24
25\noindent\hrulefill
26
27\begin{center}
28\Huge{\textbf{Mathematical Software - Retake}}
29\end{center}
30
31\noindent\hrulefill
32\begin{center}
33\begin{tabular}{lcr}
34\texttt{sebastiano.tronto@uni.lu} & \qquad \qquad \qquad \qquad &
35\textbf{Deadline: Wednesday, February 9th}
36\end{tabular}
37\end{center}
38
39\vspace{0.3cm}
40
41\begin{center}
42 \emph{\large For exercises 1 and 2 submit a .tex and a .pdf file.
43 For exercises 3 and 4 submit your Sage code either in text format (.txt or
44 .sage) or as a Jupyter Notebook file (.ipynb).
45 }
46\end{center}
47
48
49\section*{Exercise 1}
50 Write a short Latex document that contains the following theorem-like
51 environments using the \texttt{\textbackslash newtheorem} command of the
52 \texttt{amsthm} package (the box around the text is not needed):
53 \begin{center}
54 \fbox{\parbox{0.95\textwidth}{
55 \begin{prop}[Fundamental Theorem of Algebra]
56 \label{prop:fta}
57 Let \(p(x)\) be a non-constant polynomial with coefficients in
58 $\mathbb C$. Then there is \(z\in\mathbb C\) such that $p(z)=0$.
59 \end{prop}
60
61 \begin{remark}
62 Proposition \ref{prop:fta} is not true for polynomials with
63 coefficients in $\mathbb R$. For example
64 \begin{align}
65 p(x) = x^2+1
66 \end{align}
67 does not have real roots.
68 \end{remark}
69
70 \begin{thm}
71 If $X$ and $Y$ are $\sigma$-finite measure spaces and $f:X\times Y\to
72 \mathbb R$ is measurable and such that
73 \begin{align*}
74 \int_{X\times Y}|f(x,y)|\mathrm d(x,y) < \infty
75 \end{align*}
76 then
77 \begin{align}
78 \label{eq:fubini}
79 \int_X\left(\int_Yf(x,y)\mathrm d y\right)\mathrm d x =
80 \int_Y\left(\int_Xf(x,y)\mathrm d x\right)\mathrm d y =
81 \int_{X\times Y} f(x,y)\mathrm d(x,y)\,.
82 \end{align}
83 \end{thm}
84
85 \begin{remark}
86 In practice, equation \eqref{eq:fubini} means that we can switch the
87 order of integration in a double integral.
88 \end{remark}
89 }}
90 \end{center}
91 Notice that Propositions, Remarks and some of the equations are numbered,
92 and some of them are referred to in the Remarks. This numbering should change
93 accordingly if more numbered Theorems and equations are added before this
94 part of the text.
95
96\newpage
97
98\section*{Exercise 2}
99Create a Latex document containing the following pictures:
100\begin{enumerate}
101\item[(a)] The following commutative diagram:
102 \begin{center}
103 \begin{tikzcd}
104 M \ar[r, "f"] \ar[d,swap,"i",hook] & A \\
105 N \ar[ur, swap, "\tilde f", dashed]
106 \end{tikzcd}
107 \end{center}
108\item[(b)] A triangle with verteces on a grid, as below.
109 Moreover, the position of the vertex $C$ below must be easy to
110 change at will: you should use the
111 \texttt{\textbackslash pgfmathsetmacro} command to set a value
112 for its coordinates at the beginning, so that changing only
113 those numbers makes the whole picture change accordingly (sides,
114 dots, labels).
115 \begin{center}
116 \begin{tikzpicture}[scale=1]
117 \pgfmathsetmacro{\ax}{2}
118 \pgfmathsetmacro{\ay}{1}
119 \pgfmathsetmacro{\bx}{8}
120 \pgfmathsetmacro{\by}{1}
121 \pgfmathsetmacro{\cx}{9}
122 \pgfmathsetmacro{\cy}{7}
123
124 \draw[lightgray!30,thin] (0,0) grid (10,10);
125 \draw[-] (\ax, \ay) -- (\bx, \by) -- (\cx, \cy) -- cycle;
126 \filldraw[blue] (\ax, \ay) circle[radius=0.1] node[below left] {$A$};
127 \filldraw[blue] (\bx, \by) circle[radius=0.1] node[below right] {$B$};
128 \filldraw[red] (\cx, \cy) circle[radius=0.1] node[above] {$C$};
129
130 \end{tikzpicture}
131 \end{center}
132
133\end{enumerate}
134
135\newpage
136\section*{Exercise 3}
137Use SageMath to solve the following problems:
138\begin{enumerate}[label=(\arabic*)]
139 \item Find the roots of the following polynomial over $\mathbb Q$,
140 over $\mathbb R$ and over $\mathbb C$:
141 \[ p(x) = x^6+x^5-2x^4-3x^3-x^2+2x+2 \]
142 \item Find the determinant, the trace and the characteristic polynomial
143 of the following matrix:
144 \[A=
145 \left(\begin{array}{rrrrr}
146 2 & 3 & 0 & 1 & 2 \\
147 1 & 0 & \frac{1}{2} & 1 & -1 \\
148 0 & 0 & -1 & 0 & 0 \\
149 0 & -1 & -1 & 0 & -1 \\
150 -1 & -1 & -1 & -1 & 0
151 \end{array}\right)
152 \]
153 \item Find the solutions of the linear system $A\mathbf x=\mathbf 0$, where
154 $A$ is the matrix above and $\mathbf 0$ is the zero vector.
155 \item Find the points of intersection of the circle of equation $x^2+y^2=4$
156 ad the ellipse of equation $\left(\frac{x}{2}\right)^2+(2y)^2=4$
157 \item Plot the graph of the function $f(x)=\sqrt{1-x^6}$.
158 \item Find the area between the $x$-axis and the grap of the function of
159 the previous point.
160 \item Find the derivative, a primitive (integral) and the Taylor series
161 expansion up to order 4 of the function $h(x)=\log(1+x+x^2)$.
162 \item Use Sage to get the Latex code for the objects you computed in
163 the previous point.
164 \item Find a solution for the differential equation with initial conditions
165 \[
166 \begin{cases}g'(x)&=\frac{1}{3}g(x) - 7\\g(1)&=30\end{cases}
167 \]
168 \item Draw a bar chart of the data set $[0,1,3,7,5,7,2,8,9,3]$, like the foll
169 following:
170 \begin{center}
171 \includegraphics[scale=0.5]{bc.png}
172 \end{center}
173\end{enumerate}
174
175\newpage
176\section*{Grading}
177
178\vspace{0.3cm}
179\textbf{Exercise 1 (5 points).}
180\begin{itemize}
181 \item A correct use of the \texttt{\textbackslash newtheorem} command is
182 worth 2 out of 5 points.
183 \item A correct use of the labelling and reference system is worth 2 points.
184 \item Reproducing correctly the mathematical formulas is worth 1 point.
185\end{itemize}
186
187\vspace{0.3cm}
188\textbf{Exercise 2 (5 points).}
189\begin{itemize}
190 \item Part (a) is worth 2 points: 1 point for having the letters
191 $M$, $N$ and $A$ in the correct position and the arrows
192 pointing between them and 1 point for the style of the arrows
193 and the labels $f$, $i$ and $\tilde f$ in the correct position.
194 \item Part (b) is worth 3 points: 1 point for drawing a triangle, 1
195 point for the other decorative elements (colored dots, grid lines
196 and labels) and 1 point for having the point $C$ correctly set
197 as a macro so that it can be changed easily.
198\end{itemize}
199
200\vspace{0.3cm}
201\textbf{Exercise 3 (10 points).}
202\begin{itemize}
203 \item Each of the 10 parts is worth 1 point.
204\end{itemize}
205
206
207
208\end{document}
diff --git a/src/Retake/bc.png b/src/Retake/bc.png
new file mode 100644
index 0000000..72e73cd
--- /dev/null
+++ b/src/Retake/bc.png
Binary files differ

Generated with cgit - Back to sebastiano.tronto.net