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

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

\\
\left(\log z + \left(1 - z\right)\right) \cdot y + 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. Final simplification99.9%

    \[\leadsto \left(\log z + \left(1 - z\right)\right) \cdot y + 0.5 \cdot x \]
  4. Add Preprocessing

Alternative 2: 73.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\log z, y, y\right)\\ t_1 := \log z + \left(1 - z\right)\\ \mathbf{if}\;t\_1 \leq -520:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \mathbf{elif}\;t\_1 \leq -370:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq -100:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -z, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma (log z) y y)) (t_1 (+ (log z) (- 1.0 z))))
   (if (<= t_1 -520.0)
     (fma (- z) y (* 0.5 x))
     (if (<= t_1 -370.0)
       t_0
       (if (<= t_1 -100.0) (* (fma (/ y x) (- z) 0.5) x) t_0)))))
double code(double x, double y, double z) {
	double t_0 = fma(log(z), y, y);
	double t_1 = log(z) + (1.0 - z);
	double tmp;
	if (t_1 <= -520.0) {
		tmp = fma(-z, y, (0.5 * x));
	} else if (t_1 <= -370.0) {
		tmp = t_0;
	} else if (t_1 <= -100.0) {
		tmp = fma((y / x), -z, 0.5) * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = fma(log(z), y, y)
	t_1 = Float64(log(z) + Float64(1.0 - z))
	tmp = 0.0
	if (t_1 <= -520.0)
		tmp = fma(Float64(-z), y, Float64(0.5 * x));
	elseif (t_1 <= -370.0)
		tmp = t_0;
	elseif (t_1 <= -100.0)
		tmp = Float64(fma(Float64(y / x), Float64(-z), 0.5) * x);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[z], $MachinePrecision] + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -520.0], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -370.0], t$95$0, If[LessEqual[t$95$1, -100.0], N[(N[(N[(y / x), $MachinePrecision] * (-z) + 0.5), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\log z, y, y\right)\\
t_1 := \log z + \left(1 - z\right)\\
\mathbf{if}\;t\_1 \leq -520:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\

\mathbf{elif}\;t\_1 \leq -370:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq -100:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -z, 0.5\right) \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z)) < -520

    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.f6492.0

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

      \[\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. +-commutativeN/A

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

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

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

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

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

    if -520 < (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z)) < -370 or -100 < (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))

    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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

      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. 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.f6499.8

          \[\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-*.f6499.8

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

        \[\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 z around inf

        \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
      6. 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.f644.1

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

        \[\leadsto \color{blue}{\left(-z\right) \cdot y} \]
      8. Taylor expanded in x around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\frac{y}{x}, -z, 0.5\right) \cdot x \]
      13. Recombined 3 regimes into one program.
      14. Final simplification81.0%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\log z + \left(1 - z\right) \leq -520:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \mathbf{elif}\;\log z + \left(1 - z\right) \leq -370:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \mathbf{elif}\;\log z + \left(1 - z\right) \leq -100:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x}, -z, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \]
      15. Add Preprocessing

      Alternative 3: 85.1% 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.38 \cdot 10^{+93}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 32500000000000:\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\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.38e+93)
           t_0
           (if (<= y 32500000000000.0) (fma (- z) y (* 0.5 x)) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = fma((log(z) - z), y, y);
      	double tmp;
      	if (y <= -1.38e+93) {
      		tmp = t_0;
      	} else if (y <= 32500000000000.0) {
      		tmp = fma(-z, y, (0.5 * x));
      	} 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.38e+93)
      		tmp = t_0;
      	elseif (y <= 32500000000000.0)
      		tmp = fma(Float64(-z), y, Float64(0.5 * x));
      	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.38e+93], t$95$0, If[LessEqual[y, 32500000000000.0], N[((-z) * y + N[(0.5 * x), $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.38 \cdot 10^{+93}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;y \leq 32500000000000:\\
      \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -1.38000000000000005e93 or 3.25e13 < y

        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 y around inf

          \[\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.f6493.2

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

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

        if -1.38000000000000005e93 < y < 3.25e13

        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.f6486.7

            \[\leadsto x \cdot 0.5 + y \cdot \color{blue}{\left(-z\right)} \]
        5. Applied rewrites86.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. +-commutativeN/A

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

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

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

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

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

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

      Alternative 4: 98.8% accurate, 1.0× speedup?

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

        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. *-commutativeN/A

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

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

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

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

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

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

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

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

        if 0.10000000000000001 < 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 y around 0

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

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

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

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

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

      Alternative 5: 59.2% accurate, 8.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 3.2 \cdot 10^{+50}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot y\\ \end{array} \end{array} \]
      (FPCore (x y z) :precision binary64 (if (<= z 3.2e+50) (* 0.5 x) (* (- z) y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if (z <= 3.2e+50) {
      		tmp = 0.5 * x;
      	} else {
      		tmp = -z * y;
      	}
      	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) :: tmp
          if (z <= 3.2d+50) then
              tmp = 0.5d0 * x
          else
              tmp = -z * y
          end if
          code = tmp
      end function
      
      public static double code(double x, double y, double z) {
      	double tmp;
      	if (z <= 3.2e+50) {
      		tmp = 0.5 * x;
      	} else {
      		tmp = -z * y;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if z <= 3.2e+50:
      		tmp = 0.5 * x
      	else:
      		tmp = -z * y
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if (z <= 3.2e+50)
      		tmp = Float64(0.5 * x);
      	else
      		tmp = Float64(Float64(-z) * y);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if (z <= 3.2e+50)
      		tmp = 0.5 * x;
      	else
      		tmp = -z * y;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[LessEqual[z, 3.2e+50], N[(0.5 * x), $MachinePrecision], N[((-z) * y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq 3.2 \cdot 10^{+50}:\\
      \;\;\;\;0.5 \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(-z\right) \cdot y\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < 3.19999999999999983e50

        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 y around 0

          \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{x \cdot \frac{1}{2}} \]
          2. lower-*.f6451.4

            \[\leadsto \color{blue}{x \cdot 0.5} \]
        5. Applied rewrites51.4%

          \[\leadsto \color{blue}{x \cdot 0.5} \]

        if 3.19999999999999983e50 < z

        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 \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.f6480.1

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

          \[\leadsto \color{blue}{\left(-z\right) \cdot y} \]
      3. Recombined 2 regimes into one program.
      4. Final simplification64.4%

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

      Alternative 6: 74.3% 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.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.2

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

        \[\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. +-commutativeN/A

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

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

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

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

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

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

      Alternative 7: 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 y around 0

        \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{x \cdot \frac{1}{2}} \]
        2. lower-*.f6438.1

          \[\leadsto \color{blue}{x \cdot 0.5} \]
      5. Applied rewrites38.1%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
      6. Final simplification38.1%

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