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

Percentage Accurate: 100.0% → 100.0%
Time: 5.2s
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;
}
real(8) function code(x, y, z)
    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;
}
real(8) function code(x, y, z)
    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.8× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \frac{x}{2} + z\right)} \]
    4. div-invN/A

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

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

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

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

Alternative 2: 57.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot x + \frac{x}{2}\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+280}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;t\_0 \leq -5 \cdot 10^{+211}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-52}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;t\_0 \leq 10:\\ \;\;\;\;z\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+306}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (* y x) (/ x 2.0))))
   (if (<= t_0 -1e+280)
     (* y x)
     (if (<= t_0 -5e+211)
       (* x 0.5)
       (if (<= t_0 -2e-52)
         (* y x)
         (if (<= t_0 10.0) z (if (<= t_0 4e+306) (* x 0.5) (* y x))))))))
double code(double x, double y, double z) {
	double t_0 = (y * x) + (x / 2.0);
	double tmp;
	if (t_0 <= -1e+280) {
		tmp = y * x;
	} else if (t_0 <= -5e+211) {
		tmp = x * 0.5;
	} else if (t_0 <= -2e-52) {
		tmp = y * x;
	} else if (t_0 <= 10.0) {
		tmp = z;
	} else if (t_0 <= 4e+306) {
		tmp = x * 0.5;
	} else {
		tmp = y * x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y * x) + (x / 2.0d0)
    if (t_0 <= (-1d+280)) then
        tmp = y * x
    else if (t_0 <= (-5d+211)) then
        tmp = x * 0.5d0
    else if (t_0 <= (-2d-52)) then
        tmp = y * x
    else if (t_0 <= 10.0d0) then
        tmp = z
    else if (t_0 <= 4d+306) then
        tmp = x * 0.5d0
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (y * x) + (x / 2.0);
	double tmp;
	if (t_0 <= -1e+280) {
		tmp = y * x;
	} else if (t_0 <= -5e+211) {
		tmp = x * 0.5;
	} else if (t_0 <= -2e-52) {
		tmp = y * x;
	} else if (t_0 <= 10.0) {
		tmp = z;
	} else if (t_0 <= 4e+306) {
		tmp = x * 0.5;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (y * x) + (x / 2.0)
	tmp = 0
	if t_0 <= -1e+280:
		tmp = y * x
	elif t_0 <= -5e+211:
		tmp = x * 0.5
	elif t_0 <= -2e-52:
		tmp = y * x
	elif t_0 <= 10.0:
		tmp = z
	elif t_0 <= 4e+306:
		tmp = x * 0.5
	else:
		tmp = y * x
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(y * x) + Float64(x / 2.0))
	tmp = 0.0
	if (t_0 <= -1e+280)
		tmp = Float64(y * x);
	elseif (t_0 <= -5e+211)
		tmp = Float64(x * 0.5);
	elseif (t_0 <= -2e-52)
		tmp = Float64(y * x);
	elseif (t_0 <= 10.0)
		tmp = z;
	elseif (t_0 <= 4e+306)
		tmp = Float64(x * 0.5);
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (y * x) + (x / 2.0);
	tmp = 0.0;
	if (t_0 <= -1e+280)
		tmp = y * x;
	elseif (t_0 <= -5e+211)
		tmp = x * 0.5;
	elseif (t_0 <= -2e-52)
		tmp = y * x;
	elseif (t_0 <= 10.0)
		tmp = z;
	elseif (t_0 <= 4e+306)
		tmp = x * 0.5;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+280], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, -5e+211], N[(x * 0.5), $MachinePrecision], If[LessEqual[t$95$0, -2e-52], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 10.0], z, If[LessEqual[t$95$0, 4e+306], N[(x * 0.5), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot x + \frac{x}{2}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+280}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;t\_0 \leq -5 \cdot 10^{+211}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-52}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;t\_0 \leq 10:\\
\;\;\;\;z\\

\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+306}:\\
\;\;\;\;x \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1e280 or -4.9999999999999995e211 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -2e-52 or 4.00000000000000007e306 < (+.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. *-lowering-*.f6471.0

        \[\leadsto \color{blue}{x \cdot y} \]
    5. Simplified71.0%

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

    if -1e280 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -4.9999999999999995e211 or 10 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 4.00000000000000007e306

    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. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + y\right)} \]
      2. +-lowering-+.f6476.8

        \[\leadsto x \cdot \color{blue}{\left(0.5 + y\right)} \]
    5. Simplified76.8%

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

      \[\leadsto x \cdot \color{blue}{\frac{1}{2}} \]
    7. Step-by-step derivation
      1. Simplified56.6%

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

      if -2e-52 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 10

      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. Simplified78.0%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot x + \frac{x}{2} \leq -1 \cdot 10^{+280}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \cdot x + \frac{x}{2} \leq -5 \cdot 10^{+211}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \cdot x + \frac{x}{2} \leq -2 \cdot 10^{-52}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \cdot x + \frac{x}{2} \leq 10:\\ \;\;\;\;z\\ \mathbf{elif}\;y \cdot x + \frac{x}{2} \leq 4 \cdot 10^{+306}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
      7. Add Preprocessing

      Alternative 3: 98.8% accurate, 1.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -75000000:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{elif}\;y \leq 0.5:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= y -75000000.0) (fma y x z) (if (<= y 0.5) (fma x 0.5 z) (fma y x z))))
      double code(double x, double y, double z) {
      	double tmp;
      	if (y <= -75000000.0) {
      		tmp = fma(y, x, z);
      	} else if (y <= 0.5) {
      		tmp = fma(x, 0.5, z);
      	} else {
      		tmp = fma(y, x, z);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if (y <= -75000000.0)
      		tmp = fma(y, x, z);
      	elseif (y <= 0.5)
      		tmp = fma(x, 0.5, z);
      	else
      		tmp = fma(y, x, z);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[LessEqual[y, -75000000.0], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 0.5], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;y \leq -75000000:\\
      \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
      
      \mathbf{elif}\;y \leq 0.5:\\
      \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -7.5e7 or 0.5 < y

        1. Initial program 100.0%

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \frac{x}{2} + z\right)} \]
          4. div-invN/A

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

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

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

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

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

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

          if -7.5e7 < 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. +-commutativeN/A

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

              \[\leadsto \color{blue}{x \cdot \frac{1}{2}} + z \]
            3. accelerator-lowering-fma.f6498.8

              \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, z\right)} \]
          5. Simplified98.8%

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

        Alternative 4: 83.9% accurate, 1.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+16}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+112}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= y -3e+16) (* y x) (if (<= y 1.85e+112) (fma x 0.5 z) (* y x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -3e+16) {
        		tmp = y * x;
        	} else if (y <= 1.85e+112) {
        		tmp = fma(x, 0.5, z);
        	} else {
        		tmp = y * x;
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if (y <= -3e+16)
        		tmp = Float64(y * x);
        	elseif (y <= 1.85e+112)
        		tmp = fma(x, 0.5, z);
        	else
        		tmp = Float64(y * x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[LessEqual[y, -3e+16], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.85e+112], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -3 \cdot 10^{+16}:\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{elif}\;y \leq 1.85 \cdot 10^{+112}:\\
        \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;y \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -3e16 or 1.85000000000000002e112 < 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. *-lowering-*.f6471.8

              \[\leadsto \color{blue}{x \cdot y} \]
          5. Simplified71.8%

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

          if -3e16 < y < 1.85000000000000002e112

          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. +-commutativeN/A

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

              \[\leadsto \color{blue}{x \cdot \frac{1}{2}} + z \]
            3. accelerator-lowering-fma.f6493.8

              \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5, z\right)} \]
          5. Simplified93.8%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+16}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+112}:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
        5. Add Preprocessing

        Alternative 5: 49.2% accurate, 1.3× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+146}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-56}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= x -3.2e+146) (* x 0.5) (if (<= x 5.6e-56) z (* x 0.5))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -3.2e+146) {
        		tmp = x * 0.5;
        	} else if (x <= 5.6e-56) {
        		tmp = z;
        	} else {
        		tmp = x * 0.5;
        	}
        	return tmp;
        }
        
        real(8) function code(x, y, z)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8) :: tmp
            if (x <= (-3.2d+146)) then
                tmp = x * 0.5d0
            else if (x <= 5.6d-56) then
                tmp = z
            else
                tmp = x * 0.5d0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -3.2e+146) {
        		tmp = x * 0.5;
        	} else if (x <= 5.6e-56) {
        		tmp = z;
        	} else {
        		tmp = x * 0.5;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if x <= -3.2e+146:
        		tmp = x * 0.5
        	elif x <= 5.6e-56:
        		tmp = z
        	else:
        		tmp = x * 0.5
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (x <= -3.2e+146)
        		tmp = Float64(x * 0.5);
        	elseif (x <= 5.6e-56)
        		tmp = z;
        	else
        		tmp = Float64(x * 0.5);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (x <= -3.2e+146)
        		tmp = x * 0.5;
        	elseif (x <= 5.6e-56)
        		tmp = z;
        	else
        		tmp = x * 0.5;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[x, -3.2e+146], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 5.6e-56], z, N[(x * 0.5), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -3.2 \cdot 10^{+146}:\\
        \;\;\;\;x \cdot 0.5\\
        
        \mathbf{elif}\;x \leq 5.6 \cdot 10^{-56}:\\
        \;\;\;\;z\\
        
        \mathbf{else}:\\
        \;\;\;\;x \cdot 0.5\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -3.2e146 or 5.59999999999999986e-56 < x

          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. *-lowering-*.f64N/A

              \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + y\right)} \]
            2. +-lowering-+.f6485.5

              \[\leadsto x \cdot \color{blue}{\left(0.5 + y\right)} \]
          5. Simplified85.5%

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

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

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

            if -3.2e146 < x < 5.59999999999999986e-56

            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. Simplified66.4%

                \[\leadsto \color{blue}{z} \]
            5. Recombined 2 regimes into one program.
            6. 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. Step-by-step derivation
              1. div-invN/A

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(y + \color{blue}{0.5}, x, z\right) \]
            4. Applied egg-rr100.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;
            }
            
            real(8) function code(x, y, z)
                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. Simplified43.4%

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

              Reproduce

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