Numeric.SpecFunctions.Extra:bd0 from math-functions-0.1.5.2

Percentage Accurate: 77.5% → 99.7%
Time: 6.6s
Alternatives: 8
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ x \cdot \log \left(\frac{x}{y}\right) - z \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \log \left(\frac{x}{y}\right) - z \end{array} \]
(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}

Alternative 1: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ x \cdot \left(\log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right) \cdot 3\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}
Derivation
  1. Initial program 74.6%

    \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  2. Step-by-step derivation
    1. add-cube-cbrt74.6%

      \[\leadsto x \cdot \log \color{blue}{\left(\left(\sqrt[3]{\frac{x}{y}} \cdot \sqrt[3]{\frac{x}{y}}\right) \cdot \sqrt[3]{\frac{x}{y}}\right)} - z \]
    2. associate-*l*74.6%

      \[\leadsto x \cdot \log \color{blue}{\left(\sqrt[3]{\frac{x}{y}} \cdot \left(\sqrt[3]{\frac{x}{y}} \cdot \sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
    3. log-prod74.5%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + \log \left(\sqrt[3]{\frac{x}{y}} \cdot \sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
    4. pow274.5%

      \[\leadsto x \cdot \left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + \log \color{blue}{\left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{2}\right)}\right) - z \]
    5. metadata-eval74.5%

      \[\leadsto x \cdot \left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + \log \left({\left(\sqrt[3]{\frac{x}{y}}\right)}^{\color{blue}{\left(1 + 1\right)}}\right)\right) - z \]
    6. log-pow74.5%

      \[\leadsto x \cdot \left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + \color{blue}{\left(1 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)}\right) - z \]
    7. metadata-eval74.5%

      \[\leadsto x \cdot \left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + \color{blue}{2} \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
  3. Applied egg-rr74.5%

    \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) + 2 \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
  4. Step-by-step derivation
    1. distribute-rgt1-in74.5%

      \[\leadsto x \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right)} - z \]
    2. metadata-eval74.5%

      \[\leadsto x \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{x}{y}}\right)\right) - z \]
    3. *-commutative74.5%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3\right)} - z \]
  5. Simplified74.5%

    \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3\right)} - z \]
  6. Step-by-step derivation
    1. cbrt-div99.7%

      \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)} \cdot 3\right) - z \]
    2. div-inv99.7%

      \[\leadsto x \cdot \left(\log \color{blue}{\left(\sqrt[3]{x} \cdot \frac{1}{\sqrt[3]{y}}\right)} \cdot 3\right) - z \]
  7. Applied egg-rr99.7%

    \[\leadsto x \cdot \left(\log \color{blue}{\left(\sqrt[3]{x} \cdot \frac{1}{\sqrt[3]{y}}\right)} \cdot 3\right) - z \]
  8. Step-by-step derivation
    1. associate-*r/99.7%

      \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{\sqrt[3]{x} \cdot 1}{\sqrt[3]{y}}\right)} \cdot 3\right) - z \]
    2. *-rgt-identity99.7%

      \[\leadsto x \cdot \left(\log \left(\frac{\color{blue}{\sqrt[3]{x}}}{\sqrt[3]{y}}\right) \cdot 3\right) - z \]
  9. Simplified99.7%

    \[\leadsto x \cdot \left(\log \color{blue}{\left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)} \cdot 3\right) - z \]
  10. Final simplification99.7%

    \[\leadsto x \cdot \left(\log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right) \cdot 3\right) - z \]

Alternative 2: 86.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(\frac{x}{y}\right)\\ t_1 := x \cdot t_0\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;-z\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+298}:\\ \;\;\;\;\mathsf{fma}\left(t_0, x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (log (/ x y))) (t_1 (* x t_0)))
   (if (<= t_1 (- INFINITY))
     (- z)
     (if (<= t_1 2e+298) (fma t_0 x (- z)) (- z)))))
double code(double x, double y, double z) {
	double t_0 = log((x / y));
	double t_1 = x * t_0;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = -z;
	} else if (t_1 <= 2e+298) {
		tmp = fma(t_0, x, -z);
	} else {
		tmp = -z;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = log(Float64(x / y))
	t_1 = Float64(x * t_0)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(-z);
	elseif (t_1 <= 2e+298)
		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]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], (-z), If[LessEqual[t$95$1, 2e+298], N[(t$95$0 * x + (-z)), $MachinePrecision], (-z)]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(\frac{x}{y}\right)\\
t_1 := x \cdot t_0\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;-z\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(t_0, x, -z\right)\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 1.9999999999999999e298 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0 54.6%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. neg-mul-154.6%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified54.6%

      \[\leadsto \color{blue}{-z} \]

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 1.9999999999999999e298

    1. Initial program 99.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. *-commutative99.5%

        \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} - z \]
      2. fma-neg99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)} \]
    3. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \cdot \log \left(\frac{x}{y}\right) \leq 2 \cdot 10^{+298}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 3: 86.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;-z\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+298}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (log (/ x y)))))
   (if (<= t_0 (- INFINITY)) (- z) (if (<= t_0 2e+298) (- t_0 z) (- z)))))
double code(double x, double y, double z) {
	double t_0 = x * log((x / y));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = -z;
	} else if (t_0 <= 2e+298) {
		tmp = t_0 - z;
	} else {
		tmp = -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 = -z;
	} else if (t_0 <= 2e+298) {
		tmp = t_0 - z;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * math.log((x / y))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = -z
	elif t_0 <= 2e+298:
		tmp = t_0 - z
	else:
		tmp = -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(-z);
	elseif (t_0 <= 2e+298)
		tmp = Float64(t_0 - z);
	else
		tmp = Float64(-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 = -z;
	elseif (t_0 <= 2e+298)
		tmp = t_0 - z;
	else
		tmp = -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)], (-z), If[LessEqual[t$95$0, 2e+298], N[(t$95$0 - z), $MachinePrecision], (-z)]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \log \left(\frac{x}{y}\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;-z\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+298}:\\
\;\;\;\;t_0 - z\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (log.f64 (/.f64 x y))) < -inf.0 or 1.9999999999999999e298 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0 54.6%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. neg-mul-154.6%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified54.6%

      \[\leadsto \color{blue}{-z} \]

    if -inf.0 < (*.f64 x (log.f64 (/.f64 x y))) < 1.9999999999999999e298

    1. Initial program 99.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \log \left(\frac{x}{y}\right) \leq -\infty:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \cdot \log \left(\frac{x}{y}\right) \leq 2 \cdot 10^{+298}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 4: 91.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-141}:\\ \;\;\;\;\left(-z\right) - x \cdot \log \left(\frac{y}{x}\right)\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-307}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -5.2e-141)
   (- (- z) (* x (log (/ y x))))
   (if (<= x -2e-307) (- z) (- (* x (- (log x) (log y))) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -5.2e-141) {
		tmp = -z - (x * log((y / x)));
	} else if (x <= -2e-307) {
		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 <= (-5.2d-141)) then
        tmp = -z - (x * log((y / x)))
    else if (x <= (-2d-307)) 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 <= -5.2e-141) {
		tmp = -z - (x * Math.log((y / x)));
	} else if (x <= -2e-307) {
		tmp = -z;
	} else {
		tmp = (x * (Math.log(x) - Math.log(y))) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -5.2e-141:
		tmp = -z - (x * math.log((y / x)))
	elif x <= -2e-307:
		tmp = -z
	else:
		tmp = (x * (math.log(x) - math.log(y))) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -5.2e-141)
		tmp = Float64(Float64(-z) - Float64(x * log(Float64(y / x))));
	elseif (x <= -2e-307)
		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 <= -5.2e-141)
		tmp = -z - (x * log((y / x)));
	elseif (x <= -2e-307)
		tmp = -z;
	else
		tmp = (x * (log(x) - log(y))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -5.2e-141], N[((-z) - N[(x * N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2e-307], (-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.2 \cdot 10^{-141}:\\
\;\;\;\;\left(-z\right) - x \cdot \log \left(\frac{y}{x}\right)\\

\mathbf{elif}\;x \leq -2 \cdot 10^{-307}:\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log x - \log y\right) - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -5.20000000000000022e-141

    1. Initial program 86.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. clear-num86.1%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{1}{\frac{y}{x}}\right)} - z \]
      2. neg-log88.1%

        \[\leadsto x \cdot \color{blue}{\left(-\log \left(\frac{y}{x}\right)\right)} - z \]
    3. Applied egg-rr88.1%

      \[\leadsto x \cdot \color{blue}{\left(-\log \left(\frac{y}{x}\right)\right)} - z \]

    if -5.20000000000000022e-141 < x < -1.99999999999999982e-307

    1. Initial program 71.5%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0 94.1%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. neg-mul-194.1%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified94.1%

      \[\leadsto \color{blue}{-z} \]

    if -1.99999999999999982e-307 < x

    1. Initial program 67.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. log-div99.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    3. Applied egg-rr99.5%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
  3. Recombined 3 regimes into one program.
  4. Final simplification94.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-141}:\\ \;\;\;\;\left(-z\right) - x \cdot \log \left(\frac{y}{x}\right)\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-307}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]

Alternative 5: 99.5% accurate, 0.5× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.999999999999985e-310

    1. Initial program 81.6%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. frac-2neg81.6%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{-x}{-y}\right)} - z \]
      2. log-div99.6%

        \[\leadsto x \cdot \color{blue}{\left(\log \left(-x\right) - \log \left(-y\right)\right)} - z \]
    3. Applied egg-rr99.6%

      \[\leadsto x \cdot \color{blue}{\left(\log \left(-x\right) - \log \left(-y\right)\right)} - z \]

    if -4.999999999999985e-310 < y

    1. Initial program 67.1%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. log-div99.5%

        \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
    3. Applied egg-rr99.5%

      \[\leadsto x \cdot \color{blue}{\left(\log x - \log y\right)} - z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \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} \]

Alternative 6: 65.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\ \mathbf{if}\;x \leq -6.9 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-129}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-82}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{+25}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- (log (/ y x))))))
   (if (<= x -6.9e+22)
     t_0
     (if (<= x 6.5e-129)
       (- z)
       (if (<= x 5.6e-82)
         (* x (log (/ x y)))
         (if (<= x 1.45e+25) (- z) t_0))))))
double code(double x, double y, double z) {
	double t_0 = x * -log((y / x));
	double tmp;
	if (x <= -6.9e+22) {
		tmp = t_0;
	} else if (x <= 6.5e-129) {
		tmp = -z;
	} else if (x <= 5.6e-82) {
		tmp = x * log((x / y));
	} else if (x <= 1.45e+25) {
		tmp = -z;
	} else {
		tmp = t_0;
	}
	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((y / x))
    if (x <= (-6.9d+22)) then
        tmp = t_0
    else if (x <= 6.5d-129) then
        tmp = -z
    else if (x <= 5.6d-82) then
        tmp = x * log((x / y))
    else if (x <= 1.45d+25) then
        tmp = -z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * -Math.log((y / x));
	double tmp;
	if (x <= -6.9e+22) {
		tmp = t_0;
	} else if (x <= 6.5e-129) {
		tmp = -z;
	} else if (x <= 5.6e-82) {
		tmp = x * Math.log((x / y));
	} else if (x <= 1.45e+25) {
		tmp = -z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -math.log((y / x))
	tmp = 0
	if x <= -6.9e+22:
		tmp = t_0
	elif x <= 6.5e-129:
		tmp = -z
	elif x <= 5.6e-82:
		tmp = x * math.log((x / y))
	elif x <= 1.45e+25:
		tmp = -z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-log(Float64(y / x))))
	tmp = 0.0
	if (x <= -6.9e+22)
		tmp = t_0;
	elseif (x <= 6.5e-129)
		tmp = Float64(-z);
	elseif (x <= 5.6e-82)
		tmp = Float64(x * log(Float64(x / y)));
	elseif (x <= 1.45e+25)
		tmp = Float64(-z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -log((y / x));
	tmp = 0.0;
	if (x <= -6.9e+22)
		tmp = t_0;
	elseif (x <= 6.5e-129)
		tmp = -z;
	elseif (x <= 5.6e-82)
		tmp = x * log((x / y));
	elseif (x <= 1.45e+25)
		tmp = -z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-N[Log[N[(y / x), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[x, -6.9e+22], t$95$0, If[LessEqual[x, 6.5e-129], (-z), If[LessEqual[x, 5.6e-82], N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.45e+25], (-z), t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\
\mathbf{if}\;x \leq -6.9 \cdot 10^{+22}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 6.5 \cdot 10^{-129}:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq 5.6 \cdot 10^{-82}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\

\mathbf{elif}\;x \leq 1.45 \cdot 10^{+25}:\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.8999999999999998e22 or 1.44999999999999995e25 < x

    1. Initial program 73.7%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Step-by-step derivation
      1. clear-num73.7%

        \[\leadsto x \cdot \log \color{blue}{\left(\frac{1}{\frac{y}{x}}\right)} - z \]
      2. neg-log75.2%

        \[\leadsto x \cdot \color{blue}{\left(-\log \left(\frac{y}{x}\right)\right)} - z \]
    3. Applied egg-rr75.2%

      \[\leadsto x \cdot \color{blue}{\left(-\log \left(\frac{y}{x}\right)\right)} - z \]
    4. Taylor expanded in z around 0 58.6%

      \[\leadsto \color{blue}{-1 \cdot \left(\log \left(\frac{y}{x}\right) \cdot x\right)} \]

    if -6.8999999999999998e22 < x < 6.49999999999999952e-129 or 5.60000000000000049e-82 < x < 1.44999999999999995e25

    1. Initial program 74.7%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0 84.3%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. neg-mul-184.3%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified84.3%

      \[\leadsto \color{blue}{-z} \]

    if 6.49999999999999952e-129 < x < 5.60000000000000049e-82

    1. Initial program 86.8%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in z around 0 86.8%

      \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification72.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.9 \cdot 10^{+22}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-129}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-82}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{+25}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\ \end{array} \]

Alternative 7: 64.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+22} \lor \neg \left(x \leq 6.5 \cdot 10^{-129} \lor \neg \left(x \leq 5.6 \cdot 10^{-82}\right) \land x \leq 2.6 \cdot 10^{+25}\right):\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -9e+22)
         (not (or (<= x 6.5e-129) (and (not (<= x 5.6e-82)) (<= x 2.6e+25)))))
   (* x (log (/ x y)))
   (- z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -9e+22) || !((x <= 6.5e-129) || (!(x <= 5.6e-82) && (x <= 2.6e+25)))) {
		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 <= (-9d+22)) .or. (.not. (x <= 6.5d-129) .or. (.not. (x <= 5.6d-82)) .and. (x <= 2.6d+25))) 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 <= -9e+22) || !((x <= 6.5e-129) || (!(x <= 5.6e-82) && (x <= 2.6e+25)))) {
		tmp = x * Math.log((x / y));
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -9e+22) or not ((x <= 6.5e-129) or (not (x <= 5.6e-82) and (x <= 2.6e+25))):
		tmp = x * math.log((x / y))
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -9e+22) || !((x <= 6.5e-129) || (!(x <= 5.6e-82) && (x <= 2.6e+25))))
		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 <= -9e+22) || ~(((x <= 6.5e-129) || (~((x <= 5.6e-82)) && (x <= 2.6e+25)))))
		tmp = x * log((x / y));
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+22], N[Not[Or[LessEqual[x, 6.5e-129], And[N[Not[LessEqual[x, 5.6e-82]], $MachinePrecision], LessEqual[x, 2.6e+25]]]], $MachinePrecision]], N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+22} \lor \neg \left(x \leq 6.5 \cdot 10^{-129} \lor \neg \left(x \leq 5.6 \cdot 10^{-82}\right) \land x \leq 2.6 \cdot 10^{+25}\right):\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.9999999999999996e22 or 6.49999999999999952e-129 < x < 5.60000000000000049e-82 or 2.5999999999999998e25 < x

    1. Initial program 74.4%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in z around 0 58.7%

      \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} \]

    if -8.9999999999999996e22 < x < 6.49999999999999952e-129 or 5.60000000000000049e-82 < x < 2.5999999999999998e25

    1. Initial program 74.7%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Taylor expanded in x around 0 84.3%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. neg-mul-184.3%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified84.3%

      \[\leadsto \color{blue}{-z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+22} \lor \neg \left(x \leq 6.5 \cdot 10^{-129} \lor \neg \left(x \leq 5.6 \cdot 10^{-82}\right) \land x \leq 2.6 \cdot 10^{+25}\right):\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 8: 49.9% accurate, 53.5× speedup?

\[\begin{array}{l} \\ -z \end{array} \]
(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}
Derivation
  1. Initial program 74.6%

    \[x \cdot \log \left(\frac{x}{y}\right) - z \]
  2. Taylor expanded in x around 0 52.3%

    \[\leadsto \color{blue}{-1 \cdot z} \]
  3. Step-by-step derivation
    1. neg-mul-152.3%

      \[\leadsto \color{blue}{-z} \]
  4. Simplified52.3%

    \[\leadsto \color{blue}{-z} \]
  5. Final simplification52.3%

    \[\leadsto -z \]

Developer target: 88.3% accurate, 0.5× speedup?

\[\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} \]
(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}

Reproduce

?
herbie shell --seed 2023257 
(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))