?

Average Error: 0.01% → 0.01%
Time: 3.7s
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.01

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

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

    [Start]0.01

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

    associate-+l+ [=>]0.01

    \[ \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]

    *-commutative [=>]0.01

    \[ \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]

    fma-def [=>]0.01

    \[ \frac{x}{2} + \color{blue}{\mathsf{fma}\left(x, y, z\right)} \]
  3. Taylor expanded in x around 0 0.01

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

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

    [Start]0.01

    \[ z + \left(0.5 + y\right) \cdot x \]

    +-commutative [=>]0.01

    \[ \color{blue}{\left(0.5 + y\right) \cdot x + z} \]

    fma-def [=>]0.01

    \[ \color{blue}{\mathsf{fma}\left(0.5 + y, x, z\right)} \]
  5. Final simplification0.01

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

Alternatives

Alternative 1
Error31.86%
Cost1115
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{+40} \lor \neg \left(x \leq -1.9 \cdot 10^{-41}\right) \land \left(x \leq -1.75 \cdot 10^{-111} \lor \neg \left(x \leq 1.55 \cdot 10^{-107}\right) \land \left(x \leq 8.1 \cdot 10^{-53} \lor \neg \left(x \leq 3.6 \cdot 10^{-13}\right)\right)\right):\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error43.9%
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{+87}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{+75}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{-96}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-75}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error18.64%
Cost720
\[\begin{array}{l} t_0 := \left(0.5 + y\right) \cdot x\\ \mathbf{if}\;y \leq -1.15 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 300000000:\\ \;\;\;\;z + 0.5 \cdot x\\ \mathbf{elif}\;y \leq 2.65 \cdot 10^{+189}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+217}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error0.01%
Cost448
\[z + \left(0.5 + y\right) \cdot x \]
Alternative 5
Error52.94%
Cost64
\[z \]

Error

Reproduce?

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