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

(FPCore (x y) :precision binary64 (- (* x x) (* y y)))
(FPCore (x y) :precision binary64 (if (<= x 3.2e+170) (fma x x (* y (- y))) (* x x)))
double code(double x, double y) {
return (x * x) - (y * y);
}
double code(double x, double y) {
double tmp;
if (x <= 3.2e+170) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
function code(x, y) return Float64(Float64(x * x) - Float64(y * y)) end
function code(x, y) tmp = 0.0 if (x <= 3.2e+170) tmp = fma(x, x, Float64(y * Float64(-y))); else tmp = Float64(x * x); end return tmp end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, 3.2e+170], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
x \cdot x - y \cdot y
\begin{array}{l}
\mathbf{if}\;x \leq 3.2 \cdot 10^{+170}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if x < 3.19999999999999979e170Initial program 97.0%
Simplified99.6%
[Start]97.0% | \[ x \cdot x - y \cdot y
\] |
|---|---|
fma-neg [=>]99.6% | \[ \color{blue}{\mathsf{fma}\left(x, x, -y \cdot y\right)}
\] |
distribute-rgt-neg-in [=>]99.6% | \[ \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(-y\right)}\right)
\] |
if 3.19999999999999979e170 < x Initial program 70.8%
Taylor expanded in x around inf 95.8%
Simplified95.8%
[Start]95.8% | \[ {x}^{2}
\] |
|---|---|
unpow2 [=>]95.8% | \[ \color{blue}{x \cdot x}
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 6916 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.8% |
| Cost | 708 |
| Alternative 3 | |
|---|---|
| Accuracy | 76.6% |
| Cost | 521 |
| Alternative 4 | |
|---|---|
| Accuracy | 54.0% |
| Cost | 192 |
herbie shell --seed 2023263
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))