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

Percentage Accurate: 99.9% → 99.7%
Time: 9.9s
Alternatives: 10
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 10 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.7% accurate, 1.0× speedup?

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

\\
\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, \mathsf{fma}\left(y, \log z, y\right)\right)\right)
\end{array}
Derivation
  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 x \cdot \frac{1}{2} + \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right)} \]
    2. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 60.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(1 - z\right) + \log z\right) \cdot y\\ t_1 := y \cdot \left(-z\right)\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+22}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (+ (- 1.0 z) (log z)) y)) (t_1 (* y (- z))))
   (if (<= t_0 -1e+22) t_1 (if (<= t_0 2e+157) (* 0.5 x) t_1))))
double code(double x, double y, double z) {
	double t_0 = ((1.0 - z) + log(z)) * y;
	double t_1 = y * -z;
	double tmp;
	if (t_0 <= -1e+22) {
		tmp = t_1;
	} else if (t_0 <= 2e+157) {
		tmp = 0.5 * x;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((1.0d0 - z) + log(z)) * y
    t_1 = y * -z
    if (t_0 <= (-1d+22)) then
        tmp = t_1
    else if (t_0 <= 2d+157) then
        tmp = 0.5d0 * x
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = ((1.0 - z) + Math.log(z)) * y;
	double t_1 = y * -z;
	double tmp;
	if (t_0 <= -1e+22) {
		tmp = t_1;
	} else if (t_0 <= 2e+157) {
		tmp = 0.5 * x;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = ((1.0 - z) + math.log(z)) * y
	t_1 = y * -z
	tmp = 0
	if t_0 <= -1e+22:
		tmp = t_1
	elif t_0 <= 2e+157:
		tmp = 0.5 * x
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(Float64(1.0 - z) + log(z)) * y)
	t_1 = Float64(y * Float64(-z))
	tmp = 0.0
	if (t_0 <= -1e+22)
		tmp = t_1;
	elseif (t_0 <= 2e+157)
		tmp = Float64(0.5 * x);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = ((1.0 - z) + log(z)) * y;
	t_1 = y * -z;
	tmp = 0.0;
	if (t_0 <= -1e+22)
		tmp = t_1;
	elseif (t_0 <= 2e+157)
		tmp = 0.5 * x;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$1 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+22], t$95$1, If[LessEqual[t$95$0, 2e+157], N[(0.5 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\left(1 - z\right) + \log z\right) \cdot y\\
t_1 := y \cdot \left(-z\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+22}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+157}:\\
\;\;\;\;0.5 \cdot x\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < -1e22 or 1.99999999999999997e157 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z)))

    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. mul-1-negN/A

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot y} \]
      5. lower-neg.f6459.9

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

      \[\leadsto \color{blue}{\left(-z\right) \cdot y} \]

    if -1e22 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < 1.99999999999999997e157

    1. Initial program 99.9%

      \[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.f6487.0

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot x \]
      3. Step-by-step derivation
        1. Applied rewrites64.8%

          \[\leadsto 0.5 \cdot x \]
      4. Recombined 2 regimes into one program.
      5. Final simplification62.5%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(1 - z\right) + \log z\right) \cdot y \leq -1 \cdot 10^{+22}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;\left(\left(1 - z\right) + \log z\right) \cdot y \leq 2 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]
      6. Add Preprocessing

      Alternative 3: 74.7% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(1 - z\right) + \log z \leq -210:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, \left(-z\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= (+ (- 1.0 z) (log z)) -210.0)
         (fma x 0.5 (* (- z) y))
         (fma (log z) y y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if (((1.0 - z) + log(z)) <= -210.0) {
      		tmp = fma(x, 0.5, (-z * y));
      	} else {
      		tmp = fma(log(z), y, y);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if (Float64(Float64(1.0 - z) + log(z)) <= -210.0)
      		tmp = fma(x, 0.5, Float64(Float64(-z) * y));
      	else
      		tmp = fma(log(z), y, y);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[LessEqual[N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision], -210.0], N[(x * 0.5 + N[((-z) * y), $MachinePrecision]), $MachinePrecision], N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left(1 - z\right) + \log z \leq -210:\\
      \;\;\;\;\mathsf{fma}\left(x, 0.5, \left(-z\right) \cdot y\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z)) < -210

        1. Initial program 99.9%

          \[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 x \cdot \frac{1}{2} + y \cdot \color{blue}{\left(-1 \cdot z\right)} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto x \cdot \frac{1}{2} + y \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \]
          2. lower-neg.f6481.7

            \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(-z\right)} \]
        5. Applied rewrites81.7%

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

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

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

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

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

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

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

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

        if -210 < (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))

        1. Initial program 99.6%

          \[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.f6490.6

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

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

          \[\leadsto y + \color{blue}{y \cdot \log z} \]
        7. Step-by-step derivation
          1. Applied rewrites59.3%

            \[\leadsto \mathsf{fma}\left(\log z, \color{blue}{y}, y\right) \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 4: 85.2% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{if}\;y \leq -1.2:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{+47}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, \left(-z\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (fma (- (log z) z) y y)))
           (if (<= y -1.2) t_0 (if (<= y 5.4e+47) (fma x 0.5 (* (- z) y)) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = fma((log(z) - z), y, y);
        	double tmp;
        	if (y <= -1.2) {
        		tmp = t_0;
        	} else if (y <= 5.4e+47) {
        		tmp = fma(x, 0.5, (-z * y));
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	t_0 = fma(Float64(log(z) - z), y, y)
        	tmp = 0.0
        	if (y <= -1.2)
        		tmp = t_0;
        	elseif (y <= 5.4e+47)
        		tmp = fma(x, 0.5, Float64(Float64(-z) * y));
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y + y), $MachinePrecision]}, If[LessEqual[y, -1.2], t$95$0, If[LessEqual[y, 5.4e+47], N[(x * 0.5 + N[((-z) * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \mathsf{fma}\left(\log z - z, y, y\right)\\
        \mathbf{if}\;y \leq -1.2:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;y \leq 5.4 \cdot 10^{+47}:\\
        \;\;\;\;\mathsf{fma}\left(x, 0.5, \left(-z\right) \cdot y\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -1.19999999999999996 or 5.39999999999999991e47 < 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. sub-negN/A

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(\log z + \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}, y, y\right) \]
            9. sub-negN/A

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

              \[\leadsto \mathsf{fma}\left(\color{blue}{\log z - z}, y, y\right) \]
            11. lower-log.f6487.9

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

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

          if -1.19999999999999996 < y < 5.39999999999999991e47

          1. Initial program 100.0%

            \[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 x \cdot \frac{1}{2} + y \cdot \color{blue}{\left(-1 \cdot z\right)} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto x \cdot \frac{1}{2} + y \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \]
            2. lower-neg.f6487.4

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

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

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

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

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

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

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

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

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

        Alternative 5: 98.8% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 0.55:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= z 0.55) (fma (log z) y (fma 0.5 x y)) (fma (- z) y (fma 0.5 x y))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (z <= 0.55) {
        		tmp = fma(log(z), y, fma(0.5, x, y));
        	} else {
        		tmp = fma(-z, y, fma(0.5, x, y));
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if (z <= 0.55)
        		tmp = fma(log(z), y, fma(0.5, x, y));
        	else
        		tmp = fma(Float64(-z), y, fma(0.5, x, y));
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[LessEqual[z, 0.55], N[(N[Log[z], $MachinePrecision] * y + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision], N[((-z) * y + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;z \leq 0.55:\\
        \;\;\;\;\mathsf{fma}\left(\log z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if z < 0.55000000000000004

          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 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.f6498.6

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)} \]
          6. Step-by-step derivation
            1. Applied rewrites98.6%

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

            if 0.55000000000000004 < 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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(-1 \cdot z, y, \mathsf{fma}\left(\frac{1}{2}, x, y\right)\right) \]
            9. Step-by-step derivation
              1. Applied rewrites98.6%

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

            Alternative 6: 98.8% accurate, 1.0× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 0.55:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (<= z 0.55) (fma 0.5 x (fma (log z) y y)) (fma (- z) y (fma 0.5 x y))))
            double code(double x, double y, double z) {
            	double tmp;
            	if (z <= 0.55) {
            		tmp = fma(0.5, x, fma(log(z), y, y));
            	} else {
            		tmp = fma(-z, y, fma(0.5, x, y));
            	}
            	return tmp;
            }
            
            function code(x, y, z)
            	tmp = 0.0
            	if (z <= 0.55)
            		tmp = fma(0.5, x, fma(log(z), y, y));
            	else
            		tmp = fma(Float64(-z), y, fma(0.5, x, y));
            	end
            	return tmp
            end
            
            code[x_, y_, z_] := If[LessEqual[z, 0.55], N[(0.5 * x + N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]), $MachinePrecision], N[((-z) * y + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;z \leq 0.55:\\
            \;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{fma}\left(-z, y, \mathsf{fma}\left(0.5, x, y\right)\right)\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if z < 0.55000000000000004

              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 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.f6498.6

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

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

              if 0.55000000000000004 < 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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(-1 \cdot z, y, \mathsf{fma}\left(\frac{1}{2}, x, y\right)\right) \]
              9. Step-by-step derivation
                1. Applied rewrites98.6%

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

              Alternative 7: 99.9% accurate, 1.0× speedup?

              \[\begin{array}{l} \\ \mathsf{fma}\left(\left(1 + \log z\right) - z, y, x \cdot 0.5\right) \end{array} \]
              (FPCore (x y z) :precision binary64 (fma (- (+ 1.0 (log z)) z) y (* x 0.5)))
              double code(double x, double y, double z) {
              	return fma(((1.0 + log(z)) - z), y, (x * 0.5));
              }
              
              function code(x, y, z)
              	return fma(Float64(Float64(1.0 + log(z)) - z), y, Float64(x * 0.5))
              end
              
              code[x_, y_, z_] := N[(N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \mathsf{fma}\left(\left(1 + \log z\right) - z, y, x \cdot 0.5\right)
              \end{array}
              
              Derivation
              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. Final simplification99.9%

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

              Alternative 8: 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.9%

                \[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. sub-negN/A

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{\left(\log z + -1 \cdot 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 + -1 \cdot z, y, \frac{1}{2} \cdot x + y\right)} \]
                10. mul-1-negN/A

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

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

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

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

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

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

              Alternative 9: 75.3% accurate, 8.6× speedup?

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

                \[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 x \cdot \frac{1}{2} + y \cdot \color{blue}{\left(-1 \cdot z\right)} \]
              4. Step-by-step derivation
                1. mul-1-negN/A

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

                  \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(-z\right)} \]
              5. Applied rewrites75.1%

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

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

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

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

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

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

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

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

              Alternative 10: 39.7% accurate, 20.0× speedup?

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

                \[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.f6464.0

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

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

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

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

                  \[\leadsto \frac{1}{2} \cdot x \]
                3. Step-by-step derivation
                  1. Applied rewrites40.4%

                    \[\leadsto 0.5 \cdot x \]
                  2. 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 2024294 
                  (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)))))