Counting with rational generating functions