| Alternative 1 | |
|---|---|
| Accuracy | 82.8% |
| Cost | 585 |
\[\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-33} \lor \neg \left(z \leq 2.5 \cdot 10^{-19}\right):\\
\;\;\;\;\left(z \cdot z\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
(FPCore (x y z) :precision binary64 (fma z z (+ (* x y) (* 2.0 (* z z)))))
double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
double code(double x, double y, double z) {
return fma(z, z, ((x * y) + (2.0 * (z * z))));
}
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z)) end
function code(x, y, z) return fma(z, z, Float64(Float64(x * y) + Float64(2.0 * Float64(z * z)))) end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(z * z + N[(N[(x * y), $MachinePrecision] + N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(z, z, x \cdot y + 2 \cdot \left(z \cdot z\right)\right)
| Original | 99.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.9% |
Initial program 99.8%
Simplified99.9%
[Start]99.8 | \[ \left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\] |
|---|---|
+-commutative [=>]99.8 | \[ \color{blue}{z \cdot z + \left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right)}
\] |
fma-def [=>]99.9 | \[ \color{blue}{\mathsf{fma}\left(z, z, \left(x \cdot y + z \cdot z\right) + z \cdot z\right)}
\] |
associate-+l+ [=>]99.9 | \[ \mathsf{fma}\left(z, z, \color{blue}{x \cdot y + \left(z \cdot z + z \cdot z\right)}\right)
\] |
fma-def [=>]99.9 | \[ \mathsf{fma}\left(z, z, \color{blue}{\mathsf{fma}\left(x, y, z \cdot z + z \cdot z\right)}\right)
\] |
count-2 [=>]99.9 | \[ \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, \color{blue}{2 \cdot \left(z \cdot z\right)}\right)\right)
\] |
Applied egg-rr99.9%
[Start]99.9 | \[ \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right)
\] |
|---|---|
fma-udef [=>]99.9 | \[ \mathsf{fma}\left(z, z, \color{blue}{x \cdot y + 2 \cdot \left(z \cdot z\right)}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 82.8% |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 192 |
herbie shell --seed 2023137
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
:precision binary64
:herbie-target
(+ (* (* 3.0 z) z) (* y x))
(+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))