An algebraic theory of graph reduction