0
$\begingroup$

I want to write a grammar which produces binary prime numbers. But I can't find any patterns this grammar can be made of. Like this:

1. In binary all prime numbers except 2 begin and end with 1
2. Concatenation of 2 prime numbers is a prime number (not 100% sure about this...)

If I had a whole set of such rules, it wouldn't be hard to write a grammar. Any information will be valuable for me!

Thank you in advance!

$\endgroup$
  • $\begingroup$ It would seem there's no context-free grammar whose language is the set of primes (or even an infinite subset of primes), though I don't really understand the proof. This is only a partial answer since maybe the primes could be generated by a more exotic grammar, though I doubt it. $\endgroup$ – Jack M Nov 10 '18 at 22:43
  • 1
    $\begingroup$ @JackM Thank you for reply! I am talking about Type-0 and Type-1 grammars (Chomsky hierarchy) which describe Recursively enumerable and Context-sensitive languages. $\endgroup$ – Anton Ostrouhhov Nov 11 '18 at 6:55
1
$\begingroup$

I have not found such a patterns/rules so far... But I found another way to solve this problem.

I wrote Turing Machine which accepts binary primary numbers (GitHub Gist). After that my friend wrote interpreter from TM to Grammar (examples can be found on GitHub). We got about 77000 productions in resulting Grammar. I believe this number can be reduced a lot, but this is another story anyway :)

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.