Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, I need help with this exercise please: Write the transition table for the Turing machine. Organise the transitions by state or by the order
Hello, I need help with this exercise please:
Write the transition table for the Turing machine.
Organise the transitions by state or by the order they're executed Section
Use descriptive state names.
Suggestions: Write and test a machine that handles evenlength inputs and then handles oddlength inputs.
'Remove' ie blank out input symbols as you process them.
You should add tests to check your Turing machine, but you won't be awarded any marks for your tests.
You don't have to remove your tests before submitting this TMA.
In palindrometests set the debug parameter toTrueif you want to see
the configurations your Turing machine goes through.
Make sure youset it back toFalseand run the cell again before submittingyour
TMA.
############
Here is the code
from mtm import runTM ##### This class is at the bottom
RIGHT
LEFT
STAY
palindrome
# write the transitions here in the form
# state symbol: newsymbol, LEFT or RIGHT or STAY, newstate
palindrometests
# case, TM input tape, debug, output tape
palindrome palindrome, True,
not palindrome', palindrome, True,
testrunTM palindrometests
########################
THIS IS THE runTM class:
RIGHT
LEFT
STAY
MAXSTEPS
def runTMtm:dict, tape:list, debug:bool list:
Run Turing machine tm on tape and return the resulting output.
The machine runs from state 'start' until it halts or has done MAXSTEPS.
The output is the tape's content from the head onwards.
If debug is True, print each configuration.
Preconditions:
tm maps state symbol pairs to symbol movement, state triples
states are represented by strings
symbols are of any hashable type
movement is one of RIGHT, LEFT, STAY
tape is a list of symbols
the blank symbol is represented as None
head
if tape :
tape None
symbol tapehead
state 'start'
step
if debug:
printstep state, tape:head symbol, tapehead:
while step MAXSTEPS and state symbol in tm:
actions tmstate symbol
tapehead actions # write symbol may be the same
head head actions # move left, right or stay
state actions # next state may be the same
step step
if head :
printMoved left past the start of the tape'
head
step MAXSTEPS # force loop to finish
elif head lentape:
tape.appendNone # extend tape when needed
symbol tapehead
if debug:
printstep state, tape:head symbol, tapehead:
output tapehead:
while output and output None:
output.pop
return output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started