0% found this document useful (0 votes)
49 views3 pages

Ch9ex New

The document describes a Turing machine that compares two unary encoded numbers x and y on its tape. The TM has states to mark 1s in x and y with x symbols until it reaches the delimiter 0. If x runs out of 1s before y, it enters the state qn indicating x < y. If y runs out of 1s first, it enters the state qy indicating x ≥ y. If they have the same number of 1s, it also enters qy. The TM replaces symbols with 1s, 0s, and xs as needed to restore the original string at the end of the computation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

Ch9ex New

The document describes a Turing machine that compares two unary encoded numbers x and y on its tape. The TM has states to mark 1s in x and y with x symbols until it reaches the delimiter 0. If x runs out of 1s before y, it enters the state qn indicating x < y. If y runs out of 1s first, it enters the state qy indicating x ≥ y. If they have the same number of 1s, it also enters qy. The TM replaces symbols with 1s, 0s, and xs as needed to restore the original string at the end of the computation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Examples 11/14/03 Ex 9.

.7 TM which accepts L = {anbn: n 1} Q = {q0, q1, q2, q3, q4} F = {q4} = {a, b}, = {a, b, x, y, } Algorithm: Replace left-most a by x Move head to left-most b and replace by x Replace left-most a with x Replace left-most b with y etc. If no as and no bs remain w L. (Below detects too many as) (q0, a) = (q1, x, R) replace left-most a with x (q1, a) = (q1, a, R) move head right through as (q1, y) = (q1, y, R) move head right through ys (q1, b) = (q2, y, L) replace left-most b, reverse head direction [if we encounter (q1, ) string is rejected no such rule too many as] (q2, y) = (q2, y, L) move left through ys (q2, a) = (q2, a, L) move through as (q2, x) = (q0, x, R) detect 1st x, go to q0, move to 1st a? will ultimately HALT if no more as, y will be next input, must define this for q0 below: Now see if all as and bs replaced If we go back to q0 and get a y, We have: (Below detects too many bs) go to q3 (check mode) move through ys all bs used since all as used to get here, string accepted [if we encounter (q3, b) string is rejected no such rule too many bs] (q0, y) = (q3, y, R) (q3, y) = (q3, y, R) (q3, ) = (q4, , R)

Ex 9.9 Adder compute x + y Use unary notation Want: Q0w 0 w(y) * qf w(x+y)0 Simply shift the zero to right end: Q = {q0, q1, . . . q4}, F = {q4} (q0, 1) = (q0, 1, R) move through 1,s in q0 (q0, 0) = (q1, 1, R) found 0, replace it by 1 (q1, 1) = (q1, 1, R) move through 1s in q1 (q1, ) = (q2, , L) end of line go left (q2, 1) = (q3, 0, L) replace last 1 by 0 (q3, 1) = (q3, 1, L) move to left end of 1s (q3, ) = (q4, , R) park on left-most 1, final state Ex 9.11 Given x and y encoded as unary numbers. Compare: Goto qy if x u Goto qn if x < y q0 w(x) 0 w(y) * qy w(x) 0 w(y) if x y q0 w(x) 0 w(y) * qn w(x) 0 w(y) if x < y Use idea of accepter for anbn (Example 9.7) Ex 9.4 TM implementation of comparer General idea: xx11110xx111111 Xx1111110xx11111 - Similar algorithm is used for accepting {anbn; n 1} - Initial tape q0w(x) 0 w(y) w(x) and w(y) unary rep. of a number, 0 is a delimiter. - would like q0w(x) 0 w(y) * qy w(x) 0 w(y), xy * qn w(x) 0 w(y), x<y - Match 1s in w(x) with 1s in w(y) but this time they do not necessarily have to match up for success 3 cases for results: xx110xxxx xxxx0xxxx xxxx0xx11 x > y end in state qy x = y end in state qy x < y end in state qn w(s) = 11111 |w(x)| = x

TM Code For Compare Q = {q0, q1, q31, q3x, q4, q5, qy1, qn1, qy, qn} = , input alphabet is irrelevant = {0, 1, x, } F = {qy, qn} q0 = initial state = Below: Note: q2 not used

(q0, 1) = (q1, x, R) Mark off a 1 in w(x) (q0, 0) = (q3x, 0, R) No 1s left in w(x) (q1, 1) = (q1, 1, R) Move right through 1s in w(x) (q1, 0) = (q31, 0, R) We encountered the 0 while in q1 Continue processing when there still are 1s in w(x) (q31, x) = (q31, x, R) Move through xs in w(y) (q31, 1) = (q4, x, L) Mark off a 1 in w(y) (q31, ) = (qy0, , L) No more 1s in w(y) theres an unmatched one in w(x): x > y (q4, x) = (q4, x, L) Continue processing move left through xs in w(y) (q4, 0) = (q5, 0, L) Detect 0 in q5 (q5, 1) = (q5, 1, L) Move left through remaining 1s in w(x) (q5, x) = (q0, x, R) Detect x in w(x), goto start: q0 Processing for no ones left in w(x), after detecting 0 (go right) (q3x, x) = (q3x, x, R) Move through xs in w(y) (q3x, 1) = (qn1, 1, L) x < y, excess 1s in w(y) (q3x, ) = (qy1, , L) x = y, same # 1s in w(x) and w(y) Reset head (finish up) - stands for 1, 0, or x (qy1, -) = (qy1, -, L) Move left through all symbols (3 rules) (qy1, ) = (qy, , R) Done x y (qn1, -) = (qn1, -, L) Move left through all symbols (3 rules) (qn1, ) = (qn, , R) Done x < y A final note: In resetting the head (last 4 rules), we should also replace all xs with 1s (and the 0 with a 0), in order to restore the string to its original state, for example: Replace (qy1, -) = (qy1, -, L) With the two rules: (qy1, x) = (qy1, 1, L) and (qy1, 0) = (qy1, 0, L)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy