You are on page 1of 2

6

Construct a TM for the addition of two unary numbers.

Ans: Let us consider 2+3. It can be represented on type in unary format as,

q0
To add these two unary numbers, we replace + with 1 and then, we remove
last 1.
Therefore, the corresponding transitions are:

(q0 ,1) ( q0 ,1, R)

(q0 , ) (q0 ,1, R )

(q0 , ) ( q1 , , L)
( q1 ,1) ( qa , , )
qa
where

is the final

state.

Construct a TM for subtraction of two unary numbers. ie. f(a-b)=c where a >b.

Ans: Let a=3 and b=2. Then the tape contains,

(q0 ,1) (q0 ,1, R)


(q0 , ) ( q1 , , R)

(q1 ,1) (q2 ,*, L)


(q2 ,1) (q3 ,*, R)

(q3 , ) (q3 , , R)

(q3 ,*) (q3 ,*, R)


(q3 ,1) ( q1 ,*, L)
(q1 ,*) (q1 ,*, L)
(q1 , ) (q2 , , L)

(q2 ,*) (q2 ,*, L)


(q3 , ) (qa , , )
qa
where
state.

is the final

You might also like