homework
play

Homework Assignment 1: Due Tuesday, Sept 17 th Recursively Defining - PDF document

Homework Assignment 1: Due Tuesday, Sept 17 th Recursively Defining Languages Exercises in Textbook: 1.38 1.39a,b 2.10 2.36 2.39a,b,c Todays plan Computation Hall of Fame Steven Cole Kleene Recursive


  1. Homework Assignment 1: Due Tuesday, Sept 17 th Recursively Defining Languages • Exercises in Textbook: – 1.38 – 1.39a,b – 2.10 – 2.36 – 2.39a,b,c Today’s plan Computation Hall of Fame • Steven Cole Kleene • Recursive Definition of Languages – 1909-1994 • Mathematical Proofs – b. Hartford, Conn. – PhD – Princeton (1934) – Prof at U of Wisc at Madison (1935 – 1979) – Introduced Kleene Star op – Defined regular expressions Specifying Languages Specifying Languages • Recall: • How do we specify languages? – What is a language? – If language is finite, you can list all of its strings. – A language is nothing more than a set of strings. • L = {a, aa, aba, aca} – Using basic Language operations • L= {aa, ab} * ∪ {b}{bb} * – Descriptive: • L = {x | n a (x) = n b (x)} 1

  2. Specifying Languages Recursive Definitions • Today we will learn how to specify • Definition is given in terms of itself languages recursively. – Example (factorial) 4! = 4 * 3! } = 4 * (3 * 2!) ! { = 1 if n 0 = n = 4 * (3 * (2 * 1!)) − n * ( n 1 )! otherwise = 4 * (3 * (2 * (1 * 0!))) = 4 * (3 * (2 * (1 * 1)))) = 24 Recursive Definitions and Languages Recursive Definitions and Languages • Languages can also be described by using a • Example: recursive definition Recursive definition of Σ * – 1. Initial elements are added to your set 1. Λ ∈ Σ * 2. Additional elements are added to your set by applying a rule(s) to the elements already in 2. For all x ∈ Σ * and all a ∈ Σ , xa ∈ Σ * your set 3. Nothing else is in Σ * unless it can be obtained 3. Complete language is obtained by applying by a finite number of applications of rules 1 step 2 infinitely and 2. Recursive Definitions and Languages Recursive Definitions and Languages • Let’s iterate through the rules for Σ = {a,b} • Example (in honor of Kleene): – i=0 Σ * = { Λ } – Recursive definition of L * – i=1 Σ * = { Λ , a, b} – i=2 Σ * = { Λ , a, b, aa, ab, ba, bb} 1. Λ ∈ Σ * – i=3 Σ * = { Λ , a, b, aa, ab, ba, bb, aaa, aab, 2.For all x ∈ L and all y ∈ L, xy ∈ L * aba, abb, baa, bab, bba, bbb} 3.Nothing else is in Σ * unless it can be obtained by a finite number of applications of rules 1 and – …and so on 2. 2

  3. Recursive Definitions and Languages Recursive Definitions – another Example • Let’s iterate through the rules for L = {aa,bb} • Example: Palindromes – i=0 L * = { Λ } – A palindrome is a string that is the same read – i=1 L * = { Λ , aa, bb} left to right or right to left – i=2 L * = { Λ , aa, bb, aaaa, aabb, bbbb, bbaa} – First half of a palindrome is a “mirror image” – i=3 L * = { Λ , aa, bb, aaaa, aabb, bbbb, bbaa, aaaaaa, of the second half aaaabb, aabbaa, aabbbb, bbbbaa, bbbbbb, …} – Examples: • a, b, aba, abba, babbab. – …and so on Recursive Definitions – another Example Recursive Definitions – another Example • Let’s iterate through the rules for pal over Σ • Recursive definition for palindromes (pal) over Σ = {a,b} 1. Λ ∈ pal – i=0 pal = { Λ , a, b} 2. For any a ∈ Σ , a ∈ pal – i=1 pal = { Λ , a, b, aaa, aba, bab, bbb} 3. For any x ∈ pal and a ∈ Σ , axa ∈ pal – i=2 pal = { Λ , a, b, aaa, aba, bab, bbb, aaaaa, aabaa, ababa, abbba, baaab, ababa, bbabb, 4. No string is in pal unless it can be obtained by bbbbb} rules 1-3 Recursive Definitions – yet another Example Recursive Definitions – yet another Example • Example: Fully parenthesized algebraic • Recursive definition for AE expressions (AE) 1.a ∈ AE – Σ = { a, (, ), +, - } 2.For any x, y ∈ AE (x + y) and (x – y) ∈ AE – All expressions where the parens match 3.No string is in pal unless it can be obtained by correctly are in the language rules 1-2 – Examples: • a, (a + a), (a + (a – a)), ( (a + a) – (a + a)), etc. 3

  4. Recursive Definitions – yet another Example Recursive Definitions – a final Example • L = {x ∈ {0,1} * | x = 0 i 1 j and i ≥ j ≥ 0} • Let’s iterate through the rules for AE – i=0 AE = {a} – In English: • strings over the alphabet {0,1} – i=1 AE = { a, (a+a), (a-a) } • each string contains zero or more 0’s followed by a – i=2 AE = {a, (a+a), (a-a) , (a + ( a + a)), zero or more 1’s (a – (a + a)), ( a + ( a – a)), ( a – ( a – a)), ((a • the number of 1’s is greater than or equal to the + a) + a), ( (a + a) – a), …} number of 0’s Recursive Definitions and Languages Recursive Definitions – a final Example L = {x ∈ {0,1} * | x = 0 i 1 j and i ≥ j ≥ 0} • • Questions on Recursive Definition? • A recursive definition Λ ∈ L 1. For any x ∈ L, both 0 x and 0 x 1 ∈ L 2. • Functions on strings and languages can also 3. No strings are in L unless it can be obtained using rules 1-2. be defined recursively. Later we will prove that this definition does indeed describe L. Recursive Function on strings Recursive Function on strings Λ r = Λ (abca) r = ((abc)a) r • Recursive definition for the reverse of a = a (abc) r ( xa ) r = ax r string x (rev(x) or x r ) = a ((ab)c) r – eg rev (abcd) = dcba = a(c(ab) r ) = ac (ab) r = ac ((a)(b)) r 1. Λ r = Λ = ac (b(a) r ) 2. For any x ∈ Σ * and a ∈ Σ , ( xa ) r = ax r = acb(a) r = acb ( Λ a) r = acb(a(C) r ) = acb(a Λ ) = acba 4

  5. Recursive Function on strings Recursive Function on strings | Λ | = 0 | abca| = | abc | + 1 • Recursive definition for the length of a = | ab | + 1 + 1 | xa | = |x| + 1 string x, |x| = | a | + 1 + 1 + 1 = | Λ | + 1 + 1 + 1 + 1 1. | Λ | = 0 = 0 + 1 + 1 + 1 + 1 2. For any x ∈ Σ * and a ∈ Σ , | xa | = |x| + 1 = 4 Summary Questions? • Languages = set of strings • Any questions? • Recursive Definition of Languages • Recursive Definition of Functions • Let’s take a 10 minute break and then do proofs. 5

Recommend


More recommend