Superscript in regular expression

117 Views Asked by At

If I want a language where the entries are in the form of $\gamma A^{n+2}\gamma A^{n+2}...\gamma A^{n+2}$, is it possible to write a regular expression as $(\gamma A^{n+2})^*$, or is it weird to have that '$n+2$? The languages are different for each case on $n$; for example when $n=1$, the language can be expressed by $(\gamma AAA)^*$ and when $n=3$, the language can be expressed by $(\gamma AAAAA)^*$. I don't want to write as $(\gamma AAAA^*)^*$ since I want the number of $A$s in every interval be exactly $n+2$ for each case of $n$. Thank you for the help.

2

There are 2 best solutions below

0
On BEST ANSWER

I think the notation is fine as long as you make it clear that the $n$ is fixed for each language. Something like $L_n = (\gamma A^{n + 2})^*$ would be fine. And it's probably good to have an example like $n = 3$ as in the question.

You seem to be confused about how a DFA/NFA can keep track of the count $n$. It is not that finite automata cannot count, it's more that they can only count constrained by a finite memory, in terms of the states. As long as you fix $n$, you only need finite memory to count up to $n$. But if you allow $n$ to vary, the language $\bigcup_n L_n$ is not regular.

2
On

(Forgive me for missteps, I’m a computer scientist not a mathematician)

I think that that notation is fine, since a regex with “n” isn’t really one regex, but describes a family of them. At each n, the result is a valid regex.