# Finding an optimization function that is differentiable but its gradient and hessian are very hard/impossible to compute

I am looking for a test function that is differentiable since I'd like to test some gradient-based optimization methods. But the function's derivatives (both gradient and hessian) should be very hard (if not impossible) to compute analytically, any example?

(To give a counterexample, a multivariate Rosenbrock function may be an easy example, though it still takes some time for one to compute its derivatives)

If $f(x,y)$ then $g(x)=inf_y f(x,y)$ can be smooth. Computing the derivative of the inf requires finding the minimising $y$, which won't have an analytic solution in most cases. Computing the function value also requires optimisation, but you don't specify that the function value should be easy to compute.

I picked a random polynomial that might do the job:

import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize

def f(x,y):
return (pow(y-x,6) + 2*pow(y-2*x,4) + 3*pow(y+3*x,2) + 2*y + x*x)

def g(x):
return scipy.optimize.minimize(lambda y: f(x, y), 0).fun