  We prove that if $y=\sum_{n=0}^\infty{\bf a}(n)x^n\in\mathbb{F}_q[[x]]$ is an
algebraic power series of degree $d$, height $h$, and genus $g$, then the
sequence ${\bf a}$ is generated by an automaton with at most $q^{h+d+g-1}$
states, up to a vanishingly small error term. This is a significant improvement
on previously known bounds. Our approach follows an idea of David Speyer to
connect automata theory with algebraic geometry by representing the transitions
in an automaton as twisted Cartier operators on the differentials of a curve.
