Calculates the direct product or direct sum of two algebraic structures.