Top Banner
Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where a “b” preceding an “a” (a+b) * b(a+b) * a(a+b) * = (a+b) * ba(a+b) * b a b a b a Why? b a b a b a b a b a b a b a b a b a Remove previous start/final states
30

Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where a “b” preceding an “a” (a+b)

Dec 26, 2015

Download

Documents

Paul Manning
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Regular Expressions: ReviewA FA for a regular expressions can be built by composition:

Ex: all strings over S={a,b} where a “b” preceding an “a”(a+b)*b(a+b)*a(a+b)*

= (a+b)*ba(a+b)*

b ab

a

b

a

Why?

b ab

a

b

a

b ab

a

b

a

b ab

a

b

a

Remove previous start/final states

Page 2: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

FA Minimization: ReviewIdea: “Equivalent” states can be merged:

b aa,b a,b3 states!

16 states

! b ab

a

b

a

b ab

a

b

a

b aa,b a,b

b aa,b a,b

merge

merge

Page 3: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

FA Minimization: ReviewTheorem [Hopcroft 1971]: the number N of states in a FA

can be minimized within time O(N log N).

Based on earlier work by [Huffman 1954] and [Moore 1956].

Conjecture: Minimizing the number of states in a nondeterministic FA can not be done in polynomial time.

Theorem: Minimizing the number of states in a pushdown automaton (or TM) is undecidable.

Project idea: implement a finite automaton minimization tool.

Try to design it to run reasonably efficiently.

Consider also including:• A regular-expression-to-FA transformer,• A non-deterministic-to-deterministic FA converter.

Page 4: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

M

FAs and Regular Expressions: ReviewTheorem: Any FA accepts a language denoted by some RE.

Proof: Use “generalized finite automata” where each transition can be a regular expression (not just a symbol), and:

Only one super start state and one (separate) super final state.

Every state has transitions to all other states (including itself),except the super start state, with no incoming transitions, and the super final state, which has no outgoing transitions.

Original FA M

M

ØØ

ØØ

Ø

ØØ

ØØ

Generalized FA (GFA) M’

M’

Page 5: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

FAs and Regular Expressions: ReviewNow reduce the size of the GFA by one state at each step.A transformation step is as follows:

qi qj

q’R

S

T

P qi qjP

RS*T

qi qjP + RS*T

Such a transformation step is always possible, until the GFAhas only two states, the super-start and super-final states:

Label of last remaining transition isthe regular expression corresponding to the language of the original FA!

M’P

Corollary: FAs and REs denote the same class of languages.

Page 6: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Regular Expressions Identities: Review• R+S = S+R

• R(ST) = (RS)T

• R(S+T) = RS+RT

• (R+S)T = RT+ST

• Ø* = * = • R+Ø= Ø+R = R

• R= R = R

• (R*)* = R*

• ( + R)* = R*

• (R*S*)* = (R+S)*

R+ ≠ R RØ ≠ R

Page 7: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Extra credit: use this t

ool!

(to implement so

me nontrivial

TMs, PDAs, g

rammars, etc.)

Page 8: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 9: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 10: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 11: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 12: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Why Study Non-determinism?1. Helps understand the ubiquitous concept ofparallelism / concurrency;

2. Illuminates the structure of problems;

3. Can help save time & effort by solving intractable problems more efficiently;

4. Enables vast, deep, and general studies of“completeness” theories;

5. Helps explain why verifying proofs & solutionsseems to be easier than constructing them;

Page 13: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Why Study Non-determinism?6. Gave rise to new and novel mathematical

approaches, proofs, and analyses;

7. Robustly decouples / abstracts complexity from underlying computational models;

8. Gives disciplined techniques for identifying“hardest” problems / languages;

9. Forged new unifications between computer science, math & logic;

10. Non-determinism is interesting fun, and cool!

Page 14: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 15: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 16: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: compute 1111111112 in your head.

1111111112 = 12345678987654321

111111111

111111111

111111111111111111

111111111111111111

111111111111111111

111111111111111111

11111111112345678987654321

Page 17: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: What is the approximate value of:

= e to 18,457,734,525,360,901,453,873,570 digitsof precision!

1 + = 85

)( 326*7

9-(4 )

1 + = ?85

1 )( 32

85

32

1 + = 85

1 )( 32

6*7

94

NN

(1+9^(-(4^(7*6))))^(3^(2^85)) ≈ ?

Page 18: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: Does the Pythagorean theorem generalize toarbitrary figures on the sides of a right triangle?

Page 19: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: Does every closed simple curve containthe vertices of an equilateral triangle?

• What approaches fail?• What techniques work and why?• Lessons and generalizations

Page 20: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: Can an 8x8 board with two opposite corners missing be tiles with 31 dominoes?

= 31 x ?

• What approaches fail?• What techniques work and why?• Lessons and generalizations

Page 21: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: Explain the apparent discrepancy between the areas of the two arrangements.

• What approaches fail?• What techniques work and why?• Lessons and generalizations

13

5

13

5

5

Page 22: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Problem: Explain the apparent discrepancy between the areas of the three arrangements.

• What approaches fail?• What techniques work and why?• Lessons and generalizations

Page 23: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)
Page 24: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Larger alphabet:

old: Σ={0,1} new: Σ’ ={a,b,c,d}

Idea: Encode larger alphabet using smaller one.

Encoding example: a=00, b=01, c=10, d=11

Turing Machine “Enhancements”

b a d c a old: δ b

0 1new: δ'0 1 0 0 1 1 1 0 0 0

Page 25: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Double-sided infinite tape:

Turing Machine “Enhancements”

1 0 1 0 0 1

Idea: Fold into a normal single-sided infinite tape

0 0 11 0 1 1

1

0 0 1

101

1

old: δ L/R L/R L/Rnew: δ'L/R R/L R/L

Page 26: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

b

Multiple heads:

Turing Machine “Enhancements”

Idea: Mark heads locations on tape and simulate

Modified δ' processes each “virtual” head independently:• Each move of δ is simulated by a long scan & update• δ' updates & marks all “virtual” head positions

b b b a aab a

b b b a aab a bba BBAAbBB Ab

Page 27: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Multiple tapes:

Turing Machine “Enhancements”

Idea: Interlace multiple tapes into a single tape

1 0 1 10

0 1 0

1

1

1 1 1 001

0

1 0 1 10

0 1 0

1

1

1 1 1 001

0

Modified δ' processes each “virtual” tape independently:• Each move of δ is simulated by a long scan & update• δ' updates R/W head positions on all “virtual tapes”

Page 28: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Two-dimensional tape:

Turing Machine “Enhancements”

Idea: Flatten 2-D tape into a 1-D tape

1 0 1 101

1 0 1 0010 1 11 0

Modified 1-D δ' simulates the original 2-D δ:• Left/right δ moves: δ' moves horizontally

• Up/down δ moves: δ' jumps between tape sections

$ $ $

1 0 1 101

1 0 1 0010 1 11 0

This is how compilers

implement 2D arrays!

Page 29: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Non-determinism:

Turing Machine “Enhancements”

Idea: Parallel-simulate non-deterministic threads

Modified deterministic δ' simulates the original ND δ:• Each ND move by δ spawns another independent “thread”

• All current threads are simulated “in parallel”

1 1 1 101

$ $ $

1 1 00 1 11 0 1 101 1 0 1 101 1

1 1 00 1 11

1 1 1 101

Page 30: Regular Expressions: Review A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b)

Turing Machine “Enhancements”

Theorem: Combinations of “enhancements” do not increase the power of Turing machines.

Combinations:

Idea: “Enhancements” are independent (and commutative WRT preserving the language recognized).

9. 1 4 513

W o l !drH e ol l

Π α ω νλ τ

3ND