gEconpy.utilities.diff_through_time#

gEconpy.utilities.diff_through_time(eq, dx, discount_factor=1)#

Differentiate an equation with respect to a time-aware symbol, summing across time shifts.

Computes \(\sum_{k=0}^{K} \beta^k \cdot \frac{\partial}{\partial dx} \mathrm{step}^k(\mathrm{eq})\) where each step shifts every TimeAwareSymbol’s time index forward by one. The number of iterations K is determined by the spread between dx’s time index and the earliest appearance of dx’s base symbol in eq: stepping forward further can only increase the time indices of all instances, so once the leftmost has shifted past dx, no additional contribution is possible.

Parameters:
eqsympy.Expr

Equation (typically a Lagrangian) to differentiate.

dxTimeAwareSymbol

Variable to differentiate with respect to.

discount_factorsympy.Expr or int, optional

Multiplicative discount factor applied at each forward step. Default 1 (no discounting).

Returns:
totalsympy.Expr

Sum of discounted derivatives across all relevant time shifts.