I don't think that I fully understand how to use the pumping lemma to prove that a given language is not regular. I'm reading Sipser and according to him the definition of the pumping lemma is:
"If A is a regular language, then there is a number p ( the pumping length) where, if s is any string of A of length at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions: 1. for each $i \ge 0, xy^iz\in A$ 2. $\left| y \right| \gt 0$ 3. $\left|xy\right| \le p$
Now given the exercise:
Show that $A_1 = \{0^n1^n2^n | n\ge 0\}$ is not regular.
I assume that $A_1$ is regular and therefore can be divided into a form $s=xyz$ for $s\in A_1$. But now I could simply say that $s=0^p1^p2^p$ where p is the pumping length and divide s such that $x=\epsilon, y= 0^p1^p, z = 2^p$ and claim that because $\left|xy\right| \gt p$ it follows that $A_3$ is not regular. Similarly for the language $L=\{a^nb^la^k | k \neq n+l\}$ I could use the same logic. But all the solutions to those exercises come up with fairly complicated solutions compared to this logic, so I assume something is wrong here.
I think I misunderstand something about the theorem and how to use it to prove some language is not regular, what am I getting wrong?
When you use the lemma, you don't get to pick $x$, $y$, and $z$ for a given string $s$. All you know is that if the language is regular, they must exist, but not necessarily what they are. To show that a language is not regular, you need to show that for any choice of $x$, $y$, and $z$, at least one of the conditions (1), (2), and (3) fails. (Here the easiest way is probably to take a division satisfying (2) and (3) and show that (1) fails.)
Here's a hint: let $n>p$. If (2) and (3) hold, what can you say about $y$? Can you then get a string of the form $xy^kz$ that is not in the language?