?

Average Accuracy: 99.8% → 99.8%
Time: 3.6s
Precision: binary64
Cost: 6784

?

\[\left(x \cdot 3\right) \cdot y - z \]
\[\mathsf{fma}\left(3, y \cdot x, -z\right) \]
(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
(FPCore (x y z) :precision binary64 (fma 3.0 (* y x) (- z)))
double code(double x, double y, double z) {
	return ((x * 3.0) * y) - z;
}
double code(double x, double y, double z) {
	return fma(3.0, (y * x), -z);
}
function code(x, y, z)
	return Float64(Float64(Float64(x * 3.0) * y) - z)
end
function code(x, y, z)
	return fma(3.0, Float64(y * x), Float64(-z))
end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := N[(3.0 * N[(y * x), $MachinePrecision] + (-z)), $MachinePrecision]
\left(x \cdot 3\right) \cdot y - z
\mathsf{fma}\left(3, y \cdot x, -z\right)

Error?

Target

Original99.8%
Target99.8%
Herbie99.8%
\[x \cdot \left(3 \cdot y\right) - z \]

Derivation?

  1. Initial program 99.8%

    \[\left(x \cdot 3\right) \cdot y - z \]
  2. Simplified99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot 3, y, -z\right)} \]
    Proof

    [Start]99.8

    \[ \left(x \cdot 3\right) \cdot y - z \]

    fma-neg [=>]99.8

    \[ \color{blue}{\mathsf{fma}\left(x \cdot 3, y, -z\right)} \]
  3. Taylor expanded in x around 0 99.8%

    \[\leadsto \color{blue}{3 \cdot \left(y \cdot x\right) + -1 \cdot z} \]
  4. Simplified99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, y \cdot x, -z\right)} \]
    Proof

    [Start]99.8

    \[ 3 \cdot \left(y \cdot x\right) + -1 \cdot z \]

    fma-def [=>]99.8

    \[ \color{blue}{\mathsf{fma}\left(3, y \cdot x, -1 \cdot z\right)} \]

    mul-1-neg [=>]99.8

    \[ \mathsf{fma}\left(3, y \cdot x, \color{blue}{-z}\right) \]
  5. Final simplification99.8%

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

Alternatives

Alternative 1
Accuracy71.6%
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{-29}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.12 \cdot 10^{-101} \lor \neg \left(z \leq 7.8 \cdot 10^{-50}\right) \land z \leq 8 \cdot 10^{+75}:\\ \;\;\;\;3 \cdot \left(y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Accuracy99.8%
Cost448
\[3 \cdot \left(y \cdot x\right) - z \]
Alternative 3
Accuracy57.2%
Cost128
\[-z \]
Alternative 4
Accuracy2.3%
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (- (* x (* 3.0 y)) z)

  (- (* (* x 3.0) y) z))