Average Error: 0.0 → 0.0
Time: 4.1s
Precision: binary64
Cost: 6720
\[\left(\frac{x}{2} + y \cdot x\right) + z \]
\[\mathsf{fma}\left(0.5 + y, x, z\right) \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
(FPCore (x y z) :precision binary64 (fma (+ 0.5 y) x z))
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((0.5 + y), x, z);
}
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function code(x, y, z)
	return fma(Float64(0.5 + y), x, z)
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\left(\frac{x}{2} + y \cdot x\right) + z
\mathsf{fma}\left(0.5 + y, x, z\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} + \mathsf{fma}\left(x, y, z\right)} \]
    Proof
    (+.f64 (/.f64 x 2) (fma.f64 x y z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 x 2) (Rewrite<= fma-def_binary64 (+.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. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
  4. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 + y, x, z\right)} \]
    Proof
    (fma.f64 (+.f64 1/2 y) x z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 1/2 y) x) z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 z (*.f64 (+.f64 1/2 y) x))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error30.5
Cost1116
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+45}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{-188}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-217}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-221}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-263}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+29}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+191}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error16.6
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -1.28 \cdot 10^{+91}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+53} \lor \neg \left(z \leq -1.95 \cdot 10^{-31}\right) \land z \leq 2.8 \cdot 10^{-41}:\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error11.2
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+147} \lor \neg \left(x \leq 2000000000000\right):\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 4
Error1.3
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -5.2 \cdot 10^{+14} \lor \neg \left(y \leq 2.45 \cdot 10^{-14}\right):\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + \frac{x}{2}\\ \end{array} \]
Alternative 5
Error28.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+145}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{+18}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost448
\[z + \left(0.5 + y\right) \cdot x \]
Alternative 7
Error35.1
Cost64
\[z \]

Error

Reproduce

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