A piece of Python code calculating relevant contractions, via the einsum function, of exchange energy expressions in S 4 approximation, namely first-order exchange stated in equation (41), and second-order exchange-induction and exchange-dispersion presented in equations ( ) and (A2) respectively, was automatically generated by the program for symbolic derivations. The symbolical code is an extended version of the secondquant module, a part of SymPy 45 -a Python library for symbolic computations. The code has been generalized by the authors to perform derivations on a product of two Fermi vacuums. The developed code enables users i.a. to define second-quantized operators, compute their normal ordered product, and compute their expectation values in the Fermi vacuum state (understood as