?

Average Accuracy: 75.8% → 99.4%
Time: 12.3s
Precision: binary64
Cost: 32836

?

\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\begin{array}{l} t_0 := \log \left(\sqrt[3]{y}\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right), x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(t_0 \cdot -2 - \left(t_0 - \log x\right)\right) - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (log (cbrt y))))
   (if (<= y -1e-308)
     (fma (+ (log (/ -1.0 y)) (log (- x))) x (- z))
     (- (* x (- (* t_0 -2.0) (- t_0 (log 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 t_0 = log(cbrt(y));
	double tmp;
	if (y <= -1e-308) {
		tmp = fma((log((-1.0 / y)) + log(-x)), x, -z);
	} else {
		tmp = (x * ((t_0 * -2.0) - (t_0 - log(x)))) - z;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function code(x, y, z)
	t_0 = log(cbrt(y))
	tmp = 0.0
	if (y <= -1e-308)
		tmp = fma(Float64(log(Float64(-1.0 / y)) + log(Float64(-x))), x, Float64(-z));
	else
		tmp = Float64(Float64(x * Float64(Float64(t_0 * -2.0) - Float64(t_0 - log(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_] := Block[{t$95$0 = N[Log[N[Power[y, 1/3], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -1e-308], N[(N[(N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision] + N[Log[(-x)], $MachinePrecision]), $MachinePrecision] * x + (-z)), $MachinePrecision], N[(N[(x * N[(N[(t$95$0 * -2.0), $MachinePrecision] - N[(t$95$0 - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
t_0 := \log \left(\sqrt[3]{y}\right)\\
\mathbf{if}\;y \leq -1 \cdot 10^{-308}:\\
\;\;\;\;\mathsf{fma}\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right), x, -z\right)\\

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


\end{array}

Error?

Target

Original75.8%
Target87.4%
Herbie99.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 y < -9.9999999999999991e-309

    1. Initial program 75.3%

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

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

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

      [Start]99.5

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

      fma-neg [=>]99.5

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

      mul-1-neg [=>]99.5

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

    if -9.9999999999999991e-309 < y

    1. Initial program 76.3%

      \[x \cdot \log \left(\frac{x}{y}\right) - z \]
    2. Applied egg-rr76.0%

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

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

      \[\leadsto x \cdot \left(-\color{blue}{\left(2 \cdot \log \left(\sqrt[3]{y}\right) + \left(\log \left(\sqrt[3]{y}\right) - \log x\right)\right)}\right) - z \]
      Proof

      [Start]99.3

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

      associate-+r+ [=>]99.3

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

      log-rec [=>]99.4

      \[ x \cdot \left(-\left(\left(\log \left({\left(\sqrt[3]{y}\right)}^{2}\right) + \log \left(\sqrt[3]{y}\right)\right) + \color{blue}{\left(-\log x\right)}\right)\right) - z \]

      associate-+r+ [<=]99.4

      \[ x \cdot \left(-\color{blue}{\left(\log \left({\left(\sqrt[3]{y}\right)}^{2}\right) + \left(\log \left(\sqrt[3]{y}\right) + \left(-\log x\right)\right)\right)}\right) - z \]

      log-pow [=>]99.4

      \[ x \cdot \left(-\left(\color{blue}{2 \cdot \log \left(\sqrt[3]{y}\right)} + \left(\log \left(\sqrt[3]{y}\right) + \left(-\log x\right)\right)\right)\right) - z \]

      sub-neg [<=]99.4

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

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

Alternatives

Alternative 1
Accuracy87.1%
Cost26760
\[\begin{array}{l} t_0 := \log \left(\frac{x}{y}\right)\\ t_1 := x \cdot t_0\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+302}:\\ \;\;\;\;\mathsf{fma}\left(t_0, x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right)\\ \end{array} \]
Alternative 2
Accuracy87.0%
Cost26696
\[\begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+302}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right)\\ \end{array} \]
Alternative 3
Accuracy87.8%
Cost20425
\[\begin{array}{l} t_0 := x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 2 \cdot 10^{+302}\right):\\ \;\;\;\;x \cdot \log \left(y \cdot x\right) - z\\ \mathbf{else}:\\ \;\;\;\;t_0 - z\\ \end{array} \]
Alternative 4
Accuracy87.0%
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 2 \cdot 10^{+302}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 5
Accuracy99.5%
Cost19908
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(\frac{-1}{y}\right) + \log \left(-x\right), x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
Alternative 6
Accuracy90.2%
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{-140}:\\ \;\;\;\;\frac{x}{\frac{-1}{\log \left(\frac{y}{x}\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 7
Accuracy99.5%
Cost13508
\[\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 8
Accuracy65.9%
Cost7249
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+23}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-125} \lor \neg \left(z \leq -8.2 \cdot 10^{-155}\right) \land z \leq 2.3 \cdot 10^{+20}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Accuracy65.8%
Cost7248
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+23}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-125}:\\ \;\;\;\;\left(-x\right) \cdot \log \left(\frac{y}{x}\right)\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-155}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{+22}:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Accuracy49.5%
Cost128
\[-z \]

Error

Reproduce?

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