Skip to content

Commit

Permalink
reviewed according to Sam's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zune-Ahmed committed Oct 9, 2024
1 parent b346c4a commit c490a33
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 138 deletions.
49 changes: 24 additions & 25 deletions source/logic-gates/ch-practical-application.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
<title>Practical Applications of Logic Gates</title>
<introduction>
<p>
Logic gates are fundamental building blocks in digital circuits and play a crucial role in the design of modern computing systems. They operate based on binary principles, where the input and output values are either high (1) or low (0), corresponding to different logical conditions. Their importance spans from simple devices like calculators to advanced systems like microprocessors, enabling core operations like arithmetic, data routing, and memory storage.
Logic gates are fundamental building blocks in digital circuits and play a crucial role in the design of modern computing systems. They operate based on binary principles, where the input and output values are either high (<c>1</c>) or low (<c>0</c>), corresponding to different logical conditions. Their importance spans from simple devices like calculators to advanced systems like microprocessors, enabling core operations like arithmetic, data routing, and memory storage.
</p>
<p>
To better understand how logic gates impact our daily lives, let's explore a few real-world applications. These examples showcase how simple logic circuits contribute to sophisticated operations within digital devices.
</p>
</introduction>


<subsection xml:id="sec-full-adder">
<title>Full Adder: Arithmetic with Logic Gates</title>
<p>
In digital systems, adding numbers is a fundamental task, and this is where the <term>full adder</term> circuit comes into play. A full adder is a logic circuit that adds three bits: two input bits and a carry bit from a previous addition. To understand its importance, let's break it down:
</p>

<p>
<term>Binary Addition Basics</term>: In binary, numbers are represented by just 0s and 1s. When adding two binary numbers, if the result is 1 + 1, the sum is 0, and a carry of 1 is generated (similar to how 9 + 1 in decimal gives 10, where 0 is the sum, and 1 is carried to the next column). A full adder can handle this carry, making it an essential part of multi-bit addition.
<term>Binary Addition Basics</term>: In binary, numbers are represented by just <c>0</c>s and <c>1</c>s. When adding two binary numbers, if the result is <c>1 + 1</c>, the sum is <c>0</c>, and a carry of <c>1</c> is generated (similar to how <c>9 + 1</c> in decimal gives <c>10</c>, where <c>0</c> is the sum, and <c>1</c> is carried to the next column). A full adder can handle this carry, making it an essential part of multi-bit addition.
</p>

<p>
Expand All @@ -40,12 +39,12 @@
</p>

<p>
<term>Detailed Example</term>: Let’s consider adding two binary digits, A = 1, B = 1, with a carry-in of 1:
<term>Detailed Example</term>: Let’s consider adding two binary digits, <c>A = 1</c>, <c>B = 1</c>, with a carry-in of <c>1</c>:
<itemizedlist>
<item>The XOR gate first adds A and B: 1 XOR 1 = 0 (because XOR outputs 1 only if one input is 1 but not both).</item>
<item>The result is XORed with the carry-in: 0 XOR 1 = 1.</item>
<item>The sum is 1.</item>
<item>The AND gate checks if both A and B are 1, which they are, so the result is 1.</item>
<item>The XOR gate first adds A and B: <c>1 XOR 1 = 0</c> (because XOR outputs <c>1</c> only if one input is <c>1</c> but not both).</item>
<item>The result is XORed with the carry-in: <c>0 XOR 1 = 1</c>.</item>
<item>The sum is <c>1</c>.</item>
<item>The AND gate checks if both A and B are <c>1</c>, which they are, so the result is <c>1</c>.</item>
<item>This carry-out bit is passed to the next full adder in a sequence if needed.</item>
</itemizedlist>
</p>
Expand Down Expand Up @@ -90,7 +89,7 @@
</p>

<p>
For instance, consider a 4-to-1 multiplexer, which has four input signals but only one output. The selection of which input is sent to the output is controlled by two additional signals called select lines. Depending on the values of these select lines, the multiplexer connects one of the four inputs to the output.
For instance, consider a <c>4-to-1</c> multiplexer, which has four input signals but only one output. The selection of which input is sent to the output is controlled by two additional signals called select lines. Depending on the values of these select lines, the multiplexer connects one of the four inputs to the output.
</p>

<p>
Expand Down Expand Up @@ -137,37 +136,37 @@
</p>

<p>
The basic building block of memory circuits is a type of circuit called a <term>flip-flop</term>. Flip-flops are used to store a single bit of data, which can either be a 0 or a 1. Flip-flops are created using logic gates such as <c>NAND</c> or <c>NOR</c> gates, arranged in specific configurations to allow them to "remember" their state even after the input signal has been removed. This property makes flip-flops fundamental in storing data temporarily in a system.
The basic building block of memory circuits is a type of circuit called a <term>flip-flop</term>. Flip-flops are used to store a single bit of data, which can either be a <c>0</c> or a <c>1</c>. Flip-flops are created using logic gates such as <c>NAND</c> or <c>NOR</c> gates, arranged in specific configurations to allow them to "remember" their state even after the input signal has been removed. This property makes flip-flops fundamental in storing data temporarily in a system.
</p>

<p>
One common example of a flip-flop is the <term>SR (Set-Reset) flip-flop</term>, which is used to set a bit to 1 or reset it to 0. The SR flip-flop is typically built using two cross-coupled NAND gates. It operates with two inputs: the Set input (S) and the Reset input (R). Depending on the combination of these inputs, the flip-flop will either store a 1, store a 0, or retain its previous value. This ability to hold a state is what allows SR flip-flops to act as 1-bit memory elements.
One common example of a flip-flop is the <term>SR (Set-Reset) flip-flop</term>, which is used to set a bit to <c>1</c> or reset it to <c>0</c>. The SR flip-flop is typically built using two cross-coupled NAND gates. It operates with two inputs: the Set input (<c>S</c>) and the Reset input (<c>R</c>). Depending on the combination of these inputs, the flip-flop will either store a <c>1</c>, store a <c>0</c>, or retain its previous value. This ability to hold a state is what allows SR flip-flops to act as <c>1</c>-bit memory elements.
</p>

<p>
Flip-flops like the SR flip-flop are used to construct larger memory units. For instance, a register, which stores a group of bits, is made by combining several flip-flops. Memory circuits such as these are essential in the construction of computer memory, where data needs to be stored and accessed quickly.
</p>
<sage>
<input>
from sympy.logic.boolalg import Nand
from sympy import symbols
from sympy.logic.boolalg import Nand
from sympy import symbols

# Define variables S, R
S, R = symbols('S R')
# Define variables S, R
S, R = symbols('S R')

# SR Flip-flop using NAND gates
Q_not = Nand(R, True) # Assume initial state for Q (True in this case)
Q = Nand(S, Q_not) # Set input (S)
# SR Flip-flop using NAND gates
Q_not = Nand(R, True) # Assume initial state for Q (True in this case)
Q = Nand(S, Q_not) # Set input (S)

# Assign initial values for Set and Reset
S_val = True
R_val = False
# Assign initial values for Set and Reset
S_val = True
R_val = False

# Now evaluate both Q and Q_not with the given S and R values
evaluated_Q_not = Q_not.subs({R: R_val})
evaluated_Q = Q.subs({S: S_val, Q_not: evaluated_Q_not})
# Now evaluate both Q and Q_not with the given S and R values
evaluated_Q_not = Q_not.subs({R: R_val})
evaluated_Q = Q.subs({S: S_val, Q_not: evaluated_Q_not})

evaluated_Q, evaluated_Q_not
evaluated_Q, evaluated_Q_not
</input>
<output>
</output>
Expand Down
30 changes: 18 additions & 12 deletions source/logic-gates/sec-combined-logic-gates.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Logic gates can be combined to create more complex circuits that perform specific tasks. By linking gates together, we can create circuits that process multiple inputs to produce a desired output. For example, combining an <c>AND</c> gate and a <c>NOT</c> gate results in a <c>NAND</c> gate, which inverts the output of the <c>AND</c> gate. More complex circuits, such as half-adders and multiplexers, are built by combining basic gates in strategic ways.
</p>
<p>
Let's look at a simple example where an <c>OR</c> gate is combined with a <c>NOT</c> gate. The <c>OR</c> gate takes two inputs and produces a 1 if either input is 1. By applying a <c>NOT</c> gate to the output, the circuit produces the opposite, meaning it will only produce 1 if both inputs are 0.
Let's look at a simple example where an <c>OR</c> gate is combined with a <c>NOT</c> gate. The <c>OR</c> gate takes two inputs and produces a <c>1</c> if either input is <c>1</c>. By applying a <c>NOT</c> gate to the output, the circuit produces the opposite, meaning it will only produce <c>1</c> if both inputs are <c>0</c>.
</p>
<sage>
<input>
Expand Down Expand Up @@ -70,23 +70,29 @@
</p>
<sage>
<input>
from sympy.logic.boolalg import And, Or
from sympy.logic.boolalg import And, Or, truth_table
from sympy.abc import A, B
def generate_truth_table():
table = []
for A_val in [False, True]:
for B_val in [False, True]:
and_output = And(A_val, B_val)
or_output = Or(A_val, B_val)
table.append([A_val, B_val, and_output, or_output])
return table
generate_truth_table()

# Define a function to generate a truth table for any list of logic gate expressions
def generate_truth_table(expressions, variables):
for expr in expressions:
print(f"Truth table for expression: {expr}")
table = truth_table(expr, variables)
for row in table:
print(row)
print("-" * 20)

# Example usage with AND and OR gates
expressions = [And(A, B), Or(A, B)]
variables = [A, B]
generate_truth_table(expressions, variables)

</input>
<output>
</output>
</sage>
<p>
In this example, the truth table helps us see how the <c>AND</c> gate only produces 1 when both inputs are 1, while the <c>OR</c> gate produces 1 whenever at least one input is 1.
In this example, the truth table helps us see how the <c>AND</c> gate only produces <c>1</c> when both inputs are <c>1</c>, while the <c>OR</c> gate produces <c>1</c> whenever at least one input is <c>1</c>.
</p>

<p>
Expand Down
202 changes: 101 additions & 101 deletions source/logic-gates/sec-intro-logic-gates.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<title>Introduction to Logic Gates</title>

<p>
Logic gates are the building blocks of digital circuits. They process binary inputs (0s and 1s) and produce a single binary output. Logic gates are fundamental to how computers and other digital devices function, as they make decisions based on inputs and perform tasks like arithmetic, data storage, and control operations. In this chapter, we will explore the most common types of logic gates, how they are used, and how they form the basis of complex circuits.
Logic gates are the building blocks of digital circuits. They process binary inputs (<c>0</c>s and <c>1</c>s) and produce a single binary output. Logic gates are fundamental to how computers and other digital devices function, as they make decisions based on inputs and perform tasks like arithmetic, data storage, and control operations. In this chapter, we will explore the most common types of logic gates, how they are used, and how they form the basis of complex circuits.
</p>

<sage>
Expand All @@ -21,123 +21,123 @@
<aside>
<title>Notes</title>
<p>
Logic gates are the foundation of modern computing. Every operation your computer performs, from adding numbers to displaying images, is made up of logic gates that process binary signals (0s and 1s).
Logic gates are the foundation of modern computing. Every operation your computer performs, from adding numbers to displaying images, is made up of logic gates that process binary signals (<c>0</c>s and <c>1</c>s).
</p>
</aside>

<p>
The most common logic gates include <c>AND</c>, <c>OR</c>, <c>NOT</c>, <c>NAND</c>, <c>NOR</c>, <c>XOR</c>, and <c>XNOR</c>. Each gate has its own symbol and truth table that defines how it processes inputs to produce an output. Understanding these basic gates is the first step to learning how digital systems work, as more complex circuits are built by combining these gates.
</p>

<idx><h>AND</h></idx>
<idx><h>OR</h></idx>
<idx><h>NOT</h></idx>
<idx><h>NAND</h></idx>
<idx><h>NOR</h></idx>
<idx><h>XOR</h></idx>
<idx><h>XNOR</h></idx>
<idx><h>AND</h></idx>
<idx><h>OR</h></idx>
<idx><h>NOT</h></idx>
<idx><h>NAND</h></idx>
<idx><h>NOR</h></idx>
<idx><h>XOR</h></idx>
<idx><h>XNOR</h></idx>

<p>
<c>AND</c> gate: Produces a 1 only if both inputs are 1.
</p>
<sage>
<input>
A = True
B = False
And(A, B)
</input>
<output>
</output>
</sage>
<p>
<c>AND</c> gate: Produces a <c>1</c> only if both inputs are <c>1</c>.
</p>
<sage>
<input>
A = True
B = False
And(A, B)
</input>
<output>
</output>
</sage>

<p>
<c>OR</c> gate: Produces a 1 if at least one input is 1.
</p>
<sage>
<input>
A = True
B = False
Or(A, B)
</input>
<output>
</output>
</sage>
<p>
<c>OR</c> gate: Produces a <c>1</c> if at least one input is <c>1</c>.
</p>
<sage>
<input>
A = True
B = False
Or(A, B)
</input>
<output>
</output>
</sage>

<p>
<c>NOT</c> gate: Produces the opposite of the input, 1 becomes 0 and 0 becomes 1.
</p>
<sage>
<input>
A = True
Not(A)
</input>
<output>
# Shows the result of NOT gate when A is True
</output>
</sage>

<aside>
<title>Notes</title>
<p>
These logic gates are used to design everything from simple calculators to complex CPUs. Understanding the behavior of each gate is like learning the alphabet of digital logic.
</p>
</aside>
<p>
<c>NOT</c> gate: Produces the opposite of the input, <c>1</c> becomes <c>0</c> and <c>0</c> becomes <c>1</c>.
</p>
<sage>
<input>
A = True
Not(A)
</input>
<output>
# Shows the result of NOT gate when A is True
</output>
</sage>

<aside>
<title>Notes</title>
<p>
<c>NAND</c> gate: Produces a 0 only if both inputs are 1.
These logic gates are used to design everything from simple calculators to complex CPUs. Understanding the behavior of each gate is like learning the alphabet of digital logic.
</p>
<sage>
<input>
A = True
B = True
Nand(A, B)
</input>
<output>
</output>
</sage>
</aside>

<p>
<c>NOR</c> gate: Produces a 1 only if both inputs are 0.
</p>
<sage>
<input>
A = False
B = False
Nor(A, B)
</input>
<output>
</output>
</sage>
<p>
<c>NAND</c> gate: Produces a <c>0</c> only if both inputs are <c>1</c>.
</p>
<sage>
<input>
A = True
B = True
Nand(A, B)
</input>
<output>
</output>
</sage>

<p>
<c>XOR</c> gate: Produces a 1 if exactly one input is 1, but not both.
</p>
<sage>
<input>
A = True
B = False
Xor(A, B)
</input>
<output>
</output>
</sage>
<p>
<c>NOR</c> gate: Produces a <c>1</c> only if both inputs are <c>0</c>.
</p>
<sage>
<input>
A = False
B = False
Nor(A, B)
</input>
<output>
</output>
</sage>

<p>
<c>XNOR</c> gate (equivalent gate): Produces a 1 if both inputs are the same.
</p>
<sage>
<input>
A = True
B = True
Equivalent(A, B)
</input>
<output>
</output>
</sage>
<p>
<c>XOR</c> gate: Produces a <c>1</c> if exactly one input is <c>1</c>, but not both.
</p>
<sage>
<input>
A = True
B = False
Xor(A, B)
</input>
<output>
</output>
</sage>

<p>
These basic gates form the foundation for more complex circuits, allowing us to build anything from simple logic operations to entire computer processors.
</p>
<p>
<c>XNOR</c> gate (equivalent gate): Produces a <c>1</c> if both inputs are the same.
</p>
<sage>
<input>
A = True
B = True
Equivalent(A, B)
</input>
<output>
</output>
</sage>

<p>
These basic gates form the foundation for more complex circuits, allowing us to build anything from simple logic operations to entire computer processors.
</p>



Expand Down

0 comments on commit c490a33

Please sign in to comment.