CS 3313 Foundations of Computing:

Closure Properties of RE & Recursive Languages

http://gw-cs3313-2021.github.io

© Narahari 2021 © Some slides courtesy of Hopcroft & Ullman Problems

§ Informally, a (decision) “problem” is a yes/no question about an infinite of possible instances. § Example 1: “Does graph G have a Hamilton cycle (cycle that touches each node exactly once)? • Each undirected graph is an instance of the “Hamilton-cycle problem.” § Example 2: “Is graph G k-colorable ? • Each undirected graph, and value k, is an instance of the “graph coloring problem.”

2 Problems – (2)

§ Formally, a problem is a language. § Each string encodes some instance. § The string is in the language if and only if the answer to this instance of the problem is “yes.”

3 Recall Definitions

§ Recursive Language: A language L is recursive language if there is a that accepts the language and halts on all inputs w M Yes w ϵ L(M) No

§ Recursively Enumerable Language: if there is a Turing machine that accepts the language by halting when the input string is in the language • The machine may or may not halt if the string is not in the language

w Yes M w ϵ L(M) Decidable Problems

§ A problem is decidable if there is an to answer it. • Recall: An “algorithm,” formally, is a TM that halts on all inputs, accepted or not. • Put another way, “decidable problem” = “recursive language.” § Otherwise, the problem is undecidable.

5 Bullseye Picture

Not recursively enumerable languages ?? Decidable problems = Recursive languages

Recursively Are there enumerable any languages languages here? 6 Closure Properties of Recursive and RE Languages § Next topic is Decidability • Review Lab notes on Math review – diagonalization etc. § First let’s look at closure properties of these classes of languages § Both closed under union, concatenation, star, reversal, intersection, inverse homomorphism. § Recursive closed under difference, complementation. § RE closed under homomorphism. Proving Closure Properties…methodology

§ Observe: To prove the closure properties we have to construct a Turing machine, i.e., an algorithm (!!!), to accept the language • Construction shown using a flowchart & combining other ”” - Getting more and more like programming! § To prove a language L (constructed from other recursive languages) is recursive, provide an algorithm described by a ‘flowchart’ below • To show it is RE, the machine halts only if w is in the language

w M’ Yes w ϵ L No Closure under Union

§ Let L1 = L(M1) and L2 = L(M2).

§ Assume M1 and M2 are single-semi-infinite-tape TM’s. § Construct 2-tape TM M to copy its input onto the second

tape and simulate the two TM’s M1 and M2 each on one of the two tapes, “in parallel.”

§ Recursive languages: If M1 and M2 are both algorithms, then M will always halt in both simulations. § RE languages: accept if either accepts, but you may find both TM’s run forever without halting or accepting.

9 Algorithm/Picture of Union for Recursive Sets M must halt on all inputs: accepts if w is in either, rejects if w not in either

Accept M 1 Reject OR Accept

Input w M

Accept M AND Reject 2 Reject

Remember = “halt without accepting 10 Picture of Union of RE Sets

M must halt and accept if w is in either language, else it may reject and halt or may not halt

Accept M1 OR Accept

Input w M

Accept M2

11 Closure under other set operations

§ Recursive Languages are closed under • Union, Intersection, Concatenation, Star Closure • Complementation. Set difference • Reversal • Inverse Homomorphism § Recursively Enumerable (RE) languages are closed under • Union, Intersection, Concatenation, Star Closure • Reversal • Homomorphism • Inverse Homomorphism Intersection of Recursive Sets – Same Idea

Accept M 1 Reject AND Accept

Input w M

Accept M OR Reject 2 Reject

13 Intersection of RE Sets

Accept M1 AND Accept

Input w M

Accept M2

Observe: if w is in the intersection then both machines will accept and halt on w => This machine M will halt and accept w 14 Complement of Recursive Languages

w M Yes No w ϵ L(M) No Yes M’ Set Difference, Complement

§ Recursive languages: both TM’s will eventually halt.

§ Accept if M1 accepts and M2 does not. • Corollary: Recursive languages are closed under complementation.

§ RE Languages: can’t do it; M2 may never halt, so you can’t be sure input is in the difference.

16 Concatenation of RE Languages

§ Let L1 = L(M1) and L2 = L(M2).

§ Assume M1 and M2 are single-semi-infinite-tape TM’s. § Construct 2-tape Nondeterministic TM M: 1. Guess a break in input w = xy 2. Move y to second tape.

3. Simulate M1 on x, M2 on y. 4. Accept if both accept.

17 Concatenation of Recursive Languages

§ Can’t use a NTM. § Systematically try each break w = xy.

§ M1 and M2 will eventually halt for each break. § Accept if both accept for any one break. § Reject if all breaks tried and none lead to acceptance.

18 Star Closure

§ Same ideas work for each case.

§ RE: guess many breaks, accept if M1 accepts each piece. § Recursive: systematically try all ways to break input into some number of pieces.

19 Reversal

§ Start by reversing the input. § Then simulate TM for L to accept w if and only wR is in L. § Works for either Recursive or RE languages.

20 Inverse Homomorphism

§ Apply h to input w. § Simulate TM for L on h(w). § Accept w iff h(w) is in L. § Works for Recursive or RE.

21 Homomorphism/RE

§ Let L = L(M1). § Design NTM M to take input w and guess an x such that h(x) = w.

§ M accepts whenever M1 accepts x. § Note: won’t work for Recursive languages.

22