
(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 11 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 (expm1 (* 3.0 x))) (t_1 (- (exp x) -1.0)))
(if (<= y -3e-123)
(* (log1p (* (expm1 x) y)) c)
(if (<= y 530000000000.0)
(* (/ (* t_0 c) (fma (exp x) (exp x) t_1)) y)
(*
(log1p
(*
(/ (* y t_0) (+ (pow (exp x) 6.0) (pow t_1 3.0)))
(fma t_1 (- t_1 (pow (exp x) 2.0)) (pow (exp x) 4.0))))
c)))))
double code(double c, double x, double y) {
double t_0 = expm1((3.0 * x));
double t_1 = exp(x) - -1.0;
double tmp;
if (y <= -3e-123) {
tmp = log1p((expm1(x) * y)) * c;
} else if (y <= 530000000000.0) {
tmp = ((t_0 * c) / fma(exp(x), exp(x), t_1)) * y;
} else {
tmp = log1p((((y * t_0) / (pow(exp(x), 6.0) + pow(t_1, 3.0))) * fma(t_1, (t_1 - pow(exp(x), 2.0)), pow(exp(x), 4.0)))) * c;
}
return tmp;
}
function code(c, x, y) t_0 = expm1(Float64(3.0 * x)) t_1 = Float64(exp(x) - -1.0) tmp = 0.0 if (y <= -3e-123) tmp = Float64(log1p(Float64(expm1(x) * y)) * c); elseif (y <= 530000000000.0) tmp = Float64(Float64(Float64(t_0 * c) / fma(exp(x), exp(x), t_1)) * y); else tmp = Float64(log1p(Float64(Float64(Float64(y * t_0) / Float64((exp(x) ^ 6.0) + (t_1 ^ 3.0))) * fma(t_1, Float64(t_1 - (exp(x) ^ 2.0)), (exp(x) ^ 4.0)))) * c); end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(Exp[N[(3.0 * x), $MachinePrecision]] - 1), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[x], $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[y, -3e-123], N[(N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[y, 530000000000.0], N[(N[(N[(t$95$0 * c), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] * N[Exp[x], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], N[(N[Log[1 + N[(N[(N[(y * t$95$0), $MachinePrecision] / N[(N[Power[N[Exp[x], $MachinePrecision], 6.0], $MachinePrecision] + N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * N[(t$95$1 - N[Power[N[Exp[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[Power[N[Exp[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{expm1}\left(3 \cdot x\right)\\
t_1 := e^{x} - -1\\
\mathbf{if}\;y \leq -3 \cdot 10^{-123}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{elif}\;y \leq 530000000000:\\
\;\;\;\;\frac{t\_0 \cdot c}{\mathsf{fma}\left(e^{x}, e^{x}, t\_1\right)} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\frac{y \cdot t\_0}{{\left(e^{x}\right)}^{6} + {t\_1}^{3}} \cdot \mathsf{fma}\left(t\_1, t\_1 - {\left(e^{x}\right)}^{2}, {\left(e^{x}\right)}^{4}\right)\right) \cdot c\\
\end{array}
\end{array}
if y < -2.99999999999999984e-123Initial program 47.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6447.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6456.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6456.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.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
lift-*.f64N/A
*-rgt-identity99.7
Applied rewrites99.7%
if -2.99999999999999984e-123 < y < 5.3e11Initial program 40.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.0
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6461.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6461.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-*.f6485.1
Applied rewrites85.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6485.1
lift-*.f64N/A
*-rgt-identity85.1
Applied rewrites85.1%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.8
Applied rewrites99.8%
Applied rewrites99.8%
if 5.3e11 < y Initial program 13.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6413.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.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-*.f6497.3
Applied rewrites97.3%
lift-*.f64N/A
*-commutativeN/A
lift-expm1.f64N/A
flip3--N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites97.3%
lift-/.f64N/A
lift-fma.f64N/A
flip3-+N/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites97.3%
Final simplification99.3%
(FPCore (c x y) :precision binary64 (if (or (<= y -3e-123) (not (<= y 5.5e-21))) (* (log1p (* (expm1 x) y)) c) (* (/ (* (expm1 (* 3.0 x)) c) (fma (exp x) (exp x) (- (exp x) -1.0))) y)))
double code(double c, double x, double y) {
double tmp;
if ((y <= -3e-123) || !(y <= 5.5e-21)) {
tmp = log1p((expm1(x) * y)) * c;
} else {
tmp = ((expm1((3.0 * x)) * c) / fma(exp(x), exp(x), (exp(x) - -1.0))) * y;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if ((y <= -3e-123) || !(y <= 5.5e-21)) tmp = Float64(log1p(Float64(expm1(x) * y)) * c); else tmp = Float64(Float64(Float64(expm1(Float64(3.0 * x)) * c) / fma(exp(x), exp(x), Float64(exp(x) - -1.0))) * y); end return tmp end
code[c_, x_, y_] := If[Or[LessEqual[y, -3e-123], N[Not[LessEqual[y, 5.5e-21]], $MachinePrecision]], N[(N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(N[(N[(Exp[N[(3.0 * x), $MachinePrecision]] - 1), $MachinePrecision] * c), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] * N[Exp[x], $MachinePrecision] + N[(N[Exp[x], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-123} \lor \neg \left(y \leq 5.5 \cdot 10^{-21}\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(3 \cdot x\right) \cdot c}{\mathsf{fma}\left(e^{x}, e^{x}, e^{x} - -1\right)} \cdot y\\
\end{array}
\end{array}
if y < -2.99999999999999984e-123 or 5.49999999999999977e-21 < y Initial program 33.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6433.2
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6440.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.1
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-*.f6498.9
Applied rewrites98.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.9
lift-*.f64N/A
*-rgt-identity98.9
Applied rewrites98.9%
if -2.99999999999999984e-123 < y < 5.49999999999999977e-21Initial program 42.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6463.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6463.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-*.f6484.1
Applied rewrites84.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6484.1
lift-*.f64N/A
*-rgt-identity84.1
Applied rewrites84.1%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.8
Applied rewrites99.8%
Applied rewrites99.8%
Final simplification99.3%
(FPCore (c x y) :precision binary64 (if (or (<= y -3.2e-13) (not (<= y 6.5e-91))) (* (log1p (* (expm1 x) y)) c) (* (* (expm1 x) c) y)))
double code(double c, double x, double y) {
double tmp;
if ((y <= -3.2e-13) || !(y <= 6.5e-91)) {
tmp = log1p((expm1(x) * y)) * c;
} else {
tmp = (expm1(x) * c) * y;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if ((y <= -3.2e-13) || !(y <= 6.5e-91)) {
tmp = Math.log1p((Math.expm1(x) * y)) * c;
} else {
tmp = (Math.expm1(x) * c) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if (y <= -3.2e-13) or not (y <= 6.5e-91): tmp = math.log1p((math.expm1(x) * y)) * c else: tmp = (math.expm1(x) * c) * y return tmp
function code(c, x, y) tmp = 0.0 if ((y <= -3.2e-13) || !(y <= 6.5e-91)) tmp = Float64(log1p(Float64(expm1(x) * y)) * c); else tmp = Float64(Float64(expm1(x) * c) * y); end return tmp end
code[c_, x_, y_] := If[Or[LessEqual[y, -3.2e-13], N[Not[LessEqual[y, 6.5e-91]], $MachinePrecision]], N[(N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-13} \lor \neg \left(y \leq 6.5 \cdot 10^{-91}\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\end{array}
\end{array}
if y < -3.2e-13 or 6.5000000000000001e-91 < y Initial program 35.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.6
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6439.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.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-*.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.8
lift-*.f64N/A
*-rgt-identity98.8
Applied rewrites98.8%
if -3.2e-13 < y < 6.5000000000000001e-91Initial program 39.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.8
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6463.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6463.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-*.f6484.3
Applied rewrites84.3%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.8
Applied rewrites99.8%
Final simplification99.3%
(FPCore (c x y)
:precision binary64
(if (<= y -150.0)
(* (log1p (* x y)) c)
(if (<= y 25000000000.0)
(* (* (expm1 x) c) y)
(*
(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 (y <= -150.0) {
tmp = log1p((x * y)) * c;
} else if (y <= 25000000000.0) {
tmp = (expm1(x) * c) * y;
} 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 (y <= -150.0) tmp = Float64(log1p(Float64(x * y)) * c); elseif (y <= 25000000000.0) tmp = Float64(Float64(expm1(x) * c) * y); 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[y, -150.0], N[(N[Log[1 + N[(x * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[y, 25000000000.0], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $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}\;y \leq -150:\\
\;\;\;\;\mathsf{log1p}\left(x \cdot y\right) \cdot c\\
\mathbf{elif}\;y \leq 25000000000:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\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 y < -150Initial program 56.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6452.5
Applied rewrites52.5%
Taylor expanded in x around 0
log-EN/A
*-commutativeN/A
lower-*.f6457.5
Applied rewrites57.5%
if -150 < y < 2.5e10Initial program 37.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.9
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6460.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6460.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-*.f6487.4
Applied rewrites87.4%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.2
Applied rewrites99.2%
if 2.5e10 < y Initial program 13.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites55.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.0
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6496.2
Applied rewrites96.2%
Final simplification89.7%
(FPCore (c x y)
:precision binary64
(if (<= y -150.0)
(* (log1p (* x y)) c)
(if (<= y 25000000000.0)
(* (* (expm1 x) c) y)
(* (log1p (* y (* (fma (fma 0.16666666666666666 x 0.5) x 1.0) x))) c))))
double code(double c, double x, double y) {
double tmp;
if (y <= -150.0) {
tmp = log1p((x * y)) * c;
} else if (y <= 25000000000.0) {
tmp = (expm1(x) * c) * y;
} else {
tmp = log1p((y * (fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x))) * c;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (y <= -150.0) tmp = Float64(log1p(Float64(x * y)) * c); elseif (y <= 25000000000.0) tmp = Float64(Float64(expm1(x) * c) * y); else tmp = Float64(log1p(Float64(y * Float64(fma(fma(0.16666666666666666, x, 0.5), x, 1.0) * x))) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[y, -150.0], N[(N[Log[1 + N[(x * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[y, 25000000000.0], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $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]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -150:\\
\;\;\;\;\mathsf{log1p}\left(x \cdot y\right) \cdot c\\
\mathbf{elif}\;y \leq 25000000000:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\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\\
\end{array}
\end{array}
if y < -150Initial program 56.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6452.5
Applied rewrites52.5%
Taylor expanded in x around 0
log-EN/A
*-commutativeN/A
lower-*.f6457.5
Applied rewrites57.5%
if -150 < y < 2.5e10Initial program 37.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.9
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6460.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6460.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-*.f6487.4
Applied rewrites87.4%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.2
Applied rewrites99.2%
if 2.5e10 < y Initial program 13.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6413.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.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-*.f6497.3
Applied rewrites97.3%
Taylor expanded in x around 0
*-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
log-EN/A
*-rgt-identityN/A
metadata-evalN/A
log-EN/A
associate-*r*N/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
log-EN/A
lower-*.f64N/A
Applied rewrites96.2%
Final simplification89.7%
(FPCore (c x y)
:precision binary64
(if (<= y -150.0)
(* (log1p (* x y)) c)
(if (<= y 25000000000.0)
(* (* (expm1 x) c) y)
(* (log1p (* y (* (fma 0.5 x 1.0) x))) c))))
double code(double c, double x, double y) {
double tmp;
if (y <= -150.0) {
tmp = log1p((x * y)) * c;
} else if (y <= 25000000000.0) {
tmp = (expm1(x) * c) * y;
} else {
tmp = log1p((y * (fma(0.5, x, 1.0) * x))) * c;
}
return tmp;
}
function code(c, x, y) tmp = 0.0 if (y <= -150.0) tmp = Float64(log1p(Float64(x * y)) * c); elseif (y <= 25000000000.0) tmp = Float64(Float64(expm1(x) * c) * y); else tmp = Float64(log1p(Float64(y * Float64(fma(0.5, x, 1.0) * x))) * c); end return tmp end
code[c_, x_, y_] := If[LessEqual[y, -150.0], N[(N[Log[1 + N[(x * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[y, 25000000000.0], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], N[(N[Log[1 + N[(y * N[(N[(0.5 * x + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -150:\\
\;\;\;\;\mathsf{log1p}\left(x \cdot y\right) \cdot c\\
\mathbf{elif}\;y \leq 25000000000:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(y \cdot \left(\mathsf{fma}\left(0.5, x, 1\right) \cdot x\right)\right) \cdot c\\
\end{array}
\end{array}
if y < -150Initial program 56.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6452.5
Applied rewrites52.5%
Taylor expanded in x around 0
log-EN/A
*-commutativeN/A
lower-*.f6457.5
Applied rewrites57.5%
if -150 < y < 2.5e10Initial program 37.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.9
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6460.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6460.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-*.f6487.4
Applied rewrites87.4%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.2
Applied rewrites99.2%
if 2.5e10 < y Initial program 13.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6413.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6413.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-*.f6497.3
Applied rewrites97.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6496.1
Applied rewrites96.1%
Final simplification89.7%
(FPCore (c x y)
:precision binary64
(let* ((t_0 (* c (log (fma y x 1.0)))))
(if (<= y -1.16e+154)
t_0
(if (<= y 7e+73)
(* (* (expm1 x) c) y)
(if (<= y 1.12e+219) (* c (* y x)) t_0)))))
double code(double c, double x, double y) {
double t_0 = c * log(fma(y, x, 1.0));
double tmp;
if (y <= -1.16e+154) {
tmp = t_0;
} else if (y <= 7e+73) {
tmp = (expm1(x) * c) * y;
} else if (y <= 1.12e+219) {
tmp = c * (y * x);
} else {
tmp = t_0;
}
return tmp;
}
function code(c, x, y) t_0 = Float64(c * log(fma(y, x, 1.0))) tmp = 0.0 if (y <= -1.16e+154) tmp = t_0; elseif (y <= 7e+73) tmp = Float64(Float64(expm1(x) * c) * y); elseif (y <= 1.12e+219) tmp = Float64(c * Float64(y * x)); else tmp = t_0; end return tmp end
code[c_, x_, y_] := Block[{t$95$0 = N[(c * N[Log[N[(y * x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.16e+154], t$95$0, If[LessEqual[y, 7e+73], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 1.12e+219], N[(c * N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \log \left(\mathsf{fma}\left(y, x, 1\right)\right)\\
\mathbf{if}\;y \leq -1.16 \cdot 10^{+154}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+73}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\mathbf{elif}\;y \leq 1.12 \cdot 10^{+219}:\\
\;\;\;\;c \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.16000000000000001e154 or 1.1199999999999999e219 < y Initial program 37.7%
Taylor expanded in x around 0
+-commutativeN/A
log-EN/A
metadata-evalN/A
log-EN/A
associate-*r*N/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
Applied rewrites61.4%
if -1.16000000000000001e154 < y < 7.00000000000000004e73Initial program 40.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.5
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6458.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6458.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-*.f6490.0
Applied rewrites90.0%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6490.0
Applied rewrites90.0%
if 7.00000000000000004e73 < y < 1.1199999999999999e219Initial program 12.6%
Taylor expanded in x around 0
log-EN/A
metadata-evalN/A
log-EN/A
associate-*r*N/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
*-commutativeN/A
lower-*.f6472.5
Applied rewrites72.5%
(FPCore (c x y) :precision binary64 (if (or (<= y -150.0) (not (<= y 25000000000.0))) (* (log1p (* x y)) c) (* (* (expm1 x) c) y)))
double code(double c, double x, double y) {
double tmp;
if ((y <= -150.0) || !(y <= 25000000000.0)) {
tmp = log1p((x * y)) * c;
} else {
tmp = (expm1(x) * c) * y;
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if ((y <= -150.0) || !(y <= 25000000000.0)) {
tmp = Math.log1p((x * y)) * c;
} else {
tmp = (Math.expm1(x) * c) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if (y <= -150.0) or not (y <= 25000000000.0): tmp = math.log1p((x * y)) * c else: tmp = (math.expm1(x) * c) * y return tmp
function code(c, x, y) tmp = 0.0 if ((y <= -150.0) || !(y <= 25000000000.0)) tmp = Float64(log1p(Float64(x * y)) * c); else tmp = Float64(Float64(expm1(x) * c) * y); end return tmp end
code[c_, x_, y_] := If[Or[LessEqual[y, -150.0], N[Not[LessEqual[y, 25000000000.0]], $MachinePrecision]], N[(N[Log[1 + N[(x * y), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -150 \lor \neg \left(y \leq 25000000000\right):\\
\;\;\;\;\mathsf{log1p}\left(x \cdot y\right) \cdot c\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\end{array}
\end{array}
if y < -150 or 2.5e10 < y Initial program 37.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites40.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.4
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6472.2
Applied rewrites72.2%
Taylor expanded in x around 0
log-EN/A
*-commutativeN/A
lower-*.f6474.9
Applied rewrites74.9%
if -150 < y < 2.5e10Initial program 37.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.9
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6460.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6460.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-*.f6487.4
Applied rewrites87.4%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6499.2
Applied rewrites99.2%
Final simplification89.7%
(FPCore (c x y) :precision binary64 (if (<= y 7e+73) (* (* (expm1 x) c) y) (* c (* y x))))
double code(double c, double x, double y) {
double tmp;
if (y <= 7e+73) {
tmp = (expm1(x) * c) * y;
} else {
tmp = c * (y * x);
}
return tmp;
}
public static double code(double c, double x, double y) {
double tmp;
if (y <= 7e+73) {
tmp = (Math.expm1(x) * c) * y;
} else {
tmp = c * (y * x);
}
return tmp;
}
def code(c, x, y): tmp = 0 if y <= 7e+73: tmp = (math.expm1(x) * c) * y else: tmp = c * (y * x) return tmp
function code(c, x, y) tmp = 0.0 if (y <= 7e+73) tmp = Float64(Float64(expm1(x) * c) * y); else tmp = Float64(c * Float64(y * x)); end return tmp end
code[c_, x_, y_] := If[LessEqual[y, 7e+73], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], N[(c * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{+73}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;c \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if y < 7.00000000000000004e73Initial program 41.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.9
lift-log.f64N/A
lift-+.f64N/A
lower-log1p.f6457.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.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-*.f6491.0
Applied rewrites91.0%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6481.9
Applied rewrites81.9%
if 7.00000000000000004e73 < y Initial program 9.8%
Taylor expanded in x around 0
log-EN/A
metadata-evalN/A
log-EN/A
associate-*r*N/A
log-EN/A
metadata-evalN/A
*-rgt-identityN/A
*-commutativeN/A
lower-*.f6454.1
Applied rewrites54.1%
(FPCore (c x y) :precision binary64 (if (<= c 4e+38) (* (* y c) x) (* (* c x) y)))
double code(double c, double x, double y) {
double tmp;
if (c <= 4e+38) {
tmp = (y * c) * x;
} else {
tmp = (c * x) * 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 <= 4d+38) then
tmp = (y * c) * 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 <= 4e+38) {
tmp = (y * c) * x;
} else {
tmp = (c * x) * y;
}
return tmp;
}
def code(c, x, y): tmp = 0 if c <= 4e+38: tmp = (y * c) * x else: tmp = (c * x) * y return tmp
function code(c, x, y) tmp = 0.0 if (c <= 4e+38) tmp = Float64(Float64(y * c) * x); else tmp = Float64(Float64(c * x) * y); end return tmp end
function tmp_2 = code(c, x, y) tmp = 0.0; if (c <= 4e+38) tmp = (y * c) * x; else tmp = (c * x) * y; end tmp_2 = tmp; end
code[c_, x_, y_] := If[LessEqual[c, 4e+38], N[(N[(y * c), $MachinePrecision] * x), $MachinePrecision], N[(N[(c * x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq 4 \cdot 10^{+38}:\\
\;\;\;\;\left(y \cdot c\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(c \cdot x\right) \cdot y\\
\end{array}
\end{array}
if c < 3.99999999999999991e38Initial program 46.8%
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
associate-*r*N/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
associate-*r*N/A
*-rgt-identityN/A
*-commutativeN/A
lower-*.f6464.9
Applied rewrites64.9%
if 3.99999999999999991e38 < c Initial program 9.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
*-rgt-identityN/A
associate-*r*N/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
associate-*r*N/A
*-rgt-identityN/A
*-commutativeN/A
lower-*.f6454.2
Applied rewrites54.2%
Applied rewrites60.9%
Final simplification63.9%
(FPCore (c x y) :precision binary64 (* (* c x) y))
double code(double c, double x, double y) {
return (c * x) * y;
}
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 * x) * y
end function
public static double code(double c, double x, double y) {
return (c * x) * y;
}
def code(c, x, y): return (c * x) * y
function code(c, x, y) return Float64(Float64(c * x) * y) end
function tmp = code(c, x, y) tmp = (c * x) * y; end
code[c_, x_, y_] := N[(N[(c * x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(c \cdot x\right) \cdot y
\end{array}
Initial program 37.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
associate-*r*N/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
associate-*r*N/A
*-rgt-identityN/A
*-commutativeN/A
lower-*.f6462.3
Applied rewrites62.3%
Applied rewrites57.8%
Final simplification57.8%
(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 2025017
(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)))))