Optimizing for an arbitrary perfect entangler. I. Functionals