
(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 5 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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (exp (- z))))
(if (<= x -3e+16)
(exp x)
(if (<= x 4.9e-214)
t_0
(if (<= x 8.2e-151) (pow y y) (if (<= x 650.0) t_0 (exp x)))))))
double code(double x, double y, double z) {
double t_0 = exp(-z);
double tmp;
if (x <= -3e+16) {
tmp = exp(x);
} else if (x <= 4.9e-214) {
tmp = t_0;
} else if (x <= 8.2e-151) {
tmp = pow(y, y);
} else if (x <= 650.0) {
tmp = t_0;
} else {
tmp = exp(x);
}
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 = exp(-z)
if (x <= (-3d+16)) then
tmp = exp(x)
else if (x <= 4.9d-214) then
tmp = t_0
else if (x <= 8.2d-151) then
tmp = y ** y
else if (x <= 650.0d0) then
tmp = t_0
else
tmp = exp(x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.exp(-z);
double tmp;
if (x <= -3e+16) {
tmp = Math.exp(x);
} else if (x <= 4.9e-214) {
tmp = t_0;
} else if (x <= 8.2e-151) {
tmp = Math.pow(y, y);
} else if (x <= 650.0) {
tmp = t_0;
} else {
tmp = Math.exp(x);
}
return tmp;
}
def code(x, y, z): t_0 = math.exp(-z) tmp = 0 if x <= -3e+16: tmp = math.exp(x) elif x <= 4.9e-214: tmp = t_0 elif x <= 8.2e-151: tmp = math.pow(y, y) elif x <= 650.0: tmp = t_0 else: tmp = math.exp(x) return tmp
function code(x, y, z) t_0 = exp(Float64(-z)) tmp = 0.0 if (x <= -3e+16) tmp = exp(x); elseif (x <= 4.9e-214) tmp = t_0; elseif (x <= 8.2e-151) tmp = y ^ y; elseif (x <= 650.0) tmp = t_0; else tmp = exp(x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = exp(-z); tmp = 0.0; if (x <= -3e+16) tmp = exp(x); elseif (x <= 4.9e-214) tmp = t_0; elseif (x <= 8.2e-151) tmp = y ^ y; elseif (x <= 650.0) tmp = t_0; else tmp = exp(x); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[Exp[(-z)], $MachinePrecision]}, If[LessEqual[x, -3e+16], N[Exp[x], $MachinePrecision], If[LessEqual[x, 4.9e-214], t$95$0, If[LessEqual[x, 8.2e-151], N[Power[y, y], $MachinePrecision], If[LessEqual[x, 650.0], t$95$0, N[Exp[x], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-z}\\
\mathbf{if}\;x \leq -3 \cdot 10^{+16}:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{-214}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-151}:\\
\;\;\;\;{y}^{y}\\
\mathbf{elif}\;x \leq 650:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;e^{x}\\
\end{array}
\end{array}
if x < -3e16 or 650 < x Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum60.7%
exp-diff57.8%
associate-/r/57.8%
*-commutative57.8%
exp-to-pow57.8%
div-exp74.8%
Simplified74.8%
Taylor expanded in z around 0 69.0%
*-rgt-identity69.0%
associate-*l/69.0%
associate-/l*69.0%
exp-neg69.0%
remove-double-div69.0%
Simplified69.0%
Taylor expanded in y around 0 84.7%
if -3e16 < x < 4.89999999999999968e-214 or 8.2000000000000002e-151 < x < 650Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum97.3%
exp-diff83.6%
associate-/r/83.6%
*-commutative83.6%
exp-to-pow83.6%
div-exp83.6%
Simplified83.6%
Taylor expanded in y around 0 78.1%
Taylor expanded in x around 0 77.7%
rec-exp77.7%
Simplified77.7%
if 4.89999999999999968e-214 < x < 8.2000000000000002e-151Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum100.0%
exp-diff81.8%
associate-/r/81.8%
*-commutative81.8%
exp-to-pow81.8%
div-exp81.8%
Simplified81.8%
Taylor expanded in z around 0 100.0%
*-rgt-identity100.0%
associate-*l/100.0%
associate-/l*100.0%
exp-neg100.0%
remove-double-div100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification82.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e+14) (not (<= x 1450.0))) (exp x) (exp (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e+14) || !(x <= 1450.0)) {
tmp = exp(x);
} else {
tmp = exp(-z);
}
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) :: tmp
if ((x <= (-2.1d+14)) .or. (.not. (x <= 1450.0d0))) then
tmp = exp(x)
else
tmp = exp(-z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e+14) || !(x <= 1450.0)) {
tmp = Math.exp(x);
} else {
tmp = Math.exp(-z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e+14) or not (x <= 1450.0): tmp = math.exp(x) else: tmp = math.exp(-z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e+14) || !(x <= 1450.0)) tmp = exp(x); else tmp = exp(Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.1e+14) || ~((x <= 1450.0))) tmp = exp(x); else tmp = exp(-z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e+14], N[Not[LessEqual[x, 1450.0]], $MachinePrecision]], N[Exp[x], $MachinePrecision], N[Exp[(-z)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+14} \lor \neg \left(x \leq 1450\right):\\
\;\;\;\;e^{x}\\
\mathbf{else}:\\
\;\;\;\;e^{-z}\\
\end{array}
\end{array}
if x < -2.1e14 or 1450 < x Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum60.7%
exp-diff57.8%
associate-/r/57.8%
*-commutative57.8%
exp-to-pow57.8%
div-exp74.8%
Simplified74.8%
Taylor expanded in z around 0 69.0%
*-rgt-identity69.0%
associate-*l/69.0%
associate-/l*69.0%
exp-neg69.0%
remove-double-div69.0%
Simplified69.0%
Taylor expanded in y around 0 84.7%
if -2.1e14 < x < 1450Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum97.5%
exp-diff83.5%
associate-/r/83.5%
*-commutative83.5%
exp-to-pow83.5%
div-exp83.5%
Simplified83.5%
Taylor expanded in y around 0 74.5%
Taylor expanded in x around 0 74.1%
rec-exp74.1%
Simplified74.1%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e+166) (exp (- x z)) (pow y y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+166) {
tmp = exp((x - z));
} else {
tmp = pow(y, y);
}
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) :: tmp
if (y <= 1.35d+166) then
tmp = exp((x - z))
else
tmp = y ** y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+166) {
tmp = Math.exp((x - z));
} else {
tmp = Math.pow(y, y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.35e+166: tmp = math.exp((x - z)) else: tmp = math.pow(y, y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.35e+166) tmp = exp(Float64(x - z)); else tmp = y ^ y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.35e+166) tmp = exp((x - z)); else tmp = y ^ y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+166], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Power[y, y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+166}:\\
\;\;\;\;e^{x - z}\\
\mathbf{else}:\\
\;\;\;\;{y}^{y}\\
\end{array}
\end{array}
if y < 1.35000000000000006e166Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum80.1%
exp-diff73.5%
associate-/r/73.5%
*-commutative73.5%
exp-to-pow73.5%
div-exp84.2%
Simplified84.2%
Taylor expanded in y around 0 94.2%
exp-diff80.9%
associate-/r/80.9%
associate-*l/80.9%
metadata-eval80.9%
associate-/r/80.9%
remove-double-div80.9%
div-exp94.2%
Simplified94.2%
if 1.35000000000000006e166 < y Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum71.7%
exp-diff58.3%
associate-/r/58.3%
*-commutative58.3%
exp-to-pow58.3%
div-exp61.7%
Simplified61.7%
Taylor expanded in z around 0 70.0%
*-rgt-identity70.0%
associate-*l/70.0%
associate-/l*70.0%
exp-neg70.0%
remove-double-div70.0%
Simplified70.0%
Taylor expanded in x around 0 90.2%
Final simplification93.2%
(FPCore (x y z) :precision binary64 (exp x))
double code(double x, double y, double z) {
return exp(x);
}
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)
end function
public static double code(double x, double y, double z) {
return Math.exp(x);
}
def code(x, y, z): return math.exp(x)
function code(x, y, z) return exp(x) end
function tmp = code(x, y, z) tmp = exp(x); end
code[x_, y_, z_] := N[Exp[x], $MachinePrecision]
\begin{array}{l}
\\
e^{x}
\end{array}
Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
exp-sum78.1%
exp-diff69.9%
associate-/r/69.9%
*-commutative69.9%
exp-to-pow69.9%
div-exp78.9%
Simplified78.9%
Taylor expanded in z around 0 65.4%
*-rgt-identity65.4%
associate-*l/65.4%
associate-/l*65.4%
exp-neg65.4%
remove-double-div65.4%
Simplified65.4%
Taylor expanded in y around 0 57.6%
Final simplification57.6%
(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 2024077
(FPCore (x y z)
:name "Statistics.Distribution.Poisson.Internal:probability from math-functions-0.1.5.2"
:precision binary64
:alt
(exp (+ (- x z) (* (log y) y)))
(exp (- (+ x (* y (log y))) z)))