| Alternative 1 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 7044 |
\[\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\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 x) 5e+304) (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 * x) <= 5e+304) {
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 (Float64(x * x) <= 5e+304) 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[N[(x * x), $MachinePrecision], 5e+304], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
x \cdot x - y \cdot y
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\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 (*.f64 x x) < 4.9999999999999997e304Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ x \cdot x - y \cdot y
\] |
|---|---|
fma-neg [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, x, -y \cdot y\right)}
\] |
distribute-rgt-neg-in [=>]100.0% | \[ \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(-y\right)}\right)
\] |
if 4.9999999999999997e304 < (*.f64 x x) Initial program 85.5%
Taylor expanded in x around inf 96.8%
Simplified96.8%
[Start]96.8% | \[ {x}^{2}
\] |
|---|---|
unpow2 [=>]96.8% | \[ \color{blue}{x \cdot x}
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 7044 |
| Alternative 2 | |
|---|---|
| Accuracy | 77.3% |
| Cost | 1037 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 708 |
| Alternative 4 | |
|---|---|
| Accuracy | 53.8% |
| Cost | 192 |
herbie shell --seed 2023243
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))