Search code examples
automataturing-machines

Turing machine designing from equation


How can I design the following Turing machine concept? ( there was one 'L' look a like '1')

enter image description here

My attempt is given also, but it was not correct....

enter image description here


Solution

  • So it looks like you need a TM to recognize strings like this:

    • begins with (L+1) instances of X
    • continues with (L) instances of Y
    • ends with (L+3) instances of Z
    • for L > 0

    We need a strategy that ensures our TM can keep track of how many of each symbol there is. We can imagine a multi-tape solution would be pretty simple:

    1. use three auxiliary tapes: one to count instances of X, one to count instances of Y, and one to count instances of Z
    2. scan the input tape left to right, verifying that X comes before Y and Y comes before Z, and copying the symbols to the auxiliary tapes
    3. reset the tape heads and scan left to right, verifying the following:
    • there is at least one Y
    • there is exactly one more X than there are Y; that is, the X tape has an X when you see the first blank on the Y tape, and the X tape has a blank when you see the second blank on the Y tape
    • there are exactly three more Z than Y; that is, the Z tape has a Z when you see the first, second and third blanks on the Y tape, and the Z tape has a blank when you see the fourth blank on the Y tape

    Rather than try to write down a multi-tape TM, let's go for a single-tape TM:

    1. cross off X and Y until all the Y are crossed off, then verify there is just one more X remaining
    2. uncross the Y
    3. cross off Y and Z until all the Y are crossed off, then verify there are three Z remaining

    Here's a transition table:

    q    t    q'    t'    d      comment
    --   ---  --    --    -----  -------
    q0   X    q0    X     right  move right to find at least one Y
    q0   Y    q1    V     left   then cross it out and start looking for an X
    
    q1   U,V  q1    U,V   left   keep looking for an X to cross off
    q1   X    q2    U     right  cross off the X and start looking for more Y
    
    q2   U,V  q2    U,V   right  keep looking for more Y to cross off
    q2   Y    q1    V     left   we found another Y, cross off and keep going
    q2   Z    q3    Z     left   no more Y, start looking for last X
    
    q3   U,V  q3    U,V   left   keep looking for last X
    q3   X    q4    U     left   need to make sure this was the last one
    
    q4   #    q5    #     right  it was the last X, go check V & Z now
    
    q5   U    q5    U     right  skip the crossed off X (now U)
    q5   V    q5    Y     right  skip crossed off Y, and uncross back to Y
    q5   Z    q6    W     left   cross off a Z and start looking for V
    
    q6   V,W  q6    V,W   left   skip any crossed off Y/Z and look for Y
    q6   Y    q7    V     right  cross off Y, go look for more Z
    q6   U    q8    U     right  no more Y, ensure three uncrossed Z
    
    q7   V,W  q7    V,W   right  skip any crossed off Y/Z and look for Z
    q7   Z    q6    W     left   cross off another Z and start looking for Y
    
    q8   V,W  q8    V,W   right  skip any crossed off Y/Z and look for Z
    q8   Z    q9    W     right  found one Z, need two more
    
    q9   Z    qA    W     right  found a second Z, need one more
    
    qA   Z    qB    W     right  found a third Z, need zero more
    
    qB   #    hA    #     left   no more Z, halt-accept