Slides 5.2

Embed Size (px)

Citation preview

  • 8/3/2019 Slides 5.2

    1/14

    5.2: Closure Properties of Recursive and

    Recursively Enumerable LanguagesIn this section, we will see that the recursive and recursivelyenumerable languages are closed under union, concatenation, closure

    and intersection. The recursive languages are also closed under setdifference and complementation. In the next section, we will see thatthe recursively enumerable languages are not closed undercomplementation or set difference. On the other hand, we will see in

    this section that, if a language and its complement are both r.e., thenthe language is recursive.

    Copyright c 20038 Alley Stoughton

    Permission is granted to copy, distribute and/or modify this document under the terms of theGNU Free Documentation License, Version 1.2 or any later version published by the FreeSoftware Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-CoverTexts. A copy of the license is included in the section entitled GNU Free DocumentationLicense.

    The LATEX source of these slides, the associated book, and the distribution of the Forlan toolsetare available on the WWW at http://people.cis.ksu.edu/~stough/forlan/ .

    1

  • 8/3/2019 Slides 5.2

    2/14

    5.2.1: Closure Properties of Recursive Languages

    Theorem 5.2.1If L , L 1 and L 2 are recursive languages, then so are L 1 L 2 , L 1 L 2 ,L, L 1 L 2 and L 1 L 2 .

    Proof. Lets consider the concatenation case as an example. SinceL 1 and L 2 are recursive languages, there are string predicate programspr 1 and pr 2 that test whether strings are in L 1 and L 2 , respectively.We write a program pr with form

    lam (w,letSimp (f1,

    pr 1 ,letSimp (f2,

    pr 2 , ))) ,

    which tests whether its input is an element of L 1 L 2 .

    2

  • 8/3/2019 Slides 5.2

    3/14

    (5.2.1) Closure Properties of Rec. Lan. (Cont.)

    Proof (cont.). The elided part of pr generates all of the pairs of strings (x 1 , x 2 ) such that x 1 x 2 is equal to the value of w. Then itworks though these pairs, one by one. Given such a pair(x 1 , x 2 ), pr

    calls f1 with x 1 to check whether x 1 L 1 . If the answer isconst (false ), then it goes on to the next pair. Otherwise, it calls f2with x 2 to check whether x 2 L 2 . If the answer is const (false ),then it goes on to the next pair. Otherwise, it returns const (true ). If pr runs out of pairs to check, then it returns const (false ).

    We can check that pr is a string predicate program testing whetherw L 1 L 2 . Thus L 1 L 2 is recursive. 2

    3

  • 8/3/2019 Slides 5.2

    4/14

    (5.2.1) Closure Properties of Rec. Lan. (Cont.)

    Corollary 5.2.2If is an alphabet and L is recursive, then so is L .

    Proof. Follows from Theorem 5.2.1, since

    is recursive.2

    4

  • 8/3/2019 Slides 5.2

    5/14

    5.2.2: Closure Properties of Recursively

    Enumerable LanguagesTheorem 5.2.3If L , L 1 and L 2 are recursively enumerable languages, then so are L 1 L 2 , L 1 L 2 , L and L 1 L 2 .

    Proof. We consider the concatenation case as an example. Since L 1and L 2 are recursively enumerable, there are programs pr 1 and pr 2such that, for all w Str , w L 1 iff eval (app (pr 1 , str (w))) = norm (const (true )) , and for all w Str ,w L 2 iff eval (app (pr 2 , str (w))) = norm (const (true )) .

    (Remember that pr 1 and pr 2 may fail to terminate on some inputs.)

    5

  • 8/3/2019 Slides 5.2

    6/14

    5.2.2: Closure Properties of Recursively

    Enumerable LanguagesTheorem 5.2.3If L , L 1 and L 2 are recursively enumerable languages, then so are L 1 L 2 , L 1 L 2 , L and L 1 L 2 .

    Proof. We consider the concatenation case as an example. Since L 1and L 2 are recursively enumerable, there are programs pr 1 and pr 2such that, for all w Str , w L 1 iff eval (app (pr 1 , str (w))) = norm (const (true )) , and for all w Str ,w L 2 iff eval (app (pr 2 , str (w))) = norm (const (true )) .

    (Remember that pr 1 and pr 2 may fail to terminate on some inputs.)To show that L 1 L 2 is recursively enumerable, we will construct aprogram pr such that, for all w Str , w L 1 L 2 iff eval (app (pr , str (w))) = norm (const (true )) .

    5-a

  • 8/3/2019 Slides 5.2

    7/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Proof (cont.). When pr is called with str (w), for some w Str , itbehaves as follows. First, it generates all the pairs of strings (x 1 , x 2 )such that w = x 1 x 2 . Let these pairs be (x 1 , 1 , x 2 , 1 ), . . . , (x 1 ,n , x 2 ,n ).

    6

  • 8/3/2019 Slides 5.2

    8/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Proof (cont.). When pr is called with str (w), for some w Str , itbehaves as follows. First, it generates all the pairs of strings (x 1 , x 2 )such that w = x 1 x 2 . Let these pairs be (x 1 , 1 , x 2 , 1 ), . . . , (x 1 ,n , x 2 ,n ).

    Now, pr uses our incremental interpretation function to run a xednumber of steps of app (pr 1 , str (x 1 ,i )) and app (pr 2 , str (x 2 ,i ))(working with app (pr 1 , str (x 1 ,i )) and app (pr 2 , str (x 2 ,i )) ), for alli [1 : n ], and then repeat this over and over again.

    6-a

  • 8/3/2019 Slides 5.2

    9/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Proof (cont.). When pr is called with str (w), for some w Str , itbehaves as follows. First, it generates all the pairs of strings (x 1 , x 2 )such that w = x 1 x 2 . Let these pairs be (x 1 , 1 , x 2 , 1 ), . . . , (x 1 ,n , x 2 ,n ).

    Now, pr uses our incremental interpretation function to run a xednumber of steps of app (pr 1 , str (x 1 ,i )) and app (pr 2 , str (x 2 ,i ))(working with app (pr 1 , str (x 1 ,i )) and app (pr 2 , str (x 2 ,i )) ), for alli [1 : n ], and then repeat this over and over again.

    If, at some stage, the incremental interpretation of app (pr 1 , str (x 1 ,i )) returns const (true ), then x 1 ,i is marked asbeing in L 1 .

    If, at some stage, the incremental interpretation of app (pr 2 , str (x 2 ,i )) returns const (true ), then the x 2 ,i is markedas being in L 2 .

    6-b

  • 8/3/2019 Slides 5.2

    10/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Proof (cont.).

    If, at some stage, the incremental interpretation of app (pr 1 , str (x 1 ,i )) returns something other than const (true ),then the ith pair is marked as discarded.

    If, at some stage, the incremental interpretation of app (pr 2 , str (x 2 ,i )) returns something other than const (true ),

    then the ith pair is marked as discarded. If, at some stage, x 1 ,i is marked as in L 1 and x 2 ,i is marked as in

    L 2 , then Q returns const (true ).

    If, at some stage, there are no remaining pairs, then pr returnsconst (false ).

    2

    7

  • 8/3/2019 Slides 5.2

    11/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Theorem 5.2.4If is an alphabet, L is a recursively enumerable language, and L is recursively enumerable, then L is recursive.

    Proof. Since L and L are recursively enumerable languages,there are programs pr 1 and pr 2 such that, for all w Str , w L iff eval (app (pr 1 , str (w))) = norm (const (true )) , and for all w Str ,

    w L iff eval (app (pr 2 , str (w))) = norm (const (true )) .

    8

  • 8/3/2019 Slides 5.2

    12/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Theorem 5.2.4If is an alphabet, L is a recursively enumerable language, and L is recursively enumerable, then L is recursive.

    Proof. Since L and L are recursively enumerable languages,there are programs pr 1 and pr 2 such that, for all w Str , w L iff eval (app (pr 1 , str (w))) = norm (const (true )) , and for all w Str ,

    w L iff eval (app (pr 2 , str (w))) = norm (const (true )) .We construct a string predicate program pr that tests whether itsinput is in L . Given str (w), for w Str , pr proceeds as follows. If w , then pr returns const (false ). Otherwise,

    8-a

  • 8/3/2019 Slides 5.2

    13/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Theorem 5.2.4If is an alphabet, L is a recursively enumerable language, and L is recursively enumerable, then L is recursive.

    Proof. Since L and L are recursively enumerable languages,there are programs pr 1 and pr 2 such that, for all w Str , w L iff eval (app (pr 1 , str (w))) = norm (const (true )) , and for all w Str ,

    w L iff eval (app (pr 2 , str (w))) = norm (const (true )) .We construct a string predicate program pr that tests whether itsinput is in L . Given str (w), for w Str , pr proceeds as follows. If w , then pr returns const (false ). Otherwise, pr alternatesbetween incrementally interpreting app (pr 1 , str (w)) (working withapp (pr 1 , str (w)) ) and app (pr 2 , str (w)) (working withapp (pr 2 , str (w)) ).

    8-b

  • 8/3/2019 Slides 5.2

    14/14

    (5.2.2) Closure Properties of R.E. Lan. (Cont.)

    Proof (cont.).

    If, at some stage, the rst incremental interpretation returnsconst (true ), then pr returns const (true ).

    If, at some stage, the second incremental interpretation returnsconst (true ), then pr returns const (false ).

    If, at some stage, the rst incremental interpretation returnsanything other than const (true ), then pr returns const (false ).

    If, at some stage, the second incremental interpretation returnsanything other than const (true ), then pr returns const (true ).

    2

    9