Programming Assignment 7(1)

2
7/21/2019 Programming Assignment 7(1) http://slidepdf.com/reader/full/programming-assignment-71 1/2 Due 12/22 Construct a Turing machine that subtracts one ternary integer (base 3) from another. An input will be of the form !"# where an$ " are elements of %&# 1# 2' . n particular# * + n + n,1  ... + 1 + & # an$ " * y m y m,1  ... y 1 y & # with each + i # y i  in %&# 1# 2'# * (+ n  + 3 n ) (+ n,1  + 3 n,1 ) ... (+ 1  + 3 1 ) (+ &  + 3 & )# an$ " * (y m  + 3 m ) (y m,1  + 3 m,1 ) ... (y 1  + 3 1 ) (y &  + 3 & ). "our Turing machine must be a single tape# one way infinite# $eterministic Turing machine. -or this program you can use the left# right# an$ stay $irecties. hen the Turing machine completes the tape shoul$ contain 0# where 0 * , ". "ou $o not nee$ to $elete !" from the tape# you can simply position the Turing machine rea$/write hea$ at the beginning of 0. -or this assignment you will probably want to use blocs (in$ of lie Turing machine subroutines in -A4) to buil$ your Turing machine. "our Turing machine cannot mae use of the blan spaces to the left of the input string an$ lea$ing 5eros are to be remoe$ from 0 (again# you can simply position the rea$/write hea$ at the appropriate place). -A4 has some unhappiness with filenames containing special characters an$ $on6t now all the symbols that cause problems ( stic with alphanumeric# an$ hae ha$ problems with 7 an$ ! , -A4 throws an error when trying to sae the program after inserting the bloc). There us no guarantee that 8 "# so you will nee$ to put a negatie sign in front of some of the results. t too me 3 9 : hours to implement the program an$ about an hour to test it. will test your program with 2& test strings. ;ach test string has <& = >># >"> = 1&&. ;ach test string taes about 1 secon$ to run with my program# an$ half of the string hae ? " an$ half of the strings hae @ ". -or my Turing machine hae * % &# 1# 2# 3 !' an$ B * % &# 1# 2# !# 7# a# b# c# 6 6# @# 8'. y Turing machine uses blocs for the following actions. nsert terminator at the left en$ of the tape ( states) put two 7s at the left en$ of the input as a way to $etermine if an$ " hae been swappe$ (that is# to $etermine if a minus sign nee$s to by place$ at the left en$ of the result) Eewin$ the tape (2 states) only use this a couple of times# since hae the same functionality har$ co$e$ in multiple places Fsing this more woul$ most liely re$uce the number of states in a couple of the blocs Get larger (3 states) Fp$ates a marer that eeps trac of wether is larger than " hen comparing an$ "# use a H8I at the en$ of the input to $enote ? " Get " larger (3 states) Fp$ates a marer that eeps trac of wether is larger than " hen comparing an$ "# use a H@I at the en$ of the input to $enote @ " Correct or$er (23 states# < blocs 9 some may be $uplicates) Compare an$ " to $etermine which is larger# if @ "# then they are swappe$ an$ a minus sign is place in front of the result Jase$ on the symbol at the en$ of the input (H@I or H8I)# we now if ? " or @ " f H@I is at the en$ of the input# then an$ " are swappe$ (actually is copie$ to the right of ")  As an$ " are compare$# from right to left# the symbol (H@I or H8I) at the en$ of the string is up$ate$ each time the current +i an$ yi $on6t match $on6t bother forcing an$ " to hae the same length when performing this comparison  Appen$ &/1/2 (3 states) Fse$ when swapping an$ " to put the current symbol at the tail en$ of the input 1 of 2

description

wefwef

Transcript of Programming Assignment 7(1)

Page 1: Programming Assignment 7(1)

7/21/2019 Programming Assignment 7(1)

http://slidepdf.com/reader/full/programming-assignment-71 1/2

Due 12/22

Construct a Turing machine that subtracts one ternary integer (base 3) from another. An input will beof the form !"# where an$ " are elements of %&# 1# 2'. n particular# * +n+n,1 ... +1+&# an$ " *ymym,1 ... y1y&# with each +i# yi in %&# 1# 2'# * (+n + 3n) (+n,1 + 3n,1) ... (+1 + 31) (+& + 3&)# an$ " *(ym + 3m) (ym,1 + 3m,1) ... (y1 + 31) (y& + 3&). "our Turing machine must be a single tape# one wayinfinite# $eterministic Turing machine. -or this program you can use the left# right# an$ stay $irecties.hen the Turing machine completes the tape shoul$ contain 0# where 0 * , ". "ou $o not nee$ to

$elete !" from the tape# you can simply position the Turing machine rea$/write hea$ at thebeginning of 0. -or this assignment you will probably want to use blocs (in$ of lie Turing machinesubroutines in -A4) to buil$ your Turing machine. "our Turing machine cannot mae use of theblan spaces to the left of the input string an$ lea$ing 5eros are to be remoe$ from 0 (again# youcan simply position the rea$/write hea$ at the appropriate place). -A4 has some unhappiness withfilenames containing special characters an$ $on6t now all the symbols that cause problems ( sticwith alphanumeric# an$ hae ha$ problems with 7 an$ ! , -A4 throws an error when trying to saethe program after inserting the bloc).

There us no guarantee that 8 "# so you will nee$ to put a negatie sign in front of some of theresults. t too me 3 9 : hours to implement the program an$ about an hour to test it. will test your

program with 2& test strings. ;ach test string has <& = >># >"> = 1&&. ;ach test string taes about 1secon$ to run with my program# an$ half of the string hae ? " an$ half of the strings hae @ ".-or my Turing machine hae * % &# 1# 2# 3 !' an$ B * % &# 1# 2# !# 7# a# b# c# 6 6# @# 8'.

y Turing machine uses blocs for the following actions.• nsert terminator at the left en$ of the tape ( states)

◦ put two 7s at the left en$ of the input as a way to $etermine if an$ " hae beenswappe$ (that is# to $etermine if a minus sign nee$s to by place$ at the left en$ of theresult)

• Eewin$ the tape (2 states)◦ only use this a couple of times# since hae the same functionality har$ co$e$ in multiple

places◦ Fsing this more woul$ most liely re$uce the number of states in a couple of the blocs

• Get larger (3 states)◦ Fp$ates a marer that eeps trac of wether is larger than "◦ hen comparing an$ "# use a H8I at the en$ of the input to $enote ? "

• Get " larger (3 states)◦ Fp$ates a marer that eeps trac of wether is larger than "◦ hen comparing an$ "# use a H@I at the en$ of the input to $enote @ "

• Correct or$er (23 states# < blocs 9 some may be $uplicates)◦ Compare an$ " to $etermine which is larger# if @ "# then they are swappe$ an$ a

minus sign is place in front of the result

◦ Jase$ on the symbol at the en$ of the input (H@I or H8I)# we now if ? " or @ "◦ f H@I is at the en$ of the input# then an$ " are swappe$ (actually is copie$ to the right

of ")◦  As an$ " are compare$# from right to left# the symbol (H@I or H8I) at the en$ of the string is

up$ate$ each time the current +i an$ yi $on6t match◦ $on6t bother forcing an$ " to hae the same length when performing this comparison

•  Appen$ &/1/2 (3 states)◦ Fse$ when swapping an$ " to put the current symbol at the tail en$ of the input

1 of 2

Page 2: Programming Assignment 7(1)

7/21/2019 Programming Assignment 7(1)

http://slidepdf.com/reader/full/programming-assignment-71 2/2

Due 12/22

• nsert &/1/2 (K states)◦ Fse$ to insert the current alue of +i 9 yi at the left en$ of the output

• 4erform subtraction (3: states# < blocs 9 some may be $uplicates)◦ Does the actual subtraction◦ 4rocesses an$ " from right to left

• ain program (1 state# blocs 9 some may be $uplicates)◦ nitiali5es the $ata an$ calls the arious blocs

;,mail the -A4 file to me ($ai$.garrisonLbinghamton.e$u) by 11M<NM<N.NNNpm on the $ate $ue.The filename must be your last name followe$ by HOp.PffI (as an e+ample# my filename woul$ beHgarrisonOp.PffI).

2 of 2