draft of exact computation of gradient