?

Average Accuracy: 99.9% → 100.0%
Time: 7.6s
Precision: binary64
Cost: 6848

?

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

Error?

Target

Original99.9%
Target97.7%
Herbie100.0%
\[\left(x + 5\right) \cdot z + x \cdot y \]

Derivation?

  1. Initial program 99.9%

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, 5, x \cdot \left(y + z\right)\right)} \]
    Step-by-step derivation

    [Start]99.9

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

    +-commutative [=>]99.9

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

    fma-def [=>]100.0

    \[ \color{blue}{\mathsf{fma}\left(z, 5, x \cdot \left(y + z\right)\right)} \]
  3. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy61.5%
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{+237}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+137}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5 \cdot 10^{+38}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -1.62 \cdot 10^{-21}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3500000:\\ \;\;\;\;z \cdot 5\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+166}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Accuracy98.9%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 0.62\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot 5 + x \cdot y\\ \end{array} \]
Alternative 3
Accuracy85.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-21} \lor \neg \left(x \leq 0.49\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(5 + x\right)\\ \end{array} \]
Alternative 4
Accuracy75.3%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{+117}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 9.8 \cdot 10^{+62}:\\ \;\;\;\;z \cdot \left(5 + x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Accuracy99.9%
Cost576
\[z \cdot 5 + x \cdot \left(z + y\right) \]
Alternative 6
Accuracy61.8%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{-24}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-64}:\\ \;\;\;\;z \cdot 5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 7
Accuracy36.9%
Cost192
\[z \cdot 5 \]

Error

Reproduce?

herbie shell --seed 2023159 
(FPCore (x y z)
  :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
  :precision binary64

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

  (+ (* x (+ y z)) (* z 5.0)))