# ---- Convenience Wrappers ----
# Thin wrappers around pci() with the index pre-filled.

#' Process Potential Index (Cp)
#'
#' \eqn{C_p = (USL - LSL) / (6\sigma)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param sigma Short-term (within-subgroup) standard deviation.
#' @return Numeric value of \eqn{C_p}.
#' @examples
#' cp(LSL = 57, USL = 63, sigma = 1)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cp <- function(LSL, USL, sigma) {
  pci("Cp", LSL = LSL, USL = USL, sigma = sigma)
}

#' Process Capability Index (Cpk)
#'
#' \eqn{C_{pk} = \min\bigl((USL-\mu)/(3\sigma),\;(\mu-LSL)/(3\sigma)\bigr)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @return Numeric value of \eqn{C_{pk}}.
#' @examples
#' cpk(LSL = 57, USL = 63, mu = 60, sigma = 1)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cpk <- function(LSL, USL, mu, sigma) {
  pci("Cpk", LSL = LSL, USL = USL, mu = mu, sigma = sigma)
}

#' Upper Capability Index (Cpu)
#'
#' \eqn{C_{pu} = (USL - \mu) / (3\sigma)}.
#'
#' @param USL Upper specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @return Numeric value of \eqn{C_{pu}}.
#' @examples
#' cpu(USL = 63, mu = 60, sigma = 1)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cpu <- function(USL, mu, sigma) {
  pci("Cpu", USL = USL, mu = mu, sigma = sigma)
}

#' Lower Capability Index (Cpl)
#'
#' \eqn{C_{pl} = (\mu - LSL) / (3\sigma)}.
#'
#' @param LSL Lower specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @return Numeric value of \eqn{C_{pl}}.
#' @examples
#' cpl(LSL = 57, mu = 60, sigma = 1)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cpl <- function(LSL, mu, sigma) {
  pci("Cpl", LSL = LSL, mu = mu, sigma = sigma)
}

#' Taguchi Capability Index (Cpm)
#'
#' \eqn{C_{pm} = (USL - LSL) / \bigl(6\sqrt{\sigma^2 + (\mu - T)^2}\bigr)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @param target Target value \eqn{T}.
#' @return Numeric value of \eqn{C_{pm}}.
#' @examples
#' cpm(LSL = 57, USL = 63, mu = 60, sigma = 1, target = 60)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cpm <- function(LSL, USL, mu, sigma, target) {
  pci("Cpm", LSL = LSL, USL = USL, mu = mu, sigma = sigma, target = target)
}

#' Modified Taguchi Capability Index (Cpmk)
#'
#' \eqn{C_{pmk} = \min\bigl((USL-\mu),\;(\mu-LSL)\bigr) /
#'   \bigl(3\sqrt{\sigma^2+(\mu-T)^2}\bigr)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @param target Target value \eqn{T}.
#' @return Numeric value of \eqn{C_{pmk}}.
#' @examples
#' cpmk(LSL = 57, USL = 63, mu = 60, sigma = 1, target = 60)   # 1.0
#' @seealso \code{\link{pci}}
#' @export
cpmk <- function(LSL, USL, mu, sigma, target) {
  pci("Cpmk", LSL = LSL, USL = USL, mu = mu, sigma = sigma, target = target)
}

#' Performance Index (Pp)
#'
#' \eqn{P_p = (USL - LSL) / (6s)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param s Long-term (overall) standard deviation.
#' @return Numeric value of \eqn{P_p}.
#' @examples
#' pp(LSL = 57, USL = 63, s = 1.5)   # 0.6667
#' @seealso \code{\link{pci}}
#' @export
pp <- function(LSL, USL, s) {
  pci("Pp", LSL = LSL, USL = USL, s = s)
}

#' Performance Capability Index (Ppk)
#'
#' \eqn{P_{pk} = \min\bigl((USL-\bar{x})/(3s),\;(\bar{x}-LSL)/(3s)\bigr)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param xbar Long-term (overall) mean.
#' @param s Long-term standard deviation.
#' @return Numeric value of \eqn{P_{pk}}.
#' @examples
#' ppk(LSL = 57, USL = 63, xbar = 60, s = 1.5)   # 0.6667
#' @seealso \code{\link{pci}}
#' @export
ppk <- function(LSL, USL, xbar, s) {
  pci("Ppk", LSL = LSL, USL = USL, xbar = xbar, s = s)
}

#' Upper Performance Index (Ppu)
#'
#' \eqn{P_{pu} = (USL - \bar{x}) / (3s)}.
#'
#' @param USL Upper specification limit.
#' @param xbar Long-term mean.
#' @param s Long-term standard deviation.
#' @return Numeric value of \eqn{P_{pu}}.
#' @examples
#' ppu(USL = 63, xbar = 60, s = 1.5)   # 0.6667
#' @seealso \code{\link{pci}}
#' @export
ppu <- function(USL, xbar, s) {
  pci("Ppu", USL = USL, xbar = xbar, s = s)
}

#' Lower Performance Index (Ppl)
#'
#' \eqn{P_{pl} = (\bar{x} - LSL) / (3s)}.
#'
#' @param LSL Lower specification limit.
#' @param xbar Long-term mean.
#' @param s Long-term standard deviation.
#' @return Numeric value of \eqn{P_{pl}}.
#' @examples
#' ppl(LSL = 57, xbar = 60, s = 1.5)   # 0.6667
#' @seealso \code{\link{pci}}
#' @export
ppl <- function(LSL, xbar, s) {
  pci("Ppl", LSL = LSL, xbar = xbar, s = s)
}

#' Sigma Level (Z)
#'
#' \eqn{Z = \min\bigl((USL-\mu)/\sigma,\;(\mu-LSL)/\sigma\bigr)}.
#'
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param mu Short-term process mean.
#' @param sigma Short-term standard deviation.
#' @return Numeric value of \eqn{Z}.
#' @examples
#' z_level(LSL = 57, USL = 63, mu = 60, sigma = 1)   # 3.0
#' @seealso \code{\link{pci}}
#' @export
z_level <- function(LSL, USL, mu, sigma) {
  pci("Z", LSL = LSL, USL = USL, mu = mu, sigma = sigma)
}

#' Generalized Process Capability Index (Cpy)
#'
#' \eqn{C_{py} = p / p_0 = \bigl(F(USL)-F(LSL)\bigr) /
#'   \bigl(F(UDL)-F(LDL)\bigr)}, where \eqn{F} is the CDF from \code{dist}
#' (Maiti, Saha & Nanda, 2010).
#'
#' @param dist A \code{\link{pci_dist}} object.
#' @param LSL Lower specification limit.
#' @param USL Upper specification limit.
#' @param LDL Lower desirable limit (optional if \code{p0} is given).
#' @param UDL Upper desirable limit (optional if \code{p0} is given).
#' @param p0 Desired yield (optional if \code{LDL}/\code{UDL} are given).
#' @return Numeric value of \eqn{C_{py}}.
#' @examples
#' d <- pci_dist_normal(mean = 60, sd = 1)
#' cpy(d, LSL = 57, USL = 63, LDL = 57, UDL = 63)   # 1.0
#' @seealso \code{\link{pci}}, \code{\link{pci_dist}}
#' @export
cpy <- function(dist, LSL, USL, LDL = NULL, UDL = NULL, p0 = NULL) {
  pci("Cpy", dist = dist, LSL = LSL, USL = USL, LDL = LDL, UDL = UDL, p0 = p0)
}
