Derivatives of klBin and the auxiliary function g(q) = klBin p q − 2 (p − q)² #
The derivative of klBin p q with respect to q is (q − p) / (q (1 − q)).
The derivative of (p − q)² is −2 (p − q). Their difference gives the
factored form (q − p) · (1 − 2q)² / (q (1 − q)), whose sign reduces to
sign(q − p).
Derivative of (p − q)² with respect to q.