| Alternative 1 | |
|---|---|
| Error | 31.3 |
| Cost | 64 |
\[a
\]
(FPCore (a b) :precision binary64 (sqrt (- (* a a) (* b b))))
(FPCore (a b) :precision binary64 (if (<= a -2.3353896247746582e-262) (- a) a))
double code(double a, double b) {
return sqrt(((a * a) - (b * b)));
}
double code(double a, double b) {
double tmp;
if (a <= -2.3353896247746582e-262) {
tmp = -a;
} else {
tmp = a;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = sqrt(((a * a) - (b * b)))
end function
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-2.3353896247746582d-262)) then
tmp = -a
else
tmp = a
end if
code = tmp
end function
public static double code(double a, double b) {
return Math.sqrt(((a * a) - (b * b)));
}
public static double code(double a, double b) {
double tmp;
if (a <= -2.3353896247746582e-262) {
tmp = -a;
} else {
tmp = a;
}
return tmp;
}
def code(a, b): return math.sqrt(((a * a) - (b * b)))
def code(a, b): tmp = 0 if a <= -2.3353896247746582e-262: tmp = -a else: tmp = a return tmp
function code(a, b) return sqrt(Float64(Float64(a * a) - Float64(b * b))) end
function code(a, b) tmp = 0.0 if (a <= -2.3353896247746582e-262) tmp = Float64(-a); else tmp = a; end return tmp end
function tmp = code(a, b) tmp = sqrt(((a * a) - (b * b))); end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.3353896247746582e-262) tmp = -a; else tmp = a; end tmp_2 = tmp; end
code[a_, b_] := N[Sqrt[N[(N[(a * a), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := If[LessEqual[a, -2.3353896247746582e-262], (-a), a]
\sqrt{a \cdot a - b \cdot b}
\begin{array}{l}
\mathbf{if}\;a \leq -2.3353896247746582 \cdot 10^{-262}:\\
\;\;\;\;-a\\
\mathbf{else}:\\
\;\;\;\;a\\
\end{array}
Results
| Original | 31.5 |
|---|---|
| Target | 0.5 |
| Herbie | 0.9 |
if a < -2.3353896247746582e-262Initial program 31.0
Taylor expanded in a around -inf 0.7
Simplified0.7
[Start]0.7 | \[ -1 \cdot a
\] |
|---|---|
rational.json-simplify-2 [=>]0.7 | \[ \color{blue}{a \cdot -1}
\] |
rational.json-simplify-9 [=>]0.7 | \[ \color{blue}{-a}
\] |
if -2.3353896247746582e-262 < a Initial program 32.0
Taylor expanded in a around inf 1.1
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 31.3 |
| Cost | 64 |
herbie shell --seed 2023063
(FPCore (a b)
:name "bug366, discussion (missed optimization)"
:precision binary64
:herbie-target
(* (sqrt (+ (fabs a) (fabs b))) (sqrt (- (fabs a) (fabs b))))
(sqrt (- (* a a) (* b b))))