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

Percentage Accurate: 99.9% → 99.9%
Time: 9.0s
Alternatives: 10
Speedup: 0.9×

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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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}

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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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, 0.9× speedup?

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

\\
\mathsf{fma}\left(\log z, y, \mathsf{fma}\left(1 - z, y, 0.5 \cdot x\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. Applied rewrites99.9%

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

Alternative 2: 99.9% accurate, 1.1× speedup?

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

\\
\mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(\log z - z, y, 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. 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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.00145:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 0.00145

    1. Initial program 99.8%

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

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

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

    if 0.00145 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Applied rewrites100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z - \log z, -y, \frac{1}{2} \cdot \color{blue}{x}\right) \]
      17. lift-*.f6498.4

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

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

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

Alternative 4: 98.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.00145:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(\log z, y, y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 0.00145

    1. Initial program 99.8%

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

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

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

    if 0.00145 < z

    1. Initial program 100.0%

      \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
    2. Applied rewrites100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z - \log z, -y, \frac{1}{2} \cdot \color{blue}{x}\right) \]
      17. lift-*.f6498.4

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

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

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

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

    Alternative 5: 85.7% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\log z - z, y, y\right)\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{+57}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.16 \cdot 10^{+148}:\\ \;\;\;\;\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 -2.1e+57) t_0 (if (<= y 1.16e+148) (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 <= -2.1e+57) {
    		tmp = t_0;
    	} else if (y <= 1.16e+148) {
    		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 <= -2.1e+57)
    		tmp = t_0;
    	elseif (y <= 1.16e+148)
    		tmp = fma(z, Float64(-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, -2.1e+57], t$95$0, If[LessEqual[y, 1.16e+148], 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 -2.1 \cdot 10^{+57}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;y \leq 1.16 \cdot 10^{+148}:\\
    \;\;\;\;\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 < -2.09999999999999991e57 or 1.1599999999999999e148 < y

      1. Initial program 99.8%

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

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

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

          \[\leadsto \left(1 + \left(\log z - z\right)\right) \cdot y \]
        3. +-commutativeN/A

          \[\leadsto \left(\left(\log z - z\right) + 1\right) \cdot y \]
        4. distribute-lft1-inN/A

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

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

          \[\leadsto \mathsf{fma}\left(\log z - z, y, y\right) \]
        7. lift-log.f6489.0

          \[\leadsto \mathsf{fma}\left(\log z - z, y, y\right) \]
      4. Applied rewrites89.0%

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

      if -2.09999999999999991e57 < y < 1.1599999999999999e148

      1. Initial program 99.9%

        \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
      2. Applied rewrites99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 6: 75.9% accurate, 1.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\log z, y, y\right)\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+196}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{+274}:\\ \;\;\;\;\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) y y)))
         (if (<= y -2.3e+196) t_0 (if (<= y 4.6e+274) (fma z (- y) (* 0.5 x)) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = fma(log(z), y, y);
      	double tmp;
      	if (y <= -2.3e+196) {
      		tmp = t_0;
      	} else if (y <= 4.6e+274) {
      		tmp = fma(z, -y, (0.5 * x));
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	t_0 = fma(log(z), y, y)
      	tmp = 0.0
      	if (y <= -2.3e+196)
      		tmp = t_0;
      	elseif (y <= 4.6e+274)
      		tmp = fma(z, Float64(-y), Float64(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]}, If[LessEqual[y, -2.3e+196], t$95$0, If[LessEqual[y, 4.6e+274], 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, y, y\right)\\
      \mathbf{if}\;y \leq -2.3 \cdot 10^{+196}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;y \leq 4.6 \cdot 10^{+274}:\\
      \;\;\;\;\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 < -2.2999999999999998e196 or 4.60000000000000006e274 < y

        1. Initial program 99.8%

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

          \[\leadsto \color{blue}{\frac{1}{2} \cdot x + y \cdot \left(1 + \log z\right)} \]
        3. Applied rewrites50.6%

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

          \[\leadsto y + \color{blue}{y \cdot \log z} \]
        5. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto y \cdot \log z + y \]
          2. *-commutativeN/A

            \[\leadsto \log z \cdot y + y \]
          3. lift-log.f64N/A

            \[\leadsto \log z \cdot y + y \]
          4. lift-fma.f6446.5

            \[\leadsto \mathsf{fma}\left(\log z, y, y\right) \]
        6. Applied rewrites46.5%

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

        if -2.2999999999999998e196 < y < 4.60000000000000006e274

        1. Initial program 99.9%

          \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
        2. Applied rewrites99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 7: 75.9% accurate, 2.1× 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(z, Float64(-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. Applied rewrites99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(z - \log z, -y, \frac{1}{2} \cdot \color{blue}{x}\right) \]
          17. lift-*.f6482.4

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

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

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

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

          Alternative 8: 75.0% accurate, 2.2× speedup?

          \[\begin{array}{l} \\ x \cdot 0.5 - z \cdot y \end{array} \]
          (FPCore (x y z) :precision binary64 (- (* x 0.5) (* z y)))
          double code(double x, double y, double z) {
          	return (x * 0.5) - (z * y);
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(x, y, z)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              code = (x * 0.5d0) - (z * y)
          end function
          
          public static double code(double x, double y, double z) {
          	return (x * 0.5) - (z * y);
          }
          
          def code(x, y, z):
          	return (x * 0.5) - (z * y)
          
          function code(x, y, z)
          	return Float64(Float64(x * 0.5) - Float64(z * y))
          end
          
          function tmp = code(x, y, z)
          	tmp = (x * 0.5) - (z * y);
          end
          
          code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          x \cdot 0.5 - z \cdot y
          \end{array}
          
          Derivation
          1. Initial program 99.9%

            \[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right) \]
          2. Applied rewrites99.8%

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

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

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

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

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

            \[\leadsto x \cdot \frac{1}{2} - \color{blue}{z} \cdot y \]
          7. Step-by-step derivation
            1. Applied rewrites75.9%

              \[\leadsto x \cdot 0.5 - \color{blue}{z} \cdot y \]
            2. Add Preprocessing

            Alternative 9: 61.3% accurate, 0.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(\left(1 - z\right) + \log z\right)\\ t_1 := \left(-y\right) \cdot z\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+59}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+41}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (let* ((t_0 (* y (+ (- 1.0 z) (log z)))) (t_1 (* (- y) z)))
               (if (<= t_0 -1e+59) t_1 (if (<= t_0 4e+41) (* 0.5 x) t_1))))
            double code(double x, double y, double z) {
            	double t_0 = y * ((1.0 - z) + log(z));
            	double t_1 = -y * z;
            	double tmp;
            	if (t_0 <= -1e+59) {
            		tmp = t_1;
            	} else if (t_0 <= 4e+41) {
            		tmp = 0.5 * x;
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(x, y, z)
            use fmin_fmax_functions
                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 = y * ((1.0d0 - z) + log(z))
                t_1 = -y * z
                if (t_0 <= (-1d+59)) then
                    tmp = t_1
                else if (t_0 <= 4d+41) 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 = y * ((1.0 - z) + Math.log(z));
            	double t_1 = -y * z;
            	double tmp;
            	if (t_0 <= -1e+59) {
            		tmp = t_1;
            	} else if (t_0 <= 4e+41) {
            		tmp = 0.5 * x;
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	t_0 = y * ((1.0 - z) + math.log(z))
            	t_1 = -y * z
            	tmp = 0
            	if t_0 <= -1e+59:
            		tmp = t_1
            	elif t_0 <= 4e+41:
            		tmp = 0.5 * x
            	else:
            		tmp = t_1
            	return tmp
            
            function code(x, y, z)
            	t_0 = Float64(y * Float64(Float64(1.0 - z) + log(z)))
            	t_1 = Float64(Float64(-y) * z)
            	tmp = 0.0
            	if (t_0 <= -1e+59)
            		tmp = t_1;
            	elseif (t_0 <= 4e+41)
            		tmp = Float64(0.5 * x);
            	else
            		tmp = t_1;
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z)
            	t_0 = y * ((1.0 - z) + log(z));
            	t_1 = -y * z;
            	tmp = 0.0;
            	if (t_0 <= -1e+59)
            		tmp = t_1;
            	elseif (t_0 <= 4e+41)
            		tmp = 0.5 * x;
            	else
            		tmp = t_1;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-y) * z), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+59], t$95$1, If[LessEqual[t$95$0, 4e+41], N[(0.5 * x), $MachinePrecision], t$95$1]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := y \cdot \left(\left(1 - z\right) + \log z\right)\\
            t_1 := \left(-y\right) \cdot z\\
            \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+59}:\\
            \;\;\;\;t\_1\\
            
            \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+41}:\\
            \;\;\;\;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))) < -9.99999999999999972e58 or 4.00000000000000002e41 < (*.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. Taylor expanded in z around inf

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

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

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

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

                  \[\leadsto \left(-y\right) \cdot z \]
              4. Applied rewrites55.1%

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

              if -9.99999999999999972e58 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < 4.00000000000000002e41

              1. Initial program 99.9%

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

                \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
              3. Step-by-step derivation
                1. lower-*.f6468.6

                  \[\leadsto 0.5 \cdot \color{blue}{x} \]
              4. Applied rewrites68.6%

                \[\leadsto \color{blue}{0.5 \cdot x} \]
            3. Recombined 2 regimes into one program.
            4. Add Preprocessing

            Alternative 10: 40.9% accurate, 5.2× 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;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(x, y, z)
            use fmin_fmax_functions
                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. Taylor expanded in x around inf

              \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
            3. Step-by-step derivation
              1. lower-*.f6440.9

                \[\leadsto 0.5 \cdot \color{blue}{x} \]
            4. Applied rewrites40.9%

              \[\leadsto \color{blue}{0.5 \cdot x} \]
            5. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2025130 
            (FPCore (x y z)
              :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
              :precision binary64
              (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))