?

Average Error: 0.2 → 0.1
Time: 3.0s
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

Original0.2
Target0.1
Herbie0.1
\[x \cdot \left(3 \cdot y\right) - z \]

Derivation?

  1. Initial program 0.2

    \[\left(x \cdot 3\right) \cdot y - z \]
  2. Taylor expanded in x around 0 0.1

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

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

    [Start]0.1

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

    mul-1-neg [=>]0.1

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

    fma-def [=>]0.1

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

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

Alternatives

Alternative 1
Error16.7
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{-30}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-87} \lor \neg \left(z \leq -5.6 \cdot 10^{-112}\right) \land z \leq 5000:\\ \;\;\;\;3 \cdot \left(y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 2
Error16.7
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{-30}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -3.3 \cdot 10^{-86}:\\ \;\;\;\;3 \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;z \leq -1.12 \cdot 10^{-112}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 36:\\ \;\;\;\;y \cdot \left(3 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error0.1
Cost448
\[x \cdot \left(3 \cdot y\right) - z \]
Alternative 4
Error0.2
Cost448
\[y \cdot \left(3 \cdot x\right) - z \]
Alternative 5
Error27.8
Cost128
\[-z \]

Error

Reproduce?

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