[Notes]《Introduction to classical and quantum computing》 chapter 1
Chapter 1:Classical Information and Computation
本章介绍经典计算。
Quantum computing is not developing in isolation of classical computing.
量子计算的发展并不独立于经典计算。
1.1 Bits
The fundamental unit of classical information.
- Coins
硬币有正(Head),反(Tail)两种状态 - Dice
骰子有6种状态
两个骰子有6*6种可能状态 - Encoding information
两种状态是我们能辨认的最小数目(当然了,一种状态还辨认啥) - Physical Bits
许多物理系统只有两种状态(比如开灯、关灯)
所以我们引入binary digit:0、1
A bit is the smallest unit of classical information. - Binary
二进制数是基于2的数
最左边的位:the most significant bit
最右边的位:the least significant bit - ASCII(读作ass-key)
用二进制编码文字
7位一个字母
1.2 Logic Gates
- Single-Bit Gates
truth table:真值表就是列出输入输出对
最简单的门:一输入一输出
输入可能为0、1,输出可能为0、1,总共有2*2=4种输入输出可能
There are 4 possible single-gates:
· identity gate:0->0,1->1(也叫buffer gate)
· NOT gate:0->0,1->1(也叫inverter gate)
· always 0 gate:0->0,1->0
· always 1 gate:0->1,1->1 - Two-Bits Gates
该类门有2个比特作为输入
There are 5 most important two-bits gates:
· AND gate:A*B
· OR gate:A+B
· Exclusive OR(XOR) gate:A⊕B
· NAND gate: A B ‾ \overline{AB} AB
· NOR gate: A + B ‾ \overline{A+B} A+B - Logic Gates as Physical Circuits
用电路可以实现逻辑门 - Multiple Gates
可以组合门来组合出更多更复杂的运算 - Universal Gates
universal gate set: a set of gates that can perform all possible logic operations
{NOT,AND,OR};{NOT,AND};{NAND};{NOT,OR};{NOR}
1.3 Adders and Verilog
We can code circuits using Verilog(a hardware description language)
-
Adding Binary Numbers by Hand
· half adder:adds two bits and outputs a carry and a bit of the sum
· full adder:adds three bits (a carry into the sum and the two bits we want to add) and outputs a carry and a bit of a sum
· ripple-carry adder:stringing together a half adder and several full adders into a circuit -
Half Adder
Here are input bits A and B, the sum S, and the carry bit C.
S = A⊕B, C = AB -
Full Adder
S = A⊕B⊕Cin, Cout = AB+Cin(A⊕B) -
Ripple-Carry Adder
电路结构如下:
-
Ripple-Carry with Full Adders
-
Circuit Complexity
2n bits相加
Ripple-Carry: n full adders, each full adder uses 5 logic gates, 5n logic gates.
Ripple-Carry with Full Adders: The first full adder can be replaced with a half adder,5n-3 logic gates.
1.4 Circuit Simplification and Boolean Algebra
可以用布尔函数对电路进行化简。
-
Order of Operations
运算顺序和规则类似普通数学。 -
Association, Commutivity, and Distribution
AND和OR遵循以下运算规则:
associative 结合律:
ABC = (AB)C = A(BC)
A+B+C = (A+B) +C = A+ (B+C)
commutative 交换律:
AB = BA
A+B = B+A
distributive 分布律:
A(B+C) = AB+AC
A+ (BC) = (A+B)(A+C) -
Identities Involving Zero and One
• A0 = 0
• A1 = A
• A+0 = A
• A+1 = 1 -
Single-Variable Identities
• A = A ‾ ‾ A = \overline{\overline{A} } A=A
• A A = A AA = A AA=A
• A A ‾ = 0 A\overline{A}= 0 AA=0
• A + A = A A+A = A A+A=A
• A + A ‾ = 1 A+\overline{A} = 1 A+A=1 -
Two-Variable Identities and De Morgan’s Laws
Two-Variable Identities
• A + A B = A A + AB = A A+AB=A
• A + A ‾ B = A + B A+\overline{A} B = A+B A+AB=A+B
De Morgan’s Laws
• A B ‾ = A ‾ + B ‾ \overline{AB} = \overline{A} +\overline{B} AB=A+B
• A + B ‾ = A ‾ ∗ B ‾ \overline{A+B} = \overline{A} *\overline{B} A+B=A∗B -
Circuit Simplification
可以用以上定律进行电路化简。
1.5 Reversible Logic Gates
-
Reversible Gates
reversible gate: given the output(s) of the gate, we can always determine what the input(s) was (were).
example: NOT gate -
Irreversible Gates
• With a reversible gate, no information is lost since we can always recover the inputs from the outputs.
• With an irreversible gate, information is lost since, given an output, we generally do not know what the inputs were. -
Toffoli Gate: A Reversible AND Gate
Toffoli gate is also universal.
Toffoli gate= controlled-controlled-NOT gate= CCNOT gate:The third bit is flipped when A and B are both 1.
Anti-Toffoli gate:
-
Making Irreversible Gates Reversible
make gates reversible by XORing, ensuring that the outputs are unique.
1.6 Error Correction
-
Errors in Physical Devices
single event upset: High energy particles like cosmic rays, neutrons produced in the earth’s atmosphere, radiation from nuclear testing, and radiation from particle accelerators can strike computers, causing bits to flip from 0 to 1 and from 1 to 0.
宇宙射线、地球大气层中产生的中子、核试验产生的辐射以及粒子加速器产生的辐射等高能量粒子可以撞击计算机,导致比特从0翻转到1,从1翻转到0。
Errors: If we are transmitting data through the internet, then some bits may become corrupted.
Detect/correct errors: 因为错误有限,所以可以探测和纠正 -
Error Detection
Repetition code(error-detecting code): The simplest way to detect errors is to repeat each bit multiple times so that multiple physical bits encode a single logical bit. 检测错误的最简单方法是将每个比特重复多次,使多个物理比特编码一个逻辑比特。
Example: 00 encodes 0, 11 encodes 1; 出错了则为01或10。
Codewords: 00,01,10,11
Parity(奇偶校验位): whether the bit string has an even or odd number of 1’s.
error syndromes: parity can be used to distinguish whether an error has occurred -
Error Correction
error-correcting code: correct the error by taking the majority vote
可以计算在某错误率下是否值得进行错误检查
1.7 Computational Complexity
-
Asymptotic Notation
Big-O notation: upper bound, less than or equal to
5 n − 3 = O ( n ) 5n-3 = O(n ) 5n−3=O(n)
Little-o notation: upper bound, less than
5 n − 3 = o ( n 2 ) 5n-3 = o(n^{2} ) 5n−3=o(n2)
Big-Omega notation: lower bound, greater than or equal to,
5 n − 3 = Ω ( n ) 5n-3 = \Omega (\sqrt{n}) 5n−3=Ω(n)
Big-Omega notation: lower bound, greater than,
5 n − 3 = ω ( n ) 5n-3 = \omega (\sqrt{n}) 5n−3=ω(n)
Big-Theta notation: both upper bound and lower bound, * linearly with*,
5 n − 3 = Θ ( n ) 5n-3 = \Theta (n) 5n−3=Θ(n)
-
Complexity Classes
• efficient: if it takes polynomial time or less.
Polynomial time: The number of gates scales as a polynomial in n.
Constant time: O(1),比多项式时间快
Logarithmic time: O(log(n)),比多项式时间快
• inefficient:if it takes more than polynomial time(superpolynomial time)
exponential time:such as 2 n 2^{n} 2n or e n / 1000 e^{n/1000} en/1000.
subexponential time: less than exponential time but greater than polynomial time, such as 2 n 1 / 3 2^{n^{1/3}} 2n1/3
easy problem: their solutions are efficient
hard problem: their solutions are inefficient
• complexity classes: classify problems
P: stands for Polynomial-Time
Matchmaking in the “stable marriage problem.”
Determining if a number is prime
Linear programming
NP:
Factoring
Testing if two networks are equivalent
NP-COMPLETE:If we can find an efficient solution to any NP COMPLETE, then we can use it to find an efficient solution to any NP problem.
Solving n×n Sudoku puzzles.
traveling salesman problem.
Hamiltonian path problem.
bin packing problem.
PSPACE :contains all the problems that can be solved by a computer using a polynomial amount of memory, without any limits on time.
Determining whether a winning strategy exists for the game of checkers generalised to an n×n board.
Winning a generalized level of Super Mario Bros.
1.8 Turing Machines
Turing machine is another types of computers, or models of computation.
- Components
Turing machines can compute everything that a circuit-based computer can compute. But, they are easier to describe mathematically.
• A tape divided into cells, each with a symbol from some finite alphabet.
• A head that can read or write to the tape, and then move left one cell (←), right
one cell (→), or stay put (•).
• A register that stores the state of the Turing machine.
• A list of instructions or program. - Incrementing Binary Numbers
Turning machine 做加法的流程。 - Church-Turing Thesis
• The Church-Turing Thesis: everything that is computable can be computed with a Turing machine, although it could take a long time
undecidable problems: problems that cannot be computed
• Strong Church-Turing Thesis: any model of computation, be it the circuit model or something else, can be simulated by a probabilistic Turing machine with at most polynomial overhead.
An efficient algorithm on one kind of computer is also an efficient algorithm on a probabilistic Turing machine, since adding a polynomial overhead to a polynomial time algorithm is still a polynomial time algorithm.
• Why quantum computer:
what is impossible to compute remains impossible.(没有违反The Church-Turing Thesis)
But it will efficiently solve problems that are inefficient on classical computers.(违反了Strong Church-Turing Thesis)
Evidence:
①Quantum computers can efficiently factor numbers using Shor’s algorithm
②Determining the results of random quantum programs is called random circuit
sampling.
③boson sampling
• BQP: problems efficiently solved by a quantum computer