?

Average Accuracy: 100.0% → 100.0%
Time: 6.9s
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 100.0%

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

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

    [Start]100.0

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

    associate-+l+ [=>]100.0

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

    *-commutative [=>]100.0

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

    fma-def [=>]100.0

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

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

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

    [Start]100.0

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

    +-commutative [=>]100.0

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

    fma-def [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy57.0%
Cost1380
\[\begin{array}{l} \mathbf{if}\;z \leq -380000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-239}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-297}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-223}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-170}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 5.9 \cdot 10^{-37}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;z \leq 1.2:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+142}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+158}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Accuracy74.2%
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -76000000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+53} \lor \neg \left(z \leq 6.2 \cdot 10^{+101}\right) \land z \leq 8.5 \cdot 10^{+158}:\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Accuracy57.7%
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -740000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-41}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+142}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+158}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 4
Accuracy83.0%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+23} \lor \neg \left(x \leq 86000000000\right):\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 5
Accuracy98.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -35 \lor \neg \left(y \leq 6.2 \cdot 10^{-9}\right):\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + \frac{x}{2}\\ \end{array} \]
Alternative 6
Accuracy100.0%
Cost448
\[z + \left(0.5 + y\right) \cdot x \]
Alternative 7
Accuracy46.6%
Cost64
\[z \]

Error

Reproduce?

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