190 likes | 324 Vues
Lecture 3. Topics Languages Language classes Closure properties. In class reading assignment. Read Section 1.5 (pages 27-30) and answer the following questions What is a language? What is L ? What is {aa,bb}{cc,dd}? What is {aa,bb} 2 ? What are the five shortest strings in {aa,bb} * ?
E N D
Lecture 3 • Topics • Languages • Language classes • Closure properties
In class reading assignment • Read Section 1.5 (pages 27-30) and answer the following questions • What is a language? • What is L? • What is {aa,bb}{cc,dd}? • What is {aa,bb}2? • What are the five shortest strings in {aa,bb}*? • What are the five shortest strings in {aa,bb}+? • What does it mean if a language is infinite/finite? • Is there a difference between {} and {L}?
Questions • What is the English Language? • What is the C++ Language?
Describing a language L • List all elements in L • Doesn’t work for infinite languages • English language description of L • many different descriptions possible, though some are better than others • Formal mathematical description of L • Give a method for recognizing all strings in L • give a program for recognizing strings in L
Example • Describing the language of “Legal Identifiers of C++” • English 1: Legal identifiers of C++ • English 2 (CSE 231 textbook): • “In C++, an identifier should begin with a letter, which may be followed by any number of letters, digits or underscores.” • Formal Definition: • Regular expression: A(A+D+_)* • A = {a, b, …, z, A, B, …, Z} • D = {0, 1, 2 , 3, 4, 5, 6, 7, 8, 9}
Example Continued • Program to recognize language bool main( ) { char a; getc(cin, a); if (cin.eof( ) || (!alpha(a)) return false; getc(cin, a); while (!cin.eof( )) { if (!alpha(a) || !digit(a) !! (a != ‘_’)) return false; getc(cin,a); } return true; }
Work on these examples • {anbm | m,n >= 0} • shortest 3 strings? • English language description? • C++ program? • {anbn | n >= 0} • shortest 3 strings? • English language description? • C++ program?
Language classes • A language class is a set of languages • an element of a language class is a language which is a set of strings
Example language classes • the set of finite languages • the set of languages with at most 3 strings • CARD-3 • the set of languages whose l.r.p.’s can be solved • How are the above language classes related?
Closure Properties • A set is closed under an operation if applying the operation to elements of the set produces another element of the set • Example/Counterexample • set of integers and addition • set of integers and division
2 5 Integers and Addition 7 Integers
Integers and Division .4 2 5 Integers
Closure Properties for LC’s • We will be interested in closure properties of language classes. • The elements of a language class are languages which are sets themselves • Remember that we apply the set operations to the languages (elements of the language classes) rather than the language classes themselves • Example/Counterexample • Finite languages and set union operator • CARD-3 and set union operator
{0,1,00} {0,1,11} Finite Sets and Set Union {0,1,00,11} Finite Sets
{0,1,00} {0,1,11} CARD-3 and Set Union {0,1,00,11} CARD-3
Finite Sets and Set Complement {l,00,01,10,11,000,...} {0,1} Finite Sets
Infinite Number of Facts • A closure property can represent an infinite number of facts • Example: Finite languages closed under union • {} union {} is a finite language • {} union {l} is a finite language • {} union {0} is a finite language • ... • {l} union {} is a finite language • ...
First-order logic • A way to formally write a closure property • For all L1, ...,Lk in LC, L1 op ... op Lk in LC • Only one expression is needed because of the for all quantifier • Number of languages k is determined by arity of the operation • complement is unary so only one language • union is binary so two languages
Example F-O logic statements • For all L1,L2 in FINITE, L1 union L2 in FINITE • For all L1,L2 in LC3, L1 union L2 in LC3 • For all L in FINITE, Lc in FINITE • For all L in LC3, Lc in LC3