Average Error: 16.0 → 0.4
Time: 3.2s
Precision: binary64
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} \mathbf{if}\;x \leq 0:\\ \;\;\;\;\left(x \cdot \log \left(\frac{-1}{y}\right) + x \cdot \log \left(-x\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \log x - \log y, -z\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= x 0.0)
   (- (+ (* x (log (/ -1.0 y))) (* x (log (- x)))) z)
   (fma x (- (log x) (log y)) (- z))))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
double code(double x, double y, double z) {
	double tmp;
	if (x <= 0.0) {
		tmp = ((x * log((-1.0 / y))) + (x * log(-x))) - z;
	} else {
		tmp = fma(x, (log(x) - log(y)), -z);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function code(x, y, z)
	tmp = 0.0
	if (x <= 0.0)
		tmp = Float64(Float64(Float64(x * log(Float64(-1.0 / y))) + Float64(x * log(Float64(-x)))) - z);
	else
		tmp = fma(x, Float64(log(x) - log(y)), Float64(-z));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[x, 0.0], N[(N[(N[(x * N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(x * N[Log[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;x \leq 0:\\
\;\;\;\;\left(x \cdot \log \left(\frac{-1}{y}\right) + x \cdot \log \left(-x\right)\right) - z\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original16.0
Target8.2
Herbie0.4
\[\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} \]

Derivation

  1. Split input into 2 regimes
  2. if x < 0.0

    1. Initial program 16.0

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Simplified16.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \log \left(\frac{x}{y}\right), -z\right)} \]
    3. Taylor expanded in y around -inf 0.4

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

    if 0.0 < x

    1. Initial program 16.0

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Simplified16.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0:\\ \;\;\;\;\left(x \cdot \log \left(\frac{-1}{y}\right) + x \cdot \log \left(-x\right)\right) - z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \log x - \log y, -z\right)\\ \end{array} \]

Reproduce

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