This paper proposes an algorithm to optimize the trade-off between space and time for a class of electronic structure calculations involving tensor contractions. The algorithm starts with an operation-based representation and applies transformations to minimize the total memory requirement by reducing the size of intermediate arrays through loop fusion techniques. This approach addresses the challenge of large temporary memory requirements for coupled cluster and other electronic structure models.