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

Percentage Accurate: 77.1% → 98.9%
Time: 10.0s
Alternatives: 7
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 7 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.1% 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: 98.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\sqrt{y}}\right) + \log \left(\frac{\sqrt[3]{x}}{\sqrt{y}}\right)\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1e-310)
   (- (* x (- (log (- x)) (log (- y)))) z)
   (-
    (* x (+ (log (/ (pow (cbrt x) 2.0) (sqrt y))) (log (/ (cbrt x) (sqrt y)))))
    z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1e-310) {
		tmp = (x * (log(-x) - log(-y))) - z;
	} else {
		tmp = (x * (log((pow(cbrt(x), 2.0) / sqrt(y))) + log((cbrt(x) / sqrt(y))))) - z;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1e-310) {
		tmp = (x * (Math.log(-x) - Math.log(-y))) - z;
	} else {
		tmp = (x * (Math.log((Math.pow(Math.cbrt(x), 2.0) / Math.sqrt(y))) + Math.log((Math.cbrt(x) / Math.sqrt(y))))) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= -1e-310)
		tmp = Float64(Float64(x * Float64(log(Float64(-x)) - log(Float64(-y)))) - z);
	else
		tmp = Float64(Float64(x * Float64(log(Float64((cbrt(x) ^ 2.0) / sqrt(y))) + log(Float64(cbrt(x) / sqrt(y))))) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, -1e-310], N[(N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * N[(N[Log[N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] / N[Sqrt[y], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Log[N[(N[Power[x, 1/3], $MachinePrecision] / N[Sqrt[y], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right) - z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(\log \left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\sqrt{y}}\right) + \log \left(\frac{\sqrt[3]{x}}{\sqrt{y}}\right)\right) - z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -9.999999999999969e-311

    1. Initial program 73.1%

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

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

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

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

    if -9.999999999999969e-311 < y

    1. Initial program 82.5%

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

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

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

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

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

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

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

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

Alternative 2: 82.1% 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 \infty:\\ \;\;\;\;\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 INFINITY) (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 <= ((double) INFINITY)) {
		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 <= Inf)
		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, Infinity], 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 \infty:\\
\;\;\;\;\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 +inf.0 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.5%

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

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

        \[\leadsto \color{blue}{-z} \]
    4. Simplified50.5%

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

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

    1. Initial program 88.3%

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

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

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

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

    \[\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 \infty:\\ \;\;\;\;\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 3: 82.1% 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 \infty:\\ \;\;\;\;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 INFINITY) (- 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 <= ((double) INFINITY)) {
		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 <= Double.POSITIVE_INFINITY) {
		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 <= math.inf:
		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 <= Inf)
		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 <= Inf)
		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, Infinity], 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 \infty:\\
\;\;\;\;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 +inf.0 < (*.f64 x (log.f64 (/.f64 x y)))

    1. Initial program 4.5%

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

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

        \[\leadsto \color{blue}{-z} \]
    4. Simplified50.5%

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

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

    1. Initial program 88.3%

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

    \[\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 \infty:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 4: 92.6% accurate, 0.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -9.2000000000000005e185

    1. Initial program 51.4%

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

      \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} \]
    3. Step-by-step derivation
      1. frac-2neg51.4%

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

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

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

    if -9.2000000000000005e185 < x < -1.00000000000000005e-230

    1. Initial program 88.6%

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

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

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

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

    if -1.00000000000000005e-230 < x < -1.9999999999999998e-308

    1. Initial program 31.0%

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

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

        \[\leadsto \color{blue}{-z} \]
    4. Simplified88.7%

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

    if -1.9999999999999998e-308 < x

    1. Initial program 82.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.2 \cdot 10^{+185}:\\ \;\;\;\;x \cdot \left(\log \left(-x\right) - \log \left(-y\right)\right)\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-230}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right) - z\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-308}:\\ \;\;\;\;-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 -1 \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 -1e-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 <= -1e-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 <= (-1d-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 <= -1e-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 <= -1e-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 <= -1e-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 <= -1e-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, -1e-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 -1 \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 < -9.999999999999969e-311

    1. Initial program 73.1%

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

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

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

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

    if -9.999999999999969e-311 < y

    1. Initial program 82.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \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: 66.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-95}:\\
\;\;\;\;-z\\

\mathbf{elif}\;z \leq 6.8 \cdot 10^{+24}:\\
\;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3e-95 or 6.8000000000000001e24 < z

    1. Initial program 74.4%

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

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

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

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

    if -3e-95 < z < 6.8000000000000001e24

    1. Initial program 82.1%

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

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

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

Alternative 7: 50.3% 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 78.2%

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

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

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

    \[\leadsto \color{blue}{-z} \]
  5. Final simplification48.1%

    \[\leadsto -z \]

Developer target: 88.0% 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 2023185 
(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))