Regular Expressions – Is the Negation of a Regular Expression Still Regular?

regular expressions

All articles (example) I read till now about regular expressions and NFAs explain three operations:

  • sequence
  • alternation (union)
  • repetition (Kleene star)

No one talks about negation. Is the negation not regular?

Update:

@RemcoGerlich What does it mean "swap the states". Can you explain it with the Kleene closure?

Kleene closure

How would the Kleene closure look with swapped states?

Best Answer

Yes; first, every non-deterministic finite automaton can be converted to a deterministic finite automaton that accepts the same language.

Now, just make all accepting states non-accepting and vice versa: this new DFA accepts a string exactly when the original DFA wouldn't, so its language is the complement of the orignal language.

Related Topic