-1

I know the language L2 = {a^m; m >=0} is a regular language, and that L3 = {a^p; p is a prime number} is recursively enumerable.

Would L2-L3=L1 also be recursively enumerable and not context free or regular?

1 Answers1

0

Not only is L3 = {a^p; p is a prime number} recursively enumerable, it is recursive. Here is a sketch of the proof:

Imagine a multi-tape Turing machine with the following tapes:

  1. input tape, initially with a number on it, to check for prime-ness
  2. divisor tape, which records the current number we're checking as a divisor of the number on the dividend tape
  3. scratch tape, which we actually use to check whether the divisor divides the dividend with no remainder

For simplicity, assume unary representation. These tapes can be used as follows:

  1. Hard-code the behavior for a few specific inputs:
  • empty input: halt-accept, since 0 is not prime
  • just one symbol: halt-accept, since 1 is not prime
  • just two symbols: halt-reject, since 2 is prime
  1. Initialize the divisor tape with the number 2 by putting 2 symbols on it
  2. Copy the input to the scratch tape
  3. Erase as many symbols from the end of the scratch tape as there are symbols on the divisor tape; if you run out of symbols without being able to do so, reset all tape heads to the beginning, erase the scratch tape, and add a new symbol to the end of the divisor tape. If this makes the divisor greater than or equal to the input, halt-reject since this means the number was prime. Otherwise, continue from Step 3.
  4. if the scratch tape is now empty (meaning the divisor evenly divided the input), halt-accept since the input was not prime. Otherwise, continue from Step 4.

Because we can decided non-primeness for any input using this TM, we can also enumerate the strings in the language simply by giving each string to this TM and listing it if we determine it's not prime.

Example of the TM running on the number 5 (prime):

s = 0       s = 1       s = 2       s = 3       s = 4
|||||####   |||||####   |||||####   |||||####   |||||####
#########   ||#######   ||#######   ||#######   ||#######
#########   #########   |||||####   |||######   |########

s = 5       s = 6       s = 7       s = 8       
|||||####   |||||####   |||||####   |||||####   HALT
|||######   |||######   ||||#####   ||||#####   REJECT
|||||####   ||#######   |||||####   |########

Example of the TM running on 9 (non-prime):

s = 0       s = 1       s = 2       s = 3       s = 4
|||||||||   |||||||||   |||||||||   |||||||||   |||||||||
#########   ||#######   ||#######   ||#######   ||#######
#########   #########   |||||||||   |||||||##   |||||####

s = 5       s = 6       s = 7       s = 8       s = 9
|||||||||   |||||||||   |||||||||   |||||||||   |||||||||
||#######   ||#######   |||######   |||######   |||######
|||######   |########   |||||||||   ||||||###   |||######

s = 10
|||||||||   HALT
|||######   ACCEPT
#########
Patrick87
  • 27,682
  • 3
  • 38
  • 73