
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z\right) - y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z\right) - y
\end{array}
(FPCore (x y z) :precision binary64 (- (fma (log y) x (- z)) y))
double code(double x, double y, double z) {
return fma(log(y), x, -z) - y;
}
function code(x, y, z) return Float64(fma(log(y), x, Float64(-z)) - y) end
code[x_, y_, z_] := N[(N[(N[Log[y], $MachinePrecision] * x + (-z)), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x, -z\right) - y
\end{array}
Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.4e+39) (not (<= z 4e+85))) (- (- y) z) (- (* (log y) x) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e+39) || !(z <= 4e+85)) {
tmp = -y - z;
} else {
tmp = (log(y) * x) - 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 ((z <= (-3.4d+39)) .or. (.not. (z <= 4d+85))) then
tmp = -y - z
else
tmp = (log(y) * x) - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e+39) || !(z <= 4e+85)) {
tmp = -y - z;
} else {
tmp = (Math.log(y) * x) - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4e+39) or not (z <= 4e+85): tmp = -y - z else: tmp = (math.log(y) * x) - y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4e+39) || !(z <= 4e+85)) tmp = Float64(Float64(-y) - z); else tmp = Float64(Float64(log(y) * x) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.4e+39) || ~((z <= 4e+85))) tmp = -y - z; else tmp = (log(y) * x) - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4e+39], N[Not[LessEqual[z, 4e+85]], $MachinePrecision]], N[((-y) - z), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{+39} \lor \neg \left(z \leq 4 \cdot 10^{+85}\right):\\
\;\;\;\;\left(-y\right) - z\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x - y\\
\end{array}
\end{array}
if z < -3.3999999999999999e39 or 4.0000000000000001e85 < z Initial program 99.9%
Taylor expanded in x around 0 82.8%
neg-mul-182.8%
Simplified82.8%
if -3.3999999999999999e39 < z < 4.0000000000000001e85Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 95.1%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (- (- (* (log y) x) z) y))
double code(double x, double y, double z) {
return ((log(y) * x) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((log(y) * x) - z) - y
end function
public static double code(double x, double y, double z) {
return ((Math.log(y) * x) - z) - y;
}
def code(x, y, z): return ((math.log(y) * x) - z) - y
function code(x, y, z) return Float64(Float64(Float64(log(y) * x) - z) - y) end
function tmp = code(x, y, z) tmp = ((log(y) * x) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot x - z\right) - y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (- y) z))
double code(double x, double y, double z) {
return -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 = -y - z
end function
public static double code(double x, double y, double z) {
return -y - z;
}
def code(x, y, z): return -y - z
function code(x, y, z) return Float64(Float64(-y) - z) end
function tmp = code(x, y, z) tmp = -y - z; end
code[x_, y_, z_] := N[((-y) - z), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) - z
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 62.6%
neg-mul-162.6%
Simplified62.6%
Final simplification62.6%
herbie shell --seed 2023312
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))