| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 6980 |
\[\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+207}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\]

(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+207) (fma x (* y y) x) (* y (* x y))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+207) {
tmp = fma(x, (y * y), x);
} else {
tmp = y * (x * y);
}
return tmp;
}
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+207) tmp = fma(x, Float64(y * y), x); else tmp = Float64(y * Float64(x * y)); end return tmp end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+207], N[(x * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 + y \cdot y\right)
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+207}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 94.7% |
|---|---|
| Target | 99.9% |
| Herbie | 99.9% |
if (*.f64 y y) < 4.9999999999999999e207Initial program 99.9%
Simplified99.9%
[Start]99.9% | \[ x \cdot \left(1 + y \cdot y\right)
\] |
|---|---|
+-commutative [=>]99.9% | \[ x \cdot \color{blue}{\left(y \cdot y + 1\right)}
\] |
distribute-lft-in [=>]99.9% | \[ \color{blue}{x \cdot \left(y \cdot y\right) + x \cdot 1}
\] |
*-rgt-identity [=>]99.9% | \[ x \cdot \left(y \cdot y\right) + \color{blue}{x}
\] |
fma-def [=>]99.9% | \[ \color{blue}{\mathsf{fma}\left(x, y \cdot y, x\right)}
\] |
if 4.9999999999999999e207 < (*.f64 y y) Initial program 85.3%
Taylor expanded in y around inf 85.3%
Simplified99.9%
[Start]85.3% | \[ {y}^{2} \cdot x
\] |
|---|---|
unpow2 [=>]85.3% | \[ \color{blue}{\left(y \cdot y\right)} \cdot x
\] |
associate-*l* [=>]99.9% | \[ \color{blue}{y \cdot \left(y \cdot x\right)}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 6980 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 26112 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 708 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.4% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 51.7% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:herbie-target
(+ x (* (* x y) y))
(* x (+ 1.0 (* y y))))