
(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 (<= y 1.62e-255)
t_0
(if (<= y 9.2e-199)
(exp x)
(if (<= y 5.4e-181)
t_0
(if (<= y 5e-46) (exp x) (if (<= y 11000000.0) t_0 (pow y y))))))))
double code(double x, double y, double z) {
double t_0 = exp(-z);
double tmp;
if (y <= 1.62e-255) {
tmp = t_0;
} else if (y <= 9.2e-199) {
tmp = exp(x);
} else if (y <= 5.4e-181) {
tmp = t_0;
} else if (y <= 5e-46) {
tmp = exp(x);
} else if (y <= 11000000.0) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = exp(-z)
if (y <= 1.62d-255) then
tmp = t_0
else if (y <= 9.2d-199) then
tmp = exp(x)
else if (y <= 5.4d-181) then
tmp = t_0
else if (y <= 5d-46) then
tmp = exp(x)
else if (y <= 11000000.0d0) then
tmp = t_0
else
tmp = y ** y
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 (y <= 1.62e-255) {
tmp = t_0;
} else if (y <= 9.2e-199) {
tmp = Math.exp(x);
} else if (y <= 5.4e-181) {
tmp = t_0;
} else if (y <= 5e-46) {
tmp = Math.exp(x);
} else if (y <= 11000000.0) {
tmp = t_0;
} else {
tmp = Math.pow(y, y);
}
return tmp;
}
def code(x, y, z): t_0 = math.exp(-z) tmp = 0 if y <= 1.62e-255: tmp = t_0 elif y <= 9.2e-199: tmp = math.exp(x) elif y <= 5.4e-181: tmp = t_0 elif y <= 5e-46: tmp = math.exp(x) elif y <= 11000000.0: tmp = t_0 else: tmp = math.pow(y, y) return tmp
function code(x, y, z) t_0 = exp(Float64(-z)) tmp = 0.0 if (y <= 1.62e-255) tmp = t_0; elseif (y <= 9.2e-199) tmp = exp(x); elseif (y <= 5.4e-181) tmp = t_0; elseif (y <= 5e-46) tmp = exp(x); elseif (y <= 11000000.0) tmp = t_0; else tmp = y ^ y; end return tmp end
function tmp_2 = code(x, y, z) t_0 = exp(-z); tmp = 0.0; if (y <= 1.62e-255) tmp = t_0; elseif (y <= 9.2e-199) tmp = exp(x); elseif (y <= 5.4e-181) tmp = t_0; elseif (y <= 5e-46) tmp = exp(x); elseif (y <= 11000000.0) tmp = t_0; else tmp = y ^ y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[Exp[(-z)], $MachinePrecision]}, If[LessEqual[y, 1.62e-255], t$95$0, If[LessEqual[y, 9.2e-199], N[Exp[x], $MachinePrecision], If[LessEqual[y, 5.4e-181], t$95$0, If[LessEqual[y, 5e-46], N[Exp[x], $MachinePrecision], If[LessEqual[y, 11000000.0], t$95$0, N[Power[y, y], $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-z}\\
\mathbf{if}\;y \leq 1.62 \cdot 10^{-255}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-199}:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-181}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-46}:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;y \leq 11000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{y}^{y}\\
\end{array}
\end{array}
if y < 1.6200000000000001e-255 or 9.2000000000000005e-199 < y < 5.3999999999999999e-181 or 4.99999999999999992e-46 < y < 1.1e7Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum98.2%
*-commutative98.2%
exp-to-pow98.2%
Simplified98.2%
Taylor expanded in x around 0 84.6%
exp-neg84.6%
associate-*l/84.6%
*-lft-identity84.6%
Simplified84.6%
Taylor expanded in y around 0 84.1%
rec-exp84.1%
Simplified84.1%
if 1.6200000000000001e-255 < y < 9.2000000000000005e-199 or 5.3999999999999999e-181 < y < 4.99999999999999992e-46Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum100.0%
*-commutative100.0%
exp-to-pow100.0%
Simplified100.0%
Taylor expanded in z around 0 76.5%
Taylor expanded in y around 0 76.5%
if 1.1e7 < y Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum62.9%
*-commutative62.9%
exp-to-pow62.9%
Simplified62.9%
Taylor expanded in z around 0 76.0%
Taylor expanded in x around 0 84.7%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (<= x -3.7e+43) (exp x) (if (<= x 1.2e-16) (exp (- z)) (exp x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e+43) {
tmp = exp(x);
} else if (x <= 1.2e-16) {
tmp = exp(-z);
} 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) :: tmp
if (x <= (-3.7d+43)) then
tmp = exp(x)
else if (x <= 1.2d-16) then
tmp = exp(-z)
else
tmp = exp(x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.7e+43) {
tmp = Math.exp(x);
} else if (x <= 1.2e-16) {
tmp = Math.exp(-z);
} else {
tmp = Math.exp(x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.7e+43: tmp = math.exp(x) elif x <= 1.2e-16: tmp = math.exp(-z) else: tmp = math.exp(x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.7e+43) tmp = exp(x); elseif (x <= 1.2e-16) tmp = exp(Float64(-z)); else tmp = exp(x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.7e+43) tmp = exp(x); elseif (x <= 1.2e-16) tmp = exp(-z); else tmp = exp(x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.7e+43], N[Exp[x], $MachinePrecision], If[LessEqual[x, 1.2e-16], N[Exp[(-z)], $MachinePrecision], N[Exp[x], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+43}:\\
\;\;\;\;e^{x}\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-16}:\\
\;\;\;\;e^{-z}\\
\mathbf{else}:\\
\;\;\;\;e^{x}\\
\end{array}
\end{array}
if x < -3.7000000000000001e43 or 1.20000000000000002e-16 < x Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum80.4%
*-commutative80.4%
exp-to-pow80.4%
Simplified80.4%
Taylor expanded in z around 0 78.7%
Taylor expanded in y around 0 85.1%
if -3.7000000000000001e43 < x < 1.20000000000000002e-16Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum84.7%
*-commutative84.7%
exp-to-pow84.7%
Simplified84.7%
Taylor expanded in x around 0 85.4%
exp-neg85.4%
associate-*l/85.4%
*-lft-identity85.4%
Simplified85.4%
Taylor expanded in y around 0 63.3%
rec-exp63.3%
Simplified63.3%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (<= y 36000000000.0) (exp (- x z)) (pow y y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 36000000000.0) {
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 <= 36000000000.0d0) 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 <= 36000000000.0) {
tmp = Math.exp((x - z));
} else {
tmp = Math.pow(y, y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 36000000000.0: tmp = math.exp((x - z)) else: tmp = math.pow(y, y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 36000000000.0) 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 <= 36000000000.0) tmp = exp((x - z)); else tmp = y ^ y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 36000000000.0], N[Exp[N[(x - z), $MachinePrecision]], $MachinePrecision], N[Power[y, y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 36000000000:\\
\;\;\;\;e^{x - z}\\
\mathbf{else}:\\
\;\;\;\;{y}^{y}\\
\end{array}
\end{array}
if y < 3.6e10Initial program 100.0%
Taylor expanded in x around inf 99.8%
if 3.6e10 < y Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
exp-sum63.2%
*-commutative63.2%
exp-to-pow63.2%
Simplified63.2%
Taylor expanded in z around 0 76.5%
Taylor expanded in x around 0 85.3%
Final simplification93.4%
(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%
+-commutative100.0%
associate--l+100.0%
exp-sum82.8%
*-commutative82.8%
exp-to-pow82.8%
Simplified82.8%
Taylor expanded in z around 0 68.6%
Taylor expanded in y around 0 47.9%
Final simplification47.9%
(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 2023221
(FPCore (x y z)
:name "Statistics.Distribution.Poisson.Internal:probability from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(exp (+ (- x z) (* (log y) y)))
(exp (- (+ x (* y (log y))) z)))