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

Percentage Accurate: 100.0% → 100.0%
Time: 3.6s
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(0.5, x, z\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma y x (fma 0.5 x z)))
double code(double x, double y, double z) {
	return fma(y, x, fma(0.5, x, z));
}
function code(x, y, z)
	return fma(y, x, fma(0.5, x, z))
end
code[x_, y_, z_] := N[(y * x + N[(0.5 * x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(0.5, x, 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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 83.8% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{2} + x \cdot y\\
t_1 := \left(y - -0.5\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+90}:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.99999999999999993e90 or 2.00000000000000003e43 < (+.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 z around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{y \cdot x} \]
      2. distribute-rgt-inN/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(y - -0.5\right)} \cdot x \]
    5. Applied rewrites86.2%

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

    if -1.99999999999999993e90 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 2.00000000000000003e43

    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. lower-fma.f6483.1

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

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

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

Alternative 3: 98.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot y + z\\ \mathbf{if}\;y \leq -2.7:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.25:\\ \;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (* x y) z)))
   (if (<= y -2.7) t_0 (if (<= y 0.25) (fma x 0.5 z) t_0))))
double code(double x, double y, double z) {
	double t_0 = (x * y) + z;
	double tmp;
	if (y <= -2.7) {
		tmp = t_0;
	} else if (y <= 0.25) {
		tmp = fma(x, 0.5, z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(x * y) + z)
	tmp = 0.0
	if (y <= -2.7)
		tmp = t_0;
	elseif (y <= 0.25)
		tmp = fma(x, 0.5, z);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]}, If[LessEqual[y, -2.7], t$95$0, If[LessEqual[y, 0.25], N[(x * 0.5 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot y + z\\
\mathbf{if}\;y \leq -2.7:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 0.25:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.7000000000000002 or 0.25 < 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} + z \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + z \]
      2. lower-*.f6497.7

        \[\leadsto \color{blue}{y \cdot x} + z \]
    5. Applied rewrites97.7%

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

    if -2.7000000000000002 < y < 0.25

    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. lower-fma.f6498.7

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

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

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

Alternative 4: 84.0% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+66}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 1500:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.4000000000000003e66 or 1500 < 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. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6472.0

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

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

    if -3.4000000000000003e66 < y < 1500

    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. lower-fma.f6493.3

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

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

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

Alternative 5: 59.9% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.7:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 30:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -2.7) (* x y) (if (<= y 30.0) (* 0.5 x) (* x y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.7) {
		tmp = x * y;
	} else if (y <= 30.0) {
		tmp = 0.5 * x;
	} else {
		tmp = x * y;
	}
	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 (y <= (-2.7d0)) then
        tmp = x * y
    else if (y <= 30.0d0) then
        tmp = 0.5d0 * x
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.7) {
		tmp = x * y;
	} else if (y <= 30.0) {
		tmp = 0.5 * x;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -2.7:
		tmp = x * y
	elif y <= 30.0:
		tmp = 0.5 * x
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -2.7)
		tmp = Float64(x * y);
	elseif (y <= 30.0)
		tmp = Float64(0.5 * x);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -2.7)
		tmp = x * y;
	elseif (y <= 30.0)
		tmp = 0.5 * x;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -2.7], N[(x * y), $MachinePrecision], If[LessEqual[y, 30.0], N[(0.5 * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 30:\\
\;\;\;\;0.5 \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.7000000000000002 or 30 < 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. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6467.3

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites67.3%

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

    if -2.7000000000000002 < y < 30

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{y \cdot x} \]
      2. distribute-rgt-inN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\left(y - \frac{-1}{2}\right)} \cdot x \]
      8. lower--.f6449.3

        \[\leadsto \color{blue}{\left(y - -0.5\right)} \cdot x \]
    5. Applied rewrites49.3%

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

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

        \[\leadsto 0.5 \cdot x \]
    8. Recombined 2 regimes into one program.
    9. Final simplification58.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.7:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 30:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
    10. Add Preprocessing

    Alternative 6: 100.0% accurate, 2.3× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(0.5 + y, x, z\right) \end{array} \]
    (FPCore (x y z) :precision binary64 (fma (+ 0.5 y) x z))
    double code(double x, double y, double z) {
    	return fma((0.5 + y), x, z);
    }
    
    function code(x, y, z)
    	return fma(Float64(0.5 + y), x, z)
    end
    
    code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(0.5 + y, 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. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 7: 36.6% accurate, 3.8× speedup?

    \[\begin{array}{l} \\ x \cdot y \end{array} \]
    (FPCore (x y z) :precision binary64 (* x y))
    double code(double x, double y, double z) {
    	return x * y;
    }
    
    real(8) function code(x, y, z)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        code = x * y
    end function
    
    public static double code(double x, double y, double z) {
    	return x * y;
    }
    
    def code(x, y, z):
    	return x * y
    
    function code(x, y, z)
    	return Float64(x * y)
    end
    
    function tmp = code(x, y, z)
    	tmp = x * y;
    end
    
    code[x_, y_, z_] := N[(x * y), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    x \cdot y
    \end{array}
    
    Derivation
    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. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6436.3

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites36.3%

      \[\leadsto \color{blue}{y \cdot x} \]
    6. Final simplification36.3%

      \[\leadsto x \cdot y \]
    7. Add Preprocessing

    Reproduce

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