Regular Expressions
Automaton
• An automaton is a finite representation of a formal language
that may be an infinite set.
Graphs Representing State Machines
• Ex
• Λ – x represents the set of all letters except x
• A word “abstemious” can reach to the accepting state
Graphs Representing State Machines
• we can design a program by first designing the graph, and
then mechanically translating the graph into a program
• At previous Ex …
• Boolean testWord(char *p){
• If (findChar(&p, ‘a’))
• If (findChar(&p, ‘e’))
• If (findChar(&p, ‘i’))
• If (findChar(&p, ‘o’))
• If (findChar(&p, ‘u’)) return TRUE;
• return FALSE }
Graphs Representing State Machines
• we can design a program by first designing the graph, and
then mechanically translating the graph into a program
• At previous Ex …
• Boolean testWord(char *p){
• If (findChar(&p, ‘a’))
• If (findChar(&p, ‘e’))
• If (findChar(&p, ‘i’))
• If (findChar(&p, ‘o’))
• If (findChar(&p, ‘u’)) return TRUE;
• return FALSE }
This function finds desired
character, and points the next
character, and returns TRUE.
Otherwise, returns FALSE.
Graphs Representing State Machines
• we can design a program by first designing the graph, and
then mechanically translating the graph into a program
• At previous Ex …
• Boolean testWord(char *p){
• If (findChar(&p, ‘a’))
• If (findChar(&p, ‘e’))
• If (findChar(&p, ‘i’))
• If (findChar(&p, ‘o’))
• If (findChar(&p, ‘u’)) return TRUE;
• return FALSE }
Ex) think a input “abstemious”
It leads to TRUE!
Deterministic and Nondeterministic
Automata
• Programs cannot go to two places(states) at once
Deterministic and Nondeterministic
Automata
• Deterministic Automataon vs Nondeterminsitc Automaton
vs
Deterministic and Nondeterministic
Automata
• Deterministic Automataon vs Nondeterminsitc Automaton
vs
Given an input ‘m’,
It can go to state 0 and
1 at the same time
Non programmableprogrammable
From Nondeterminism to Determinism
• We say N and D are equivalent if they accept the same set of
input string
• By constructing an equivalent deterministic automaton, we
can convert nondeterministic automaton into deterministic
automaton.
• How? Induction, or Algorithmic way
From Nondeterminism to Determinism
From Nondeterminism to Determinism
From Nondeterminism to Determinism
The Subset Construction
S is the Subset Construction,
where D is determinism
N is nondeterminism
The Subset Construction
Yet there is no guarantee that the
deterministic automaton will be small
because 𝑘-sate nondeterministic
automaton could wind up being
converted to a deterministic
automaton with at most 2 𝑘
states.
Minimization of Automata
• One of the issues concerning automata, especially when they
are used to design circuits, is how few states are needed to
perform a given task.
• If states s and t are equivalent, we can merge s and t into a
single state
Regular Expressions
• Regular Expressions are algebraic way to define patterns
• Operands
• A character 𝒙 be denoted by that character in boldface
• The symbol ε denotes the 𝑒𝑚𝑝𝑡𝑦 𝑠𝑡𝑟𝑖𝑛𝑔
• The symbol ∅ denotes the 𝑒𝑚𝑝𝑡𝑦 𝑠𝑒𝑡 𝑜𝑓 𝑠𝑡𝑟𝑖𝑛𝑔
• A variable whose value can be any pattern defined by a regular
expression
Regular Expressions
• For regular expressions, the value of each expression is a
pattern consisting of a set of strings often called a language
• The language denoted by a regular expression 𝐸 will be referred to
as 𝐿(𝐸)
• The languages of the atomic operands
• If 𝒙 is any character, the regular expression 𝒙 stands for the
language 𝐿 𝒙 = {𝑥}
• 𝐿 ε = ε
• 𝐿 ∅ = ∅
• A variable whose value can be any pattern defined by a regular
expression
Operators of Regular Expressions
• Suppose that 𝑅, 𝑆 are two regular expressions
• Union
• 𝑅 | 𝑆 denotes the union of the languages that 𝑅 and 𝑆 denote
• That is, 𝐿 𝑅 𝑆) = 𝐿 𝑅 ∪ L S
• Concatenation
• 𝐿 𝑅𝑆 , the language denoted by 𝑅𝑆, is formed from the languages
𝐿(𝑅) and L(𝑆)
• Closure
• 𝑅 ∗ is the closure of regular expression 𝑅.
• 𝑅 ∗ = ε | R | RR | RRR | ...
From Regular Expressions to Automata
• Designing deterministic automata is often a good way to
design a program
• However, we also saw that deterministic automata could be
hard to design
• It is good news that there is a way to convert any regular
expression into a nondeterministic automaton, and from there
we can use the subset construction to convert to a
deterministic automaton
From Regular Expressions to Automata
• Convert any regular expression to an automaton with ε-
transitions that defines the same language.
• Convert the automaton with ε-transitions to an automaton
without ε-transitions that accepts the same language.
From Regular Expressions to Automata
• Ex) Given a regular expression 𝑎|𝑏𝑐 ∗
• Construct An expression tree for this regular expression
Internal nodes = operators
Precedence is like this arrow
leaves
From Regular Expressions to Automata
• There are three leaves, and for each, we construct an instance
of the automaton, given the input 𝑎|𝑏𝑐 ∗
From Regular Expressions to Automata
• Apply operators and construct larger automata as we go,
given the input 𝑎|𝑏𝑐 ∗
From Regular Expressions to Automata
• Apply operators and construct larger automata as we go,
given the input 𝑎|𝑏𝑐 ∗
From Regular Expressions to Automata
• Apply operators and construct larger automata as we go,
given the input 𝑎|𝑏𝑐 ∗
From Regular Expressions to Automata
• Using depth-first search, we can construct Table of
reachability
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language. Important
states
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language.
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language. Important
statesBecome the accepting state, if the col has 1
Cannot reach any important state
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language.
Become the accepting state, if the col has 1
Cannot reach any important state
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language. Important
statesBecome the accepting state, if the col has 1
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language.
Become the accepting state, if the col has 1
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language. Important
statesBecome the accepting state, if the col has 1
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language.
Become the accepting state, if the col has 1
Accepting states
From Regular Expressions to Automata
• Find automaton without ε-transitions that accepts the same
language.
Become the accepting state, if the col has 1
Accepting states
From Regular Expressions to Automata
• there is a simpler deterministic automaton that accepts the
same language By recognizing that
states 5 and 8 are
equivalent, they can be
merged.
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states until two states remains
A regular expression for the set of
strings that get us from state s to
state t is
𝑆 ∗ 𝑈 𝑇 𝑉𝑆 ∗ 𝑈 ∗
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• 0101101
• 0000111
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• Case1
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• Case2
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• All cases have elimination of b
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• All cases have elimination of b
• For the a–a pair
• 𝑎 → 𝑎 𝑖𝑠 𝑟𝑒𝑝𝑙𝑎𝑐𝑒𝑑 𝑏𝑦 0|1∅0
• ∄ the a-c pair
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
• Ex) bounce filter
• After the elimination of b,
• Two cases exist
• Case 1: delete d
• Case 2: delete c
• Union(Case1, Case2)
From Automata to Regular Expressions
• The key step in conversion from an automaton to a regular
expression is the elimination of states
Union
0 10 ∗ 11 1 01 00 0 10 ∗ 11 ∗
0 10 ∗ 111 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗
From Automata to Regular Expressions
• Simplify this expression
•
•
0 10 ∗ 11 1 01 00 0 10 ∗ 11 ∗ | 0 10 ∗ 111 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗
0 10 ∗ 11| ( 1 01 00 0 10 ∗ 11 ∗ | 1 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗ )

Regular expression automata

  • 1.
  • 2.
    Automaton • An automatonis a finite representation of a formal language that may be an infinite set.
  • 3.
    Graphs Representing StateMachines • Ex • Λ – x represents the set of all letters except x • A word “abstemious” can reach to the accepting state
  • 4.
    Graphs Representing StateMachines • we can design a program by first designing the graph, and then mechanically translating the graph into a program • At previous Ex … • Boolean testWord(char *p){ • If (findChar(&p, ‘a’)) • If (findChar(&p, ‘e’)) • If (findChar(&p, ‘i’)) • If (findChar(&p, ‘o’)) • If (findChar(&p, ‘u’)) return TRUE; • return FALSE }
  • 5.
    Graphs Representing StateMachines • we can design a program by first designing the graph, and then mechanically translating the graph into a program • At previous Ex … • Boolean testWord(char *p){ • If (findChar(&p, ‘a’)) • If (findChar(&p, ‘e’)) • If (findChar(&p, ‘i’)) • If (findChar(&p, ‘o’)) • If (findChar(&p, ‘u’)) return TRUE; • return FALSE } This function finds desired character, and points the next character, and returns TRUE. Otherwise, returns FALSE.
  • 6.
    Graphs Representing StateMachines • we can design a program by first designing the graph, and then mechanically translating the graph into a program • At previous Ex … • Boolean testWord(char *p){ • If (findChar(&p, ‘a’)) • If (findChar(&p, ‘e’)) • If (findChar(&p, ‘i’)) • If (findChar(&p, ‘o’)) • If (findChar(&p, ‘u’)) return TRUE; • return FALSE } Ex) think a input “abstemious” It leads to TRUE!
  • 7.
    Deterministic and Nondeterministic Automata •Programs cannot go to two places(states) at once
  • 8.
    Deterministic and Nondeterministic Automata •Deterministic Automataon vs Nondeterminsitc Automaton vs
  • 9.
    Deterministic and Nondeterministic Automata •Deterministic Automataon vs Nondeterminsitc Automaton vs Given an input ‘m’, It can go to state 0 and 1 at the same time Non programmableprogrammable
  • 10.
    From Nondeterminism toDeterminism • We say N and D are equivalent if they accept the same set of input string • By constructing an equivalent deterministic automaton, we can convert nondeterministic automaton into deterministic automaton. • How? Induction, or Algorithmic way
  • 11.
  • 12.
  • 13.
  • 14.
    The Subset Construction Sis the Subset Construction, where D is determinism N is nondeterminism
  • 15.
    The Subset Construction Yetthere is no guarantee that the deterministic automaton will be small because 𝑘-sate nondeterministic automaton could wind up being converted to a deterministic automaton with at most 2 𝑘 states.
  • 16.
    Minimization of Automata •One of the issues concerning automata, especially when they are used to design circuits, is how few states are needed to perform a given task. • If states s and t are equivalent, we can merge s and t into a single state
  • 17.
    Regular Expressions • RegularExpressions are algebraic way to define patterns • Operands • A character 𝒙 be denoted by that character in boldface • The symbol ε denotes the 𝑒𝑚𝑝𝑡𝑦 𝑠𝑡𝑟𝑖𝑛𝑔 • The symbol ∅ denotes the 𝑒𝑚𝑝𝑡𝑦 𝑠𝑒𝑡 𝑜𝑓 𝑠𝑡𝑟𝑖𝑛𝑔 • A variable whose value can be any pattern defined by a regular expression
  • 18.
    Regular Expressions • Forregular expressions, the value of each expression is a pattern consisting of a set of strings often called a language • The language denoted by a regular expression 𝐸 will be referred to as 𝐿(𝐸) • The languages of the atomic operands • If 𝒙 is any character, the regular expression 𝒙 stands for the language 𝐿 𝒙 = {𝑥} • 𝐿 ε = ε • 𝐿 ∅ = ∅ • A variable whose value can be any pattern defined by a regular expression
  • 19.
    Operators of RegularExpressions • Suppose that 𝑅, 𝑆 are two regular expressions • Union • 𝑅 | 𝑆 denotes the union of the languages that 𝑅 and 𝑆 denote • That is, 𝐿 𝑅 𝑆) = 𝐿 𝑅 ∪ L S • Concatenation • 𝐿 𝑅𝑆 , the language denoted by 𝑅𝑆, is formed from the languages 𝐿(𝑅) and L(𝑆) • Closure • 𝑅 ∗ is the closure of regular expression 𝑅. • 𝑅 ∗ = ε | R | RR | RRR | ...
  • 20.
    From Regular Expressionsto Automata • Designing deterministic automata is often a good way to design a program • However, we also saw that deterministic automata could be hard to design • It is good news that there is a way to convert any regular expression into a nondeterministic automaton, and from there we can use the subset construction to convert to a deterministic automaton
  • 21.
    From Regular Expressionsto Automata • Convert any regular expression to an automaton with ε- transitions that defines the same language. • Convert the automaton with ε-transitions to an automaton without ε-transitions that accepts the same language.
  • 22.
    From Regular Expressionsto Automata • Ex) Given a regular expression 𝑎|𝑏𝑐 ∗ • Construct An expression tree for this regular expression Internal nodes = operators Precedence is like this arrow leaves
  • 23.
    From Regular Expressionsto Automata • There are three leaves, and for each, we construct an instance of the automaton, given the input 𝑎|𝑏𝑐 ∗
  • 24.
    From Regular Expressionsto Automata • Apply operators and construct larger automata as we go, given the input 𝑎|𝑏𝑐 ∗
  • 25.
    From Regular Expressionsto Automata • Apply operators and construct larger automata as we go, given the input 𝑎|𝑏𝑐 ∗
  • 26.
    From Regular Expressionsto Automata • Apply operators and construct larger automata as we go, given the input 𝑎|𝑏𝑐 ∗
  • 27.
    From Regular Expressionsto Automata • Using depth-first search, we can construct Table of reachability
  • 28.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Important states
  • 29.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language.
  • 30.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Important statesBecome the accepting state, if the col has 1 Cannot reach any important state
  • 31.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Become the accepting state, if the col has 1 Cannot reach any important state
  • 32.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Important statesBecome the accepting state, if the col has 1
  • 33.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Become the accepting state, if the col has 1
  • 34.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Important statesBecome the accepting state, if the col has 1
  • 35.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Become the accepting state, if the col has 1 Accepting states
  • 36.
    From Regular Expressionsto Automata • Find automaton without ε-transitions that accepts the same language. Become the accepting state, if the col has 1 Accepting states
  • 37.
    From Regular Expressionsto Automata • there is a simpler deterministic automaton that accepts the same language By recognizing that states 5 and 8 are equivalent, they can be merged.
  • 38.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states until two states remains A regular expression for the set of strings that get us from state s to state t is 𝑆 ∗ 𝑈 𝑇 𝑉𝑆 ∗ 𝑈 ∗
  • 39.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • 0101101 • 0000111
  • 40.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • Case1
  • 41.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • Case2
  • 42.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • All cases have elimination of b
  • 43.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • All cases have elimination of b • For the a–a pair • 𝑎 → 𝑎 𝑖𝑠 𝑟𝑒𝑝𝑙𝑎𝑐𝑒𝑑 𝑏𝑦 0|1∅0 • ∄ the a-c pair
  • 44.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states • Ex) bounce filter • After the elimination of b, • Two cases exist • Case 1: delete d • Case 2: delete c • Union(Case1, Case2)
  • 45.
    From Automata toRegular Expressions • The key step in conversion from an automaton to a regular expression is the elimination of states Union 0 10 ∗ 11 1 01 00 0 10 ∗ 11 ∗ 0 10 ∗ 111 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗
  • 46.
    From Automata toRegular Expressions • Simplify this expression • • 0 10 ∗ 11 1 01 00 0 10 ∗ 11 ∗ | 0 10 ∗ 111 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗ 0 10 ∗ 11| ( 1 01 00 0 10 ∗ 11 ∗ | 1 ∗ 0 11 ∗ 0 0 0|10 ∗ 111 ∗ 0 ∗ )