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
Kis determined by the spread betweendx’s time index and the earliest appearance ofdx’s base symbol ineq: stepping forward further can only increase the time indices of all instances, so once the leftmost has shifted pastdx, no additional contribution is possible.- Parameters:
- eq
sympy.Expr Equation (typically a Lagrangian) to differentiate.
- dx
TimeAwareSymbol Variable to differentiate with respect to.
- discount_factor
sympy.Exprorint, optional Multiplicative discount factor applied at each forward step. Default 1 (no discounting).
- eq
- Returns:
- total
sympy.Expr Sum of discounted derivatives across all relevant time shifts.
- total