SlideShare ist ein Scribd-Unternehmen logo
1 von 84
Properties
     of
Context-Free
 languages
Union

             Context-free languages
             are closed under:   Union


L1   is context free
                                 L1   L2
L2   is context free           is context-free
Example
 Language                      Grammar

      n n
 L1 {a b }                S1      aS1b |

            R
 L2 {ww }            S2        aS2a | bS2b |

                 Union

    n n          R         S       S1 | S2
L {a b } {ww }
In general:
   For context-free languages          L1,    L2
   with context-free grammars          G1,    G2
   and start variables                 S1,    S2
   It is assumed that variable sets of G1 and G2 are
   disjoint

  The grammar of the union        L1     L2
  has new start variable          S
  and additional production       S      S1 | S2
Concatenation

      Context-free languages
      are closed under:      Concatenation



L1   is context free
                                    L1L2
L2   is context free            is context-free
Example
Language                         Grammar

     n n
L1 {a b }                   S1       aS1b |

           R
L2 {ww }               S2        aS2a | bS2b |

               Concatenation

    n n           R              S     S1S2
L {a b }{ww }
In general:

   For context-free languages   L1,   L2
   with context-free grammars   G1,   G2
   and start variables          S1,   S2


   The grammar of the concatenation L1L2
   has new start variable    S
   and additional production S    S1S2
Star Operation



    Context-free languages
    are closed under:      Star-operation




L is context free         *
                         L is context-free
Example

 Language               Grammar

     n n
L {a b }               S    aSb |


        Star Operation

     n n
L {a b } *             S1   SS1 |
In general:

   For context-free language   L
   with context-free grammar   G
   and start variable
                               S


   The grammar of the star operation L *
   has new start variable    S1
   and additional production S1   SS1 |
Negative Properties
        of
  Context-Free
   Languages
Intersection


       Context-free languages
       are not closed under:  intersection

L1   is context free
                                 L1    L2
L2   is context free           not necessarily
                               context-free
Example
       n n m                       n m m
L1 {a b c }                L2 {a b c }
 Context-free:               Context-free:
 S    AC                     S    AB
 A    aAb |                  A    aA |
 C    cC |                   B    bBc |
              Intersection
              n n n
L1   L2 {a b c } NOT context-free
Complement


     Context-free languages
     are not closed under:  complement



L is context free      L   not necessarily
                           context-free
Example
      n n m                          n m m
L1 {a b c }                 L2 {a b c }
Context-free:                 Context-free:
S    AC                       S      AB
A    aAb |                    A      aA |
C    cC |                     B      bBc |
                 Complement
                                  n n n
    L1      L2    L1   L2 {a b c }
            NOT context-free
Context-free
    languages
       and
Regular Languages
The intersection of
           a context-free language and
           a regular language
 is a context-free language



L1   context free
                             L1   L2
L2   regular               context-free
Machine   M1            Machine     M2
NPDA for   L1          DFA for      L2
 context-free             regular


    Construct a new NPDA machine   M
    that accepts L1 L2


M simulates in parallel M1 and M 2
NPDA    M1                     DFA       M2
      a, b   c                            a
q1                q2           p1                  p2
     transition                     transition



                   NPDA    M

             q1, p1 a, b   c
                                q2 , p2
                   transition
NPDA      M1                    DFA    M2

     q0                               p0
initial state                   initial state



                NPDA        M

                  q0 , p0
                Initial state
Therefore:   L ( M1 )    L( M 2 )   is context-free

                      (since   M is NPDA)




                 L1     L2     is context-free
The Pumping Lemma
        for
    Context-Free
     Languages
Take an infinite context-free language


       Generates an infinite number
       of different strings



Example:        S     AB
                A     aBb
                B     Sb
                B     b
S    AB
                 A    aBb
                 B    Sb
                 B    b

A derivation:             Variables are repeated

  S     AB aBbB abbB
      abbSb abbABb abbaBbBb
      abbabbBb       abbabbbb
Derivation tree                   string   abbabbbb
                      S

        A                                  B

 a      B    b                        S        b

        b                     A            B

                  a       B       b        b

                          b
Derivation tree                   string   abbabbbb
                      S

        A                                  B

 a      B    b                        S        b

        b                     A            B

                  a       B       b        b

 repeated                 b
B       Sb   ABb                    B

    aBbBb        aBbbb          S       b

                        A           B

             a      B       b       b

                    b
    B    b
Repeated Part                     B

                              S       b

                      A           B

          a       B       b       b



              B          aBbbb
Another possible derivation                       B

                                              S       b

                                      A           B
 B         aBbbb        a       B        b       b

                             S            b

                     A            B

            a    B       b        b



B          aBbbb               aaBbbbbbb
S

    A                           B

a   B   b                   S       b

    b               A           B
                                    B      aBbbb
            a       B   b       b




        S                  abbaBbbb
S

        A                                       B

    a   B           b                       S       b

        b                           A           B
                                                    B          aBbbb
                        a           B   b       b

                            S           b

                A                   B

    a       B       b               b




S                  abbaBbbb                           abbaaBbbbbbb
S

        A                                       B

    a   B       b                           S       b

        b                           A           B

                    a           B       b       b

                        S               b

            A                   B

    a   B       b               b                   B     b
        b

S              abbaaBbbbbbb                            abbaabbbbbbb
S         abbaabbbbbbb

Therefore, the string


           abbaabbbbbbb

is also generated by the grammar
We know:       B      b
               B          aBbbb
               S          abbaBbbb
We also know this string is generated:


           S             abbaBbbb
                   abbaabbbb
We know:       B      b
               B         aBbbb
               S         abbaBbbb
Therefore, this string is also generated:


           S         abbaBbbb
                   abbaaBbbbbbb
                   abbaabbbbbbb
We know:       B   b
               B          aBbbb
           S              abbaBbbb
Therefore, this string is also generated:
           S          abbaBbbb
               abba(a ) B(bbb)bbb
                       2       2
               abba(a ) B(bbb) bbb
                       2       2
               abba(a ) b(bbb) bbb
We know:    B       b
            B              aBbbb
           S               abbaBbbb
Therefore, this string is also generated:
           S           abbaBbbb
                
                        i       i
                abba(a ) B(bbb) bbb
                        i       i
                abba(a ) b(bbb) bbb
Therefore, knowing that

               abbabbbb

is generated by grammar   G,
we also know that

                   i      i
         abba(a) b(bbb) bbb

 is generated by   G
In general:

      We are given an infinite
      context-free grammar G




     Assume   G has no unit-productions
                    no     -productions
Take a string w L (G )
with length bigger than


m   > (Number of productions) x
      (Largest right side of a production)


Consequence:
     Some variable must be repeated
     in the derivation of w
u , v, x, y, z : strings of terminals
String   w uvxyz             S


                 u                        z
   Last repeated variable    A

                 v                        y
                     repeated A


                             x
S
Possible
derivations:   u       z
                   A
S    uAz
               v       y
A   vAy            A

A    x
                   x
We know:

   S    uAz          A    vAy       A   x

This string is also generated:

                          *
               S    uAz       uxz


                     0    0
                   uv xy z
We know:

   S    uAz             A    vAy            A   x

This string is also generated:

                    *           *
         S    uAz       uvAyz       uvxyz

                                    1   1
           The original     w uv xy z
We know:

      S    uAz              A    vAy           A   x

This string is also generated:

                *           *             *
  S       uAz       uvAyz       uvvAyyz       uvvxyyz


                            2    2
                       uv xy z
We know:

   S       uAz         A    vAy           A   x

This string is also generated:
                           *              *
       S    uAz    uvAyz        uvvAyyz
       *               *
           uvvvAyyyz       uvvvxyyyz
                       3    3
                  uv xy z
We know:

   S    uAz          A       vAy   A   x
This string is also generated:
       S * uAz * uvAyz * uvvAyyz *
       * uvvvAyyyz * 
       * uvvvvAy  yyyz *
       * uvvvvxy  yyyz
                     i   i
                   uv xy z
Therefore, any string of the form


                  i   i
               uv xy z         i 0

is generated by the grammar   G
Therefore,



 knowing that   uvxyz       L(G)



                        i   i
 we also know that   uv xy z       L(G )
S


           u                 z
                     A

           v                 y
                     A


                     x
Observation:   | vxy |   m
Since   A is the last repeated variable
S


            u                z
                     A

            v                y
                     A


                     x
Observation:    | vy |   1
Since there are no unit or   productions
The Pumping Lemma:
  For infinite context-free language    L
   there exists an integer   m such that
   for any string    w L,      | w| m
   we can write     w uvxyz
   with lengths     | vxy | m and | vy | 1
   and it must be:
            i i
          uv xy z     L,     for all i 0
Applications
     of
The Pumping
  Lemma
Non-context free languages
       n n n
    {a b c : n 0}


          Context-free languages

                 n n
               {a b : n 0}
Theorem: The language
                  n n n
            L {a b c : n 0}
          is not context free




Proof:   Use the Pumping Lemma
         for context-free languages
n n n
           L {a b c : n 0}

Assume for contradiction that   L
is context-free




Since L is context-free and infinite
we can apply the pumping lemma
n n n
             L {a b c : n 0}
Pumping Lemma gives a magic number   m
such that:


  Pick any string   w L with length | w | m


                    m m m
  We pick:   w a b c
n n n
        L {a b c : n 0}


                      m m m
                w a b c


We can write:    w uvxyz



with lengths    | vxy | m   and   | vy | 1
n n n
           L {a b c : n 0}
       m m m
  w a b c
  w uvxyz          | vxy | m      | vy | 1




Pumping Lemma says:

       i   i
     uv xy z   L      for all   i 0
n n n
           L {a b c : n 0}
        m m m
  w a b c
  w uvxyz          | vxy | m      | vy | 1




We examine all the possible locations
of string vxy in w
n n n
            L {a b c : n 0}
          m m m
  w a b c
  w uvxyz         | vxy | m       | vy | 1

                              m
Case 1:    vxy is within a

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
     u vxy                z
n n n
          L {a b c : n 0}
       m m m
  w a b c
  w uvxyz         | vxy | m     | vy | 1

Case 1: v and y consist from only a

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
      u vxy             z
n n n
            L {a b c : n 0}
       m m m
  w a b c
  w uvxyz         | vxy | m   | vy | 1

Case 1: Repeating v and y
      k 1
     m k             m        m
 aaaaaa...aaaaaa bbb...bbb ccc...ccc
  u     2     2           z
       v xy
n n n
             L {a b c : n 0}
        m m m
  w a b c
  w uvxyz         | vxy | m    | vy | 1

                               2   2
Case 1: From Pumping Lemma: uv xy z       L
       k 1
      m k             m        m
  aaaaaa...aaaaaa bbb...bbb ccc...ccc
  u      2    2           z
       v xy
n n n
            L {a b c : n 0}
       m m m
  w a b c
  w uvxyz          | vxy | m        | vy | 1

                                    2    2
Case 1: From Pumping Lemma: uv xy z              L
       k 1
               2    2          m k m m
 However:    uv xy z       a     b c         L
            Contradiction!!!
n n n
            L {a b c : n 0}
          m m m
  w a b c
  w uvxyz         | vxy | m       | vy | 1

                              m
Case 2:    vxy is within b

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
            u      vxy        z
n n n
           L {a b c : n 0}
        m m m
   w a b c
   w uvxyz         | vxy | m       | vy | 1

Case 2: Similar analysis with case 1


         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
            u       vxy        z
n n n
            L {a b c : n 0}
          m m m
  w a b c
  w uvxyz         | vxy | m       | vy | 1

                              m
Case 3:    vxy is within c

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
               u           vxy z
n n n
           L {a b c : n 0}
        m m m
   w a b c
   w uvxyz          | vxy | m       | vy | 1

Case 3: Similar analysis with case 1


         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
                u               vxy z
n n n
            L {a b c : n 0}
          m m m
  w a b c
  w uvxyz         | vxy | m       | vy | 1

                            m             m
Case 4:    vxy overlaps a       and   b

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
      u     vxy           z
n n n
            L {a b c : n 0}
         m m m
   w a b c
   w uvxyz         | vxy | m     | vy | 1

Case 4: Possibility 1: v contains only a
                      y contains only b
         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
       u     vxy           z
n n n
            L {a b c : n 0}
         m m m
      w a b c
      w uvxyz          | vxy | m     | vy | 1

Case 4: Possibility 1: v contains only a
  k1 k2 1                 y contains only b
    m k1          m k2           m
 aaa...aaaaaaa bbbbbbb...bbb ccc...ccc
  u          2     2                z
            v xy
n n n
           L {a b c : n 0}
        m m m
     w a b c
     w uvxyz          | vxy | m   | vy | 1

                                      2   2
Case 4: From Pumping Lemma: uv xy z           L
  k1 k2 1
    m k1          m k2           m
 aaa...aaaaaaa bbbbbbb...bbb ccc...ccc
 u          2     2               z
           v xy
n n n
            L {a b c : n 0}
        m m m
   w a b c
   w uvxyz            | vxy | m   | vy | 1

                                  2   2
Case 4: From Pumping Lemma: uv xy z              L
  k1 k2 1

              2   2        m k1 m k2 m
 However:   uv xy z      a     b    c        L
             Contradiction!!!
n n n
           L {a b c : n 0}
         m m m
   w a b c
   w uvxyz         | vxy | m     | vy | 1

Case 4: Possibility 2: v contains a and b
                      y contains only b
         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
       u     vxy           z
n n n
           L {a b c : n 0}
         m m m
    w a b c
    w uvxyz            | vxy | m   | vy | 1

Case 4: Possibility 2: v contains a and b
 k1 k2 k 1          y contains only b
     m     k1 k 2    m k            m
aaa...aaaaabbaabb bbbbbbb...bbb ccc...ccc
u             2
            v xy   2                 z
n n n
           L {a b c : n 0}
        m m m
    w a b c
    w uvxyz            | vxy | m   | vy | 1

                                   2       2
Case 4: From Pumping Lemma: uv xy z            L
 k1 k2 k 1
     m     k1 k 2    m k           m
aaa...aaaaabbaabb bbbbbbb...bbb ccc...ccc
u            2
            v xy   2                   z
n n n
             L {a b c : n 0}
         m m m
   w a b c
   w uvxyz          | vxy | m    | vy | 1

                                 2       2
Case 4: From Pumping Lemma: uv xy z          L

 However:           k1 k2 k 1
     2   2      m k1 k2 m k m
   uv xy z     a b a b     c         L
              Contradiction!!!
n n n
            L {a b c : n 0}
         m m m
   w a b c
   w uvxyz         | vxy | m      | vy | 1

Case 4: Possibility 3: v contains only a
                      y contains a and b
         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
       u     vxy           z
n n n
            L {a b c : n 0}
         m m m
   w a b c
   w uvxyz          | vxy | m       | vy | 1

Case 4: Possibility 3: v contains only a
                        y contains a and b


      Similar analysis with Possibility 2
n n n
            L {a b c : n 0}
          m m m
  w a b c
  w uvxyz         | vxy | m       | vy | 1

                            m             m
Case 5:    vxy overlaps b       and   c

        m         m         m
     aaa...aaa bbb...bbb ccc...ccc
            u          vxy      z
n n n
           L {a b c : n 0}
        m m m
   w a b c
   w uvxyz         | vxy | m     | vy | 1

Case 5: Similar analysis with case 4


         m         m         m
      aaa...aaa bbb...bbb ccc...ccc
             u          vxy      z
There are no other cases to consider



(since   | vxy | m , string vxy cannot
             m   m       m
 overlap   a , b and c       at the same time)
In all cases we obtained a contradiction


Therefore: The original assumption that
                    n n n
              L {a b c : n 0}
              is context-free must be wrong



Conclusion:   L is not context-free

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Theory of Automata
Theory of AutomataTheory of Automata
Theory of Automata
 
Post Machine
Post MachinePost Machine
Post Machine
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Push down automata
Push down automataPush down automata
Push down automata
 
Lecture 1,2
Lecture 1,2Lecture 1,2
Lecture 1,2
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
Pda to cfg h2
Pda to cfg h2Pda to cfg h2
Pda to cfg h2
 
NFA or Non deterministic finite automata
NFA or Non deterministic finite automataNFA or Non deterministic finite automata
NFA or Non deterministic finite automata
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
Generalized transition graphs
Generalized transition graphsGeneralized transition graphs
Generalized transition graphs
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Pumping lemma
Pumping lemmaPumping lemma
Pumping lemma
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
 

Mehr von lavishka_anuj

Mehr von lavishka_anuj (10)

Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
One ques
One quesOne ques
One ques
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
 
Moore and mealy machines
Moore and mealy machinesMoore and mealy machines
Moore and mealy machines
 
Grammar
GrammarGrammar
Grammar
 
Flat
FlatFlat
Flat
 
Finite automata intro
Finite automata introFinite automata intro
Finite automata intro
 
Finite automata
Finite automataFinite automata
Finite automata
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Turing machines
Turing machinesTuring machines
Turing machines
 

Kürzlich hochgeladen

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Kürzlich hochgeladen (20)

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

Properties of cfg

  • 1. Properties of Context-Free languages
  • 2. Union Context-free languages are closed under: Union L1 is context free L1 L2 L2 is context free is context-free
  • 3. Example Language Grammar n n L1 {a b } S1 aS1b | R L2 {ww } S2 aS2a | bS2b | Union n n R S S1 | S2 L {a b } {ww }
  • 4. In general: For context-free languages L1, L2 with context-free grammars G1, G2 and start variables S1, S2 It is assumed that variable sets of G1 and G2 are disjoint The grammar of the union L1 L2 has new start variable S and additional production S S1 | S2
  • 5. Concatenation Context-free languages are closed under: Concatenation L1 is context free L1L2 L2 is context free is context-free
  • 6. Example Language Grammar n n L1 {a b } S1 aS1b | R L2 {ww } S2 aS2a | bS2b | Concatenation n n R S S1S2 L {a b }{ww }
  • 7. In general: For context-free languages L1, L2 with context-free grammars G1, G2 and start variables S1, S2 The grammar of the concatenation L1L2 has new start variable S and additional production S S1S2
  • 8. Star Operation Context-free languages are closed under: Star-operation L is context free * L is context-free
  • 9. Example Language Grammar n n L {a b } S aSb | Star Operation n n L {a b } * S1 SS1 |
  • 10. In general: For context-free language L with context-free grammar G and start variable S The grammar of the star operation L * has new start variable S1 and additional production S1 SS1 |
  • 11. Negative Properties of Context-Free Languages
  • 12. Intersection Context-free languages are not closed under: intersection L1 is context free L1 L2 L2 is context free not necessarily context-free
  • 13. Example n n m n m m L1 {a b c } L2 {a b c } Context-free: Context-free: S AC S AB A aAb | A aA | C cC | B bBc | Intersection n n n L1 L2 {a b c } NOT context-free
  • 14. Complement Context-free languages are not closed under: complement L is context free L not necessarily context-free
  • 15. Example n n m n m m L1 {a b c } L2 {a b c } Context-free: Context-free: S AC S AB A aAb | A aA | C cC | B bBc | Complement n n n L1 L2 L1 L2 {a b c } NOT context-free
  • 16. Context-free languages and Regular Languages
  • 17. The intersection of a context-free language and a regular language is a context-free language L1 context free L1 L2 L2 regular context-free
  • 18. Machine M1 Machine M2 NPDA for L1 DFA for L2 context-free regular Construct a new NPDA machine M that accepts L1 L2 M simulates in parallel M1 and M 2
  • 19. NPDA M1 DFA M2 a, b c a q1 q2 p1 p2 transition transition NPDA M q1, p1 a, b c q2 , p2 transition
  • 20. NPDA M1 DFA M2 q0 p0 initial state initial state NPDA M q0 , p0 Initial state
  • 21. Therefore: L ( M1 ) L( M 2 ) is context-free (since M is NPDA) L1 L2 is context-free
  • 22. The Pumping Lemma for Context-Free Languages
  • 23. Take an infinite context-free language Generates an infinite number of different strings Example: S AB A aBb B Sb B b
  • 24. S AB A aBb B Sb B b A derivation: Variables are repeated S AB aBbB abbB abbSb abbABb abbaBbBb abbabbBb abbabbbb
  • 25. Derivation tree string abbabbbb S A B a B b S b b A B a B b b b
  • 26. Derivation tree string abbabbbb S A B a B b S b b A B a B b b repeated b
  • 27. B Sb ABb B aBbBb aBbbb S b A B a B b b b B b
  • 28. Repeated Part B S b A B a B b b B  aBbbb
  • 29. Another possible derivation B S b A B B  aBbbb a B b b S b A B a B b b B  aBbbb aaBbbbbbb
  • 30. S A B a B b S b b A B B  aBbbb a B b b S  abbaBbbb
  • 31. S A B a B b S b b A B B  aBbbb a B b b S b A B a B b b S  abbaBbbb  abbaaBbbbbbb
  • 32. S A B a B b S b b A B a B b b S b A B a B b b B b b S  abbaaBbbbbbb abbaabbbbbbb
  • 33. S  abbaabbbbbbb Therefore, the string abbaabbbbbbb is also generated by the grammar
  • 34. We know: B b B  aBbbb S  abbaBbbb We also know this string is generated: S  abbaBbbb abbaabbbb
  • 35. We know: B b B  aBbbb S  abbaBbbb Therefore, this string is also generated: S  abbaBbbb abbaaBbbbbbb abbaabbbbbbb
  • 36. We know: B b B  aBbbb S  abbaBbbb Therefore, this string is also generated: S  abbaBbbb abba(a ) B(bbb)bbb 2 2 abba(a ) B(bbb) bbb 2 2 abba(a ) b(bbb) bbb
  • 37. We know: B b B  aBbbb S  abbaBbbb Therefore, this string is also generated: S  abbaBbbb  i i abba(a ) B(bbb) bbb i i abba(a ) b(bbb) bbb
  • 38. Therefore, knowing that abbabbbb is generated by grammar G, we also know that i i abba(a) b(bbb) bbb is generated by G
  • 39. In general: We are given an infinite context-free grammar G Assume G has no unit-productions no -productions
  • 40. Take a string w L (G ) with length bigger than m > (Number of productions) x (Largest right side of a production) Consequence: Some variable must be repeated in the derivation of w
  • 41. u , v, x, y, z : strings of terminals String w uvxyz S u z Last repeated variable A v y repeated A x
  • 42. S Possible derivations: u z A S uAz v y A vAy A A x x
  • 43. We know: S uAz A vAy A x This string is also generated: * S uAz uxz 0 0 uv xy z
  • 44. We know: S uAz A vAy A x This string is also generated: * * S uAz uvAyz uvxyz 1 1 The original w uv xy z
  • 45. We know: S uAz A vAy A x This string is also generated: * * * S uAz uvAyz uvvAyyz uvvxyyz 2 2 uv xy z
  • 46. We know: S uAz A vAy A x This string is also generated: * * S uAz uvAyz uvvAyyz * * uvvvAyyyz uvvvxyyyz 3 3 uv xy z
  • 47. We know: S uAz A vAy A x This string is also generated: S * uAz * uvAyz * uvvAyyz * * uvvvAyyyz *  * uvvvvAy  yyyz * * uvvvvxy  yyyz i i uv xy z
  • 48. Therefore, any string of the form i i uv xy z i 0 is generated by the grammar G
  • 49. Therefore, knowing that uvxyz L(G) i i we also know that uv xy z L(G )
  • 50. S u z A v y A x Observation: | vxy | m Since A is the last repeated variable
  • 51. S u z A v y A x Observation: | vy | 1 Since there are no unit or productions
  • 52. The Pumping Lemma: For infinite context-free language L there exists an integer m such that for any string w L, | w| m we can write w uvxyz with lengths | vxy | m and | vy | 1 and it must be: i i uv xy z L, for all i 0
  • 53. Applications of The Pumping Lemma
  • 54. Non-context free languages n n n {a b c : n 0} Context-free languages n n {a b : n 0}
  • 55. Theorem: The language n n n L {a b c : n 0} is not context free Proof: Use the Pumping Lemma for context-free languages
  • 56. n n n L {a b c : n 0} Assume for contradiction that L is context-free Since L is context-free and infinite we can apply the pumping lemma
  • 57. n n n L {a b c : n 0} Pumping Lemma gives a magic number m such that: Pick any string w L with length | w | m m m m We pick: w a b c
  • 58. n n n L {a b c : n 0} m m m w a b c We can write: w uvxyz with lengths | vxy | m and | vy | 1
  • 59. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Pumping Lemma says: i i uv xy z L for all i 0
  • 60. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 We examine all the possible locations of string vxy in w
  • 61. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 m Case 1: vxy is within a m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 62. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 1: v and y consist from only a m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 63. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 1: Repeating v and y k 1 m k m m aaaaaa...aaaaaa bbb...bbb ccc...ccc u 2 2 z v xy
  • 64. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 1: From Pumping Lemma: uv xy z L k 1 m k m m aaaaaa...aaaaaa bbb...bbb ccc...ccc u 2 2 z v xy
  • 65. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 1: From Pumping Lemma: uv xy z L k 1 2 2 m k m m However: uv xy z a b c L Contradiction!!!
  • 66. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 m Case 2: vxy is within b m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 67. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 2: Similar analysis with case 1 m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 68. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 m Case 3: vxy is within c m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 69. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 3: Similar analysis with case 1 m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 70. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 m m Case 4: vxy overlaps a and b m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 71. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 1: v contains only a y contains only b m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 72. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 1: v contains only a k1 k2 1 y contains only b m k1 m k2 m aaa...aaaaaaa bbbbbbb...bbb ccc...ccc u 2 2 z v xy
  • 73. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 4: From Pumping Lemma: uv xy z L k1 k2 1 m k1 m k2 m aaa...aaaaaaa bbbbbbb...bbb ccc...ccc u 2 2 z v xy
  • 74. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 4: From Pumping Lemma: uv xy z L k1 k2 1 2 2 m k1 m k2 m However: uv xy z a b c L Contradiction!!!
  • 75. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 2: v contains a and b y contains only b m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 76. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 2: v contains a and b k1 k2 k 1 y contains only b m k1 k 2 m k m aaa...aaaaabbaabb bbbbbbb...bbb ccc...ccc u 2 v xy 2 z
  • 77. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 4: From Pumping Lemma: uv xy z L k1 k2 k 1 m k1 k 2 m k m aaa...aaaaabbaabb bbbbbbb...bbb ccc...ccc u 2 v xy 2 z
  • 78. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 2 2 Case 4: From Pumping Lemma: uv xy z L However: k1 k2 k 1 2 2 m k1 k2 m k m uv xy z a b a b c L Contradiction!!!
  • 79. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 3: v contains only a y contains a and b m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 80. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 4: Possibility 3: v contains only a y contains a and b Similar analysis with Possibility 2
  • 81. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 m m Case 5: vxy overlaps b and c m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 82. n n n L {a b c : n 0} m m m w a b c w uvxyz | vxy | m | vy | 1 Case 5: Similar analysis with case 4 m m m aaa...aaa bbb...bbb ccc...ccc u vxy z
  • 83. There are no other cases to consider (since | vxy | m , string vxy cannot m m m overlap a , b and c at the same time)
  • 84. In all cases we obtained a contradiction Therefore: The original assumption that n n n L {a b c : n 0} is context-free must be wrong Conclusion: L is not context-free