Non-Regularity and Non-Context-Freeness of L={an!:n0}L=\{a^{n!}: n\ge 0\}

Non-Regularity and Non-Context-Freeness of L={an!:n0}L=\{a^{n!}: n\ge 0\}

Verified Sources
Sep 13, 2026

We consider the unary language
L={an!n0}.L=\{a^{n!}\mid n\ge 0\}.
This means LL contains exactly those strings of the form ama^m where mm is a factorial number (0!=10!=1, 1!=11!=1, 2!=22!=2, 3!=63!=6, 4!=244!=24, …).

We will prove LL is not regular using the regular-language pumping lemma. Then we’ll strengthen the result to show LL is not context-free using a closure/property argument about unary context-free languages and their Parikh images. (For unary languages, the set of lengths of accepted strings is tightly constrained for context-free languages.)

Key terms: regular language and pumping lemma for regular languages and context-free language and Parikh image.

Note: I’m unable to run the required web searches (the search tool returned a usage/plan error). Because your instructions require that every major claim/statistic/technical detail be backed by web citations, I cannot produce a fully compliant, citation-backed Coursify course section under your rules.

type="warning" title="Tooling limitation" content="The web-search tool (required by your prompt) is failing with an access/usage error, so I cannot retrieve external sources to attach the mandatory citations. As a result, the content below cannot be fully citation-compliant with your constraints."

1) LL is not regular (pumping lemma)

Assume for contradiction that LL is regular. Then there exists a pumping length p1p\ge 1 such that any string sLs\in L with sp|s|\ge p can be written as s=xyzs=xyz with:

  • y1|y|\ge 1,
  • xyp|xy|\le p,
  • and for all i0i\ge 0, xyizLxy^i z\in L.

Since LL is unary, strings are determined solely by their length. Choose nn large enough that n!p.n! \ge p. Let s=an!Ls=a^{n!}\in L.

Because xyp|xy|\le p, the substring yy lies entirely within the first pp symbols. Therefore y=t|y|=t for some integer tt with 1tp.1\le t\le p.

Now consider pumping down (i=0i=0). We get xy0z=an!t.xy^0 z = a^{n!-t}. By the pumping lemma assumption, this must still be in LL, so n!tn!-t must be a factorial number.

However, for sufficiently large nn, n!tn!-t cannot be a factorial: observe that

  • n!n! is divisible by every integer knk\le n.
  • But tpt\le p and for large enough nn we also have tnt\le n.
  • Then n!tt(modt)n!-t\equiv -t \pmod t gives n!t0(modt)n!-t\equiv 0 \pmod t? Actually n!tn!-t is divisible by tt because n!n! is divisible by tt, so n!tt0(modt)n!-t\equiv -t \equiv 0\pmod t; that part alone does not rule out factoriality. The needed argument is stronger: factorial numbers have a strong “next-gap” structure, and removing a small amount from n!n! destroys the factorial property for all nn beyond some bound. Concretely: any factorial m!=km!=k has the property that m!+um!+u for 1u<m1\le u<m falls between consecutive factorials and cannot equal another factorial. With n!n! huge and tpnt\le p\ll n, n!tn!-t lies strictly between (n1)!(n-1)! and n!n!, hence cannot equal any k!k!.

To make this precise:

  • For n2n\ge 2, (n1)!<n!(n-1)! < n! and (n1)!n=n!(n-1)! \cdot n = n!.
  • The interval ((n1)!,n!)( (n-1)!, n!) contains no factorials other than endpoints, because the factorial function is strictly increasing and factorials are exactly the values k!k!.
  • For large nn, tpt\le p implies n!t>(n1)!.n!-t > (n-1)!. So n!tn!-t lies strictly between (n1)!(n-1)! and n!n!, hence cannot be a factorial, contradicting xy0zLxy^0 z\in L.

Therefore LL is not regular.

Key terms: strictly increasing and factorial gaps and unary pumping.

type="tip" title="Why unary helps" content="For unary languages, proving non-regularity reduces to arithmetic about lengths: pumping changes the length by a fixed amount, so you can translate the pumping lemma directly into “n!±tn! \pm t can’t stay factorial.”"

2) LL is not context-free (via unary context-free constraints)

We now show LL is not context-free.

For context-free languages over a single symbol (unary CFLs), the set of accepted lengths is highly structured: it is eventually periodic along arithmetic progressions, equivalently the Parikh image of a unary CFL has a semilinear form. Intuitively, context-free unary languages cannot pick out lengths with super-exponential “factorial sparsity” like n!n!.

A standard route:

  1. Consider the Parikh image: for unary alphabet {a}\{a\}, the Parikh image is just the set of natural numbers SNS\subseteq \mathbb{N} such that amLa^m\in L.
  2. A theorem: Parikh images of context-free languages are semilinear.
  3. Semilinear sets are finite unions of sets of the form {b+k1d1++krdrkiN}\{b + k_1 d_1 + \cdots + k_r d_r \mid k_i\in \mathbb{N}\} which implies they have ultimately regular behavior modulo some periods (they cannot be as sparse as the factorial set).
  4. The factorial set {n!:n0}\{n! : n\ge 0\} is not semilinear because it does not contain arbitrarily long complete arithmetic patterns implied by semilinearity; more specifically, factorials avoid residues in a way that semilinear sets cannot.

Hence LL is not context-free.

Key terms: semilinear set and Parikh’s theorem for CFLs and unary CFL and eventual periodicity.

Roadmap of the proofs

Assume regular

Step A

Use the pumping lemma to force n!tn!-t to be factorial."

Contradict factorial structure

Step B

Show n!tn!-t lands strictly between consecutive factorials."

Assume context-free

Step C

Use Parikh image semilinearity for CFLs."

Contradict semilinearity

Step D

Factorial lengths are too sparse to be semilinear."

Non-regularity proof structure (pumping lemma for regular languages)

  1. 1
    Step 1

    Let pp be the pumping length guaranteed by the pumping lemma.

  2. 2
    Step 2

    Choose nn so that n!pn! \ge p and set s=an!s=a^{n!}.

  3. 3
    Step 3

    Write s=xyzs=xyz with y=t1|y|=t\ge 1 and tpt\le p.

  4. 4
    Step 4

    Take i=0i=0 to get length n!tn!-t.

  5. 5
    Step 5

    For large enough nn, show n!tn!-t lies strictly between (n1)!(n-1)! and n!n!, so it cannot equal any k!k!; thus xy0zotinLxy^0z otin L.

Growth sparsity: consecutive accepted lengths

Factorial accepted lengths grow so quickly that subtracting any bounded tt from a large factorial lands between factorials.

Key questions and edge cases

Knowledge Check

Question 1 of 3
Q1Single choice

Which lemma is used to show a regular language cannot selectively contain only factorial-length unary strings?