input: Write a python function to perform gradient descent optimization.
  assert optimize(lambda x: 2*(x**2) - 4*x, 10) < 2
  assert optimize(lambda x: 2*(x**2) - 4*x, 0) == 2
  assert optimize(lambda x: 2*(x**2) - 4*x, -10) < 2
output: def optimize(f, x, learning_rate=0.01, tolerance=1e-6, max_iterations=1000):
      def derivative(f, x, h=1e-6):
          return (f(x + h) - f(x - h)) / (2 * h)
      
      for _ in range(max_iterations):
          grad = derivative(f, x)
          if abs(grad) < tolerance:
              break
          x = x - learning_rate * grad
      
      return f(x)