<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: baaz</title>
    <description>The latest articles on DEV Community by baaz (@baaz_a45).</description>
    <link>https://dev.to/baaz_a45</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4127520%2F6e3b29fc-4c01-448f-b2df-942b1072b44a.png</url>
      <title>DEV Community: baaz</title>
      <link>https://dev.to/baaz_a45</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baaz_a45"/>
    <language>en</language>
    <item>
      <title>Pumping Lemma Explained: Proving a Language Isn't Regular</title>
      <dc:creator>baaz</dc:creator>
      <pubDate>Wed, 16 Sep 2026 09:42:36 +0000</pubDate>
      <link>https://dev.to/baaz_a45/pumping-lemma-explained-proving-a-language-isnt-regular-47h1</link>
      <guid>https://dev.to/baaz_a45/pumping-lemma-explained-proving-a-language-isnt-regular-47h1</guid>
      <description>&lt;h1&gt;
  
  
  The Pumping Lemma: How to Prove a Language &lt;em&gt;Isn't&lt;/em&gt; Regular
&lt;/h1&gt;

&lt;p&gt;If you've spent any time with automata theory, you've probably built a dozen DFAs and NFAs without much trouble. Given a language, you draw states, you connect transitions, you're done. But then you hit a language like &lt;code&gt;{aⁿbⁿ | n ≥ 0}&lt;/code&gt; — equal numbers of a's followed by equal numbers of b's — and no matter how you draw it, you can't make a finite-state machine that accepts it and rejects everything else.&lt;/p&gt;

&lt;p&gt;That's not a failure of your drawing skills. It's because the language genuinely &lt;em&gt;isn't&lt;/em&gt; regular — and the Pumping Lemma is the tool that lets you prove it, instead of just failing to find a machine and hoping that means something.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Idea, Before the Formalism
&lt;/h2&gt;

&lt;p&gt;A finite automaton has a fixed number of states — say, &lt;em&gt;n&lt;/em&gt; of them. If you feed it a string longer than &lt;em&gt;n&lt;/em&gt; symbols, something has to give: by the time the machine has read &lt;em&gt;n&lt;/em&gt; symbols, it must have visited some state twice (there are only &lt;em&gt;n&lt;/em&gt; states, so &lt;em&gt;n&lt;/em&gt; transitions can't all land on new ones). That repeated state means the machine has looped.&lt;/p&gt;

&lt;p&gt;And if it looped once, it can loop any number of times — zero times, twice, a hundred times — and still end up in the same place, because a loop is a loop. So if a long-enough string is accepted, then so is that string with the looped segment repeated any number of times, or removed entirely.&lt;/p&gt;

&lt;p&gt;That's the entire lemma. Everything else is just writing it precisely enough to use in a proof.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Formal Statement
&lt;/h2&gt;

&lt;p&gt;For any regular language &lt;em&gt;L&lt;/em&gt;, there exists a &lt;strong&gt;pumping length&lt;/strong&gt; &lt;em&gt;p&lt;/em&gt; such that every string &lt;em&gt;s&lt;/em&gt; in &lt;em&gt;L&lt;/em&gt; with length at least &lt;em&gt;p&lt;/em&gt; can be split into three parts, &lt;em&gt;s = xyz&lt;/em&gt;, satisfying:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;|y| &amp;gt; 0&lt;/strong&gt; — the middle piece isn't empty (there's actually something to repeat)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;|xy| ≤ p&lt;/strong&gt; — the split happens within the first &lt;em&gt;p&lt;/em&gt; characters (the repeat has to occur early, where the state-repetition argument applies)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;For every i ≥ 0, xyⁱz is also in L&lt;/strong&gt; — you can repeat &lt;em&gt;y&lt;/em&gt; any number of times (including zero) and the result still belongs to the language&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note what this is: a property every regular language &lt;em&gt;must&lt;/em&gt; have. It doesn't tell you how to build an automaton, and it doesn't prove a language &lt;em&gt;is&lt;/em&gt; regular. It's a one-way test — a necessary condition, not a sufficient one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using It: Proof by Contradiction
&lt;/h2&gt;

&lt;p&gt;Because it's a necessary condition, the Pumping Lemma is almost always used in reverse: assume the language &lt;em&gt;is&lt;/em&gt; regular, show that leads to a contradiction, and conclude it isn't.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Claim:&lt;/strong&gt; &lt;code&gt;L = {aⁿbⁿ | n ≥ 0}&lt;/code&gt; is not regular.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof:&lt;/strong&gt;&lt;br&gt;
Assume, for contradiction, that &lt;em&gt;L&lt;/em&gt; is regular. Then a pumping length &lt;em&gt;p&lt;/em&gt; exists.&lt;/p&gt;

&lt;p&gt;Choose the string &lt;code&gt;s = aᵖbᵖ&lt;/code&gt;. This is in &lt;em&gt;L&lt;/em&gt;, and its length is 2p ≥ p, so the lemma applies — &lt;em&gt;s&lt;/em&gt; must split into &lt;em&gt;xyz&lt;/em&gt; satisfying all three conditions.&lt;/p&gt;

&lt;p&gt;Since |xy| ≤ p, and the first &lt;em&gt;p&lt;/em&gt; characters of &lt;em&gt;s&lt;/em&gt; are all a's, both &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; consist entirely of a's. Since |y| &amp;gt; 0, &lt;em&gt;y&lt;/em&gt; is a nonempty string of a's — say, &lt;em&gt;y = aᵏ&lt;/em&gt; for some &lt;em&gt;k ≥ 1&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now pump &lt;em&gt;y&lt;/em&gt;: consider &lt;em&gt;xy²z&lt;/em&gt;. This adds &lt;em&gt;k&lt;/em&gt; extra a's without touching the b's, giving a string with &lt;em&gt;p + k&lt;/em&gt; a's and only &lt;em&gt;p&lt;/em&gt; b's. That string has unequal numbers of a's and b's — so it's &lt;strong&gt;not&lt;/strong&gt; in &lt;em&gt;L&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But the lemma guarantees &lt;em&gt;xy²z&lt;/em&gt; &lt;strong&gt;must&lt;/strong&gt; be in &lt;em&gt;L&lt;/em&gt;, since &lt;em&gt;i = 2&lt;/em&gt; is a valid choice. Contradiction.&lt;/p&gt;

&lt;p&gt;Therefore, &lt;em&gt;L&lt;/em&gt; is not regular. ∎&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Students Usually Go Wrong
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Picking the wrong string.&lt;/strong&gt; The lemma lets &lt;em&gt;you&lt;/em&gt; pick &lt;em&gt;s&lt;/em&gt;, as long as it's in &lt;em&gt;L&lt;/em&gt; and long enough. Pick something that forces the split to land in a "rigid" part of the string — like the block of a's before any b's appear — so that pumping is guaranteed to break something.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting condition 2.&lt;/strong&gt; Students often try to pump the middle of the string and forget that the split &lt;em&gt;xy&lt;/em&gt; must fall within the first &lt;em&gt;p&lt;/em&gt; characters. This is exactly what pins &lt;em&gt;y&lt;/em&gt; down to being made of only one kind of symbol in languages like &lt;code&gt;aⁿbⁿ&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trying to prove a language IS regular using the lemma.&lt;/strong&gt; It can't do that — satisfying the pumping property doesn't guarantee regularity (some non-regular languages happen to satisfy it too). It only rules languages &lt;em&gt;out&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It's Worth Actually Understanding
&lt;/h2&gt;

&lt;p&gt;Beyond exams, this is one of the first real "limits of computation" results you encounter — a formal, provable boundary on what a certain class of machines can do. The same style of argument (find a bound, force a repetition, derive a contradiction) reappears throughout theoretical CS, including in the Pumping Lemma for context-free languages and, in spirit, in results like the Halting Problem. Once this clicks, a lot of automata theory stops feeling like memorized rules and starts feeling like one coherent idea applied over and over.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>theory</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
