I have just started reading about the Pumping Lemma, and I have some difficulties understanding the proofs of non-regularity of languages.
For example, in the book I am reading there's a proof for the fact that the language
$$C =\{w \mid \text{ w has an equal number of 0s and 1s} \}$$ is not regular.
The proof starts like this:
Assume to the contrary that $C$ is regular. Let $p$ be the pumping length given by the pumping lemma. Let $s$ be the string $0^p1^p$. With $s$ being a member of $C$, and having length more than $p$, the pumping lemma guarantees that $s$ can be split into three pieces $$s = xyz$$ where for any $i \geq 0$ the string $$xy^iz \in C$$ We would like to show that this outcome is impossible. But wait, it is possible! If we let $x$ and $z$ be the empty string and $y$ be the string $0^p1^p$, then $xy^iz$ always has an equal number of $0$s and $1$s and hence is in $C$. So it seems that $s$ can be pumped.
Here condition 3 in the pumping lemma is useful. It stipulates that when pumping $s$, it must be divided so that $|xy| \leq p$. That restriction on the way that $s$ may be divided makes it easier to show that the string $s = 0^p1^p$ we selected cannot be pumped. If $|xy| \leq p$, then $y$ must consist only of $0$s, so $xyyz \not \in C$. Therefore, $s$ cannot be pumped. That gives us the desired contradiction.
The part that I really didn't catch is the last paragraph, when the third condition (which is explained in the proof immediately after) is used.
The third condition says that the length of the concatenation between $x$ and $y$ must be less or equal to the number $p$ (the pumping length).
Specifically, the part that I don't understand is
If $|xy| \leq p$, then $y$ must consist only of $0$s, so $xyyz \not \in C$.
Why then $y$ must consist of only $0$s? And so why $xyyz \not \in C$?
In general, if you give an explanation of the proof with more details, I might eventually understand it better.
Remember that $s = 0^p1^p = xyz$. Now, if $|xy| \leqslant p$, then $xy$ is a prefix of $0^p$ and hence consists only of $0$s. Now, $y$ being a suffix of $xy$, it also consists only of $0$'s. Therefore, denoting by $|u|_0$ ($|u|_1$) the number of $0$s ($1$s) in a word $u$, one gets $|y|_0 = |y|$ and $|y|_1 = 0$, whence $$ |xyz|_0 = |s|_0 = p = |s|_1 = |xyz|_1 $$ but $$ |xyyz|_0 = |xyz|_0 + |y|_0 = p + |y| \quad \text{and}\quad |xyyz|_1 = |xyz|_1 + |y|_1 = p + 0 = p $$ It follows that if $y$ is a nonempty word, $xyyz \notin C$.