# INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.

## Presentation on theme: "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."— Presentation transcript:

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011

THE PUMPING LEMMA Let L be a regular language with |L| =  Then there exists a length P such that 1. |y| > 0 2. |xy| ≤ P 3. xy i z  L for any i ≥ 0 ∀ w  L, if |w| ≥ P then there exist xyz = w where:

PUMPING DOWN C = { 0 i 1 j | i > j ≥ 0} Assume … pumping length P Find a w ∈ C longer than P Show that … w cannot be pumped: If w = xyz with |xy| ≤ P then y = 0 J for some J ≥ 1. Then xy 0 z = xz = 0 P+1-J 1 P  C 0 P+1 1 P 00…0011…11 P+1 P w= y xyyz = 00…00011…11 > P+1 P xz = 0…0011…11 ≤ P P

CHOOSING WISELY Let BALANCED = { w | w has an equal # of 1s and 0s } Assume … there is a P Find a w ∈ BALANCED longer than P (01) P Show that w cannot be pumped: If w = xyz with |xy| ≤ P then y = 0 J for some J>0. Then xyyz = 0 P+J 1 P  BALANCED 0P1P0P1P

REUSING A PROOF Pumping a language can be lots of work… Let’s try to reuse that work! {0 n 1 n : n ≥ 0} = BALANCED ∩ 0*1* If BALANCED is regular then so is {0 n 1 n : n ≥ 0}

USING CLOSURE A C B ∩ = (Not regular) Prove: A is not regular or any of {¬, ∪, ∩, ･, R, *} If A is regular, then A ∩ C (= B) is regular. (regular) But B is not regular so neither is A.

Prove A = {0 i 1 j : i  j} is not regular using B = {0 n 1 n : n ≥ 0} B ∪ { strings that mix 0s and 1s } B = ¬A ∩ 0*1* ¬A =

PUMPING NON-REGULAR LANGUAGES Let F = {a i b j c k | i, j, k ≥ 0 and i=1 ⇒ j=k} F has pumping length 2! F ∩ ab*c* = {ab n c n | n ≥ 0} i = 0 i = 1 i = 2 A non-regular language may still satisfy the pumping lemma.

4011 SO FAR… MODEL OF A PROGRAM: DFA MODEL OF A PROBLEM: LANGUAGE EQUIVALENT MODELS: NFA, REGEXP PROBLEMS THAT A DFA CAN’T SOLVE ARE WE DONE?

Σ = {0, 1}, L = { 0 n 1 n | n ≥ 0 } Σ = {a, b, c, …, z}, L = { w | w = w R } Σ = { (, ) }, L = { balanced strings of parens } NONE OF THESE ARE REGULAR We can write a SCHEME or JAVA program for any of them!

PUSHDOWN AUTOMATA FINITE STATE CONTROL STACK (Last in, first out) INPUT

ε,ε → \$ 0,ε → 0 1,0 → ε ε,\$ → ε stringpoppush 0011 STACK\$ 0011011 \$0 11 \$ 0 1

ε,ε → \$ 0,ε → 0 1,0 → ε ε,\$ → ε stringpoppush 001 STACK\$\$0\$ 0 1 01001 PDA to recognize L = { 0 n 1 n | n ≥ 0 }

Definition: A (non-deterministic) PDA is a tuple P = (Q, Σ, Γ, , q 0, F), where: Q is a finite set of states Γ is the stack alphabet q 0  Q is the start state F  Q is the set of accept states Σ is the input alphabet  : Q  Σ ε  Γ ε → (Q  Γ ε ) (Q) is the set of subsets of Q and Σ ε = Σ  {ε}

ε,ε → \$ 0,ε → 0 1,0 → ε ε,\$ → ε q0q0 q1q1 q2q2 q3q3 Q = {q 0, q 1, q 2, q 3 }Γ =Σ =  : Q  Σ ε  Γ ε → (Q  Γ ε ) {0,1}{\$,0,1}  (q 1,1,0) = { (q 2,ε) }  (q 2,1,1) = 

EVEN-LENGTH PALINDROMES Σ = {a, b, c, …, z} ε,ε → \$ ε,ε → εε,ε → ε , → ε, → ε ε,\$ → ε q0q0 q1q1 q2q2 q3q3 ,ε → ,ε → 

Build a PDA to recognize L = { a i b j c k | i, j, k ≥ 0 and (i = j or i = k) } ε,ε → \$ b,a → ε ε,\$ → ε q0q0 q5q5 q1q1 q3q3 a,ε → a q2q2 q4q4 ε,ε → ε q6q6 ε,\$ → ε b,ε → ε c,a → ε c,ε → ε

Build a PDA to recognize… L = { x0y | |x| = |y| }

A → 0A1 A → B B → # CONTEXT-FREE GRAMMARS A variables terminals production rules start variable  0A1  00A11  00B11  00#11

→ → LIKE → UMM → YOU KNOW → GAG ME WITH A SPOON → ε → AS IF → WHATEVER VALLEY GIRL GRAMMAR → LOSER

→ | → LIKE | UMM → YOU KNOW | ε → GAG ME WITH A SPOON | AS IF | WHATEVER | LOSER VALLEY GIRL GRAMMAR

CONTEXT-FREE GRAMMARS A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where: V is a finite set of variables R is set of production rules of the form A → W, where A  V and W  (V  Σ)* S  V is the start variable Σ is a finite set of terminals (disjoint from V) G = { {S}, {0,1}, R, S }R = { S → 0S1, S → ε } L(G) = { 0 n 1 n | n ≥ 0 }

A → 0A1 A → B B → # CONTEXT-FREE GRAMMARS A variables terminals production rules start variable  0A1  00A11  00B11  00#11 uVw yields uvw if (V → v) ∈ R. A derives 00#11 in 4 steps.

WRITE A CFG FOR EVEN-LENGTH PALINDROMES S →  S  for all   Σ S → ε

WRITE A CFG FOR THE EMPTY SET G = { {S}, Σ, , S }

GIVE A CFG FOR… L 3 = { strings of balanced parens } L 4 = { a i b j c k | i, j, k ≥ 0 and (i = j or j = k) }

VERY INTERESTING CFGs… http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html http://unununium.org/darcs/stackless-python/Grammar/Grammar

Download ppt "INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011."

Similar presentations