draft of exact computation of gradient
adding debugging to reference code; made inputs and outputs explicit