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

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


\end{array}

Error

Target

Original15.3
Target7.9
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 < -9.9999999999999991e-309

    1. Initial program 15.3

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

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

      \[\leadsto \color{blue}{\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right) \cdot x} - z \]
      Proof
    4. Applied egg-rr0.4

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

    if -9.9999999999999991e-309 < y

    1. Initial program 15.4

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

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

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

Alternatives

Alternative 1
Error8.1
Cost20424
\[\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 10^{+303}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Error4.8
Cost13644
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{+179}:\\ \;\;\;\;\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right) \cdot x\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-94}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 3
Error0.3
Cost13572
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right)\right) \cdot x - z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 4
Error10.8
Cost13516
\[\begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{-90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-120}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+193}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x\\ \end{array} \]
Alternative 5
Error6.6
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{-95}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right) - z\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(\log x - \log y\right) \cdot x - z\\ \end{array} \]
Alternative 6
Error21.7
Cost7248
\[\begin{array}{l} t_0 := \log \left(\frac{x}{y}\right) \cdot x\\ \mathbf{if}\;z \leq -2.3 \cdot 10^{-121}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-86}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error32.3
Cost128
\[-z \]

Error

Reproduce

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