Construct turing machine that adds two ternary real numbers

Assignment Help Theory of Computation
Reference no: EM133155110

Question: Construct a Turing machine that adds two ternary real numbers. An input will be of the form X#Y, where X and Y are elements of {0, 1, 2}+.{0, 1, 2}+. In particular, X = xnxn-1 ... x1x0.x-1x-2 ... x-k, and Y = ymym-1 ... y1y0.y-1y-2 ... y-l with xi, yi in {0, 1, 2}, X = (xn x 3n) + (xn-1 x 3n-1) + ... + (x1 x 31) + (x0 x 30) + (x-1 x3-1) + ... + (x-k x 3-k), and Y = (ym x 3m) + (ym-1 x 3m-1) + ... + (y1 x 31) + (y0 x 30) + (y-1 x 3-1) + ... + (y-1 x 3- l).

Your Turing machine must be a single tape, one way infinite, deterministic Turing machine. When the Turing machine completes, the tape should contain Z, where Z = X + Y. You do not need to delete X#Y from the tape, you can simply position the Turing machine's read/write head at the beginning of Z (leftmost symbol of Z).

For your result to be correct, it will not have any leading 0s to the left of the decimal point unless Z is less than 1, and the result will not having any trailing 0s to the right of the decimal point, unless Z is an integer. That is, the following are invalid, 02.0 and 2.10, and likewise the following three are valid, 0.2, 1.0, and 0.0. For the trailing 0s, you can move to the right end of Z and move left over 0s, overwriting them with blank spaces, until either a 1, a 2, or a decimal point is found.

If a decimal point is found, the blank space to the right of it can be changed back to a 0. For leading 0s, when you position the read/write head on the leftmost symbol of Z, you can simply move to the right of any leading 0s until either a 1, a 2, or a decimal point is found. If a decimal point is found, simply move left. For this assignment you may want to use blocks (subroutines in JFLAP) to build your Turing machine. You can also make use of the S directive for read/write head motion (L - left, R- right, S - stay). You may use the "~" to match any symbol for reading/writing in a transition. Otherwise any transition must read/write a single symbol. You may not use the JFLAP transitions like "(a,b,c}w; w, R)" (stores a symbol in a JFLAP internal variable).

Your Turing machine cannot make use of the blank spaces to the left of the input string. JFLAP has some unhappiness with filenames containing special characters and I don't know all the symbols that cause problems (I stick with alphanumeric and the underscore symbol, and have had problems with $, #, and the blank space in block file names). When you create a block, I would suggest you create it as a separate file, test it, and then insert it into your main program (or a block that goes into your main program). I've heard from students that if you are editing a block from within your main program and you save the block before closing it, it will overwrite your file with the block you are editing (you need to exit block edit mode prior to saving). Keep backup copies of all of your file (often). You can do a save as while editing a block to save the block as a separate file.

It took me about three hours to implement my version of the program, an hour to test/debug it, and probably an hour to write a Java program to verify the output was correct (unfortunately Java's BigDecimal class doesn't support non-base 10 representations). For my final test I generated 1000 random strings of the form X#Y where X and Y have length between 4 and 10 symbols and ran my program against the strings and verified that the result of adding X and Y was correct.

Below is some additional information about my implementation.

My Turing machine uses 4 blocks. The blocks perform the following actions.
• InsertLeftTerminatorAndAppendDollarSign - block that inserts a "tiny_mce_markerquot; at the left end of the input, shifting all of the input to the right one position, and appends a "#" at the right end of the string
- The block has 9 states and rewinds the tape leaving the read/write head under the "tiny_mce_markerquot;
- The "#" appended to the input is to mark where Z (Z = X + Y) begins
• fixOrder - block that reorders X & Y if X has less symbols to the right of the decimal point than does

? The block has 24 states
? After this block completes we have the first of the two strings has at least as many symbols to the right of the decimal point as the second - this is to make it more efficient to pad the second of the two with 0s such that they have the same number of symbols to the right of the decimal point
• fixLength - block that appends 0s to the end of Y to make X & Y have the same number of digits to the right of the decimal point
? The block has 12 states
• performAddition - block that actually adds X & Y
? The block has 46 states
? We will discuss performing ternary addition in class
• main program - uses the four blocks and one accept state

My Turing machine uses an input alphabet of {0, 1, 2, ., #} and a tape alphabet of {0, 1, 2, ., x, a, b, c, #, $, blank space}. The x is used to mark symbols of X and Y as having been processed and a, b, and c are used to mark 0, 1, and 2 when they need to be restored in the future (in fixOrder & fixLength).

I also did a verion of the program without using blocks. Assuming I counted correctly, it has 85 states. Below is an image of the version of my program that uses blocks (no real help there).

Below is an image of the version of my program that doesn't use blocks. All of the transitions have been replaced with a single transition. The image is to show the same structure works without blocks.

Attachment:- Programming assignment.rar

Reference no: EM133155110

Questions Cloud

Discuss the implications specifically for motivation : Moreover, he was travelling almost everywhere to every workshop. Marcus explained to Kathy that he is a winner and hoping to be promoted. In the monthly quarter
Patient medical record categories contains : Provide a summary of what information each of the key patient medical record categories contains: patient demographic, socioeconomic, administrative, financial,
Importance and urgency of sustainability : Do you think multinational corporations understand the importance and urgency of sustainability? If so, how do you see the change? If not, why not and what can
Compute for the capital gains tax : The local stock exchange at its fair market value amounting to P550,000. Cost of the shares sold is P300,000. Compute for the capital gains tax
Construct turing machine that adds two ternary real numbers : Construct a Turing machine that adds two ternary real numbers - deterministic Turing machine. When the Turing machine completes, the tape should contain Z
Crime data from victims of crime : Uniform Crime Reports (UCR), National Incident-Based Reporting System (NIBRS), and Crime Data from Victims of Crime:
Leadership team regarding role that government intervention : Provide a memo to your leadership team regarding the role that government intervention will play in your expansion to the specific country you selected for your
Read extensively about restaurant budgeting : Now that you've read extensively about restaurant budgeting, explain what the main factors are that contribute to the high rate of failure that restaurants expe
Make an income statement for the period ending december : Stock on 31 December 2014 was valued at $2,000,000. Make an income Statement for the period ending 31 December 2014

Reviews

Write a Review

Theory of Computation Questions & Answers

  Finite-state machine design

Create a finite-state machine design to turn your FPGA development board into a simple programmable music box.

  Redundant sequence identi cation

Redundant sequence identi cation

  Compute a shortest superstring

Dynamic programming algorithm to compute a shortest superstring.

  Propositional and predicate logic

Write down a structural induction principle for the PlayTree free type

  Design a syntactic analyzer

Design a syntactic analyzer for the language specified by the grammar

  Design unambiguous grammar to parse expressions

Write a program would read two numbers and then print all numbers between the first and the second, inclusive. Design unambiguous grammar to parse expressions

  Consider a logic function with three outputs

Consider a logic function with three outputs,  A ,  B , and  C , and three inputs,  D ,  E , and  F . The function is defined as follows:  A  is true if at least one input is true,  B  is true

  Considering a single programmed operating system

Considering a single programmed operating system, what is the minimal total time required to complete executions of the two processes? You should explain your answer with a diagram.

  How to construct an nfa

Give a construction that assumes you are given a DFA for L and show how to construct an NFA (with or without ε-moves) to recognize sort(L).

  Equivalence classes to construct minimal dfa for language

How many equivalence classes does this relation have and what are they? Use these equivalence classes to construct the minimal DFA for the language.

  Impact of moore-s law on data center costs

Discuss the impact of Moore's law on data center costs on such things as servers and communications equipment. List at least 3 steps or recommendations your data center can take to offset some or all of the effect of Moore's law.

  Problem encountered in statements in predicate logic

How the problem would be encountered in attempting to represent the following statements in Predicate logic. it should be possible to: John only likes to see French movies.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd