System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2

Percentage Accurate: 99.9% → 99.9%
Time: 7.7s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + log(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 * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z):
	return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z)
	return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z))))
end
function tmp = code(x, y, z)
	tmp = (x * 0.5) + (y * ((1.0 - z) + log(z)));
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\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 9 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.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + log(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 * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
	return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z):
	return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z)
	return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z))))
end
function tmp = code(x, y, z)
	tmp = (x * 0.5) + (y * ((1.0 - z) + log(z)));
end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.75 \cdot 10^{+50} \lor \neg \left(y \leq 8.2 \cdot 10^{+86}\right):\\ \;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -2.75e+50) (not (<= y 8.2e+86)))
   (fma (- (log z) z) y y)
   (fma (- z) y (* 0.5 x))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.75e+50) || !(y <= 8.2e+86)) {
		tmp = fma((log(z) - z), y, y);
	} else {
		tmp = fma(-z, y, (0.5 * x));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((y <= -2.75e+50) || !(y <= 8.2e+86))
		tmp = fma(Float64(log(z) - z), y, y);
	else
		tmp = fma(Float64(-z), y, Float64(0.5 * x));
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.75e+50], N[Not[LessEqual[y, 8.2e+86]], $MachinePrecision]], N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y + y), $MachinePrecision], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.75 \cdot 10^{+50} \lor \neg \left(y \leq 8.2 \cdot 10^{+86}\right):\\
\;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.7499999999999999e50 or 8.1999999999999998e86 < y

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{y \cdot \left(\left(1 + \log z\right) - z\right)} \]
    4. Step-by-step derivation
      1. associate--l+N/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log z - z}, y, y\right) \]
      7. lower-log.f6491.2

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

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

    if -2.7499999999999999e50 < y < 8.1999999999999998e86

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot z}, y, \frac{1}{2} \cdot x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.75 \cdot 10^{+50} \lor \neg \left(y \leq 8.2 \cdot 10^{+86}\right):\\ \;\;\;\;\mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.8% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 9.00000000000000057e-5

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.00000000000000057e-5 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot z}, y, \frac{1}{2} \cdot x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

Alternative 4: 98.8% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 9.00000000000000057e-5

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

    if 9.00000000000000057e-5 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot z}, y, \frac{1}{2} \cdot x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 9 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 99.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 74.9% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 4.0999999999999998e-10

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \left(\left(1 + \log z\right) - z\right)} \]
    6. Step-by-step derivation
      1. associate--l+N/A

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log z - z}, y, y\right) \]
      8. lower-log.f6459.0

        \[\leadsto \mathsf{fma}\left(\color{blue}{\log z} - z, y, y\right) \]
    7. Applied rewrites59.0%

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

      \[\leadsto \mathsf{fma}\left(\log z, y, y\right) \]
    9. Step-by-step derivation
      1. Applied rewrites58.5%

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

      if 4.0999999999999998e-10 < z

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot z}, y, \frac{1}{2} \cdot x\right) \]
      6. Step-by-step derivation
        1. mul-1-negN/A

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

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

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

    Alternative 8: 75.0% accurate, 8.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{-1 \cdot z}, y, \frac{1}{2} \cdot x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

    Alternative 9: 37.3% accurate, 15.0× speedup?

    \[\begin{array}{l} \\ \left(-y\right) \cdot z \end{array} \]
    (FPCore (x y z) :precision binary64 (* (- y) z))
    double code(double x, double y, double z) {
    	return -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 = -y * z
    end function
    
    public static double code(double x, double y, double z) {
    	return -y * z;
    }
    
    def code(x, y, z):
    	return -y * z
    
    function code(x, y, z)
    	return Float64(Float64(-y) * z)
    end
    
    function tmp = code(x, y, z)
    	tmp = -y * z;
    end
    
    code[x_, y_, z_] := N[((-y) * z), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \left(-y\right) \cdot z
    \end{array}
    
    Derivation
    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    4. Step-by-step derivation
      1. associate-*r*N/A

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot z \]
      4. lower-neg.f6434.8

        \[\leadsto \color{blue}{\left(-y\right)} \cdot z \]
    5. Applied rewrites34.8%

      \[\leadsto \color{blue}{\left(-y\right) \cdot z} \]
    6. Final simplification34.8%

      \[\leadsto \left(-y\right) \cdot z \]
    7. Add Preprocessing

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

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

    Reproduce

    ?
    herbie shell --seed 2024326 
    (FPCore (x y z)
      :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
      :precision binary64
    
      :alt
      (! :herbie-platform default (- (+ y (* 1/2 x)) (* y (- z (log z)))))
    
      (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))