Non-Context-Free Languages - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Non-Context-Free Languages

Description:

... Languages except that it is based on a grammar rather than a ... So one of them ... {ww | w *} is not context-free. Use s = ww, where w = ap 1b. ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 31
Provided by: robbko
Category:
Tags: context | free | languages | non | use

less

Transcript and Presenter's Notes

Title: Non-Context-Free Languages


1
Non-Context-Free Languages
  • Lecture 10
  • Section 2.3
  • Fri, Oct 13, 2006

2
Non-Context-Free Languages
  • It turns out that not all languages are
    context-free.
  • An example of a non-context-free language is
  • anbncn n ? 0.
  • To process this would require two stacks.

3
The Pumping Lemma
  • The Pumping Lemma for Context-Free Languages If
    L is a context-free language then there exists an
    integer p such that if any string s in L has
    length at least p, then s may be divided into
    five substrings uvxyz such that

4
The Pumping Lemma
  • vy gt 0,
  • vxy ? p,
  • uvixyiz is in L for all i ? 0.

5
The Proof
  • The proof is somewhat similar to the proof of the
    Pumping Lemma for Regular Languages except that
    it is based on a grammar rather than a machine.

6
An Example
  • But first, an example.
  • Let L anbncn n ? 0.
  • We will show that L is not context-free.

7
An Example
  • Proof
  • Suppose it is.
  • Then let p be the p of the Pumping Lemma.
  • Let s apbpcp.
  • Then s uvxyz such that vy gt 0, vxy ? p, and
    uvixyiz is in L.
  • We will show that this is not possible.

8
An Example
  • vxy is the middle part of uvxyz and it has
    length at most p.
  • Therefore, it consists of
  • All as,
  • Some as followed by some bs,
  • All bs,
  • Some bs followed by some cs, or
  • All cs.

9
An Example
  • It is enough to consider the first two cases.
  • The other three are similar.
  • Case 1 Suppose vxy consists of all as.
  • Then v ak and y am for some k, m, not both 0.

10
An Example
  • So uv2xy2z ap k mbpcp, which is not in L.
  • This is a contradiction.
  • Case 2 vxy consists of some as and some bs.
  • There are three possibilities
  • v is all as and y is all bs,
  • v is all as and y is some as, some bs,
  • v is some as, some bs and y is all as.

11
An Example
  • It doesnt really matter because both v and y get
    pumped up.
  • Let k be the number of as and m be the number of
    bs in vy.
  • m and k are not both 0.
  • So uv2xy2z ap kbp mcp, which is not in L.
  • This is a contradiction.

12
An Example
  • Therefore, L is not context-free.

13
Proof of the Pumping Lemma
  • Proof

14
The Idea Behind the Proof
  • If a CFL contains a word w with a sufficiently
    long derivation
  • S ? w,
  • then some variable A must appear more than once.
  • That is, we have
  • S ? uAz ? uvAyz ? uvxyz.

15
The Idea Behind the Proof
  • Thus, A ? vAy and A ? x.
  • We may repeat the derivation
  • A ? vAy
  • as many times as we like (including zero times),
    producing strings uvnxynz, for any n ? 0.

16
The Proof
  • Proof
  • Let b be the largest number of symbols on the
    right-hand side of any grammar rule.
  • (Assume b ? 2.)
  • Let h be the height of the derivation tree of a
    string s.
  • Then s can contain at most bh symbols.

17
The Proof
  • Conversely, if s contains more than bh symbols,
    then the height of the parse tree must be more h.

18
The Proof
  • Now V is the number of variables in the grammar
    of L.
  • So if a string in L has a length greater than
    bV 1, then the height of its parse tree must
    be more than V 1.
  • So let p bV 1 and suppose that a string s
    in L has length at least p.

19
The Proof
  • Consider the longest path through the tree.
  • It has length at least V 1.
  • That path has V 2 nodes on it, counting the
    root node S and the leaf node, which is a
    terminal.

20
The Proof
  • Thus, V 1 of the nodes are variables.
  • So one of them must be repeated.
  • As we follow the longest path from leaf to root,
    let A be the first variable that repeats.
  • Now consider these two occurrences of A along the
    longest path.

21
The Proof
22
The Proof
  • The middle part of this tree, the part that
    produces
  • A ? vAy,
  • may be repeated as many times as desired.

23
The Proof
24
The Proof
25
The Proof
S
A
z
u
A
y
v
A
y
v
A
y
v
x
26
The Proof
  • Therefore, the strings uv2xy2z, uv3xy3z, etc. can
    also be derived.
  • So can the string uxz.

27
The Proof
  • Furthermore, we may assume that this was the
    shortest derivation of s.
  • It follows that v and y cannot both be empty
    strings.

28
The Proof
  • If they were, then the middle part of the
    derivation would be
  • A ? A,
  • which could be eliminated.
  • Thus, vy gt 0.

29
The Proof
  • Finally, we must show that vxy ? p.
  • The subtree rooted at the second-to-last A has
    height at most V 1.
  • So the string vxy has at most
  • bV 1 p symbols.

30
An Example
  • Let ? a, b.
  • Show that the language
  • ww w ??
  • is not context-free.
  • Use s ww, where w ap 1b.
Write a Comment
User Comments (0)
About PowerShow.com