Zyflair's right: practice makes perfect. When you really get down to it, algebra is actually pretty easy.
...enough to the point where it is reasonably possible to quite literally do it in your sleep.
(I've actually done that. It's very entertaining, slightly funny, and most unusual.)