?

Average Error: 0.0 → 0.0
Time: 5.0s
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

    [Start]0.0

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

    associate-+l+ [=>]0.0

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

    *-commutative [=>]0.0

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

    fma-def [=>]0.0

    \[ \frac{x}{2} + \color{blue}{\mathsf{fma}\left(x, y, z\right)} \]
  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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error30.6
Cost1380
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{+222}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{+143}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq -7.1 \cdot 10^{+34}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-75}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{-175}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-74}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 700000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+28}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+85}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot x\\ \end{array} \]
Alternative 2
Error10.8
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -3 \cdot 10^{-59} \lor \neg \left(z \leq 2.5 \cdot 10^{-31}\right):\\ \;\;\;\;z + 0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \end{array} \]
Alternative 3
Error0.9
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \lor \neg \left(y \leq 1.72 \cdot 10^{-12}\right):\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + 0.5 \cdot x\\ \end{array} \]
Alternative 4
Error16.5
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+169}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+48}:\\ \;\;\;\;\left(0.5 + y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 5
Error28.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{-56}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 315000000000:\\ \;\;\;\;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 2023054 
(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))