Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,

Similar presentations


Presentation on theme: "1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,"— Presentation transcript:

1 1 Language Definitions Lecture # 2

2 Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition, using Regular Expressions(RE) and using Finite Automaton(FA) etc. Descriptive definition of language: The language is defined, describing the conditions imposed on its words.

3 Example: The language L of strings of odd length, defined over Σ ={a}, can be written as L={a, aaa, aaaaa,…..} Example: The language L of strings that does not start with a, defined over Σ ={a,b,c}, can be written as L={b, c, ba, bb, bc, ca, cb, cc, …}

4 Example: The language L of strings of length 2, defined over Σ ={0,1,2}, can be written as L={00, 01, 02,10, 11,12,20,21,22} Example: The language L of strings of the length 3 ending in 0, defined over Σ ={0,1}, can be written as L={0,00,10,000,010,100,110,…}

5 Example: The language EQUAL, of strings with number of a’s equal to number of b’s, defined over Σ ={a,b}, can be written as { Λ,ab,aabb,abab,baba,abba,…} Example: The language EVEN-EVEN, of strings with even number of a’s and even number of b’s, defined over Σ ={a,b}, can be written as { Λ, aa, bb, aaaa,aabb,abab, abba, baab, baba, bbaa, bbbb,…}

6 Example: The language INTEGER, of strings defined over Σ ={-,0,1,2,3,4,5,6,7,8,9}, can be written as INTEGER = {…,-2,-1,0,1,2,…} Example: The language EVEN, of stings defined over Σ ={-,0,1,2,3,4,5,6,7,8,9}, can be written as EVEN = { …,-4,-2,0,2,4,…}

7 PALINDROME: The language consisting of Λ and the strings s defined over Σ such that Rev(s)=s. It is to be denoted that the words of PALINDROME are called palindromes. English language example: EYE, RADAR, LEVEL, NOON etc. Example: Σ ={a,b}, PALINDROME={ Λ, a, b, aa, bb, aaa, aba, bab, bbb,...}

8 8 A new method to define languages: This method involve 3 different steps: 1. Specify the basic words (base case). 2. Rules for constructing new words from ones already known (recursive case). 3. Declare that no word except those constructed by following rules 1 and 2 are in the language. RECURSIVE DEFINITIONS

9 Recursive Definitions 9 Example EVEN is the set of all whole numbers divisible by 2. EVEN = {2n | n = 1, 2, 3, 4, …} EVEN is defined by the rules: 1. 2 is in EVEN. 2. If x is in EVEN, x+2 is in EVEN. 3. The only elements in EVEN are the ones that are constructed by following rules 1 and 2.

10 Recursive Definitions 10 Prove: 12 is in EVEN Divisible by 2? Yes, 12/2 = 6. 12 = 2n? Yes, n = 6. Rules of the recursive definition? Rule 1: 2  EVEN Rule 2: x=2, 2+2 = 4  EVEN Rule 2: x=4, 4+2 = 6  EVEN Rule 2: x=6, 6+2 = 8  EVEN Rule 2: x=8, 8+2 = 10  EVEN Rule 2: x=10, 10+2 = 12  EVEN

11 Recursive Definitions 11 Another equivalent recursive definition for the set EVEN  2 is in EVEN.  If x and y are in EVEN, x+y is in EVEN. Using the alternative definition Rule 1: 2  EVEN Rule 2: x=2, y=2, 2+2 = 4  EVEN Rule 2: x=4, y=4. 4+4 = 8  EVEN Rule 2: x=4, y=8, 4+8 = 12  EVEN

12 12 Recursive Definitions Another equivalent recursive definition for the set EVEN  2 is in EVEN.  If x and y are in EVEN, x+y is in EVEN. Using the alternative definition Rule 1: 2  EVEN Rule 2: x=2, y=2, 2+2 = 4  EVEN Rule 2: x=4, y=4. 4+4 = 8  EVEN Rule 2: x=4, y=8, 4+8 = 12  EVEN

13 13 Recursive Definitions Example: Recursive definition of the set POLYNOMIAL  All numbers are in POLYNOMIAL.  The variable x is in POLYNOMIAL.  If x and y are in POLYNOMIAL, x+y, x – y, and x*y are also in POLYNOMIAL.  The only elements in POLYNOMIAL are the ones that are constructed by following rules 1, 2, and 3.

14 14 Recursive Definitions Theorem: 5x 3 -8x+7 is in POLYNOMIAL Rule 1: 5  POLYNOMIAL Rule 2: x  POLYNOMIAL Rule 3: 5x  POLYNOMIAL Rule 3: 5xx = 5x 2  POLYNOMIAL Rule 3: 5x 2 x = 5x 3  POLYNOMIAL Rule 1: 8  POLYNOMIAL Rule 3: 8x  POLYNOMIAL Rule 3: 5x 3 – 8x  POLYNOMIAL Rule 1: 7  POLYNOMIAL Rule 3: 5x 3 – 8x + 7  POLYNOMIAL

15 END 15


Download ppt "1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,"

Similar presentations


Ads by Google