Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2

Percentage Accurate: 99.8% → 99.9%
Time: 8.0s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z):
	return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function tmp = code(x, y, z)
	tmp = ((x - ((y + 0.5) * log(y))) + y) - z;
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z):
	return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function tmp = code(x, y, z)
	tmp = ((x - ((y + 0.5) * log(y))) + y) - z;
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ x (fma (- (log y)) (+ 0.5 y) y)) z))
double code(double x, double y, double z) {
	return (x + fma(-log(y), (0.5 + y), y)) - z;
}
function code(x, y, z)
	return Float64(Float64(x + fma(Float64(-log(y)), Float64(0.5 + y), y)) - z)
end
code[x_, y_, z_] := N[(N[(x + N[((-N[Log[y], $MachinePrecision]) * N[(0.5 + y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right) - z
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
    2. lift--.f64N/A

      \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
    3. lift-*.f64N/A

      \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
    4. fp-cancel-sub-sign-invN/A

      \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
    5. associate-+l+N/A

      \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
    6. lower-+.f64N/A

      \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
    7. distribute-lft-neg-outN/A

      \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
    8. *-commutativeN/A

      \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
    9. distribute-lft-neg-inN/A

      \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
    10. lower-fma.f64N/A

      \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
    11. lower-neg.f6499.9

      \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
    12. lift-+.f64N/A

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
    13. +-commutativeN/A

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
    14. lower-+.f6499.9

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
  5. Add Preprocessing

Alternative 2: 89.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+50}:\\ \;\;\;\;\left(x + y\right) - \log y \cdot y\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+39}:\\ \;\;\;\;\mathsf{fma}\left(\left(-y\right) - 0.5, \log y, y\right) - z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -3.4e+50)
   (- (+ x y) (* (log y) y))
   (if (<= x 4.4e+39)
     (- (fma (- (- y) 0.5) (log y) y) z)
     (- (fma -0.5 (log y) x) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.4e+50) {
		tmp = (x + y) - (log(y) * y);
	} else if (x <= 4.4e+39) {
		tmp = fma((-y - 0.5), log(y), y) - z;
	} else {
		tmp = fma(-0.5, log(y), x) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (x <= -3.4e+50)
		tmp = Float64(Float64(x + y) - Float64(log(y) * y));
	elseif (x <= 4.4e+39)
		tmp = Float64(fma(Float64(Float64(-y) - 0.5), log(y), y) - z);
	else
		tmp = Float64(fma(-0.5, log(y), x) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[x, -3.4e+50], N[(N[(x + y), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.4e+39], N[(N[(N[((-y) - 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+50}:\\
\;\;\;\;\left(x + y\right) - \log y \cdot y\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+39}:\\
\;\;\;\;\mathsf{fma}\left(\left(-y\right) - 0.5, \log y, y\right) - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.3999999999999998e50

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
      2. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
      3. lift-*.f64N/A

        \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      6. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
      8. *-commutativeN/A

        \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
      10. lower-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
      11. lower-neg.f6499.9

        \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
      12. lift-+.f64N/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
      13. +-commutativeN/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
      14. lower-+.f6499.9

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
    5. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right) - z} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right)} - z \]
      3. lift-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(\left(-\log y\right) \cdot \left(\frac{1}{2} + y\right) + y\right)}\right) - z \]
      4. +-commutativeN/A

        \[\leadsto \left(x + \color{blue}{\left(y + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)}\right) - z \]
      5. associate-+r+N/A

        \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      6. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      7. lift-+.f64N/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      8. lift-neg.f64N/A

        \[\leadsto \left(\left(y + x\right) + \color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)} \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\left(y + x\right) - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(y + x\right) - \color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)}\right) - z \]
      11. associate--l-N/A

        \[\leadsto \color{blue}{\left(y + x\right) - \left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      12. lift-*.f64N/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)} + z\right) \]
      13. *-commutativeN/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      14. lift-fma.f64N/A

        \[\leadsto \left(y + x\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      15. lower--.f6499.9

        \[\leadsto \color{blue}{\left(y + x\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
      16. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(y + x\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      18. lower-+.f6499.9

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(0.5 + y, \log y, z\right) \]
    6. Applied rewrites99.9%

      \[\leadsto \color{blue}{\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
    7. Taylor expanded in y around inf

      \[\leadsto \left(x + y\right) - \color{blue}{-1 \cdot \left(y \cdot \log \left(\frac{1}{y}\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(x + y\right) - -1 \cdot \color{blue}{\left(\log \left(\frac{1}{y}\right) \cdot y\right)} \]
      2. associate-*r*N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
      3. mul-1-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)} \cdot y \]
      4. log-recN/A

        \[\leadsto \left(x + y\right) - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right) \cdot y \]
      5. remove-double-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
      6. lower-*.f64N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]
      7. lower-log.f6487.4

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
    9. Applied rewrites87.4%

      \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]

    if -3.3999999999999998e50 < x < 4.4000000000000003e39

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\left(y - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
    4. Step-by-step derivation
      1. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(y + \left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(\frac{1}{2} + y\right) + y\right)} - z \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\log y \cdot \left(\frac{1}{2} + y\right)\right)\right)} + y\right) - z \]
      4. distribute-rgt-inN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\frac{1}{2} \cdot \log y + y \cdot \log y\right)}\right)\right) + y\right) - z \]
      5. +-commutativeN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(y \cdot \log y + \frac{1}{2} \cdot \log y\right)}\right)\right) + y\right) - z \]
      6. distribute-neg-inN/A

        \[\leadsto \left(\color{blue}{\left(\left(\mathsf{neg}\left(y \cdot \log y\right)\right) + \left(\mathsf{neg}\left(\frac{1}{2} \cdot \log y\right)\right)\right)} + y\right) - z \]
      7. mul-1-negN/A

        \[\leadsto \left(\left(\color{blue}{-1 \cdot \left(y \cdot \log y\right)} + \left(\mathsf{neg}\left(\frac{1}{2} \cdot \log y\right)\right)\right) + y\right) - z \]
      8. distribute-lft-neg-inN/A

        \[\leadsto \left(\left(-1 \cdot \left(y \cdot \log y\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y}\right) + y\right) - z \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot \left(y \cdot \log y\right) - \frac{1}{2} \cdot \log y\right)} + y\right) - z \]
      10. associate-*r*N/A

        \[\leadsto \left(\left(\color{blue}{\left(-1 \cdot y\right) \cdot \log y} - \frac{1}{2} \cdot \log y\right) + y\right) - z \]
      11. distribute-rgt-out--N/A

        \[\leadsto \left(\color{blue}{\log y \cdot \left(-1 \cdot y - \frac{1}{2}\right)} + y\right) - z \]
      12. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot y - \frac{1}{2}\right) \cdot \log y} + y\right) - z \]
      13. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot y - \frac{1}{2}, \log y, y\right)} - z \]
      14. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} - \frac{1}{2}, \log y, y\right) - z \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right) - \frac{1}{2}}, \log y, y\right) - z \]
      16. lower-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right)} - \frac{1}{2}, \log y, y\right) - z \]
      17. lower-log.f6497.8

        \[\leadsto \mathsf{fma}\left(\left(-y\right) - 0.5, \color{blue}{\log y}, y\right) - z \]
    5. Applied rewrites97.8%

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

    if 4.4000000000000003e39 < x

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f6483.7

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites83.7%

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

Alternative 3: 89.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+50}:\\ \;\;\;\;\left(x + y\right) - \log y \cdot y\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+39}:\\ \;\;\;\;y - \mathsf{fma}\left(0.5 + y, \log y, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -3.4e+50)
   (- (+ x y) (* (log y) y))
   (if (<= x 4.4e+39)
     (- y (fma (+ 0.5 y) (log y) z))
     (- (fma -0.5 (log y) x) z))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.4e+50) {
		tmp = (x + y) - (log(y) * y);
	} else if (x <= 4.4e+39) {
		tmp = y - fma((0.5 + y), log(y), z);
	} else {
		tmp = fma(-0.5, log(y), x) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (x <= -3.4e+50)
		tmp = Float64(Float64(x + y) - Float64(log(y) * y));
	elseif (x <= 4.4e+39)
		tmp = Float64(y - fma(Float64(0.5 + y), log(y), z));
	else
		tmp = Float64(fma(-0.5, log(y), x) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[x, -3.4e+50], N[(N[(x + y), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.4e+39], N[(y - N[(N[(0.5 + y), $MachinePrecision] * N[Log[y], $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+50}:\\
\;\;\;\;\left(x + y\right) - \log y \cdot y\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+39}:\\
\;\;\;\;y - \mathsf{fma}\left(0.5 + y, \log y, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.3999999999999998e50

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
      2. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
      3. lift-*.f64N/A

        \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      6. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
      8. *-commutativeN/A

        \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
      10. lower-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
      11. lower-neg.f6499.9

        \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
      12. lift-+.f64N/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
      13. +-commutativeN/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
      14. lower-+.f6499.9

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
    5. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right) - z} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right)} - z \]
      3. lift-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(\left(-\log y\right) \cdot \left(\frac{1}{2} + y\right) + y\right)}\right) - z \]
      4. +-commutativeN/A

        \[\leadsto \left(x + \color{blue}{\left(y + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)}\right) - z \]
      5. associate-+r+N/A

        \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      6. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      7. lift-+.f64N/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      8. lift-neg.f64N/A

        \[\leadsto \left(\left(y + x\right) + \color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)} \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\left(y + x\right) - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(y + x\right) - \color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)}\right) - z \]
      11. associate--l-N/A

        \[\leadsto \color{blue}{\left(y + x\right) - \left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      12. lift-*.f64N/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)} + z\right) \]
      13. *-commutativeN/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      14. lift-fma.f64N/A

        \[\leadsto \left(y + x\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      15. lower--.f6499.9

        \[\leadsto \color{blue}{\left(y + x\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
      16. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(y + x\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      18. lower-+.f6499.9

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(0.5 + y, \log y, z\right) \]
    6. Applied rewrites99.9%

      \[\leadsto \color{blue}{\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
    7. Taylor expanded in y around inf

      \[\leadsto \left(x + y\right) - \color{blue}{-1 \cdot \left(y \cdot \log \left(\frac{1}{y}\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(x + y\right) - -1 \cdot \color{blue}{\left(\log \left(\frac{1}{y}\right) \cdot y\right)} \]
      2. associate-*r*N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
      3. mul-1-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)} \cdot y \]
      4. log-recN/A

        \[\leadsto \left(x + y\right) - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right) \cdot y \]
      5. remove-double-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
      6. lower-*.f64N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]
      7. lower-log.f6487.4

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
    9. Applied rewrites87.4%

      \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]

    if -3.3999999999999998e50 < x < 4.4000000000000003e39

    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
    4. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto y - \color{blue}{\left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      3. *-commutativeN/A

        \[\leadsto y - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      4. lower-fma.f64N/A

        \[\leadsto y - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      5. lower-+.f64N/A

        \[\leadsto y - \mathsf{fma}\left(\color{blue}{\frac{1}{2} + y}, \log y, z\right) \]
      6. lower-log.f6497.8

        \[\leadsto y - \mathsf{fma}\left(0.5 + y, \color{blue}{\log y}, z\right) \]
    5. Applied rewrites97.8%

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

    if 4.4000000000000003e39 < x

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f6483.7

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites83.7%

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

Alternative 4: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 2.9 \cdot 10^{-19}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(x + \left(1 - \log y\right) \cdot y\right) - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 2.9e-19)
   (- (fma -0.5 (log y) x) z)
   (- (+ x (* (- 1.0 (log y)) y)) z)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 2.9e-19) {
		tmp = fma(-0.5, log(y), x) - z;
	} else {
		tmp = (x + ((1.0 - log(y)) * y)) - z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 2.9e-19)
		tmp = Float64(fma(-0.5, log(y), x) - z);
	else
		tmp = Float64(Float64(x + Float64(Float64(1.0 - log(y)) * y)) - z);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 2.9e-19], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(x + N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 2.9e-19

    1. Initial program 100.0%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f64100.0

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites100.0%

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

    if 2.9e-19 < y

    1. Initial program 99.7%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
      2. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
      3. lift-*.f64N/A

        \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      6. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
      8. *-commutativeN/A

        \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
      10. lower-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
      11. lower-neg.f6499.8

        \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
      12. lift-+.f64N/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
      13. +-commutativeN/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
      14. lower-+.f6499.8

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
    4. Applied rewrites99.8%

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
    5. Taylor expanded in y around inf

      \[\leadsto \left(x + \color{blue}{y \cdot \left(1 + \log \left(\frac{1}{y}\right)\right)}\right) - z \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(x + \color{blue}{\left(1 + \log \left(\frac{1}{y}\right)\right) \cdot y}\right) - z \]
      2. lower-*.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(1 + \log \left(\frac{1}{y}\right)\right) \cdot y}\right) - z \]
      3. *-lft-identityN/A

        \[\leadsto \left(x + \left(1 + \color{blue}{1 \cdot \log \left(\frac{1}{y}\right)}\right) \cdot y\right) - z \]
      4. fp-cancel-sign-sub-invN/A

        \[\leadsto \left(x + \color{blue}{\left(1 - \left(\mathsf{neg}\left(1\right)\right) \cdot \log \left(\frac{1}{y}\right)\right)} \cdot y\right) - z \]
      5. metadata-evalN/A

        \[\leadsto \left(x + \left(1 - \color{blue}{-1} \cdot \log \left(\frac{1}{y}\right)\right) \cdot y\right) - z \]
      6. mul-1-negN/A

        \[\leadsto \left(x + \left(1 - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)}\right) \cdot y\right) - z \]
      7. log-recN/A

        \[\leadsto \left(x + \left(1 - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right)\right) \cdot y\right) - z \]
      8. remove-double-negN/A

        \[\leadsto \left(x + \left(1 - \color{blue}{\log y}\right) \cdot y\right) - z \]
      9. lower--.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(1 - \log y\right)} \cdot y\right) - z \]
      10. lower-log.f6498.1

        \[\leadsto \left(x + \left(1 - \color{blue}{\log y}\right) \cdot y\right) - z \]
    7. Applied rewrites98.1%

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

Alternative 5: 85.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(x + y\right) - \log y \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 7.2e+171) (- (fma -0.5 (log y) x) z) (- (+ x y) (* (log y) y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 7.2e+171) {
		tmp = fma(-0.5, log(y), x) - z;
	} else {
		tmp = (x + y) - (log(y) * y);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 7.2e+171)
		tmp = Float64(fma(-0.5, log(y), x) - z);
	else
		tmp = Float64(Float64(x + y) - Float64(log(y) * y));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 7.2e+171], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(x + y), $MachinePrecision] - N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 7.20000000000000036e171

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f6486.1

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites86.1%

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

    if 7.20000000000000036e171 < y

    1. Initial program 99.5%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
      2. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
      3. lift-*.f64N/A

        \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      6. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
      8. *-commutativeN/A

        \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
      10. lower-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
      11. lower-neg.f6499.6

        \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
      12. lift-+.f64N/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
      13. +-commutativeN/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
      14. lower-+.f6499.6

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
    4. Applied rewrites99.6%

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
    5. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right) - z} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right)} - z \]
      3. lift-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(\left(-\log y\right) \cdot \left(\frac{1}{2} + y\right) + y\right)}\right) - z \]
      4. +-commutativeN/A

        \[\leadsto \left(x + \color{blue}{\left(y + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)}\right) - z \]
      5. associate-+r+N/A

        \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      6. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      7. lift-+.f64N/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      8. lift-neg.f64N/A

        \[\leadsto \left(\left(y + x\right) + \color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)} \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\left(y + x\right) - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(y + x\right) - \color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)}\right) - z \]
      11. associate--l-N/A

        \[\leadsto \color{blue}{\left(y + x\right) - \left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      12. lift-*.f64N/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)} + z\right) \]
      13. *-commutativeN/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      14. lift-fma.f64N/A

        \[\leadsto \left(y + x\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      15. lower--.f6499.6

        \[\leadsto \color{blue}{\left(y + x\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
      16. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(y + x\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      18. lower-+.f6499.6

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(0.5 + y, \log y, z\right) \]
    6. Applied rewrites99.6%

      \[\leadsto \color{blue}{\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
    7. Taylor expanded in y around inf

      \[\leadsto \left(x + y\right) - \color{blue}{-1 \cdot \left(y \cdot \log \left(\frac{1}{y}\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(x + y\right) - -1 \cdot \color{blue}{\left(\log \left(\frac{1}{y}\right) \cdot y\right)} \]
      2. associate-*r*N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
      3. mul-1-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)} \cdot y \]
      4. log-recN/A

        \[\leadsto \left(x + y\right) - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right) \cdot y \]
      5. remove-double-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
      6. lower-*.f64N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]
      7. lower-log.f6492.9

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
    9. Applied rewrites92.9%

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

Alternative 6: 85.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(y - \log y \cdot y\right) + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 7.2e+171) (- (fma -0.5 (log y) x) z) (+ (- y (* (log y) y)) x)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 7.2e+171) {
		tmp = fma(-0.5, log(y), x) - z;
	} else {
		tmp = (y - (log(y) * y)) + x;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 7.2e+171)
		tmp = Float64(fma(-0.5, log(y), x) - z);
	else
		tmp = Float64(Float64(y - Float64(log(y) * y)) + x);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 7.2e+171], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(y - N[(N[Log[y], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 7.20000000000000036e171

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f6486.1

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites86.1%

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

    if 7.20000000000000036e171 < y

    1. Initial program 99.5%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
      2. lift--.f64N/A

        \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
      3. lift-*.f64N/A

        \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      6. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
      7. distribute-lft-neg-outN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
      8. *-commutativeN/A

        \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
      9. distribute-lft-neg-inN/A

        \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
      10. lower-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
      11. lower-neg.f6499.6

        \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
      12. lift-+.f64N/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
      13. +-commutativeN/A

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
      14. lower-+.f6499.6

        \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
    4. Applied rewrites99.6%

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
    5. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right) - z} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right)} - z \]
      3. lift-fma.f64N/A

        \[\leadsto \left(x + \color{blue}{\left(\left(-\log y\right) \cdot \left(\frac{1}{2} + y\right) + y\right)}\right) - z \]
      4. +-commutativeN/A

        \[\leadsto \left(x + \color{blue}{\left(y + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)}\right) - z \]
      5. associate-+r+N/A

        \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      6. +-commutativeN/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      7. lift-+.f64N/A

        \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      8. lift-neg.f64N/A

        \[\leadsto \left(\left(y + x\right) + \color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)} \cdot \left(\frac{1}{2} + y\right)\right) - z \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(\left(y + x\right) - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
      10. lift-*.f64N/A

        \[\leadsto \left(\left(y + x\right) - \color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)}\right) - z \]
      11. associate--l-N/A

        \[\leadsto \color{blue}{\left(y + x\right) - \left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      12. lift-*.f64N/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)} + z\right) \]
      13. *-commutativeN/A

        \[\leadsto \left(y + x\right) - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      14. lift-fma.f64N/A

        \[\leadsto \left(y + x\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      15. lower--.f6499.6

        \[\leadsto \color{blue}{\left(y + x\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
      16. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(y + x\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
      18. lower-+.f6499.6

        \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(0.5 + y, \log y, z\right) \]
    6. Applied rewrites99.6%

      \[\leadsto \color{blue}{\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
    7. Taylor expanded in y around inf

      \[\leadsto \left(x + y\right) - \color{blue}{-1 \cdot \left(y \cdot \log \left(\frac{1}{y}\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(x + y\right) - -1 \cdot \color{blue}{\left(\log \left(\frac{1}{y}\right) \cdot y\right)} \]
      2. associate-*r*N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
      3. mul-1-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)} \cdot y \]
      4. log-recN/A

        \[\leadsto \left(x + y\right) - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right) \cdot y \]
      5. remove-double-negN/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
      6. lower-*.f64N/A

        \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]
      7. lower-log.f6492.9

        \[\leadsto \left(x + y\right) - \color{blue}{\log y} \cdot y \]
    9. Applied rewrites92.9%

      \[\leadsto \left(x + y\right) - \color{blue}{\log y \cdot y} \]
    10. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + y\right) - \log y \cdot y} \]
      2. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x + y\right)} - \log y \cdot y \]
      3. associate--l+N/A

        \[\leadsto \color{blue}{x + \left(y - \log y \cdot y\right)} \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{\left(y - \log y \cdot y\right) + x} \]
      5. lower-+.f64N/A

        \[\leadsto \color{blue}{\left(y - \log y \cdot y\right) + x} \]
      6. lower--.f6492.9

        \[\leadsto \color{blue}{\left(y - \log y \cdot y\right)} + x \]
    11. Applied rewrites92.9%

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

Alternative 7: 82.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.28 \cdot 10^{+172}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \log y\right) \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.28e+172) (- (fma -0.5 (log y) x) z) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.28e+172) {
		tmp = fma(-0.5, log(y), x) - z;
	} else {
		tmp = (1.0 - log(y)) * y;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.28e+172)
		tmp = Float64(fma(-0.5, log(y), x) - z);
	else
		tmp = Float64(Float64(1.0 - log(y)) * y);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 1.28e+172], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.28 \cdot 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.28000000000000004e172

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x - \left(z + \frac{1}{2} \cdot \log y\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x - \color{blue}{\left(\frac{1}{2} \cdot \log y + z\right)} \]
      2. associate--r+N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      3. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x - \frac{1}{2} \cdot \log y\right) - z} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \color{blue}{\left(x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y\right)} - z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \log y + x\right)} - z \]
      6. metadata-evalN/A

        \[\leadsto \left(\color{blue}{\frac{-1}{2}} \cdot \log y + x\right) - z \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{2}, \log y, x\right)} - z \]
      8. lower-log.f6486.1

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, x\right) - z \]
    5. Applied rewrites86.1%

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

    if 1.28000000000000004e172 < y

    1. Initial program 99.5%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(1 - -1 \cdot \log \left(\frac{1}{y}\right)\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 - -1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
      2. mul-1-negN/A

        \[\leadsto \left(1 - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)}\right) \cdot y \]
      3. log-recN/A

        \[\leadsto \left(1 - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right)\right) \cdot y \]
      4. remove-double-negN/A

        \[\leadsto \left(1 - \color{blue}{\log y}\right) \cdot y \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(1 - \log y\right) \cdot y} \]
      6. lower--.f64N/A

        \[\leadsto \color{blue}{\left(1 - \log y\right)} \cdot y \]
      7. lower-log.f6480.1

        \[\leadsto \left(1 - \color{blue}{\log y}\right) \cdot y \]
    5. Applied rewrites80.1%

      \[\leadsto \color{blue}{\left(1 - \log y\right) \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ x y) (fma (+ 0.5 y) (log y) z)))
double code(double x, double y, double z) {
	return (x + y) - fma((0.5 + y), log(y), z);
}
function code(x, y, z)
	return Float64(Float64(x + y) - fma(Float64(0.5 + y), log(y), z))
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] - N[(N[(0.5 + y), $MachinePrecision] * N[Log[y], $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right) + y\right)} - z \]
    2. lift--.f64N/A

      \[\leadsto \left(\color{blue}{\left(x - \left(y + \frac{1}{2}\right) \cdot \log y\right)} + y\right) - z \]
    3. lift-*.f64N/A

      \[\leadsto \left(\left(x - \color{blue}{\left(y + \frac{1}{2}\right) \cdot \log y}\right) + y\right) - z \]
    4. fp-cancel-sub-sign-invN/A

      \[\leadsto \left(\color{blue}{\left(x + \left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y\right)} + y\right) - z \]
    5. associate-+l+N/A

      \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
    6. lower-+.f64N/A

      \[\leadsto \color{blue}{\left(x + \left(\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right)\right)\right) \cdot \log y + y\right)\right)} - z \]
    7. distribute-lft-neg-outN/A

      \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\left(y + \frac{1}{2}\right) \cdot \log y\right)\right)} + y\right)\right) - z \]
    8. *-commutativeN/A

      \[\leadsto \left(x + \left(\left(\mathsf{neg}\left(\color{blue}{\log y \cdot \left(y + \frac{1}{2}\right)}\right)\right) + y\right)\right) - z \]
    9. distribute-lft-neg-inN/A

      \[\leadsto \left(x + \left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right) \cdot \left(y + \frac{1}{2}\right)} + y\right)\right) - z \]
    10. lower-fma.f64N/A

      \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\log y\right), y + \frac{1}{2}, y\right)}\right) - z \]
    11. lower-neg.f6499.9

      \[\leadsto \left(x + \mathsf{fma}\left(\color{blue}{-\log y}, y + 0.5, y\right)\right) - z \]
    12. lift-+.f64N/A

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{y + \frac{1}{2}}, y\right)\right) - z \]
    13. +-commutativeN/A

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{\frac{1}{2} + y}, y\right)\right) - z \]
    14. lower-+.f6499.9

      \[\leadsto \left(x + \mathsf{fma}\left(-\log y, \color{blue}{0.5 + y}, y\right)\right) - z \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, 0.5 + y, y\right)\right)} - z \]
  5. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right) - z} \]
    2. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(x + \mathsf{fma}\left(-\log y, \frac{1}{2} + y, y\right)\right)} - z \]
    3. lift-fma.f64N/A

      \[\leadsto \left(x + \color{blue}{\left(\left(-\log y\right) \cdot \left(\frac{1}{2} + y\right) + y\right)}\right) - z \]
    4. +-commutativeN/A

      \[\leadsto \left(x + \color{blue}{\left(y + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)}\right) - z \]
    5. associate-+r+N/A

      \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
    6. +-commutativeN/A

      \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
    7. lift-+.f64N/A

      \[\leadsto \left(\color{blue}{\left(y + x\right)} + \left(-\log y\right) \cdot \left(\frac{1}{2} + y\right)\right) - z \]
    8. lift-neg.f64N/A

      \[\leadsto \left(\left(y + x\right) + \color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)} \cdot \left(\frac{1}{2} + y\right)\right) - z \]
    9. fp-cancel-sub-sign-invN/A

      \[\leadsto \color{blue}{\left(\left(y + x\right) - \log y \cdot \left(\frac{1}{2} + y\right)\right)} - z \]
    10. lift-*.f64N/A

      \[\leadsto \left(\left(y + x\right) - \color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)}\right) - z \]
    11. associate--l-N/A

      \[\leadsto \color{blue}{\left(y + x\right) - \left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
    12. lift-*.f64N/A

      \[\leadsto \left(y + x\right) - \left(\color{blue}{\log y \cdot \left(\frac{1}{2} + y\right)} + z\right) \]
    13. *-commutativeN/A

      \[\leadsto \left(y + x\right) - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
    14. lift-fma.f64N/A

      \[\leadsto \left(y + x\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
    15. lower--.f6499.8

      \[\leadsto \color{blue}{\left(y + x\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
    16. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(y + x\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
    17. +-commutativeN/A

      \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right) \]
    18. lower-+.f6499.8

      \[\leadsto \color{blue}{\left(x + y\right)} - \mathsf{fma}\left(0.5 + y, \log y, z\right) \]
  6. Applied rewrites99.8%

    \[\leadsto \color{blue}{\left(x + y\right) - \mathsf{fma}\left(0.5 + y, \log y, z\right)} \]
  7. Add Preprocessing

Alternative 9: 56.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \log y, -z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \log y\right) \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 7.2e+171) (fma -0.5 (log y) (- z)) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 7.2e+171) {
		tmp = fma(-0.5, log(y), -z);
	} else {
		tmp = (1.0 - log(y)) * y;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= 7.2e+171)
		tmp = fma(-0.5, log(y), Float64(-z));
	else
		tmp = Float64(Float64(1.0 - log(y)) * y);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, 7.2e+171], N[(-0.5 * N[Log[y], $MachinePrecision] + (-z)), $MachinePrecision], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+171}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, -z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 7.20000000000000036e171

    1. Initial program 99.9%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
    4. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto y - \color{blue}{\left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      3. *-commutativeN/A

        \[\leadsto y - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      4. lower-fma.f64N/A

        \[\leadsto y - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      5. lower-+.f64N/A

        \[\leadsto y - \mathsf{fma}\left(\color{blue}{\frac{1}{2} + y}, \log y, z\right) \]
      6. lower-log.f6464.9

        \[\leadsto y - \mathsf{fma}\left(0.5 + y, \color{blue}{\log y}, z\right) \]
    5. Applied rewrites64.9%

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

      \[\leadsto -1 \cdot \color{blue}{\left(z + \frac{1}{2} \cdot \log y\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites51.7%

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

      if 7.20000000000000036e171 < y

      1. Initial program 99.5%

        \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
      2. Add Preprocessing
      3. Taylor expanded in y around inf

        \[\leadsto \color{blue}{y \cdot \left(1 - -1 \cdot \log \left(\frac{1}{y}\right)\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(1 - -1 \cdot \log \left(\frac{1}{y}\right)\right) \cdot y} \]
        2. mul-1-negN/A

          \[\leadsto \left(1 - \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{1}{y}\right)\right)\right)}\right) \cdot y \]
        3. log-recN/A

          \[\leadsto \left(1 - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\log y\right)\right)}\right)\right)\right) \cdot y \]
        4. remove-double-negN/A

          \[\leadsto \left(1 - \color{blue}{\log y}\right) \cdot y \]
        5. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(1 - \log y\right) \cdot y} \]
        6. lower--.f64N/A

          \[\leadsto \color{blue}{\left(1 - \log y\right)} \cdot y \]
        7. lower-log.f6480.1

          \[\leadsto \left(1 - \color{blue}{\log y}\right) \cdot y \]
      5. Applied rewrites80.1%

        \[\leadsto \color{blue}{\left(1 - \log y\right) \cdot y} \]
    8. Recombined 2 regimes into one program.
    9. Add Preprocessing

    Alternative 10: 42.2% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(-0.5, \log y, -z\right) \end{array} \]
    (FPCore (x y z) :precision binary64 (fma -0.5 (log y) (- z)))
    double code(double x, double y, double z) {
    	return fma(-0.5, log(y), -z);
    }
    
    function code(x, y, z)
    	return fma(-0.5, log(y), Float64(-z))
    end
    
    code[x_, y_, z_] := N[(-0.5 * N[Log[y], $MachinePrecision] + (-z)), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(-0.5, \log y, -z\right)
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
    4. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \color{blue}{y - \left(z + \log y \cdot \left(\frac{1}{2} + y\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto y - \color{blue}{\left(\log y \cdot \left(\frac{1}{2} + y\right) + z\right)} \]
      3. *-commutativeN/A

        \[\leadsto y - \left(\color{blue}{\left(\frac{1}{2} + y\right) \cdot \log y} + z\right) \]
      4. lower-fma.f64N/A

        \[\leadsto y - \color{blue}{\mathsf{fma}\left(\frac{1}{2} + y, \log y, z\right)} \]
      5. lower-+.f64N/A

        \[\leadsto y - \mathsf{fma}\left(\color{blue}{\frac{1}{2} + y}, \log y, z\right) \]
      6. lower-log.f6469.2

        \[\leadsto y - \mathsf{fma}\left(0.5 + y, \color{blue}{\log y}, z\right) \]
    5. Applied rewrites69.2%

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

      \[\leadsto -1 \cdot \color{blue}{\left(z + \frac{1}{2} \cdot \log y\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites43.0%

        \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{\log y}, -z\right) \]
      2. Add Preprocessing

      Alternative 11: 30.3% accurate, 39.3× speedup?

      \[\begin{array}{l} \\ -z \end{array} \]
      (FPCore (x y z) :precision binary64 (- z))
      double code(double x, double y, double z) {
      	return -z;
      }
      
      real(8) function code(x, y, z)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          code = -z
      end function
      
      public static double code(double x, double y, double z) {
      	return -z;
      }
      
      def code(x, y, z):
      	return -z
      
      function code(x, y, z)
      	return Float64(-z)
      end
      
      function tmp = code(x, y, z)
      	tmp = -z;
      end
      
      code[x_, y_, z_] := (-z)
      
      \begin{array}{l}
      
      \\
      -z
      \end{array}
      
      Derivation
      1. Initial program 99.8%

        \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
      2. Add Preprocessing
      3. Taylor expanded in z around inf

        \[\leadsto \color{blue}{-1 \cdot z} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
        2. lower-neg.f6433.2

          \[\leadsto \color{blue}{-z} \]
      5. Applied rewrites33.2%

        \[\leadsto \color{blue}{-z} \]
      6. Add Preprocessing

      Developer Target 1: 99.8% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y \end{array} \]
      (FPCore (x y z) :precision binary64 (- (- (+ y x) z) (* (+ y 0.5) (log y))))
      double code(double x, double y, double z) {
      	return ((y + x) - z) - ((y + 0.5) * log(y));
      }
      
      real(8) function code(x, y, z)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          code = ((y + x) - z) - ((y + 0.5d0) * log(y))
      end function
      
      public static double code(double x, double y, double z) {
      	return ((y + x) - z) - ((y + 0.5) * Math.log(y));
      }
      
      def code(x, y, z):
      	return ((y + x) - z) - ((y + 0.5) * math.log(y))
      
      function code(x, y, z)
      	return Float64(Float64(Float64(y + x) - z) - Float64(Float64(y + 0.5) * log(y)))
      end
      
      function tmp = code(x, y, z)
      	tmp = ((y + x) - z) - ((y + 0.5) * log(y));
      end
      
      code[x_, y_, z_] := N[(N[(N[(y + x), $MachinePrecision] - z), $MachinePrecision] - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y
      \end{array}
      

      Reproduce

      ?
      herbie shell --seed 2024338 
      (FPCore (x y z)
        :name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
        :precision binary64
      
        :alt
        (! :herbie-platform default (- (- (+ y x) z) (* (+ y 1/2) (log y))))
      
        (- (+ (- x (* (+ y 0.5) (log y))) y) z))