eolas/zk/Logic_gates.md

206 lines
7.5 KiB
Markdown
Raw Normal View History

2022-04-23 13:26:53 +01:00
---
2022-08-20 15:30:04 +01:00
tags: [logic-gates, binary]
2022-04-23 13:26:53 +01:00
---
2022-06-04 14:00:04 +01:00
# Logic gates
2022-09-07 20:00:05 +01:00
> [A logic gate consists in] three connections where there may or may not be
> some electricity. Two of those connections are places where electricity may be
> put into the device, and the third connection is a place where electricity may
> come out of the device.
[J.C. Scott. 2009. **But How Do It Know? The Basics of Computers for Everyone**,
21]
Logic gates are the basic building blocks of digital computing. **A logic gate
is an electrical circuit that has one or more than one input and only one
output.** The input and output points of the gate are
2024-02-17 11:57:44 +00:00
[pins](Integrated_circuits.md) The
input controls the output and the logic determining which types of input
(on/off) lead to specific outputs (on/off) is isomorphic with the
truth-conditions of the
2024-02-17 11:57:44 +00:00
[Boolean connectives](Truth-functional_connectives.md) specifiable in
terms of [truth tables](Truth-tables.md).
Physically, what 'travels through' the gates is electrical current and what
constitutes the 'gate' is a
2024-02-17 11:57:44 +00:00
[transistor](Transistors.md)
responding to the current. Going up a level of abstraction, the current/ charge
is identified with a
2024-02-17 11:57:44 +00:00
[bit](Binary_units_of_measurement.md#binary-units-of-measurement).
It is bits that go into the gate and bits which come out: binary information
that may be either 1 or 0.
2022-06-05 09:30:04 +01:00
2022-12-27 10:30:05 +00:00
## Elementary and composite gates
We distinguish elementary from composite logic gates. An elementary gate is a
single gate embodying a single logical connective. It cannot be reduced any
lower as a logical abstraction. A composite gate is a gate made up of more than
one elemen>tary gate and/or other composite gates.
2022-12-27 10:30:05 +00:00
An example of a composite gate would be a three-way AND. An AND with three
inputs rather than the standard two that furnish the elementary AND gate. This
gate would output 1 when all three gates have the value 1 and 0 otherwise.
2024-02-17 11:57:44 +00:00
[Adders](Half_adder_and_full_adder.md)
and [latche>s](Latches.md) whilst
being
2024-02-17 11:57:44 +00:00
[integrated circuits](Integrated_circuits.md)
are also, technically speaking, composite gates.
2022-12-27 10:30:05 +00:00
## Gate interface / gate implementation
The gate _interface_ is an abstraction that the enables the user to think of the
gate simply in terms of inputs and outputs, without being conc>erned with the
technical details of how this is achieved. How it is achieved is the gate
_implementation_.
2022-12-27 10:30:05 +00:00
We can demonstrate this with the earlier example of a three-way AND. The diagram
below represents the gate as an interface:
2022-12-27 11:00:06 +00:00
// Add: Interface diagram
2022-12-27 11:00:06 +00:00
Whereas this diagram presents the implementation of the gate: it shows the
specific combination of gates which creates the enables the behaviour
represented in the interface diagram.
2022-12-27 11:00:06 +00:00
// Add: Implementation diagram
2022-12-27 11:00:06 +00:00
> Importantly, a single interface may be implemented in a variety of ways. There
> is a one-to-many relationship at work here. From the point of view of the user
> interface these differences should not be detectable. This is another example
> of
2024-02-17 11:57:44 +00:00
> [hardware abstraction](Hardware_abstraction_and_modularity.md)
2022-12-27 10:30:05 +00:00
2022-12-06 07:54:42 +00:00
## NOT gate
> The NOT gate inverts the value of whatever input it receives
### Truth conditions
2022-12-20 08:00:07 +00:00
| $P$ | $\lnot P$ |
| --- | --------- |
| 1 | 0 |
| 0 | 1 |
2022-12-06 07:54:42 +00:00
### Interactive circuit
2023-01-18 19:52:45 +00:00
<iframe src="https://circuitverse.org/simulator/embed/not-gate-aeb5f9e5-9f58-4883-b8e5-d70f6d023185?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginhe
2022-12-27 10:00:06 +00:00
2023-01-18 19:52:45 +00:00
### Truth conditions
2022-12-05 08:00:05 +00:00
2023-01-18 19:52:45 +00:00
tion) truth functional connective
2022-12-05 08:00:05 +00:00
### Symbol
2024-02-16 16:14:01 +00:00
![](/img/and-gate-new-2.png)
2022-12-06 15:10:08 +00:00
2022-12-05 08:00:05 +00:00
### Truth conditions
2023-01-18 19:52:45 +00:00
### Truth conditions
| 1 | 0 | 0 | | 0 | 0 | 0 | | 0 | 0 | 0 |
2022-12-05 08:00:05 +00:00
### Interactive circuit
2022-12-27 10:00:06 +00:00
<iframe src="https://circuitverse.org/simulator/embed/and-gate-b6937338-e83f-474b-af79-854b39c151a3?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="250" width="500" allowFullScreen></iframe>
2022-12-05 08:00:05 +00:00
## NAND gate
> The NAND gate inverts the truth conditions of AND.
### Symbol
2024-02-16 16:14:01 +00:00
![](/img/nand-gate-new.png)
2022-12-06 15:10:08 +00:00
2022-12-05 08:00:05 +00:00
### Truth conditions
2022-12-20 08:00:07 +00:00
| $P$ | $Q$ | $\lnot(P \land Q)$ |
| --- | --- | ------------------ |
| 1 | 1 | 0 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
2022-12-05 08:00:05 +00:00
2022-12-06 07:54:42 +00:00
### Interactive circuit
2022-12-27 10:00:06 +00:00
<iframe src="https://circuitverse.org/simulator/embed/nand-gate-60613ab9-9562-445e-9883-c4ea1920e206?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="250" width="500" allowFullScreen></iframe>
NAND is a **universal logic gate**: equipped with just a NAND we can represent
every other possible logical condition. In practice with circuits, it is more
efficient to use specific dedicated gates (i.e OR, AND, NOT etc) for the other
Boolean connectives but in principle the same output can be achieved through
NANDs alone.
2022-12-05 08:00:05 +00:00
## OR gate
> The OR gate represents the truth conditions of the
2024-02-17 11:57:44 +00:00
> [disjunction](Truth-functional_connectives### Truth
> conditions.md#disjunction) truth functional connective
2022-12-05 08:00:05 +00:00
### Symbol
2024-02-16 16:14:01 +00:00
![](/img/or-gate-new.png)
2022-12-06 15:10:08 +00:00
2023-01-18 19:52:45 +00:00
### Truth condition
2022-12-05 08:00:05 +00:00
### Truth conditions
2023-01-18 19:52:45 +00:00
s
2022-12-20 08:00:07 +00:00
| $P$ | $Q$ | $P \lor Q$ |
| --- | --- | ---------- |
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 0 | 0 | 0 |
2022-12-05 08:00:05 +00:00
2023-01-18 19:52:45 +00:00
### Interactive circui
### Truth conditions
t
2022-12-06 07:54:42 +00:00
2022-12-27 10:30:05 +00:00
<iframe src="https://circuitverse.org/simulator/embed/or-gate-087e4933-7963-482d-b4bf-9e130ef05706?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="250" width="500" allowFullScreen></iframe>
2022-12-05 08:00:05 +00:00
## XOR gate
> The OR gate represents the truth conditions of the exclusive OR
### Symbol
2024-02-16 16:14:01 +00:00
![](/img/xor-gate-new.png)
2022-12-06 15:10:08 +00:00
2022-12-05 08:00:05 +00:00
### Truth conditions
2022-12-20 08:00:07 +00:00
| $P$ | $Q$ | $\lnot(P \Leftrightarrow Q)$ |
| --- | --- | ---------------------------- |
| 1 | 1 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 0 | 0 | 0 |
2022-12-05 08:00:05 +00:00
### Interactive circuit
2022-12-27 10:30:05 +00:00
<iframe src="https://circuitverse.org/simulator/embed/xor-gate-a240131e-a9c3-4240-a52b-e14412fdd654?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="250" width="500" allowFullScreen></iframe>
2022-12-06 07:54:42 +00:00
## NOR gate
> The NOR gate inverts the function of an OR gate
### Symbol
2024-02-16 16:14:01 +00:00
![](/img/nor-gate-new.png)
2022-12-06 15:10:08 +00:00
2022-12-06 07:54:42 +00:00
### Truth conditions
2022-12-20 08:00:07 +00:00
| $P$ | $Q$ | $P \lor Q$ |
| --- | --- | ---------- |
| 1 | 1 | 0 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 1 |
2022-12-06 07:54:42 +00:00
### Interactive circuit
2022-12-27 10:30:05 +00:00
<iframe src="https://circuitverse.org/simulator/embed/nor-gate-ac7946b4-f5d0-4c87-afd1-a2e92326d006?theme=default&display_title=false&clock_time=true&fullscreen=true&zoom_in_out=true" style="border-width:; border-style: solid; border-color:;" name="myiframe" id="projectPreview" scrolling="no" frameborder="1" marginheight="0px" marginwidth="0px" height="250" width="500" allowFullScreen></iframe>