INAM ULLAH KHAN
B12101038
2nd year section A MORNING
Turing Machine
Turing Machines is a Model of Computation.Turing
Machine is for modelling human computers.Human
Computers are Computers which we use.
A Turing machine has three component.
-An unending tape divided into squares.The tape is the
workspace.Input,ouput and intermediate calculations are
written on the tape.we think of the tape as infinite both to
the right and to the left(if you prefer:imagine that we
always have the possibility of adding more squares, at
either end, should we need them)
-There is a read/write head(or simple,head) which moves
along the tape ,the tape is restricted in its movement :it
can only move one square left or right at a time. The head
can read the symbol(if any) that is written on the tape, and
write one of the finite number of symbols on the tape.
Formal definition
Hopcroft and Ullman (1979, p. 148) formally defined a
(one-tape) Turing machine as a 7-tuple where
• is a finite, non-empty set of states
• is a finite, non-empty set of the tape alphabet/symbols
• is the blank symbol (the only symbol allowed to occur
on the tape infinitely often at any step during the
computation)
• is the set of input symbols
• is the initial state
• is the set of final or accepting states.
• is a partial function called the program function or
instruction where L is left shift, R is right shift. (A
relatively uncommon variant allows "no shift", say N,
as a third element of the latter set.)
Anything that operates according to these specifications is
a Turing machine.
Turing Machine for
Multiplication
Multiplication in unary notation:
To compute the product of two unary numbers separated
by 0 i.e.,
1 0 1
For a machine with so many states, it becomes tedious to
represent the steps of the computation. Instead, we can
give a general description of the behavior of Multiplication
Following are the steps:
1 Decrement i.
2.Write a 0 at the end of the input string
3.Move to the right and write j 1s.
4.Repeat steps (1) and (2) i-1 times and (3) i-2 times.
5.Remove the 0s. We are left with i * j 1s, the product of i
and j in unary notation.
Example
Multiplication of 3 and 4, So the unary representation of
3 and 4 and is separated by zero in between them:
111 0 1111
Step 1: Decrement 3.
11 0 1111
Step 2:write a zero at the end of input string
011 0 1111
Step 3:Move to the right and write No’s of 1’s contain 4
011 0 11111111
Repeat steps (1)i-1 times and (2) i-2 times.
Step 1: Decrement 2.
01 0 1111
Step 2:write a zero at the end of input.
001 0 11111111
Step 3: move to the right and write No’s of 1’s contain 4
0010 111111111111
Step 1: Decrement 1.
00 0 1111
Step 2:write a zero at the end of input string
000 0 111111111111
Step 3: Remove the zeroes then we are left with 3*4 in
unary notation.
111111111111
Turing Machine For
Sum Of Product
1. Replace ‘x’ mark with 0
2. Decrement i.
3. Write a 0 at the end of the i
4. Move to the right of ‘x’ mark and write j 1s.
5. Repeat steps (2) and (3) i-1 times and step (4) i-2 times.
6. Remove the 0s separating the i groups of j ones.
We are left with i * j 1s, the product of i and j in unary
notation
7.After the multiplication of i and j, move towards right till
+ mark occurs .when the + mark occur ignore the + mark
for a while until the multiplication of X and Y is done and
move towards right by one box.
8.Decrement X.
9. Write a 0 at the end of the X
10. Move to the right of ‘x’ mark and write Y 1s.
11.Repeat step (8) and (9) X-1 times and Step (10) i-2
times
12. Remove the 0s separating the X groups of Y ones.
We are left with X * Y 1s, the product of X and Y in unary
notation.
Step 1: First of all replace ‘x’ mark with 0
11 0 1111 + 111 0 1
Step 2: Decrement i.
1 0 1111 + 111 0 1
Step 3:write a zero at the end of I;
01 0 1111 + 111 0 1
Step 4: move to the right and write No’s of 1’s contain 4
01 0 11111111 + 111 0 1
Step 5:Repeat step (1) and (2) 2-1 times i.e 1 time and
step (3) 2-2 times i.e 0 time
Step 2: Decrement i.
0 0 1111 + 111 0 1
Step 3:write a zero at the end of i
00 0 11111111 + 111 0 1
Step 6:Remove the zeroes from the left side of ‘+’ mark
then we are left with 2*4 in unary notation on the left side
of ‘+’ mark
11111111 + 111 0 1
Step 7:
After the multiplication of 2 and 4, move towards right till +
mark occurs .when the + mark occur ignore the + mark for
a while until the multiplication of 3 and 1 is done and move
towards right by one box.
Step 8: Decrement X
1111111 + 11 0 1
Step 9:write a zero at the end of X;
11111111 + 011 0 1
Step 10: move to the right write No’s of 1’s contain 1
11111111 + 011 0 11
Step 11:Repeat step (8) and (9) X-1 times step (10) X-2
times i.e 0 time
Step 8: Decrement X.
11111111 + 01 0 11
Step 9:write a zero at the end of X
11111111 + 001 0 11
Step 10: move to the right write No’s of 1’s contain 1
11111111 + 001 0 111
Step 8: Decrement X.
11111111 + 00 0 11
Step 8:write a zero at the end of x
11111111 + 000 0 111
Step 12:Remove the zeroes from the right side of ‘+’ mark
then we are left with 3*1 in unary notation on the right side
of ‘+’ mark
11111111 + 111
Now perform the sum of 8 and 3 in unary representation.
Replace ‘+’ mark with 0.
Move to the left most input of input string
1
1 1 1 1 1 1 1 1 0 1 1 1 0. . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0. . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0. . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0. . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0 . . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0 . . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0 . . .
1-Right -1
1
1 1 1 1 1 1 1 1 0 1 1 1 0 . . .
1-Right -2
2
1 1 1 1 1 1 1 1 1 1 1 1 0. . .
1-Right -2
2
1 1 1 1 1 1 1 1 1 1 1 1 0. . .
1-Right -2
2
1 1 1 1 1 1 1 1 1 1 1 1 0. . .
1-Right -2
2
1 1 1 1 1 1 1 1 1 1 1 1 0. . .
0-left -3
3
1 1 1 1 1 1 1 1 1 1 1 1 0. . .
Halt
1 1 1 1 1 1 1 1 1 1 1 0 0. . .

Turing machine(automata )

  • 1.
    INAM ULLAH KHAN B12101038 2ndyear section A MORNING Turing Machine Turing Machines is a Model of Computation.Turing Machine is for modelling human computers.Human Computers are Computers which we use. A Turing machine has three component. -An unending tape divided into squares.The tape is the workspace.Input,ouput and intermediate calculations are written on the tape.we think of the tape as infinite both to the right and to the left(if you prefer:imagine that we always have the possibility of adding more squares, at either end, should we need them) -There is a read/write head(or simple,head) which moves along the tape ,the tape is restricted in its movement :it can only move one square left or right at a time. The head can read the symbol(if any) that is written on the tape, and write one of the finite number of symbols on the tape. Formal definition Hopcroft and Ullman (1979, p. 148) formally defined a (one-tape) Turing machine as a 7-tuple where • is a finite, non-empty set of states • is a finite, non-empty set of the tape alphabet/symbols
  • 2.
    • is theblank symbol (the only symbol allowed to occur on the tape infinitely often at any step during the computation) • is the set of input symbols • is the initial state • is the set of final or accepting states. • is a partial function called the program function or instruction where L is left shift, R is right shift. (A relatively uncommon variant allows "no shift", say N, as a third element of the latter set.) Anything that operates according to these specifications is a Turing machine. Turing Machine for Multiplication Multiplication in unary notation: To compute the product of two unary numbers separated by 0 i.e., 1 0 1
  • 3.
    For a machinewith so many states, it becomes tedious to represent the steps of the computation. Instead, we can give a general description of the behavior of Multiplication Following are the steps: 1 Decrement i. 2.Write a 0 at the end of the input string 3.Move to the right and write j 1s. 4.Repeat steps (1) and (2) i-1 times and (3) i-2 times. 5.Remove the 0s. We are left with i * j 1s, the product of i and j in unary notation. Example Multiplication of 3 and 4, So the unary representation of 3 and 4 and is separated by zero in between them: 111 0 1111 Step 1: Decrement 3. 11 0 1111 Step 2:write a zero at the end of input string 011 0 1111 Step 3:Move to the right and write No’s of 1’s contain 4 011 0 11111111 Repeat steps (1)i-1 times and (2) i-2 times.
  • 4.
    Step 1: Decrement2. 01 0 1111 Step 2:write a zero at the end of input. 001 0 11111111 Step 3: move to the right and write No’s of 1’s contain 4 0010 111111111111 Step 1: Decrement 1. 00 0 1111 Step 2:write a zero at the end of input string 000 0 111111111111 Step 3: Remove the zeroes then we are left with 3*4 in unary notation. 111111111111 Turing Machine For Sum Of Product
  • 5.
    1. Replace ‘x’mark with 0 2. Decrement i. 3. Write a 0 at the end of the i 4. Move to the right of ‘x’ mark and write j 1s. 5. Repeat steps (2) and (3) i-1 times and step (4) i-2 times. 6. Remove the 0s separating the i groups of j ones. We are left with i * j 1s, the product of i and j in unary notation 7.After the multiplication of i and j, move towards right till + mark occurs .when the + mark occur ignore the + mark for a while until the multiplication of X and Y is done and move towards right by one box. 8.Decrement X. 9. Write a 0 at the end of the X 10. Move to the right of ‘x’ mark and write Y 1s. 11.Repeat step (8) and (9) X-1 times and Step (10) i-2 times 12. Remove the 0s separating the X groups of Y ones.
  • 6.
    We are leftwith X * Y 1s, the product of X and Y in unary notation. Step 1: First of all replace ‘x’ mark with 0 11 0 1111 + 111 0 1 Step 2: Decrement i. 1 0 1111 + 111 0 1 Step 3:write a zero at the end of I; 01 0 1111 + 111 0 1 Step 4: move to the right and write No’s of 1’s contain 4 01 0 11111111 + 111 0 1 Step 5:Repeat step (1) and (2) 2-1 times i.e 1 time and step (3) 2-2 times i.e 0 time Step 2: Decrement i. 0 0 1111 + 111 0 1 Step 3:write a zero at the end of i 00 0 11111111 + 111 0 1 Step 6:Remove the zeroes from the left side of ‘+’ mark then we are left with 2*4 in unary notation on the left side of ‘+’ mark 11111111 + 111 0 1
  • 7.
    Step 7: After themultiplication of 2 and 4, move towards right till + mark occurs .when the + mark occur ignore the + mark for a while until the multiplication of 3 and 1 is done and move towards right by one box. Step 8: Decrement X 1111111 + 11 0 1 Step 9:write a zero at the end of X; 11111111 + 011 0 1 Step 10: move to the right write No’s of 1’s contain 1 11111111 + 011 0 11 Step 11:Repeat step (8) and (9) X-1 times step (10) X-2 times i.e 0 time Step 8: Decrement X. 11111111 + 01 0 11 Step 9:write a zero at the end of X 11111111 + 001 0 11 Step 10: move to the right write No’s of 1’s contain 1 11111111 + 001 0 111 Step 8: Decrement X. 11111111 + 00 0 11 Step 8:write a zero at the end of x
  • 8.
    11111111 + 0000 111 Step 12:Remove the zeroes from the right side of ‘+’ mark then we are left with 3*1 in unary notation on the right side of ‘+’ mark 11111111 + 111 Now perform the sum of 8 and 3 in unary representation. Replace ‘+’ mark with 0. Move to the left most input of input string 1 1 1 1 1 1 1 1 1 0 1 1 1 0. . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0. . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0. . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0. . . 1-Right -1
  • 9.
    1 1 1 11 1 1 1 1 0 1 1 1 0 . . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 . . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 . . . 1-Right -1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 . . . 1-Right -2 2 1 1 1 1 1 1 1 1 1 1 1 1 0. . . 1-Right -2 2 1 1 1 1 1 1 1 1 1 1 1 1 0. . . 1-Right -2 2 1 1 1 1 1 1 1 1 1 1 1 1 0. . . 1-Right -2 2 1 1 1 1 1 1 1 1 1 1 1 1 0. . . 0-left -3 3 1 1 1 1 1 1 1 1 1 1 1 1 0. . . Halt 1 1 1 1 1 1 1 1 1 1 1 0 0. . .