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

Percentage Accurate: 100.0% → 100.0%
Time: 1.9s
Alternatives: 6
Speedup: 1.5×

Specification

?
\[\left(\frac{x}{2} + y \cdot x\right) + z \]
(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]
\left(\frac{x}{2} + y \cdot x\right) + z

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 6 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?

\[\left(\frac{x}{2} + y \cdot x\right) + z \]
(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]
\left(\frac{x}{2} + y \cdot x\right) + z

Alternative 1: 100.0% accurate, 1.5× speedup?

\[\mathsf{fma}\left(y - -0.5, x, z\right) \]
(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]
\mathsf{fma}\left(y - -0.5, x, z\right)
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. add-flipN/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(y + \frac{1}{2}\right) \cdot x} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) \]
    12. remove-double-negN/A

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

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

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

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

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

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

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

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

Alternative 2: 84.7% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ t_1 := \left(y - -0.5\right) \cdot x\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ x 2.0) (* y x))) (t_1 (* (- y -0.5) x)))
   (if (<= t_0 -5e+154) t_1 (if (<= t_0 2e+128) (fma 0.5 x z) t_1))))
double code(double x, double y, double z) {
	double t_0 = (x / 2.0) + (y * x);
	double t_1 = (y - -0.5) * x;
	double tmp;
	if (t_0 <= -5e+154) {
		tmp = t_1;
	} else if (t_0 <= 2e+128) {
		tmp = fma(0.5, x, z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
	t_1 = Float64(Float64(y - -0.5) * x)
	tmp = 0.0
	if (t_0 <= -5e+154)
		tmp = t_1;
	elseif (t_0 <= 2e+128)
		tmp = fma(0.5, x, z);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+154], t$95$1, If[LessEqual[t$95$0, 2e+128], N[(0.5 * x + z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
t_1 := \left(y - -0.5\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -5.00000000000000004e154 or 2.0000000000000002e128 < (+.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. Taylor expanded in x around 0

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

        \[\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-+.f6460.6%

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

        \[\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. lower-*.f6460.6%

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

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

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

          \[\leadsto \left(y + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right) \cdot x \]
        7. sub-flipN/A

          \[\leadsto \left(y - \frac{-1}{2}\right) \cdot x \]
        8. lower--.f6460.6%

          \[\leadsto \left(y - -0.5\right) \cdot x \]
      6. Applied rewrites60.6%

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

      if -5.00000000000000004e154 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 2.0000000000000002e128

      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. add-flipN/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(y + \frac{1}{2}\right) \cdot x} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) \]
        12. remove-double-negN/A

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 84.6% accurate, 0.9× speedup?

      \[\begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+20}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= y -1.6e+20) (* x y) (if (<= y 4.1e+36) (fma 0.5 x z) (* x y))))
      double code(double x, double y, double z) {
      	double tmp;
      	if (y <= -1.6e+20) {
      		tmp = x * y;
      	} else if (y <= 4.1e+36) {
      		tmp = fma(0.5, x, z);
      	} else {
      		tmp = x * y;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if (y <= -1.6e+20)
      		tmp = Float64(x * y);
      	elseif (y <= 4.1e+36)
      		tmp = fma(0.5, x, z);
      	else
      		tmp = Float64(x * y);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[LessEqual[y, -1.6e+20], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.1e+36], N[(0.5 * x + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
      
      \begin{array}{l}
      \mathbf{if}\;y \leq -1.6 \cdot 10^{+20}:\\
      \;\;\;\;x \cdot y\\
      
      \mathbf{elif}\;y \leq 4.1 \cdot 10^{+36}:\\
      \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;x \cdot y\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -1.6e20 or 4.10000000000000013e36 < 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 rewrites40.6%

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

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

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

          if -1.6e20 < y < 4.10000000000000013e36

          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. add-flipN/A

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

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

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

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

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

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

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

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

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

              \[\leadsto \color{blue}{\left(y + \frac{1}{2}\right) \cdot x} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right) \]
            12. remove-double-negN/A

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

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

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

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

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

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

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

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

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

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

          Alternative 4: 61.4% accurate, 0.3× speedup?

          \[\begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+300}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+125}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (let* ((t_0 (+ (/ x 2.0) (* y x))))
             (if (<= t_0 -4e+300)
               (* x y)
               (if (<= t_0 -1e+125) (* x 0.5) (if (<= t_0 2e+128) z (* x y))))))
          double code(double x, double y, double z) {
          	double t_0 = (x / 2.0) + (y * x);
          	double tmp;
          	if (t_0 <= -4e+300) {
          		tmp = x * y;
          	} else if (t_0 <= -1e+125) {
          		tmp = x * 0.5;
          	} else if (t_0 <= 2e+128) {
          		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) :: t_0
              real(8) :: tmp
              t_0 = (x / 2.0d0) + (y * x)
              if (t_0 <= (-4d+300)) then
                  tmp = x * y
              else if (t_0 <= (-1d+125)) then
                  tmp = x * 0.5d0
              else if (t_0 <= 2d+128) then
                  tmp = z
              else
                  tmp = x * y
              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 <= -4e+300) {
          		tmp = x * y;
          	} else if (t_0 <= -1e+125) {
          		tmp = x * 0.5;
          	} else if (t_0 <= 2e+128) {
          		tmp = z;
          	} else {
          		tmp = x * y;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	t_0 = (x / 2.0) + (y * x)
          	tmp = 0
          	if t_0 <= -4e+300:
          		tmp = x * y
          	elif t_0 <= -1e+125:
          		tmp = x * 0.5
          	elif t_0 <= 2e+128:
          		tmp = z
          	else:
          		tmp = x * y
          	return tmp
          
          function code(x, y, z)
          	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
          	tmp = 0.0
          	if (t_0 <= -4e+300)
          		tmp = Float64(x * y);
          	elseif (t_0 <= -1e+125)
          		tmp = Float64(x * 0.5);
          	elseif (t_0 <= 2e+128)
          		tmp = z;
          	else
          		tmp = Float64(x * y);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	t_0 = (x / 2.0) + (y * x);
          	tmp = 0.0;
          	if (t_0 <= -4e+300)
          		tmp = x * y;
          	elseif (t_0 <= -1e+125)
          		tmp = x * 0.5;
          	elseif (t_0 <= 2e+128)
          		tmp = z;
          	else
          		tmp = x * y;
          	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[LessEqual[t$95$0, -4e+300], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -1e+125], N[(x * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 2e+128], z, N[(x * y), $MachinePrecision]]]]]
          
          \begin{array}{l}
          t_0 := \frac{x}{2} + y \cdot x\\
          \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+300}:\\
          \;\;\;\;x \cdot y\\
          
          \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{+125}:\\
          \;\;\;\;x \cdot 0.5\\
          
          \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\
          \;\;\;\;z\\
          
          \mathbf{else}:\\
          \;\;\;\;x \cdot y\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -4.0000000000000002e300 or 2.0000000000000002e128 < (+.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. Taylor expanded in x around 0

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

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

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

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

              if -4.0000000000000002e300 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -9.9999999999999992e124

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

                  \[\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-+.f6460.6%

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

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

                  \[\leadsto x \cdot \frac{1}{2} \]
                6. Step-by-step derivation
                  1. Applied rewrites25.6%

                    \[\leadsto x \cdot 0.5 \]

                  if -9.9999999999999992e124 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 2.0000000000000002e128

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

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

                  Alternative 5: 61.0% accurate, 0.4× speedup?

                  \[\begin{array}{l} t_0 := \frac{x}{2} + y \cdot x\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
                  (FPCore (x y z)
                   :precision binary64
                   (let* ((t_0 (+ (/ x 2.0) (* y x))))
                     (if (<= t_0 -5e+154) (* x y) (if (<= t_0 2e+128) z (* x y)))))
                  double code(double x, double y, double z) {
                  	double t_0 = (x / 2.0) + (y * x);
                  	double tmp;
                  	if (t_0 <= -5e+154) {
                  		tmp = x * y;
                  	} else if (t_0 <= 2e+128) {
                  		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) :: t_0
                      real(8) :: tmp
                      t_0 = (x / 2.0d0) + (y * x)
                      if (t_0 <= (-5d+154)) then
                          tmp = x * y
                      else if (t_0 <= 2d+128) then
                          tmp = z
                      else
                          tmp = x * y
                      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 <= -5e+154) {
                  		tmp = x * y;
                  	} else if (t_0 <= 2e+128) {
                  		tmp = z;
                  	} else {
                  		tmp = x * y;
                  	}
                  	return tmp;
                  }
                  
                  def code(x, y, z):
                  	t_0 = (x / 2.0) + (y * x)
                  	tmp = 0
                  	if t_0 <= -5e+154:
                  		tmp = x * y
                  	elif t_0 <= 2e+128:
                  		tmp = z
                  	else:
                  		tmp = x * y
                  	return tmp
                  
                  function code(x, y, z)
                  	t_0 = Float64(Float64(x / 2.0) + Float64(y * x))
                  	tmp = 0.0
                  	if (t_0 <= -5e+154)
                  		tmp = Float64(x * y);
                  	elseif (t_0 <= 2e+128)
                  		tmp = z;
                  	else
                  		tmp = Float64(x * y);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(x, y, z)
                  	t_0 = (x / 2.0) + (y * x);
                  	tmp = 0.0;
                  	if (t_0 <= -5e+154)
                  		tmp = x * y;
                  	elseif (t_0 <= 2e+128)
                  		tmp = z;
                  	else
                  		tmp = x * y;
                  	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[LessEqual[t$95$0, -5e+154], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, 2e+128], z, N[(x * y), $MachinePrecision]]]]
                  
                  \begin{array}{l}
                  t_0 := \frac{x}{2} + y \cdot x\\
                  \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+154}:\\
                  \;\;\;\;x \cdot y\\
                  
                  \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+128}:\\
                  \;\;\;\;z\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;x \cdot y\\
                  
                  
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -5.00000000000000004e154 or 2.0000000000000002e128 < (+.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. Taylor expanded in x around 0

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

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

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

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

                      if -5.00000000000000004e154 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 2.0000000000000002e128

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

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

                      Alternative 6: 40.6% accurate, 12.8× speedup?

                      \[z \]
                      (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
                      
                      z
                      
                      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 rewrites40.6%

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

                        Reproduce

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