announcement
play

Announcement Career Fair Strings and Languages Wednesday, - PDF document

Announcement Career Fair Strings and Languages Wednesday, September 27th 10am -- 4pm Gordon Field House http://www.rit.edu/co-op/careers Announcement What did the witch say? Were looking for a few good programmers!


  1. Announcement  Career Fair Strings and Languages  Wednesday, September 27th  10am -- 4pm  Gordon Field House  http://www.rit.edu/co-op/careers Announcement What did the witch say?  We’re looking for a few good programmers! “It is always best to start at the  ACM Programming Contest beginning”  Teams up to 3 people  Local Tryouts: Sept 22nd at 5pm (ICL4) -- Glynda, the good witch of the North  Free food will be served  Contact : Paul Tymann (ptt@cs.rit.edu)  By Sept 18th (if interested)  http://www.cs.rit.edu/~icpc What is a Language? What is a string?  A string over Σ is a finite sequence  A language is a set of strings made of of (possibly empty) of elements of Σ . symbols from a given alphabet.  λ denotes the null string , the string with  An alphabet is a finite set of symbols (usually denoted by Σ ) no symbols.  Examples of alphabets:  Example strings over {a, b}  {0, 1}  λ , a, aa, bb, aba, abbba  { α , β , χ , δ , ε , φ , γ , η }  NOT strings over {a, b}  {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t , u, v,  aaaa…., abca w, x, y, z}  {a} 1

  2. The length of a string Strings and languages  For any alphabet Σ , the set of all strings  The length of a string x , denoted | x |, is over Σ is denoted as Σ * . the number of symbols in the string  A language over Σ is a subset of Σ *  Example:  Example  |abbab| = 5  {a,b} * = { λ , a, b, aa, bb, ab, ba, aaa, bbb, baa, …}  |a| = 1  Example Languages over {a,b}  |bbbbbbb| = 7  { λ , a, b, aa, bb} ∅  | λ | = 0  {x ∈ {a,b} * | |x| = 8} {x ∈ {a,b} * | |x| is odd}  {x ∈ {a,b} * | n a (x) = n b (x)} { λ }  {x ∈ {a,b} * | n a (x) =2 and x starts with b} Concatenation of String Some string related definitions  For x , y ∈ Σ *  x is a substring of y if there exists w,z ∈ Σ * (possibly λ ) such that y = wxz.  xy is the concatenation of x and y .  car is a substring of carnage , descartes ,  x = aba, y = bbb, xy=ababbb vicar , car , but not a substring of charity.  For all x , λ x = x λ = x  x is a suffix of y if there exists w ∈ Σ *  x i for an integer i, indicates concatenation such that y = wx . of x, i times  x is a prefix of y if there exists z ∈ Σ *  x = aba, x 3 = abaabaaba such that y = xz .  For all x, x 0 = λ Operations on Languages Concatenation of Languages  Since languages are simply sets of  If L 1 and L 2 are languages over Σ * strings, regular set operations can be  L 1 L 2 = { xy | x ∈ L 1 and y ∈ L 2 } applied:  Example:  For languages L 1 and L 2 over Σ *  L 1 = {hope, fear}  L 1 ∪ L 2 = all strings in L 1 or L 2  L 2 = {less, fully}  L 1 ∩ L 2 = all strings in both L 1 and L 2  L 1 L 2 = {hopeless, hopefully, fearless,  L 1 – L 2 = strings in L 1 that are not in L 2 fearfully}  L’ = Σ * – L 2

  3. Concatenation of Languages Kleene Star Operation  If L is a language over Σ *  The set of strings that can be obtained by concatenating any number of elements of a  L k is the set of strings formed by language L is called the Kleene Star, L * concatenating elements of L, k times. �  Example: L * U L i L 0 L 1 L 2 L 3 L 4 ... = = � � � �  L = {aa, bb} i 0 =  L 3 = {aaaaaa, aaaabb, aabbaa, aabbbb,  Note that since, L * contains L 0 , λ is an bbbbbb, bbbbaa, bbaabb, bbaaaa} element of L *  L 0 = { λ } Kleene Star Operation Specifying Languages  The set of strings that can be obtained by  How do we specify languages? concatenating one or more elements of a  If language is finite, you can list all of its language L is denoted L + strings. + U  L = {a, aa, aba, aca} � i 1 2 3 4 L L L L L L ... = = � � �  Using basic Language operations i 1  L= {aa, ab} * ∪ {b}{bb} * =  Descriptive:  L = {x | n a (x) = n b (x)} Specifying Languages Recursive Definitions  Next we will define how to specify  Definition is given in terms of itself languages recursively  Example (factorial) 4! = 4 * 3! } = 4 * (3 * 2!)  In future classes, we will describe how ! { 1 if n 0 = to specify languages by defining a n = 4 * (3 * (2 * 1!)) = n * ( n 1 )! otherwise � mechanism for generating the language = 4 * (3 * (2 * (1 * 0!))) = 4 * (3 * (2 * (1 * 1))))  Any questions? = 24 3

  4. Recursive Definitions and Languages Recursive Definitions and Languages  Languages can also be described by Example:  using a recursive definition Recursive definition of Σ *  1. Initial elements are added to your set (BASIS) λ ∈ Σ * 1. 2. Additional elements are added to your set For all x ∈ Σ * and all a ∈ Σ , xa ∈ Σ * by applying a rule(s) to the elements 2. already in your set (INDUCTION) Nothing else is in Σ * unless it can be 3. 3. Complete language is obtained by obtained by a finite number of applying step 2 infinitely applications of rules 1 and 2. Recursive Definitions and Languages Recursive Definitions and Languages  Let’s iterate through the rules for Σ = {a,b}  Example:  i=0 Σ * = { λ }  Recursive definition of L *  i=1 Σ * = { λ , a, b}  i=2 Σ * = { λ , a, b, aa, ab, ba, bb} 1. λ ∈ L *  i=3 Σ * = { λ , a, b, aa, ab, ba, bb, aaa, aab, aba, 2. For all x ∈ L and all y ∈ L, xy ∈ L * abb, baa, bab, bba, bbb} 3. Nothing else is in L * unless it can be obtained by a finite number of applications of rules 1 and 2.  …and so on Recursive Definitions – another Recursive Definitions and Languages 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  i=1 L * = { λ , aa, bb} read left to right or right to left  i=2 L * = { λ , aa, bb, aaaa, aabb, bbbb, bbaa}  First half of a palindrome is a “mirror  i=3 L * = { λ , aa, bb, aaaa, aabb, bbbb, bbaa, image” of the second half aaaaaa, aaaabb, aabbaa, aabbbb, bbbbaa, bbbbbb, …}  Examples:  a, b, aba, abba, babbab.  …and so on 4

  5. Recursive Definitions – another Recursive Definitions – another Example Example Recursive definition for palindromes  Let’s iterate through the rules for pal over Σ  = {a,b} (pal) over Σ  i=0 pal = { λ , a, b} λ ∈ pal 1.  i=1 pal = { λ , a, b, aa, bb, aaa, aba, bab, bbb} For any a ∈ Σ , a ∈ pal 2.  i=2 pal = { λ , a, b, aa, bb, aaa, aba, bab, bbb, For any x ∈ pal and a ∈ Σ , axa ∈ pal aaaa, baab, abba, bbbb, aaaaa, aabaa, ababa, 3. abbba, baaab, ababa, bbabb, bbbbb} No string is in pal unless it can be 4. obtained by rules 1-3 Structural Induction Recursive Definitions and Languages  Questions on Recursive Definition?  When dealing with languages, it is sometime cumbersome to restate the problems in terms of an integer.  Functions on strings and languages can  For languages described using a also be defined recursively. recursive definition, another type of induction, structural induction, is useful. Structural Induction Structural Induction  Principles Then   Suppose To prove that every element of L has   U is a set, some property P, it is sufficient to show:  I is a subset of U (BASIS), Every element of I has property P 1.  Op is a set of operations on U (INDUCTION). The set of elements of L having property P is 2.  L is a subset of U defined recursively as closed under Op follows:  I ⊆ L #2: If x ∈ L has property P, Op(x) also must  L is closed under each operation in Op  L is the smallest set satisfying 1 & 2 have property P 5

  6. Structural Induction Structural Induction  Principles Consider this recursive definition of a language L  Suppose  λ ∈ L  U is a set U = {0,1} * 1. For any x ∈ L, both 0 x and 0 x 1 ∈ L  I is a subset of U, I = { λ } 2. No strings are in L unless it can be obtained using  Op is a set of ops on U. Op = {0x, 0x1} 3. rules 1-2.  L is a subset of U defined recursively as And: follows: A = {x ∈ {0,1} * | x = 0 i 1 j and i ≥ j ≥ 0}  I ⊆ L Show L ⊆ A by structural induction  L is closed under each operation in Op  L is the smallest set satisfying 1 & 2. Structural Induction Structural Induction  To prove that every element of L has  To prove that every element of L has some property P, it is sufficient to show: some property P: 1. Every element of I has property P  Our property is: In our case, must show that λ has property P, A = {x ∈ {0,1} * | x = 0 i 1 j and i ≥ j ≥ 0} I.e. λ ∈ A, λ = 0 i 1 j , i ≥ j ≥ 0 P(x) is true if x ∈ A. Once again, this is the case where i=j=0 Structural Induction Structural Induction 2. The set of elements of L having property P is closed  Questions? under Op If x ∈ L has property P, Op(x) also must have property P Assume x has property P, x ∈ A, x = 0 i 1 j , i ≥ j ≥ 0 Op1(x) = 0x, which is an element of A Op2(x) = 0x1 which is an element of A Similar proof to induction with no mention of an integer 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend