Nested optimization problems arise when an agent must take into account the effect of their decisions on their own future behaviour, or the behaviour of others. In these problems, calculating marginal costs and benefits involves differentiating the solutions to nested problems. But are these solutions differentiable functions? We develop a tool called Reverse Calculus, and establish first-order conditions for (i) a Stackelberg leader considering the follower's best response function, (ii) a sovereign borrower considering its own future default policy, and (iii) non-convex dynamic programming problems.