Karel as a Turing Machine CSE-111 12/03/04. Facts Any programming language which satisfies Boehm & Jacopini's conditions can be expressed by means of.

Slides:



Advertisements
Similar presentations
1 karel_IF_part1 Conditional Statements Flavor 1: if ( ) { } For now: these are method invokations (see next slide)
Advertisements

Karel – Making More Complex Decisions IF / THEN / ELSE IF THEN BEGIN Instructions END ELSE BEGIN Instructions END Do these when test = False Do these when.
Copyright, Joseph Bergin
Nested If Statements While Loops
1 karel_part4_functions.ppt Functions Functions return values or Objects. –Using a function allows the programmer to focus on other task. –Using a function.
Karel’s Sensory Equipment This PPT originated with Dr. Untch and Dr. Hankins Modifications have been made by Dr. Cripps.
CMPUT 101 Lab # 2 September 17, :00 – 16:50.
Karel The Robot Nested If Statements While Loops Copyright © 2008 by Helene G. Kershner.
Karel the Robot -- ITERATE Problem Statement: Karel is told to “take a walk around the block!” Revise Algorithm: Define move ahead 5 streets Define turnright.
Conditionals How do we solve tasks in which every particular of a task is not specifically known? – A robot needs the ability to survey its immediate environment.
Polymorphism Are there different ways to solve the Harvester problem? – Robot teams – instead of one robot to solve a problem, let’s get a team of robots.
Homework #9 Solutions.
Whatiscompn.ppt version: What Is Computation? William J. Rapaport Department of Computer Science & Engineering, Department of Philosophy, Department.
Presented by Ravi Teja Pampana
Chapter 5 Conditionally Executing Instructions
1 karel_part5_loops Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit (known)
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Models of Computation - Turing Machines Dale Roberts, Lecturer.
Recursion – means to recur or to repeat – A different way to get a robot to repeat an action A programming language that allows recursive definitions (and.
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.
5.2: Solving Systems of Equations using Substitution
1 Karel J Robot OOP approach to learning computer science “Its study involves development of the ability to abstract the essential features of a problem.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
Chapter 5.  We’ve been using UrRobot – knows only 5 things  Let’s now use a new type of Robot: Robot!  i.e. – public class MileMover extends Robot.
Solving Systems of Equations By Substitution – Easier
Computation Motivating questions: What does “computation” mean? What are the similarities and differences between computation in computers and in natural.
ITK 168 Decisions Dr. Doug Twitchell September 20, 2005.
Computer Theory Michael J. Watts
Karel J. Robot Chapter 6 Instructions That Repeat.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
1 Turing Machines - Chap 8 Turing Machines Recursive and Recursively Enumerable Languages.
December 3, 2009Theory of Computation Lecture 21: Turing Machines III 1 Simulation of T in L Now the MIDDLE section of Q can be generated by replacing.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
1 Introduction to Turing Machines
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Karel J. Robot Chapter 5 Conditionally Executing Instructions.
Karel J Robot Chapter 5.
1 Chapter 5 Karel J Robot 2 Chapter 5 Chapter 5 Conditional Statements Flavor 1: if ( ) { } For now: these are method invocations (see next slide)
Turing Theory. Turing Machine A Turing Machine denoted by TM, is a collection of six things. –An alphabet  of input letters –A TAPE divided into a sequence.
Karel J. Robot Chapter 6 Instructions That Repeat.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
TM Macro Language MA/CSSE 474 Theory of Computation.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
TMs for {a2n | n  0} {a2n | n  0}
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Karel J Robot.
CS 106A, Lecture 2 Programming with Karel
Theory of Computation Lecture 22: Turing Machines III
Predicates Predicate: A Boolean (yes-no) function. Example:
CSE 105 theory of computation
Karel J Robot OOP approach to learning computer science
Karel the Robot – Making Decisions
CSE 105 theory of computation
Karel J Robot OOP approach to learning computer science
Recall last lecture and Nondeterministic TMs
Nested If Statements While Loops
CSE 105 theory of computation
CSE 105 theory of computation
Theory of Computation Lecture 22: Turing Machines II
Theory of Computation Lecture 23: Turing Machines III
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Karel as a Turing Machine CSE /03/04

Facts Any programming language which satisfies Boehm & Jacopini's conditions can be expressed by means of a Turing machine. Any programming language which satisfies Boehm & Jacopini's conditions can be expressed by means of a Turing machine. The reverse is also true i.e. any programming language can be used to program a Turing Machine The reverse is also true i.e. any programming language can be used to program a Turing Machine

Turing Machine-Recapitulation A tape of (infinite) squares with a tape head. A tape of (infinite) squares with a tape head. Squares contain 0, 1 Squares contain 0, 1 Tape head

Turing Machine-Recapitulation Performs the following actions Performs the following actions Tape head

Performs the following actions Performs the following actions 1. Move-left-one- square Turing Machine-Recapitulation Tape head

Performs the following actions Performs the following actions 1. Move-left-one- square 2. Move-right-one- square Turing Machine-Recapitulation Tape head

Performs the following actions Performs the following actions 1. Move-left-one- square 2. Move-right-one- square 3. Print-0-at-current- square Turing Machine-Recapitulation Tape head

Performs the following actions Performs the following actions 1. Move-left-one- square 2. Move-right-one- square 3. Print-0-at-current- square 4. Print-1-at-current- square Turing Machine-Recapitulation Tape head

Performs the following actions Performs the following actions 1. Move-left-one- square 2. Move-right-one- square 3. Print-0-at-current- square 4. Print-1-at-current- square 5. Erase Turing Machine-Recapitulation Tape head

Karel as a TM For Karel to work as a TM find an infinite tape. find an infinite tape. A way to represent 0 and 1. A way to represent 0 and 1. Program Karel to imitate the 5 functions or verbs Program Karel to imitate the 5 functions or verbs

Infinite Tape? Karel has Karel has infinite number of streets infinite number of streets infinite number of avenues infinite number of avenues

Infinite Tape The 1 st street and The 1 st street and 1 st avenue can be used as the tape. Each corner can be used as a square on the tape Each corner can be used as a square on the tape

Representation of 0 and 1 2 beeper on corner can represent a square with a 0 2 beeper on corner can represent a square with a 0 1 beeper on corner can represent a square with a 1 1 beeper on corner can represent a square with a 1 A corner with no beepers is a blank square A corner with no beepers is a blank square

Programming Karel to become a TM Define 5 new instructions in Karel for each of the 5 functions/verbs of Turing Machine. Define 5 new instructions in Karel for each of the 5 functions/verbs of Turing Machine. Define all other instructions that may be required (by the 5 verb-instructions or the main program). Define all other instructions that may be required (by the 5 verb-instructions or the main program). Write the main program which should perform the task of the Turing machine Write the main program which should perform the task of the Turing machine

Move-left-one-square face-west face-west If on first street, (except on 1 st ave) If on first street, (except on 1 st ave) front should be clear so move. front should be clear so move.

Move-left-one-square face-west face-west If on first street, (except on 1 st ave) If on first street, (except on 1 st ave) front should be clear so move. front should be clear so move. If on first avenue, If on first avenue, face-north and move.

Move-left-one-square face-west face-west If on first street, (except on 1 st ave) If on first street, (except on 1 st ave) front should be clear so move. If on first avenue, If on first avenue, face-north and move. If on a corner with no beeper, print -0 or put 2 beepers If on a corner with no beeper, print -0 or put 2 beepers

define-new-instruction move-left as begin face-west; if front-is-clear then moveelsebeginface-north;moveend; if not-next-to-a-beeper then print-0; end; end; Move-left-one-square

define-new-instruction move-right as begin face-south; if front-is-clear then moveelsebeginface-east;moveend; if not-next-to-a-beeper then print-0; end; end; Move-right-one-square

Print-0 Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Pick all the beepers at the current corner (there may be 1 or 2 beepers already) define-new-instruction print-0 as begin pickallbeeper; putbeeper; putbeeperend;

Print-0 Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Put 2 beepers. Put 2 beepers. define-new-instruction print-0 as begin pickallbeeper; putbeeper; putbeeper;end;

Print-1 Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Pick all the beepers at the current corner (there may be 1 or 2 beepers already) define-new-instruction print-1 as begin pickallbeeper; putbeeper; end;

Print-0 Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Pick all the beepers at the current corner (there may be 1 or 2 beepers already) Put 1 beeper. Put 1 beeper. define-new-instruction print-1 as begin pickallbeeper; putbeeper; end;

Erase Check whether at left end Move left but don’t print 0(or put beeper)Move left but don’t print 0(or put beeper) if not on a beeper (i.e indeed on left end)if not on a beeper (i.e indeed on left end)  Move right but don’t print 0 ( go back to previous corner)  Pick all the beepers (erase)  Move right but don’t print 0(move to square on right) if on a beeperif on a beeper  Move right but don’t print 0 Check whether at right end

Erase Move right but don’t print 0(or put beeper)Move right but don’t print 0(or put beeper) if not on a beeper (i.e indeed on right end)if not on a beeper (i.e indeed on right end)  Move left but don’t print 0 ( go back to previous corner)  Pick all the beepers (erase)  Move left but don’t print 0(move to square on left) if on a beeperif on a beeper  Move left but don’t print 0

Erase define-new-instruction erase as begin begin move-left-without- putting-beeper; if not-next-to-a-beeper then begin moveright-without- putting-beeper; pickallbeeper; moveright-without- putting-beeper endelsebegin moveright-without- putting-beeper; moveright-without-putting-beeper; if not-next-to-a-beeper then if not-next-to-a-beeper thenbegin moveleft- without-putting -beeper; pickallbeeper; moveleft- without-putting -beeperendelse moveleft-without- putting-beeper moveleft-without- putting-beeper end endend;

How to write a Turing Machine flowchart in Karel Example: Negation of a binary digit Example: Negation of a binary digit I/P: 1 square O/P: 2 square

How to write a Turing Machine flowchart in Karel Example: Negation of a binary digit Example: Negation of a binary digit I/P: 1 square O/P: 2 square Start Is 0? Move right Print 1 Stop False True

How to write a Turing Machine flowchart in Karel For Karel: For Karel: See whether he is on the corner with one or two beepers, move right, and place beepers accordingly move right, and place beepers accordingly Start Is 0? Move right Print 1 Stop False True

How to write a Turing Machine flowchart in Karel beginning-of-execution beginning-of-execution if next-to-a-beeper then beginpickbeeper; if next-to-a-beeper then begin if next-to-a-beeper then beginputbeeper;move-right;print-1endelsebeginputbeeper;move-rightendend;turnoff;end-of-execution Start Is 0? Move right Print 1 Stop False True