| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19520 |
\[\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\]

(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot \sin y + z \cdot \cos y
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.8%
Applied egg-rr99.8%
[Start]99.8% | \[ x \cdot \sin y + z \cdot \cos y
\] |
|---|---|
+-commutative [=>]99.8% | \[ \color{blue}{z \cdot \cos y + x \cdot \sin y}
\] |
*-commutative [=>]99.8% | \[ \color{blue}{\cos y \cdot z} + x \cdot \sin y
\] |
fma-def [=>]99.8% | \[ \color{blue}{\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19520 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13248 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.7% |
| Cost | 6985 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.6% |
| Cost | 6857 |
| Alternative 5 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 6857 |
| Alternative 6 | |
|---|---|
| Accuracy | 41.8% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 52.1% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 38.7% |
| Cost | 64 |
herbie shell --seed 2023167
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))