Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1

Percentage Accurate: 100.0% → 100.0%
Time: 1.3s
Alternatives: 5
Speedup: 1.5×

Specification

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

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\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 5 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: 100.0% accurate, 1.0× speedup?

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

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}

Alternative 1: 100.0% accurate, 1.5× speedup?

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

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

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + \frac{1}{2}}, z\right) \]
    11. metadata-eval100.0

      \[\leadsto \mathsf{fma}\left(x, y + \color{blue}{0.5}, z\right) \]
  3. Applied rewrites100.0%

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

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

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

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

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

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

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

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

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

Alternative 2: 84.9% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8:\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\

\mathbf{elif}\;y \leq 7 \cdot 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.79999999999999982

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{z} \]
    3. Step-by-step derivation
      1. Applied rewrites39.9%

        \[\leadsto \color{blue}{z} \]
      2. Taylor expanded in x around inf

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

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

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

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

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

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

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

          \[\leadsto \left(y + \frac{1}{2}\right) \cdot x \]
        5. add-flipN/A

          \[\leadsto \left(y - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right) \cdot x \]
        6. metadata-evalN/A

          \[\leadsto \left(y - \frac{-1}{2}\right) \cdot x \]
        7. lift--.f64N/A

          \[\leadsto \left(y - \frac{-1}{2}\right) \cdot x \]
        8. lower-*.f6461.4

          \[\leadsto \left(y - -0.5\right) \cdot \color{blue}{x} \]
      6. Applied rewrites61.4%

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

      if -5.79999999999999982 < y < 6.99999999999999955e68

      1. Initial program 100.0%

        \[\left(\frac{x}{2} + y \cdot x\right) + z \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + \frac{1}{2}}, z\right) \]
        11. metadata-eval100.0

          \[\leadsto \mathsf{fma}\left(x, y + \color{blue}{0.5}, z\right) \]
      3. Applied rewrites100.0%

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

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

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

        if 6.99999999999999955e68 < y

        1. Initial program 100.0%

          \[\left(\frac{x}{2} + y \cdot x\right) + z \]
        2. Taylor expanded in x around 0

          \[\leadsto \color{blue}{z} \]
        3. Step-by-step derivation
          1. Applied rewrites39.9%

            \[\leadsto \color{blue}{z} \]
          2. Taylor expanded in y around inf

            \[\leadsto \color{blue}{x \cdot y} \]
          3. Step-by-step derivation
            1. lower-*.f6437.3

              \[\leadsto x \cdot \color{blue}{y} \]
          4. Applied rewrites37.3%

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

        Alternative 3: 84.8% accurate, 0.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+28}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+68}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= y -1.45e+28) (* x y) (if (<= y 7e+68) (fma x 0.5 z) (* x y))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -1.45e+28) {
        		tmp = x * y;
        	} else if (y <= 7e+68) {
        		tmp = fma(x, 0.5, z);
        	} else {
        		tmp = x * y;
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if (y <= -1.45e+28)
        		tmp = Float64(x * y);
        	elseif (y <= 7e+68)
        		tmp = fma(x, 0.5, z);
        	else
        		tmp = Float64(x * y);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[LessEqual[y, -1.45e+28], N[(x * y), $MachinePrecision], If[LessEqual[y, 7e+68], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -1.45 \cdot 10^{+28}:\\
        \;\;\;\;x \cdot y\\
        
        \mathbf{elif}\;y \leq 7 \cdot 10^{+68}:\\
        \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;x \cdot y\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -1.4500000000000001e28 or 6.99999999999999955e68 < y

          1. Initial program 100.0%

            \[\left(\frac{x}{2} + y \cdot x\right) + z \]
          2. Taylor expanded in x around 0

            \[\leadsto \color{blue}{z} \]
          3. Step-by-step derivation
            1. Applied rewrites39.9%

              \[\leadsto \color{blue}{z} \]
            2. Taylor expanded in y around inf

              \[\leadsto \color{blue}{x \cdot y} \]
            3. Step-by-step derivation
              1. lower-*.f6437.3

                \[\leadsto x \cdot \color{blue}{y} \]
            4. Applied rewrites37.3%

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

            if -1.4500000000000001e28 < y < 6.99999999999999955e68

            1. Initial program 100.0%

              \[\left(\frac{x}{2} + y \cdot x\right) + z \]
            2. Step-by-step derivation
              1. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + \frac{1}{2}}, z\right) \]
              11. metadata-eval100.0

                \[\leadsto \mathsf{fma}\left(x, y + \color{blue}{0.5}, z\right) \]
            3. Applied rewrites100.0%

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

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

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

            Alternative 4: 60.7% accurate, 1.1× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{+28}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+68}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (<= y -2.1e+28) (* x y) (if (<= y 7e+68) z (* x y))))
            double code(double x, double y, double z) {
            	double tmp;
            	if (y <= -2.1e+28) {
            		tmp = x * y;
            	} else if (y <= 7e+68) {
            		tmp = z;
            	} else {
            		tmp = x * y;
            	}
            	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 (y <= (-2.1d+28)) then
                    tmp = x * y
                else if (y <= 7d+68) then
                    tmp = z
                else
                    tmp = x * y
                end if
                code = tmp
            end function
            
            public static double code(double x, double y, double z) {
            	double tmp;
            	if (y <= -2.1e+28) {
            		tmp = x * y;
            	} else if (y <= 7e+68) {
            		tmp = z;
            	} else {
            		tmp = x * y;
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	tmp = 0
            	if y <= -2.1e+28:
            		tmp = x * y
            	elif y <= 7e+68:
            		tmp = z
            	else:
            		tmp = x * y
            	return tmp
            
            function code(x, y, z)
            	tmp = 0.0
            	if (y <= -2.1e+28)
            		tmp = Float64(x * y);
            	elseif (y <= 7e+68)
            		tmp = z;
            	else
            		tmp = Float64(x * y);
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z)
            	tmp = 0.0;
            	if (y <= -2.1e+28)
            		tmp = x * y;
            	elseif (y <= 7e+68)
            		tmp = z;
            	else
            		tmp = x * y;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := If[LessEqual[y, -2.1e+28], N[(x * y), $MachinePrecision], If[LessEqual[y, 7e+68], z, N[(x * y), $MachinePrecision]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -2.1 \cdot 10^{+28}:\\
            \;\;\;\;x \cdot y\\
            
            \mathbf{elif}\;y \leq 7 \cdot 10^{+68}:\\
            \;\;\;\;z\\
            
            \mathbf{else}:\\
            \;\;\;\;x \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -2.09999999999999989e28 or 6.99999999999999955e68 < y

              1. Initial program 100.0%

                \[\left(\frac{x}{2} + y \cdot x\right) + z \]
              2. Taylor expanded in x around 0

                \[\leadsto \color{blue}{z} \]
              3. Step-by-step derivation
                1. Applied rewrites39.9%

                  \[\leadsto \color{blue}{z} \]
                2. Taylor expanded in y around inf

                  \[\leadsto \color{blue}{x \cdot y} \]
                3. Step-by-step derivation
                  1. lower-*.f6437.3

                    \[\leadsto x \cdot \color{blue}{y} \]
                4. Applied rewrites37.3%

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

                if -2.09999999999999989e28 < y < 6.99999999999999955e68

                1. Initial program 100.0%

                  \[\left(\frac{x}{2} + y \cdot x\right) + z \]
                2. Taylor expanded in x around 0

                  \[\leadsto \color{blue}{z} \]
                3. Step-by-step derivation
                  1. Applied rewrites39.9%

                    \[\leadsto \color{blue}{z} \]
                4. Recombined 2 regimes into one program.
                5. Add Preprocessing

                Alternative 5: 39.9% accurate, 12.8× speedup?

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

                  \[\left(\frac{x}{2} + y \cdot x\right) + z \]
                2. Taylor expanded in x around 0

                  \[\leadsto \color{blue}{z} \]
                3. Step-by-step derivation
                  1. Applied rewrites39.9%

                    \[\leadsto \color{blue}{z} \]
                  2. Add Preprocessing

                  Reproduce

                  ?
                  herbie shell --seed 2025150 
                  (FPCore (x y z)
                    :name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
                    :precision binary64
                    (+ (+ (/ x 2.0) (* y x)) z))