CS 490: Automata and Language Theory

Post on 08-Feb-2016

160 views 0 download

description

CS 490: Automata and Language Theory. Daniel Firpo Spring 2003. Regular Languages. Finite Automata (also known as the Finite State Machine) Regular Expressions. Regular Languages: Finite Automata. Formally, a finite automaton is a 5-tuple (Q, Σ, δ, q 0 , F), where: - PowerPoint PPT Presentation

Transcript of CS 490: Automata and Language Theory

CS 490: Automata and Language Theory

Daniel FirpoSpring 2003

Regular Languages

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

• Regular Expressions

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.

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

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

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).

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.

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.

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

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*.

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.

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.

Context-Free Languages

• Pushdown automata (PDA)• Context-free grammars (CFG)

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.

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.

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ε

ε,$ε

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

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.

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.

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.

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.

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

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}.

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.

Decidability

• The relationship among the four main classes of languages:

Regular

Context-free

Decidable

Turing-recognizable

Resource:

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