
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
return (x * log((x / 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 = (x * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
return (x * Math.log((x / y))) - z;
}
def code(x, y, z): return (x * math.log((x / y))) - z
function code(x, y, z) return Float64(Float64(x * log(Float64(x / y))) - z) end
function tmp = code(x, y, z) tmp = (x * log((x / y))) - z; end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
double code(double x, double y, double z) {
return (x * log((x / 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 = (x * log((x / y))) - z
end function
public static double code(double x, double y, double z) {
return (x * Math.log((x / y))) - z;
}
def code(x, y, z): return (x * math.log((x / y))) - z
function code(x, y, z) return Float64(Float64(x * log(Float64(x / y))) - z) end
function tmp = code(x, y, z) tmp = (x * log((x / y))) - z; end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log \left(\frac{x}{y}\right) - z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (* (log (/ (cbrt x) (cbrt y))) 3.0)) z))
double code(double x, double y, double z) {
return (x * (log((cbrt(x) / cbrt(y))) * 3.0)) - z;
}
public static double code(double x, double y, double z) {
return (x * (Math.log((Math.cbrt(x) / Math.cbrt(y))) * 3.0)) - z;
}
function code(x, y, z) return Float64(Float64(x * Float64(log(Float64(cbrt(x) / cbrt(y))) * 3.0)) - z) end
code[x_, y_, z_] := N[(N[(x * N[(N[Log[N[(N[Power[x, 1/3], $MachinePrecision] / N[Power[y, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right) \cdot 3\right) - z
\end{array}
Initial program 76.9%
add-cube-cbrt76.9%
log-prod76.8%
pow276.8%
Applied egg-rr76.8%
log-pow76.8%
distribute-lft1-in76.8%
metadata-eval76.8%
*-commutative76.8%
Simplified76.8%
cbrt-div99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log (/ x y)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 1e+292)))
(- (* x 0.0) z)
(- t_0 z))))
double code(double x, double y, double z) {
double t_0 = x * log((x / y));
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 1e+292)) {
tmp = (x * 0.0) - z;
} else {
tmp = t_0 - z;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = x * Math.log((x / y));
double tmp;
if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 1e+292)) {
tmp = (x * 0.0) - z;
} else {
tmp = t_0 - z;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log((x / y)) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 1e+292): tmp = (x * 0.0) - z else: tmp = t_0 - z return tmp
function code(x, y, z) t_0 = Float64(x * log(Float64(x / y))) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 1e+292)) tmp = Float64(Float64(x * 0.0) - z); else tmp = Float64(t_0 - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * log((x / y)); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 1e+292))) tmp = (x * 0.0) - z; else tmp = t_0 - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 1e+292]], $MachinePrecision]], N[(N[(x * 0.0), $MachinePrecision] - z), $MachinePrecision], N[(t$95$0 - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 10^{+292}\right):\\
\;\;\;\;x \cdot 0 - z\\
\mathbf{else}:\\
\;\;\;\;t_0 - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 1e292 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 6.2%
add-cube-cbrt6.2%
log-prod6.2%
pow26.2%
Applied egg-rr6.2%
log-pow6.2%
distribute-lft1-in6.2%
metadata-eval6.2%
*-commutative6.2%
Simplified6.2%
add-log-exp6.2%
exp-to-pow6.2%
pow36.2%
add-cube-cbrt6.2%
add-sqr-sqrt5.0%
sqrt-unprod5.7%
clear-num5.7%
neg-log5.7%
clear-num5.7%
neg-log10.4%
sqr-neg10.4%
sqrt-unprod0.8%
add-sqr-sqrt2.9%
clear-num1.4%
add-sqr-sqrt1.4%
associate-/r*1.4%
metadata-eval1.4%
sqrt-div1.4%
clear-num1.4%
add-exp-log1.4%
add-sqr-sqrt0.6%
sqrt-unprod0.6%
Applied egg-rr0.0%
+-inverses46.6%
Simplified46.6%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 1e292Initial program 99.5%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (<= x -2.25e-212) (- (* x (- (log (/ y x)))) z) (if (<= x -2e-307) (- (* x 0.0) z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.25e-212) {
tmp = (x * -log((y / x))) - z;
} else if (x <= -2e-307) {
tmp = (x * 0.0) - z;
} else {
tmp = (x * (log(x) - log(y))) - 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.25d-212)) then
tmp = (x * -log((y / x))) - z
else if (x <= (-2d-307)) then
tmp = (x * 0.0d0) - z
else
tmp = (x * (log(x) - log(y))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.25e-212) {
tmp = (x * -Math.log((y / x))) - z;
} else if (x <= -2e-307) {
tmp = (x * 0.0) - z;
} else {
tmp = (x * (Math.log(x) - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.25e-212: tmp = (x * -math.log((y / x))) - z elif x <= -2e-307: tmp = (x * 0.0) - z else: tmp = (x * (math.log(x) - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.25e-212) tmp = Float64(Float64(x * Float64(-log(Float64(y / x)))) - z); elseif (x <= -2e-307) tmp = Float64(Float64(x * 0.0) - z); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.25e-212) tmp = (x * -log((y / x))) - z; elseif (x <= -2e-307) tmp = (x * 0.0) - z; else tmp = (x * (log(x) - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.25e-212], N[(N[(x * (-N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, -2e-307], N[(N[(x * 0.0), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{-212}:\\
\;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right) - z\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-307}:\\
\;\;\;\;x \cdot 0 - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -2.2499999999999999e-212Initial program 83.7%
clear-num82.8%
log-rec83.9%
Applied egg-rr83.9%
if -2.2499999999999999e-212 < x < -1.99999999999999982e-307Initial program 53.7%
add-cube-cbrt53.7%
log-prod53.7%
pow253.7%
Applied egg-rr53.7%
log-pow53.7%
distribute-lft1-in53.7%
metadata-eval53.7%
*-commutative53.7%
Simplified53.7%
add-log-exp53.7%
exp-to-pow53.7%
pow353.7%
add-cube-cbrt53.7%
add-sqr-sqrt11.1%
sqrt-unprod47.3%
clear-num47.1%
neg-log47.1%
clear-num47.1%
neg-log47.1%
sqr-neg47.1%
sqrt-unprod36.0%
add-sqr-sqrt47.1%
clear-num47.1%
add-sqr-sqrt47.1%
associate-/r*47.1%
metadata-eval47.1%
sqrt-div47.1%
clear-num47.1%
add-exp-log47.1%
add-sqr-sqrt11.1%
sqrt-unprod46.2%
Applied egg-rr46.5%
+-inverses85.8%
Simplified85.8%
if -1.99999999999999982e-307 < x Initial program 74.7%
log-div99.5%
Applied egg-rr99.5%
Final simplification92.1%
(FPCore (x y z) :precision binary64 (if (<= y -2e-310) (- (* x (- (log (- x)) (log (- y)))) z) (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-310) {
tmp = (x * (log(-x) - log(-y))) - z;
} else {
tmp = (x * (log(x) - log(y))) - 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 (y <= (-2d-310)) then
tmp = (x * (log(-x) - log(-y))) - z
else
tmp = (x * (log(x) - log(y))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2e-310) {
tmp = (x * (Math.log(-x) - Math.log(-y))) - z;
} else {
tmp = (x * (Math.log(x) - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e-310: tmp = (x * (math.log(-x) - math.log(-y))) - z else: tmp = (x * (math.log(x) - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e-310) tmp = Float64(Float64(x * Float64(log(Float64(-x)) - log(Float64(-y)))) - z); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e-310) tmp = (x * (log(-x) - log(-y))) - z; else tmp = (x * (log(x) - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e-310], N[(N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if y < -1.999999999999994e-310Initial program 79.3%
frac-2neg79.3%
log-div99.5%
Applied egg-rr99.5%
if -1.999999999999994e-310 < y Initial program 74.7%
log-div99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (- (* x 0.0) z))
double code(double x, double y, double z) {
return (x * 0.0) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.0d0) - z
end function
public static double code(double x, double y, double z) {
return (x * 0.0) - z;
}
def code(x, y, z): return (x * 0.0) - z
function code(x, y, z) return Float64(Float64(x * 0.0) - z) end
function tmp = code(x, y, z) tmp = (x * 0.0) - z; end
code[x_, y_, z_] := N[(N[(x * 0.0), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0 - z
\end{array}
Initial program 76.9%
add-cube-cbrt76.9%
log-prod76.8%
pow276.8%
Applied egg-rr76.8%
log-pow76.8%
distribute-lft1-in76.8%
metadata-eval76.8%
*-commutative76.8%
Simplified76.8%
add-log-exp76.8%
exp-to-pow76.9%
pow376.9%
add-cube-cbrt76.9%
add-sqr-sqrt36.9%
sqrt-unprod60.5%
clear-num59.7%
neg-log59.7%
clear-num59.7%
neg-log60.9%
sqr-neg60.9%
sqrt-unprod22.7%
add-sqr-sqrt38.3%
clear-num37.9%
add-sqr-sqrt37.9%
associate-/r*37.9%
metadata-eval37.9%
sqrt-div37.9%
clear-num37.9%
add-exp-log37.9%
add-sqr-sqrt15.2%
sqrt-unprod38.4%
Applied egg-rr39.4%
+-inverses50.7%
Simplified50.7%
Final simplification50.7%
(FPCore (x y z) :precision binary64 (if (< y 7.595077799083773e-308) (- (* x (log (/ x y))) z) (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
double tmp;
if (y < 7.595077799083773e-308) {
tmp = (x * log((x / y))) - z;
} else {
tmp = (x * (log(x) - log(y))) - 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 (y < 7.595077799083773d-308) then
tmp = (x * log((x / y))) - z
else
tmp = (x * (log(x) - log(y))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y < 7.595077799083773e-308) {
tmp = (x * Math.log((x / y))) - z;
} else {
tmp = (x * (Math.log(x) - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y < 7.595077799083773e-308: tmp = (x * math.log((x / y))) - z else: tmp = (x * (math.log(x) - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (y < 7.595077799083773e-308) tmp = Float64(Float64(x * log(Float64(x / y))) - z); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y < 7.595077799083773e-308) tmp = (x * log((x / y))) - z; else tmp = (x * (log(x) - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[y, 7.595077799083773e-308], N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y < 7.595077799083773 \cdot 10^{-308}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
herbie shell --seed 2023192
(FPCore (x y z)
:name "Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(if (< y 7.595077799083773e-308) (- (* x (log (/ x y))) z) (- (* x (- (log x) (log y))) z))
(- (* x (log (/ x y))) z))