| Alternative 1 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 6916 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 2.52 \cdot 10^{+123}:\\
\;\;\;\;\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 2.52e+123) (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 <= 2.52e+123) {
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 <= 2.52e+123) 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, 2.52e+123], 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 2.52 \cdot 10^{+123}:\\
\;\;\;\;\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 < 2.52e123Initial program 95.9%
Simplified98.6%
[Start]95.9% | \[ x \cdot x - y \cdot y
\] |
|---|---|
fma-neg [=>]98.6% | \[ \color{blue}{\mathsf{fma}\left(x, x, -y \cdot y\right)}
\] |
distribute-rgt-neg-in [=>]98.6% | \[ \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(-y\right)}\right)
\] |
if 2.52e123 < x Initial program 77.8%
Taylor expanded in x around inf 97.2%
Simplified97.2%
[Start]97.2% | \[ {x}^{2}
\] |
|---|---|
unpow2 [=>]97.2% | \[ \color{blue}{x \cdot x}
\] |
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 6916 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.9% |
| Cost | 708 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 521 |
| Alternative 4 | |
|---|---|
| Accuracy | 54.5% |
| Cost | 192 |
herbie shell --seed 2023272
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))