Module 11
Download
1 / 337

Module 11 - PowerPoint PPT Presentation


  • 56 Views
  • Uploaded on

Module 11. Proving more specific problems are not solvable Input transformation technique Use subroutine theme to show that if one problem is unsolvable, so is a second problem Need to clearly differentiate between use of program as a subroutine and

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Module 11' - odessa-willis


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Module 11
Module 11

  • Proving more specific problems are not solvable

  • Input transformation technique

    • Use subroutine theme to show that if one problem is unsolvable, so is a second problem

    • Need to clearly differentiate between

      • use of program as a subroutine and

      • a program being an input to another program



Primality testing problem
Primality Testing Problem

  • Consider the following two problems

    • Halting Problem

      • Input: Program P, unsigned x

      • Yes/No Question: Does P halt on x?

    • Primality Testing Problem (PTP)

      • Input: Program P, unsigned x

      • Yes/No Question: Does P output correctly whether or not x is a prime number?

  • Which problem seems harder and why?


Question
Question

  • Suppose we construct a program PH which solves the Halting problem H under the following conditions

    • All of PH is known to be correct with the exception of one procedure PL.

    • This procedure PL is being used to solve the Primality Testing Problem.

  • What can we conclude in this scenario?


Formalizing technique
Formalizing Technique

  • Assume PL is a procedure that solves problem L

    • We have no idea how PL solves L

  • Construct a program PH that solves H using PL as a subroutine

    • We use PL as a black box

    • (We could use any unsolvable problem in place of H)

  • Argue PH solves H

  • Conclude that L is unsolvable

    • Otherwise PL would exist and then H would be solvable

    • L will be a problem about program behavior


Focusing on h
Focusing on H

  • In this module, we will typically use H, the Halting Problem, as our known unsolvable problem

  • The technique generalizes to using any unsolvable problem L’ in place of H.

    • You would need to change the proofs to work with L’ instead of H, but in general it can be done

  • The technique also can be applied to solvable problems to derive alternative consequences

  • We focus on H to simplify the explanation


Constructing p h using p l

Constructing PH using PL

Answer-preserving input transformations and Program PT


P h has two subroutines
PH has two subroutines

  • There are many ways to construct PH using program PL that solves L

  • We focus on one method in which PH consists of two subroutines

    • Procedure PL that solves L

    • Procedure PT which computes a function f that I call an answer-preserving (or answer-reversing) input transformation

      • More about this in a moment


Pictoral representation of p h

PT(x)

x

PT

Y/N

Yes/No

PL

PH

Pictoral Representation of PH *


Answer preserving input transformation p t
Answer-preserving input transformation PT

  • Input

    • An input to H

  • Output

    • An input to L such that

      • yes inputs of H map to yes inputs of L

      • no inputs of H map to no inputs of L

  • Note, PT must not loop when given any legal input to H


Why this works
Why this works *

yes input to H

PT

yes input to L

yes

PL

no

no input to H

no input to L

PH

We have assumed that PL solves L


Answer reversing input transformation p t
Answer-reversing input transformation PT

  • Input

    • An input to H

  • Output

    • An input to L such that

      • yes inputs of H map to no inputs of L

      • no inputs of H map to yes inputs of L

  • Note, PT must not loop when given any legal input to H


Why this works1
Why this works

yes input to H

PT

no input to L

no

yes

PL

no

no input to H

yes input to L

yes

PH

We have assumed that PL solves L


Yes yes and no no

x

PT(x)

Yes/No

PL

PT

PH

Yes->Yes and No->No

No inputs

for H

Yes inputs

for H

Domain of H

Yes inputs

for L

No inputs

for L

Domain of L


Notation and terminology

Yes inputs

No inputs

Domain of H

Yes inputs

No inputs

Domain of L

Notation and Terminology

  • If there is such an answer-preserving (or answer-reversing) input transformation f (and the corresponding program PT), we say that H transforms to (many-one reduces to) L

  • Notation

    H <= L



Generalization
Generalization

  • As noted earlier, while we focus on transforming H to other problems, the concept of transformation generalizes beyond H and beyond unsolvable program behavior problems

  • We work with some solvable, language recognition problems to illustrate some aspects of the transformation process in the next few slides


Example 1

Yes inputs

No inputs

Domain of L1

Yes inputs

No inputs

Domain of L2

Example 1

  • L1 is the set of even length strings over {0,1}

    • What are the set of legal input instances and no inputs for the L1 LRP?

  • L2 is the set of odd length strings over {0,1}

    • Same question as above

  • Tasks

    • Give an answer-preserving input transformation f that shows that L1 LRP <= L2 LRP

    • Give a corresponding program PT that computes f


Program p t
Program PT

string main(string x)

{

return(x concatenate “0”);

}


Example 2

Yes inputs

No inputs

Domain of L1

Yes inputs

No inputs

Domain of L2

Example 2

  • L1 is the set of all strings over {0,1}

    • What is the set of all inputs, yes inputs, no inputs for the L1 LRP?

  • L2 is {0}

    • Same question as above

  • Tasks

    • Give an answer-preserving input transformation f which shows that the L1 LRP <=L2 LRP

    • Give a corresponding program PT which computes f


Program p t1
Program PT

string main(string x)

{

return( “0”);

}


Example 3

Yes inputs

No inputs

Domain of L1

Yes inputs

No inputs

Domain of L2

Example 3

  • L1

    • Input: Java program P that takes as input an unsigned int

    • Yes/No Question: Does P halt on all legal inputs

  • L2

    • Input: C++ program P that takes as input an unsigned int

    • Yes/No Question: Does P halt on all legal inputs

  • Tasks

    • Describe what an answer-preserving input transformation f that shows that L1 <=L2 would be/do?



Problem definitions

Halting Problem H

Input

Program QH that has one input of type unsigned int

non-negative integer y that is input to program QH

Yes/No Question

Does QH halt on y?

Target Problem L

Input

Program QL that has one input of type string

Yes/No question

Does Y(QL) = the set of even length strings?

Assume program PL solves L

Problem Definitions *


Construction review

PT(x)

x

PT

Y/N

Yes/No

PL

PH

  • We are building a program PH to solve the halting problem H

  • PH will use PL as a subroutine, and we have no idea

  • how PL accomplishes its task

  • PH will use PT as a subroutine, and we must explicitly

  • construct PT using specific properties of H and L

Construction review


P s and q s
P’s and Q’s

  • Programs which are PART of program PH and thus “executed” when PH executes

    • Program PT, an actual program we construct

    • Program PL, an assumed program which solves problem L

  • Programs which are INPUTS/OUTPUTS of programs PH, PL, and PT and which are not “executed” when PH executes

    • Programs QH, QL, and QYL

      • code for QYL is available to PT


Two inputs for l

Target Problem L

Input

Program Q that has one input of type string

Yes/No question

Does Y(Q) = the set of even length strings?

Program PL

Solves L

We don’t know how

Consider the following program Q1

bool main(string z)

{while (1>0) ;}

What does PL output when given Q1 as input?

Consider the following program Q2

bool main(string z)

{ if ((z.length %2) = = 0) return (yes)

else return (no); }

What does PL output when given Q2 as input?

Two inputs for L *


Another input for l

Target Problem L

Input

Program Q that has one input of type string

Yes/No question

Does Y(Q) = the set of even length strings?

Program PL

Solves L

We don’t know how

Consider the following program QL with 2 procedures Q1 and QYL

bool main(string z) {

Q1(5); /* ignore return value */

return(QYL(z));

}

bool Q1(unsigned x) {

if (x > 3) return (no); else loop;

}

bool QYL(string y) {

if ((y.length( ) % 2) = = 0) return (yes); else return(no);

}

What does PL output when given QL as input?

Another input for L *


Input and output of p t

Input of PT

(Also Input of H)

Program QH

one input of type unsigned int

Non-negative integer y

Program QL that is the output of PT

(Also input of L)

bool main(string z) {

QH(y); /* QH and y come left-hand side */

/* ignore return value */

return(QYL(z));

}

bool QH(unsigned x) {

/* comes from left-hand side

}

bool QYL(string y) {

if ((y.length( ) % 2) = = 0) return (yes); else return(no);

}

PT

QH,y

QL

Input and Output of PT *


Example 11

PT

QH,y

QL

Example 1 *

Input to PT

Program QH

bool main(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

Input y

5

Output of PT

Program QL

bool QH(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

bool QYL(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);

}

bool main(string z) {

unsigned y = 5;

QH(y);

return (QYL(z));

}


Example 21

PT

QH,y

QL

Example 2

Input to PT

Program QH

bool main(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

Input y

3

Output of PT

Program QL

bool QH(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

bool QYL(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);

}

bool main(string z) {

unsigned y = 3;

QH(y);

return (QYL(z));

}


P t in more detail

PT in more detail


Declaration of p t

QH,y

QL

Declaration of PT

Yes/No

PL

PT

PH

  • What is the return type of PT?

    • Type program1 (with one input of type string)

  • What are the input parameters of PT?

    • The same as the input parameters to H; in this case,

      • type program2 (with one input of type unsigned int)

      • unsigned int (input type to program2)

        program1 main(program2 QH, unsigned y)


Code for PT

QH,y

QL

Yes/No

PL

PT

PH

program1 main(program2 P, unsigned y) {

/* Will be viewing types program1 and program2 as STRINGS over the program alphabet SP */

program1 QL = replace-main-with-QH(P);

/* Insert line break */

QL += “\n”;

/* Insert QYL */

QL += “bool QYL(string z) {\n \t if ((z.length % 2) == 0) return (yes) else return (no);\n }”;

/* Add main routine of QL */

QL += “bool main(string z) {\n\t”; /* determined by L */

QL += “unsigned y =”

QL += convert-to-string(y);

QL += “;\n\t QH(y)\n\t return(QYL(z));\n}”;

return(QL);

}

program1 replace-main-with-QH(program2 P) /* Details hidden */

string convert-to-string(unsigned y) /* Details hidden */


P t in action

QH,y

QL

Yes/No

PL

PT

PH

PT

code

for QYL

Y/N

QYL

y

start

halt

QH

QL

QH

z

QYL

PT

Y/N

unsigned y

PT in action

Program QH

bool main(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

Input y

5

Program QL

bool QH(unsigned y) {

if (y ==5) return yes;

else if (y ==4) return no;

else while (1>0) {};

}

bool QYL(string z) {

if ((z.length % 2) == 0) return (yes) else return (no);

}

bool main(string z) {

unsigned y = 5;

QH(y);

return (QYL(z));

}


Constructing q l and thus p t

Constructing QL (and thus PT)


Start with no input for h

If QH, y is a no input to the Halting problem

Program QL

bool main(string z) {

QH(y); /* ignore return value */

return(Q?L(z)); /* yes or no? */

}

bool QH(unsigned x) {

/* comes from left-hand side

}

bool Q?L(string y) {

}

Start with no input for H

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L


Answer preserving input transformation

If QH, y is a no input to the Halting problem

  • Now choose a QYL (or QNL) that is a yes (or no) input instance to L

Answer-preserving input transformation

  • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes */

    • }

    • bool QH(unsigned x) {

      • /* comes from left-hand side

    • }

    • bool QYL(string y) {

    • }

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L


Make yes for h map to yes for l

If QH, y is a no input to the Halting problem

  • Now choose a QYL (or QNL) that is a yes (or no) input instance to L

Make yes for H map to yes for L

  • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes */

    • }

    • bool QH(unsigned x) {

      • /* comes from left-hand side

    • }

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L


Possible shortcut
Possible shortcut

  • Program QL

    • bool main(string z) {

    • QH(y); /* ignore return value */

    • return(QYL(z)); /* yes */

    • }

    • bool QH(unsigned x) {

      • /* comes from left-hand side

    • }

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Program QL

    • bool main(string z) {

    • QH(y); /* ignore return value */

    • if ((z.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

    • bool QH(unsigned x) {

      • /* comes from left-hand side

    • }



Problem definitions1

Halting Problem H

Input

Program QH that has one input of type unsigned int

non-negative integer y that is input to program QH

Yes/No Question

Does QH halt on y?

Target Problem L

Input

Program QL that has one input of type string

Yes/No question

Is Y(QL) finite?

Assume program PL solves L

Problem Definitions


Start with no input for h1

If QH, y is a no input to the Halting problem

Program QL

bool main(string z) {

QH(y); /* ignore return value */

return(Q?L(z)); /* yes or no? */

}

bool QH(unsigned x) {

/* comes from left-hand side

}

bool Q?L(string y) {

}

Start with no input for H

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L


Answer reversing input transformation

If QH, y is a no input to the Halting problem

Program QL

bool main(string z) {

QH(y); /* ignore return value */

return(QNL(z));/* no */

}

bool QH(unsigned x) {

/* comes from left-hand side

}

bool QNL(string y) {

}

  • Now choose a QYL (or QNL) that is a yes (or no) input instance to L

Answer-reversing input transformation

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L


Make yes for h map to no for l

If QH, y is a no input to the Halting problem

Program QL

bool main(string z) {

QH(y); /* ignore return value */

return(QNL(z));/* no */

}

bool QH(unsigned x) {

/* comes from left-hand side

}

bool QNL(string y) {

if ((y.length( ) % 2) = = 0) return(yes);

else return(no);

}

  • Now choose a QYL (or QNL) that is a yes (or no) input instance to L

Make yes for H map to no for L

  • QHloops on y

  • Thus Y(QL) = {}

  • Determine if this makes QL a no or yes input instance to L



Problem setup
Problem Setup

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L

    • Input: Program P

    • Yes/No Question: Is Y(P) = {aa}?

  • Question: Is the transformation on the left an answer-preserving or answer-reversing input transformation from H to problem L?


Key step
Key Step

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L

    • Input: Program P

    • Yes/No Question: Is Y(P) = {aa}?

  • The output of the transformation is the input to the problem.

    • Plug QL in for program P above

    • Is Y(QL) = {aa}?


Is y q l aa
Is Y(QL) = {aa}?

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L

    • Input: Program P

    • Yes/No Question: Is Y(P) = {aa}?

  • Analysis

    • If QH loops on x, Y(QL)={}

    • No input to H creates a QL that is a no input for L

    • If QH halts on x, Y(QL) = {even length strings}

    • Yes input to H creates a QL that is a no input for L

  • Transformation does not work

    • All inputs map to no inputs


Three other problems
Three other problems

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L1

    • Input: Program P

    • Yes/No Question: Is Y(P) infinite?

  • Problem L2

    • Input: Program P

    • Yes/No Question: Is Y(P) finite?

  • Problem L3

    • Input: Program P

    • Yes/No Question: Is Y(P) = {} or is Y(P) infinite?


Is y p infinite
Is Y(P) infinite?

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L1

    • Input: Program P

    • Yes/No Question: Is Y(P) infinite?

  • Analysis

    • If QH loops on x, Y(QL)={}

    • No input to H creates a QL that is a no input for L

    • If QH halts on x, Y(QL) = {even length strings}

    • Yes input to H creates a QL that is a yes input for L

  • Transformation works

    • Answer-preserving


Is y p finite
Is Y(P) finite?

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L2

    • Input: Program P

    • Yes/No Question: Is Y(P) finite?

  • Analysis

    • If QH loops on x, Y(QL)={}

    • No input to H creates a QL that is a yes input for L

    • If QH halts on x, Y(QL) = {even length strings}

    • Yes input to H creates a QL that is a no input for L

  • Transformation works

    • Answer-reversing


Is y p or is y p infinite
Is Y(P) = {} or is Y(P) infinite?

  • Input of Transformation

    • Program QH, unsigned x

  • Output of Transformation

    • Program QL

    • bool main(string z) {

      • QH(y); /* ignore return value */

      • return(QYL(z)); /* yes or no */

    • }

    • bool QH(unsigned x) {}

    • bool QYL(string y) {

    • if ((y.length( ) % 2) = = 0) return (yes);

    • else return (no);

    • }

  • Problem L3

    • Input: Program P

    • Yes/No Question: Is Y(P) = {} or is Y(P) infinite?

  • Analysis

    • If QH loops on x, Y(QL)={}

    • No input to H creates a QL that is a yes input for L

    • If QH halts on x, Y(QL) = {even length strings}

    • Yes input to H creates a QL that is a yes input for L

  • Transformation does not work

    • All inputs map to yes inputs


Module 12
Module 12

  • Computation and Configurations

    • Formal Definition

    • Examples


Definitions
Definitions

  • Configuration

    • Functional Definition

      • Given the original program and the current configuration of a computation, someone should be able to complete the computation

    • Contents of a configuration for a C++ program

      • current instruction to be executed

      • current value of all variables

  • Computation

    • Complete sequence of configurations


Computation 1

1 int main(int x,y) {

2 int r = x % y;

3 if (r== 0) goto 8;

4 x = y;

5 y = r;

6 r = x % y;

7 goto 3;

8 return y; }

Input: 10 3

Line 1, x=?,y=?,r=?

Line 2, x=10, y=3,r=?

Line 3, x=10, y=3, r=1

Line 4, x=10, y=3, r=1

Line 5, x= 3, y=3, r=1

Line 6, x=3, y=1, r=1

Line 7, x=3, y=1, r=0

Line 3, x=3, y=1, r=0

Line 8, x=3, y=1, r=0

Output is 1

Computation 1


Computation 2

int main(int x,y) {

2 int r = x % y;

3 if (r== 0) goto 8;

4 x = y;

5 y = r;

6 r = x % y;

7 goto 3;

8 return y; }

Input: 53 10

Line 1, x=?,y=?,r=?

Line 2, x=53, y=10, r=?

Line 3, x= 53, y=10, r=3

Line 4, x=53, y=10, r=3

Line 5, x=10, y=10, r=3

Line 6, x=10, y=3, r=3

Line 7, x=10, y=3, r=1

Line 3, x=10, y=3, r=1

...

Computation 2


Computations 1 and 2

Line 1, x=?,y=?,r=?

Line 2, x=53, y=10, r=?

Line 3, x= 53, y=10, r=3

Line 4, x=53, y=10, r=3

Line 5, x=10, y=10, r=3

Line 6, x=10, y=3, r=3

Line 7, x=10, y=3, r=1

Line 3, x=10, y=3, r=1

...

Computations 1 and 2

  • Line 1, x=?,y=?,r=?

  • Line 2, x=10, y=3,r=?

  • Line 3, x=10, y=3, r=1

  • Line 4, x=10, y=3, r=1

  • Line 5, x= 3, y=3, r=1

  • Line 6, x=3, y=1, r=1

  • Line 7, x=3, y=1, r=0

  • Line 3, x=3, y=1, r=0

  • Line 8, x=3, y=1, r=0

  • Output is 1


Observation

int main(int x,y) {

2 int r = x % y;

3 if (r== 0) goto 8;

4 x = y;

5 y = r;

6 r = x % y;

7 goto 3;

8 return y; }

Line 3, x= 10, y=3, r=1

Program and current configuration

Together, these two pieces of information are enough to complete the computation

Are they enough to determine what the original input was?

No!

Both previous inputs, 10 3 as well as 53 10 eventually reached the same configuration (Line 3, x=10, y=3, r=1)

Observation


Module 13
Module 13

  • Studying the internal structure of REC, the set of solvable problems

    • Complexity theory overview

    • Automata theory preview

  • Motivating Problem

    • string searching


Studying rec

Studying REC

Complexity Theory

Automata Theory


Current picture of all languages
Current picture of all languages

All Languages

REC

Solvable

RE-REC

All languages - RE

Half

Solvable

Not even half solvable

Which language class should be studied further?


Complexity theory
Complexity Theory *

REC

RE -

REC

All languages

- RE

  • In complexity theory, we differentiate problems by how hard a problem is to solve

    • Remember, all problems in REC are solvable

  • Which problem is harder and why?

    • Max:

      • Input: list of n numbers

      • Task: return largest of the n numbers

    • Element

      • Input: list of n numbers

      • Task: return any of the n numbers


Resource usage
Resource Usage *

  • How do we formally measure the hardness of a problem?

    • We measure the resources required to solve input instances of the problem

      • Typical resources are?

      • Need a notion of size of an input instance

        • Obviously larger input instances require more resources to solve


Poly language class
Poly Language Class *

REC

RE -

REC

All languages

- RE

Poly

Rest of REC

Informal Definition: A problem L1 is easier than problem L2

if problem L1 can be solved in less time than problem L2.

Poly: the set of problems which can be solved in polynomial time (typically referred to as P, not Poly)

Major goal: Identify whether or not a problem belongs to Poly


Working with poly
Working with Poly

Poly

Rest of REC

  • How do you prove a problem L is in Poly?

  • How do you prove a problem L is not in Poly?

    • We are not very good at this.

    • For a large class of interesting problems, we have techniques (polynomial-time answer-preserving input transformations) that show a problem L probably is not in Poly, but few which prove it.


Examples

Shortest Path Problem

Input

Graph G

nodes s and t

Task

Find length of shortest path from s to t in G

Longest Path Problem

Input

Graph G

nodes s and t

Task

Find length of longest path from s to t in G

Examples

Poly

Rest of REC

Which problem is provably solvable in polynomial time?


Automata theory
Automata Theory

REC

RE -

REC

All languages

- RE

  • In automata theory, we will define new models of computation which we call automata

    • Finite State Automata (FSA)

    • Pushdown Automata (PDA)

  • Key concept

    • FSA’s and PDA’s are restricted models of computation

      • FSA’s and PDA’s cannot solve all the problems that C++ programs can

    • We then identify which problems can be solved using FSA’s and PDA’s


New language classes

Solvable

by FSA’s

and PDA’s

Solvable

by

PDA’s

New language classes

REC

RE -

REC

All languages

- RE

  • REC is the set of solvable languages when we start with a general model of computation like C++ programs

  • We want to identify which problems in REC can be solved when using these restricted automata

Rest of REC


Recap
Recap *

  • Complexity Theory

    • Studies structure of the set of solvable problems

    • Method: analyze resources (processing time) used to solve a problem

  • Automata Theory

    • Studies structure of the set of solvable problems

    • Method: define automata with restricted capabilities and resources and see what they can solve (and what they cannot solve)

    • This theory also has important implications in the development of programming languages and compilers


Motivating problem

Motivating Problem

String Searching


String searching

Input

String x

String y

Tasks

Return location of y in string x

Does string y occur in string x?

Can you identify applications of this type of problem in real life?

Try and develop a solution to this problem.

String Searching


String searching ii

Input

String x

pattern y

Tasks

Return location of y in string x

Does pattern y occur in string x?

Pattern

[anything].html

$EN4$$

Try and develop a solution to this problem.

String Searching II


String searching1
String Searching

  • We will show an easy way to solve these string searching problems

  • In particular, we will show that we can solve these problems in the following manner

    • write down the pattern

    • the computer automatically turns this into a program which performs the actual string search


Module 14
Module 14

  • Regular languages

    • Inductive definitions

    • Regular expressions

      • syntax

      • semantics


Regular languages regular expressions
Regular Languages(Regular Expressions)


Regular languages
Regular Languages

  • New language class

    • Elements are languages

  • We will show that this language class is identical to LFSA

    • Language class to be defined by Finite State Automata (FSA)

    • Once we have shown this, we will use the term “regular languages” to refer to this language class


Inductive definition of integers
Inductive Definition of Integers *

  • Base case definition

    • 0 is an integer

  • Inductive case definition

    • If x is an integer, then

      • x+1 is an integer

      • x-1 is an integer

  • Completeness

    • Only numbers generated using the above rules are integers


Inductive definition of regular languages
Inductive Definition of Regular Languages

  • Base case definition

    • Let S denote the alphabet

    • {} is a regular language

    • {l} is a regular language

    • {a} is a regular language for any character a in S

  • Inductive case definition

    • If L1 and L2 are regular languages, then

      • L1 union L2 is a regular language

      • L1 concatenate L2 is a regular language

      • L1* is a regular language

  • Completeness

    • Only languages generated using above rules are regular languages


Proving a language is regular
Proving a language is regular *

  • Prove that {aa, bb} is a regular language

    • {a} and {b} are regular languages

      • base case of definition

    • {aa} = {a}{a} is a regular language

      • concatenation rule

    • {bb} = {b}{b} is a regular language

      • concatenation rule

    • {aa, bb} = {aa} union {bb} is a regular language

      • union rule

  • Typically, we will not go through this process to prove a language is regular


Regular expressions
Regular Expressions

  • How do we describe a regular language?

    • Use set notation

      • {aa, bb, ab, ba}*

      • {a}{a,b}*{b}

    • Use regular expressions R

      • Inductive def of regular languages and regular expressions on page 72

      • (aa+bb+ab+ba)*

      • a(a+b)*b


R and l r
R and L(R) *

  • How we interpret a regular expression

    • What does a regular expression R mean to us?

      • aaba represents the regular language {aaba}

      • f represents the regular language {}

      • aa+bb represents the regular language {aa, bb}

    • We use L(R) to denote the regular language represented by regular expression R.


Precedence rules
Precedence rules *

  • What is L(ab+c*)?

    • Possible answers:

      • {a}({b} union {c}*}

      • ({a}{b,c})*

      • ({ab} union {c})*

      • {ab} union {c}*

    • Must know precedence rules

      • * first, then concatenation, then +


Precedence rules continued
Precedence rules continued

  • Precedence rules similar to those for arithmetic expressions

    • ab+c2

      • (a times b) + (c times c)

      • exponentiation first, then multiplication, then addition

      • Think of Kleene closure as exponentiation, concatenation as multiplication, and union as addition and the precedence rules are identical


Regular expressions are strings
Regular expressions are strings *

  • Let L be a regular language over the alphabet S

    • A regular expression R for L is just a string over the alphabet S union {(, ), +, *, f, l} which follows certain syntactic rules

      • That is, the set of legal regular expressions is itself a language over the alphabet S union {(, ), +, *}

        • f, a*aba are strings in the language of legal reg. exp.

        • )(, *a* are strings NOT in the language of legal reg. exp.


Semantics
Semantics *

  • We give a regular expression R meaning when we interpret it to represent L(R).

    • aaba is just a string

    • we interpret it to represent the language {aaba}.

  • We do similar things with arithmetic expressions

    • 10+72 is just a string

    • We interpret this string to represent the number 59


Key fact
Key fact *

  • A language L is a regular language iff there exists a reg. exp. R such that L(R) = L

    • When I ask for a proof that a language L is regular, rather than going through the inductive proof we saw earlier, I expect you to give me a regular expression R s.t. L(R) = L


Summary
Summary *

  • Regular expressions are strings

    • syntax for legal regular expressions

    • semantics for interpreting regular expressions

  • Regular languages are a new language class

    • A language L is regular iff there exists a regular expression R s.t. L(R) = L

  • We will show that the regular languages are identical to LFSA


Module 15
Module 15

  • FSA’s

    • Defining FSA’s

    • Computing with FSA’s

      • Defining L(M)

    • Defining language class LFSA

    • Comparing LFSA to set of solvable languages (REC)


Finite state automata

Finite State Automata

New Computational Model


Tape

  • We assume that you have already seen FSA’s in CSE 260

    • If not, review material in reference textbook

  • Only data structure is a tape

    • Input appears on tape followed by a B character marking the end of the input

    • Tape is scanned by a tape head that starts at leftmost cell and always scans to the right


Data type states
Data type/States

  • The only data type for an FSA is char

  • The instructions in an FSA are referred to as states

  • Each instruction can be thought of as a switch statement with several cases based on the char being scanned by the tape head


Example program
Example program

1 switch(current tape cell) {

case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {

case a: goto 1

case b: goto 1

case B: return no;

}


New model of computation

FSA M=(Q,S,q0,A,d)

Q = set of states = {1,2}

S = character set = {a,b}

don’t need B as we see below

q0 = initial state = 1

A = set of accepting (final) states = {1}

A is the set of states where we return yes on B

Q-A is set of states that return no on B

d = state transition function

1 switch(current tape cell) {

case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {

case a: goto 1

case b: goto 1

case B: return no;

}

New model of computation


Textual representations of d

1 switch(current tape cell) {

case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {

case a: goto 1

case b: goto 1

case B: return no;

}

a

b

1

2

2

2

1

1

Textual representations of d *

d(1,a) = 2, d(1,b)=2,

d(2,a)=1, d(2,b) = 1

{(1,a,2), (1,b,2), (2,a,1), (2,b,1)}


Transition diagrams

1 switch(current tape cell) {

case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {

case a: goto 1

case b: goto 1

case B: return no;

}

a,b

2

1

a,b

Transition diagrams

Note, this transition diagram

represents all 5 components

of an FSA, not just the transition

function d


Exercise
Exercise *

  • FSA M = (Q, S, q0, A, d)

    • Q = {1, 2, 3}

    • S = {a, b}

    • q0 = 1

    • A = {2,3}

    • d: {d(1,a) = 1, d(1,b) = 2, d(2,a)= 2, d(2,b) = 3, d(3,a) = 3, d(3,b) = 1}

  • Draw this FSA as a transition diagram


Transition diagram

a

a

b

2

1

b

b

3

a

Transition Diagram



Computation example

a

a

b

2

1

b

b

3

a

Computation Example *

Input: aabbaa


Computation of fsa s in detail
Computation of FSA’s in detail

  • A computation of an FSA M on an input x is a complete sequence of configurations

  • We need to define

    • Initial configuration of the computation

    • How to determine the next configuration given the current configuration

    • Halting or final configurations of the computation


Initial configuration

Given an FSA M and an input string x, what is the initial configuration of the computation of M on x?

(q0,x)

Examples

x = aabbaa

(1, aabbaa)

x = abab

(1, abab)

x = l

(1, l)

a

a

b

2

1

b

b

3

a

Initial Configuration

FSA M


Definition of m

( configuration of the computation of M on x?1, aabbaa) |-M (1, abbaa)

config 1 “yields” config 2 in one step using FSA M

(1,aabbaa) |-M (2, baa)

config 1 “yields” config 2 in 3 steps using FSA M

(1, aabbaa) |-M (2, baa)

config 1 “yields” config 2 in 0 or more steps using FSA M

Comment:

|-M determined by transition functiond

There must always be one and only one next configuration

If not, M is not an FSA

a

a

b

2

1

b

b

3

a

Definition of |-M

3

*

FSA M


Halting configurations

Halting configuration configuration of the computation of M on x?

(q, l)

Examples

(1, l)

(3, l)

Accepting Configuration

State in halting configuration is in A

Rejecting Configuration

State in halting configuration is not in A

a

a

b

2

1

b

b

3

a

Halting Configurations *

FSA M


Fsa m on x

a configuration of the computation of M on x?

a

b

FSA M

b

b

a

FSA M on x *

  • Two possibilities for M running on x

    • M accepts x

      • M accepts x iff the computation of M on x ends up in an accepting configuration

      • (q0, x) |-M (q, l) where q is in A

    • M rejects x

      • M rejects x iff the computation of M on x ends up in a rejecting configuration

      • (q0, x) |-M (q, l) where q is not in A

    • M does not loop or crash on x

*

*


Examples1

a configuration of the computation of M on x?

a

b

FSA M

b

b

a

Examples

  • For the following input strings, does M accept or reject?

    • l

    • aa

    • aabba

    • aab

    • babbb


Definition of d q x

Notation from the book configuration of the computation of M on x?

d(q, c) = p

dk(q, x) = p

k is the length of x

d*(q, x) = p

Examples

d(1, a) = 1

d(1, b) = 2

d4(1, abbb) = 1

d*(1, abbb) = 1

d*(2, baaaaa) = 3

a

a

b

2

1

b

b

3

a

Definition of d*(q, x)

FSA M


L m and lfsa

a configuration of the computation of M on x?

a

b

FSA M

b

b

a

L(M) and LFSA *

  • L(M) or Y(M)

    • The set of strings M accepts

      • Basically the same as Y(P) from previous unit

    • We say that M accepts/decides/recognizes/solves L(M)

      • Remember an FSA will not loop or crash

    • What is L(M) (or Y(M)) for the FSA M above?

  • N(M)

    • Rarely used, but it is the set of strings M rejects

  • LFSA

    • L is in LFSA iff there exists an FSA M such that L(M) = L.


Lfsa unit overview
LFSA Unit Overview configuration of the computation of M on x?

  • Study limits of LFSA

    • Understand what languages are in LFSA

      • Develop techniques for showing L is in LFSA

    • Understand what languages are not in LFSA

      • Develop techniques for showing L is not in LFSA

  • Prove Closure Properties of LFSA

  • Identify relationship of LFSA to other language classes


Comparing language classes

Comparing language classes configuration of the computation of M on x?

Showing LFSA is a subset of REC, the set of solvable languages


Lfsa subset rec
LFSA subset REC configuration of the computation of M on x?

  • Proof

    • Let L be an arbitrary language in LFSA

    • Let M be an FSA such that L(M) = L

      • M exists by definition of L in LFSA

    • Construct C++ program P from FSA M

    • Argue P solves L

    • There exists a C++ program P which solves L

    • L is solvable


Visualization

L configuration of the computation of M on x?

L

C++ Programs

M

P

FSA’s

Visualization

  • Let L be an arbitrary language in LFSA

  • Let M be an FSA such that L(M) = L

    • M exists by definition of L in LFSA

  • Construct C++ program P from FSA M

  • Argue P solves L

  • There exists a program P which solves L

  • L is solvable

LFSA

REC


Construction
Construction configuration of the computation of M on x?

FSA

M

Program

P

Construction

Algorithm

  • The construction is an algorithm which solves a problem with a program as input

    • Input to A: FSA M

    • Output of A: C++ program P such that P solves L(M)

    • How do we do this?


Comparing computational models
Comparing computational models configuration of the computation of M on x?

  • The previous slides show one method for comparing the relative power of two different computational models

    • Computational model CM1 is at least as general or powerful as computational model CM2 if

      • Any program P2 from computational model CM2 can be converted into an equivalent program P1 in computational model CM1.

    • Question: How can we show two computational models are equivalent?


Module 16
Module 16 configuration of the computation of M on x?

  • Distinguishability

    • Definition

    • Help in designing/debugging FSA’s


Distinguishability

Distinguishability configuration of the computation of M on x?


Questions
Questions configuration of the computation of M on x?

  • Let L be the set of strings over {a,b} which end with aaba.

  • Let M be an FSA such that L(M) = L.

  • Questions

    • Can aaba and aab endup in the same state of M? Why or why not?

    • How about aa and aab?

    • How about l or a?

    • How about b or bb?

    • How about l or bbab?


Definition
Definition * configuration of the computation of M on x?

  • String x is distinguishable from string y with respect to language L iff there exists a string z such that

    • xz is in L and yz is not in L OR

    • xz is not in L and yz is in L

  • When reviewing, identify the z for pair of strings on the previous slide


Questions1
Questions configuration of the computation of M on x?

  • Let L be the set of strings over {a,b} that have length 2 mod 5 or 4 mod 5.

  • Let M be an FSA such that L(M) = L.

  • Questions

    • Are aa and aab distinguishable with respect to L? Can they endup in the same state of M?

    • How about aa and aaba?

    • How about l and a?

    • How about b and aabbaa?


Design an fsa to accept l

One design method configuration of the computation of M on x?

Is l in L?

Implication?

Is a distinguishable from l wrt L?

Implication?

Is b distinguishable from l wrt L?

Implication?

Is b distinguishable froma wrt L?

Implication?

L = set of strings x over {a,b} such that length of x is 2 or 4 mod 5

Design an FSA to accept L


Design an fsa to accept l1

Design continued configuration of the computation of M on x?

Is aa distinguishable from l wrt L?

Implication?

Is aa distinguishable froma wrt L?

Implication?

L = set of strings x over {a,b} such that length of x is 2 or 4 mod 5

Design an FSA to accept L


Design an fsa to accept l2

Design continued configuration of the computation of M on x?

What strings would we compare ab to?

What results do we get?

Implications?

How about ba?

How about bb?

L = set of strings x over {a,b} such that length of x is 2 or 4 mod 5

Design an FSA to accept L


Design an fsa to accept l3

Design continued configuration of the computation of M on x?

We can continue in this vein, but it could go on forever

Now lets try something different

Consider string l.

What set of strings are indistinguishable from it wrt L?

Implications?

L = set of strings x over {a,b} such that length of x is 2 or 4 mod 5

Design an FSA to accept L


Design an fsa to accept l4

Design continued configuration of the computation of M on x?

Consider string a.

What set of strings are indistinguishable from it wrt L?

Implications?

Consider string aa.

What set of strings are indistinguishable from it wrt L?

Implications?

L = set of strings x over {a,b} such that length of x is 2 or 4 mod 5

Design an FSA to accept L


Debugging an fsa
Debugging an FSA configuration of the computation of M on x?

  • Do essentially the same thing

    • Identify some strings which end up in each state

    • Try and generalize each state to describe the language of strings which end up at that state.


Example 12
Example 1 configuration of the computation of M on x?

a,b

I

a

II

a

III

b

IV

a

V

b

a

b

b

VI

a,b


Example 22
Example 2 configuration of the computation of M on x?

b

a

a,b

I

II

III

IV

V

a

a

b

a

b

b


Example 31
Example 3 configuration of the computation of M on x?

a,b

II

a

I

a

IV

b

a

III

b

b


Module 17
Module 17 configuration of the computation of M on x?

  • Closure Properties of Language class LFSA

    • Remember ideas used in solvable languages unit

    • Set complement

    • Set intersection, union, difference, symmetric difference


Lfsa is closed under set complement
LFSA is closed under set complement configuration of the computation of M on x?

  • If L is in LFSA, then Lc is in LFSA

  • Proof

    • Let L be an arbitrary language in LFSA

    • Let M be the FSA such that L(M) = L

      • M exists by definition of L in LFSA

    • Construct FSA M’ from M

    • Argue L(M’) = Lc

    • There exists an FSA M’ such that L(M’) = Lc

    • Lc is in LFSA


Visualization1

L configuration of the computation of M on x?

Lc

M

M’

FSA’s

Visualization

  • Let L be an arbitrary language in LFSA

  • Let M be the FSA such that L(M) = L

    • M exists by definition of L in LFSA

  • Construct FSA M’ from M

  • Argue L(M’) = Lc

  • Lc is in LFSA

LFSA


Construct fsa m from m
Construct FSA M’ from M configuration of the computation of M on x?

  • What did we do when we proved that REC, the set of solvable languages, is closed under set complement?

  • Construct program P’ from program P

  • Can we translate this to the FSA setting?


Construct fsa m from m1
Construct FSA M’ from M configuration of the computation of M on x?

  • M = (Q, S, q0, A, d)

  • M’ = (Q’, S’, q’, A’, d’)

    • M’ should say yes when M says no

    • M’ should say no when M says yes

    • How?

      • Q’ = Q

      • S’ = S

      • q’ = q0

      • d’ = d

      • A’ = Q-A


Example

a configuration of the computation of M on x?

a

b

2

1

b

b

3

FSA M’

a

  • Q’ = Q

  • S’ = S

  • q’ = q0

  • d’ = d

  • A’ = Q-A

Example

a

a

b

2

1

b

b

3

FSA M

a


Construction is an algorithm
Construction is an algorithm * configuration of the computation of M on x?

FSA

M

FSA

M’

Construction

Algorithm

  • Set Complement Construction

    • Algorithm Specification

      • Input: FSA M

      • Output: FSA M’ such that L(M’) = L(M)c

    • Comments

      • This algorithm can be in any computational model.

        • It does not have to be (and typically is not) an FSA

      • These set closure constructions are useful.

        • More on this later


Specification of the algorithm
Specification of the algorithm configuration of the computation of M on x?

FSA

M

FSA

M’

Construction

Algorithm

  • Your algorithm must give a complete specification of M’ in terms of M

    • Example:

      • Let input FSA M = (Q, S, q0, A, d)

      • Output FSA M’ = (Q’, S’, q’, A’, d’) where

        • Q’ = Q

        • S’ = S

        • q’ = q0

        • d’ = d

        • A’ = Q-A

      • When I ask for such a construction algorithm specification, this type of answer is what I am looking for. Further algorithmic details on how such an algorithm would work are unnecessary.


Lfsa closed under set intersection operation
LFSA closed under Set Intersection Operation configuration of the computation of M on x?

(also set union, set difference, and symmetric difference)


Lfsa closed under set intersection operation1
LFSA closed under set intersection operation * configuration of the computation of M on x?

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA

  • Construct FSA M3 from FSA’s M1 and M2

  • Argue L(M3) = L1 intersect L2

  • There exists FSA M3 s.t. L(M3) = L1 intersect L2

  • L1 intersect L2 is in LFSA


Visualization2

L configuration of the computation of M on x?1

L1 intersect L2

L2

M1

M3

M2

FSA’s

Visualization

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA

  • Construct FSA M3 from FSA’s M1 and M2

  • Argue L(M3) = L1 intersect L2

  • There exists FSA M3 s.t. L(M3) = L1 intersect L2

  • L1 intersect L2 is in LFSA

LFSA


Algorithm specification

Alg configuration of the computation of M on x?

Algorithm Specification

  • Input

    • Two FSA’s M1 and M2

  • Output

    • FSA M3 such that L(M3) = L(M1) intersection L(M2)

FSA M1

FSA M2

FSA M3


Use old ideas

FSA M configuration of the computation of M on x?1

FSA M2

Alg

FSA M3

Use Old Ideas

  • Key concept: Try ideas from previous closure property proofs

  • Example

    • How did the algorithm that was used to prove that REC is closed under set intersection work?

    • If we adapt this approach, what should M3 do with respect to M1, M2, and the input string?


Run m 1 and m 2 simultaneously

FSA M configuration of the computation of M on x?1

FSA M2

Alg

FSA M3

l,A

0,A

1,A

2,A

1

0,1

l,B

0,B

1,B

2,B

A

0

B

M2

M3

Run M1 and M2 Simultaneously

0

1

1

0

l

0

0

1

2

1

0

1

M1

What happens when M1 and M2 run on input string 11010?


Construction1

Input configuration of the computation of M on x?

FSA M1 = (Q1, S1, q1, d1, A1)

FSA M2 = (Q2, S2, q2, d2, A2)

Output

FSA M3 = (Q3, S3, q3, d3, A3)

What is Q3?

Q3 = Q1 X Q2 where X is cartesian product

In this case, Q3 = {(l,A), (l,B), (0,A), (0,B), (1,A), (1,B), (2,A), (2,B)}

What is S3?

S3 = S1 = S2

In this case, S3 = {0,1}

0

1

1

0

l

0

0

1

2

1

0

1

M1

1

0,1

0

A

B

M2

Construction *


Construction2

Input configuration of the computation of M on x?

FSA M1 = (Q1, S1, q1, d1, A1)

FSA M2 = (Q2, S2, q2, d2, A2)

Output

FSA M3 = (Q3, S3, q3, d3, A3)

What is q3?

q3 = (q1, q2)

In this case, q3 = (l,A)

What is A3?

A3 = {(p, q) | p in A1 and q in A2}

In this case, A3 = {(0,B)}

0

1

1

0

l

0

0

1

2

1

0

1

M1

1

0,1

0

A

B

M2

Construction *


Construction3

Input configuration of the computation of M on x?

FSA M1 = (Q1, S1, q1, d1, A1)

FSA M2 = (Q2, S2, q2, d2, A2)

Output

FSA M3 = (Q3, S3, q3, d3, A3)

What is d3?

For all p in Q1, q in Q2, a in S, d3((p,q),a) = (d1(p,a),d2(q,a))

In this case,

d3((0,A),0) = (d1(0,0),d2(A,0))

= (0,B)

d3((0,A),1) = (d1(0,1),d2(A,1))

= (1,A)

0

1

1

0

l

0

0

1

2

1

0

1

M1

1

0,1

0

A

B

M2

Construction


Example summary

1 configuration of the computation of M on x?

0,1

A

0

B

M2

Example Summary

1

0

1

1

1

0

l

0

0

1

2

l,A

0,A

1

1,A

2,A

1

0

1

0

0

0

M1

1

0

0

1

l,B

0,B

1,B

2,B

0

1

M3


Observation1
Observation configuration of the computation of M on x?

  • Input

    • FSA M1 = (Q1, S1, q1, d1, A1)

    • FSA M2 = (Q2, S2, q2, d2, A2)

  • Output

    • FSA M3 = (Q3, S3, q3, d3, A3)

    • What is A3?

      • A3 = {(p, q) | p in A1 and q in A2}

  • What if operation were different?

    • Set union, set difference, symmetric difference


Observation continued
Observation continued * configuration of the computation of M on x?

  • Input

    • FSA M1 = (Q1, S1, q1, d1, A1)

    • FSA M2 = (Q2, S2, q2, d2, A2)

  • Output

    • FSA M3 = (Q3, S3, q3, d3, A3)

    • What is A3?

      • Set intersection: A3 = {(p, q) | p in A1and q in A2}

      • Set union: A3 = {(p, q) | p in A1or q in A2}

      • Set difference: A3 = {(p, q) | p in A1 and q not in A2}

      • Symmetric difference: A3 = {(p, q) | (p in A1 and q not in A2) or (p not in A1 and q in A2) }


Observation conclusion
Observation conclusion configuration of the computation of M on x?

  • LFSA is closed under

    • set intersection

    • set union

    • set difference

    • symmetric difference

  • The constructions used to prove these closure properties are essentially identical


Comments
Comments * configuration of the computation of M on x?

  • You should be able to execute this algorithm

    • Convert two FSA’s into a third FSA with the correct properties.

  • You should understand the idea behind this algorithm

    • The third FSA essentially runs both input FSA’s simultaneously on any input string

    • How we set A3 depending on the specific set operation

  • You should understand how this algorithm can be used to simplify design of FSA’s

  • You should be able to construct new algorithms for new closure property proofs


Comparison

L configuration of the computation of M on x?

L1

L1 intersect L2

L

LFSA

L2

REC

LFSA

M1

M3

C++ Programs

M

M2

P

FSA’s

FSA’s

Comparison *


Module 18
Module 18 configuration of the computation of M on x?

  • NFA’s

    • nondeterministic transition functions

      • computations are trees, not paths

    • L(M) and LNFA

  • LFSA subset of LNFA

    • Comparing computational models


Nondeterministic finite state automata

Nondeterministic Finite State Automata configuration of the computation of M on x?

NFA’s


Change d is a relation
Change: configuration of the computation of M on x? d is a relation

  • For an FSA M, d(q,a) results in one and only one state for all states q and characters a.

    • That is, d is a function

  • For an NFA M, d(q,a) can result in a set of states

    • That is, d is now a relation

    • Next step is not determined (nondeterministic)


Example nfa

a,b configuration of the computation of M on x?

a,b

a

a

b

a

Example NFA

  • Why is this only an NFA and not an FSA? Identify as many reasons as you can.


Computing with nfa s
Computing with NFA’s configuration of the computation of M on x?

  • Configurations: same as they are for FSA’s

  • Computations are different

    • Initial configuration is identical

    • However, there may be several next configurations or there may be none.

      • Computation is no longer a “path” but is now a “graph” (often a tree) rooted at the initial configuration

    • Definition of halting, accepting, and rejecting configurations is identical

    • Definition of acceptance must be modified


Computation graph tree

(1, configuration of the computation of M on x?aaaba)

(2, aaaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

crash

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

a

a

b

a

(1, a)

(4, a)

(1, l)

(2, l)

(5, l)

Computation Graph (Tree)

Input string aaaaba

(1, aaaaba)


Definition of unchanged

(1, configuration of the computation of M on x?aaaaba)

(1, aaaba)

(2, aaaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

crash

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

a

a

b

a

(1, a)

(4, a)

(1, l)

(2, l)

(5, l)

Definition of |- unchanged *

Input string aaaaba

(1, aaaaba) |- (1, aaaba)

(1, aaaaba) |- (2, aaaba)

(1, aaaaba) |-3 (1, aba)

(1, aaaaba) |-3 (3, aba)

(1, aaaaba) |-* (2, aba)

(1, aaaaba) |-* (3, aba)

(1, aaaaba) |-* (1, l)

(1, aaaaba) |-* (5, l)


Acceptance and rejection

(1, configuration of the computation of M on x?aaaaba)

(1, aaaba)

(2, aaaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

crash

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

a

a

b

a

(1, a)

(4, a)

(1, l)

(2, l)

(5, l)

Acceptance and Rejection *

Input string aaaaba

M accepts string x if one of the configurations reached is an accepting configuration

(q0, x) |-* (f, l),f in A

M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations


Comparison1

a,b configuration of the computation of M on x?

a,b

a

a

b

a

NFA

Comparison

b

a

a,b

a

a

b

a

b

b

FSA


Defining l m and lnfa

M configuration of the computation of M on x?accepts string x if one of the configurations reached is an accepting configuration

(q0, x) |-* (f, l),f in A

M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations

L(M) (or Y(M))

The set of strings accepted by M

N(M)

The set of strings rejected by M

LNFA

Language L is in language class LNFA iff there exists an NFA M such that L(M) = L

Defining L(M) and LNFA


Comparing language classes1

Comparing language classes configuration of the computation of M on x?

LFSA subset of LNFA


Lfsa subset lnfa
LFSA subset LNFA configuration of the computation of M on x?

  • Let L be an arbitrary language in LFSA

  • Let M be the FSA such that L(M) = L

    • M exists by definition of L in LFSA

  • Construct an NFA M’ such that L(M’) = L

  • Argue L(M’) = L

  • There exists an NFA M’ such that L(M’) = L

  • L is in LNFA

    • By definition of L in LNFA


Visualization3

L configuration of the computation of M on x?

L

M

M’

FSA’s

NFA’s

Visualization

  • Let L be an arbitrary language in LFSA

  • Let M be an FSA such that L(M) = L

    • M exists by definition of L in LFSA

  • Construct NFA M’ from FSA M

  • Argue L(M’) = L

  • There exists an NFA M’ such that L(M’) = L

  • L is in LNFA

LFSA

LNFA


Construction4
Construction configuration of the computation of M on x?

  • We need to make M into an NFA M’ such that L(M’) = L(M)

  • How do we accomplish this?


Module 19
Module 19 configuration of the computation of M on x?

  • LNFA subset of LFSA

    • Theorem 4.1 on page 131 of Martin textbook

    • Compare with set closure proofs

  • Main idea

    • A state in FSA represents a set of states in original NFA


Lnfa subset lfsa
LNFA subset LFSA configuration of the computation of M on x?

  • Let L be an arbitrary language in LNFA

  • Let M be the NFA such that L(M) = L

    • M exists by definition of L in LNFA

  • Construct an FSA M’ such that L(M’) = L

  • Argue L(M’) = L

  • There exists an FSA M’ such that L(M’) = L

  • L is in LFSA

    • By definition of L in LFSA


Visualization4

L configuration of the computation of M on x?

L

M

M’

NFA’s

FSA’s

Visualization

  • Let L be an arbitrary language in LNFA

  • Let M be an NFA such that L(M) = L

    • M exists by definition of L in LNFA

  • Construct FSA M’ from NFA M

  • Argue L(M’) = L

  • There exists an FSA M’ such that L(M’) = L

  • L is in LFSA

LNFA

LFSA


Construction specification
Construction Specification configuration of the computation of M on x?

  • We need an algorithm which does the following

    • Input: NFA M

    • Output: FSA M’ such that L(M’) = L(M)


Difficulty

An NFA can be in several states after processing an input string x

(1, aaaaba)

(1, aaaba)

(2, aaaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

crash

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

a

a

b

a

(1, a)

(4, a)

(1, l)

(2, l)

(5, l)

Difficulty *

Input string aaaaba


Observation2

All strings which end up in the set of states {1,2,3} are string xindistinguishable with respect to L(M)

(1, aaaaba)

(1, aaaba)

(2, aaaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

crash

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

a

a

b

a

(1, a)

(4, a)

(1, l)

(2, l)

(5, l)

Observation *

Input string aaaaba


Given an NFA M = (Q, string xS,q0,d,A), the equivalent FSA M’ should have one state for each subset of Q

Example

In this case there are 5 states in Q

There are 25 subsets of Q including {} and Q

The FSA M’ will have 25 states

What strings end up in state {1,2,3} of M’?

The strings which end up in states 1, 2, and 3 of NFA M.

In this case, strings which do not contain aaba and end with aa such as aa, aaa, and aaaa.

a,b

a,b

a

a

b

a

Idea

Input string aaaaba


Idea illustrated

( string x1,aaaaba)

({1}, aaaaba)

(1, aaaba)

(2, aaaba)

({1,2}, aaaba)

({1,2,3}, aaba)

(1, aaba)

(2, aaba)

(3, aaba)

(1, aba)

(2, aba)

(3, aba)

({1,2,3}, aba)

a,b

a,b

(1, ba)

(2, ba)

(3, ba)

({1,2,3}, ba)

a

a

b

a

({1,4}, a)

(1, a)

(4, a)

({1,2,5}, l)

(1, l)

(2, l)

(5, l)

Idea Illustrated

Input string aaaaba


Construction5

a,b string x

a,b

Input NFA M = (Q, S, q0, d, A)

Output FSA M’ = (Q’, S’, q’, d’, A’)

What is Q’?

all subsets of Q including Q and {}

In this case, Q’ =

What is S’?

We always make S’ = S

In this case, S’ = S = {a,b}

What is q’?

We always make q’ = {q0}

In this case q’ =

NFA M

a

a

1

2

3

Construction


Construction6

a,b string x

a,b

Input NFA M = (Q, S, q0, d, A)

Output FSA M’ = (Q’, S’, q’, d’, A’)

What is A’?

Suppose a string x ends up in states 1 and 2 of the NFA M above.

Is x accepted by M?

Should {1,2} be an accepting state in FSA M’?

Suppose a string x ends up in states 1 and 2 and 3 of the NFA M above.

Is x accepted by M?

Should {1,2,3} be an accepting state in FSA M’?

Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q

p is in A’ iff at least one of the states q1, q2, …, qk is in A

In this case, A’ =

NFA M

a

a

1

2

3

Construction


Construction7

a,b string x

a,b

Input NFA M = (Q, S, q0, d, A)

Output FSA M’ = (Q’, S’, q’, d’, A’)

What is d’?

If string x ends up in states 1 and 2 after being processed by the NFA above, where does string xa end up after being processed by the NFA above?

Figuring out d’(p,a) in general

Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q

Then d’(p,a) = d(q1,a) union d(q2,a) union … union d(qk,a)

Similar to 2 FSA to 1 FSA construction

In this case

d’({1,2},a) =

NFA M

a

a

1

2

3

Construction


Construction summary

a,b string x

a,b

Input NFA M = (Q, S, q0, d, A)

Output FSA M’ = (Q’, S’, q’, d’, A’)

Q’ =all subsets of Q including Q and {}

In this case, Q’ = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}

S’ = S

In this case, S’ = S = {a,b}

q’ ={q0}

In this case, q’ = {1}

A’

Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q

p is in A’ iff at least one of the states q1, q2, …, qk is in A

d’

Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q

Then d’(p,a) = d(q1,a) union d(q2,a) union … union d(qk,a)

NFA M

a

a

1

2

3

Construction Summary


Example summary1

a string x

b

b

a

b

a

{1}

{1,2}

{1,2,3}

{1,3}

b

a

a,b

a,b

b

a

a,b

{}

{2}

{3}

{2,3}

FSA M’

Example Summary

a,b

a,b

1

a

2

a

3

NFA M


Example summary continued

These states cannot be reached from initial state and are unnecessary.

Example Summary Continued

a

b

b

a,b

a,b

a

b

a

{1}

{1,2}

{1,2,3}

{1,3}

1

a

2

a

3

b

a

a,b

a,b

NFA M

b

a

a,b

{}

{2}

{3}

{2,3}

FSA M’


Example summary continued1
Example Summary Continued unnecessary.

a

b

b

a,b

a,b

a

b

a

{1}

{1,2}

{1,2,3}

{1,3}

1

a

2

a

3

b

a

NFA M

Smaller FSA M’

By examination, we can see that state {1,3} is unnecessary.

However, this is a case by case optimization.

It is not a general technique or algorithm.


Example 23

A unnecessary.

B

C

Example 2

a,b

a

b

NFA M

Step 1: name the three states of NFA M


Step 2 transition table

a,b unnecessary.

a

b

A

B

C

{B}

NFA M

{}

Step 2: transition table

a

b

{A}

{B}

{}

d’({B,C},a) = d(B,a) U d(C,a)

= {B} U {}

= {B}

d’({B,C},b) = d(B,b) U d(C,b)

= {B,C} U {}

= {B,C}

{B}

{B,C}

{}

{}

{B,C}

{B}

{B,C}


Step 3 accepting states

a,b unnecessary.

a

b

A

B

C

NFA M

Step 3: accepting states

a

b

Which states should be accepting?

Any state which includes an accepting state of M, in this case, C.

A’ = {{B,C}}

{A}

{B}

{}

{B}

{B}

{B,C}

{}

{}

{}

{B,C}

{B}

{B,C}


Step 4 answer

a,b unnecessary.

a

b

a

b

A

B

C

{A}

{B}

{}

{B}

{B}

{B,C}

NFA M

{}

{}

{}

{B,C}

{B}

{B,C}

Step 4: Answer

Initial state is {A}

Set of final states A’ = {{B,C}}

This is sufficient. You do NOT need to turn this into a diagram.


Step 5 optional

a,b unnecessary.

a

b

A

B

C

a

b

a

b

NFA M

{A}

{B}

{B,C}

a

a,b

b

{}

Step 5: Optional

FSA M’


Comments1
Comments unnecessary.

  • You should be able to execute this algorithm

    • You should be able to convert any NFA into an equivalent FSA.

  • You should understand the idea behind this algorithm

    • For an FSA M’, strings which end up in the same state of M’ are indistinguishable wrt L(M’)

    • For an NFA M, strings which end up in the same set of states of M are indistinguishable wrt L(M)


Comments2
Comments unnecessary.

  • You should understand the importance of this algorithm

    • Design tool

      • We can design using NFA’s

      • A computer will convert this NFA into an equivalent FSA

        • FSA’s can be executed by computers whereas NFA’s cannot (or at least cannot easily be run by computers)

    • Chaining together algorithms

      • Perhaps it is easy to build NFA’s to accept L1 and L2

      • Use this algorithm to turn these NFA’s to FSA’s

      • Use previous algorithm to build FSA to accept L1 intersect L2

  • You should be able to construct new algorithms for new closure property proofs


Module 20
Module 20 unnecessary.

  • NFA’s with l-transitions

    • NFA-l’s

      • Formal definition

      • Simplifies construction

    • LNFA-l

    • Showing LNFA-l is a subset of LNFA (extra credit)

      • and therefore a subset of LFSA


Defining nfa l s
Defining NFA- unnecessary.l’s


Change l transitions
Change: unnecessary. l-transitions

  • We now allow an NFA M to change state without reading input

  • That is, we add the following categories of transitions to d

    • d(q,l) is allowed


Example1

a,b unnecessary.

a,b

a

a

b

a

l

b

a

a

b

l

a,b

a,b

Example *


Defining l m and lnfa l

M unnecessary.accepts string x if one of the configurations reached is an accepting configuration

(q0, x) |-* (f, l),f e A

M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations

L(M) or Y(M)

N(M)

LNFA-l

Language L is in language class LNFA-l iff

Defining L(M) and LNFA-l


Lnfa l subset lfsa
LNFA- unnecessary.l subset LFSA

  • Recap of what we already know

    • Let M be any NFA

    • There exists an algorithm A1 which constructs an FSA M’ such that L(M’) = L(M)

  • New goal

    • Let M be any NFA-l

    • There exists an algorithm A2 which constructs an FSA M’ such that L(M’) = L(M)


Visualization5

A unnecessary.2

Visualization

  • Goal

    • Let M be any NFA-l

    • There exists an algorithm A2 which constructs an FSA M’ such that L(M’) = L(M)

NFA-l M

FSA M’


Modified goal

NFA unnecessary.

M1

NFA-l M

A2

FSA M’

A2’

A1

NFA-l M

FSA M’

Algorithm A2

Modified Goal

  • Question

    • Can we use any existing algorithms to simplify the task of developing algorithm A2?

      • Yes, we can use algorithm A1 which converts an NFA M1 into an FSA M’ such that L(M’) = L(M1)


New goal extra credit

NFA- unnecessary.l M

A2’

NFA M1

New Goal (extra credit)

  • Difficulty

    • NFA-l M can make transitions on l

    • How can the NFA M1 simulate these l-transitions?

a

l

b

l

l

b

1

2

3

4

5

6


Basic idea

NFA- unnecessary.l M

A2’

NFA M1

b

b

b

Basic Idea

  • For each state q of M and each character a of S, figure out which states are reachable from q taking any number of l-transitions and exactly one transition on that character a.

  • In the NFA-d M1, directly connect q to each of these states using an arc labeled with a.

a

l

b

l

l

b

1

2

3

4

5

6

1

2

3

4

5

6


Process state 2

NFA- unnecessary.d M1

NFA-l M

A2’

b

b

b

b

b

b

Process State 2

a

l

b

l

l

b

1

2

3

4

5

6

1

2

3

4

5

6


Process state 3

NFA- unnecessary.d M1

NFA-l M

A2’

b

a

b

b

a

b

b

b

b

Process State 3

a

l

b

l

l

b

1

2

3

4

5

6

1

2

3

4

5

6


Final picture

a unnecessary.

l

b

l

l

b

1

2

3

4

5

6

NFA-d M1

NFA-l M

A2’

b

b

b

b

b

b

Final Picture

a

a

a

a

b

1

2

3

4

5

6

b

b


Construction8

Input NFA- unnecessary.l M = (Q, S, q0, d, A)

Output NFA M1 = (Q1, S1, q1, d1, A1)

What is Q1?

Q1 = Q

In this case, Q1 = {1,2,3,4,5,6}

What is S1?

S1 = S

In this case, S1 = S = {a,b}

What is q1?

We always make q1 = q0

In this case q1 = 1

a

l

b

l

l

b

1

2

3

4

5

6

Construction


Construction9

Input NFA- unnecessary.l M = (Q, S, q0, d, A)

Output NFA M1 = (Q1, S1, q1, d1, A1)

What is d1?

d1(q,a) = the set of states reachable from state q in M taking any number of l-transitions and exactly one transition on the character a

More on this later

In this case

d1(1,a) = {}

d1(1,b) = {3,4,5}

What is A1?

A1 = A with one minor change

If an accepting state is reachable from q0 using only l-transitions, then we make q1 an element of A1

In this case, using only l-transitions, no accepting state is reachable from q0, so A1 = A

a

l

b

l

l

b

1

2

3

4

5

6

Construction


Computing d 1 q a

d unnecessary.1(q,a) = the set of states reachable from state q in M taking 0 or more l-transitions and exactly one transition on the character a

Break this down into three steps

First compute all states reachable from q using 0 or more l-transitions

We call this set of states L(q)

Next, compute all states reachable from any element of L(q) using the character a

We can denote these states as d(L(q),a)

Finally, compute all states reachable from states in d(L(q),a) using 0 or more l-transitions

We denote these states as L(d(L(q),a))

This is the desired answer

a

l

b

l

l

b

1

2

3

4

5

6

Computing d1(q,a)


Example2

d unnecessary.1(1,b) = {3,4,5}

Compute L(1), all states reachable from state 1 using 0 or more l-transitions

L(1) = {1,2}

Compute d(L(q),b), all states reachable from any element L(1) of using the character b:

d(L(q),b) = d({1,2},b)

= d(1,b) U d(2,b)

= {} U {3} = {3}

Compute L(d(L(q),a)), all states reachable from states in d(L(q),a) using 0 or more l-transitions

L(d(L(q),a)) = L(3)

= {3,4,5}

a

l

b

l

l

b

1

2

3

4

5

6

Example


Comments3
Comments unnecessary.

  • For extra credit, you should be able to execute this algorithm

    • Convert any NFA-l into an equivalent NFA.

  • For extra credit, you should understand the idea behind this algorithm

    • Why the transition function is computed the way it is

    • Why A1 may need to include q1 in some cases

  • You should understand the importance of this algorithm

    • Compiler role again

    • Use in combination with previous algorithm for converting any NFA into an equivalent FSA to create a new algorithm for converting any NFA-l into an equivalent FSA


Lnfa l lfsa
LNFA- unnecessary.l = LFSA

  • Implications

    • Let us primarily use the term LFSA to refer to this language class

    • Given a language L is in LFSA

      • We know there exists an FSA M s.t. L(M) = L

      • We know there exists an NFA M s.t. L(M) = L

    • To show a language L is in LFSA

      • Show there exists an FSA M s.t. L(M) = L

      • Show there exists an NFA-l M s.t. L(M) = L


Module 21
Module 21 unnecessary.

  • Closure Properties for LFSA using NFA’s

    • From now on, when I say NFA, I mean any NFA including an NFA-l unless I add a specific restriction

    • union (second proof)

    • concatenation

    • Kleene closure


Lfsa closed under set union again
LFSA closed under set union unnecessary.(again)


Lfsa closed under set union
LFSA closed under set union unnecessary.

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M3 from NFA’s M1 and M2

  • Argue L(M3) = L1 union L2

  • There exists NFA M3 s.t. L(M3) = L1 union L2

  • L1 union L2 is in LFSA


Visualization6

L unnecessary.1

L1 union L2

L2

M1

M3

M2

NFA’s

Visualization

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M3 from NFA’s M1 and M2

  • Argue L(M3) = L1 union L2

  • There exists NFA M3 s.t. L(M3) = L1 union L2

  • L1 union L2 is in LFSA

LFSA


Algorithm specification1

A unnecessary.

Algorithm Specification

  • Input

    • Two NFA’s M1 and M2

  • Output

    • NFA M3 such that L(M3) = ?

NFA M1

NFA M2

NFA M3


Use l transition

a unnecessary.

l

a,b

l

a,b

a,b

A

M3

NFA M1

NFA M2

NFA M3

Use l-transition

a

M1

a,b

a,b

a,b

M2


General case

M unnecessary.2

M1

l

l

A

M3

NFA M1

NFA M2

NFA M3

General Case *


Construction10

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

NFA M2 = (Q2, S2, q2, d2, A2)

Output

NFA M3 = (Q3, S3, q3, d3, A3)

What is Q3?

Q3 =

What is S3?

S3 = S1 = S2

What is q3?

q3 =

A

NFA M1

NFA M2

NFA M3

Construction *


Construction11

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

NFA M2 = (Q2, S2, q2, d2, A2)

Output

NFA M3 = (Q3, S3, q3, d3, A3)

What is A3?

A3 =

What is d3?

d3 =

A

NFA M1

NFA M2

NFA M3

Construction


Comments4
Comments unnecessary.

  • You should be able to execute this algorithm

  • You should understand the idea behind this algorithm

  • You should understand how this algorithm can be used to simplify design

  • You should be able to design new algorithms for new closure properties

  • You should understand how this helps prove result that regular languages and LFSA are identical

    • In particular, you should understand how this is used to construct an NFA M from a regular expression r s.t. L(M) = L(r)

    • To be seen later



Lfsa closed under set concatenation1
LFSA closed under set concatenation unnecessary.

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M3 from NFA’s M1 and M2

  • Argue L(M3) = L1concatenate L2

  • There exists NFA M3 s.t. L(M3) = L1 concatenate L2

  • L1 concatenate L2 is in LFSA


Visualization7

L unnecessary.1

L1 concatenate L2

L2

M1

M3

M2

NFA’s

Visualization

  • Let L1 and L2 be arbitrary languages in LFSA

  • Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2

    • M1 and M2 exist by definition of L1 and L2 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M3 from NFA’s M1 and M2

  • Argue L(M3) = L1concatenate L2

  • There exists NFA M3 s.t. L(M3) = L1 concatenate L2

  • L1 concatenate L2 is in LFSA

LFSA


Algorithm specification2

A unnecessary.

Algorithm Specification

  • Input

    • Two NFA’s M1 and M2

  • Output

    • NFA M3 such that L(M3) =

NFA M1

NFA M2

NFA M3


Use l transition1

a unnecessary.

l

a,b

a,b

a,b

A

M3

NFA M1

NFA M2

NFA M3

Use l-transition

a

M1

a,b

a,b

a,b

M2


General case1

M unnecessary.2

M1

l

l

A

M3

NFA M1

NFA M2

NFA M3

General Case


Construction12

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

NFA M2 = (Q2, S2, q2, d2, A2)

Output

NFA M3 = (Q3, S3, q3, d3, A3)

What is Q3?

Q3 =

What is S3?

S3 = S1 = S2

What is q3?

q3 =

A

NFA M1

NFA M2

NFA M3

Construction


Construction13

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

NFA M2 = (Q2, S2, q2, d2, A2)

Output

NFA M3 = (Q3, S3, q3, d3, A3)

What is A3?

A3 =

What is d3?

d3 =

A

NFA M1

NFA M2

NFA M3

Construction


Comments5
Comments unnecessary.

  • You should be able to execute this algorithm

  • You should understand the idea behind this algorithm

  • You should understand how this algorithm can be used to simplify design

  • You should be able to design new algorithms for new closure properties

  • You should understand how this helps prove result that regular languages and LFSA are identical

    • In particular, you should understand how this is used to construct an NFA M from a regular expression r s.t. L(M) = L(r)

    • To be seen later



Lfsa closed under kleene closure1
LFSA closed under Kleene Closure unnecessary.

  • Let L be arbitrary language in LFSA

  • Let M1 be an NFA s.t. L(M1) = L

    • M1 exists by definition of L1 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M2 from NFA M1

  • Argue L(M2) = L1*

  • There exists NFA M2 s.t. L(M2) = L1*

  • L1* is in LFSA


Visualization8

L unnecessary.1

L1*

M1

M2

NFA’s

Visualization

  • Let L be arbitrary language in LFSA

  • Let M1 be an NFA s.t. L(M1) = L

    • M1 exists by definition of L1 in LFSA and the fact that every FSA is an NFA

  • Construct NFA M2 from NFA M1

  • Argue L(M2) = L1*

  • There exists NFA M2 s.t. L(M2) = L1*

  • L1* is in LFSA

LFSA


Algorithm specification3

A unnecessary.

Algorithm Specification

  • Input

    • NFA M1

  • Output

    • NFA M2 such that L(M2) =

NFA M1

NFA M2


Use l transition2

NFA M unnecessary.1

NFA M2

l

a

l

M2

A

Use l-transition

a

M1


General case2

NFA M unnecessary.1

NFA M2

l

M1

l

A

l

M3

General Case *


Construction14

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

Output

NFA M2 = (Q2, S2, q2, d2, A2)

What is Q2?

What is S2?

S2 = S1

What is q2?

q2 =

NFA M1

NFA M2

A

Construction


Construction15

Input unnecessary.

NFA M1 = (Q1, S1, q1, d1, A1)

Output

NFA M2 = (Q2, S2, q2, d2, A2)

What is A2?

A2 =

What is d2?

d2 =

NFA M1

NFA M2

A

Construction


Comments6
Comments unnecessary.

  • You should be able to execute this algorithm

  • You should understand the idea behind this algorithm

    • Why do we need to make an extra state p?

  • You should understand how this algorithm can be used to simplify design

  • You should be able to design new algorithms for new closure properties

  • You should understand how this helps prove result that regular languages and LFSA are identical

    • In particular, you should understand how this is used to construct an NFA M from a regular expression r s.t. L(M) = L(r)

    • To be seen later


Module 22
Module 22 unnecessary.

  • Regular languages are a subset of LFSA

    • algorithm for converting any regular expression into an equivalent NFA

    • Builds on existing algorithms described in previous lectures



Reg lang subset lfsa
Reg. Lang. subset LFSA unnecessary.

  • Let L be an arbitrary regular language

  • Let R be the regular expression such that L(R) = L

    • R exists by definition of L is regular

  • Construct an NFA-l M such that L(M) = L

    • M is constructed from regular expression R

  • Argue L(M) = L

  • There exists an NFA-l M such that L(M) = L

  • L is in LFSA

    • By definition of L in LFSA and equivalence of LFSA and LNFA-l


Visualization9

L unnecessary.

L

R

M

Regular

Expressions

NFA-l’s

Visualization

  • Let L be an arbitrary regular language

  • Let R be the regular expression such that L(R) = L

    • R exists by definition of L is regular

  • Construct an NFA-l M such that L(M) = L

    • M is constructed from regular expression R

  • Argue L(M) = L

  • There exists an NFA-l M such that L(M) = L

  • L is in LFSA

    • By definition of L in LFSA and equivalence of LFSA and LNFA-l

Regular

Languages

LFSA


Algorithm specification4

A unnecessary.

Algorithm Specification

  • Input

    • Regular expression R

  • Output

    • NFA M such that L(M) =

NFA-l M

Regular expression R


Recursive algorithm
Recursive Algorithm unnecessary.

  • We have an inductive definition for regular languages and regular expressions

  • Our algorithm for converting any regular expression into an equivalent NFA is recursive in nature

    • Base Case

    • Recursive or inductive Case


Base case
Base Case unnecessary.

  • Regular expression R has zero operators

    • No concatenation, union, Kleene closure

    • For any alphabet S, only |S| + 2 regular languages can be depicted by any regular expression with zero operators

      • The empty language f

      • The language {l}

      • The |S| languages consisting of one string {a} for all a in S


Table lookup
Table lookup unnecessary.

  • Finite number of base cases means we can use table lookup to handle them

f

l

a

b


Recursive case
Recursive Case unnecessary.

  • Regular expression R has at least one operator

    • This means R is built up from smaller regular expressions using the union, Kleene closure, or concatenation operators

    • More specifically, there are 3 cases:

      • R = R1+R2

      • R = R1R2

      • R = R1*


Recursive calls
Recursive Calls unnecessary.

1) R = R1 + R22) R = R1 R23) R = R1*

  • The algorithm recursively calls itself to generate NFA’s M1 and M2 which accept L(R1) and L(R2)

  • The algorithm applies the appropriate construction

    • union

    • concatenation

    • Kleene closure

      to NFA’s M1 and M2 to produce an NFA M such that L(M) = L(R)


Pseudocode algorithm
Pseudocode Algorithm unnecessary.

_____________ RegExptoNFA(_____________) {

regular expression R1, R2;

NFA M1, M2;

Modify R by removing unnecessary enclosing parentheses

/* Base Case */

If R = a, return (NFA for {a}) /* include l here */

If R = f, return (NFA for {})

/* Recursive Case */

Find “last operator O” of regular expression R

Identify regular expressions R1 (and R2 if necessary)

M1 = RegExptoNFA(R1)

M2 = RegExptoNFA(R2) /* if necessary */

return (OP(M1, M2)) /* OP is chosen based on O */

}


Example3
Example unnecessary.

A: R = (b+a)a*

Last operator is concatenation

R1 = (b+a)

R2 = a*

Recursive call with R1 = (b+a)

B: R = (b+a)

Extra parentheses stripped away

Last operator is union

R1 = b

R2 = a

Recursive call with R1 = b


Example continued
Example Continued unnecessary.

C: R = b

Base case

NFA for {b} returned

B: return to this invocation of procedure

Recursive call where R = R2 = a

D: R = a

Base case

NFA for {a} returned

B: return to this invocation of procedure

return UNION(NFA for {b}, NFA for {a})

A: return to this invocation of procedure

Recursive call where R = R2 = a*


Example finished
Example Finished unnecessary.

E: R = a*

Last operator is Kleene closure

R1 = a

Recursive call where R = R1 = a

F: R = a

Base case

NFA for {a} returned

E: return to this invocation of procedure

return (KLEENE(NFA for {a}))

A: return to this invocation of procedure

return CONCAT(NFA for {b,a}, NFA for {a}*)


Pictoral view

(b|a) unnecessary.

a*

b

a

a

a

b

a

l

l

a

l

l

l

b

l

l

a

l

a

l

b

l

Pictoral View

concatenate

(b|a)a*

union

Kleene Closure

a


Parse tree

concatenate unnecessary.

union

Kleene closure

b

a

a

Parse Tree

We now present the “parse” tree for regular expression (b+a)a*


Module 23
Module 23 unnecessary.

  • Regular languages review

    • Several ways to define regular languages

    • Two main types of proofs/algorithms

      • Relative power of two computational models proofs/constructions

      • Closure property proofs/constructions

    • Language class hierarchy

  • Applications of regular languages



Three definitions
Three definitions unnecessary.

  • LFSA

    • A language L is in LFSA iff there exists an FSA M s.t. L(M) = L

  • LNFA

    • A language L is in LNFA iff there exists an NFA M s.t. L(M) = L

  • Regular languages

    • A language L is regular iff there exists a regular expression R s.t. L(R) = L

  • Conclusion

    • All these language classes are equivalent

    • Any language which can be represented using any one of these models can be represented using either of the other two models



Relative power proofs
Relative power proofs unnecessary.

  • These proofs work between two language classes and two computational models

  • The crux of these proofs are algorithms which behave as follows:

    • Input: One program from the first computational model

    • Output: A program from the second computational model that is equivalent in function to the first program


Closure property proofs
Closure property proofs unnecessary.

  • These proofs work within a single language class and typically within a single computational model

  • The crux of these proofs are algorithms which behave as follows:

    • Input: 1 or 2 programs from a given computational model

    • Output: A third program from the same computational model that accepts/describes a third language which is a combination of the languages accepted/described by the two input programs


Comparison2

L unnecessary.

L1

L1 intersect L2

L

LNFA

L2

LFSA

LFSA

M1

M3

M

M2

M’

NFA’s

FSA’s

FSA’s

Comparison


Language class hierarchy

REC unnecessary.

H

?

RE

All languages over alphabet S

H

Language class hierarchy

regular


Three remaining topics
Three remaining topics unnecessary.

  • Myhill-Nerode Theorem

    • Provides technique for proving a language is not regular

    • Also represents fundamental understanding of what a regular language is

  • Decision problems about regular languages

    • Most are solvable in contrast to problems about recursive languages

  • Pumping lemma

    • Provides technique for proving a language is not regular


Module 24
Module 24 unnecessary.

  • Myhill-Nerode Theorem

    • distinguishability

    • equivalence classes of strings

    • designing FSA’s

    • proving a language L is not regular


Distinguishability1
Distinguishability unnecessary.


Distinguishable and indistinguishable
Distinguishable and Indistinguishable unnecessary.

  • String x is distinguishable from string y with respect to language L iff

    • there exists a string z such that

      • xz is in L and yz is not in L OR

      • xz is not in L and yz is in L

  • String x is indistinguishable from string y with respect to language L iff

    • for all strings z,

      • xz and yz are both in L OR

      • xz and yz are both not in L


Example4
Example unnecessary.

  • Let EVEN-ODD be the set of strings over {a,b} with an even number of a’s and an odd number of b’s

    • Is the string aa distinguishable from the string bb with respect to EVEN-ODD?

    • Is the string aa distinguishable from the string ab with respect to EVEN-ODD?



Definition of equivalence classes
Definition of equivalence classes unnecessary.

  • Every language L partitionsS* into equivalence classes via indistinguishability

    • Two strings x and y belong to the same equivalence class defined by L iff x and y are indistinguishable w.r.t L

    • Two strings x and y belong to different equivalence classes defined by L iff x and y are distinguishable w.r.t. L


Example5
Example unnecessary.

How does EVEN-ODD partition {a,b}* into equivalence classes?

Strings with an

EVEN number of a’s

and an

EVEN number of b’s

Strings with an

ODD number of a’s

and an

EVEN number of b’s

Strings with an

EVEN number of a’s

and an

ODD number of b’s

Strings with an

ODD number of a’s

and an

ODD number of b’s


Second example
Second Example unnecessary.

Let 1MOD3 be the set of strings over {a,b} whose length mod 3 = 1.

How does 1MOD3 partition {a,b}* into equivalence classes?

Length mod 3 = 0

Length mod 3 = 1

Length mod 3 = 2


Designing fsa s
Designing FSA’s unnecessary.


Designing an fsa for even odd

l unnecessary.

a

a

b

b

b

ab

a

Even

Even

Odd

Even

Designing an FSA for EVEN-ODD

Even

Odd

Odd

Odd


Designing an fsa for 1mod3

a,b unnecessary.

l

a

aa

a,b

a,b

Length mod 3 = 0

Designing an FSA for 1MOD3

Length mod 3 = 1

Length mod 3 = 2



Third example
Third Example unnecessary.

  • Let EQUAL be the set of strings x over {a,b} s.t. the number of a’s in x = the number of b’s in x

  • How does EQUAL partition {a,b}* into equivalence classes?

  • How many equivalence classes are there?

  • Can we construct a finite state automaton for EQUAL?


Myhill nerode theorem
Myhill-Nerode Theorem unnecessary.


Theorem statement
Theorem Statement unnecessary.

  • Two part statement

    • If L is regular, then L partitions S* into a finite number of equivalence classes

    • If L partitions S* into a finite number of equivalence classes, then L is regular

  • One part statement

    • L is regular iff L partitions S* into a finite number of equivalence classes


Implication 1
Implication 1 unnecessary.

  • Method for constructing FSA’s to accept a language L

    • Identify equivalence classes defined by L

    • Make a state for each equivalence class

    • Identify initial and accepting states

    • Add transitions between the states

      • You can use a canonical element of each equivalence class to help with building the transition function d


Implication 2
Implication 2 unnecessary.

  • Method for proving a language L is not regular

    • Identify equivalence classes defined by L

    • Show there are an infinite number of such equivalence classes

      • Table format may help, but it is only a way to help illustrate that there are an infinite number of equivalence classes defined by L



Proving equal is not regular
Proving EQUAL is not regular unnecessary.

  • Let EQUAL be the set of strings x over {a,b} s.t. the number of a’s in x = the number of b’s in x

  • We want to show that EQUAL partitions {a,b}* into an infinite number of equivalence classes

  • We will use a table that is somewhat reminiscent of the table used for diagonalization

    • Again, you must be able to identify the infinite number of equivalence classes being defined by the table. They ultimately represent the proof that EQUAL or whatever language you are working with is not regular.


Table
Table * unnecessary.

b

IN

OUT

OUT

OUT

OUT

...

bb

OUT

IN

OUT

OUT

OUT

...

bbb

OUT

OUT1

IN

OUT

OUT

...

bbbb

OUT

OUT

OUT

IN

OUT

...

bbbbb

OUT

OUT

OUT

OUT

IN

...

a

aa

aaa

aaaa

aaaaa

...

The strings being distinguished are the rows.

The tables entries indicate that the concatenation of the row

string with the column string is in or not in EQUAL.

Each complete column shows one row string is distinguishable

from all the other row strings.


Concluding equal is nonregular
Concluding EQUAL is nonregular * unnecessary.

  • We have shown that EQUAL partitions {a,b}* into an infinite number of equivalence classes

    • In this case, we only identified some of the equivalence classes defined by EQUAL, but that is sufficient

  • Thus, the Myhill-Nerode Theorem implies that EQUAL is nonregular


Summary1
Summary unnecessary.

  • Myhill-Nerode Theorem and what it says

    • It does not say a language L is regular iff L is finite

      • Many regular languages such as S* are not finite

    • It says that a language L is regular iff L partitions S* into a finite number of equivalence classes

  • Provides method for designing FSA’s

  • Provides method for proving a language L is not regular

    • Show that L partitions S* into an infinite number of equivalence classes


Two three types of problems
Two/Three Types of Problems unnecessary.

  • Create a table that helps prove that a specific language L is not regular

    • You get to choose the “row” and “column” strings

    • I choose the “row” strings

  • Identify the equivalence classes defined by L as highlighted by a given table


Module 25
Module 25 unnecessary.

  • Decision problems about regular languages

    • Basic problems are solvable

      • halting, accepting, and emptiness problems

    • Solvability of other problems

      • answer-preserving input transformations to basic problems


Programs
Programs unnecessary.

  • In this unit, our programs are the following three types of objects

    • FSA’s

    • NFA’s

    • regular expressions

  • Previously, they were C++ programs

    • Review those topics after mastering today’s examples


Basic decision problems and algorithms for solving them
Basic Decision Problems unnecessary.(and algorithms for solving them)


Halting problem
Halting Problem unnecessary.

  • Input

    • FSA M

    • Input string x to M

  • Question

    • Does M halt on x?

  • Give an algorithm for solving the FSA halting problem.


Accepting problem
Accepting Problem unnecessary.

  • Input

    • FSA M

    • Input string x to M

  • Question

    • Is x in L(M)?

  • Give an algorithm ACCEPT for solving the accepting problem.


Empty language problem
Empty Language Problem unnecessary.

  • Input

    • FSA M

  • Question

    • Is L(M)={}?

  • Give an algorithm for solving the empty language problem.

    • Don’t look ahead to the next slide.


Algorithms for solving empty language problem
Algorithms for solving empty language problem unnecessary.

  • Algorithm 1

    • View FSA M as a directed graph (nodes, arcs)

    • See if any accepting node is reachable from the start node

  • Algorithm 2

    • Let n be the number of states in FSA M

    • Run ACCEPT(M,x) for all input strings of length < n

    • If any are accepted THEN no ELSE yes

      • Why is algorithm 2 correct?


Solving other problems using answer preserving input transformations
Solving Other Problems unnecessary.(using answer-preserving input transformations)


Complement empty problem
Complement Empty Problem unnecessary.

  • Input

    • FSA M

  • Question

    • Is (L(M))c = {}?

  • Show how to use an answer-preserving input transformation to help solve this problem

    • Show that the Complement Empty problem transforms to the Empty Language problem

    • Don’t look at next two slides


Algorithm description
Algorithm Description unnecessary.

  • Convert input FSA M into an FSA M’ such that L(M’) = (L(M))c

    • We do this by applying the algorithm which we used to show that LFSA is closed under complement

  • Feed FSA M’ into algorithm which solves the empty language problem

  • If that algorithm returns yes THEN yes ELSE no


Input transformation illustrated

Complement unnecessary.

Construction

FSA M’

Input Transformation Illustrated

Algorithm for

solving empty

language problem

FSA M

Yes/No

Algorithm for complement empty problem

The complement construction algorithm is the answer-pres. input transformation.

If M is a yes input instance of CE, then M’ is a yes input instance of EL.

If M is a no input instance of CE, then M’ is a no input instance of EL.


Nfa empty problem
NFA Empty Problem unnecessary.

  • Input

    • NFA M

  • Question

    • Is L(M)={}?

  • Show how to use answer-preserving input transformations to help solve this problem

    • Show that the NFA Empty problem transforms to the Empty Language problem


Input transformation
Input Transformation unnecessary.

Yes/No

Algorithm for NFA empty problem


Equal problem
Equal Problem unnecessary.

  • Input

    • FSA’s M1 and M2

  • Question

    • Is L(M1) = L(M2)?

  • Show how to use answer-preserving input transformations to solve this problem

    • Try and transform this problem to the empty language problem

    • If L(M1) = L(M2), then what combination of L(M1) and L(M2) must be empty?


Input transformation illustrated1
Input Transformation Illustrated unnecessary.

Yes/No

Algorithm for Equal problem


Summary2
Summary unnecessary.

  • Decision problems with programs as inputs

  • Basic problems

    • You need to develop algorithms from scratch based on properties of FSA’s

  • Solving new problems

    • You need to figure out how to combine the various algorithms we have seen in this unit to solve the given problem


Module 26
Module 26 unnecessary.

  • Pumping Lemma

    • A technique for proving a language L is NOT regular

    • What does the Pumping Lemma mean?

    • Proof of Pumping Lemma


Pumping lemma

Pumping Lemma unnecessary.

How do we use it?


Pumping condition
Pumping Condition unnecessary.

  • A language L satisfies the pumping condition if:

    • there exists an integer n > 0 such that

    • for all strings x in L of length at least n

    • there exist strings u, v, w such that

      • x = uvw and

      • |uv| <= n and

      • |v| >= 1 and

      • For all k >= 0, uvkw is in L


Pumping lemma1

“Pumping Languages” unnecessary.

All languages over {a,b}

Pumping Lemma

  • All regular languages satisfy the pumping condition

Regular languages


Implications

Pumping unnecessary.

Implications

Regular

  • We can use the pumping lemma to prove a language L is not regular

    • How?

  • We cannot use the pumping lemma to prove a language is regular

    • How might we try to use the pumping lemma to prove that a language L is regular and why does it fail?


Pumping lemma2

Pumping Lemma unnecessary.

What does it mean?


Pumping condition1
Pumping Condition unnecessary.

  • A language L satisfies the pumping condition if:

    • there exists an integer n > 0 such that

    • for all strings x in L of length at least n

    • there exist strings u, v, w such that

      • x = uvw and

      • |uv| <= n and

      • |v| >= 1 and

      • For all k >= 0, uvkw is in L


V can be pumped
v can be pumped unnecessary.

1) x in L2) x = uvw3) For all k >= 0, uvkw is in L

  • Let x = abcdefg be in L

  • Then there exists a substring v in x such that v can be repeated (pumped) in place any number of times and the resulting string is still in L

    • uvkw is in L for all k >= 0

  • For example

    • v = cde

      • uv0w = uw =abfg is in L

      • uv1w = uvw = abcdefgis in L

      • uv2w = uvvw = abcdecdefgis in L

      • uv3w = uvvvw = abcdecdecdefg is in L


What the other parts mean
What the other parts mean unnecessary.

  • A language L satisfies the pumping condition if:

    • there exists an integer n > 0 such that

      • defer what n is till later

    • for all strings x in L of length at least n

      • x must be in L and have sufficient length

    • there exist strings u, v, w such that

      • x = uvw and

      • |uv| <= n and

        • v occurs in the first n characters of x

      • |v| >= 1 and

        • v is not l

      • For all k >= 0, uvkw is in L


Examples2
Examples unnecessary.

  • Example 1

    • Let L be the set of even length strings over {a,b}

    • Let x = abaa

    • Let n = 2

    • What are the possibilities for v?

      • abaa, abaa

      • abaa

    • Which one satisfies the pumping lemma?


Examples3
Examples * unnecessary.

  • Example 2

    • Let L be the set of strings over {a,b} where the number of a’s mod 3 is 1

    • Let x = abbaaa

    • Let n = 3

    • What are the possibilities for v?

      • abbaaa, abbaaa, abbaaa

      • abbaaa, abbaaa

      • abbaaa

    • Which ones satisfy the pumping lemma?


Pumping lemma3

Pumping Lemma unnecessary.

Proof


High level outline
High Level Outline unnecessary.

  • Let L be an arbitrary regular language

  • Let M be an FSA such that L(M) = L

    • M exists by definition of LFSA and the fact that regular languages and LFSA are identical

  • Show that L satisfies the pumping condition

    • Use M in this part

  • Pumping Lemma follows


First step n 1 prefixes of x
First step: n+1 prefixes of x unnecessary.

  • Let n be the number of states in M

  • Let x be an arbitrary string in L of length at least n

    • Let xi denote the ith character of string x

  • There are at least n+1 distinct prefixes of x

    • length 0: l

    • length 1: x1

    • length 2: x1x2

    • ...

    • length i: x1x2 … xi

    • ...

    • length n: x1x2 … xi … xn


Example6
Example unnecessary.

  • Let n = 8

  • Let x = abcdefgh

  • There are 9 distinct prefixes of x

    • length 0: l

    • length 1: a

    • length 2: ab

    • ...

    • length 8: abcdefgh


Second step pigeon hole principle
Second step: Pigeon-hole Principle unnecessary.

  • As M processes string x, it processes each prefix of x

    • In particular, each prefix of x must end up in some state of M

  • Situation

    • There are n+1 distinct prefixes of x

    • There are only n states in M

  • Conclusion

    • At least two prefixes of x must end up in the same state of M

      • Pigeon-hole principle

    • Name these two prefixes p1 and p2


Third step forming u v w
Third step: Forming u, v, w unnecessary.

  • Setting:

    • Prefix p1 has length i

    • Prefix p2 has length j > i

      • prefix p1 of length i: x1x2 … xi

      • prefix p2 of length j: x1x2 … xi xi+1 … xj

  • Forming u, v, w

    • Set u = p1 = x1x2 … xi

    • Set v = xi+1… xj

    • Set w = xj+1 … x|x|

    • x1x2 … xixi+1… xj xj+1 … x|x|

      u v w


Example 13
Example 1 unnecessary.

0

1

2

3

4

  • Let M be a 5-state FSA that accepts all strings over {a,b,c,…,z} whose length mod 5 = 3

  • Consider x = abcdefghijklmnopqr, a string in L

  • What are the two prefixes p1 and p2?

  • What are u, v, w?


Example 24

0 unnecessary.

1

Example 2

1

0

0

1

2

  • Let M be a 3-state FSA that accepts all strings over {0,1} whose binary value mod 3 = 1

  • Consider x = 10011, a string in L

  • What are the two prefixes p1 and p2?

  • What are u, v, w?


Fourth step showing u v w satisfy all the conditions
Fourth step: Showing u, v, w satisfy all the conditions unnecessary.

  • |uv| <= n

    • uv = p2

    • p2 is one of the first n+1 prefixes of string x

  • |v| >= 1

    • v consists of the characters in p2 after p1

    • Since p2 and p1 are distinct prefixes of x, v is not l

  • For all k >= 0, uvkw in L

    • u=p1 and uv=p2 end up in the same state q of M

      • This is how we defined p1 and p2

    • Thus for all k >= 0, uvk ends up in state q

    • The string w causes M to go from state q to an accepting state


Example 1 again
Example 1 again unnecessary.

0

1

2

3

4

  • Let M be a 5-state FSA that accepts all strings over {a,b,c,…,z} whose length mod 5 = 3

  • Consider x = abcdefghijklmnopqr, a string in L

  • What are u, v, w?

    • u = l

    • v = abcde

    • w = fghijklmnopqr

  • |uv| = 5 <= 5

  • |v| = 5 >= 1

  • For all t>=0, (abcde)tfghijklmnopqr is in L


Example 2 again

0 unnecessary.

1

Example 2 again

1

0

0

1

2

  • Let M be a 3-state FSA that accepts all strings over {0,1} whose binary interpretation mod 3 = 1

  • Consider x = 10011, a string in L

  • What are u, v, w?

    • u = 1

    • v = 00

    • w = 11

  • |uv| = 3 <= 3

  • |v| = 2 >= 1

  • For all k>=0, 1(00)k11 is in L


Pumping lemma4
Pumping Lemma unnecessary.

  • A language L satisfies the pumping condition if:

    • there exists an integer n > 0 such that

    • for all strings x in L of length at least n

    • there exist strings u, v, w such that

      • x = uvw and

      • |uv| <= n and

      • |v| >= 1 and

      • For all k >= 0, uvkw is in L

  • Pumping Lemma: All regular languages satisfy the pumping condition


Module 27
Module 27 unnecessary.

  • Applications of Pumping Lemma

    • General proof template

      • What is the same in every proof

      • What changes in every proof

    • Incorrect pumping lemma proofs

    • Some rules of thumb


Pumping lemma5

Pumping Lemma unnecessary.

Applying it to prove a specific language L is not regular


How we use the pumping lemma
How we use the Pumping Lemma unnecessary.

  • We choose a specific language L

    • For example, {ajbj | j > 0}

  • We show that L does not satisfy the pumping condition

  • We conclude that L is not regular


Showing l does not pump

A language L unnecessary.satisfies the pumping condition if:

there exists an integer n > 0 such that

for all strings x in L of length at least n

there exist strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1 and

For all k >= 0, uvkw is in L

A language L does not satisfy the pumping condition if:

for all integers n of sufficient size

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Showing L “does not pump”


Example proof

A language L unnecessary.does not satisfy the pumping condition if:

for all integers n of sufficient size

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Proof that L = {aibi | i>0} does not satisfy the pumping condition

Let n be the integer from the pumping lemma

Choose x = anbn

Consider all strings u, v, w s.t.

x = uvw and

|uv| <= n and

|v| >= 1

Argue that uvkw is not in L for some k >= 0

Argument must apply to all possible u,v,w

Continued on next slide

Example Proof


Example proof continued

Proof that L = {a unnecessary.ibi | i>0} does not satisfy the pumping condition

Let n be the integer from the pumping lemma

Choose x = anbn

Consider all strings u, v, w s.t.

x = uvw and

|uv| <= n and

|v| >= 1

Argue that uvkw is not in L for some k >= 0

Argument must apply to all possible u,v,w

Continued on right

uv0w = uw is not in L

uv contains only a’s

why?

uw = an-|v|bn

Follows from previous line and uvw = x = anbn

uw contains fewer a’s than b’s

why?

Therefore, uw is not in L

Therefore L does not satisfy the pumping condition

Example Proof Continued


Alternate choice of k

Proof that L = {a unnecessary.ibi | i>0} does not satisfy the pumping condition

Let n be the integer from the pumping lemma

Choose x = anbn

Consider all strings u, v, w s.t.

x = uvw and

|uv| <= n and

|v| >= 1

Argue that uvkw is not in L for some k >= 0

Argument must apply to all possible u,v,w

Continued on right

uv2w = uvvw is not in L

uv contains only a’s

why?

uvvw = an+|v|bn

follows from previous line and uvw = x = anbn

uvvw contains more a’s than b’s

why?

Therefore, uvvw is not in L

Therefore L does not satisfy the pumping condition

Alternate choice of k


Pumping lemma6

Pumping Lemma unnecessary.

Some bad applications of the pumping lemma


Bad pumping lemma applications
Bad Pumping Lemma Applications unnecessary.

  • We now look at some examples of bad applications of the pumping lemma

  • We work with the language EQUAL consisting of the set of strings over {a,b} such that the number of a’s equals the number of b’s

  • We focus first on bad choices of string x

  • We then consider another flawed technique


First bad choice of x

A language L unnecessary.does not satisfy the pumping condition if:

Let n be the integer from the pumping lemma

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Let n be the integer from the pumping lemma

Choose x = a10b10

What is wrong with this choice of x?

First bad choice of x


Second bad choice of x

A language L unnecessary.does not satisfy the pumping condition if:

Let n be the integer from the pumping lemma

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Let n be the integer from the pumping lemma

Choose x = anb2n

What is wrong with this choice of x?

Second bad choice of x


Third bad choice of x

A language L unnecessary.does not satisfy the pumping condition if:

Let n be the integer from the pumping lemma

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Let n be the integer from the pumping lemma

Choose x = (ab)n

What is wrong with this choice of x?

The problem is there is a choice of u, v, w satisfying the three conditions such that for all k >=0, uvkw is in L

What is an example of such a u, v, w?

Third bad choice of x


Find the flaw in this proof

A language L unnecessary.does not satisfy the pumping condition if:

Let n be the integer from the pumping lemma

there exists a string x in L of length at least n such that

for all strings u, v, w such that

x = uvw and

|uv| <= n and

|v| >= 1

There exists a k >= 0 such that uvkw is not in L

Let n be the integer from the pumping lemma

Choose x = anbn

Let u = a2, v =a, w = an-3bn

|uv| = 3 <= n

|v| = 1

Choose k = 2

Argue uv2w is not in EQUAL

uv2w = uvvw = a2aaan-3bn = an+1bn

There is one more a than b in uv2w

Thus uv2w is not in L

Find the flaw in this proof


Pumping lemma7

Pumping Lemma unnecessary.

Two rules of thumb


Two rules of thumb
Two Rules of Thumb * unnecessary.

  • Try to make the first n characters of x identical

    • For EQUAL, choose x = anbn rather than (ab)n

      • Simplifies case analysis as v only contains a’s

  • Try k=0 or k=2

    • k=0

      • This reduces number of occurrences of that first character

    • k=2

      • This increases number of occurrences of that first character


Summary3
Summary unnecessary.

  • We use the Pumping Lemma to prove a language is not regular

    • Note, does not work for all nonregular languages, though

  • Choosing a good string x is first key step

  • Choosing a good integer k is second key step

  • Must apply argument to all legal u, v, w


ad