Skip to content

Commit 9c62964

Browse files
committed
Wrap code in quotes
1 parent 1a2420d commit 9c62964

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

notebooks/04_recursion_and_induction.ipynb renamed to notebooks/04_logic.ipynb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"nbformat_minor": 0,
44
"metadata": {
55
"colab": {
6-
"name": "03_recursion_and_induction.ipynb",
6+
"name": "04_logic.ipynb",
77
"provenance": [],
88
"collapsed_sections": []
99
},
@@ -40,7 +40,7 @@
4040
" if int(str(2 ** n)[:2]) == 65:\n",
4141
" print(f'2**{n}={2 ** n}')"
4242
],
43-
"execution_count": 1,
43+
"execution_count": null,
4444
"outputs": [
4545
{
4646
"output_type": "stream",
@@ -57,8 +57,8 @@
5757
"id": "7gJYRIxbR_Hy"
5858
},
5959
"source": [
60-
"Here, we use $\\texttt{int(str(2 ** n)[:2])}$ to compute the first two digits \n",
61-
"of $2^n$. Indeed, the function $\\texttt{str}$ converts the value of $2^n$ into a string, then the slice $\\texttt{[:2]}$ takes the first two characters of this string, and finally the function $\\texttt{int}$ converts the result back into an integer."
60+
"Here, we use `int(str(2 ** n)[:2])` to compute the first two digits \n",
61+
"of $2^n$. Indeed, the function `str` converts the value of $2^n$ into a string, then the slice `[:2]` takes the first two characters of this string, and finally the function `int` converts the result back into an integer."
6262
]
6363
},
6464
{
@@ -98,7 +98,7 @@
9898
" if not is_prime(n ** 2 + n + 41):\n",
9999
" print(n)"
100100
],
101-
"execution_count": 7,
101+
"execution_count": null,
102102
"outputs": [
103103
{
104104
"output_type": "stream",
@@ -118,7 +118,7 @@
118118
"id": "Dren-X37VKmU"
119119
},
120120
"source": [
121-
"Here, the function $\\texttt{is_prime}$ checks whether the given positive integer $n$ is prime simply by checking all its potential divisors $2 \\le d < n$ (recall that $n=1$ is not prime by convention).\n",
121+
"Here, the function `is_prime` checks whether the given positive integer $n$ is prime simply by checking all its potential divisors $2 \\le d < n$ (recall that $n=1$ is not prime by convention).\n",
122122
"We then go through all $1 \\le n < 50$ and check if $n^2+n+41$ \n",
123123
"is prime. If it is not, we print $n$.\n",
124124
"\n",
@@ -142,7 +142,7 @@
142142
"print(next(n for n in range(2, 100) if\n",
143143
" not is_prime(n * n + n + 41)))\n"
144144
],
145-
"execution_count": 9,
145+
"execution_count": null,
146146
"outputs": [
147147
{
148148
"output_type": "stream",
@@ -181,7 +181,7 @@
181181
" if a ** 2 + b ** 2 == c ** 2:\n",
182182
" print(f'{a}**2 + {b}**2 = {c}**2')"
183183
],
184-
"execution_count": 10,
184+
"execution_count": null,
185185
"outputs": [
186186
{
187187
"output_type": "stream",
@@ -202,8 +202,8 @@
202202
"id": "JeYfJUppWIPx"
203203
},
204204
"source": [
205-
"This code enumerates all triples $1\\leq a \\le b \\le c < 20$ (by using the $\\texttt{combinations}$ function from the $\\texttt{itertools}$ module). \n",
206-
"For each such triple, it checks whether $a^2+b^2=c^2$ (recall the $\\texttt{python}$ notation $\\texttt{a ** n}$ for $a^n$)."
205+
"This code enumerates all triples $1\\leq a \\le b \\le c < 20$ (by using the `combinations` function from the `itertools` module). \n",
206+
"For each such triple, it checks whether $a^2+b^2=c^2$ (recall the Python notation `a ** n` for $a^n$)."
207207
]
208208
},
209209
{
@@ -249,7 +249,7 @@
249249
"print(95800 ** 4 + 217519 ** 4 + 414560 ** 4)\n",
250250
"print(422481 ** 4)"
251251
],
252-
"execution_count": 11,
252+
"execution_count": null,
253253
"outputs": [
254254
{
255255
"output_type": "stream",
@@ -288,7 +288,7 @@
288288
"\n",
289289
"print(x ** 3 + y ** 3 + z ** 3)"
290290
],
291-
"execution_count": 12,
291+
"execution_count": null,
292292
"outputs": [
293293
{
294294
"output_type": "stream",
@@ -307,7 +307,7 @@
307307
"source": [
308308
"## Logic\n",
309309
"\n",
310-
"A *proposition* is a statement that is true or false. For example, `I'm a human` and `25 is a multiple of 7` are propositions (the first one is true, and the second one if false), while `You should fly to the Moon` is not a proposition. Using the language of mathematical logic, we create compound propositions from simple ones (\"$i\\geq0$ and $i\\leq n$ and $a[i]$ divides $100$, or $i$ is a prime\"). We use such propositions as conditions in $\\texttt{if}$-statemenets and $\\texttt{while}$-loops, and, thus, \"give directions\" to computer programs. Here are a few examples of propositions."
310+
"A *proposition* is a statement that is true or false. For example, *I'm a human* and *25 is a multiple of 7* are propositions (the first one is true, and the second one if false), while *You should fly to the Moon* is not a proposition. Using the language of mathematical logic, we create compound propositions from simple ones (\"$i\\geq0$ and $i\\leq n$ and $a[i]$ divides $100$, or $i$ is a prime\"). We use such propositions as conditions in `if`-statemenets and `while`-loops, and, thus, \"give directions\" to computer programs. Here are a few examples of propositions."
311311
]
312312
},
313313
{
@@ -324,7 +324,7 @@
324324
"print(3 < 5 and not(7 < 5))\n",
325325
"print(2+2 == 5 or 2+2 == 4)\n"
326326
],
327-
"execution_count": 13,
327+
"execution_count": null,
328328
"outputs": [
329329
{
330330
"output_type": "stream",
@@ -343,7 +343,7 @@
343343
"id": "x76h0PHuwP9G"
344344
},
345345
"source": [
346-
"In the following code, the function $\\texttt{foo}$ prints out \"Foo!\". One of the conditions in the $\\texttt{if}$-statement calls the function $\\texttt{foo}$. Why don't we see \"Foo!\" in the output of the program?"
346+
"In the following code, the function `foo` prints out \"Foo!\". One of the conditions in the `if`-statement calls the function `foo`. Why don't we see \"Foo!\" in the output of the program?"
347347
]
348348
},
349349
{
@@ -366,7 +366,7 @@
366366
"else:\n",
367367
" print('False')"
368368
],
369-
"execution_count": 14,
369+
"execution_count": null,
370370
"outputs": [
371371
{
372372
"output_type": "stream",
@@ -383,7 +383,7 @@
383383
"id": "_ojnHiO6wC4h"
384384
},
385385
"source": [
386-
"This is known as *lazy evaluation*. The $\\texttt{python}$ interpreter knows that the whole $\\texttt{if}$-condition evaluates to $\\texttt{False}$ after evaluating its first part. That is why it does not even bother to call the $\\texttt{foo()}$ function (so \"Foo!\" is not printed). Try changing the order of two statements in the $\\texttt{if}$-statement and see what happens!"
386+
"This is known as *lazy evaluation*. The Python interpreter knows that the whole `if`-condition evaluates to `False` after evaluating its first part. That is why it does not even bother to call the `foo()` function (so \"Foo!\" is not printed). Try changing the order of two statements in the `if`$-statement and see what happens!"
387387
]
388388
},
389389
{
@@ -392,18 +392,18 @@
392392
"id": "jBvsZgdexAgD"
393393
},
394394
"source": [
395-
"The universal quantifier is a mathematical analogue of the function $\\texttt{all}$ in $\\texttt{python}$ that outputs $\\texttt{True}$ if all elements\n",
396-
"in the list are $\\texttt{True}$. Similarly, the existential quantifier is \n",
397-
"a mathematical formalization of the function $\\texttt{any}$ that outputs $\\texttt{True}$ if at least one of the elements in the list \n",
398-
"is $\\texttt{True}$.\n",
395+
"The universal quantifier is a mathematical analogue of the function `{all}` in Python that outputs `True` if all elements\n",
396+
"in the list are `True`. Similarly, the existential quantifier is \n",
397+
"a mathematical formalization of the function `any` that outputs `True` if at least one of the elements in the list \n",
398+
"is `True`.\n",
399399
"\n",
400400
"For example, the following program verifies the following two statements with universal quantifiers: \n",
401401
"\n",
402-
"`All integers in ${6, 2, 4}$ are even` \n",
402+
"*All integers in ${6, 2, 4}$ are even*\n",
403403
"\n",
404404
"and \n",
405405
"\n",
406-
"`All integers in ${2, 7, 6}$ are even`.\n"
406+
"*All integers in ${2, 7, 6}$ are even*.\n"
407407
]
408408
},
409409
{
@@ -421,7 +421,7 @@
421421
"a = (2, 7, 6)\n",
422422
"print(all((i % 2 == 0) for i in a))"
423423
],
424-
"execution_count": 15,
424+
"execution_count": null,
425425
"outputs": [
426426
{
427427
"output_type": "stream",
@@ -441,11 +441,11 @@
441441
"source": [
442442
"Similarly, the following code evaluates the statements with the existential quantifier \n",
443443
"\n",
444-
"`There is an even integer in ${1, 7, 9}$` \n",
444+
"*There is an even integer in $\\{1, 7, 9\\}$*\n",
445445
"\n",
446446
"and \n",
447447
"\n",
448-
"`There is an even integer in ${9, 2, 3}$`"
448+
"*There is an even integer in $\\{9, 2, 3\\}$*"
449449
]
450450
},
451451
{
@@ -463,7 +463,7 @@
463463
"a = (9, 2, 3)\n",
464464
"print(any((i % 2 == 0) for i in a))"
465465
],
466-
"execution_count": 16,
466+
"execution_count": null,
467467
"outputs": [
468468
{
469469
"output_type": "stream",
@@ -483,11 +483,11 @@
483483
"source": [
484484
"The negation of a universal quantifier is an existential quantifier; and the negation of an existential quantifier is a universal quantifier. For example, the negation of the statement\n",
485485
"\n",
486-
"`For all $n, A(n)$ is true`\n",
486+
"*For all $n, \\, A(n)$ is true*\n",
487487
"\n",
488488
"is the statement \n",
489489
"\n",
490-
"`There exists $n$, such that $A(n)$ is false`."
490+
"*There exists $n$, such that $A(n)$ is false.*"
491491
]
492492
},
493493
{
@@ -509,7 +509,7 @@
509509
"print(not any([is_divisible_by_3(x) for x in lst]))\n",
510510
"print(all([not is_divisible_by_3(x) for x in lst]))"
511511
],
512-
"execution_count": 17,
512+
"execution_count": null,
513513
"outputs": [
514514
{
515515
"output_type": "stream",
@@ -527,12 +527,12 @@
527527
"id": "5kQScsCL1rO2"
528528
},
529529
"source": [
530-
"In this example, the function $\\texttt{is_divisible_by_3(x)}$ returns $\\texttt{True}$ or $\\texttt{False}$ when $\\texttt{x}$ is (or is not) a multiple of $3$. Here, $\\texttt{True}$ and $\\texttt{False}$ are *Boolean values*. We may want to check whether \n",
531-
"a list $\\texttt{lst}$ of integers contains a multiple of $3$. For that, we use a special $\\texttt{python}$ construction. First, $\\texttt{[is_divisible_by_3(x) for x in lst]}$ is the list of Boolean values $\\texttt{is_divisible_by_3(x)}$ for all elements $\\texttt{x}$ in the list $\\texttt{lst}$. \n",
530+
"In this example, the function `is_divisible_by_3(x)` returns `True` or `False` when `x` is (or is not) a multiple of $3$. Here, `True` and `False` are *Boolean values*. We may want to check whether \n",
531+
"a list `lst` of integers contains a multiple of $3$. For that, we use a special Python construction. First, `[is_divisible_by_3(x) for x in lst]` is the list of Boolean values `is_divisible_by_3(x)` for all elements `x` in the list `lst`. \n",
532532
"\n",
533-
"In our example, $\\texttt{l=[5,17,6,10]}$, so this list equals $\\texttt{[False, False, True, False]}$ (only $6$ is divisible by $3$). Then, $\\texttt{any(S)}$ checks whether there exists a $\\texttt{True}$ value in $\\texttt{S}$, and $\\texttt{not}$ reverses the answer. This way, we evaluate the statement \"there is no element $\\texttt{x}$ in the list $\\texttt{lst}$ that is divisible by $3$\". \n",
533+
"In our example, `l=[5,17,6,10]`, so this list equals `[False, False, True, False]` (only $6$ is divisible by $3$). Then, `any(S)` checks whether there exists a `True` value in `S`, and `not` reverses the answer. This way, we evaluate the statement *there is no element `x` in the list `lst` that is divisible by $3$*. \n",
534534
"\n",
535-
"In the next line, we evaluate the statement \"all elements of $\\texttt{l}$ are not divisible by $3$\" and get the same answer $\\texttt{False}$: there is no good element in the list if and only if all elements are bad."
535+
"In the next line, we evaluate the statement *all elements of `l` are not divisible by $3$* and get the same answer `False`: there is no good element in the list if and only if all elements are bad."
536536
]
537537
}
538538
]

notebooks/05_invariants.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"nbformat_minor": 0,
44
"metadata": {
55
"colab": {
6-
"name": "04_invariants.ipynb",
6+
"name": "05_invariants.ipynb",
77
"provenance": [],
88
"collapsed_sections": []
99
},
@@ -25,7 +25,7 @@
2525
"But once he fixes one bug, three new bugs appear. During the night, \n",
2626
"Bob fixed $15$ bugs. How many pending bugs does Bob have at this point?\n",
2727
"\n",
28-
"Let us model this process in $\\texttt{python}$."
28+
"Let us model this process in Python."
2929
]
3030
},
3131
{
@@ -46,7 +46,7 @@
4646
"\n",
4747
"print(number_of_pending_bugs)"
4848
],
49-
"execution_count": 1,
49+
"execution_count": null,
5050
"outputs": [
5151
{
5252
"output_type": "stream",
@@ -93,7 +93,7 @@
9393
"after $i$ days, the first $i$ volumes stay at their intended positions. It remains to note that by the end of ninth day, volume $10$ must stay at position $10$: indeed, volumes $1,2,\\dotsc,9$ stay at positions $1,2,\\dotsc,9$, hence\n",
9494
"$10$ is the only available position for volume $10$.\n",
9595
"\n",
96-
"It is particularly easy to implement this strategy in $\\texttt{python}$. \n",
96+
"It is particularly easy to implement this strategy in Python. \n",
9797
"The code below uses $0$-based indexing for days, books, and positions."
9898
]
9999
},
@@ -120,7 +120,7 @@
120120
"\n",
121121
"sort_books([0, 5, 8, 1, 2, 3, 7, 4, 9, 6])"
122122
],
123-
"execution_count": 2,
123+
"execution_count": null,
124124
"outputs": [
125125
{
126126
"output_type": "stream",
@@ -183,7 +183,7 @@
183183
"for v in (7, 15, 22, 33):\n",
184184
" print(v, represent(9, v))\n"
185185
],
186-
"execution_count": 3,
186+
"execution_count": null,
187187
"outputs": [
188188
{
189189
"output_type": "stream",

notebooks/index.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"\n",
5555
"[Chapter 2. Finding an Example](02_finding_an_example.ipynb)\n",
5656
"\n",
57-
"[Chapter 4. Recursion and Induction](04_recursion_and_induction.ipynb)\n",
57+
"[Chapter 4. Logic](04_logic.ipynb)\n",
5858
"\n",
5959
"[Chapter 5. Invariants](05_invariants.ipynb)"
6060
]

0 commit comments

Comments
 (0)