690 likes | 709 Views
Chapter 12. C H A P T E R 3. Theory of Computation. J. Glenn Brookshear 蔡 文 能. J. Glenn Brookshear. Chapter 12: Theory of Computation. 12.1 Functions and Their Computation 12.2 Turing Machines 12.3 Universal Programming Languages 12.4 A Noncomputable Function
E N D
Chapter12 C H A P T E R 3 Theory of Computation J. Glenn Brookshear 蔡 文 能 J. Glenn Brookshear
Chapter 12: Theory of Computation • 12.1 Functions and Their Computation • 12.2 Turing Machines • 12.3 Universal Programming Languages • 12.4 A Noncomputable Function • 12.5 Complexity of Problems • 12.6 Public-Key Cryptography
Functions • Function: A correspondence between a collection of possible input values and a collection of possible output values so that each possible input is assigned a single output • Computing a function:Determining the output value associated with a given set of input values • Noncomputable function:A function that cannot be computed by any algorithm
Complexity of Problems • Time Complexity: The number of instruction executions required • Unless otherwise noted, “complexity” means “time complexity.” • A problem is in class O(f(n)) if it can be solved by an algorithm in Q(f(n)). • A problem is in class Q(f(n)) if the best algorithm to solve it is in class Q(f(n)).
Software Efficiency How shall we measure the amount of work done by an algorithm? • Measured as number of instructions executed • Let f (n) be a function. f(n) is the maximum number of basic operations performed by the algorithm on any input size n. • notation for efficiency classes • O( ? ) • ( ? ) • Q ( ? ) • Best case, worst case, and average case Time Complexity vs. Space Complexity
Asymptotic Upper Bound (Big O) • f(n) c g(n) for all nn0 • g(n) is called an • asymptotic upper bound of f(n). • We write f(n)=O(g(n)) • It reads f(n) equals big oh of g(n). c g(n) f(n) n0
Asymptotic Lower Bound (Big Omega) • f(n) c g(n) for all nn0 • g(n) is called an • asymptotic lower bound of f(n). • We write f(n)=(g(n)) • It reads f(n) equals big omega of g(n). f(n) c g(n) n0
Asymptotically Tight Bound (Big Theta) • f(n) = O(g(n)) and f(n) = (g(n)) • g(n) is called an • asymptotically tight bound of f(n). • We write f(n)=(g(n)) • It reads f(n) equals theta of g(n). c2 g(n) f(n) c1 g(n) n0
P versus NP • Class P: All problems in any class Q(f(n)), where f(n) is a Polynomial • Class NP: All problems that can be solved by a nondeterministic algorithm in polynomial time Nondeterministic algorithm = an “algorithm” whose steps may not be uniquely and completely determined by the process state • Whether the class NP is bigger than class P is currently unknown.
Figure 12.12: A graphic summation of problem classification US$1,000,000 dollars for a solution: http://www.claymath.org/millennium/
Figure 12.1 An attempt to display the function that converts measurements in yards into meters
Turing Machine Operation • Inputs at each step • State • Value at current tape position • Actions at each step • Write a value at current tape position • Move read/write head • Change state
CHURCH-TURING THESIS • The functions that are computable by a Turing machine are exactly the functions that can be computed by any algorithmic means. • Any well-defined procedure that can be grasped and performed by the human mind and pencil/paper, can be performed on a conventional digital computer with no bound on memory. The Church-Turing Thesis is NOT a theorem. It is a statement of belief concerning the universe we live in.
Universal Programming Language A language with which a solution to any computable function can be expressed • Examples: “Bare Bones” and most popular programming languages
The Bare Bones Language • Bare Bones is a simple, yet universal language. • Statements • clear name; // while(x){--x;} • incr name; // ++x; • decr name; // --x; • while name not 0 do; … end; 如何做出 x = y; // copy y to x 如何做出 if(x) state_1; else state_2 ; 的效果? 如何做出 invert(x); ?
Figure 12.4 A Bare Bones program for computing X x Y Z = X * Y; 問題: 原來的 X 還在嗎? 如何保存? Hint: 原來的 Y 還在!
Figure 12.5: A Bare Bones implementation of the instruction “copy Today to Tomorrow” Tomorrow = Today; tmp = 0; Tomorrow = 0; while(Today) { tmp++; Today--; } while (tmp) { Today++; Tomorrow+; tmp--; }
Alan Turing (1912-1954) • Published On Computable Numbers …(1936) • Introduced the Halting Problem • Formal model of computation (now known as “Turing Machine”) • Codebreaker at Bletchley Park • Broke Enigma Cipher (二次大戰德軍用) • Perhaps more important than Lorenz • After the war: convicted of homosexuality (then a crime in Britain), committed suicide eating cyanide apple (含氰化物的蘋果) Lorenz: 另一種加密法
Turing 的重要貢獻 • Turing 1936年11月號的Journal of Symnbolic Logic 發表On Computable Numbers, with an Application to the Entscheidungsproblem (論可計算數及其在判定性問題上之應用 ) • Turing於1950年發表了一篇思慮清晰的哲學論文: 計算機械與智慧 (Computing Machinery and Intelligence), 是人工智慧研究上,一篇歷史性的文獻。 • Turing test (Imitation Game; 模仿遊戲 ) • Turing 1954年6月8日Turing死後,其在邏輯與計算機科學領域的貢獻慢慢獲得肯定,美國計算機協會 (Association for Computing Machinery;ACM) 從1966年起設立Turing獎,做為對計算科學有貢獻人士的最高獎項。 (Turing獎被譽為計算機科學界的諾貝爾獎) • 1998年6月22日,英國下議院通過修改法條,使得十六歲以上同性或異性間的自願性行為均屬合法。 2009年9月10日,英國首相布朗發出公函,正式向1952年被政府因其同性戀性傾向受迫害的Alan Mathison Turing正式道歉。(2010年五月英國大選後首相已換David Cameron)
Bletchley Park (布雷奇萊園區) 英國 破解密碼的情報單位 • During World War II the German armed forces top secret codes were broken at Bletchley Park, providing the allies with vital information towards their war effort. Situated 50 miles North-West of London, the site played host to a diverse group of code breakers, including Alan Turing and Dilly Knox. Among the ciphers that were broken were Enigma(奇謎密碼) and Lorenz. • 在第二次世界大戰期間破解Enigma因此大西洋之役中使英國船隊免於遭到德國潛艇(U-boot)狼群戰術的攻擊
The Caesar Cipher 凱撒密碼 • One of the simplest examples of a substitution cipher is the Caesar cipher, which is said to have been used by Julius Caesar to communicate with his army. Caesar is considered to be one of the first persons to have ever employed encryption for the sake of securing messages. • Caesar decided that shifting each letter in the message would be his standard algorithm, and so he informed all of his generals of his decision, and was then able to send them secured messages. Using the Caesar Shift (3 to the right), the message, "RETURN TO ROME" would be encrypted as: "UHWXUQ WR URPH"
The Enigma Cipher (奇謎密碼) • The Enigma cipher is most well known for it's contributions to World War II on the Germans' side. They developed what came to be known as The Enigma Machine. • The machine was based on a system of three rotors that substituted cipher text letters for plain text letters. The rotors would spin in conjunction with each other, thus performing varying substitutions much like the Caeser Shift.
The CODE Book (by Simon Singh ; 賽門‧辛) http://www.books.com.tw/exep/prod/booksfile.php?item=0010131762 • 人類自開始書寫以來即伴隨著密碼術的產生, 我們可以從若干歷史事件當中看出密碼術的演化過程, 以及密碼本身又是如何扮演著改變歷史的關鍵性角色。 一場持續了三千多年的攻防戰至今仍方興未艾, 編碼者不斷努力建造更強的密碼系統來防衛通訊, 解碼者則不斷發明更有威力的方法來破解密碼。 兩者之間的爾虞我詐,動員了各種學科的知識與技術, 將人類科技文明推向不可思議的極限。 編碼者和解碼者之間這場演化競爭的最終贏家是誰? 我們且拭目以待! http://www.kmt.org.tw/Forum/ViewOpinion.asp?Art_Id=1865
The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography 第一章 蘇格蘭瑪麗女王的密碼第二章 無法破解的密碼第三章 秘密書寫的機械化第四章 破解「奇謎」(Enigma Cipher)第五章 語言障礙第六章 愛麗絲和巴伯的公開鑰匙第七章 極佳隱私(PGP)第八章 躍進量子世界密碼挑戰‧十階通達一萬英鎊 附錄A 小說《虛空》開頭第一段附錄B 頻率分析的基本要訣附錄C 所謂的「聖經密碼」附錄D 豬圈密碼附錄E 波雷費密碼附錄F ADFGVX密碼附錄G 單次鑰匙簿的回收缺點附錄H 《每日電訊報》縱橫字謎的秘密附錄I 尚待解譯的古文字附錄J RSA所使用的數學 碼書
Windtalkers獵風行動 -- 主演: Nicolas Cage • 密碼法發展史上,第一個重要的方法-維吉內爾密碼法(Vigenere cypher),這個密碼法在十六世紀被發展出來,也一舉擊潰當時破解密碼者擅長的頻率分析法。 • 但是,這個當時堪稱無敵的密碼法到了十九世紀,仍舊被破解了,破解之人則是提出現代計算機模型的先驅—現代計算機之父: 巴貝奇(Charles Babbage)。 • 另一種加密法-使用少數民族語言,例如在二次世界大戰中當時美軍為了不讓日軍破解密碼所使用的納瓦荷語(Navajo) 。 • 2001/07/26美國總統布希26日頒獎給一批納瓦荷族美國印第安人,表揚他們錯綜複雜的語言提供美軍一種無法破解的密碼,在第二次世界大戰期間協助美國擊敗日本的貢獻。將此一事蹟拍成電影的華人導演吳宇森也應邀觀禮。
Computability Theory The theory of what can and can’t be computed by an ideal computer is called Computability Theoryor Recursion Theory.
Fix any finite set of symbols, . Fix any precise programming language, e.x., Java. A program is a finite string of characters that is syntactically valid.A function f: * -> * is computable if there is a program P that when executed on an ideal computer, computes f. That is, for all strings x belongs to *, P(x) = f(x). Computable Function
Decidability A problem P is decidable if some Turing machine decides (solves) the problem. Consider problems with answer YES or NO Decidable problems: • Does Machine M have three states ? • Is string w a binary number? • Does DFA M accept any input?
Decision problems A decision problem is a computational problem with a yes or no answer. Example: Is the number n prime? Why focus on decision problems? Decision problems are simple: This makes it easy to develop a rigorous mathematical theory. Decision problems are surprisingly general: Many other problems can be recast in terms of decision problems that are essentially equivalent.
Recasting other problems as decision problems Multiplication problem:What is the product of m and n? Multiplication decision problem:Is the kth bit of the product of m and n a one? Time required to solve one of these problems is the same (to within a small overhead) as the time required to solve the other. Factoring problem:What is the smallest non-trivial factor of n? Factoring decision problem:Does n have a non-trivial factor smaller than k? Time required to solve one of these problems is the same (to within a small overhead) as the time required to solve the other.
The Turing machine that decides (solves) a problem answers YES or NO for each instance of the problem YES Input problem instance Turing Machine NO
The machine that decides (solves) a problem: • If the answer is YES • then halts in a yes state • If the answer is NO • then halts in a no state These states may not be final states
Turing Machine that decides a problem YES states NO states YES and NO states are halting states
Some problems are undecidable: which means: there is no Turing Machine that solves all instances of the problem A problem is undecidable if it cannot be solved by any Turing machine that halts on all inputs. A simple undecidable problem: The Halting problem
The Halting problem • Given the encoded version of any program, return 1 if the program is self-terminating, or return 0 if the program is not. • P(x) means the output that arises from running program P on input x • P(P) means the output obtained when we run P on the text of its own source code. • Write a program HALT such that: HALT(P) = yes, if P(P) halts HALT(P) = no, if P(P) does not halt
THEOREM: There is no program to solve the halting problem (Alan Turing 1937) • Suppose a program HALT, solving the halting problem, existed: • HALT(P)= yes, if P(P) halts • HALT(P)= no, if P(P) does not halt • We will call HALT as a subroutine in a new program called CONFUSE.
CONFUSE(P): If HALT(P) then loop_for_ever; Else return (i.e., halt); <text of subroutine HALT goes here> -------------------------------------------- Does CONFUSE(CONFUSE) halt? YES implies HALT(CONFUSE) = yes thus, CONFUSE(CONSFUSE) will not halt NO implies HALT(CONFUSE) = no thus, CONFUSE(CONFUSE) halts CONTRADICTION
Figure 12.7 Proving the unsolvability of the halting program
The halting problem again Does program x halt on input of x? Is there an algorithm to solve the halting problem, that is, to compute h(x)? PROGRAM: TURING(x) IF h(x) = 1 THEN HALT ELSE loop forever Suppose such an algorithm exists. Let T be the program number for TURING. Contradiction! h(T) = 0 TURING(T) halts h(T) = 1
Figure 12.9 The merge sort algorithm implemented as a procedure MergeSort
Figure 12.10 The hierarchy of problems generated by the merge sort algorithm
Efficiency insolvable insolvable hard soluble soluble soluble easy Nomenclature: easy = “tractable” = “efficiently computable” hard = “intractable” = “not efficiently computable” Definition: A problem is easy if there is a Turing machine to solve the problem that runs in time polynomialin the size of the problem input. Otherwise the problem ishard. This definition is usually applied to both decision problems and more general problems.
Can it be decided efficiently? • Class P problems: problems that can be solved in polynomial time with a deterministic machine. • Class NP problems (Cook 1971): problems that can be solved in Polynomial time with a Non-deterministic machine. Theory: unknown if P = NP. • Class NP-Complete problems: a problem X is NP-Complete if it can be converted in polynomial time to an NP-Complete problem Y.
NonDeterministic Turing Machine • States • 0 Initial • 1 Record • 2 Look for 0 • 3 Look for 1 • 4 Scan Left • 5+ Rest of program Read Symbol B 0 1 0 1,B,R — — 1 accept,B,R 2,B,R 3,B,R — 2,0,R 4,2,L 2,1,R 2 Current State — 3,0,R 3,1,R 4,2,L 3 5,B,R 4,0,L 4,1,L 4 Nondeterministic TM: 2 possible actions from single point ‘—’ means no possible action from this point Deterministic TM: At most one possible action at any point
Figure 12.11 Graphs of the mathematical expressions n, lg n, n lg n, and n2