The Logic of Chemical Synthesis