Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by:

Similar documents
Register machines L2 18

CSC : Homework #3

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

(a) Definition of TMs. First Problem of URMs

Turing Machine Variants

Automata Theory CS S-12 Turing Machine Modifications

Computability Theory

Lecture 13: Sequential Circuits, FSM

System Data Bus (8-bit) Data Buffer. Internal Data Bus (8-bit) 8-bit register (R) 3-bit address 16-bit register pair (P) 2-bit address

Design of Sequential Circuits

Theory of Computer Science. D5.1 Introduction. Theory of Computer Science. D5.2 Primitive Recursion vs. LOOP. D5.3 µ-recursion vs.

Lecture 13: Sequential Circuits, FSM

SOLUTION: SOLUTION: SOLUTION:

Section 20: Arrow Diagrams on the Integers

Logic and Computer Design Fundamentals. Chapter 8 Sequencing and Control

Counters. We ll look at different kinds of counters and discuss how to build them

CpSc 421 Final Exam December 15, 2006

Undecidability of the validity problem

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Building Algorithmic Polytopes. David Bremner with D. Avis, H.R. Tiwary, and O. Watanabe December 16, 2014

Part I: Definitions and Properties

Turing Machines. Wolfgang Schreiner

Most General computer?

Design at the Register Transfer Level

Practice Homework Solution for Module 4

Mohammad Farshi Department of Computer Science Yazd University. Computer Science Theory. (Master Course) Yazd Univ.

Q520: Answers to the Homework on Hopfield Networks. 1. For each of the following, answer true or false with an explanation:

CS20a: Turing Machines (Oct 29, 2002)

Parallelism and Machine Models

CMPT-150-e1: Introduction to Computer Design Final Exam

Sequential programs. Uri Abraham. March 9, 2014

Turing machine. Turing Machine Model. Turing Machines. 1. Turing Machines. Wolfgang Schreiner 2. Recognizing Languages

Elementary Algebra - Problem Drill 01: Introduction to Elementary Algebra

Ordinal Computability

Latches. October 13, 2003 Latches 1

An Invitation to Mathematics Prof. Sankaran Vishwanath Institute of Mathematical Sciences, Chennai. Unit I Polynomials Lecture 1A Introduction

Lecture 14: State Tables, Diagrams, Latches, and Flip Flop

Table of Content. Chapter 11 Dedicated Microprocessors Page 1 of 25

Lecture Notes for Chapter 17: Amortized Analysis

MAC Module 1 Systems of Linear Equations and Matrices I

Register Machines Storing Ordinals and Running for Ordinal Time

Part III: A Simplex pivot

CSC D70: Compiler Optimization Static Single Assignment (SSA)

Programming Language Concepts, CS2104 Lecture 3

6.852: Distributed Algorithms Fall, Class 24

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer Engineering Department

#29: Logarithm review May 16, 2009

An Invitation to Mathematics Prof. Sankaran Vishwanath Institute of Mathematical Science, Chennai. Unit - I Polynomials Lecture 1B Long Division

Turing Machines. Nicholas Geis. February 5, 2015

Fundamentals of Boolean Algebra

Turing Machines Part Two

Notes. Relations. Introduction. Notes. Relations. Notes. Definition. Example. Slides by Christopher M. Bourke Instructor: Berthe Y.

ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University

Math 31 Lesson Plan. Day 22: Tying Up Loose Ends. Elizabeth Gillaspy. October 31, Supplies needed: Colored chalk.

CprE 281: Digital Logic

Languages, regular languages, finite automata

Portland State University ECE 587/687. Branch Prediction

CSC 5170: Theory of Computational Complexity Lecture 4 The Chinese University of Hong Kong 1 February 2010

Class Notes: Solving Simultaneous Linear Equations by Gaussian Elimination. Consider a set of simultaneous linear equations:

MATHEMATICAL INDUCTION

On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work

Chapter 4 Continuous Random Variables and Probability Distributions

Algebra 1 Summer Assignment 2018

CSE. 1. In following code. addi. r1, skip1 xor in r2. r3, skip2. counter r4, top. taken): PC1: PC2: PC3: TTTTTT TTTTTT

Chapter 1 Review of Equations and Inequalities

Student Self-Assessment of Mathematics (SSAM) for Intermediate Algebra

EXPERIMENT Bit Binary Sequential Multiplier

Construction of Static Single-Assignment Form

Linear Systems of n equations for n unknowns

Data Structures and Algorithm. Xiaoqing Zheng

CSCE 551 Final Exam, April 28, 2016 Answer Key

Turing Machines Part II

1 Definition of a Turing machine

where Q is a finite set of states

State Machines. Example FSM: Roboant

Lecture for Week 2 (Secs. 1.3 and ) Functions and Limits

CS20a: Turing Machines (Oct 29, 2002)

8.5 Taylor Polynomials and Taylor Series

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

2.6 Variations on Turing Machines

MITOCW watch?v=vug2jncrxyg

Confusion of Memory. Lawrence S. Moss. Department of Mathematics Indiana University Bloomington, IN USA February 14, 2008

Semiconductor Optoelectronics Prof. M. R. Shenoy Department of physics Indian Institute of Technology, Delhi

YOU CAN BACK SUBSTITUTE TO ANY OF THE PREVIOUS EQUATIONS

Virtualization. Introduction. G. Lettieri A/A 2014/15. Dipartimento di Ingegneria dell Informazione Università di Pisa. G. Lettieri Virtualization

Modular numbers and Error Correcting Codes. Introduction. Modular Arithmetic.

Algorithms Exam TIN093 /DIT602

Johns Hopkins Math Tournament Proof Round: Automata

COSE312: Compilers. Lecture 17 Intermediate Representation (2)

Binary addition example worked out

LABORATORY MANUAL MICROPROCESSORS AND MICROCONTROLLERS. S.E (I.T) ( S e m. IV)

Computations on Ordinals

What is a Computer? computer: anything that is able to take a mathematically

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

Lecture 13: Sequential Circuits

UNIVERSITY OF WISCONSIN MADISON

highlights proof by contradiction what about the real numbers?

Finite Automata. Finite Automata

Examples of Unlimited Register Machine programs for Turingcomputable

Section Summary. Proof by Cases Existence Proofs

Transcription:

Models of Computation, 2010 1 Definition Recall Register Machines A register machine (sometimes abbreviated M) is specified by: Slide 1 finitely many registers R 0, R 1,..., R n, each capable of storing a natural number; a program consisting of a finite list of instructions of the form label : body where, for i = 0,1,2,..., the (i + 1) th instruction has label L i. The instruction body takes the form: R + L add 1 to contents of register R and jump to instruction labelled L R L,L if contents of R is > 0, then subtract 1 and jump to L, else jump to L HALT stop executing instructions Recall the Codings of Pairs, Lists and programs x,y 2 x (2y + 1) Pairs For x,y N, define x,y 2 x (2y + 1) 1 Slide 2 Lists For l List N, define l N by [] 0 x :: l x, l = 2 x (2 l + 1) Programs P [ body 0,..., body n ] where body is: R + i L j 2i,j R i L j,l k 2i + 1, j,k HALT 0

Models of Computation, 2010 2 Recall Addition f(x, y) x + y is Computable Slide 3 Registers R 0 R 1 R 2 Program L 0 : R 1 L 1,L 2 L 1 : R + 0 L 0 L 2 : R 2 L 3,L 4 L 3 : R + 0 L 2 Graphical Representation START L 4 : HALT HALT If the machine starts with registers (R 0,R 1,R 2 ) = (0,x,y), it halts R 1 R 2 with registers (R 0,R 1,R 2 ) = (x + y,0,0). R + 0 R + 0 Coding of the RM for Addition P [ B 0,..., B 4 ] where Slide 4 B 0 = R 1 L 1,L 2 = (2 1) + 1, 1,2 = 3,9 = 8 (18 + 1) = 152 B 1 = R + 0 L 0 = 2 0,0 = 1 B 2 = R 2 L 3,L 4 = (2 2) + 1, 3,4 = 5,(8 9) 1 = 5,71 = 2 5 ((2 71) + 1) = 32 143 = 4576 B 3 = R + 0 L 2 = 2 0,2 = 5 B 4 = HALT = 0.

Models of Computation, 2010 3 Decoding Numbers as Bodies and Programs Any x N decodes to a unique instruction body(x): Slide 5 if x = 0 then body(x) is HALT, else (x > 0 and) let x = y,z in if y = 2i is even, then body(x) is R + i L z, else y = 2i + 1 is odd, let z = j,k in body(x) is R i L j,l k So any e N decodes to a unique program prog(e), called the register machine program with index e: prog(e) L 0 :body(x 0 ). where e = [x 0,...,x n ] L n :body(x n ) Example of prog(e) Slide 6 786432 = 2 19 + 2 18 = 0b110. {z.. 0 } = [18, 0] 18 0 s 18 = 0b10010 = 1, 4 = 1, 0,2 = R 0 L 0,L 2 0 = HALT So prog(786432) = L 0 :R 0 L 0,L 2 L 1 :HALT

Models of Computation, 2010 4 Notice that, when e = 0, we have 0 = [] so prog(0) is the program with an list of instructions, which by convention we regard as a RM that does nothing (i.e. that halts immediately). Also, notice in slide 6 the jump to a label with no body (an erroneous halt). Again, choose some numbers and see what the register-machine programs they correspond to. Gadgets To construct register machines which perform complex operations, we introduce gadgets which are small components used to perform small specific operations. A gadget is defined informally as a partial register-machine graph that has a designated initial label and one or more designated labels (which contain no instructions). The gadget operates on registers specified in the gadget s name, and are used for input and output we call these the input/output registers. The gadget may use other registers for temporary storage we call these scratch registers. The gadget assumes the scratch registers are initially set to 0, and must ensure that they are set back to 0 when the gadget s. Ensuring that the scratch registers are reset to 0 is important so that the gadget may be safely used within loops. Gadgets A gadget is a partial register-machine graph. It has one entry wire, and one or more wires. Slide 7 The gadget operates on input and output registers specified in the gadget s name. The gadget may use other registers, called scratch registers, for temporary storage. The gadget assumes the scratch registers are initially set to 0, and must ensure that they are set back to 0 when the gadget s.

Models of Computation, 2010 5 Gadget: zero R 0 Slide 8 The gadget zero R 0 sets register R 0 to be zero, whatever its initial value: entry R 0

Models of Computation, 2010 6 Gadget: add R 1 2 The gadget add R 1 2 adds the initial value of R 1 to register R 2, storing the result in R 2 but restoring R 1 to its initial value. entry Slide 9 R + 2 R 1 S + S R + 1 We can compose gadgets, constructing bigger gadgets and eventually complete register machines. To construct such bigger gadgets, we rename the registers used by each gadget: all of its scratch registers are renamed to things that do not occur in the rest of the machine, and its input/output registers are renamed to whichever registers the program requires. We then wire up the gadgets to make bigger gadgets, by joining (possibly many) wires to the unique entry wire. For example, consider the gadget copy R 1 2 defined on slide 10. We will use this gadget to construct the universal register machine. The gadget copy R 1 2 copies the value of register R 1 into register R 2, leaving R 1 with its initial value. It does this by joining together the zero and add gadgets: it first sets register R 2 to zero, then adds the value of R 1 2 and leaves the value of R 1 the same, using some unnamed scratch register inside the add gadget.

Models of Computation, 2010 7 Gadget: copy R 1 2 The gadget copy R 1 2 copies the value of register R 1 into register R 2, leaving R 1 with its initial value: entry Slide 10 zero R 2 add R 1 2 Now to construct the instance copy R 1 3 of the gadget, we rename the scratch register R 3 to be something completely fresh, say R 7, and rename R 1 and R 2 1 and R 3 respectively. Joining these gadgets together, we obtain the larger gadget copy R 1 2 and R 3.

Models of Computation, 2010 8 Gadget : copy R 1 2 and R 3 entry Slide 11 copy R 1 2 copy R 1 3 Gadget: copy R 1 2 and R 3 entry zero R 2 Slide 12 add R 1 2 zero R 3 add R 1 3

Models of Computation, 2010 9 Gadget: copy R 1 2 and R 3 entry R + 2 R 2 Slide 13 S + 1 R 1 S 1 R + 1 R + 3 R 3 S + 2 R 1 S 2 R + 1 Recall the register machine for multiplication given earlier in the course, which multiplies R 1 by R 2 and stores the result in R 0, possibly overwriting the initial values of R 1 and R 2. We can construct this register machine using the zero and add gadgets.

Models of Computation, 2010 10 Gadgets: multiply R 1 by R 2 0 We can implement multiply R 1 by R 2 0 by repeated addition: entry Slide 14 zero R 0 R 1 add R 2 0 As well as the copy gadget, we require two more gadgets to define the universal register machine: push X to L and pop L to X. Given input values X = x and L = l, the gadget push X to L returns the value X = 0 and L = 2 x (2l + 1). Given input value L = x,l and X = y, the gadget pop L to X returns X = x and L = l. Given input L = 0, the gadget returns X = 0 and L = 0.

Models of Computation, 2010 11 Gadget: push X to L The gadget push X to L : Slide 15 entry Z + L Z X Z + L + Given input values X = x, L = l and Z = 0, it returns the output values X = 0,L = x,l = 2 x (2l + 1) and Z = 0: Z + 2L = 2 x X (2l + 1) L = 2 x X (2l + 1), Z = 0 Slide 16 entry Z + L Z X Z + L + X = x, L = l, Z = 0 Z + L = 2 x X (2l + 1) X = 0, L = 2 x (2l + 1), Z = 0

Models of Computation, 2010 12 The gadget pop L to X : Gadget: pop L to X X + Slide 17 L + L Z Z entry X L Z + L + If L = 0 then return X = 0 and go to. If L = x,l then return X = x and L = l, and go to. n = 2 X+1 L, Z = 0 n = 2 X (L + Z) n = 2 X (2L + Z) Slide 18 L = n, X = y, Z = 0 L + entry X L X + L Z Z + L + Z n = 2 X (2L + Z + 1) n = 0 = L = X = Z n = 2 X (2L + 1), Z = 0

Models of Computation, 2010 13 The Universal Register machine A universal register machine (URM) is a register machine that can simulate an arbitrary register machine on arbitrary input. It achievs this by reading the code (unique description) of the machine to be simulated and the code (unique description) of the input. The Universal Register Machine The universal regiseter machine carries out the following computation, starting with R 0 = 0, R 1 = e (code of a program), R 2 = a (code of Slide 19 a list of arguments) and all other registers zeroed: decode e as a RM program P decode a as a list of register values a 1,..., a n carry out the computation of the RM program P starting with R 0 = 0,R 1 = a 1,...,R n = a n (and any other registers occurring in P set to 0).

Models of Computation, 2010 14 Mnemonics for the registers of U and the role they play in its program: R 0 result of the simulated RM computation (if any). R 1 P code of the RM to be simulated R 2 A code of current register contents of simulated RM Slide 20 R 3 PC program counter number of the current instruction (counting from 0) R 4 N code of the current instruction body R 5 C type of the current instruction body R 6 R current value of the register to be incremented or decremented by current instruction (if not HALT ) R 7 S and R 8 T are auxiliary registers. R 9... other scratch registers. Overall structure of the URM 1 copy PC th item of list in P to N (halting if PC > length of list); goto 2 2 if N = 0 then halt, else decode N as y,z ; C ::= y; N ::= z; Slide 21 goto 3 {at this point either C = 2i is even and current instruction is R + i L z, or C = 2i + 1 is odd and current instruction is R i L j,l k where z = j,k } 3 copy ith item of list in A ; goto 4 4 execute current instruction on R; update PC to next label; restore register values ; goto 1

Models of Computation, 2010 15 Gadget: copy R 1 2 The gadget copy R 1 2 copies the value of register R 1 into register R 2, leaving R 1 with its initial value: entry Slide 22 zero R 2 add R 1 2 Gadget: push X to L The gadget push X to L : Slide 23 entry Z + L Z X Z + L + Given input values X = x, L = l and Z = 0, it returns the output values X = 0,L = x,l = 2 x (2l + 1) and Z = 0:

Models of Computation, 2010 16 The gadget pop L to X : Gadget: pop L to X X + Slide 24 L + L Z Z entry X L Z + L + If L = 0 then return X = 0 and go to. If L = x,l then return X = x and L = l, and go to. The Universal Register Machine Slide 25 START pop S 0 copy P to T pop T to N P 0 to C HALT copy N R + R N + to S

Models of Computation, 2010 17 The Universal Register Machine Slide 26 START pop S 0 copy P to T pop T to N P 0 to C HALT copy N R + R N + to S The Universal Register Machine Slide 27 START pop S 0 copy P to T pop T to N P 0 to C HALT copy N R + R N + to S

Models of Computation, 2010 18 The Universal Register Machine Slide 28 START pop S 0 copy P to T pop T to N P 0 to C HALT copy N R + R N + to S The Universal Register Machine Slide 29 START pop S 0 copy P to T pop T to N P 0 to C HALT copy N R + R N + to S