Section 1 : Gates, Circuits and Boolean Algebra

文章目录

  • Section 1 : Gates, Circuits and Boolean Algebra
    • Gates
    • Logic circuits
    • Boolean Algebra
    • Reducing Boolean Expressions
    • Axioms
    • How to design a circuit
    • De Morgan’s Laws
    • Working through a typical problem
    • The R-S flip-flop (also called a latch)

  In Computer Science (the study of what is possible with computers), it is important to understand the machine that we work with. Computers are made up of thousands of electronic circuits. In this section we will describe the basic components of a circuit and how to design circuits for specific purposes.

Gates

The basic components of a computer are gates. These are real components that you can buy and use to make electrical circuits. We are interested in the NOT gate, the AND gate and the OR gate. We use diagrams to indicate the gates:
  NOT          AND          OR
You should remember these symbols. It helps to imagine that the symbol for the AND gate is shaped like the D in AND that the symbol for the OR gate is curved on the left to fit the O of OR.

The AND gate and the OR gate have two input lines each and one output line. The NOT gate has one input line and one output line. It is possible for the AND and OR gates to have more than two input lines each – more about this later.

We construct truth tables to help us remember how each gate works:

These truth tables are drawn with “On” and “Off”. It is more usual to see truth tables showing TRUE
(or T) for On and FALSE (or F) for Off. Sometimes we also write 1 for On and 0 for Off.

The truth tables provide us with the following knowledge about gates:

NOT gate when the input line is on (or 1 or TRUE) then the output line is off ; when the input line is off (or 0 or FALSE) then the output line is on
AND gate if both input lines are on then the output line is on (otherwise it is off)
OR gate if both input lines are off then the output line is off (otherwise it is on)

Logic circuits

We connect gates with lines (think of them as electric wires) to create circuits and we include switches and lights as needed. A switch can set a line to be on or off. A light glows if its input line is on.

Example: What does this circuit do:

When we flip the switch on, the light goes off and when we flip the switch off, the light comes on. This effect is caused by the NOT gate in the circuit.

We now move on to a more interesting circuit to solve a specific problem, which is:
  Ed will take 159.102 if Dan does or Carol does
  Dan will take 159.102 if Ann does and Bob does not

We will construct a logic circuit that will automatically tell Ed what to do. We use electricity to represent what each person does – if they take 159.102 we switch on, otherwise we switch off.

First we construct a circuit to see what Dan will do:

We have labelled the diagram for one particular situation. Work through every situation and label the diagram for each one of those situations.

Now we can build this circuit into a bigger circuit to see what Ed should do:


Check every possibility for this circuit.

For example, what happens if Ann, Bob and Carol all do not take 159.102?

This circuit performs a logic function. A function is a rule that takes in some input and produces some output. We are familiar with functions which take in numbers and produce another number. For

Boolean Algebra

Logic circuits take up a lot of space and time. We need a more concise notation. Algebra in mathematics uses variables to represent numbers. In Boolean Algebra we use variables to represent
statements. The value of these statements can be TRUE or FALSE.

Example: Let R = “it is raining today” (this can be TRUE or FALSE)

Symbols in Boolean Algebra

We use ~ to represent not. Thus ~R means “it is not raining today”.

Assume N = “it is not raining today”. Then ~R = N.

Note that ~~R = R. This is true for any variable, i.e. it is true for any statement.

We use + to represent OR.

Thus R + S means: for the whole statement to be true – R must be true, or S must be true, or they must both be true.

(Aside: if we want R to be true or S to be true but not both to be true – we would use XOR).

We use ● to represent AND.

Thus R ● S means: for the whole statement to be true – R must be true and S must be true. (Note that ● is often written simply as a full stop like this: R.S)

Priority of Operations

Many of us learnt the rule BEDMAS to remind us of the order of priority of arithmetic operations.

The rule for Boolean Algebra is NOTANDOR (and also brackets).

Examples:

(Mathematics) 4 + 2 * 3 = 10 but (4 + 2) * 3 = 18

(Boolean Algebra) H + J ● K = TRUE but (H + J) ● K = FALSE
(assume H = TRUE, J = FALSE, K = FALSE)

Evaluating Expressions

In Mathematics we could have the expression x + y. We cannot evaluate the expression until we assign values to x and y. For example, if x = 2 and y = 3 then x + y = 5.

Similarly in Boolean Algebra we can evaluate expressions once we assign values to variables.

Assume P = FALSE and Q = TRUE and evaluate: (P + ~P) ● ~~Q

(P + ~P) ● ~~Q = (P + ~P) ● Q = (FALSE + TRUE) ● TRUE = TRUE ● TRUE = TRUE

Note that for any statement P + ~P is always true.
You need to be able to switch between Boolean Algebra, logic circuits and truth tables.

For example:

Boolean Expression: X = ~(H ● M) + (M ● ~Q)

X is known as the output of the circuit. We usually put brackets around each term.

The corresponding truth table is:

Some things to notice about the truth table:

We set up a pattern to draw the truth table – Q changes F,T,F,T,etc, M changes F,F,T,T,F,F,etc, and H changes in fours. By using this pattern we ensure that we cover all possible situations.

We notice patterns in the output, e.g. if H is FALSE then the output is true. Also if M is FALSE then the output is true. This enables us to take some short cuts in the design of the circuit.

If designing the circuit from the truth table, make sure that you include all situations where the output is TRUE. We can ignore any situations where the output is FALSE.

Summary
We study logic circuits because they are the basis for designing a computer.
We study Boolean Algebra as a short-hand notation for writing logic circuits. The Boolean Algebra also assists us to find ways of reducing the circuit by removing components, e.g. ~~R = R.
We use truth tables to check that our circuit is functioning for every situation.

Reducing Boolean Expressions

Let us set up the logic circuit for (P + ~P) ● ~~Q (We make a “black box” with 2 inputs and 1 output).

We can now reduce this circuit by using Boolean Algebra as follows:

Reduce (P + ~P) ● ~~Q

Step 1: ~~Q = Q so we reduce to (P + ~P) ● Q

Step 2: P + ~P = true so we reduce to true ● Q

Step 3: true ● Q = Q so we reduce to Q

Note that the two “black boxes” do the same thing – you can prove it with a truth table!

By using Boolean Algebra we can reduce Boolean expressions. Reduced Boolean expressions enable us to build smaller circuits in computers. Smaller circuits save space (computers get smaller with bigger memory) and money (less components so cheaper to build).

Axioms

Axioms are the laws or rules that form the foundation of any algebra.

The Axioms of Boolean Algebra

P + Q = Q + P P ● Q = Q ● P Commutative
(P + Q) + R = P + (Q + R) (P ● Q) ● R = P ● (Q ● R) Associative
P ● Q + P ● R = P ● (Q + R) (P + Q) ● (P + R) = P + (Q ● R) Distributive
TRUE + P = TRUE FALSE + P = P TRUE ● P = P FALSE ● P = FALSE Identities
P + ~P = TRUE P ● ~P = FALSE Complement
P + P = P P ● P = P Idempotent
~~P = P Involution

Because Boolean algebra only has two values (TRUE and FALSE) we can use truth tables to show that an axiom is true for every possibility.

For example:

Use a truth table to show that P ● Q + P ● R = P ● (Q + R) is always TRUE:

The truth table shows that the LHS = RHS for every possibility.

How to design a circuit

Assume we have a problem that requires a circuit – understand the problem.
Create a truth table to cover every possibility that will exist for the new circuit.
Convert the truth table into a Boolean expression.
Reduce the expression using the axioms of Boolean algebra.
Design a circuit that corresponds to the reduced Boolean expression.
Check that the circuit matches the truth table for every situation.
Example: the 3-way voting circuit
A. The Problem: there are three people on a committee. They are called A, B and C. When they
vote on a proposal, the proposal will be approved if there are 2 or 3 votes in favour of the proposal and
the proposal will fail if there are 0 or 1 votes for it. Design a voting circuit in which there is a switch
for each person and a light that comes on if the proposal has enough votes.

B. Truth Table: create a truth table to cover every possible situation


C. Convert the truth table to Boolean expression:
Ignore any rows with an output of F. Each row becomes a term. Link the terms together with OR.
So we get: A ● B ● C + A ● B ● ~C + A ● ~B ● C + ~A ● B ● C

D. Reduce the Expression: we start by increasing the number of terms using the axiom P = P + P.
We also make use of the axiom that P + Q = Q + P, so we get:
A ● B ● C + A ● B ● ~C + A ● B ● C + A ● ~B ● C + A ● B ● C + ~A ● B ● C
Now we use the axiom P ● Q + P ● R = P ● (Q + R) to get:
A ● B ● (C + ~C) + A ● C ● (B + ~B) + B ● C ● (A + ~A)
Now we use the axiom P + ~P = true and the axiom P ● true = P to get:
A ● B + A ● C + B ● C
Finally we again use the axiom P ● Q + P ● R = P ● (Q + R) to get:
A ● (B + C) + B ● C
IMPORTANT: check the reduced expression against every situation in the truth table!!
E. Design the circuit:

IMPORTANT: check that the circuit does what it is meant to do!!

De Morgan’s Laws

The English mathematician Augustus De Morgan (in about 1850) established two further laws:
~(P ● Q) = ~P + ~Q and ~(P + Q) = ~P ● ~Q

We can show that they are correct for every situation by looking at the truth tables, for example:

De Morgan’s Laws are important as they allow us to convert AND into OR or vice versa.
Let us study the following circuit:

The output is (P ● ~Q) = ((P + Q)) = P + Q. Thus this circuit does the same thing as an OR gate but it does not include an OR gate. De Morgan’s Laws enable us to build an OR gate by using
AND and NOT.

One of the components inside this circuit was:

This combination of AND and NOT occurs frequently so we create a new gate by combining them.

Similarly, we can develop the NOR gate with symbol and truth table as follows:

All other gates can be constructed by using NAND gates and NOT gates.

Gates with multiple inputs:

Two little rules that can be helpful when you are looking at gates with multiple inputs:
  OR gate: you need just one input line to be true to make the output true.
      the output is false only if all input lines are false.
  AND gate: you need just one input line to be false to make the output false
      the output is true only if all input lines are true.

Working through a typical problem

Here is a truth table. Write down the corresponding Boolean expression, reduce the expression and design the circuit. Check the final circuit against the truth table.

Note: you need to be able to answer this type of question from any point in the cycle:

Truth table → Boolean expression → circuit → truth table → ….

Example: start with the following truth table:

To construct the Boolean expression, ignore all rows ending with F and so we get:

A ● B ● C + ~A ● ~B ● C + ~A ● ~B ● ~C

Using the axiom P ● Q + P ● R = P ● (Q + R) we get: A ● B ● C + ~A ● ~B ● (C + ~C)

Using P + ~P = true and true ● P = P we get: A ● B ● C + ~A ● ~B

And using De Morgan’s Law we get: A ● B ● C + ~(A + B)

And now we can design the circuit

Now go back to the truth table and check the circuit against each row of the table. For example: if A is OFF (FALSE) and B and C are both ON (TRUE) then the output should be OFF (FALSE).

The R-S flip-flop (also called a latch)

The circuit for the R-S flip-flop (where S means Set and R means Reset):

This circuit is rather difficult to follow but we will just accept it and not try to figure out exactly how it works. Looking at the black box (simplified) version of the R-S flip-flip we can see that it has two input lines (R and S) and two output lines (Q and ~Q). When S is switched briefly on (and then off again), Q will be set to on (or TRUE or 1). When R is switched briefly on (and then off again), Q will be set to off (or FALSE or 0). Q is called the state of the flip-flop. This is a bistable circuit, i.e. it has two states (on and off). The flip-flop can be used as a memory cell capable of storing zero (off) or one (on). We want to store larger numbers so we group a number of cells together to form a memory location.

Thus a memory location is a group of flipflops (circuits) that work together to store a binary number represented by zeros and ones.

C++ 从入门到入土(English Version) Section 1:Gates, Circuits and Boolean Algebra相关推荐

  1. spring 依赖注入_Spring从入门到入土——依赖注入(DI)

    Dependency Injection 概念 依赖注入(DI) 依赖:指Bean对象的创建依赖于容器.Bean对象的依赖资源 注入:指Bean对象 注入方式 一共有三种:分别是构造器注入:Set注入 ...

  2. Flink 教程 gitbook 从入门到入土(详细教程)

    Flink从入门到入土(详细教程) 和其他所有的计算框架一样,flink也有一些基础的开发步骤以及基础,核心的API,从开发步骤的角度来讲,主要分为四大部分 1.Environment Flink J ...

  3. Ajax!从入门到入土

    Ajax!从入门到入土 Ajax 1.JSON 1.1 什么是JSON 1.2 JSON语法 2.JSON的解析 2.1 Java中解析JSON 2.1.1 FastJSON解析 2.1.2 Jack ...

  4. 决战Go语言从入门到入土v0.1

    下载地址:https://gitcode.net/as604049322/blog_pdf 安装与运行环境 Go 语言环境安装 Go语言支持Linux.Mac和Windows,本人接下来的学习全部基于 ...

  5. Mermaid从入门到入土

    概述 What Mermaid是基于Javascript的绘图工具,用户可以方便快捷地通过代码创建图表 项目地址:mermaid How 特定的Mermaid渲染器:mermaid-live-edit ...

  6. rocketmq怎么保证消息一致性_从入门到入土(三)RocketMQ 怎么保证的消息不丢失?...

    精彩推荐 一百期Java面试题汇总SpringBoot内容聚合IntelliJ IDEA内容聚合Mybatis内容聚合 接上一篇:RocketMQ入门到入土(二)事务消息&顺序消息 面试官常常 ...

  7. Activiti工作流从入门到入土:完整Hello World大比拼(Activiti工作流 API结合实例讲解)

    文章源码托管:https://github.com/OUYANGSIHAI/Activiti-learninig 欢迎 star !!! 本来想着闲来无事,前面在项目中刚刚用到了工作流 Activit ...

  8. activiti api文档_【白银人机】Activiti 工作流从入门到入土:完整 hello world 大比拼(API 结合实例讲解)...

    点击上方"好好学java",选择"置顶"公众号 重磅资源.干货,第一时间送达 重磅推荐  ① 纯福利 | 公众号资源大汇总,一年才一次! ② 重磅!!2018年 ...

  9. 从入门到入土(十)RocketMQ集群流程以及核心概念

    精彩推荐 一百期Java面试题汇总 SpringBoot内容聚合 IntelliJ IDEA内容聚合 Mybatis内容聚合 接上一篇:从入门到入土(九)手摸手教你搭建RocketMQ双主双从同步集群 ...

  10. 从入门到入土(九)手摸手教你搭建RocketMQ双主双从同步集群,不信学不会!...

    精彩推荐 一百期Java面试题汇总 SpringBoot内容聚合 IntelliJ IDEA内容聚合 Mybatis内容聚合 接上一篇:从入门到入土(八)RocketMQ的Consumer是如何做的负 ...

最新文章

  1. 后端必备 Git 分支开发:规范指南
  2. 独家 | 一文读懂如何用深度学习实现网络安全
  3. python连接数据库的技术_(技术)Python 3 与 pymysql 操作数据库
  4. Base64与文件(docx)流的加密和解密
  5. JavaScript从父页面获取子页面的值(子页面又如何访问父页面)
  6. 用EasyRecovery恢复手残误删的文件
  7. 【TSP】基于matlab自重启伪遗传改良算法求解旅行商问题【含Matlab源码 1510期】
  8. ImageJ批量操作时常见报错及其原因
  9. 环境管理体系ISO14001认证常见的审核问题有哪些?
  10. 蘑菇丁周记范文计算机销售40篇,毕业生实习周记及销售实习周记范文 毕业生蘑菇钉周记范文(最新)...
  11. R语言读取(加载)txt格式数据为dataframe、依据学号字段从dataframe随机抽取10位同学的数据
  12. 逻辑删除和物理删除的区别
  13. 私网地址与公网地址转换
  14. Windows 局域网中文件进行自动同步备份通过synctoy和计划任务实现
  15. 半导体激光芯片商长光华芯完成B轮1.5亿融资,推进三类主营业务战略建设
  16. 滴滴梁李印:滴滴是如何从零构建中式实时计算平台的?
  17. vue-shop 表格中使用树形控件 vue-table-width-tree-grid
  18. Android免费小说阅读器—程序员自己的阅读器,没广告,所有小说可搜索,专注阅读体验
  19. buctoj-2022寒假集训4
  20. JAVA--线程同步的三种方法

热门文章

  1. 数据结构与算法python—12.二叉搜索树及python实现与leetcode总结
  2. python基础4-序列
  3. 巧用“搜索”解决自学编程遇到的难题
  4. 构建运营级IPv6网络
  5. 35线性映射02—— 线性映射概念与运算、矩阵表示
  6. 深入浅出带你了解Python2与Python3的异同
  7. ubuntu使用pytorch训练出现killed_目标检测之pytorch预训练模型的使用(削减削减网络层,修改参数)fine-tune技巧...
  8. linux跟踪函数代码,linux ltrace-跟踪进程调用库函数的情况
  9. python的map函数和reduce_python函数_map()、filter()和reduce()
  10. 力扣-剑指offer 06 从尾到头打印链表