
(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 9 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 -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 (y <= -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 (y <= (-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 (y <= -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 y <= -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 (y <= -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 (y <= -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[y, -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}\;y \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 y < -4.999999999999985e-310Initial program 79.7%
frac-2neg79.7%
log-div99.4%
Applied egg-rr99.4%
if -4.999999999999985e-310 < y Initial program 76.8%
log-div99.5%
Applied egg-rr99.5%
Final simplification99.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log (/ x y)))) (t_1 (* x (log (* y x)))))
(if (<= t_0 (- INFINITY))
(- t_1 z)
(if (<= t_0 5e+296) (- t_0 z) (- (fabs t_1) z)))))
double code(double x, double y, double z) {
double t_0 = x * log((x / y));
double t_1 = x * log((y * x));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1 - z;
} else if (t_0 <= 5e+296) {
tmp = t_0 - z;
} else {
tmp = fabs(t_1) - z;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = x * Math.log((x / y));
double t_1 = x * Math.log((y * x));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1 - z;
} else if (t_0 <= 5e+296) {
tmp = t_0 - z;
} else {
tmp = Math.abs(t_1) - z;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log((x / y)) t_1 = x * math.log((y * x)) tmp = 0 if t_0 <= -math.inf: tmp = t_1 - z elif t_0 <= 5e+296: tmp = t_0 - z else: tmp = math.fabs(t_1) - z return tmp
function code(x, y, z) t_0 = Float64(x * log(Float64(x / y))) t_1 = Float64(x * log(Float64(y * x))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(t_1 - z); elseif (t_0 <= 5e+296) tmp = Float64(t_0 - z); else tmp = Float64(abs(t_1) - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * log((x / y)); t_1 = x * log((y * x)); tmp = 0.0; if (t_0 <= -Inf) tmp = t_1 - z; elseif (t_0 <= 5e+296) tmp = t_0 - z; else tmp = abs(t_1) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(t$95$1 - z), $MachinePrecision], If[LessEqual[t$95$0, 5e+296], N[(t$95$0 - z), $MachinePrecision], N[(N[Abs[t$95$1], $MachinePrecision] - z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
t_1 := x \cdot \log \left(y \cdot x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1 - z\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;t_0 - z\\
\mathbf{else}:\\
\;\;\;\;\left|t_1\right| - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0Initial program 8.2%
log-div40.7%
Applied egg-rr40.7%
sub-neg40.7%
distribute-rgt-in40.7%
Applied egg-rr40.7%
distribute-rgt-out40.7%
sub-neg40.7%
log-div8.2%
*-commutative8.2%
log-div40.7%
sub-neg40.7%
add-log-exp40.7%
sum-log0.7%
add-sqr-sqrt0.0%
sqrt-unprod37.1%
sqr-neg37.1%
sqrt-unprod37.1%
add-sqr-sqrt37.1%
add-exp-log49.2%
Applied egg-rr49.2%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296Initial program 99.6%
if 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 4.1%
add-cube-cbrt4.1%
log-prod4.1%
pow24.1%
metadata-eval4.1%
log-pow4.1%
metadata-eval4.1%
Applied egg-rr4.1%
distribute-lft1-in4.1%
metadata-eval4.1%
*-commutative4.1%
Simplified4.1%
add-log-exp4.1%
exp-to-pow4.1%
pow34.1%
add-cube-cbrt4.1%
add-sqr-sqrt4.1%
sqrt-unprod4.1%
pow24.1%
Applied egg-rr50.8%
unpow250.8%
rem-sqrt-square54.8%
Simplified54.8%
Final simplification88.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log (/ x y)))) (t_1 (log (* y x))))
(if (<= t_0 (- INFINITY))
(- (* x (fabs t_1)) z)
(if (<= t_0 5e+296) (- t_0 z) (- (fabs (* x t_1)) z)))))
double code(double x, double y, double z) {
double t_0 = x * log((x / y));
double t_1 = log((y * x));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (x * fabs(t_1)) - z;
} else if (t_0 <= 5e+296) {
tmp = t_0 - z;
} else {
tmp = fabs((x * t_1)) - z;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = x * Math.log((x / y));
double t_1 = Math.log((y * x));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = (x * Math.abs(t_1)) - z;
} else if (t_0 <= 5e+296) {
tmp = t_0 - z;
} else {
tmp = Math.abs((x * t_1)) - z;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log((x / y)) t_1 = math.log((y * x)) tmp = 0 if t_0 <= -math.inf: tmp = (x * math.fabs(t_1)) - z elif t_0 <= 5e+296: tmp = t_0 - z else: tmp = math.fabs((x * t_1)) - z return tmp
function code(x, y, z) t_0 = Float64(x * log(Float64(x / y))) t_1 = log(Float64(y * x)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(x * abs(t_1)) - z); elseif (t_0 <= 5e+296) tmp = Float64(t_0 - z); else tmp = Float64(abs(Float64(x * t_1)) - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * log((x / y)); t_1 = log((y * x)); tmp = 0.0; if (t_0 <= -Inf) tmp = (x * abs(t_1)) - z; elseif (t_0 <= 5e+296) tmp = t_0 - z; else tmp = abs((x * t_1)) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(x * N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[t$95$0, 5e+296], N[(t$95$0 - z), $MachinePrecision], N[(N[Abs[N[(x * t$95$1), $MachinePrecision]], $MachinePrecision] - z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
t_1 := \log \left(y \cdot x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;x \cdot \left|t_1\right| - z\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+296}:\\
\;\;\;\;t_0 - z\\
\mathbf{else}:\\
\;\;\;\;\left|x \cdot t_1\right| - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0Initial program 8.2%
add-cube-cbrt8.2%
*-un-lft-identity8.2%
times-frac8.2%
log-prod64.4%
pow264.4%
Applied egg-rr64.4%
add-sqr-sqrt41.6%
sqrt-unprod64.7%
pow264.7%
Applied egg-rr53.6%
unpow253.6%
rem-sqrt-square53.6%
Simplified53.6%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296Initial program 99.6%
if 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 4.1%
add-cube-cbrt4.1%
log-prod4.1%
pow24.1%
metadata-eval4.1%
log-pow4.1%
metadata-eval4.1%
Applied egg-rr4.1%
distribute-lft1-in4.1%
metadata-eval4.1%
*-commutative4.1%
Simplified4.1%
add-log-exp4.1%
exp-to-pow4.1%
pow34.1%
add-cube-cbrt4.1%
add-sqr-sqrt4.1%
sqrt-unprod4.1%
pow24.1%
Applied egg-rr50.8%
unpow250.8%
rem-sqrt-square54.8%
Simplified54.8%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (log (/ x y))))) (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+296))) (- 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+296)) {
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+296)) {
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+296): 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+296)) 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+296))) 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+296]], $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^{+296}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0 - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 6.0%
remove-double-neg6.0%
sub-neg6.0%
distribute-neg-in6.0%
distribute-rgt-neg-in6.0%
remove-double-neg6.0%
fma-udef6.0%
log-div46.5%
sub-neg46.5%
distribute-neg-in46.5%
remove-double-neg46.5%
+-commutative46.5%
sub-neg46.5%
log-div11.2%
Simplified11.2%
Taylor expanded in x around 0 45.0%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296Initial program 99.6%
Final simplification87.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (log (/ x y)))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+296)))
(- (* x (log (* y x))) 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+296)) {
tmp = (x * log((y * x))) - 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+296)) {
tmp = (x * Math.log((y * x))) - 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+296): tmp = (x * math.log((y * x))) - 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+296)) tmp = Float64(Float64(x * log(Float64(y * x))) - 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+296))) tmp = (x * log((y * x))) - 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+296]], $MachinePrecision]], N[(N[(x * N[Log[N[(y * x), $MachinePrecision]], $MachinePrecision]), $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 5 \cdot 10^{+296}\right):\\
\;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\
\mathbf{else}:\\
\;\;\;\;t_0 - z\\
\end{array}
\end{array}
if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 5.0000000000000001e296 < (*.f64 x (log.f64 (/.f64 x y))) Initial program 6.0%
log-div46.5%
Applied egg-rr46.5%
sub-neg46.5%
distribute-rgt-in46.4%
Applied egg-rr46.4%
distribute-rgt-out46.5%
sub-neg46.5%
log-div6.0%
*-commutative6.0%
log-div46.5%
sub-neg46.5%
add-log-exp46.5%
sum-log2.0%
add-sqr-sqrt1.7%
sqrt-unprod18.9%
sqr-neg18.9%
sqrt-unprod17.3%
add-sqr-sqrt22.3%
add-exp-log48.7%
Applied egg-rr48.7%
if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 5.0000000000000001e296Initial program 99.6%
Final simplification88.1%
(FPCore (x y z)
:precision binary64
(if (<= x -5.5e+258)
(* x (- (log (- x)) (log (- y))))
(if (<= x -3.4e-198)
(- (fma x (log (/ y x)) z))
(if (<= x -5e-309) (- z) (- (* x (- (log x) (log y))) z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e+258) {
tmp = x * (log(-x) - log(-y));
} else if (x <= -3.4e-198) {
tmp = -fma(x, log((y / x)), z);
} else if (x <= -5e-309) {
tmp = -z;
} else {
tmp = (x * (log(x) - log(y))) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.5e+258) tmp = Float64(x * Float64(log(Float64(-x)) - log(Float64(-y)))); elseif (x <= -3.4e-198) tmp = Float64(-fma(x, log(Float64(y / x)), z)); elseif (x <= -5e-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, -5.5e+258], N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.4e-198], (-N[(x * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision] + z), $MachinePrecision]), If[LessEqual[x, -5e-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 -5.5 \cdot 10^{+258}:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-198}:\\
\;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -5.49999999999999978e258Initial program 54.8%
remove-double-neg54.8%
sub-neg54.8%
distribute-neg-in54.8%
distribute-rgt-neg-in54.8%
remove-double-neg54.8%
fma-udef54.8%
log-div0.0%
sub-neg0.0%
distribute-neg-in0.0%
remove-double-neg0.0%
+-commutative0.0%
sub-neg0.0%
log-div57.8%
Simplified57.8%
Taylor expanded in x around inf 0.0%
log-rec0.0%
sub-neg0.0%
log-div57.8%
Simplified57.8%
frac-2neg57.8%
log-div98.7%
Applied egg-rr98.7%
if -5.49999999999999978e258 < x < -3.3999999999999998e-198Initial program 85.2%
remove-double-neg85.2%
sub-neg85.2%
distribute-neg-in85.2%
distribute-rgt-neg-in85.2%
remove-double-neg85.2%
fma-udef85.2%
log-div0.0%
sub-neg0.0%
distribute-neg-in0.0%
remove-double-neg0.0%
+-commutative0.0%
sub-neg0.0%
log-div86.8%
Simplified86.8%
if -3.3999999999999998e-198 < x < -4.9999999999999995e-309Initial program 73.0%
remove-double-neg73.0%
sub-neg73.0%
distribute-neg-in73.0%
distribute-rgt-neg-in73.0%
remove-double-neg73.0%
fma-udef73.0%
log-div0.0%
sub-neg0.0%
distribute-neg-in0.0%
remove-double-neg0.0%
+-commutative0.0%
sub-neg0.0%
log-div69.6%
Simplified69.6%
Taylor expanded in x around 0 100.0%
if -4.9999999999999995e-309 < x Initial program 76.8%
log-div99.5%
Applied egg-rr99.5%
Final simplification94.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.4e-198) (- (fma x (log (/ y x)) z)) (if (<= x -2e-306) (- z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e-198) {
tmp = -fma(x, log((y / x)), z);
} else if (x <= -2e-306) {
tmp = -z;
} else {
tmp = (x * (log(x) - log(y))) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.4e-198) tmp = Float64(-fma(x, log(Float64(y / x)), z)); elseif (x <= -2e-306) 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, -3.4e-198], (-N[(x * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision] + z), $MachinePrecision]), If[LessEqual[x, -2e-306], (-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 -3.4 \cdot 10^{-198}:\\
\;\;\;\;-\mathsf{fma}\left(x, \log \left(\frac{y}{x}\right), z\right)\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-306}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\
\end{array}
\end{array}
if x < -3.3999999999999998e-198Initial program 81.4%
remove-double-neg81.4%
sub-neg81.4%
distribute-neg-in81.4%
distribute-rgt-neg-in81.4%
remove-double-neg81.4%
fma-udef81.4%
log-div0.0%
sub-neg0.0%
distribute-neg-in0.0%
remove-double-neg0.0%
+-commutative0.0%
sub-neg0.0%
log-div83.2%
Simplified83.2%
if -3.3999999999999998e-198 < x < -2.00000000000000006e-306Initial program 73.0%
remove-double-neg73.0%
sub-neg73.0%
distribute-neg-in73.0%
distribute-rgt-neg-in73.0%
remove-double-neg73.0%
fma-udef73.0%
log-div0.0%
sub-neg0.0%
distribute-neg-in0.0%
remove-double-neg0.0%
+-commutative0.0%
sub-neg0.0%
log-div69.6%
Simplified69.6%
Taylor expanded in x around 0 100.0%
if -2.00000000000000006e-306 < x Initial program 76.8%
log-div99.5%
Applied egg-rr99.5%
Final simplification92.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.24e-54) (not (<= z 6.2e-76))) (- z) (* (- x) (log (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.24e-54) || !(z <= 6.2e-76)) {
tmp = -z;
} else {
tmp = -x * log((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 <= (-1.24d-54)) .or. (.not. (z <= 6.2d-76))) then
tmp = -z
else
tmp = -x * log((y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.24e-54) || !(z <= 6.2e-76)) {
tmp = -z;
} else {
tmp = -x * Math.log((y / x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.24e-54) or not (z <= 6.2e-76): tmp = -z else: tmp = -x * math.log((y / x)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.24e-54) || !(z <= 6.2e-76)) tmp = Float64(-z); else tmp = Float64(Float64(-x) * log(Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.24e-54) || ~((z <= 6.2e-76))) tmp = -z; else tmp = -x * log((y / x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.24e-54], N[Not[LessEqual[z, 6.2e-76]], $MachinePrecision]], (-z), N[((-x) * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.24 \cdot 10^{-54} \lor \neg \left(z \leq 6.2 \cdot 10^{-76}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right)\\
\end{array}
\end{array}
if z < -1.23999999999999999e-54 or 6.19999999999999939e-76 < z Initial program 79.6%
remove-double-neg79.6%
sub-neg79.6%
distribute-neg-in79.6%
distribute-rgt-neg-in79.6%
remove-double-neg79.6%
fma-udef79.6%
log-div42.5%
sub-neg42.5%
distribute-neg-in42.5%
remove-double-neg42.5%
+-commutative42.5%
sub-neg42.5%
log-div79.8%
Simplified79.8%
Taylor expanded in x around 0 77.7%
if -1.23999999999999999e-54 < z < 6.19999999999999939e-76Initial program 77.0%
remove-double-neg77.0%
sub-neg77.0%
distribute-neg-in77.0%
distribute-rgt-neg-in77.0%
remove-double-neg77.0%
fma-udef76.9%
log-div46.6%
sub-neg46.6%
distribute-neg-in46.6%
remove-double-neg46.6%
+-commutative46.6%
sub-neg46.6%
log-div77.2%
Simplified77.2%
Taylor expanded in x around inf 39.4%
log-rec39.4%
sub-neg39.4%
log-div68.8%
Simplified68.8%
Final simplification73.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 78.4%
remove-double-neg78.4%
sub-neg78.4%
distribute-neg-in78.4%
distribute-rgt-neg-in78.4%
remove-double-neg78.4%
fma-udef78.4%
log-div44.3%
sub-neg44.3%
distribute-neg-in44.3%
remove-double-neg44.3%
+-commutative44.3%
sub-neg44.3%
log-div78.6%
Simplified78.6%
Taylor expanded in x around 0 50.4%
Final simplification50.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 2024011
(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))