% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/operations.R
\name{Math,dbMatrix-method}
\alias{Math,dbMatrix-method}
\title{Math Operations for \code{\link{dbMatrix}} Objects}
\usage{
\S4method{Math}{dbMatrix}(x)
}
\arguments{
\item{x}{A \code{\link{dbMatrix}} object.}
}
\value{
A \code{\link{dbMatrix}} object with the mathematical operation applied to each element.
}
\description{
Implements the \code{Math} \code{\link{S4groupGeneric}} functions
for \code{\link{dbMatrix}} objects. This includes various mathematical operations such as
logarithms, exponentials, trigonometric functions, and other transformations.
}
\details{
This method provides implementations for the following Math functions:

\emph{Arithmetic and rounding}:
\itemize{
\item \code{abs()}, \code{sign()}, \code{sqrt()}, \code{ceiling()}, \code{floor()}, \code{trunc()}
}

\emph{Cumulative operations}:
\itemize{
\item \code{cummax()}, \code{cummin()}, \code{cumprod()}, \code{cumsum()}
\item \strong{Note: \code{cumprod()} is not supported}
}

\emph{Logarithmic}:
\itemize{
\item \code{log()}, \code{log10()}, \code{log2()}, \code{log1p()}
}

\strong{DuckDB Log Function Mappings}:\tabular{lll}{
   R Function \tab DuckDB Function \tab Notes \cr
   \code{log(x)} \tab \code{LN(x)} \tab Natural logarithm \cr
   \code{log10(x)} \tab \code{LOG10(x)} \tab Base-10 logarithm \cr
   \code{log2(x)} \tab \code{LOG2(x)} \tab Base-2 logarithm \cr
   \code{log1p(x)} \tab \code{LN(x + 1)} \tab log(1+x), computed as LN \cr
}


\strong{Sparsity-Preserving Log}:
For \code{dbSparseMatrix} with pending operations, \code{log(x + 1)} operations preserve sparsity
since \code{log(0 + 1) = 0}. The multiplicative component is applied first,
then the log transformation is applied to sparse values only.

\emph{Trigonometric}:
\itemize{
\item \code{cos()}, \code{sin()}, \code{tan()}, \code{acos()}, \code{asin()}, \code{atan()}
\item \code{cosh()}, \code{sinh()}, \code{tanh()}, \code{acosh()}, \code{asinh()}, \code{atanh()}
\item \code{cospi()}, \code{sinpi()}, \code{tanpi()}
\item \strong{Note: \code{acosh()} \code{asinh()} \code{atanh()} are not supported}
}

\emph{Exponential}:
\itemize{
\item \code{exp()}, \code{expm1()}
\item \strong{Note: \code{expm1()} is not supported}
}

\emph{Special functions}:
\itemize{
\item \code{gamma()}, \code{lgamma()}, \code{digamma()}, \code{trigamma()}
\item \strong{Note: \code{digamma()} \code{trigamma()} are not supported}
}

The function applies the specified mathematical operation to each element
of the \code{\link{dbMatrix}} object.
}
\examples{
mat <- matrix(1, nrow = 3, ncol = 3)
dbmat <- as.dbMatrix(mat)
log(dbmat)
sqrt(dbmat)
sin(dbmat)

}
\concept{transform}
