| Alternative 1 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 708 |
\[\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+294}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\]

(FPCore (x y) :precision binary64 (- (* x x) (* y y)))
(FPCore (x y) :precision binary64 (if (<= (* x x) 4e+294) (- (* 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) <= 4e+294) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) - (y * y)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 4d+294) then
tmp = (x * x) - (y * y)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
return (x * x) - (y * y);
}
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 4e+294) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): return (x * x) - (y * y)
def code(x, y): tmp = 0 if (x * x) <= 4e+294: tmp = (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) <= 4e+294) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(x * x); end return tmp end
function tmp = code(x, y) tmp = (x * x) - (y * y); end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 4e+294) tmp = (x * x) - (y * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 4e+294], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
x \cdot x - y \cdot y
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+294}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (*.f64 x x) < 4.00000000000000027e294Initial program 100.0%
if 4.00000000000000027e294 < (*.f64 x x) Initial program 73.9%
Taylor expanded in x around inf 92.8%
Simplified92.8%
[Start]92.8% | \[ {x}^{2}
\] |
|---|---|
unpow2 [=>]92.8% | \[ \color{blue}{x \cdot x}
\] |
Final simplification98.0%
| Alternative 1 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 708 |
| Alternative 2 | |
|---|---|
| Accuracy | 76.4% |
| Cost | 520 |
| Alternative 3 | |
|---|---|
| Accuracy | 54.0% |
| Cost | 192 |
herbie shell --seed 2023277
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))