
(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 10 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 (if (or (<= y -2e-106) (not (<= y 2e-11))) (* (log1p (* (expm1 x) y)) c) (* (fma -0.5 (* (pow (expm1 x) 2.0) y) (expm1 x)) (* c y))))
double code(double c, double x, double y) {
double tmp;
if ((y <= -2e-106) || !(y <= 2e-11)) {
tmp = log1p((expm1(x) * y)) * c;
} else {
tmp = fma(-0.5, (pow(expm1(x), 2.0) * y), expm1(x)) * (c * y);
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if ((y <= -2e-106) || !(y <= 2e-11)) tmp = Float64(log1p(Float64(expm1(x) * y)) * c); else tmp = Float64(fma(-0.5, Float64((expm1(x) ^ 2.0) * y), expm1(x)) * Float64(c * y)); end return tmp end
code[c_, x_, y_] := If[Or[LessEqual[y, -2e-106], N[Not[LessEqual[y, 2e-11]], $MachinePrecision]], N[(N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(-0.5 * N[(N[Power[N[(Exp[x] - 1), $MachinePrecision], 2.0], $MachinePrecision] * y), $MachinePrecision] + N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision] * N[(c * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-106} \lor \neg \left(y \leq 2 \cdot 10^{-11}\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, {\left(\mathsf{expm1}\left(x\right)\right)}^{2} \cdot y, \mathsf{expm1}\left(x\right)\right) \cdot \left(c \cdot y\right)\\
\end{array}
\end{array}
if y < -1.99999999999999988e-106 or 1.99999999999999988e-11 < y Initial program 35.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.2
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6442.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.6
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Applied rewrites99.6%
if -1.99999999999999988e-106 < y < 1.99999999999999988e-11Initial program 35.0%
Taylor expanded in y around 0
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites69.7%
Applied rewrites99.1%
Final simplification99.4%
(FPCore (c x y)
:precision binary64
(if (or (<= c 1.1e+177) (not (<= c 4e+231)))
(* (log1p (* (expm1 x) y)) c)
(*
(* c (fma (* (pow (- (pow (E) x) 1.0) 2.0) y) -0.5 (* (fma 0.5 x 1.0) x)))
y)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 1.1 \cdot 10^{+177} \lor \neg \left(c \leq 4 \cdot 10^{+231}\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot \mathsf{fma}\left({\left({\mathsf{E}\left(\right)}^{x} - 1\right)}^{2} \cdot y, -0.5, \mathsf{fma}\left(0.5, x, 1\right) \cdot x\right)\right) \cdot y\\
\end{array}
\end{array}
if c < 1.0999999999999999e177 or 4.0000000000000002e231 < c Initial program 37.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.1
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6459.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.5
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6495.3
Applied rewrites95.3%
Applied rewrites95.3%
if 1.0999999999999999e177 < c < 4.0000000000000002e231Initial program 4.4%
Taylor expanded in y around 0
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites10.5%
Taylor expanded in x around 0
Applied rewrites93.2%
Final simplification95.1%
(FPCore (c x y)
:precision binary64
(if (or (<= c 1.1e+177) (not (<= c 4e+231)))
(* (log1p (* (expm1 x) y)) c)
(*
(*
(fma
(* (* x x) y)
(fma (fma -0.2916666666666667 x -0.5) x -0.5)
(*
(fma (fma (fma 0.041666666666666664 x 0.16666666666666666) x 0.5) x 1.0)
x))
c)
y)))
double code(double c, double x, double y) {
double tmp;
if ((c <= 1.1e+177) || !(c <= 4e+231)) {
tmp = log1p((expm1(x) * y)) * c;
} else {
tmp = (fma(((x * x) * y), fma(fma(-0.2916666666666667, x, -0.5), x, -0.5), (fma(fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5), x, 1.0) * x)) * c) * y;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if ((c <= 1.1e+177) || !(c <= 4e+231)) tmp = Float64(log1p(Float64(expm1(x) * y)) * c); else tmp = Float64(Float64(fma(Float64(Float64(x * x) * y), fma(fma(-0.2916666666666667, x, -0.5), x, -0.5), Float64(fma(fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5), x, 1.0) * x)) * c) * y); end return tmp end
code[c_, x_, y_] := If[Or[LessEqual[c, 1.1e+177], N[Not[LessEqual[c, 4e+231]], $MachinePrecision]], N[(N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * y), $MachinePrecision] * N[(N[(-0.2916666666666667 * x + -0.5), $MachinePrecision] * x + -0.5), $MachinePrecision] + N[(N[(N[(N[(0.041666666666666664 * x + 0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 1.1 \cdot 10^{+177} \lor \neg \left(c \leq 4 \cdot 10^{+231}\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\left(x \cdot x\right) \cdot y, \mathsf{fma}\left(\mathsf{fma}\left(-0.2916666666666667, x, -0.5\right), x, -0.5\right), \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 c\right) \cdot y\\
\end{array}
\end{array}
if c < 1.0999999999999999e177 or 4.0000000000000002e231 < c Initial program 37.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.1
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6459.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.5
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6495.3
Applied rewrites95.3%
Applied rewrites95.3%
if 1.0999999999999999e177 < c < 4.0000000000000002e231Initial program 4.4%
Taylor expanded in y around 0
*-commutativeN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites10.5%
Taylor expanded in x around 0
Applied rewrites81.3%
Taylor expanded in y around 0
Applied rewrites93.2%
Taylor expanded in c around 0
Applied rewrites93.2%
Final simplification95.1%
(FPCore (c x y)
:precision binary64
(if (<= x -0.066)
(* (* (expm1 x) y) c)
(if (or (<= x -2.6e-191) (not (<= x 4.2e-208)))
(*
(log1p
(*
y
(fma
(* (fma (fma 0.041666666666666664 x 0.16666666666666666) x 0.5) x)
x
x)))
c)
(* (* x c) y))))
double code(double c, double x, double y) {
double tmp;
if (x <= -0.066) {
tmp = (expm1(x) * y) * c;
} else if ((x <= -2.6e-191) || !(x <= 4.2e-208)) {
tmp = log1p((y * fma((fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5) * x), x, x))) * c;
} else {
tmp = (x * c) * y;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -0.066) tmp = Float64(Float64(expm1(x) * y) * c); elseif ((x <= -2.6e-191) || !(x <= 4.2e-208)) tmp = Float64(log1p(Float64(y * fma(Float64(fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5) * x), x, x))) * c); else tmp = Float64(Float64(x * c) * y); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -0.066], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], If[Or[LessEqual[x, -2.6e-191], N[Not[LessEqual[x, 4.2e-208]], $MachinePrecision]], N[(N[Log[1 + N[(y * N[(N[(N[(N[(0.041666666666666664 * x + 0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.066:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-191} \lor \neg \left(x \leq 4.2 \cdot 10^{-208}\right):\\
\;\;\;\;\mathsf{log1p}\left(y \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x, 0.16666666666666666\right), x, 0.5\right) \cdot x, x, x\right)\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\end{array}
\end{array}
if x < -0.066000000000000003Initial program 43.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.6
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
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.6
Applied rewrites71.6%
if -0.066000000000000003 < x < -2.59999999999999986e-191 or 4.20000000000000024e-208 < x Initial program 26.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.0
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6428.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.6
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6492.3
Applied rewrites92.3%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6489.9
Applied rewrites89.9%
if -2.59999999999999986e-191 < x < 4.20000000000000024e-208Initial program 38.7%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6482.7
Applied rewrites82.7%
Applied rewrites95.8%
Final simplification84.6%
(FPCore (c x y)
:precision binary64
(let* ((t_0 (fma (fma 0.041666666666666664 x 0.16666666666666666) x 0.5)))
(if (<= x -0.066)
(* (* (expm1 x) y) c)
(if (<= x -2.6e-191)
(* (log1p (* (* (fma t_0 x 1.0) x) y)) c)
(if (<= x 4.2e-208)
(* (* x c) y)
(* (log1p (* y (fma (* t_0 x) x x))) c))))))
double code(double c, double x, double y) {
double t_0 = fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5);
double tmp;
if (x <= -0.066) {
tmp = (expm1(x) * y) * c;
} else if (x <= -2.6e-191) {
tmp = log1p(((fma(t_0, x, 1.0) * x) * y)) * c;
} else if (x <= 4.2e-208) {
tmp = (x * c) * y;
} else {
tmp = log1p((y * fma((t_0 * x), x, x))) * c;
}
return tmp;
}
function code(c, x, y) t_0 = fma(fma(0.041666666666666664, x, 0.16666666666666666), x, 0.5) tmp = 0.0 if (x <= -0.066) tmp = Float64(Float64(expm1(x) * y) * c); elseif (x <= -2.6e-191) tmp = Float64(log1p(Float64(Float64(fma(t_0, x, 1.0) * x) * y)) * c); elseif (x <= 4.2e-208) tmp = Float64(Float64(x * c) * y); else tmp = Float64(log1p(Float64(y * fma(Float64(t_0 * x), x, x))) * c); end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(N[(0.041666666666666664 * x + 0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision]}, If[LessEqual[x, -0.066], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], If[LessEqual[x, -2.6e-191], N[(N[Log[1 + N[(N[(N[(t$95$0 * x + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[x, 4.2e-208], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision], N[(N[Log[1 + N[(y * N[(N[(t$95$0 * x), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x, 0.16666666666666666\right), x, 0.5\right)\\
\mathbf{if}\;x \leq -0.066:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-191}:\\
\;\;\;\;\mathsf{log1p}\left(\left(\mathsf{fma}\left(t\_0, x, 1\right) \cdot x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-208}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(y \cdot \mathsf{fma}\left(t\_0 \cdot x, x, x\right)\right) \cdot c\\
\end{array}
\end{array}
if x < -0.066000000000000003Initial program 43.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.6
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
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.6
Applied rewrites71.6%
if -0.066000000000000003 < x < -2.59999999999999986e-191Initial program 22.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6422.8
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6426.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.7
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6495.5
Applied rewrites95.5%
Applied rewrites95.5%
Taylor expanded in x around 0
Applied rewrites94.4%
if -2.59999999999999986e-191 < x < 4.20000000000000024e-208Initial program 38.7%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6482.7
Applied rewrites82.7%
Applied rewrites95.8%
if 4.20000000000000024e-208 < x Initial program 28.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.6
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6430.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6430.2
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6489.7
Applied rewrites89.7%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6486.3
Applied rewrites86.3%
Final simplification84.6%
(FPCore (c x y)
:precision binary64
(if (<= x -235.0)
(* (* (expm1 x) y) c)
(if (or (<= x -2.6e-191) (not (<= x 4.2e-208)))
(* (log1p (* y (* (fma (fma 0.16666666666666666 x 0.5) x 1.0) x))) c)
(* (* x c) y))))
double code(double c, double x, double y) {
double tmp;
if (x <= -235.0) {
tmp = (expm1(x) * y) * c;
} else if ((x <= -2.6e-191) || !(x <= 4.2e-208)) {
tmp = log1p((y * (fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x))) * c;
} else {
tmp = (x * c) * y;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -235.0) tmp = Float64(Float64(expm1(x) * y) * c); elseif ((x <= -2.6e-191) || !(x <= 4.2e-208)) tmp = Float64(log1p(Float64(y * Float64(fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x))) * c); else tmp = Float64(Float64(x * c) * y); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -235.0], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], If[Or[LessEqual[x, -2.6e-191], N[Not[LessEqual[x, 4.2e-208]], $MachinePrecision]], N[(N[Log[1 + N[(y * N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -235:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-191} \lor \neg \left(x \leq 4.2 \cdot 10^{-208}\right):\\
\;\;\;\;\mathsf{log1p}\left(y \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right) \cdot x\right)\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\end{array}
\end{array}
if x < -235Initial program 43.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.0
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
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6472.3
Applied rewrites72.3%
if -235 < x < -2.59999999999999986e-191 or 4.20000000000000024e-208 < x Initial program 26.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.6
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6429.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.3
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6492.4
Applied rewrites92.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6488.9
Applied rewrites88.9%
if -2.59999999999999986e-191 < x < 4.20000000000000024e-208Initial program 38.7%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6482.7
Applied rewrites82.7%
Applied rewrites95.8%
Final simplification84.5%
(FPCore (c x y)
:precision binary64
(if (<= x -0.0028)
(* (* (expm1 x) y) c)
(if (or (<= x -2.6e-191) (not (<= x 4.2e-208)))
(* (log1p (* y (* (fma 0.5 x 1.0) x))) c)
(* (* x c) y))))
double code(double c, double x, double y) {
double tmp;
if (x <= -0.0028) {
tmp = (expm1(x) * y) * c;
} else if ((x <= -2.6e-191) || !(x <= 4.2e-208)) {
tmp = log1p((y * (fma(0.5, x, 1.0) * x))) * c;
} else {
tmp = (x * c) * y;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (x <= -0.0028) tmp = Float64(Float64(expm1(x) * y) * c); elseif ((x <= -2.6e-191) || !(x <= 4.2e-208)) tmp = Float64(log1p(Float64(y * Float64(fma(0.5, x, 1.0) * x))) * c); else tmp = Float64(Float64(x * c) * y); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -0.0028], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], If[Or[LessEqual[x, -2.6e-191], N[Not[LessEqual[x, 4.2e-208]], $MachinePrecision]], N[(N[Log[1 + N[(y * N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0028:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-191} \lor \neg \left(x \leq 4.2 \cdot 10^{-208}\right):\\
\;\;\;\;\mathsf{log1p}\left(y \cdot \left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right)\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\end{array}
\end{array}
if x < -0.00279999999999999997Initial program 43.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.8
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6471.2
Applied rewrites71.2%
if -0.00279999999999999997 < x < -2.59999999999999986e-191 or 4.20000000000000024e-208 < x Initial program 25.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6425.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6427.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6427.3
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6492.2
Applied rewrites92.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6489.7
Applied rewrites89.7%
if -2.59999999999999986e-191 < x < 4.20000000000000024e-208Initial program 38.7%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6482.7
Applied rewrites82.7%
Applied rewrites95.8%
Final simplification84.2%
(FPCore (c x y) :precision binary64 (if (<= x -3.6e-18) (* (* (expm1 x) y) c) (* (* x c) y)))
double code(double c, double x, double y) {
double tmp;
if (x <= -3.6e-18) {
tmp = (expm1(x) * y) * c;
} else {
tmp = (x * c) * y;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (x <= -3.6e-18) {
tmp = (Math.expm1(x) * y) * c;
} else {
tmp = (x * c) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if x <= -3.6e-18: tmp = (math.expm1(x) * y) * c else: tmp = (x * c) * y return tmp
function code(c, x, y) tmp = 0.0 if (x <= -3.6e-18) tmp = Float64(Float64(expm1(x) * y) * c); else tmp = Float64(Float64(x * c) * y); end return tmp end
code[c_, x_, y_] := If[LessEqual[x, -3.6e-18], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision] * c), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-18}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\end{array}
\end{array}
if x < -3.6000000000000001e-18Initial program 43.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.2
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6497.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.4
lift--.f64N/A
lift-pow.f64N/A
pow-to-expN/A
lower-expm1.f64N/A
lift-E.f64N/A
log-EN/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6470.7
Applied rewrites70.7%
if -3.6000000000000001e-18 < x Initial program 30.0%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6471.3
Applied rewrites71.3%
Applied rewrites77.2%
Final simplification74.7%
(FPCore (c x y) :precision binary64 (if (<= c 1e-7) (* (* c y) x) (* (* x c) y)))
double code(double c, double x, double y) {
double tmp;
if (c <= 1e-7) {
tmp = (c * y) * x;
} else {
tmp = (x * c) * y;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(c, x, y)
use fmin_fmax_functions
real(8), intent (in) :: c
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (c <= 1d-7) then
tmp = (c * y) * x
else
tmp = (x * c) * y
end if
code = tmp
end function
public static double code(double c, double x, double y) {
double tmp;
if (c <= 1e-7) {
tmp = (c * y) * x;
} else {
tmp = (x * c) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if c <= 1e-7: tmp = (c * y) * x else: tmp = (x * c) * y return tmp
function code(c, x, y) tmp = 0.0 if (c <= 1e-7) tmp = Float64(Float64(c * y) * x); else tmp = Float64(Float64(x * c) * y); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (c <= 1e-7) tmp = (c * y) * x; else tmp = (x * c) * y; end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[c, 1e-7], N[(N[(c * y), $MachinePrecision] * x), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 10^{-7}:\\
\;\;\;\;\left(c \cdot y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\
\end{array}
\end{array}
if c < 9.9999999999999995e-8Initial program 43.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
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
lower-*.f6449.9
Applied rewrites49.9%
if 9.9999999999999995e-8 < c Initial program 17.9%
Taylor expanded in x around 0
associate-*r*N/A
log-EN/A
*-rgt-identityN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/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
*-commutativeN/A
*-lft-identityN/A
lower-*.f6450.8
Applied rewrites50.8%
Applied rewrites60.3%
Final simplification53.2%
(FPCore (c x y) :precision binary64 (* (* c y) x))
double code(double c, double x, double y) {
return (c * y) * x;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(c, x, y)
use fmin_fmax_functions
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.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
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
log-EN/A
metadata-evalN/A
log-EN/A
lower-*.f64N/A
log-EN/A
*-commutativeN/A
*-lft-identityN/A
lower-*.f6450.2
Applied rewrites50.2%
Final simplification50.2%
(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 2025015
(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)))))