Average Error: 15.7 → 0.3
Time: 6.9s
Precision: binary64
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} \mathbf{if}\;y \leq 3.50923658615853 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{fma}\left(x, \log \left(-x\right) - \log \left(-y\right), -z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y 3.50923658615853e-310)
   (fma x (- (log (- x)) (log (- y))) (- z))
   (- (* 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 (y <= 3.50923658615853e-310) {
		tmp = fma(x, (log(-x) - log(-y)), -z);
	} else {
		tmp = (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 (y <= 3.50923658615853e-310)
		tmp = fma(x, Float64(log(Float64(-x)) - log(Float64(-y))), Float64(-z));
	else
		tmp = Float64(Float64(x * Float64(log(x) - log(y))) - 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[y, 3.50923658615853e-310], N[(x * N[(N[Log[(-x)], $MachinePrecision] - N[Log[(-y)], $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision], N[(N[(x * N[(N[Log[x], $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq 3.50923658615853 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(x, \log \left(-x\right) - \log \left(-y\right), -z\right)\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original15.7
Target8.0
Herbie0.3
\[\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 y < 3.509236586158526e-310

    1. Initial program 15.8

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

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

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

    if 3.509236586158526e-310 < y

    1. Initial program 15.6

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

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

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{\log \left(-x\right) - \log \left(-y\right)}, -z\right) \]
    4. Taylor expanded in z around 0 64.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 3.50923658615853 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{fma}\left(x, \log \left(-x\right) - \log \left(-y\right), -z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]

Reproduce

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