#' @keywords internal
#' @importFrom stats approx

phi0_vec <- function(t) exp(-0.5 * t^2)

make_K_C <- function(t) {
  phi  <- function(x) exp(-0.5 * x^2)
  S <- outer(t, t, "+")
  D <- outer(t, t, "-")
  ft <- outer(t, t, function(s, u) phi(s) * phi(u))

  K <- phi(D) - ft
  C <- phi(S) - ft

  list(K = K, C = C)
}

interp_complex <- function(x.known, y.complex, x.out) {
  y.re <- approx(x.known, Re(y.complex), xout = x.out, rule = 2)$y
  y.im <- approx(x.known, Im(y.complex), xout = x.out, rule = 2)$y
  y.re + 1i * y.im
}
