Average Error: 0.0 → 0
Time: 3.1s
Precision: binary64
Cost: 6656
\[x - y \cdot z \]
\[\mathsf{fma}\left(y, -z, x\right) \]
(FPCore (x y z) :precision binary64 (- x (* y z)))
(FPCore (x y z) :precision binary64 (fma y (- z) x))
double code(double x, double y, double z) {
	return x - (y * z);
}
double code(double x, double y, double z) {
	return fma(y, -z, x);
}
function code(x, y, z)
	return Float64(x - Float64(y * z))
end
function code(x, y, z)
	return fma(y, Float64(-z), x)
end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(y * (-z) + x), $MachinePrecision]
x - y \cdot z
\mathsf{fma}\left(y, -z, x\right)

Error

Target

Original0.0
Target0.0
Herbie0
\[\frac{x + y \cdot z}{\frac{x + y \cdot z}{x - y \cdot z}} \]

Derivation

  1. Initial program 0.0

    \[x - y \cdot z \]
  2. Simplified0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, -z, x\right)} \]
    Proof
    (fma.f64 y (neg.f64 z) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 z)) x)): 2 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y z))) x): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 y) z)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (neg.f64 y) z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 x (*.f64 y z))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0

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

Alternatives

Alternative 1
Error22.0
Cost784
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1.529666242508243 \cdot 10^{-99}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.530285007476673 \cdot 10^{+48}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+154}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost320
\[x - y \cdot z \]
Alternative 3
Error26.6
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022290 
(FPCore (x y z)
  :name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, C"
  :precision binary64

  :herbie-target
  (/ (+ x (* y z)) (/ (+ x (* y z)) (- x (* y z))))

  (- x (* y z)))