def chain_3(d3f_dg3, dg_dx, d2f_dg2, d2g_dx2, df_dg, d3g_dx3):
if np.all(dg_dx==<NUM_LIT:1.>) and np.all(d2g_dx2==<NUM_LIT:0>) and np.all(d3g_dx3==<NUM_LIT:0>):<EOL><INDENT>return d3f_dg3<EOL><DEDENT>dg_dx_3 = np.clip(dg_dx, -np.inf, _lim_val_cube)**<NUM_LIT:3><EOL>return d3f_dg3*(dg_dx_3) + <NUM_LIT:3>*d2f_dg2*dg_dx*d2g_dx2 + df_dg*d3g_dx3<EOL>
Generic chaining function for third derivative

.. math::
    \\frac{d^{3}(f . g)}{dx^{3}} = \\frac{d^{3}f}{dg^{3}}(\\frac{dg}{dx})^{3} + 3\\frac{d^{2}f}{dg^{2}}\\frac{dg}{dx}\\frac{d^{2}g}{dx^{2}} + \\frac{df}{dg}\\frac{d^{3}g}{dx^{3}}