| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 7872 |
\[\mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\left(x \cdot x\right) \cdot 3 - y \cdot y\right) + \left(y \cdot y\right) \cdot 2
\]

(FPCore (x y) :precision binary64 (+ (- (* 9.0 (pow x 4.0)) (pow y 4.0)) (* 2.0 (* y y))))
(FPCore (x y) :precision binary64 (+ (* (fma (* x x) 3.0 (* y y)) (- (* (* x x) 3.0) (* y y))) (* (* y y) 2.0)))
double code(double x, double y) {
return ((9.0 * pow(x, 4.0)) - pow(y, 4.0)) + (2.0 * (y * y));
}
double code(double x, double y) {
return (fma((x * x), 3.0, (y * y)) * (((x * x) * 3.0) - (y * y))) + ((y * y) * 2.0);
}
function code(x, y) return Float64(Float64(Float64(9.0 * (x ^ 4.0)) - (y ^ 4.0)) + Float64(2.0 * Float64(y * y))) end
function code(x, y) return Float64(Float64(fma(Float64(x * x), 3.0, Float64(y * y)) * Float64(Float64(Float64(x * x) * 3.0) - Float64(y * y))) + Float64(Float64(y * y) * 2.0)) end
code[x_, y_] := N[(N[(N[(9.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(N[(N[(x * x), $MachinePrecision] * 3.0 + N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\left(9 \cdot {x}^{4} - {y}^{4}\right) + 2 \cdot \left(y \cdot y\right)
\mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\left(x \cdot x\right) \cdot 3 - y \cdot y\right) + \left(y \cdot y\right) \cdot 2
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 18.8%
Applied egg-rr100.0%
[Start]18.8% | \[ \left(9 \cdot {x}^{4} - {y}^{4}\right) + 2 \cdot \left(y \cdot y\right)
\] |
|---|---|
add-sqr-sqrt [=>]18.8% | \[ \left(\color{blue}{\sqrt{9 \cdot {x}^{4}} \cdot \sqrt{9 \cdot {x}^{4}}} - {y}^{4}\right) + 2 \cdot \left(y \cdot y\right)
\] |
metadata-eval [<=]18.8% | \[ \left(\sqrt{9 \cdot {x}^{4}} \cdot \sqrt{9 \cdot {x}^{4}} - {y}^{\color{blue}{\left(2 + 2\right)}}\right) + 2 \cdot \left(y \cdot y\right)
\] |
pow-prod-up [<=]18.8% | \[ \left(\sqrt{9 \cdot {x}^{4}} \cdot \sqrt{9 \cdot {x}^{4}} - \color{blue}{{y}^{2} \cdot {y}^{2}}\right) + 2 \cdot \left(y \cdot y\right)
\] |
pow2 [<=]18.8% | \[ \left(\sqrt{9 \cdot {x}^{4}} \cdot \sqrt{9 \cdot {x}^{4}} - \color{blue}{\left(y \cdot y\right)} \cdot {y}^{2}\right) + 2 \cdot \left(y \cdot y\right)
\] |
pow2 [<=]18.8% | \[ \left(\sqrt{9 \cdot {x}^{4}} \cdot \sqrt{9 \cdot {x}^{4}} - \left(y \cdot y\right) \cdot \color{blue}{\left(y \cdot y\right)}\right) + 2 \cdot \left(y \cdot y\right)
\] |
difference-of-squares [=>]100.0% | \[ \color{blue}{\left(\sqrt{9 \cdot {x}^{4}} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right)} + 2 \cdot \left(y \cdot y\right)
\] |
*-commutative [=>]100.0% | \[ \left(\sqrt{\color{blue}{{x}^{4} \cdot 9}} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
sqrt-prod [=>]100.0% | \[ \left(\color{blue}{\sqrt{{x}^{4}} \cdot \sqrt{9}} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
sqrt-pow1 [=>]100.0% | \[ \left(\color{blue}{{x}^{\left(\frac{4}{2}\right)}} \cdot \sqrt{9} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
metadata-eval [=>]100.0% | \[ \left({x}^{\color{blue}{2}} \cdot \sqrt{9} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
pow2 [<=]100.0% | \[ \left(\color{blue}{\left(x \cdot x\right)} \cdot \sqrt{9} + y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x \cdot x, \sqrt{9}, y \cdot y\right)} \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, \color{blue}{3}, y \cdot y\right) \cdot \left(\sqrt{9 \cdot {x}^{4}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\sqrt{\color{blue}{{x}^{4} \cdot 9}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
sqrt-prod [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\color{blue}{\sqrt{{x}^{4}} \cdot \sqrt{9}} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
sqrt-pow1 [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\color{blue}{{x}^{\left(\frac{4}{2}\right)}} \cdot \sqrt{9} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} \cdot \sqrt{9} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
pow2 [<=]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \sqrt{9} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x \cdot x, 3, y \cdot y\right) \cdot \left(\left(x \cdot x\right) \cdot \color{blue}{3} - y \cdot y\right) + 2 \cdot \left(y \cdot y\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 7872 |
| Alternative 2 | |
|---|---|
| Accuracy | 9.6% |
| Cost | 7040 |
| Alternative 3 | |
|---|---|
| Accuracy | 1.5% |
| Cost | 576 |
herbie shell --seed 2023178
(FPCore (x y)
:name "From Rump in a 1983 paper"
:precision binary64
:pre (and (== x 10864.0) (== y 18817.0))
(+ (- (* 9.0 (pow x 4.0)) (pow y 4.0)) (* 2.0 (* y y))))