Average Error: 0.0 → 0.0
Time: 3.5s
Precision: binary64
Cost: 6848
\[\left(\frac{x}{2} + y \cdot x\right) + z \]
\[\mathsf{fma}\left(y, x, z + x \cdot 0.5\right) \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
(FPCore (x y z) :precision binary64 (fma y x (+ z (* x 0.5))))
double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
double code(double x, double y, double z) {
	return fma(y, x, (z + (x * 0.5)));
}
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function code(x, y, z)
	return fma(y, x, Float64(z + Float64(x * 0.5)))
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
code[x_, y_, z_] := N[(y * x + N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{x}{2} + y \cdot x\right) + z
\mathsf{fma}\left(y, x, z + x \cdot 0.5\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    Proof
    (+.f64 (/.f64 x 2) (+.f64 (*.f64 x y) z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 x 2) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 y x)) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (/.f64 x 2) (*.f64 y x)) z)): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, z + x \cdot 0.5\right)} \]
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error28.5
Cost1116
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+26}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-136}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-203}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-238}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-118}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-60}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{+58}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error11.1
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(y + 0.5\right)\\ t_1 := z + y \cdot x\\ \mathbf{if}\;x \leq -5.5 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{+88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{+33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error27.7
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+159}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{+88}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{+21}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+17}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.5\\ \end{array} \]
Alternative 4
Error15.6
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+37}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{+59}:\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 5
Error0.9
Cost584
\[\begin{array}{l} t_0 := z + y \cdot x\\ \mathbf{if}\;y \leq -0.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.5:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[z + x \cdot \left(y + 0.5\right) \]
Alternative 7
Error34.6
Cost64
\[z \]

Error

Reproduce

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