
(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 7 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 (* 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}
Initial program 42.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.6
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6458.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6458.6
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6493.6
Applied rewrites93.6%
Final simplification93.6%
(FPCore (c x y)
:precision binary64
(if (<= x -0.0125)
(* (* (expm1 x) y) c)
(*
(log1p
(*
(*
(fma (fma (fma 0.041666666666666664 x 0.16666666666666666) x 0.5) x 1.0)
x)
y))
c)))
double code(double c, double x, double y) {
double tmp;
if (x <= -0.0125) {
tmp = (expm1(x) * y) * c;
} else {
tmp = log1p(((fma(fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5), x, 1.0) * x) * y)) * c;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -0.0125) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(log1p(Float64(Float64(fma(fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5), x, 1.0) * x) * y)) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -0.0125], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[Log[1 + N[(N[(N[(N[(N[(0.041666666666666664 * x + 0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0125:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x, 0.16666666666666666\right), x, 0.5\right), x, 1\right) \cdot x\right) \cdot y\right) \cdot c\\
\end{array}
\end{array}
if x < -0.012500000000000001Initial program 45.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.3
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
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
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.4
Applied rewrites71.4%
if -0.012500000000000001 < x Initial program 41.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6441.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.8
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6491.1
Applied rewrites91.1%
Taylor expanded in x around 0
*-commutativeN/A
Applied rewrites90.1%
Final simplification84.7%
(FPCore (c x y) :precision binary64 (if (<= x -0.011) (* (* (expm1 x) y) c) (* (log1p (* (* (fma (fma 0.16666666666666666 x 0.5) x 1.0) x) y)) c)))
double code(double c, double x, double y) {
double tmp;
if (x <= -0.011) {
tmp = (expm1(x) * y) * c;
} else {
tmp = log1p(((fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x) * y)) * c;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -0.011) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(log1p(Float64(Float64(fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x) * y)) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -0.011], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[Log[1 + N[(N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.011:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right) \cdot x\right) \cdot y\right) \cdot c\\
\end{array}
\end{array}
if x < -0.010999999999999999Initial program 45.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.3
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
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
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.4
Applied rewrites71.4%
if -0.010999999999999999 < x Initial program 41.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6441.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.8
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6491.1
Applied rewrites91.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6490.1
Applied rewrites90.1%
Final simplification84.7%
(FPCore (c x y) :precision binary64 (if (<= x -0.000108) (* (* (expm1 x) y) c) (* (log1p (* (* (fma 0.5 x 1.0) x) y)) c)))
double code(double c, double x, double y) {
double tmp;
if (x <= -0.000108) {
tmp = (expm1(x) * y) * c;
} else {
tmp = log1p(((fma(0.5, x, 1.0) * x) * y)) * c;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -0.000108) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(log1p(Float64(Float64(fma(0.5, x, 1.0) * x) * y)) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -0.000108], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[Log[1 + N[(N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000108:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right) \cdot y\right) \cdot c\\
\end{array}
\end{array}
if x < -1.08e-4Initial program 45.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.3
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
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
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.4
Applied rewrites71.4%
if -1.08e-4 < x Initial program 41.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6441.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.8
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lift-E.f64N/A
log-EN/A
*-lft-identityN/A
lower-expm1.f6491.1
Applied rewrites91.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6490.1
Applied rewrites90.1%
Final simplification84.7%
(FPCore (c x y) :precision binary64 (if (<= x -4.7e-14) (* (* (expm1 x) y) c) (* (* c x) y)))
double code(double c, double x, double y) {
double tmp;
if (x <= -4.7e-14) {
tmp = (expm1(x) * y) * c;
} else {
tmp = (c * x) * y;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (x <= -4.7e-14) {
tmp = (Math.expm1(x) * y) * c;
} else {
tmp = (c * x) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -4.7e-14: tmp = (math.expm1(x) * y) * c else: tmp = (c * x) * y return tmp
function code(c, x, y) tmp = 0.0 if (x <= -4.7e-14) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(Float64(c * x) * y); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -4.7e-14], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[(c * x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{-14}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot x\right) \cdot y\\
\end{array}
\end{array}
if x < -4.7000000000000002e-14Initial program 45.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
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
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6470.5
Applied rewrites70.5%
if -4.7000000000000002e-14 < x Initial program 41.3%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
lower-*.f6484.0
Applied rewrites84.0%
Applied rewrites85.2%
Final simplification80.9%
(FPCore (c x y) :precision binary64 (if (<= c 5e-70) (* (* c y) x) (* (* c x) y)))
double code(double c, double x, double y) {
double tmp;
if (c <= 5e-70) {
tmp = (c * y) * x;
} else {
tmp = (c * x) * y;
}
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 (c <= 5d-70) then
tmp = (c * y) * x
else
tmp = (c * x) * y
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (c <= 5e-70) {
tmp = (c * y) * x;
} else {
tmp = (c * x) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if c <= 5e-70: tmp = (c * y) * x else: tmp = (c * x) * y return tmp
function code(c, x, y) tmp = 0.0 if (c <= 5e-70) tmp = Float64(Float64(c * y) * x); else tmp = Float64(Float64(c * x) * y); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (c <= 5e-70) tmp = (c * y) * x; else tmp = (c * x) * y; end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[c, 5e-70], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision], N[(N[(c * x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 5 \cdot 10^{-70}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot x\right) \cdot y\\
\end{array}
\end{array}
if c < 4.9999999999999998e-70Initial program 48.7%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
lower-*.f6465.1
Applied rewrites65.1%
if 4.9999999999999998e-70 < c Initial program 23.8%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
lower-*.f6460.8
Applied rewrites60.8%
Applied rewrites67.0%
Final simplification65.6%
(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 42.6%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
lower-*.f6464.0
Applied rewrites64.0%
(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 2024332
(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)))))