Merge branch 'master' of github.com:thomasabishop/computer_science
This commit is contained in:
commit
875c756d21
40 changed files with 305 additions and 27 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"cSpell.words": [
|
||||
"elif"
|
||||
]
|
||||
}
|
27
Computer_Architecture/Hardware_abstraction_and_modularity.md
Normal file
27
Computer_Architecture/Hardware_abstraction_and_modularity.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
categories:
|
||||
- Computer Architecture
|
||||
- Hardware
|
||||
tags: [abstraction, modules]
|
||||
---
|
||||
|
||||
# Hardware abstraction and modularity
|
||||
|
||||
In computer architecture we deal with complexity by breaking the system into **modules**. For each module we distinguish **_abstraction_** from **_implementation_**.
|
||||
|
||||
<dl>
|
||||
<dt>abstraction</dt>
|
||||
<dd>what the module does</dd>
|
||||
<dt>implementation</dt>
|
||||
<dd>how it does it</dd>
|
||||
</dl>
|
||||
|
||||
When using a module as a building block you are to focus exclusively on the module's abstraction, ignoring completely its implementation details.
|
||||
|
||||
> The abstraction-implementation paradigm helps developers manage complexity and maintain sanity: by dividing an overwhelming system into well-defined modules we create manageable chunks of implementation work and localize error detection and correction.
|
||||
|
||||
[N.Nisan, S.Schoken. 2021. **The Elements of Computing Systems** (Second Edition)]
|
||||
|
||||
The design of the diagram below emphasises the role of abstraction and modularity in the movement from transistors to chips:
|
||||
|
||||

|
|
@ -13,7 +13,7 @@ _Encoding_ is the process of establishing a correspondence between sets of binar
|
|||
|
||||
> An encoding system maps each symbol to a unique sequence of bits. A computer then interprets that sequence of bits and displays the apppropriate symbol to the user.
|
||||
|
||||
The length of the binary number (bytes, 16-bit, 32-bit etc) that is used to represent a given data set is determined by the number of variations that you require to capture the entire range of the dataset. For example, say we know that there are 18 levels to a computer game. To encode a reference for each level we would need a binary number that is capable of at least 18 total variations. In this instance a 16-bit number would not suffice because it would give us only 16 variants. Thus 32-bit ($2^{5}$) would be the right choice
|
||||
The length of the binary number (bytes, 16-bit, 32-bit etc) that is used to represent a given data set is determined by the number of variations that you require to capture the entire range of the dataset. For example, say we know that there are 18 levels to a computer game. To encode a reference for each level we would need a binary number that is capable of at least 18 total variations. In this insta<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
|
||||
|
||||
```
|
||||
00001 (1)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
---
|
||||
categories:
|
||||
- Mathematics
|
||||
tags: [logic]
|
||||
---
|
||||
|
||||
# Boolean functions
|
||||
|
||||
An example of a Boolean function:
|
||||
|
||||
$$
|
||||
f(x,y,z) = (x \land y) \lor (\lnot(x) \land z )
|
||||
$$
|
||||
|
||||
Here is a work through where $f(1, 0, 1)$:
|
|
@ -1,9 +1,11 @@
|
|||
---
|
||||
categories:
|
||||
- Mathematics
|
||||
tags: [logic, theorems]
|
||||
- Logic
|
||||
tags: [logic, laws]
|
||||
---
|
||||
|
||||
# DeMorgan's Laws
|
||||
|
||||
DeMorgan's laws express some fundamental equivalences that obtain between the Boolean [connectives](Truth-functional%20connectives.md):
|
||||
|
||||
## First Law
|
||||
|
@ -16,14 +18,14 @@ $$
|
|||
|
||||
The equivalence is demonstrated with the following truth-table
|
||||
|
||||

|
||||

|
||||
|
||||
## Second Law
|
||||
|
||||
> The negation of a disjunction is equivalent to the conjunction of the negation of the original disjuncts.
|
||||
|
||||
$$
|
||||
\sim (P \lor Q) \equiv \sim P & \sim Q
|
||||
\sim (P \lor Q) \equiv \sim P \& \sim Q
|
||||
$$
|
||||
|
||||

|
||||

|
138
Logic/Propositional_logic/Boolean_algebra.md
Normal file
138
Logic/Propositional_logic/Boolean_algebra.md
Normal file
|
@ -0,0 +1,138 @@
|
|||
---
|
||||
categories:
|
||||
- Logic
|
||||
- Computer Architecture
|
||||
tags: [propositional-logic, algebra]
|
||||
---
|
||||
|
||||
# Boolean algebra
|
||||
|
||||
## Algebraic laws
|
||||
|
||||
Many of the laws that obtain in the mathematical realm of algebra also obtain for Boolean expressions.
|
||||
|
||||
### The Commutative Law
|
||||
|
||||
$$
|
||||
x \land y = y \land x \\
|
||||
$$
|
||||
|
||||
$$
|
||||
|
||||
x \lor y = y \lor x
|
||||
$$
|
||||
|
||||
Compare the [Commutative Law](/Mathematics/Prealgebra/Whole_numbers.md#the-commutative-property) in the context of arithmetic.
|
||||
|
||||
### The Associative Law
|
||||
|
||||
$$
|
||||
x \land (y \land z) = (x \land y) \land z
|
||||
$$
|
||||
|
||||
$$
|
||||
x \lor (y \lor z) = (x \lor y) \lor z
|
||||
$$
|
||||
|
||||
Compare the [Associative Law](/Mathematics/Prealgebra/Whole_numbers.md#the-associative-property) in the context of arithmetic.
|
||||
|
||||
### The Distributive Law
|
||||
|
||||
$$
|
||||
x \land (y \lor z) = (x \land y) \lor (x \land z)
|
||||
$$
|
||||
|
||||
$$
|
||||
x \lor (y \land z) = (x \lor y) \land (x \lor z)
|
||||
$$
|
||||
|
||||
Compare how the [Distributive Law applies in the case of algebra based on arithmetic](/Mathematics/Prealgebra/Distributivity.md):
|
||||
|
||||
$$
|
||||
a \cdot (b + c) = a \cdot b + a \cdot c
|
||||
$$
|
||||
|
||||
### Double Negation Elimination
|
||||
|
||||
$$
|
||||
\lnot \lnot x = x
|
||||
$$
|
||||
|
||||
### Idempotent Law
|
||||
|
||||
$$
|
||||
x \land x = x
|
||||
$$
|
||||
|
||||
> Combining a quantity with itself either by logical addition or logical multiplication will result in a logical sum or product that is the equivalent of the quantity
|
||||
|
||||
### DeMorgan's Laws
|
||||
|
||||
In addition we have [DeMorgan's Laws](/Logic/Laws_and_theorems.md/DeMorgan's_Laws.md) which express the relationship that obtains between the negations of conjunctive and disjunctive expressions:
|
||||
|
||||
$$
|
||||
\lnot(x \land y) = \lnot x \lor \lnot y
|
||||
$$
|
||||
|
||||
$$
|
||||
\lnot (x \lor y) = \lnot x \land \lnot y
|
||||
$$
|
||||
|
||||
## Applying the laws to simplify complex Boolean expressions
|
||||
|
||||
Say we have the following expression:
|
||||
|
||||
$$
|
||||
\lnot(\lnot(x) \land \lnot (x \lor y))
|
||||
$$
|
||||
|
||||
We can employ DeMorgan's Laws to convert the second conjunct to a different form:
|
||||
|
||||
$$
|
||||
\lnot (x \lor x) = \lnot x \land \lnot y
|
||||
$$
|
||||
|
||||
So now we have:
|
||||
|
||||
$$
|
||||
\lnot(\lnot(x) \land (\lnot x \land \lnot y ))
|
||||
$$
|
||||
|
||||
As we have now have an expression of the form _P and (Q and R)_ we can apply the Distributive Law to simplify the brackets (_P and Q and R_):
|
||||
|
||||
$$
|
||||
\lnot( \lnot(x) \land \lnot(x) \land \lnot(y))
|
||||
$$
|
||||
|
||||
Notice that we are repeating ourselves in this reformulation. We have $\lnot(x) \land \lnot(x)$ but this is just the same $\lnot(x)$ by the principle of **idempotence**. So we can reduce to:
|
||||
|
||||
$$
|
||||
\lnot(\lnot(x) \land \lnot(y))
|
||||
$$
|
||||
|
||||
This gives our expression the form of the first DeMorgan Law ($\lnot (P \land Q)$), thus we can apply the law ($\lnot P \lor \lnot Q$) to get:
|
||||
|
||||
$$
|
||||
\lnot(\lnot(x)) \lor \lnot(\lnot(y))
|
||||
$$
|
||||
|
||||
Of course now we have two double negatives. We can apply the double negation law to get:
|
||||
|
||||
$$
|
||||
x \lor y
|
||||
$$
|
||||
|
||||
### Truth table
|
||||
|
||||
Whenever we simplify an algebraic expression the value of the resulting expression should match that of the complex expression. We can demonstrate this with a truth table:
|
||||
|
||||
| $x$ | $y$ | $\lnot(\lnot(x) \land \lnot (x \lor y))$ | $x \lor y$ |
|
||||
| --- | --- | ---------------------------------------- | ---------- |
|
||||
| 0 | 0 | 0 | 0 |
|
||||
| 0 | 1 | 1 | 1 |
|
||||
| 1 | 0 | 1 | 1 |
|
||||
| 1 | 1 | 1 | 1 |
|
||||
|
||||
### Significance for computer architecture
|
||||
|
||||
The fact that we can take a complex Boolean function and reduce it to a simpler formulation has great significance for the development of computer architectures, specifically [logic gates](/Electronics_and_Hardware/Digital_circuits/Logic_gates.md). It would be rather resource intensive and inefficient to create a gate that is representative of the complex function. Whereas the simplified version only requires a single [OR gate](/Electronics_and_Hardware/Digital_circuits/Logic_gates.md#or-gate).
|
84
Logic/Propositional_logic/Boolean_function_synthesis.md
Normal file
84
Logic/Propositional_logic/Boolean_function_synthesis.md
Normal file
|
@ -0,0 +1,84 @@
|
|||
---
|
||||
categories:
|
||||
- Logic
|
||||
- Computer Architecture
|
||||
tags: [logic, propositional-logic, nand-to-tetris]
|
||||
---
|
||||
|
||||
# Boolean function synthesis
|
||||
|
||||
When we looked at [boolean functions](/Logic/Propositional_logic/Boolean_functions.md) we were working in a particular direction: from a function to a truth table. When we do Boolean function synthesis we work in the opposite direction: from a function to a truth table.
|
||||
|
||||
This is an important skill that we will use when constructing [logic circuits](/Electronics_and_Hardware/Digital_circuits/Digital_circuits.md). We will go from truth conditions (i.e. what we want the circuit to do and when we want it to do it) to a function expression which is then reduced and implemented with [logic gates](/Electronics_and_Hardware/Digital_circuits/Logic_gates.md).
|
||||
|
||||
## The process
|
||||
|
||||
The process proceeds as follows:
|
||||
|
||||
1. Work out the truth conditions for the circuit we want to construct
|
||||
2. Identify the rows where the output is equal to 1
|
||||
3. For each of these rows construct a Boolean expression that evaluates to that output
|
||||
4. Join each expression with OR
|
||||
5. Reduce these expressions to a single expression in its simplest form
|
||||
|
||||
## Example
|
||||
|
||||
Let's say we have the following truth table:
|
||||
|
||||
| Line | $x$ | $y$ | $z$ | $f$ |
|
||||
| ---- | --- | --- | --- | --- |
|
||||
| 1 | 0 | 0 | 0 | 1 |
|
||||
| 2 | 0 | 0 | 1 | 0 |
|
||||
| 3 | 0 | 1 | 0 | 1 |
|
||||
| 4 | 0 | 1 | 1 | 0 |
|
||||
| 5 | 1 | 0 | 0 | 1 |
|
||||
| 6 | 1 | 0 | 1 | 0 |
|
||||
| 7 | 1 | 1 | 0 | 0 |
|
||||
| 8 | 1 | 1 | 1 | 0 |
|
||||
|
||||
We only need to focus on lines 1, 3, and 5 since they have the output 1:
|
||||
|
||||
| Line | $x$ | $y$ | $z$ | $f$ |
|
||||
| ---- | --- | --- | --- | --- |
|
||||
| 1 | 0 | 0 | 0 | 1 |
|
||||
| 3 | 0 | 1 | 0 | 1 |
|
||||
| 5 | 1 | 0 | 0 | 1 |
|
||||
|
||||
For each line we construct a Boolean expression that would result in the value in the $f$ column. In other words we construct the function:
|
||||
|
||||
| Line | $x$ | $y$ | $z$ | $f$ |
|
||||
| ---- | --- | --- | --- | ------------------------------------------- |
|
||||
| 1 | 0 | 0 | 0 | $ \lnot(x) \land \lnot (y) \land \lnot(z) $ |
|
||||
| 3 | 0 | 1 | 0 | $ \lnot(x) \land y \land \lnot(z) $ |
|
||||
| 5 | 1 | 0 | 0 | $ x \land \lnot(y) \land \lnot(z) $ |
|
||||
|
||||
We can now join each expression to create a complex expression that covers the entire truth table. Since 1 will be output for any one of these sub-expressions we can just join them up with OR:
|
||||
|
||||
$$
|
||||
(\lnot(x) \land \lnot (y) \land \lnot(z)) \lor (\lnot(x) \land y \land \lnot(z)) \lor (x \land \lnot(y) \land \lnot(z))
|
||||
$$
|
||||
|
||||
It's clear that we have transcribed the truth conditions accurately but that we are doing so in a rather verbose way. We can simplify by just looking at the position of the 1s in the truth table. Notice:
|
||||
|
||||
- $z$ is always 0
|
||||
- $x$ and $y$ are either 0 or 1 but never both 1 in the same row
|
||||
|
||||
So we simplify:
|
||||
|
||||
$$
|
||||
(\lnot(x) \land \lnot(z)) \lor (\lnot(y) \land \lnot(z))
|
||||
$$
|
||||
|
||||
Notice that $\lnot(z)$ is repeated so we can remove the repetition:
|
||||
|
||||
$$
|
||||
\lnot z \land (\lnot(x) \lor \lnot(y))
|
||||
$$
|
||||
|
||||
The upshot is that we now have a simpler expression that uses only NOT, OR and AND. We could therefore construct a circuit that just uses these gates to construct the conditions we specified in the first truth table.
|
||||
|
||||
> This is important and is an instance of the general theorem that _any Boolean function_ can be represented using an expression containing AND, OR and NOT operations
|
||||
|
||||
But even this is too complex. We could get rid of the OR and just use AND and NOT, in other words, NAND:
|
||||
|
||||
stopped at 6:38
|
33
Logic/Propositional_logic/Boolean_functions.md
Normal file
33
Logic/Propositional_logic/Boolean_functions.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
categories:
|
||||
- Logic
|
||||
- Computer Architecture
|
||||
tags: [logic, propositional-logic, nand-to-tetris]
|
||||
---
|
||||
|
||||
# Boolean functions
|
||||
|
||||
An example of a Boolean function:
|
||||
|
||||
$$
|
||||
f(x,y,z) = (x \land y) \lor (\lnot(x) \land z )
|
||||
$$
|
||||
|
||||
Here is a work through where $f(1, 0, 1)$:
|
||||
|
||||
- The first disjunction : $ \lnot(x) \land z $ is false because $x$ is 1 and $z$ is 0
|
||||
- The second disjunction: $x \land y$ is false because $x$ is 1 and $y$ is 1
|
||||
- The overall function returns false because the main connective is disjunction and both of its disjuncts are false
|
||||
|
||||
We can compute all possible outputs of the function by constructing a [truth-table](/Logic/Propositional_logic/Truth-tables.md) with each possible variable as the truth conditions and the output of the function as the truth value:
|
||||
|
||||
| $x$ | $y$ | $z$ | $f(x,y,z) = (x \land y) \lor (\lnot(x) \land z )$ |
|
||||
| --- | --- | --- | ------------------------------------------------- |
|
||||
| 0 | 0 | 0 | 0 |
|
||||
| 0 | 0 | 1 | 1 |
|
||||
| 0 | 1 | 0 | 0 |
|
||||
| 0 | 1 | 1 | 1 |
|
||||
| 1 | 0 | 0 | 0 |
|
||||
| 1 | 0 | 1 | 0 |
|
||||
| 1 | 1 | 0 | 1 |
|
||||
| 1 | 1 | 1 | 1 |
|
|
@ -16,7 +16,7 @@ P. Norvig, S. Russell. 2020. **Artificial Intelligence: A Modern Approach**
|
|||
|
||||
N. Weiner. 1948. **Cybernetics**
|
||||
|
||||
## Backend (CPD)
|
||||
## Backend (general)
|
||||
|
||||
[Backend Roadmap](https://roadmap.sh/backend)
|
||||
|
||||
|
@ -50,6 +50,8 @@ Hennesy, Patterson. 2020. **Computer Organization and Design** ([BBC O'Reilly Li
|
|||
|
||||
Bryant, O'Halloran. 2016. **Computer Systems: A Programmer's Perspective**
|
||||
|
||||
N.Nisan, S.Schoken. 2021. **The Elements of Computing Systems** (Second Edition)
|
||||
|
||||
[How do transistors work, anyway?](https://lcamtuf.substack.com/p/how-do-transistors-work-anyway)
|
||||
|
||||
[NAND latch](http://hyperphysics.phy-astr.gsu.edu/hbase/Electronic/nandlatch.html)
|
||||
|
@ -80,6 +82,10 @@ E. Lehman, F. Thomson Leighton, A.R. Meyer 2017. **Mathematics for Computer Scie
|
|||
|
||||
G. Caldarelli, M. Catanzaro. 2012. **Networks: A Very Short Introduction**
|
||||
|
||||
[Course: NodeJS Essential Training (LinkedIn Learning)](https://www.linkedin.com/learning/node-js-essential-training-14888164)
|
||||
|
||||
[Course: Building RESTful APIs with Node.js and Express](https://www.linkedin.com/learning/building-restful-apis-with-node-js-and-express-16069959)
|
||||
|
||||
## Python
|
||||
|
||||
A. Sweighart. 2020. **Beyond the Basic Stuff with Python**
|
||||
|
@ -93,3 +99,11 @@ A. Sweighart. 2015. **Automate the Boring Stuff with Python**
|
|||
## Shell
|
||||
|
||||
B. Perry, D. Taylor. 2015. **Wicked Cool Shell Scripts**
|
||||
|
||||
[What is the difference between `${var}`, `"$var"`, and `"${var}"` in the Bash shell? (Stack Overflow)](https://stackoverflow.com/q/18135451/10484600)
|
||||
|
||||
## SQL
|
||||
|
||||
[Course: MySQL Essential Training (LinkedIn Learning)](https://www.linkedin.com/learning/mysql-essential-training-2)
|
||||
|
||||
[Course: MySQL Advanced Topics (LinkedIn Learning)](https://www.linkedin.com/learning/mysql-advanced-topics)
|
||||
|
|
Loading…
Add table
Reference in a new issue