smish.dev
implicit_function_derivatives

Say we have some system of equations f(x,y)=0, where f and y each have n components and x has m components. If we were given values for x, we could imagine solving f(x,y)=0 for y, which lets us think of y as an implicit function of x.

As a matter of notation, let's express this implicit function as y:=y(x).

How do we compute the gradient and Hessian of the implicit function y(x)?

To start, we can differentiate the system of equations to obtain

f(x,y)=0df=0

Then, with a little bit of algebra we can manipulate this to get an expression for dydx

0=dfi0=fixkdxk+fiyjdyjfiyjdyj=fixkdxkfiyjdyjdxk=fixkylfifiyjdyjdxk=ylfifixk,yifj:=[fy]ij1δljdyjdxk=ylfifixkdyldxk=ylfifixkdyldxk=ylfifixk

We can follow a similar process to get the Hessian, but it is more involved. Start by differentiating our gradient expression above

d2yldxkdxm=ddxm(dyldxk)=ddxm(ylfifixk)=ddxm(ylfi)fixkylfiddxm(fixk)=(ylfpddxm(fpyq)yqfi)fixkylfi(2fixkxm+2fixkyjdyjdxm)=ylfp(2fpyqxm+2fpyqyjdyjdxm)yqfifixkylfi(2fixkxm+2fixkyjdyjdxm)=ylfp(2fpyqxm+2fpyqyjdyjdxm)dyqdxkylfi(2fixkxm+2fixkyjdyjdxm)d2yldxkdxm=ylfp(2fpxkxm+2fpxkyjdyjdxm+2fpyqxmdyqdxk+2fpyqyjdyqdxkdyjdxm)d2yldxkdxm=ylfp(2fpxkxm+2fpxkyjdyjdxm+2fpyqxmdyqdxk+2fpyqyjdyqdxkdyjdxm)

Here is a mathematica notebook verifying the correctness of these expressions for scalar and vector-valued functions.