
(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 6 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 x (log y) (- (- z) y)))
double code(double x, double y, double z) {
return fma(x, log(y), (-z - y));
}
function code(x, y, z) return fma(x, log(y), Float64(Float64(-z) - y)) end
code[x_, y_, z_] := N[(x * N[Log[y], $MachinePrecision] + N[((-z) - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \log y, \left(-z\right) - y\right)
\end{array}
Initial program 99.9%
associate--l-99.9%
fma-neg99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.4e+103) (not (<= x 1.1e+33))) (- (* x (log y)) y) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e+103) || !(x <= 1.1e+33)) {
tmp = (x * log(y)) - y;
} else {
tmp = -z - 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 ((x <= (-6.4d+103)) .or. (.not. (x <= 1.1d+33))) then
tmp = (x * log(y)) - y
else
tmp = -z - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e+103) || !(x <= 1.1e+33)) {
tmp = (x * Math.log(y)) - y;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.4e+103) or not (x <= 1.1e+33): tmp = (x * math.log(y)) - y else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.4e+103) || !(x <= 1.1e+33)) tmp = Float64(Float64(x * log(y)) - y); else tmp = Float64(Float64(-z) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.4e+103) || ~((x <= 1.1e+33))) tmp = (x * log(y)) - y; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.4e+103], N[Not[LessEqual[x, 1.1e+33]], $MachinePrecision]], N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{+103} \lor \neg \left(x \leq 1.1 \cdot 10^{+33}\right):\\
\;\;\;\;x \cdot \log y - y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -6.39999999999999985e103 or 1.09999999999999997e33 < x Initial program 99.8%
associate--l-99.8%
fma-neg99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around 0 86.5%
if -6.39999999999999985e103 < x < 1.09999999999999997e33Initial program 100.0%
associate--l-100.0%
fma-neg100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 92.0%
mul-1-neg92.0%
+-commutative92.0%
distribute-neg-in92.0%
sub-neg92.0%
Simplified92.0%
Final simplification90.0%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= z -6.6e+149)
(- z)
(if (<= z -3.1e+45)
(- y)
(if (<= z -1.35e-32) (- z) (if (<= z 1.25e-52) (- y) (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+149) {
tmp = -z;
} else if (z <= -3.1e+45) {
tmp = -y;
} else if (z <= -1.35e-32) {
tmp = -z;
} else if (z <= 1.25e-52) {
tmp = -y;
} else {
tmp = -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 (z <= (-6.6d+149)) then
tmp = -z
else if (z <= (-3.1d+45)) then
tmp = -y
else if (z <= (-1.35d-32)) then
tmp = -z
else if (z <= 1.25d-52) then
tmp = -y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+149) {
tmp = -z;
} else if (z <= -3.1e+45) {
tmp = -y;
} else if (z <= -1.35e-32) {
tmp = -z;
} else if (z <= 1.25e-52) {
tmp = -y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e+149: tmp = -z elif z <= -3.1e+45: tmp = -y elif z <= -1.35e-32: tmp = -z elif z <= 1.25e-52: tmp = -y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+149) tmp = Float64(-z); elseif (z <= -3.1e+45) tmp = Float64(-y); elseif (z <= -1.35e-32) tmp = Float64(-z); elseif (z <= 1.25e-52) tmp = Float64(-y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e+149) tmp = -z; elseif (z <= -3.1e+45) tmp = -y; elseif (z <= -1.35e-32) tmp = -z; elseif (z <= 1.25e-52) tmp = -y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+149], (-z), If[LessEqual[z, -3.1e+45], (-y), If[LessEqual[z, -1.35e-32], (-z), If[LessEqual[z, 1.25e-52], (-y), (-z)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+149}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -3.1 \cdot 10^{+45}:\\
\;\;\;\;-y\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-32}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-52}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if z < -6.6e149 or -3.09999999999999988e45 < z < -1.3499999999999999e-32 or 1.25e-52 < z Initial program 99.9%
associate--l-99.9%
fma-neg99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 61.2%
neg-mul-161.2%
Simplified61.2%
if -6.6e149 < z < -3.09999999999999988e45 or -1.3499999999999999e-32 < z < 1.25e-52Initial program 99.9%
associate--l-99.9%
fma-neg99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 59.6%
neg-mul-159.6%
Simplified59.6%
Final simplification60.4%
(FPCore (x y z) :precision binary64 (- (- z) y))
double code(double x, double y, double z) {
return -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 = -z - y
end function
public static double code(double x, double y, double z) {
return -z - y;
}
def code(x, y, z): return -z - y
function code(x, y, z) return Float64(Float64(-z) - y) end
function tmp = code(x, y, z) tmp = -z - y; end
code[x_, y_, z_] := N[((-z) - y), $MachinePrecision]
\begin{array}{l}
\\
\left(-z\right) - y
\end{array}
Initial program 99.9%
associate--l-99.9%
fma-neg99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 71.7%
mul-1-neg71.7%
+-commutative71.7%
distribute-neg-in71.7%
sub-neg71.7%
Simplified71.7%
Final simplification71.7%
(FPCore (x y z) :precision binary64 (- y))
double code(double x, double y, double z) {
return -y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -y
end function
public static double code(double x, double y, double z) {
return -y;
}
def code(x, y, z): return -y
function code(x, y, z) return Float64(-y) end
function tmp = code(x, y, z) tmp = -y; end
code[x_, y_, z_] := (-y)
\begin{array}{l}
\\
-y
\end{array}
Initial program 99.9%
associate--l-99.9%
fma-neg99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 38.5%
neg-mul-138.5%
Simplified38.5%
Final simplification38.5%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))