
(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 8 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 81.4%
add-cube-cbrt81.4%
pow381.4%
Applied egg-rr81.4%
pow-to-exp81.4%
rem-log-exp81.4%
Applied egg-rr81.4%
cbrt-div99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (log (/ x y))))) (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+305))) (- 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 <= 5e+305)) {
tmp = -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 <= 5e+305)) {
tmp = -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 <= 5e+305): tmp = -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 <= 5e+305)) tmp = Float64(-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 <= 5e+305))) tmp = -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, 5e+305]], $MachinePrecision]], (-z), 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 5 \cdot 10^{+305}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0 - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 5.00000000000000009e305 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 6.6%
Taylor expanded in x around 0 49.0%
neg-mul-149.0%
Simplified49.0%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.00000000000000009e305Initial program 99.6%
Final simplification89.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* x (log (/ x y))) z)))
(if (<= x -2.8e-180)
t_0
(if (<= x 1.1e-183)
(- z)
(if (<= x 1.15e+205) t_0 (* x (- (log x) (log y))))))))
double code(double x, double y, double z) {
double t_0 = (x * log((x / y))) - z;
double tmp;
if (x <= -2.8e-180) {
tmp = t_0;
} else if (x <= 1.1e-183) {
tmp = -z;
} else if (x <= 1.15e+205) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * log((x / y))) - z
if (x <= (-2.8d-180)) then
tmp = t_0
else if (x <= 1.1d-183) then
tmp = -z
else if (x <= 1.15d+205) then
tmp = t_0
else
tmp = x * (log(x) - log(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * Math.log((x / y))) - z;
double tmp;
if (x <= -2.8e-180) {
tmp = t_0;
} else if (x <= 1.1e-183) {
tmp = -z;
} else if (x <= 1.15e+205) {
tmp = t_0;
} else {
tmp = x * (Math.log(x) - Math.log(y));
}
return tmp;
}
def code(x, y, z): t_0 = (x * math.log((x / y))) - z tmp = 0 if x <= -2.8e-180: tmp = t_0 elif x <= 1.1e-183: tmp = -z elif x <= 1.15e+205: tmp = t_0 else: tmp = x * (math.log(x) - math.log(y)) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * log(Float64(x / y))) - z) tmp = 0.0 if (x <= -2.8e-180) tmp = t_0; elseif (x <= 1.1e-183) tmp = Float64(-z); elseif (x <= 1.15e+205) tmp = t_0; else tmp = Float64(x * Float64(log(x) - log(y))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * log((x / y))) - z; tmp = 0.0; if (x <= -2.8e-180) tmp = t_0; elseif (x <= 1.1e-183) tmp = -z; elseif (x <= 1.15e+205) tmp = t_0; else tmp = x * (log(x) - log(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[x, -2.8e-180], t$95$0, If[LessEqual[x, 1.1e-183], (-z), If[LessEqual[x, 1.15e+205], t$95$0, N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right) - z\\
\mathbf{if}\;x \leq -2.8 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-183}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{+205}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right)\\
\end{array}
\end{array}
if x < -2.79999999999999997e-180 or 1.1e-183 < x < 1.15000000000000004e205Initial program 90.0%
if -2.79999999999999997e-180 < x < 1.1e-183Initial program 58.1%
Taylor expanded in x around 0 95.0%
neg-mul-195.0%
Simplified95.0%
if 1.15000000000000004e205 < x Initial program 58.1%
add-cube-cbrt58.1%
pow358.1%
Applied egg-rr58.1%
Taylor expanded in x around inf 94.5%
log-rec94.5%
distribute-rgt-in94.1%
mul-1-neg94.1%
log-rec94.1%
remove-double-neg94.1%
distribute-rgt-in94.5%
+-commutative94.5%
sub-neg94.5%
Simplified94.5%
(FPCore (x y z) :precision binary64 (if (<= x -4.1e-181) (- (* x (log (/ x y))) z) (if (<= x -5e-310) (- z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.1e-181) {
tmp = (x * log((x / y))) - z;
} else if (x <= -5e-310) {
tmp = -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 <= (-4.1d-181)) then
tmp = (x * log((x / y))) - z
else if (x <= (-5d-310)) then
tmp = -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 <= -4.1e-181) {
tmp = (x * Math.log((x / y))) - z;
} else if (x <= -5e-310) {
tmp = -z;
} else {
tmp = (x * (Math.log(x) - Math.log(y))) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.1e-181: tmp = (x * math.log((x / y))) - z elif x <= -5e-310: tmp = -z else: tmp = (x * (math.log(x) - math.log(y))) - z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.1e-181) tmp = Float64(Float64(x * log(Float64(x / y))) - z); elseif (x <= -5e-310) tmp = Float64(-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 <= -4.1e-181) tmp = (x * log((x / y))) - z; elseif (x <= -5e-310) tmp = -z; else tmp = (x * (log(x) - log(y))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.1e-181], N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, -5e-310], (-z), 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 -4.1 \cdot 10^{-181}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -4.1000000000000001e-181Initial program 90.1%
if -4.1000000000000001e-181 < x < -4.999999999999985e-310Initial program 53.1%
Taylor expanded in x around 0 92.3%
neg-mul-192.3%
Simplified92.3%
if -4.999999999999985e-310 < x Initial program 80.8%
Taylor expanded in x around 0 99.6%
log-rec99.6%
neg-mul-199.6%
neg-mul-199.6%
sub-neg99.6%
Simplified99.6%
(FPCore (x y z) :precision binary64 (if (<= x -5e-310) (- (* x (- (log (- x)) (log (- y)))) z) (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-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 (x <= (-5d-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 (x <= -5e-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 x <= -5e-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 (x <= -5e-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 (x <= -5e-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[x, -5e-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}\;x \leq -5 \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 x < -4.999999999999985e-310Initial program 82.0%
Taylor expanded in y around -inf 99.4%
metadata-eval99.4%
distribute-neg-frac99.4%
distribute-frac-neg299.4%
neg-mul-199.4%
log-rec99.4%
sub-neg99.4%
Simplified99.4%
if -4.999999999999985e-310 < x Initial program 80.8%
Taylor expanded in x around 0 99.6%
log-rec99.6%
neg-mul-199.6%
neg-mul-199.6%
sub-neg99.6%
Simplified99.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-73) (not (<= x 1.55e+28))) (* x (log (/ x y))) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-73) || !(x <= 1.55e+28)) {
tmp = x * log((x / 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 ((x <= (-6.2d-73)) .or. (.not. (x <= 1.55d+28))) then
tmp = x * log((x / y))
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-73) || !(x <= 1.55e+28)) {
tmp = x * Math.log((x / y));
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-73) or not (x <= 1.55e+28): tmp = x * math.log((x / y)) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-73) || !(x <= 1.55e+28)) tmp = Float64(x * log(Float64(x / y))); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e-73) || ~((x <= 1.55e+28))) tmp = x * log((x / y)); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-73], N[Not[LessEqual[x, 1.55e+28]], $MachinePrecision]], N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-73} \lor \neg \left(x \leq 1.55 \cdot 10^{+28}\right):\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.19999999999999938e-73 or 1.55e28 < x Initial program 82.1%
Taylor expanded in z around 0 64.4%
if -6.19999999999999938e-73 < x < 1.55e28Initial program 80.6%
Taylor expanded in x around 0 76.5%
neg-mul-176.5%
Simplified76.5%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 81.4%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
Simplified46.6%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 81.4%
Taylor expanded in x around 0 46.6%
neg-mul-146.6%
Simplified46.6%
neg-sub046.6%
sub-neg46.6%
add-sqr-sqrt22.8%
sqrt-unprod12.6%
sqr-neg12.6%
sqrt-unprod1.2%
add-sqr-sqrt2.3%
Applied egg-rr2.3%
+-lft-identity2.3%
Simplified2.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 2024181
(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))