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

Percentage Accurate: 99.9% → 99.9%
Time: 3.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)));
}
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}

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)));
}
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, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+55} \lor \neg \left(y \leq 1.05 \cdot 10^{+80}\right):\\
\;\;\;\;\left(\left(\log z - -1\right) - z\right) \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.80000000000000042e55 or 1.05000000000000001e80 < 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 x around 0

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

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

      if -8.80000000000000042e55 < y < 1.05000000000000001e80

      1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 75.4% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 7.5 \cdot 10^{-280} \lor \neg \left(z \leq 1.95 \cdot 10^{-112}\right):\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z 7.5e-280) (not (<= z 1.95e-112)))
         (fma (- z) y (* 0.5 x))
         (fma (log z) y y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= 7.5e-280) || !(z <= 1.95e-112)) {
      		tmp = fma(-z, y, (0.5 * x));
      	} else {
      		tmp = fma(log(z), y, y);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= 7.5e-280) || !(z <= 1.95e-112))
      		tmp = fma(Float64(-z), y, Float64(0.5 * x));
      	else
      		tmp = fma(log(z), y, y);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[z, 7.5e-280], N[Not[LessEqual[z, 1.95e-112]], $MachinePrecision]], N[((-z) * y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[Log[z], $MachinePrecision] * y + y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq 7.5 \cdot 10^{-280} \lor \neg \left(z \leq 1.95 \cdot 10^{-112}\right):\\
      \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < 7.4999999999999999e-280 or 1.9500000000000001e-112 < 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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 7.4999999999999999e-280 < z < 1.9500000000000001e-112

          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. Applied rewrites99.8%

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

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

                \[\leadsto \mathsf{fma}\left(\log z, \color{blue}{y}, y\right) \]
            4. Recombined 2 regimes into one program.
            5. Final simplification83.6%

              \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 7.5 \cdot 10^{-280} \lor \neg \left(z \leq 1.95 \cdot 10^{-112}\right):\\ \;\;\;\;\mathsf{fma}\left(-z, y, 0.5 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log z, y, y\right)\\ \end{array} \]
            6. Add Preprocessing

            Alternative 4: 98.9% accurate, 1.0× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 0.28:\\ \;\;\;\;\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.28) (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.28) {
            		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.28)
            		tmp = fma(0.5, x, fma(log(z), y, y));
            	else
            		tmp = fma(Float64(-z), y, Float64(0.5 * x));
            	end
            	return tmp
            end
            
            code[x_, y_, z_] := If[LessEqual[z, 0.28], 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.28:\\
            \;\;\;\;\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.28000000000000003

              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. Applied rewrites99.2%

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

                if 0.28000000000000003 < 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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 5: 60.2% accurate, 8.6× speedup?

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

                  1. Initial program 99.8%

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

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

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

                    if 9.500000000000001e21 < 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. Applied rewrites79.1%

                        \[\leadsto \color{blue}{\left(-y\right) \cdot z} \]
                    5. Recombined 2 regimes into one program.
                    6. Add Preprocessing

                    Alternative 6: 74.6% 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. 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 x \cdot \frac{1}{2} + \color{blue}{y \cdot \left(\left(1 - z\right) + \log z\right)} \]
                      3. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      Alternative 7: 40.3% 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;
                      }
                      
                      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. Add Preprocessing
                      3. Taylor expanded in x around inf

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

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

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

                        \[\begin{array}{l} \\ \left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right) \end{array} \]
                        (FPCore (x y z) :precision binary64 (- (+ y (* 0.5 x)) (* y (- z (log z)))))
                        double code(double x, double y, double z) {
                        	return (y + (0.5 * x)) - (y * (z - log(z)));
                        }
                        
                        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 = (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 2025026 
                        (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)))))