
(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 (if (<= y -4e-310) (- (* x (- (log (- 0.0 x)) (log (- 0.0 y)))) z) (- (+ (* x (log x)) (* x (log (/ 1.0 y)))) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-310) {
tmp = (x * (log((0.0 - x)) - log((0.0 - y)))) - z;
} else {
tmp = ((x * log(x)) + (x * log((1.0 / 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 <= (-4d-310)) then
tmp = (x * (log((0.0d0 - x)) - log((0.0d0 - y)))) - z
else
tmp = ((x * log(x)) + (x * log((1.0d0 / y)))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4e-310) {
tmp = (x * (Math.log((0.0 - x)) - Math.log((0.0 - y)))) - z;
} else {
tmp = ((x * Math.log(x)) + (x * Math.log((1.0 / y)))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-310: tmp = (x * (math.log((0.0 - x)) - math.log((0.0 - y)))) - z else: tmp = ((x * math.log(x)) + (x * math.log((1.0 / y)))) - z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-310) tmp = Float64(Float64(x * Float64(log(Float64(0.0 - x)) - log(Float64(0.0 - y)))) - z); else tmp = Float64(Float64(Float64(x * log(x)) + Float64(x * log(Float64(1.0 / y)))) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e-310) tmp = (x * (log((0.0 - x)) - log((0.0 - y)))) - z; else tmp = ((x * log(x)) + (x * log((1.0 / y)))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-310], N[(N[(x * N[(N[Log[N[(0.0 - x), $MachinePrecision]], $MachinePrecision] - N[Log[N[(0.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Log[N[(1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(\log \left(0 - x\right) - \log \left(0 - y\right)\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \log x + x \cdot \log \left(\frac{1}{y}\right)\right) - z\\
\end{array}
\end{array}
if y < -3.999999999999988e-310Initial program 75.5%
frac-2negN/A
log-divN/A
--lowering--.f64N/A
log-lowering-log.f64N/A
neg-sub0N/A
metadata-evalN/A
--lowering--.f64N/A
metadata-evalN/A
log-lowering-log.f64N/A
neg-sub0N/A
metadata-evalN/A
--lowering--.f64N/A
metadata-eval99.6%
Applied egg-rr99.6%
if -3.999999999999988e-310 < y Initial program 78.4%
log-divN/A
sub-negN/A
distribute-rgt-inN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
neg-logN/A
log-lowering-log.f64N/A
/-lowering-/.f6498.2%
Applied egg-rr98.2%
Final simplification98.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log (/ x y)))))
(if (<= t_0 (- INFINITY))
(- 0.0 z)
(if (<= t_0 INFINITY) (- t_0 z) (- 0.0 z)))))
double code(double x, double y, double z) {
double t_0 = x * log((x / y));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = 0.0 - z;
} else if (t_0 <= ((double) INFINITY)) {
tmp = t_0 - z;
} else {
tmp = 0.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) {
tmp = 0.0 - z;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 - z;
} else {
tmp = 0.0 - z;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log((x / y)) tmp = 0 if t_0 <= -math.inf: tmp = 0.0 - z elif t_0 <= math.inf: tmp = t_0 - z else: tmp = 0.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)) tmp = Float64(0.0 - z); elseif (t_0 <= Inf) tmp = Float64(t_0 - z); else tmp = Float64(0.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) tmp = 0.0 - z; elseif (t_0 <= Inf) tmp = t_0 - z; else tmp = 0.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[LessEqual[t$95$0, (-Infinity)], N[(0.0 - z), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(t$95$0 - z), $MachinePrecision], N[(0.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:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0 - z\\
\mathbf{else}:\\
\;\;\;\;0 - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or +inf.0 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 4.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6446.5%
Simplified46.5%
sub0-negN/A
neg-lowering-neg.f6446.5%
Applied egg-rr46.5%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < +inf.0Initial program 85.4%
Final simplification81.3%
(FPCore (x y z)
:precision binary64
(if (<= x -1e-305)
(- (* x (- (log (- 0.0 x)) (log (- 0.0 y)))) z)
(if (<= x 7.6e-183)
(- 0.0 z)
(if (<= x 4.1e+172)
(- (* (- 0.0 x) (log (/ y x))) z)
(* x (- (log x) (log y)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e-305) {
tmp = (x * (log((0.0 - x)) - log((0.0 - y)))) - z;
} else if (x <= 7.6e-183) {
tmp = 0.0 - z;
} else if (x <= 4.1e+172) {
tmp = ((0.0 - x) * log((y / x))) - z;
} else {
tmp = x * (log(x) - log(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 <= (-1d-305)) then
tmp = (x * (log((0.0d0 - x)) - log((0.0d0 - y)))) - z
else if (x <= 7.6d-183) then
tmp = 0.0d0 - z
else if (x <= 4.1d+172) then
tmp = ((0.0d0 - x) * log((y / x))) - z
else
tmp = x * (log(x) - log(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1e-305) {
tmp = (x * (Math.log((0.0 - x)) - Math.log((0.0 - y)))) - z;
} else if (x <= 7.6e-183) {
tmp = 0.0 - z;
} else if (x <= 4.1e+172) {
tmp = ((0.0 - x) * Math.log((y / x))) - z;
} else {
tmp = x * (Math.log(x) - Math.log(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e-305: tmp = (x * (math.log((0.0 - x)) - math.log((0.0 - y)))) - z elif x <= 7.6e-183: tmp = 0.0 - z elif x <= 4.1e+172: tmp = ((0.0 - x) * math.log((y / x))) - z else: tmp = x * (math.log(x) - math.log(y)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e-305) tmp = Float64(Float64(x * Float64(log(Float64(0.0 - x)) - log(Float64(0.0 - y)))) - z); elseif (x <= 7.6e-183) tmp = Float64(0.0 - z); elseif (x <= 4.1e+172) tmp = Float64(Float64(Float64(0.0 - x) * log(Float64(y / x))) - z); else tmp = Float64(x * Float64(log(x) - log(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1e-305) tmp = (x * (log((0.0 - x)) - log((0.0 - y)))) - z; elseif (x <= 7.6e-183) tmp = 0.0 - z; elseif (x <= 4.1e+172) tmp = ((0.0 - x) * log((y / x))) - z; else tmp = x * (log(x) - log(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e-305], N[(N[(x * N[(N[Log[N[(0.0 - x), $MachinePrecision]], $MachinePrecision] - N[Log[N[(0.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, 7.6e-183], N[(0.0 - z), $MachinePrecision], If[LessEqual[x, 4.1e+172], N[(N[(N[(0.0 - x), $MachinePrecision] * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-305}:\\
\;\;\;\;x \cdot \left(\log \left(0 - x\right) - \log \left(0 - y\right)\right) - z\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-183}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+172}:\\
\;\;\;\;\left(0 - x\right) \cdot \log \left(\frac{y}{x}\right) - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right)\\
\end{array}
\end{array}
if x < -9.99999999999999996e-306Initial program 76.1%
frac-2negN/A
log-divN/A
--lowering--.f64N/A
log-lowering-log.f64N/A
neg-sub0N/A
metadata-evalN/A
--lowering--.f64N/A
metadata-evalN/A
log-lowering-log.f64N/A
neg-sub0N/A
metadata-evalN/A
--lowering--.f64N/A
metadata-eval99.6%
Applied egg-rr99.6%
if -9.99999999999999996e-306 < x < 7.5999999999999993e-183Initial program 55.3%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64100.0%
Simplified100.0%
sub0-negN/A
neg-lowering-neg.f64100.0%
Applied egg-rr100.0%
if 7.5999999999999993e-183 < x < 4.1e172Initial program 89.2%
clear-numN/A
log-recN/A
neg-lowering-neg.f64N/A
log-lowering-log.f64N/A
/-lowering-/.f6491.3%
Applied egg-rr91.3%
if 4.1e172 < x Initial program 56.5%
Taylor expanded in x around inf
distribute-lft-inN/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-lowering-*.f64N/A
log-recN/A
unsub-negN/A
remove-double-negN/A
log-recN/A
mul-1-negN/A
--lowering--.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
log-lowering-log.f64N/A
log-lowering-log.f6492.2%
Simplified92.2%
Final simplification96.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.1e-52) (- 0.0 z) (if (<= z 5.4e-18) (* x (log (/ x y))) (- 0.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e-52) {
tmp = 0.0 - z;
} else if (z <= 5.4e-18) {
tmp = x * log((x / y));
} else {
tmp = 0.0 - 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 <= (-1.1d-52)) then
tmp = 0.0d0 - z
else if (z <= 5.4d-18) then
tmp = x * log((x / y))
else
tmp = 0.0d0 - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e-52) {
tmp = 0.0 - z;
} else if (z <= 5.4e-18) {
tmp = x * Math.log((x / y));
} else {
tmp = 0.0 - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e-52: tmp = 0.0 - z elif z <= 5.4e-18: tmp = x * math.log((x / y)) else: tmp = 0.0 - z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e-52) tmp = Float64(0.0 - z); elseif (z <= 5.4e-18) tmp = Float64(x * log(Float64(x / y))); else tmp = Float64(0.0 - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.1e-52) tmp = 0.0 - z; elseif (z <= 5.4e-18) tmp = x * log((x / y)); else tmp = 0.0 - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e-52], N[(0.0 - z), $MachinePrecision], If[LessEqual[z, 5.4e-18], N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.0 - z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-52}:\\
\;\;\;\;0 - z\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{-18}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;0 - z\\
\end{array}
\end{array}
if z < -1.10000000000000005e-52 or 5.39999999999999977e-18 < z Initial program 76.5%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.2%
Simplified75.2%
sub0-negN/A
neg-lowering-neg.f6475.2%
Applied egg-rr75.2%
if -1.10000000000000005e-52 < z < 5.39999999999999977e-18Initial program 77.5%
Taylor expanded in z around 0
*-lowering-*.f64N/A
log-lowering-log.f64N/A
/-lowering-/.f6469.2%
Simplified69.2%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (- 0.0 z))
double code(double x, double y, double z) {
return 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 = 0.0d0 - z
end function
public static double code(double x, double y, double z) {
return 0.0 - z;
}
def code(x, y, z): return 0.0 - z
function code(x, y, z) return Float64(0.0 - z) end
function tmp = code(x, y, z) tmp = 0.0 - z; end
code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
\\
0 - z
\end{array}
Initial program 76.9%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6448.3%
Simplified48.3%
sub0-negN/A
neg-lowering-neg.f6448.3%
Applied egg-rr48.3%
Final simplification48.3%
(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 2024138
(FPCore (x y z)
:name "Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (if (< y 7595077799083773/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* x (log (/ x y))) z) (- (* x (- (log x) (log y))) z)))
(- (* x (log (/ x y))) z))