#' @title Stationary Invariant Gibbs-Boltzmann Density
#' @description Computes exact invariant potential landscape density p_infinity(y).
#' @param y_grid Vector. Discretized grid on [0, 1].
#' @param N Integer. Population size.
#' @param drift_fn Function b(y).
#' @param diff_fn Function a(y).
#' @return Vector of normalized density values over `y_grid`.
#' @export
fuzzyurn_stationary <- function(y_grid, N, drift_fn, diff_fn) {
  integrand <- sapply(y_grid, function(u) {
    a_u <- diff_fn(u)
    b_u <- drift_fn(u)
    if (a_u <= 1e-10) return(0)
    return(b_u / a_u)
  })
  
  dy <- diff(y_grid)[1]
  cum_int <- cumsum(integrand) * dy
  
  unnorm_p <- sapply(1:length(y_grid), function(i) {
    a_y <- diff_fn(y_grid[i])
    if (a_y <= 1e-10) return(0)
    (1 / a_y) * exp(2 * N * cum_int[i])
  })
  
  norm_constant <- sum(unnorm_p) * dy
  return(unnorm_p / norm_constant)
}
