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

Error

Derivation

  1. Initial program 0.0

    \[\frac{x \cdot y}{2} - \frac{z}{8} \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y \cdot 0.5, z \cdot -0.125\right)} \]
    Proof
    (fma.f64 x (*.f64 y 1/2) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (*.f64 y (Rewrite<= metadata-eval (neg.f64 -1/2))) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (*.f64 y (neg.f64 (Rewrite<= metadata-eval (/.f64 -1 2)))) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (/.f64 -1 2)) y)) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 (/.f64 -1 2) y))) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (neg.f64 (Rewrite<= associate-/r/_binary64 (/.f64 -1 (/.f64 2 y)))) (*.f64 z -1/8)): 18 points increase in error, 0 points decrease in error
    (fma.f64 x (neg.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -1 y) 2))) (*.f64 z -1/8)): 0 points increase in error, 18 points decrease in error
    (fma.f64 x (neg.f64 (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) 2)) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (neg.f64 y)) 2)) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 (Rewrite=> remove-double-neg_binary64 y) 2) (*.f64 z -1/8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 y 2) (*.f64 z (Rewrite<= metadata-eval (/.f64 -1 8)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 y 2) (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 -1 8) z))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 y 2) (Rewrite<= associate-/r/_binary64 (/.f64 -1 (/.f64 8 z)))): 25 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 y 2) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -1 z) 8))): 0 points increase in error, 25 points decrease in error
    (fma.f64 x (/.f64 y 2) (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 z)) 8)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (/.f64 y 2) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 z 8)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x (/.f64 y 2)) (/.f64 z 8))): 2 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) 2)) (/.f64 z 8)): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error17.1
Cost848
\[\begin{array}{l} t_0 := 0.5 \cdot \left(x \cdot y\right)\\ \mathbf{if}\;z \leq -7.220923419859223 \cdot 10^{+40}:\\ \;\;\;\;z \cdot -0.125\\ \mathbf{elif}\;z \leq -3501177887211045000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.4758906421462062 \cdot 10^{-56}:\\ \;\;\;\;z \cdot -0.125\\ \mathbf{elif}\;z \leq 5.442425913107027 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot -0.125\\ \end{array} \]
Alternative 2
Error0.0
Cost576
\[\frac{x \cdot y}{2} - \frac{z}{8} \]
Alternative 3
Error27.1
Cost192
\[z \cdot -0.125 \]

Error

Reproduce

herbie shell --seed 2022317 
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:quartForm  from diagrams-solve-0.1, D"
  :precision binary64
  (- (/ (* x y) 2.0) (/ z 8.0)))