The algebraic theory of switching circuits