1 language definitions lecture # 2. defining languages the languages can be defined in different...

Click here to load reader

Upload: austin-long

Post on 13-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Recursive Definitions

1Language DefinitionsLecture # 2Course Instructor Waqar Azam

Defining LanguagesThe 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. Example:The language L of strings of odd length, defined over ={a}, can be written asL={a, aaa, aaaaa,..}

Example:The language L of strings that does not start with a, defined over ={a,b,c}, can be written asL={b, c, ba, bb, bc, ca, cb, cc, }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 asL={0,00,10,000,010,100,110,}

Example: The language EQUAL, of strings with number of as equal to number of bs, defined over ={a,b}, can be written as{ ,ab,aabb,abab,baba,abba,}

Example: The language EVEN-EVEN, of strings with even number of as and even number of bs, defined over ={a,b}, can be written as{, aa, bb, aaaa,aabb,abab, abba, baab, baba, bbaa, bbbb,}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,}

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, ...}8A new method to define languages:

This method involve 3 different steps:Specify the basic words (base case).Rules for constructing new words from ones already known (recursive case).Declare that no word except those constructed by following rules 1 and 2 are in the language.RECURSIVE DEFINITIONSRecursive Definitions9Example EVEN is the set of all whole numbers divisible by 2. EVEN = {2n | n = 1, 2, 3, 4, } EVEN is defined by the rules:2 is in EVEN.If x is in EVEN, x+2 is in EVEN.The only elements in EVEN are the ones that are constructed by following rules 1 and 2.Recursive Definitions10Prove: 12 is in EVENDivisible by 2? Yes, 12/2 = 6.12 = 2n? Yes, n = 6.Rules of the recursive definition?Rule 1: 2 EVENRule 2: x=2, 2+2 = 4 EVENRule 2: x=4, 4+2 = 6 EVENRule 2: x=6, 6+2 = 8 EVENRule 2: x=8, 8+2 = 10 EVENRule 2: x=10, 10+2 = 12 EVENRecursive Definitions11Another equivalent recursive definition for the set EVEN2 is in EVEN.If x and y are in EVEN, x+y is in EVEN.

Using the alternative definitionRule 1: 2 EVENRule 2: x=2, y=2, 2+2 = 4 EVENRule 2: x=4, y=4. 4+4 = 8 EVENRule 2: x=4, y=8, 4+8 = 12 EVEN12Recursive DefinitionsAnother equivalent recursive definition for the set EVEN2 is in EVEN.If x and y are in EVEN, x+y is in EVEN.

Using the alternative definitionRule 1: 2 EVENRule 2: x=2, y=2, 2+2 = 4 EVENRule 2: x=4, y=4. 4+4 = 8 EVENRule 2: x=4, y=8, 4+8 = 12 EVEN13Recursive DefinitionsExample: 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.14Recursive DefinitionsTheorem: 5x3-8x+7 is in POLYNOMIALRule 1: 5 POLYNOMIALRule 2: x POLYNOMIALRule 3: 5x POLYNOMIALRule 3: 5xx = 5x2 POLYNOMIALRule 3: 5x2x = 5x3 POLYNOMIALRule 1: 8 POLYNOMIALRule 3: 8x POLYNOMIALRule 3: 5x3 8x POLYNOMIALRule 1: 7 POLYNOMIALRule 3: 5x3 8x + 7 POLYNOMIALEND15