Source: https://homepages.dcc.ufmg.br/~hbarbosa/teaching/uiowa/toc/notes/05-nonregular.pdf