  This paper describes Wick&d, an implementation of the algebra of
second-quantized operators normal ordered with respect to general correlated
references and the corresponding Wick theorem [W. Kutzelnigg and D. Mukherjee,
J. Chem. Phys. 107, 432 (1997)]. Wick&d employs a compact representation of
operators and a backtracking algorithm to efficiently evaluate Wick
contractions. Since Wick&d can handle both fully and partially contracted
terms, it can be applied to both projective and Fock-space many-body
formalisms. To demonstrate the usefulness of Wick&d, we use it to evaluate the
single-reference coupled cluster equations up to octuple excitations and report
an automated derivation and implementation of the second-order driven
similarity renormalization group multireference perturbation theory
(DSRG-MRPT2).
