Embarrassing but my mistake was due to using the floor function —
it has derivative zero almost everywhere, and thus whatever composite function it is part of will also have derivative zero by the chain rule