Final Lecture: Applications, Chomsky Hierarchy, and Recap

Final Lecture: Applications, Chomsky Hierarchy, and Recap

Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Final lecture: Applications, Chomsky hierarchy, and Recap H. Geuvers and J. Rot Institute for Computing and Information Sciences Radboud University Nijmegen Version: 2016-17 J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 1 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Outline Applications of CFGs Beyond CFGs Recap J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 2 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Programming languages Most programming languages are (deterministic) context-free. There are tools to automatically build: • a lexical analyzer (`lexer') from regular expressions. \if x = 2 then P else Q00 if x = 2 then P else Q ; • a parser from a CFG. ifthenelse ; = P Q x 2 J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 4 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Lindenmayer systems \The development of an organism...may be considered as the execution of a `developmental program' present in the fertilized egg... A central task of developmental biology is to discover the underlying algorithm from the course of development." { Lindenmayer & Rozenberg (1976) Example: Start with A, expand once per iteration: A ! AB 0 A B ! A 1 AB 2 ABA 3 ABAAB 4 ABAABABA ::: J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 5 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Lindenmayer systems Drawing a Lindenmayer system: • F: move forward • +: rotate counter clockwise • −: rotate clockwise • [: push location/angle • ]: pop location/angle Example: F ! F + F − −F + F 0 F 1 F+F--F+F 2 F+F--F+F+F+F--F+F--F+F--F+F+F+F--F+F 3 ::: J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 6 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Lindenmayer systems S ! F [+S][−S] S ! F − [[S] + S] + F [+FS] − S F ! FF J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 7 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Lindenmayer systems (cont'd) Example: Penrose Tiling (P3) S ! [N] + +[N] + +[N] + +[N] + +[N] M ! OF + +PF − − − −NF [−OF − − − −MF ] + + N ! +OF − −PF [− − −MF − −NF ]+ O ! −MF + +NF [+ + +OF + +PF ]− P ! − − OF + + + +MF [+PF + + + +NF ] − −NF J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 8 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Natural language S = hsentencei ! hnoun-phraseihverb-phrasei: hsentencei ! hnoun-phraseihverb-phraseihobject-phrasei: hnoun-phrasei ! hnameiharticleihnouni hnamei ! John j Jill hnouni ! bicycle j mango harticlei ! a j the hverb-phrasei ! hverbi j hadverbihverbi hverbi ! eats j rides hadverbi ! slowly j frequently hadjective-listi ! hadjectiveihadjective-listi j λ hadjectivei ! big j juicy j yellow hobject-phrasei ! hadjective-listihnamei hobject-phrasei ! harticleihadjective-listihnouni Jill frequently eats a juicy yellow mango. belongs to this language J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 9 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Natural language • Many sentences can be modelled using CFGs, e.g.: ...because I saw Cecilia feed the hippopotamuses . • But some (particularly crazy ) natural languages have non-context-free features like,cross-serial dependencies: ...omdat ik Cecilia de nijlpaarden zag voeren. • To capture these, one needs more power than CFGs J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 10 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Context-sensitive languages • Whereas context-free grammars have rules like this: X ! w X 2 V ; w 2 (Σ [ V )∗ • ...a context-sensitive grammar has rules like this: αX β ! αwβ with X 2 V , α; β; w 2 (Σ [ V )∗, w 6= λ. • Context-sensitive grammars generate context-sensitive languages. J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 12 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Context-sensitive languages Example: fanbncn j n > 0g S ! aBC j aSBC CB ! XB XB ! XC XC ! BC aB ! ab bB ! bb bC ! bc cC ! cc J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 13 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Turing machines • An unrestricted grammar has rules like: u ! v u; v 2 (Σ [ V )∗ • Recognisable by Turing machines • The stack is replaced by an infinite tape: ··· ··· • Transitions look like this: a=b; a=b; ! p q p q which read a, write b, and move left or right on the tape • We no longer need a separate input. Just use the tape: ··· a b b ··· J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 14 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Enumerable and computable languages • Languages recognisable by Turing machine are called enumerable languages • A languages is computable if both L and L = Σ∗ − L are enumerable. • In other words, there is a Turing machine with terminates telling us w 2 L and a (possibly different) one that terminates telling us w 2= L • Example: fan j n is not primeg. • Church-Turing thesis: \computable" () \computable by Turing machine" • (To be continued: Berekenbaarheid, 2nd year) J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 15 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Chomsky hierarchy fw j w describes a terminating Turing machine g;::: fan j n is primeg;::: fanbncn j n > 0g;::: fanbn j n > 0g;::: fan j n > 0g;::: Regular Context-free Context-sensitive Computable Enumerable J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 16 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Trade-offs Bigger classes of languages: • More languages can be described. • But, you can say less about them. w 2 L? time memory L1 = L2? Regular yes jwj const. yes Deterministic context-free yes jwj jwj no Context-free yes jwj3 jwj2 no Context-sensitive yes 2jwj jwjk no Computable yes 1 1 no Enumerable if w 2 L 1 1 no J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 17 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Exam topic: regular expressions You should know: • the definition of regular expression • how to compute a regular expression from an NFAλ using the elimination-of-states method • how to build an NFAλ from a regular expression using the `toolkit' J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 19 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Exam topic: finite automata You should know: • the definition of DFA, NFA, NFAλ • how to construct a DFA, NFA or NFAλ for a given language • how to construct a DFA from an NFA (the subset construction) • the constructions on DFAs for complement and intersection (product construction) of languages J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 20 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Exam Topic: regular languages You should know: • the closure properties of regular languages (union, intersection, complement), and how to use them to prove that a language is regular (or is not regular) n n • typical non-regular languages (fa b j n 2 Ng and palindromes) • Kleene's theorem • how to apply the pumping lemma to show that a language is not regular J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 21 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Exam topic: grammars You should know: • the definition of context-free grammar (CFG) • how to generate strings in a CFG (with leftmost derivations) • how to find the language generated by a (simple) CFG • how to construct a CFG that generates a given (context-free) language • the definition of regular grammar • how to construct a regular grammar from a NFA • how to construct an NFAλ from a regular grammar J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 22 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Exam topic: pushdown automata and CFLs You should know: • the definition of pushdown automata (PDAs) • how to give a PDA for a given (simple context-free) language • how find the language accepted by a given PDA • how to construct a PDA from a CFG • how to construct a CFG from a PDA • the closure properties of context-free languages J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 23 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Remarks on sets Beware that ; 6= f;g ; 6= λ ; 6= fλg. and ;· L = L ·; = ; and fλg · L = L · fλg = L. Symbols: • w 2 L: \is in". • L1 ⊆ L2: is a subset of, i.e. everything in L1 is also in L2. • L1 [ L2:union, the things in either of the two sets. • L1 \ L2: intersection, only the things in both sets. • L: complement, the words not in L, L = Σ∗ − L. Terminology: Language described using set-notation, examples: ∗ n m fw 2 fa; bg j jwja is eveng; fa b j n < mg; ; J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 24 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Remarks on words and languages Languages • contain words. • can be infinite, but words are finite. The language L∗ • always contains λ. • is not the same as fw n j w 2 L; n ≥ 0g. • is L0 [ L1 [ L2 [··· . J. Rot Version: 2016-17 Formal Languages, Grammars and Automata 25 / 28 Applications of CFGs Beyond CFGs Recap Radboud University Nijmegen Remarks on proofs To prove that L1 = L2, show that • L1 ⊆ L2 (for all w, w 2 L1 implies w 2 L2), and • L1 ⊇ L2 (for all w, w 2 L2 implies w 2 L1). Proof by contradiction • If regular languages have property X , and L1 does not have property X , then L1 is not regular.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    25 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us