CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

26
CS 490: Automata and Language Theory Daniel Firpo Spring 2003
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    0

Transcript of CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Page 1: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

CS 490: Automata and Language Theory

Daniel Firpo

Spring 2003

Page 2: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages

• Finite Automata (also known as the Finite State Machine)

• Regular Expressions

Page 3: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• Formally, a finite automaton is a 5-tuple (Q, Σ, δ, q0, F), where:

• Q is a finite set of states, • Σ is a finite set called the alphabet (of the

automaton), • δ : Q x Σ --> Q is the transition function,

• q0 Q is the start state, and

• F Q is the set of accept states.

Page 4: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• Finite Automaton are visually represented as state diagrams. For example:

• Finite Automaton, M:

q1 q2 q3

0 1

1 0

0,1

Page 5: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• Finite Automaton, M: • M = (Q, Σ, δ, q0, F):

• Q = {q1, q2, q3},

• Σ = {0,1},

• δ is described as:• 0 1

– q1 q1 q2

– q2 q3 q2

– q3 q2 q2

• q1 is the start state,

• And F = {q2}.

q1 q2 q3

0 1

1 0

0,1

Page 6: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• The type of finite automaton described in the preceding example is a deterministic finite automaton (DFA).

• An easier model to work with is the nondeterministic finite automaton (NFA).

Page 7: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• While in a DFA, every state must have exactly one transition path for each symbol in the automaton’s alphabet, an NFA can have as one, none, or as many transition path as it needs for each symbol in the alphabet.

• An NFA can also have a transition path(s) for the empty input, ε.

• DFA’a and NFA’s are equivalent.

Page 8: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Finite Automata

• Formally, an NFA is a 5-tuple (Q, Σ, δ, q0, F), where:

• Q is a finite set of states, • Σ is a finite set called the alphabet (of the

automaton),

• δ : Q x Σε --> P(Q) is the transition function,

• q0 Q is the start state, and • F Q is the set of accept states.

Page 9: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

q4

Regular Languages: Finite Automata

• The NFA, N: • N = (Q, Σ, δ, q0, F):

• Q = {q1, q2, q3, q4},• Σ = {0,1},• δ is described as:

• 0 1 ε

– q1 { q1} {q1,q2} Ø– q2 { q3} Ø {q3}– q3 Ø q2 Ø– q4 {q4} {q4} Ø

• q1 is the start state,

• And F = {q4}.

q1 q2

0,1

1

q3

0,10, ε

1

Page 10: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages:

• Regular Operations:

• Union: A B = {x|x A or x B},

• Concatenation: AB = {xy|x A and x B},

• Star: A* = {x1x2…xk|k 0 and each xi A}.

• The class of regular languages is closed under the regular operations. That is, if A and B are regular languages, than so is A B, AB, and A*.

Page 11: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Regular Expressions

• Formally, we say that R is a regular expression if R is:

• A, for some a in the alphabet Σ,• ε, the empty string,• Ø, the empty language,• A B,• AB, or• A*,

• Where A and B are regular languages.

Page 12: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Regular Languages: Regular Expressions

• Regular expressions are useful for designing compilers. The syntax of the tokens, the elemental objects in a programming language, such as the variables and constants, can be described by regular expressions. Once this is done, systems generate the lexical analyzer, which processes the input program.

• Regular expressions and finite automata are equivalent.

Page 13: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages

• Pushdown automata (PDA)

• Context-free grammars (CFG)

Page 14: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages: Pushdown Automaton

• A PDA is very similar to a NFA.

• The main difference is that a PDA has a stack, which serves to provide additional memory to the automata.

Page 15: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages: Pushdown Automaton

• Formally, a pushdown automaton is a 6-tuple (Q, Σ, Γ, δ, q0, F), where:

• Q is a finite set of states, • Σ is a finite set called the alphabet (of the automaton), • Γ is the stack alphabet,

• δ : Q x Σε x Γε --> P(Q x Γε) is the transition function,

• q0 Q is the start state, and

• F Q is the set of accept states.

Page 16: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

q4 q3

Context-Free Languages: Pushdown Automata

• The PDA, M: • M = (Q, Σ, Γ, δ, q0, F):

• Q = {q1, q2, q3, q4},

• Σ = {0,1},

• Γ = {0,$},

• δ is described on the next slide,

• q1 is the start state,

• And F = {q1,q4}.

q1 q2

0,ε0

ε,εε

1,0ε

1,0ε

ε,$ε

Page 17: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages: Pushdown Automata

• The PDA, M: • δ is described by:

q4 q3

q1 q2

0,ε0

ε,εε

1,0ε

1,0ε

ε,$ε

Σ 0 - - 1 - - ε - -

Γ 0 $ ε 0 $ ε 0 $ ε

q1 q2,$

q2 q2,0 q3,ε

q3 q3,ε q4,ε

q4

Page 18: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages: Context-Free Grammars

• Formally, a context-free grammar is a 4-tuple, (V, Σ, R, S), where:

• V is a finite set of variables,

• Σ is a finite set of terminals,

• R is a finite set of rules, and

• S V is the start variable.

Page 19: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Context-Free Languages: Context-Free Grammars

• For example, the following grammar:– G = (V, Σ, R, S), where– V = {S,T},– Σ = {0,1},– and R, the rules, are

• S 0S1 | T• T ε

• Generates strings such as 01, 0011, and 000111. The language of this grammar, L(G), is:

• {0n1n | n 0}.• CFG’s and PDA’s are equivalent.

Page 20: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Turing Machines

• Turing Machines (TM) are similar to PDA’s, but with memory that is unlimited and unrestricted.

• The Turing Machine uses an infinite tape.

• The tape head can read and write symbols on the tape. It can also move to the left or right over the tape.

• Turing machines have accept states and reject states, which take immediate effect.

Page 21: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Turing Machines

• Turing machines are formally defined as a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where

• Q is a finite set of states,• Σ is the input alphabet,• Γ is the tape alphabet, containing the special blank

symbol, , where Γ and Σ Γ,• δ : Q x Γ Q x Γ x {L,R} is the transition function,

• q0 Q is the start state,

• qaccept Q is the accept state, and

• qreject Q is the reject state, where qreject != qaccept.

Page 22: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Turing Machines

• An example, the Turing machine, M:

q3q1

xR q5

0LxL

q2

q5

xR

qreject

qaccept xR

RxR

R

R

0,R

0x,R

LR

0x,R0x

Page 23: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Turing Machines

• In this Turing Machine, M = (Q,Σ,Γ,δ,q0,qaccept,qreject), such that

• Q = {q1,q2,q3,q4,q5,qaccept,qreject},• Σ = {0},• Γ = {0,x,},• δ is described by the state diagram on the previous slide,

• The start state is q0,

• The accept state is qaccept, and

• The reject state is qreject.• M decides the language A = {02^n | n 0}.

Page 24: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Decidability

• A language is called Turing recognizable if some Turing machine recognizes it.

• When a Turing machine receives an input, it can either accept, reject, or loop. The machine fails to accept an input that either rejects or loops.

• A Turing machine that never loops (either accepts or rejects) is called a decider.

• A decider that recognizes a language is also said to decide the language.

• A language is decidable if some Turing machine decides it. The TM in the previous example was a decider.

Page 25: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Decidability

• The relationship among the four main classes of languages:

Regular

Context-free

Decidable

Turing-recognizable

Page 26: CS 490: Automata and Language Theory Daniel Firpo Spring 2003.

Resource:

• Sipser, Michael. Introduction to the Theory of Computation. Boston: PWS Publishing Company, 1997.