
(FPCore (c x y) :precision binary64 (* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))
\begin{array}{l}
\\
c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (c x y) :precision binary64 (* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))
\begin{array}{l}
\\
c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right)
\end{array}
(FPCore (c x y) :precision binary64 (let* ((t_0 (* c (log1p (* (expm1 x) y))))) (if (<= y -1.8e-274) t_0 (if (<= y 1.45e-208) (* (* c y) x) t_0))))
double code(double c, double x, double y) {
double t_0 = c * log1p((expm1(x) * y));
double tmp;
if (y <= -1.8e-274) {
tmp = t_0;
} else if (y <= 1.45e-208) {
tmp = (c * y) * x;
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double c, double x, double y) {
double t_0 = c * Math.log1p((Math.expm1(x) * y));
double tmp;
if (y <= -1.8e-274) {
tmp = t_0;
} else if (y <= 1.45e-208) {
tmp = (c * y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(c, x, y): t_0 = c * math.log1p((math.expm1(x) * y)) tmp = 0 if y <= -1.8e-274: tmp = t_0 elif y <= 1.45e-208: tmp = (c * y) * x else: tmp = t_0 return tmp
function code(c, x, y) t_0 = Float64(c * log1p(Float64(expm1(x) * y))) tmp = 0.0 if (y <= -1.8e-274) tmp = t_0; elseif (y <= 1.45e-208) tmp = Float64(Float64(c * y) * x); else tmp = t_0; end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(c * N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.8e-274], t$95$0, If[LessEqual[y, 1.45e-208], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{-274}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-208}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.79999999999999991e-274 or 1.45e-208 < y Initial program 33.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6433.7
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6450.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.1
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6496.2
Applied rewrites96.2%
if -1.79999999999999991e-274 < y < 1.45e-208Initial program 49.6%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6494.8
Applied rewrites94.8%
Final simplification96.1%
(FPCore (c x y) :precision binary64 (if (<= x -2.6e-10) (* (* (expm1 x) y) c) (* (log1p (* x y)) c)))
double code(double c, double x, double y) {
double tmp;
if (x <= -2.6e-10) {
tmp = (expm1(x) * y) * c;
} else {
tmp = log1p((x * y)) * c;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (x <= -2.6e-10) {
tmp = (Math.expm1(x) * y) * c;
} else {
tmp = Math.log1p((x * y)) * c;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -2.6e-10: tmp = (math.expm1(x) * y) * c else: tmp = math.log1p((x * y)) * c return tmp
function code(c, x, y) tmp = 0.0 if (x <= -2.6e-10) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(log1p(Float64(x * y)) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -2.6e-10], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[Log[1 + N[(x * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-10}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(x \cdot y\right) \cdot c\\
\end{array}
\end{array}
if x < -2.59999999999999981e-10Initial program 47.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6447.0
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6472.5
Applied rewrites72.5%
if -2.59999999999999981e-10 < x Initial program 30.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6430.7
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6431.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6431.8
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6490.0
Applied rewrites90.0%
Taylor expanded in x around 0
lower-*.f6489.1
Applied rewrites89.1%
(FPCore (c x y) :precision binary64 (if (<= x -3.8e-29) (* (* (expm1 x) y) c) (* (* c y) x)))
double code(double c, double x, double y) {
double tmp;
if (x <= -3.8e-29) {
tmp = (expm1(x) * y) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (x <= -3.8e-29) {
tmp = (Math.expm1(x) * y) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -3.8e-29: tmp = (math.expm1(x) * y) * c else: tmp = (c * y) * x return tmp
function code(c, x, y) tmp = 0.0 if (x <= -3.8e-29) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(Float64(c * y) * x); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -3.8e-29], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-29}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\end{array}
\end{array}
if x < -3.79999999999999976e-29Initial program 43.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.7
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6491.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.2
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.9
Applied rewrites71.9%
if -3.79999999999999976e-29 < x Initial program 31.6%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6482.9
Applied rewrites82.9%
(FPCore (c x y) :precision binary64 (if (<= x -66.0) (* (* (* (- y) y) (/ x (- (* (* 0.5 (- y (* y y))) x) y))) c) (* (* c y) x)))
double code(double c, double x, double y) {
double tmp;
if (x <= -66.0) {
tmp = ((-y * y) * (x / (((0.5 * (y - (y * y))) * x) - y))) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
real(8) function code(c, x, y)
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-66.0d0)) then
tmp = ((-y * y) * (x / (((0.5d0 * (y - (y * y))) * x) - y))) * c
else
tmp = (c * y) * x
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (x <= -66.0) {
tmp = ((-y * y) * (x / (((0.5 * (y - (y * y))) * x) - y))) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -66.0: tmp = ((-y * y) * (x / (((0.5 * (y - (y * y))) * x) - y))) * c else: tmp = (c * y) * x return tmp
function code(c, x, y) tmp = 0.0 if (x <= -66.0) tmp = Float64(Float64(Float64(Float64(-y) * y) * Float64(x / Float64(Float64(Float64(0.5 * Float64(y - Float64(y * y))) * x) - y))) * c); else tmp = Float64(Float64(c * y) * x); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (x <= -66.0) tmp = ((-y * y) * (x / (((0.5 * (y - (y * y))) * x) - y))) * c; else tmp = (c * y) * x; end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[x, -66.0], N[(N[(N[((-y) * y), $MachinePrecision] * N[(x / N[(N[(N[(0.5 * N[(y - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -66:\\
\;\;\;\;\left(\left(\left(-y\right) \cdot y\right) \cdot \frac{x}{\left(0.5 \cdot \left(y - y \cdot y\right)\right) \cdot x - y}\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\end{array}
\end{array}
if x < -66Initial program 49.4%
Taylor expanded in x around 0
*-commutativeN/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites4.4%
Applied rewrites4.2%
Taylor expanded in x around 0
Applied rewrites25.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6425.0
Applied rewrites25.2%
if -66 < x Initial program 30.1%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6481.6
Applied rewrites81.6%
Final simplification66.4%
(FPCore (c x y) :precision binary64 (if (<= x -66.0) (* (/ (* (* (- y) y) x) (- (* (* 0.5 (- y (* y y))) x) y)) c) (* (* c y) x)))
double code(double c, double x, double y) {
double tmp;
if (x <= -66.0) {
tmp = (((-y * y) * x) / (((0.5 * (y - (y * y))) * x) - y)) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
real(8) function code(c, x, y)
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-66.0d0)) then
tmp = (((-y * y) * x) / (((0.5d0 * (y - (y * y))) * x) - y)) * c
else
tmp = (c * y) * x
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (x <= -66.0) {
tmp = (((-y * y) * x) / (((0.5 * (y - (y * y))) * x) - y)) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -66.0: tmp = (((-y * y) * x) / (((0.5 * (y - (y * y))) * x) - y)) * c else: tmp = (c * y) * x return tmp
function code(c, x, y) tmp = 0.0 if (x <= -66.0) tmp = Float64(Float64(Float64(Float64(Float64(-y) * y) * x) / Float64(Float64(Float64(0.5 * Float64(y - Float64(y * y))) * x) - y)) * c); else tmp = Float64(Float64(c * y) * x); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (x <= -66.0) tmp = (((-y * y) * x) / (((0.5 * (y - (y * y))) * x) - y)) * c; else tmp = (c * y) * x; end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[x, -66.0], N[(N[(N[(N[((-y) * y), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[(0.5 * N[(y - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -66:\\
\;\;\;\;\frac{\left(\left(-y\right) \cdot y\right) \cdot x}{\left(0.5 \cdot \left(y - y \cdot y\right)\right) \cdot x - y} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\end{array}
\end{array}
if x < -66Initial program 49.4%
Taylor expanded in x around 0
*-commutativeN/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites4.4%
Applied rewrites4.2%
Taylor expanded in x around 0
Applied rewrites25.0%
if -66 < x Initial program 30.1%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6481.6
Applied rewrites81.6%
Final simplification66.3%
(FPCore (c x y) :precision binary64 (if (<= x -66.0) (* (/ (* (* (- y) y) x) (* (* (fma (- y) y y) x) 0.5)) c) (* (* c y) x)))
double code(double c, double x, double y) {
double tmp;
if (x <= -66.0) {
tmp = (((-y * y) * x) / ((fma(-y, y, y) * x) * 0.5)) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -66.0) tmp = Float64(Float64(Float64(Float64(Float64(-y) * y) * x) / Float64(Float64(fma(Float64(-y), y, y) * x) * 0.5)) * c); else tmp = Float64(Float64(c * y) * x); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -66.0], N[(N[(N[(N[((-y) * y), $MachinePrecision] * x), $MachinePrecision] / N[(N[(N[((-y) * y + y), $MachinePrecision] * x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -66:\\
\;\;\;\;\frac{\left(\left(-y\right) \cdot y\right) \cdot x}{\left(\mathsf{fma}\left(-y, y, y\right) \cdot x\right) \cdot 0.5} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\end{array}
\end{array}
if x < -66Initial program 49.4%
Taylor expanded in x around 0
*-commutativeN/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites4.4%
Applied rewrites4.2%
Taylor expanded in x around 0
Applied rewrites25.0%
Taylor expanded in x around inf
Applied rewrites25.0%
if -66 < x Initial program 30.1%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6481.6
Applied rewrites81.6%
Final simplification66.3%
(FPCore (c x y) :precision binary64 (if (<= x -110.0) (* (/ (* (* (- y) y) x) (* (fma 0.5 x -1.0) y)) c) (* (* c y) x)))
double code(double c, double x, double y) {
double tmp;
if (x <= -110.0) {
tmp = (((-y * y) * x) / (fma(0.5, x, -1.0) * y)) * c;
} else {
tmp = (c * y) * x;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -110.0) tmp = Float64(Float64(Float64(Float64(Float64(-y) * y) * x) / Float64(fma(0.5, x, -1.0) * y)) * c); else tmp = Float64(Float64(c * y) * x); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -110.0], N[(N[(N[(N[((-y) * y), $MachinePrecision] * x), $MachinePrecision] / N[(N[(0.5 * x + -1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -110:\\
\;\;\;\;\frac{\left(\left(-y\right) \cdot y\right) \cdot x}{\mathsf{fma}\left(0.5, x, -1\right) \cdot y} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\end{array}
\end{array}
if x < -110Initial program 49.4%
Taylor expanded in x around 0
*-commutativeN/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites4.4%
Applied rewrites4.2%
Taylor expanded in x around 0
Applied rewrites25.0%
Taylor expanded in y around 0
Applied rewrites24.8%
if -110 < x Initial program 30.1%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6481.6
Applied rewrites81.6%
Final simplification66.3%
(FPCore (c x y) :precision binary64 (* (* c y) x))
double code(double c, double x, double y) {
return (c * y) * x;
}
real(8) function code(c, x, y)
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (c * y) * x
end function
public static double code(double c, double x, double y) {
return (c * y) * x;
}
def code(c, x, y): return (c * y) * x
function code(c, x, y) return Float64(Float64(c * y) * x) end
function tmp = code(c, x, y) tmp = (c * y) * x; end
code[c_, x_, y_] := N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(c \cdot y\right) \cdot x
\end{array}
Initial program 35.3%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
*-commutativeN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-rgt-identityN/A
lower-*.f6464.6
Applied rewrites64.6%
(FPCore (c x y) :precision binary64 (* c (log1p (* (expm1 x) y))))
double code(double c, double x, double y) {
return c * log1p((expm1(x) * y));
}
public static double code(double c, double x, double y) {
return c * Math.log1p((Math.expm1(x) * y));
}
def code(c, x, y): return c * math.log1p((math.expm1(x) * y))
function code(c, x, y) return Float64(c * log1p(Float64(expm1(x) * y))) end
code[c_, x_, y_] := N[(c * N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)
\end{array}
herbie shell --seed 2024276
(FPCore (c x y)
:name "Logarithmic Transform"
:precision binary64
:alt
(* c (log1p (* (expm1 x) y)))
(* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))