GithubHelp home page GithubHelp logo

mycloud012 / multiplicationturingmachine Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 27 KB

This repository simulates a code for Turing Machine which perform multiplication operation followed by addition of 1, f(x) = 7x + 1

Java 100.00%

multiplicationturingmachine's Introduction

MultiplicationTuringMachine

This repository simulates a code for Turing Machine which perform multiplication operation followed by addition of one. f(x) = 7x + 1

Problem Analysis

For the given problem 𝑓 (π‘₯) = 7π‘₯ + 1 π‘“π‘œπ‘Ÿ π‘’π‘£π‘’π‘Ÿπ‘¦ π‘₯ β‰₯ 0, it is required to essentially create a Turing Machine for multiplying two number such that 𝑓 (π‘₯, y) = XY , finally at the end of the multiplication , an addition operation shall be performed to the output such that 𝑓 (π‘₯,y) = π‘₯ + y.

Problem Solution

In order to perform multiplication of two numbers, initially the numbers will be converted into unary system and then inserted into the tape. In the given problem, the tape alphabet will consist of {#, 0, 1, *, X, Y}.

Initially β€œ#” will be inserted into the tape indicating start of an input, followed by 7 ones, followed by β€œ*” sign.

On the right hand of the tape (after the β€œ*” symbol) the multiplier will be inserted followed by β€œ#” indicating end of input, assuming the multiplier is 2, then the tape will look like this:

The machine which performs the multiplication procedure followed by the addition is shown below:

The Turing Machine procedure works as below:

  1. In q0, if the read symbol is β€œ#”, head to the right. If β€œ1” was read, then change it to β€œX” and move right, change state to q1.

  2. In q1, if the read symbol is β€œ1” keep moving right (basically escaping all the ones) until the β€œ*” is reached, head to state q2 and move right.

  3. In state q2 (now the reading hand is standing after the β€œ*” symbol), if the read symbol is β€œ1”, change it to β€œY” and head toward state q3, and move right.

  4. In q3, for every read β€œ1” move right (basically escaping all the ones on the RHS) until β€œ#” is reached, change state to q4 and move right.

  5. In q4, if read input is β€œblank” then insert β€œ0” , move right, and head to state q5.

  6. In q5, on reading either {0, #, 1, Y} keep heading to the left side of the tape until the multiplication symbol is reached, head to q2 and repeat the procedure of replacing every β€œ1” with β€œY” and adding β€œ0”to the end of tape, until all the ones on the right side after the β€œ*” changed to β€œY”.

  7. A rest procedure shall be applied to transform the β€œY” into β€œ1” again as long as there still β€œ1”s on the LHS of the multiplication tape. This is performed during the transitions from state q6 to q8.

  8. Eventually, when all the β€œ1”s on the LHS of the multiplication symbol have turned into β€œX”, this indicates that the multiplication procedure is completed and it is time to sum an extra 1 to the output of the multiplication left on the most RHS of tape, this is done by adding an extra β€œ1” to the tape.

The complete version of the Turing Machine which simulates 𝑓 (π‘₯) = 7π‘₯ + 1 π‘“π‘œπ‘Ÿ π‘’π‘£π‘’π‘Ÿπ‘¦ π‘₯ β‰₯ 0

The first part of the machine (RHS) is basically inserting the 7 ones followed by #. Then the machine explained above takes the wheel to compute the multiplication and addition operations.


Complete run output for the function in Java program: https://gist.github.com/MyCloud012/ccfdf8e6e99a50c8834b

If you are interested in this kind of science, I recommend textbook "Introcuction to Theory of computation by Micheal Sipser Ist Ed".

PS: The implementation is not following any of the principles for code modularity, its more like a handy implementation for simulation purposes.

multiplicationturingmachine's People

Contributors

mycloud012 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.