Average Error: 15.3 → 0.2
Time: 6.9s
Precision: binary64
Cost: 26112
\[x \cdot \log \left(\frac{x}{y}\right) - z \]
\[\mathsf{fma}\left(x \cdot 3, \log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right), -z\right) \]
(FPCore (x y z) :precision binary64 (- (* x (log (/ x y))) z))
(FPCore (x y z)
 :precision binary64
 (fma (* x 3.0) (log (/ (cbrt x) (cbrt y))) (- z)))
double code(double x, double y, double z) {
	return (x * log((x / y))) - z;
}
double code(double x, double y, double z) {
	return fma((x * 3.0), log((cbrt(x) / cbrt(y))), -z);
}
function code(x, y, z)
	return Float64(Float64(x * log(Float64(x / y))) - z)
end
function code(x, y, z)
	return fma(Float64(x * 3.0), log(Float64(cbrt(x) / cbrt(y))), Float64(-z))
end
code[x_, y_, z_] := N[(N[(x * N[Log[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(x * 3.0), $MachinePrecision] * N[Log[N[(N[Power[x, 1/3], $MachinePrecision] / N[Power[y, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + (-z)), $MachinePrecision]
x \cdot \log \left(\frac{x}{y}\right) - z
\mathsf{fma}\left(x \cdot 3, \log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right), -z\right)

Error

Target

Original15.3
Target7.7
Herbie0.2
\[\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. Initial program 15.3

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

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

    \[\leadsto x \cdot \color{blue}{\left(\log \left(\sqrt[3]{\frac{x}{y}}\right) \cdot 3\right)} - z \]
    Proof
    (*.f64 (log.f64 (cbrt.f64 (/.f64 x y))) 3): 0 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 3 (log.f64 (cbrt.f64 (/.f64 x y))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (Rewrite<= metadata-eval (+.f64 2 1)) (log.f64 (cbrt.f64 (/.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 2 (log.f64 (cbrt.f64 (/.f64 x y)))) (log.f64 (cbrt.f64 (/.f64 x y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= log-pow_binary64 (log.f64 (pow.f64 (cbrt.f64 (/.f64 x y)) 2))) (log.f64 (cbrt.f64 (/.f64 x y)))): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr15.4

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

    \[\leadsto \mathsf{fma}\left(x \cdot 3, \log \color{blue}{\left(\sqrt[3]{x} \cdot \frac{1}{\sqrt[3]{y}}\right)}, -z\right) \]
  6. Simplified0.2

    \[\leadsto \mathsf{fma}\left(x \cdot 3, \log \color{blue}{\left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)}, -z\right) \]
    Proof
    (/.f64 (cbrt.f64 x) (cbrt.f64 y)): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 (cbrt.f64 x) 1)) (cbrt.f64 y)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-*r/_binary64 (*.f64 (cbrt.f64 x) (/.f64 1 (cbrt.f64 y)))): 36 points increase in error, 38 points decrease in error
  7. Final simplification0.2

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

Alternatives

Alternative 1
Error8.7
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 4 \cdot 10^{+287}:\\ \;\;\;\;t_0 - z\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Error0.2
Cost19776
\[x \cdot \left(3 \cdot \log \left(\frac{\sqrt[3]{x}}{\sqrt[3]{y}}\right)\right) - z \]
Alternative 3
Error6.1
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{-123}:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right) - z\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-309}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x - \log y\right) - z\\ \end{array} \]
Alternative 4
Error0.3
Cost13508
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \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 5
Error21.4
Cost7048
\[\begin{array}{l} \mathbf{if}\;z \leq -6.6 \cdot 10^{-46}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 28000:\\ \;\;\;\;x \cdot \left(-\log \left(\frac{y}{x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error21.6
Cost6984
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{-46}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 16.5:\\ \;\;\;\;x \cdot \log \left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error32.8
Cost128
\[-z \]
Alternative 8
Error62.5
Cost64
\[z \]

Error

Reproduce

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