4

The machine takes 2 natural numbers (a, b) as input in unary form and outputs the integer quotient and the remainder of the integer division a / b. What would the initial and final state on the tape be? What would the functionality diagram look like?

Thanks in advance.

  • 1
    I'm voting to close this question as off-topic because stack overflow is not a code writing service. Thats true even for sensible architectures of computation nevermind ones that would be pursued essentially only to prove that you can. – Chris Stratton Dec 24 '19 at 20:53
  • I am just asking for guidance, because I can find little to no information on this specific topic. – Panagiotis Iatrou Dec 24 '19 at 20:55
  • 1
    @Panagiotis Iatrou You should use what you know about math and about Turing machines to *try and figure it out* -- you already have enough information to do so. I'll give you a hint: use long division. – Dante Falzone Dec 25 '19 at 05:02

1 Answers1

1

A design to use here is the following:

  1. cross off b instances of 1 from the part of the tape representing a, and increment a new part of the tape representing the quotient q each time you do it.

  2. if you ever have more 1s in b than you have remaining in the part that used to represent a, stop dividing; the symbols remaining represent the remainer and whatever your current quotient is, that's the answer

An implementation might do the following:

  1. take the input as #11...1011...1# where the first string of 1s represents a in unary, the second string represents b in unary, # is a blank and the tape head initially starts on the leftmost 1;

  2. immediately go write a Q at the end of the tape; anything after this is the quotient

  3. check whether b > a; if so, run some routine to rewrite the quotient and remainder in a pretty format before terminating. check by bouncing back and forth across the 0 and temporarily marking pairs of cells, then change them back to 1s afterwards.

  4. otherwise, change the b leftmost instances of 1 to X, go add a 1 after the rightmost 1, and then repeat from step 3. Mark off the b instances by bouncing back and forth across the 0 and temporarily marking the 1s comprising b so you don't double count; then, change them back to 1s.

Example:

initial tape: #11111011#
after step 2: #11111011Q#
after step 3: (same)
after step 4: #XX111011Q1#
after step 3: (same)
after step 4: #XXXX1011Q11#
after step 3: #1101# (formatted)
Patrick87
  • 27,682
  • 3
  • 38
  • 73