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

Percentage Accurate: 100.0% → 100.0%
Time: 8.0s
Alternatives: 8
Speedup: 2.3×

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}

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 8 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.4× speedup?

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

\\
\left(0.5 \cdot x + y \cdot x\right) + z
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    Alternative 2: 57.9% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+14}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-157}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-16}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;y \leq 1.36 \cdot 10^{+147}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= y -6.5e+14)
       (* y x)
       (if (<= y 1.6e-157)
         z
         (if (<= y 2.4e-16) (* 0.5 x) (if (<= y 1.36e+147) z (* y x))))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (y <= -6.5e+14) {
    		tmp = y * x;
    	} else if (y <= 1.6e-157) {
    		tmp = z;
    	} else if (y <= 2.4e-16) {
    		tmp = 0.5 * x;
    	} else if (y <= 1.36e+147) {
    		tmp = z;
    	} else {
    		tmp = y * x;
    	}
    	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 <= (-6.5d+14)) then
            tmp = y * x
        else if (y <= 1.6d-157) then
            tmp = z
        else if (y <= 2.4d-16) then
            tmp = 0.5d0 * x
        else if (y <= 1.36d+147) then
            tmp = z
        else
            tmp = y * x
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double tmp;
    	if (y <= -6.5e+14) {
    		tmp = y * x;
    	} else if (y <= 1.6e-157) {
    		tmp = z;
    	} else if (y <= 2.4e-16) {
    		tmp = 0.5 * x;
    	} else if (y <= 1.36e+147) {
    		tmp = z;
    	} else {
    		tmp = y * x;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if y <= -6.5e+14:
    		tmp = y * x
    	elif y <= 1.6e-157:
    		tmp = z
    	elif y <= 2.4e-16:
    		tmp = 0.5 * x
    	elif y <= 1.36e+147:
    		tmp = z
    	else:
    		tmp = y * x
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if (y <= -6.5e+14)
    		tmp = Float64(y * x);
    	elseif (y <= 1.6e-157)
    		tmp = z;
    	elseif (y <= 2.4e-16)
    		tmp = Float64(0.5 * x);
    	elseif (y <= 1.36e+147)
    		tmp = z;
    	else
    		tmp = Float64(y * x);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	tmp = 0.0;
    	if (y <= -6.5e+14)
    		tmp = y * x;
    	elseif (y <= 1.6e-157)
    		tmp = z;
    	elseif (y <= 2.4e-16)
    		tmp = 0.5 * x;
    	elseif (y <= 1.36e+147)
    		tmp = z;
    	else
    		tmp = y * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[LessEqual[y, -6.5e+14], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.6e-157], z, If[LessEqual[y, 2.4e-16], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 1.36e+147], z, N[(y * x), $MachinePrecision]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y \leq -6.5 \cdot 10^{+14}:\\
    \;\;\;\;y \cdot x\\
    
    \mathbf{elif}\;y \leq 1.6 \cdot 10^{-157}:\\
    \;\;\;\;z\\
    
    \mathbf{elif}\;y \leq 2.4 \cdot 10^{-16}:\\
    \;\;\;\;0.5 \cdot x\\
    
    \mathbf{elif}\;y \leq 1.36 \cdot 10^{+147}:\\
    \;\;\;\;z\\
    
    \mathbf{else}:\\
    \;\;\;\;y \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if y < -6.5e14 or 1.35999999999999996e147 < y

      1. Initial program 100.0%

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

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

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

        if -6.5e14 < y < 1.6000000000000001e-157 or 2.40000000000000005e-16 < y < 1.35999999999999996e147

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{z} \]
        4. Step-by-step derivation
          1. Applied rewrites63.6%

            \[\leadsto \color{blue}{z} \]

          if 1.6000000000000001e-157 < y < 2.40000000000000005e-16

          1. Initial program 100.0%

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

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

              \[\leadsto \color{blue}{\left(y - -0.5\right) \cdot x} \]
            2. Taylor expanded in y around 0

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

                \[\leadsto 0.5 \cdot x \]
            4. Recombined 3 regimes into one program.
            5. Add Preprocessing

            Alternative 3: 98.8% accurate, 1.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (or (<= y -26000000.0) (not (<= y 0.5))) (fma y x z) (fma 0.5 x z)))
            double code(double x, double y, double z) {
            	double tmp;
            	if ((y <= -26000000.0) || !(y <= 0.5)) {
            		tmp = fma(y, x, z);
            	} else {
            		tmp = fma(0.5, x, z);
            	}
            	return tmp;
            }
            
            function code(x, y, z)
            	tmp = 0.0
            	if ((y <= -26000000.0) || !(y <= 0.5))
            		tmp = fma(y, x, z);
            	else
            		tmp = fma(0.5, x, z);
            	end
            	return tmp
            end
            
            code[x_, y_, z_] := If[Or[LessEqual[y, -26000000.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(y * x + z), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.5\right):\\
            \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -2.6e7 or 0.5 < y

              1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if -2.6e7 < y < 0.5

                  1. Initial program 100.0%

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

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

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \end{array} \]
                  7. Add Preprocessing

                  Alternative 4: 80.7% accurate, 1.2× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 2.6 \cdot 10^{+197}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \end{array} \end{array} \]
                  (FPCore (x y z)
                   :precision binary64
                   (if (or (<= y -6.5e+14) (not (<= y 2.6e+197))) (* y x) (fma 0.5 x z)))
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if ((y <= -6.5e+14) || !(y <= 2.6e+197)) {
                  		tmp = y * x;
                  	} else {
                  		tmp = fma(0.5, x, z);
                  	}
                  	return tmp;
                  }
                  
                  function code(x, y, z)
                  	tmp = 0.0
                  	if ((y <= -6.5e+14) || !(y <= 2.6e+197))
                  		tmp = Float64(y * x);
                  	else
                  		tmp = fma(0.5, x, z);
                  	end
                  	return tmp
                  end
                  
                  code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e+14], N[Not[LessEqual[y, 2.6e+197]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 2.6 \cdot 10^{+197}\right):\\
                  \;\;\;\;y \cdot x\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if y < -6.5e14 or 2.59999999999999987e197 < y

                    1. Initial program 100.0%

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

                      \[\leadsto \color{blue}{x \cdot y} \]
                    4. Step-by-step derivation
                      1. Applied rewrites76.8%

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

                      if -6.5e14 < y < 2.59999999999999987e197

                      1. Initial program 100.0%

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

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

                          \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, z\right)} \]
                      5. Recombined 2 regimes into one program.
                      6. Final simplification88.1%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 2.6 \cdot 10^{+197}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \end{array} \]
                      7. Add Preprocessing

                      Alternative 5: 57.7% accurate, 1.3× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 1.36 \cdot 10^{+147}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
                      (FPCore (x y z)
                       :precision binary64
                       (if (or (<= y -6.5e+14) (not (<= y 1.36e+147))) (* y x) z))
                      double code(double x, double y, double z) {
                      	double tmp;
                      	if ((y <= -6.5e+14) || !(y <= 1.36e+147)) {
                      		tmp = y * x;
                      	} else {
                      		tmp = 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 ((y <= (-6.5d+14)) .or. (.not. (y <= 1.36d+147))) then
                              tmp = y * x
                          else
                              tmp = z
                          end if
                          code = tmp
                      end function
                      
                      public static double code(double x, double y, double z) {
                      	double tmp;
                      	if ((y <= -6.5e+14) || !(y <= 1.36e+147)) {
                      		tmp = y * x;
                      	} else {
                      		tmp = z;
                      	}
                      	return tmp;
                      }
                      
                      def code(x, y, z):
                      	tmp = 0
                      	if (y <= -6.5e+14) or not (y <= 1.36e+147):
                      		tmp = y * x
                      	else:
                      		tmp = z
                      	return tmp
                      
                      function code(x, y, z)
                      	tmp = 0.0
                      	if ((y <= -6.5e+14) || !(y <= 1.36e+147))
                      		tmp = Float64(y * x);
                      	else
                      		tmp = z;
                      	end
                      	return tmp
                      end
                      
                      function tmp_2 = code(x, y, z)
                      	tmp = 0.0;
                      	if ((y <= -6.5e+14) || ~((y <= 1.36e+147)))
                      		tmp = y * x;
                      	else
                      		tmp = z;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e+14], N[Not[LessEqual[y, 1.36e+147]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 1.36 \cdot 10^{+147}\right):\\
                      \;\;\;\;y \cdot x\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;z\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if y < -6.5e14 or 1.35999999999999996e147 < y

                        1. Initial program 100.0%

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

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

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

                          if -6.5e14 < y < 1.35999999999999996e147

                          1. Initial program 100.0%

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

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

                              \[\leadsto \color{blue}{z} \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification64.3%

                            \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+14} \lor \neg \left(y \leq 1.36 \cdot 10^{+147}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
                          7. Add Preprocessing

                          Alternative 6: 100.0% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 7: 100.0% accurate, 2.3× 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. Add Preprocessing
                            3. Taylor expanded in x around 0

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

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

                            Alternative 8: 40.4% accurate, 23.0× 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. Add Preprocessing
                            3. Taylor expanded in x around 0

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

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

                              Reproduce

                              ?
                              herbie shell --seed 2025018 
                              (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))