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

Percentage Accurate: 100.0% → 100.0%
Time: 3.5s
Alternatives: 7
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 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: 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, 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 2: 58.2% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+179} \lor \neg \left(t\_0 \leq 5 \cdot 10^{-35}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (let* ((t_0 (+ (/ x 2.0) (* y x))))
       (if (or (<= t_0 -2e+179) (not (<= t_0 5e-35))) (* y x) z)))
    double code(double x, double y, double z) {
    	double t_0 = (x / 2.0) + (y * x);
    	double tmp;
    	if ((t_0 <= -2e+179) || !(t_0 <= 5e-35)) {
    		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) :: t_0
        real(8) :: tmp
        t_0 = (x / 2.0d0) + (y * x)
        if ((t_0 <= (-2d+179)) .or. (.not. (t_0 <= 5d-35))) then
            tmp = y * x
        else
            tmp = z
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double t_0 = (x / 2.0) + (y * x);
    	double tmp;
    	if ((t_0 <= -2e+179) || !(t_0 <= 5e-35)) {
    		tmp = y * x;
    	} else {
    		tmp = z;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	t_0 = (x / 2.0) + (y * x)
    	tmp = 0
    	if (t_0 <= -2e+179) or not (t_0 <= 5e-35):
    		tmp = y * x
    	else:
    		tmp = z
    	return tmp
    
    function code(x, y, z)
    	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
    	tmp = 0.0
    	if ((t_0 <= -2e+179) || !(t_0 <= 5e-35))
    		tmp = Float64(y * x);
    	else
    		tmp = z;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	t_0 = (x / 2.0) + (y * x);
    	tmp = 0.0;
    	if ((t_0 <= -2e+179) || ~((t_0 <= 5e-35)))
    		tmp = y * x;
    	else
    		tmp = z;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+179], N[Not[LessEqual[t$95$0, 5e-35]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{x}{2} + y \cdot x\\
    \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+179} \lor \neg \left(t\_0 \leq 5 \cdot 10^{-35}\right):\\
    \;\;\;\;y \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;z\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.99999999999999996e179 or 4.99999999999999964e-35 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x))

      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 rewrites61.6%

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

        if -1.99999999999999996e179 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 4.99999999999999964e-35

        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 rewrites61.7%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{2} + y \cdot x \leq -2 \cdot 10^{+179} \lor \neg \left(\frac{x}{2} + y \cdot x \leq 5 \cdot 10^{-35}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
        7. Add Preprocessing

        Alternative 3: 59.6% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-13}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-26}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+65}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= y -2e-13)
           (* y x)
           (if (<= y 2.3e-26) (* 0.5 x) (if (<= y 7.2e+65) z (* y x)))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -2e-13) {
        		tmp = y * x;
        	} else if (y <= 2.3e-26) {
        		tmp = 0.5 * x;
        	} else if (y <= 7.2e+65) {
        		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 <= (-2d-13)) then
                tmp = y * x
            else if (y <= 2.3d-26) then
                tmp = 0.5d0 * x
            else if (y <= 7.2d+65) 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 <= -2e-13) {
        		tmp = y * x;
        	} else if (y <= 2.3e-26) {
        		tmp = 0.5 * x;
        	} else if (y <= 7.2e+65) {
        		tmp = z;
        	} else {
        		tmp = y * x;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if y <= -2e-13:
        		tmp = y * x
        	elif y <= 2.3e-26:
        		tmp = 0.5 * x
        	elif y <= 7.2e+65:
        		tmp = z
        	else:
        		tmp = y * x
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (y <= -2e-13)
        		tmp = Float64(y * x);
        	elseif (y <= 2.3e-26)
        		tmp = Float64(0.5 * x);
        	elseif (y <= 7.2e+65)
        		tmp = z;
        	else
        		tmp = Float64(y * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (y <= -2e-13)
        		tmp = y * x;
        	elseif (y <= 2.3e-26)
        		tmp = 0.5 * x;
        	elseif (y <= 7.2e+65)
        		tmp = z;
        	else
        		tmp = y * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[y, -2e-13], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.3e-26], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 7.2e+65], z, N[(y * x), $MachinePrecision]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -2 \cdot 10^{-13}:\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{elif}\;y \leq 2.3 \cdot 10^{-26}:\\
        \;\;\;\;0.5 \cdot x\\
        
        \mathbf{elif}\;y \leq 7.2 \cdot 10^{+65}:\\
        \;\;\;\;z\\
        
        \mathbf{else}:\\
        \;\;\;\;y \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if y < -2.0000000000000001e-13 or 7.19999999999999957e65 < 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.1%

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

            if -2.0000000000000001e-13 < y < 2.30000000000000009e-26

            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 rewrites56.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 rewrites56.3%

                  \[\leadsto 0.5 \cdot x \]

                if 2.30000000000000009e-26 < y < 7.19999999999999957e65

                1. Initial program 99.9%

                  \[\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 rewrites60.3%

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

                Alternative 4: 98.8% accurate, 1.2× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 3.6 \cdot 10^{-13}\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 -0.5) (not (<= y 3.6e-13))) (fma y x z) (fma 0.5 x z)))
                double code(double x, double y, double z) {
                	double tmp;
                	if ((y <= -0.5) || !(y <= 3.6e-13)) {
                		tmp = fma(y, x, z);
                	} else {
                		tmp = fma(0.5, x, z);
                	}
                	return tmp;
                }
                
                function code(x, y, z)
                	tmp = 0.0
                	if ((y <= -0.5) || !(y <= 3.6e-13))
                		tmp = fma(y, x, z);
                	else
                		tmp = fma(0.5, x, z);
                	end
                	return tmp
                end
                
                code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 3.6e-13]], $MachinePrecision]], N[(y * x + z), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 3.6 \cdot 10^{-13}\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 < -0.5 or 3.5999999999999998e-13 < 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 \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. Taylor expanded in y around inf

                    \[\leadsto \mathsf{fma}\left(y, x, z\right) \]
                  6. Step-by-step derivation
                    1. Applied rewrites97.8%

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

                    if -0.5 < y < 3.5999999999999998e-13

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

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

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

                    Alternative 5: 84.7% accurate, 1.2× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{+20} \lor \neg \left(y \leq 7.3 \cdot 10^{+65}\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 -9e+20) (not (<= y 7.3e+65))) (* y x) (fma 0.5 x z)))
                    double code(double x, double y, double z) {
                    	double tmp;
                    	if ((y <= -9e+20) || !(y <= 7.3e+65)) {
                    		tmp = y * x;
                    	} else {
                    		tmp = fma(0.5, x, z);
                    	}
                    	return tmp;
                    }
                    
                    function code(x, y, z)
                    	tmp = 0.0
                    	if ((y <= -9e+20) || !(y <= 7.3e+65))
                    		tmp = Float64(y * x);
                    	else
                    		tmp = fma(0.5, x, z);
                    	end
                    	return tmp
                    end
                    
                    code[x_, y_, z_] := If[Or[LessEqual[y, -9e+20], N[Not[LessEqual[y, 7.3e+65]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;y \leq -9 \cdot 10^{+20} \lor \neg \left(y \leq 7.3 \cdot 10^{+65}\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 < -9e20 or 7.29999999999999973e65 < 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 rewrites79.4%

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

                        if -9e20 < y < 7.29999999999999973e65

                        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.6%

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

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

                        Alternative 6: 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 7: 40.2% 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 rewrites36.5%

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

                          Reproduce

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