
(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 7 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 -2e-312) (- (fma (- (log (- y)) (log (- x))) x z)) (- (* x (- (log x) (log y))) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e-312) {
tmp = -fma((log(-y) - log(-x)), x, z);
} else {
tmp = (x * (log(x) - log(y))) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2e-312) tmp = Float64(-fma(Float64(log(Float64(-y)) - log(Float64(-x))), x, z)); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2e-312], (-N[(N[(N[Log[(-y)], $MachinePrecision] - N[Log[(-x)], $MachinePrecision]), $MachinePrecision] * x + 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^{-312}:\\
\;\;\;\;-\mathsf{fma}\left(\log \left(-y\right) - \log \left(-x\right), x, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if y < -2.0000000000019e-312Initial program 78.0%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
distribute-lft-inN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
distribute-lft-neg-inN/A
*-inversesN/A
fp-cancel-sign-subN/A
*-rgt-identityN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.5%
if -2.0000000000019e-312 < y Initial program 78.9%
lift-log.f64N/A
lift-/.f64N/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lower-log.f6499.4
Applied rewrites99.4%
(FPCore (x y z)
:precision binary64
(if (<= x -6e+144)
(* (- (log (- x)) (log (- y))) x)
(if (<= x -6e-120)
(fma (pow (pow (log (/ x y)) -1.0) -1.0) x (- z))
(if (<= x -1e-309) (- z) (- (* x (- (log x) (log y))) z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e+144) {
tmp = (log(-x) - log(-y)) * x;
} else if (x <= -6e-120) {
tmp = fma(pow(pow(log((x / y)), -1.0), -1.0), x, -z);
} else if (x <= -1e-309) {
tmp = -z;
} else {
tmp = (x * (log(x) - log(y))) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6e+144) tmp = Float64(Float64(log(Float64(-x)) - log(Float64(-y))) * x); elseif (x <= -6e-120) tmp = fma(((log(Float64(x / y)) ^ -1.0) ^ -1.0), x, Float64(-z)); elseif (x <= -1e-309) tmp = Float64(-z); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6e+144], N[(N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, -6e-120], N[(N[Power[N[Power[N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision], -1.0], $MachinePrecision], -1.0], $MachinePrecision] * x + (-z)), $MachinePrecision], If[LessEqual[x, -1e-309], (-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 -6 \cdot 10^{+144}:\\
\;\;\;\;\left(\log \left(-x\right) - \log \left(-y\right)\right) \cdot x\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-120}:\\
\;\;\;\;\mathsf{fma}\left({\left({\log \left(\frac{x}{y}\right)}^{-1}\right)}^{-1}, x, -z\right)\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-309}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -5.9999999999999998e144Initial program 73.0%
Taylor expanded in x around -inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.3%
if -5.9999999999999998e144 < x < -6.00000000000000022e-120Initial program 92.1%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.1
Applied rewrites92.1%
Applied rewrites99.4%
Applied rewrites92.1%
if -6.00000000000000022e-120 < x < -1.000000000000002e-309Initial program 56.5%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6486.8
Applied rewrites86.8%
if -1.000000000000002e-309 < x Initial program 78.9%
lift-log.f64N/A
lift-/.f64N/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lower-log.f6499.4
Applied rewrites99.4%
Final simplification94.7%
(FPCore (x y z) :precision binary64 (if (<= x -6e-120) (fma (pow (pow (log (/ x y)) -1.0) -1.0) x (- z)) (if (<= x -1e-309) (- z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-120) {
tmp = fma(pow(pow(log((x / y)), -1.0), -1.0), x, -z);
} else if (x <= -1e-309) {
tmp = -z;
} else {
tmp = (x * (log(x) - log(y))) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6e-120) tmp = fma(((log(Float64(x / y)) ^ -1.0) ^ -1.0), x, Float64(-z)); elseif (x <= -1e-309) tmp = Float64(-z); else tmp = Float64(Float64(x * Float64(log(x) - log(y))) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6e-120], N[(N[Power[N[Power[N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision], -1.0], $MachinePrecision], -1.0], $MachinePrecision] * x + (-z)), $MachinePrecision], If[LessEqual[x, -1e-309], (-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 -6 \cdot 10^{-120}:\\
\;\;\;\;\mathsf{fma}\left({\left({\log \left(\frac{x}{y}\right)}^{-1}\right)}^{-1}, x, -z\right)\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-309}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -6.00000000000000022e-120Initial program 86.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6486.3
Applied rewrites86.3%
Applied rewrites99.3%
Applied rewrites86.3%
if -6.00000000000000022e-120 < x < -1.000000000000002e-309Initial program 56.5%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6486.8
Applied rewrites86.8%
if -1.000000000000002e-309 < x Initial program 78.9%
lift-log.f64N/A
lift-/.f64N/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lower-log.f6499.4
Applied rewrites99.4%
Final simplification92.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (log (/ x y))))
(if (<= x -6e-120)
(fma (pow (pow t_0 -1.0) -1.0) x (- z))
(if (<= x 6e-208)
(- z)
(if (<= x 1.38e+206) (fma t_0 x (- z)) (* (- (log x) (log y)) x))))))
double code(double x, double y, double z) {
double t_0 = log((x / y));
double tmp;
if (x <= -6e-120) {
tmp = fma(pow(pow(t_0, -1.0), -1.0), x, -z);
} else if (x <= 6e-208) {
tmp = -z;
} else if (x <= 1.38e+206) {
tmp = fma(t_0, x, -z);
} else {
tmp = (log(x) - log(y)) * x;
}
return tmp;
}
function code(x, y, z) t_0 = log(Float64(x / y)) tmp = 0.0 if (x <= -6e-120) tmp = fma(((t_0 ^ -1.0) ^ -1.0), x, Float64(-z)); elseif (x <= 6e-208) tmp = Float64(-z); elseif (x <= 1.38e+206) tmp = fma(t_0, x, Float64(-z)); else tmp = Float64(Float64(log(x) - log(y)) * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -6e-120], N[(N[Power[N[Power[t$95$0, -1.0], $MachinePrecision], -1.0], $MachinePrecision] * x + (-z)), $MachinePrecision], If[LessEqual[x, 6e-208], (-z), If[LessEqual[x, 1.38e+206], N[(t$95$0 * x + (-z)), $MachinePrecision], N[(N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{-120}:\\
\;\;\;\;\mathsf{fma}\left({\left({t\_0}^{-1}\right)}^{-1}, x, -z\right)\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-208}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.38 \cdot 10^{+206}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, x, -z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\log x - \log y\right) \cdot x\\
\end{array}
\end{array}
if x < -6.00000000000000022e-120Initial program 86.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6486.3
Applied rewrites86.3%
Applied rewrites99.3%
Applied rewrites86.3%
if -6.00000000000000022e-120 < x < 5.99999999999999972e-208Initial program 61.2%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6489.2
Applied rewrites89.2%
if 5.99999999999999972e-208 < x < 1.38e206Initial program 88.2%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6488.2
Applied rewrites88.2%
if 1.38e206 < x Initial program 54.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
log-recN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower-log.f6494.2
Applied rewrites94.2%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (log (/ x y)))) (if (<= (* x t_0) 2e+305) (fma t_0 x (- z)) (- z))))
double code(double x, double y, double z) {
double t_0 = log((x / y));
double tmp;
if ((x * t_0) <= 2e+305) {
tmp = fma(t_0, x, -z);
} else {
tmp = -z;
}
return tmp;
}
function code(x, y, z) t_0 = log(Float64(x / y)) tmp = 0.0 if (Float64(x * t_0) <= 2e+305) tmp = fma(t_0, x, Float64(-z)); else tmp = Float64(-z); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x * t$95$0), $MachinePrecision], 2e+305], N[(t$95$0 * x + (-z)), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;x \cdot t\_0 \leq 2 \cdot 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, x, -z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < 1.9999999999999999e305Initial program 91.7%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.7
Applied rewrites91.7%
if 1.9999999999999999e305 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 7.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6447.8
Applied rewrites47.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e+62) (not (<= z 7e+20))) (- z) (* (log (/ x y)) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+62) || !(z <= 7e+20)) {
tmp = -z;
} else {
tmp = log((x / y)) * x;
}
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.8d+62)) .or. (.not. (z <= 7d+20))) then
tmp = -z
else
tmp = log((x / y)) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+62) || !(z <= 7e+20)) {
tmp = -z;
} else {
tmp = Math.log((x / y)) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e+62) or not (z <= 7e+20): tmp = -z else: tmp = math.log((x / y)) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e+62) || !(z <= 7e+20)) tmp = Float64(-z); else tmp = Float64(log(Float64(x / y)) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e+62) || ~((z <= 7e+20))) tmp = -z; else tmp = log((x / y)) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e+62], N[Not[LessEqual[z, 7e+20]], $MachinePrecision]], (-z), N[(N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+62} \lor \neg \left(z \leq 7 \cdot 10^{+20}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{x}{y}\right) \cdot x\\
\end{array}
\end{array}
if z < -3.79999999999999984e62 or 7e20 < z Initial program 79.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6477.2
Applied rewrites77.2%
if -3.79999999999999984e62 < z < 7e20Initial program 77.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-log.f64N/A
lower-/.f6463.7
Applied rewrites63.7%
Final simplification69.5%
(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 78.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6446.4
Applied rewrites46.4%
(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 2024320
(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))