| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 708 |
\[\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 100000000000:\\
\;\;\;\;x \cdot \left(y \cdot y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\]
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
(FPCore (x y) :precision binary64 (if (<= (* y y) 100000000000.0) (fma x (* y y) x) (* y (* y x))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
double code(double x, double y) {
double tmp;
if ((y * y) <= 100000000000.0) {
tmp = fma(x, (y * y), x);
} else {
tmp = y * (y * x);
}
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) <= 100000000000.0) tmp = fma(x, Float64(y * y), x); else tmp = Float64(y * Float64(y * x)); 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], 100000000000.0], N[(x * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 + y \cdot y\right)
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 100000000000:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
| Original | 5.4 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
if (*.f64 y y) < 1e11Initial program 0.0
Simplified0.0
[Start]0.0 | \[ x \cdot \left(1 + y \cdot y\right)
\] |
|---|---|
distribute-lft-in [=>]0.0 | \[ \color{blue}{x \cdot 1 + x \cdot \left(y \cdot y\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{x \cdot \left(y \cdot y\right) + x \cdot 1}
\] |
*-rgt-identity [=>]0.0 | \[ x \cdot \left(y \cdot y\right) + \color{blue}{x}
\] |
fma-def [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(x, y \cdot y, x\right)}
\] |
if 1e11 < (*.f64 y y) Initial program 16.2
Taylor expanded in y around inf 16.4
Simplified0.4
[Start]16.4 | \[ {y}^{2} \cdot x
\] |
|---|---|
unpow2 [=>]16.4 | \[ \color{blue}{\left(y \cdot y\right)} \cdot x
\] |
associate-*l* [=>]0.4 | \[ \color{blue}{y \cdot \left(y \cdot x\right)}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 708 |
| Alternative 2 | |
|---|---|
| Error | 6.2 |
| Cost | 580 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Error | 21.1 |
| Cost | 64 |
herbie shell --seed 2023031
(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))))