sm2220 – class 06 finite automata. sm2220 – class 06 topic in theoretical computing. a subset of...

46
SM2220 – Class 06 Finite Automata

Upload: ezra-daniels

Post on 18-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Finite Automata

Page 2: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Topic in theoretical computing.

A subset of computation machines.

Closely related to formal language.

Page 3: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Finite Automata

Finite State Automata

Finite State Machine (FSM)

Page 4: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Before discussing Finite Automata, we have to

take care of the concepts,

• Symbol and coding in textual environment;

• Computation.

Page 5: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

We are taught in SM1001 that everything inside

the computer is represented by string of 0 and 1.

English text comprises of alphabets (a-z, A-Z),

digits (0-9) and punctuation (, . ; , etc.)

They are represented by a coding scheme,

ASCII.

Page 6: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

If we count the number of symbols for a piece of

typical English text, it has around 80 such

characters.

One unit of binary digit can represent 2 symbols,

0 and 1.

It needs at least 7 digits (7 bits) to represent

common English text.

Page 7: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Page 8: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

A basic unit of storage is 8 bits – byte.

It takes 1 byte to represent an English text

symbol.

That is all for the symbol for the time being. If we

want to manipulate the text in computer, we

have to think about the computation process.

Page 9: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

From a functional point of view, computation can

be considered as a black box which takes in

symbols and produces symbols.

ComputationInput symbols Output symbols

Page 10: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Since all symbols are patterns of 0 and 1, the

simplest computation takes one symbol and

produce another one.

Computation1 1

0 0

Page 11: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Or another simple one.

Computation1 0

0 1

Page 12: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

A little more complicated with 2 symbols as

input.

Computation

0 00 11 01 1

0001

Page 13: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Such computation can be described

mathematically by Boolean Algebra.

A and B

0 and 0 = 00 and 1 = 01 and 0 = 01 and 1 = 1

A or B

0 or 0 = 00 or 1 = 11 or 0 = 11 or 1 = 1

Page 14: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

The computation can become very complicated

such as

A and (B or (C and B) and (A or C)) and (D or B)

Page 15: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

No matter how complicated and long the

expression, it always gives the same result with

the same combination of A, B, C and D.

A and (B or (C and B) and (A or C)) and (D or B)

Page 16: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Once you have the combination of A, B, C and

D, the result is fixed, instantly available and

always be the same.

A and (B or (C and B) and (A or C)) and (D or B)

Combinational Logic.

Page 17: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Imagine this strange Boolean algebra formula,

AND NOTA

Page 18: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

The feedback loop introduces the element of

time and most importantly, memory.

AND NOTA

Page 19: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

The current formula is not very stable. It can

perform better with in introduction of another

input.

AND NOTA

Page 20: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

AND NOTA

AND NOTB

Page 21: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

The memory gives you the state (status) of the

computing device.

The previous one can only remember two states

(1 bit information).

Page 22: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Finite Automata is an abstract computing device

capable of remembering finite number of states.

Page 23: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

A less abstract description

Nonlinear description of how an object can

change its state over time, possibly in response

to events in its environment.

The Ultimate Guide to FSMs in Games – Dan Fu and Ryan Houlette

Page 24: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

It starts at an initial state. By accepting different

inputs, it changes to different states. Eventually,

it stops at an ending state.

Page 25: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

S0

S1

S2

a

b

b

Simple example

Page 26: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

The diagram is known as a Graph in

Mathematics. Each state is a node and each

input symbol is a directed link.

A graph is different from a tree that it can

contain a loop.

Page 27: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

State transition table

Current state Input Next state

S0 a S1

S0 b S2

S1 b S2

Page 28: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

If you consider the input symbol sequence, you

can notice the valid ones are,

• ab

• b

All the other input symbol sequences are invalid.

Page 29: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Essentially this simple finite automata defines a

simple language which has only 2 alphabets: a,

b. And the valid syntax for the language are the

2 sentences: ab and b.

Page 30: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Such language is known as,

• Regular language

• Regular grammar

• Regular expression

Page 31: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

A regular language can also be described by

other means.

If the language has only two alphabets: a, b,

they can be written down like,

ab – concatenation of symbol a and b.

a+b – either a or b.

a* - zero or more occurrences of a.

Page 32: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Exercise time

aa*

(a+b)*

(aa+ab+ba+bb)*

((a+b)(a+b))*

Page 33: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

If a regular language and a finite automata are

equivalent, can we draw a finite automata which

is the same as

aa*

Page 34: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

S0 S1

aa

Page 35: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

State transition table

Current state Input Next state

S0 a S1

S1 a S1

Page 36: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

S0

S1 S3

S2

a

a

b

b a

b

a, b

More complicated example

Page 37: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Exercise time

Try to draw the transition table for the finite

automata.

Try to identify the regular language pattern.

Page 38: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

More exercise

Try to use regular language or finite automata to

describe a pattern which starts with a number of

a’s and ends with the same number of b’s

afterwards. E.g.

ab, aabb, aaaaabbbbb, etc.

Page 39: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Applications of Finite Automata

Page 40: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

If you start replacing the a, b symbols with

sentences, plots, etc., you can end up with a

piece of text like the Oulipo experiments.

Page 41: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Gather Treasure

Flee

Fight

Monster in sight

Monster dead

Simple application in game

CorneredMonster away

Page 42: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

If you start replacing the states: S0, S1, etc. with

scenes, movie clips or frames, you will end up

with an interactive movie. The symbols: a, b will

become your participants’ input, such as sensor

values or keyboard inputs.

Remember the previous workshop.

Page 43: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Let’s get back to this transition table.

Current state Input Next state

S0 a S1

S0 b S2

S1 b S2

Page 44: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

From the state transition table, the next state is

a function of both the current state and input

symbol.

Current state Input Next state

S0 a S1

S0 b S2

S1 b S2

Page 45: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

(S0, a) -> S1

(S0, b) -> S2

(S1, b) -> S2

It is a mapping from a 2D array to the set of

states, which has been shown in your previous

workshop.

Page 46: SM2220 – Class 06 Finite Automata. SM2220 – Class 06 Topic in theoretical computing. A subset of computation machines. Closely related to formal language

SM2220 – Class 06

Q & A