Average Error: 15.5 → 0.3
Time: 3.0s
Precision: 64
\[x \cdot \log \left(\frac{x}{y}\right) - z\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.50299343895823 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{fma}\left(\log \left(-x\right) - \log \left(-y\right), x, -z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x - \log y, x, -z\right)\\ \end{array}\]
x \cdot \log \left(\frac{x}{y}\right) - z
\begin{array}{l}
\mathbf{if}\;y \le -2.50299343895823 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(\log \left(-x\right) - \log \left(-y\right), x, -z\right)\\

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

\end{array}
double code(double x, double y, double z) {
	return ((x * log((x / y))) - z);
}
double code(double x, double y, double z) {
	double VAR;
	if ((y <= -2.50299343895823e-310)) {
		VAR = fma((log(-x) - log(-y)), x, -z);
	} else {
		VAR = fma((log(x) - log(y)), x, -z);
	}
	return VAR;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.5
Target7.7
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y \lt 7.59507779908377277 \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 < -2.50299343895823e-310

    1. Initial program 15.1

      \[x \cdot \log \left(\frac{x}{y}\right) - z\]
    2. Using strategy rm
    3. Applied *-commutative15.1

      \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} - z\]
    4. Applied fma-neg15.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)}\]
    5. Using strategy rm
    6. Applied frac-2neg15.1

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

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

    if -2.50299343895823e-310 < y

    1. Initial program 15.9

      \[x \cdot \log \left(\frac{x}{y}\right) - z\]
    2. Using strategy rm
    3. Applied *-commutative15.9

      \[\leadsto \color{blue}{\log \left(\frac{x}{y}\right) \cdot x} - z\]
    4. Applied fma-neg15.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log \left(\frac{x}{y}\right), x, -z\right)}\]
    5. Using strategy rm
    6. Applied log-div0.3

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

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

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(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))