Sei sulla pagina 1di 22

CT111-3-2-COMT Computing Theory Individual Assignment

ASIA PACIFIC UNIVERSITY

UC2F1801CS

CT111-3-2-COMT

COMPUTING THEORY

Hand out date : 12th February 2018

Hand in date : 6th April 2018

Weightage : 50%

Lecturer : Dr. Booma Poolan Marikannan

________________________________________________________________________

Name : Daniel Lee Yao Yi TP99999

Level 2 Asia Pacific University of Technology and Innovation Page 1 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Contents

Introduction ......................................................................................................................... 3

Part A: Non Deterministic Finite Automata ....................................................................... 5

Identifying the tuples ....................................................................................................... 5

Transition Table .............................................................................................................. 6

NFA Diagram .................................................................................................................. 7

Computation Tree............................................................................................................ 8

Test I: W, W, B ............................................................................................................... 9

Test II: B, W, B ............................................................................................................. 10

Test III: B, B, W, B ....................................................................................................... 11

Test IV: W, W, W, W, B ............................................................................................... 12

Test V: B, W, W, B, W, B............................................................................................. 13

Part B: Regular Expressions ............................................................................................. 14

Rule I ............................................................................................................................. 14

Rule II............................................................................................................................ 15

Rule III .......................................................................................................................... 16

Rule IV .......................................................................................................................... 16

Conclusion ........................................................................................................................ 21

References ......................................................................................................................... 22

Level 2 Asia Pacific University of Technology and Innovation Page 2 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Introduction

The following documentation is a study on Computing Theory where it mainly focuses


on Nondeterministic Finite Automata (NFA), Definitive Finite Automata (DFA) and
regular expressions which are parts of Computing Theory. This documentation contains
two parts which include the creating of a NFA diagram and also converting a NFA to
regular expressions.

According to DifferenceBetween.net, the theory of computation is a branch of computer


science that deals with how problems are solved using algorithms which further branches
into three separate theories where one of them is the automaton theory. (Emelda M., 2013)

Furthermore, according to Amal Dar Aziz at Stanford dot edu, the automaton theory
established its roots during the 20th Century as mathematicians began developing
machines which imitated certain features of man that completes calculations more
quickly and reliably. In short, automata theory deals with the logic of computation with
respect to simple machines. (Amal Dar Aziz, 2004)

The automaton theory has several classes which include Deterministic Finite Automata
(DFA) and Nondeterministic Finite Automata (NFA) where both are transition functions
of automaton. In transition, the main difference between NFA and DFA is that in NFA,
for a single input symbol, the machine can move to any combination of states. Or in other
words, a single input can be transitioned to more than one state in the machine which also
represents that the machines moves cannot be determined.

DFA on the other hand has only one state transition for every input that it receives and it
also only has one final state for its transition. This also means that in DFA, for each input
that is read, there is only one corresponding state in DFA, hence for the same set of
inputs, it will reach the same state at the end. If the end state does not reach the final state
of the machine, it will reject it. (Emelda M., 2013)

Level 2 Asia Pacific University of Technology and Innovation Page 3 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

As for regular expressions, just as how finite automata are used to recognize patterns of
strings, regular expressions are used to generate patterns of string. Furthermore,
according to Malte Helmert, DFA and NFA can both describe regular languages and we
can denote them by using regular expressions. (Malte Helmert, 2016)

Operands that can exist in regular expressions are characters like alphabets, epsilon ε,
which denotes empty strings that contain no characters and also null which denotes the
empty set of strings. Operations on the other hand are also in regular expressions which
include union which is represented with U or +, concatenation which is represented with
the symbols “.” and Kleene closure “*”. (Regular Expressions, n.d)

Level 2 Asia Pacific University of Technology and Innovation Page 4 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Part A: Non Deterministic Finite Automata

In detail, a Non Deterministic Finite Automata consists of five tuples which are Q, ∑, δ,
q0 and F where Q is the finite set of states, ∑ is the set of inputs, δ being the transition
states, q0 is the initial state and finally F being the final state.

Diagram 1: 3 X 3 Chess board

Identifying the tuples

To create a Non Deterministic Finite Automata for the 3 X 3 chess board above,
we will first need to identify the 5 tuples for this machine. The states for this machine
will be the numbered squares on the chess board where each number or square represents
a state in the machine, therefore Q = {1,2,3,4,5,6,7,8,9,}. The next will be the set of
inputs that it will receive which is either white or black for it to move to the adjacent
white or black square, therefore ∑ = {W, B} “W” for white, “B” for black. For the initial
state and final state of this machine, the rule states that the start state and the final stat
must be in opposite corners, therefore we can conclude that there will be four possibilities
where the machine will start at. For example if q0 = {1} then the final state will be F =
{9}; if q0 = {3} then the final state will be F = {7}; if q0 = {7} then the final state will be
F = {3}; if q0 = {9} then the final state will be F = {1}.

To create this machine, we will assume one initial state, which is at square 1 or
state 1. Next, at first the machine will receive an input which will be either white or
black, based on the rule given, if the input is white, it will have to move to white squares

Level 2 Asia Pacific University of Technology and Innovation Page 5 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

adjacent to it, which is state or square 2 or 4; if the input was black, it should move to
state 5, and from the state moved, receive another input and have the possibility to move
to another set of states. With this same concept, we are able to plot out a state transition
table to show all the possible states that the machine can transition to in each state that is
on the chessboard which is from 1 to 9.

Transition Table

Input W B
State
1 2,4 5

2 4,6 1,3,5

3 2,6 5

4 2,8 1,5,7

5 2,4,6,8 1,3,7,9

6 2,8 3,5,9

7 4,8 5

8 4,6 5,7,9

9 6,8 5

Table 1: State Transition Table of NFA

Based on the transition table created, for every state, we can now clearly see each
possible state that the machine will transition to when a certain input is provided. Now
based on the transition table created, we can draw a NFA diagram that clearly shows how
a machine will transition between the states based on the accepted input.

Level 2 Asia Pacific University of Technology and Innovation Page 6 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

NFA Diagram

Start

Diagram 2: NFA diagram

With the transition table and NFA diagram planned out, we can now test them out
by provide a series of inputs to test them. For example, if the inputs provided are “w”,
“w” and “b” we can check if whether it reaches the final state or not, if the final state is
included in the states transitioned to after the final input, then the set of inputs are correct
and can be accepted as it applies all the rules in getting to the final state.

Level 2 Asia Pacific University of Technology and Innovation Page 7 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Computation Tree

Diagram 3: Computation Tree of NFA

Based on the transition table created, we are able to draw a tree diagram to show
all the possible moves and also outcomes that the machine will reach upon. At state 1, the
input received is white hence the available options for the move to be made are state 2 or
state 4. At state 2, the input is also white hence the possible states are states 4 and 6; state
4 on the other hand will have the possibility to move to states 2 and 8. And this goes the
same for the next input which is black where the end states 1, 3, 5, 7 and 9 are all
possibilities. As we can see, the end state of the transition includes state 9 which is the
final state of the machine hence this input is accepted as it can reach the final state. Based
on the above tree, the machine can clearly predict every move that will be taken to reach
the final point.

Level 2 Asia Pacific University of Technology and Innovation Page 8 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Test I: W, W, B

Diagram 4: Transition of input W, W, B on the NFA diagram

The subset construction of the transition can also be written as


δ(1, W) = 2;
δ( δ(1, W), W) = 6;
δ( δ( δ(1, W), W), B) = 9;

Level 2 Asia Pacific University of Technology and Innovation Page 9 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Test II: B, W, B

Diagram 5: Transition of B, W, B on the NFA diagram

Subset Construction of the transition


δ(1, B) = 2;
δ( δ(1, B), W) = 6;
δ( δ( δ(1, B), W), B) = 9

Level 2 Asia Pacific University of Technology and Innovation Page 10 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Test III: B, B, W, B

Diagram 6: Transition of B, B, W, B on the NFA diagram

Subset construction of the transition


δ(1, B) = 5;
δ( δ(1, B), B) = 3;
δ( δ( δ(1, B), B), W) = 6;
δ( δ( δ( δ(1, B), B), W), B) = 9;

Level 2 Asia Pacific University of Technology and Innovation Page 11 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Test IV: W, W, W, W, B

Diagram 7: Transition of W, W, W, W, B on the NFA diagram

Subset construction of the transition


δ(1, W) = 2;
δ( δ(1, W), W) = 4;
δ( δ( δ(1, W), W), W) = 8;
δ( δ( δ( δ(1, W), W), W), W) = 6;
δ( δ( δ( δ( δ(1, W), W), W), W), B) = 9;

Level 2 Asia Pacific University of Technology and Innovation Page 12 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Test V: B, W, W, B, W, B

Diagram 8: Transition of B, W, W, B, W, B

Subset construction of the transition


δ(1, B) = 5;
δ( δ(1, B), W) = 2;
δ( δ( δ(1, B), W), W) = 6;
δ( δ( δ( δ(1, B), W), W), B) = 5;
δ( δ( δ( δ( δ(1, B), W), W), B), W) = 8;
δ( δ( δ( δ( δ( δ(1, B), W), W), B), W), B) = 9

Level 2 Asia Pacific University of Technology and Innovation Page 13 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Part B: Regular Expressions

Rule I

Diagram 9: Initial state that accepts inputs

Based on Naomi Nishimura, to convert the above NFA to a regular expression


form, the first step is to avoid the initial state from accepting any inputs, and if the initial
state accepts any input, we should add another state as its initial state. After adding the
initial state, the new state should have an empty input pointing towards the original initial
state. (Naomi Nishimura, n.d)

Diagram 10: Adding a new initial state

Level 2 Asia Pacific University of Technology and Innovation Page 14 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Now, we have an initial state without any input to it that connects to the original
initial state with an epsilon in between.

Rule II

The second rule is to deny the final state from giving any inputs to any state. And
to avoid that, we should add another final state to the diagram just like what we did in the
initial state. (Naomi Nishimura, n.d)

Diagram 11: Final State with outgoing edges

As we can see, the final state in the NFA diagram is giving an input to itself,
which is a loop that loops itself, hence the second rule needs to be implemented so that
the final state has no outgoing edges.

Level 2 Asia Pacific University of Technology and Innovation Page 15 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Diagram 12: Creating a new Final State

Rule III

After adding a new final state, the third rule of the Elimination Method is to
eliminate the final states if there is more than one. In the NFA diagram, we can see that
there is only one final state which is the one that we have added. In this case, the NFA
diagram has already complied with the rule and hence the step to eliminate any other
final state is not required.

Rule IV

The fourth rule is to eliminate all the other states in the diagram except for the
initial and final state.

Level 2 Asia Pacific University of Technology and Innovation Page 16 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Diagram 13: Modifying the NFA diagram and naming the states

After rewriting the NFA diagram in another order, based on diagram 13, we can
clearly see that there is a loop that includes three states which starts from state 3 and
consists of states 6 and 7 hence we can eliminate the 2 states, 6 and 7 by reducing it to
just only a loop. To eliminate the states, we need to write the inputs into regular
expression, which in this case is, 1, 0 can be written as 1 + 0 in regular expression. This is
because the symbol “,” in NFA means that the 2 inputs, 0 and 1 are travelling in a parallel
line together from a state to another, in that case, we can write this in regular expressions
operation known as Union , either U or +.

Level 2 Asia Pacific University of Technology and Innovation Page 17 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Diagram 14: The loop that involves state 3, 6 and 7

Diagram 15: Inputs changed to regular expressions

After changing the inputs to regular expressions, we can now eliminate the states
by merging them into regular expressions known as the operation Concatenation.

When a series of input is flowing in the same flow of direction, for example: State
A has input 1 flowing to State B and State B has input 0 flowing to State C

Level 2 Asia Pacific University of Technology and Innovation Page 18 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Diagram 16: Example I


The above example can also be written in regular expression form between state
A and State C as 10.

Diagram 17: Example II


Applying the same concept, the loop in diagram 10 can also be written as
(0+1)(0+1)(0+1) in regular expression form.

Diagram 18: After eliminating state 6 and state 7

Diagram 19: NFA diagram after eliminating state 6 and 7


Other than that, we will have to eliminate states 2, 3 and 4 which consist of a loop.
When a state has an input that acts as a loop, we know that it can loop itself through that
input for 0 or more times, hence to represent that it is a loop in regular expressions which
will repeat that certain input for n amount of times, we can represent it using Kleene Star,
which is a * symbol. For example: if state A loops itself with an input 1 then passes an

Level 2 Asia Pacific University of Technology and Innovation Page 19 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

input 0 to state B, the regular expression can be written as 1*0, meaning that it loops
itself a certain amount of times then passes to the next input which is 0.

Diagram 20: Example III

Can be written as:

Diagram 21: Example IV

As seen, the input 1 that is a loop is written as 1* and concatenated to the input
next to it. By applying the same principle, we can do the same for states 2, 3 and 4 of the
NFA diagram.

Diagram 22: NFA expressed in regular expression

Finally, we have successfully changed the NFA to regular expression where the
regular expression being: (0+1)*0((0+1)(0+1)(0+1))*0(0+1)*

Level 2 Asia Pacific University of Technology and Innovation Page 20 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

Conclusion

To sum it all up, we have created a NFA diagram based on the 5 tuples, Q, ∑, δ,
q0 and F and also was able to successfully convert a NFA into regular expressions form
by using the elimination method.

In creating the NFA diagram, based on the 5 tuples identified, we were able to
create a transition table from scratch and proceeded to create a NFA diagram based on
the created transition table. After testing it with a series of inputs, we are able to conclude
that the NFA diagram was successful in predicting the moves that the player will make
when specific inputs were to be entered as long as it applies the rules already stated.

In converting the NFA to regular expressions, we were able to use the elimination
to complete the conversion. In a nutshell, the elimination method has 4 rules that had to
be applied to convert the NFA to regular expressions which has the operations union,
concatenation and Kleene closure. Other than that, we also learnt that regular expressions
was a way to

Level 2 Asia Pacific University of Technology and Innovation Page 21 of 22


CT111-3-2-COMT Computing Theory Individual Assignment

References

Emelda M. (2011) Difference Between NFA and DFA.


[Online] Available from:
http://www.differencebetween.net/technology/software-technology/difference-between-
nfa-and-dfa/
[Accessed: 25/3/2018]

Amal Dar Aziz (2004) Basics of Automata Theory


[Online] Available from:
https://cs.stanford.edu/people/eroberts/courses/soco/projects/2004-05/automata-
theory/basics.html#top
[Accessed: 27/3/2018]

Malte Helmert (2016) Theory of Computer Science – Regular Languages: Regular


Expressions, Pumping Lemma
[Online] Available from:
http://ai.cs.unibas.ch/_files/teaching/fs16/theo/slides/theory-c03.pdf
[Accessed: 2/4/2018]

Rochester.edu (n.d) Regular Expressions


[Online] Available from:
https://www.cs.rochester.edu/~nelson/courses/csc_173/fa/re.html
[Accessed: 3/4/2018]

Naomi Nishimura (n.d) Kleene’s Theorem


[Online] Available from:
https://cs.uwaterloo.ca/~nishi/360W16/Resources/kleenesupplement.pdf
[Accessed: 4/4/2018]

Level 2 Asia Pacific University of Technology and Innovation Page 22 of 22

Potrebbero piacerti anche