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

Percentage Accurate: 100.0% → 100.0%
Time: 5.0s
Alternatives: 6
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 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?

\[\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. Taylor expanded in x around 0

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{z + \frac{1}{2} \cdot x}\right) \]
  9. Step-by-step derivation
    1. +-commutativeN/A

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

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

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

Alternative 2: 83.1% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+170} \lor \neg \left(t\_0 \leq 5 \cdot 10^{-14}\right):\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.00000000000000003e170 or 5.0000000000000002e-14 < (+.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 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. lower-fma.f6442.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot y - \frac{1}{2}\right)\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

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

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

        \[\leadsto \left(-1 \cdot x\right) \cdot \left(-1 \cdot y\right) - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \frac{1}{2} \]
      4. fp-cancel-sign-subN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(-1 \cdot y\right) \]
      8. fp-cancel-sub-sign-invN/A

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

        \[\leadsto \color{blue}{x \cdot \frac{1}{2}} - x \cdot \left(-1 \cdot y\right) \]
      10. distribute-lft-out--N/A

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

        \[\leadsto x \cdot \left(\frac{1}{2} - \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \cdot y\right) \]
      12. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{2} + y\right) \cdot x} \]
    8. Applied rewrites89.5%

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

    if -1.00000000000000003e170 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 5.0000000000000002e-14

    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. lower-fma.f6485.9

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

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

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

Alternative 3: 84.2% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{+18} \lor \neg \left(y \leq 1.35 \cdot 10^{+51}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.55e+18) (not (<= y 1.35e+51))) (* y x) (fma 0.5 x z)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.55e+18) || !(y <= 1.35e+51)) {
		tmp = y * x;
	} else {
		tmp = fma(0.5, x, z);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.55e+18) || !(y <= 1.35e+51))
		tmp = Float64(y * x);
	else
		tmp = fma(0.5, x, z);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e+18], N[Not[LessEqual[y, 1.35e+51]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+18} \lor \neg \left(y \leq 1.35 \cdot 10^{+51}\right):\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.55e18 or 1.34999999999999996e51 < y

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

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

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

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

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

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Applied rewrites76.4%

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

    if -1.55e18 < y < 1.34999999999999996e51

    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. lower-fma.f6495.4

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

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

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

Alternative 4: 59.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -0.5) (not (<= y 0.5))) (* y x) (* 0.5 x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -0.5) || !(y <= 0.5)) {
		tmp = y * x;
	} else {
		tmp = 0.5 * 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) :: tmp
    if ((y <= (-0.5d0)) .or. (.not. (y <= 0.5d0))) then
        tmp = y * x
    else
        tmp = 0.5d0 * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -0.5) || !(y <= 0.5)) {
		tmp = y * x;
	} else {
		tmp = 0.5 * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -0.5) or not (y <= 0.5):
		tmp = y * x
	else:
		tmp = 0.5 * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -0.5) || !(y <= 0.5))
		tmp = Float64(y * x);
	else
		tmp = Float64(0.5 * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -0.5) || ~((y <= 0.5)))
		tmp = y * x;
	else
		tmp = 0.5 * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.5 or 0.5 < y

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Add Preprocessing
    3. Taylor expanded in 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. lower-fma.f6428.5

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

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

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

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

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Applied rewrites73.0%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot y - \frac{1}{2}\right)\right)} \]
    7. Step-by-step derivation
      1. associate-*r*N/A

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

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

        \[\leadsto \left(-1 \cdot x\right) \cdot \left(-1 \cdot y\right) - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \frac{1}{2} \]
      4. fp-cancel-sign-subN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(-1 \cdot y\right) \]
      8. fp-cancel-sub-sign-invN/A

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

        \[\leadsto \color{blue}{x \cdot \frac{1}{2}} - x \cdot \left(-1 \cdot y\right) \]
      10. distribute-lft-out--N/A

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

        \[\leadsto x \cdot \left(\frac{1}{2} - \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \cdot y\right) \]
      12. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{2} + y\right) \cdot x} \]
    8. Applied rewrites52.5%

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

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

        \[\leadsto 0.5 \cdot x \]
    11. Recombined 2 regimes into one program.
    12. Final simplification61.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \]
    13. Add Preprocessing

    Alternative 5: 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. Taylor expanded in x around 0

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

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

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

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

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

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

    Alternative 6: 36.3% accurate, 3.8× speedup?

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

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot x} \]
    9. Add Preprocessing

    Reproduce

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