
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z): return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z) return exp(Float64(Float64(x + Float64(y * log(y))) - z)) end
function tmp = code(x, y, z) tmp = exp(((x + (y * log(y))) - z)); end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z): return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z) return exp(Float64(Float64(x + Float64(y * log(y))) - z)) end
function tmp = code(x, y, z) tmp = exp(((x + (y * log(y))) - z)); end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}
(FPCore (x y z) :precision binary64 (exp (- (+ x (* y (log y))) z)))
double code(double x, double y, double z) {
return exp(((x + (y * log(y))) - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp(((x + (y * log(y))) - z))
end function
public static double code(double x, double y, double z) {
return Math.exp(((x + (y * Math.log(y))) - z));
}
def code(x, y, z): return math.exp(((x + (y * math.log(y))) - z))
function code(x, y, z) return exp(Float64(Float64(x + Float64(y * log(y))) - z)) end
function tmp = code(x, y, z) tmp = exp(((x + (y * log(y))) - z)); end
code[x_, y_, z_] := N[Exp[N[(N[(x + N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x + y \cdot \log y\right) - z}
\end{array}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (log y))))
(if (<= t_0 -2e-302)
(exp (- x z))
(if (<= t_0 3.25e+268)
(exp
(fma (- z) (/ z (+ x z)) (fma z (fma z (/ (- 1.0 (/ z x)) x) -1.0) x)))
(exp
(fma
(- z)
(fma z (fma z (/ z (* x (* x x))) (- (/ z (* x x)))) (/ z x))
(* (* x x) (/ 1.0 (+ x z)))))))))
double code(double x, double y, double z) {
double t_0 = y * log(y);
double tmp;
if (t_0 <= -2e-302) {
tmp = exp((x - z));
} else if (t_0 <= 3.25e+268) {
tmp = exp(fma(-z, (z / (x + z)), fma(z, fma(z, ((1.0 - (z / x)) / x), -1.0), x)));
} else {
tmp = exp(fma(-z, fma(z, fma(z, (z / (x * (x * x))), -(z / (x * x))), (z / x)), ((x * x) * (1.0 / (x + z)))));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * log(y)) tmp = 0.0 if (t_0 <= -2e-302) tmp = exp(Float64(x - z)); elseif (t_0 <= 3.25e+268) tmp = exp(fma(Float64(-z), Float64(z / Float64(x + z)), fma(z, fma(z, Float64(Float64(1.0 - Float64(z / x)) / x), -1.0), x))); else tmp = exp(fma(Float64(-z), fma(z, fma(z, Float64(z / Float64(x * Float64(x * x))), Float64(-Float64(z / Float64(x * x)))), Float64(z / x)), Float64(Float64(x * x) * Float64(1.0 / Float64(x + z))))); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-302], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, 3.25e+268], N[Exp[N[((-z) * N[(z / N[(x + z), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(N[(1.0 - N[(z / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[((-z) * N[(z * N[(z * N[(z / N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[(z / N[(x * x), $MachinePrecision]), $MachinePrecision])), $MachinePrecision] + N[(z / x), $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * N[(1.0 / N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \log y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-302}:\\
\;\;\;\;e^{x - z}\\
\mathbf{elif}\;t\_0 \leq 3.25 \cdot 10^{+268}:\\
\;\;\;\;e^{\mathsf{fma}\left(-z, \frac{z}{x + z}, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \frac{1 - \frac{z}{x}}{x}, -1\right), x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\mathsf{fma}\left(-z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \frac{z}{x \cdot \left(x \cdot x\right)}, -\frac{z}{x \cdot x}\right), \frac{z}{x}\right), \left(x \cdot x\right) \cdot \frac{1}{x + z}\right)}\\
\end{array}
\end{array}
if (*.f64 y (log.f64 y)) < -1.9999999999999999e-302Initial program 100.0%
Taylor expanded in y around 0
lower--.f6498.4
Applied rewrites98.4%
if -1.9999999999999999e-302 < (*.f64 y (log.f64 y)) < 3.25e268Initial program 100.0%
Taylor expanded in y around 0
lower--.f6461.3
Applied rewrites61.3%
Applied rewrites10.3%
Applied rewrites57.1%
Taylor expanded in z around 0
Applied rewrites65.4%
if 3.25e268 < (*.f64 y (log.f64 y)) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6432.1
Applied rewrites32.1%
Applied rewrites0.6%
Applied rewrites39.7%
Taylor expanded in z around 0
Applied rewrites84.6%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (<= (* y (log y)) 5e+29) (exp (- x z)) (exp (fma y (log y) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * log(y)) <= 5e+29) {
tmp = exp((x - z));
} else {
tmp = exp(fma(y, log(y), x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(y * log(y)) <= 5e+29) tmp = exp(Float64(x - z)); else tmp = exp(fma(y, log(y), x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision], 5e+29], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Exp[N[(y * N[Log[y], $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \log y \leq 5 \cdot 10^{+29}:\\
\;\;\;\;e^{x - z}\\
\mathbf{else}:\\
\;\;\;\;e^{\mathsf{fma}\left(y, \log y, x\right)}\\
\end{array}
\end{array}
if (*.f64 y (log.f64 y)) < 5.0000000000000001e29Initial program 100.0%
Taylor expanded in y around 0
lower--.f6497.9
Applied rewrites97.9%
if 5.0000000000000001e29 < (*.f64 y (log.f64 y)) Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f64N/A
lower-log.f6492.4
Applied rewrites92.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (log y)))) (if (<= t_0 3.5e+119) (exp (- x z)) (exp t_0))))
double code(double x, double y, double z) {
double t_0 = y * log(y);
double tmp;
if (t_0 <= 3.5e+119) {
tmp = exp((x - z));
} else {
tmp = exp(t_0);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * log(y)
if (t_0 <= 3.5d+119) then
tmp = exp((x - z))
else
tmp = exp(t_0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * Math.log(y);
double tmp;
if (t_0 <= 3.5e+119) {
tmp = Math.exp((x - z));
} else {
tmp = Math.exp(t_0);
}
return tmp;
}
def code(x, y, z): t_0 = y * math.log(y) tmp = 0 if t_0 <= 3.5e+119: tmp = math.exp((x - z)) else: tmp = math.exp(t_0) return tmp
function code(x, y, z) t_0 = Float64(y * log(y)) tmp = 0.0 if (t_0 <= 3.5e+119) tmp = exp(Float64(x - z)); else tmp = exp(t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * log(y); tmp = 0.0; if (t_0 <= 3.5e+119) tmp = exp((x - z)); else tmp = exp(t_0); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 3.5e+119], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Exp[t$95$0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \log y\\
\mathbf{if}\;t\_0 \leq 3.5 \cdot 10^{+119}:\\
\;\;\;\;e^{x - z}\\
\mathbf{else}:\\
\;\;\;\;e^{t\_0}\\
\end{array}
\end{array}
if (*.f64 y (log.f64 y)) < 3.5000000000000001e119Initial program 100.0%
Taylor expanded in y around 0
lower--.f6492.9
Applied rewrites92.9%
if 3.5000000000000001e119 < (*.f64 y (log.f64 y)) Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
log-recN/A
remove-double-negN/A
lower-*.f64N/A
lower-log.f6491.2
Applied rewrites91.2%
(FPCore (x y z)
:precision binary64
(if (<= (* y (log y)) -2e-302)
(exp (- x z))
(exp
(fma (- z) (/ z (+ x z)) (fma z (fma z (/ (- 1.0 (/ z x)) x) -1.0) x)))))
double code(double x, double y, double z) {
double tmp;
if ((y * log(y)) <= -2e-302) {
tmp = exp((x - z));
} else {
tmp = exp(fma(-z, (z / (x + z)), fma(z, fma(z, ((1.0 - (z / x)) / x), -1.0), x)));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(y * log(y)) <= -2e-302) tmp = exp(Float64(x - z)); else tmp = exp(fma(Float64(-z), Float64(z / Float64(x + z)), fma(z, fma(z, Float64(Float64(1.0 - Float64(z / x)) / x), -1.0), x))); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision], -2e-302], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Exp[N[((-z) * N[(z / N[(x + z), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(N[(1.0 - N[(z / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \log y \leq -2 \cdot 10^{-302}:\\
\;\;\;\;e^{x - z}\\
\mathbf{else}:\\
\;\;\;\;e^{\mathsf{fma}\left(-z, \frac{z}{x + z}, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \frac{1 - \frac{z}{x}}{x}, -1\right), x\right)\right)}\\
\end{array}
\end{array}
if (*.f64 y (log.f64 y)) < -1.9999999999999999e-302Initial program 100.0%
Taylor expanded in y around 0
lower--.f6498.4
Applied rewrites98.4%
if -1.9999999999999999e-302 < (*.f64 y (log.f64 y)) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6458.4
Applied rewrites58.4%
Applied rewrites9.3%
Applied rewrites55.3%
Taylor expanded in z around 0
Applied rewrites62.1%
(FPCore (x y z) :precision binary64 (exp (- x z)))
double code(double x, double y, double z) {
return exp((x - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp((x - z))
end function
public static double code(double x, double y, double z) {
return Math.exp((x - z));
}
def code(x, y, z): return math.exp((x - z))
function code(x, y, z) return exp(Float64(x - z)) end
function tmp = code(x, y, z) tmp = exp((x - z)); end
code[x_, y_, z_] := N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{x - z}
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
lower--.f6478.3
Applied rewrites78.3%
(FPCore (x y z) :precision binary64 (exp (- z)))
double code(double x, double y, double z) {
return exp(-z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp(-z)
end function
public static double code(double x, double y, double z) {
return Math.exp(-z);
}
def code(x, y, z): return math.exp(-z)
function code(x, y, z) return exp(Float64(-z)) end
function tmp = code(x, y, z) tmp = exp(-z); end
code[x_, y_, z_] := N[Exp[(-z)], $MachinePrecision]
\begin{array}{l}
\\
e^{-z}
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6450.0
Applied rewrites50.0%
(FPCore (x y z) :precision binary64 (exp (+ (- x z) (* (log y) y))))
double code(double x, double y, double z) {
return exp(((x - z) + (log(y) * y)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = exp(((x - z) + (log(y) * y)))
end function
public static double code(double x, double y, double z) {
return Math.exp(((x - z) + (Math.log(y) * y)));
}
def code(x, y, z): return math.exp(((x - z) + (math.log(y) * y)))
function code(x, y, z) return exp(Float64(Float64(x - z) + Float64(log(y) * y))) end
function tmp = code(x, y, z) tmp = exp(((x - z) + (log(y) * y))); end
code[x_, y_, z_] := N[Exp[N[(N[(x - z), $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x - z\right) + \log y \cdot y}
\end{array}
herbie shell --seed 2024220
(FPCore (x y z)
:name "Statistics.Distribution.Poisson.Internal:probability from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (exp (+ (- x z) (* (log y) y))))
(exp (- (+ x (* y (log y))) z)))