
(FPCore (x y) :precision binary64 (sqrt (fabs (- x y))))
double code(double x, double y) {
return sqrt(fabs((x - y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(abs((x - y)))
end function
public static double code(double x, double y) {
return Math.sqrt(Math.abs((x - y)));
}
def code(x, y): return math.sqrt(math.fabs((x - y)))
function code(x, y) return sqrt(abs(Float64(x - y))) end
function tmp = code(x, y) tmp = sqrt(abs((x - y))); end
code[x_, y_] := N[Sqrt[N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left|x - y\right|}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (sqrt (fabs (- x y))))
double code(double x, double y) {
return sqrt(fabs((x - y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(abs((x - y)))
end function
public static double code(double x, double y) {
return Math.sqrt(Math.abs((x - y)));
}
def code(x, y): return math.sqrt(math.fabs((x - y)))
function code(x, y) return sqrt(abs(Float64(x - y))) end
function tmp = code(x, y) tmp = sqrt(abs((x - y))); end
code[x_, y_] := N[Sqrt[N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left|x - y\right|}
\end{array}
(FPCore (x y) :precision binary64 (sqrt (fabs (- x y))))
double code(double x, double y) {
return sqrt(fabs((x - y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(abs((x - y)))
end function
public static double code(double x, double y) {
return Math.sqrt(Math.abs((x - y)));
}
def code(x, y): return math.sqrt(math.fabs((x - y)))
function code(x, y) return sqrt(abs(Float64(x - y))) end
function tmp = code(x, y) tmp = sqrt(abs((x - y))); end
code[x_, y_] := N[Sqrt[N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left|x - y\right|}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x 6e-72) (sqrt (- y x)) (sqrt x)))
double code(double x, double y) {
double tmp;
if (x <= 6e-72) {
tmp = sqrt((y - x));
} else {
tmp = sqrt(x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 6d-72) then
tmp = sqrt((y - x))
else
tmp = sqrt(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 6e-72) {
tmp = Math.sqrt((y - x));
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 6e-72: tmp = math.sqrt((y - x)) else: tmp = math.sqrt(x) return tmp
function code(x, y) tmp = 0.0 if (x <= 6e-72) tmp = sqrt(Float64(y - x)); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 6e-72) tmp = sqrt((y - x)); else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 6e-72], N[Sqrt[N[(y - x), $MachinePrecision]], $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6 \cdot 10^{-72}:\\
\;\;\;\;\sqrt{y - x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
\end{array}
if x < 6e-72Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
expm1-log1p-u94.0%
expm1-udef71.0%
log1p-udef71.0%
add-exp-log76.9%
add-sqr-sqrt54.9%
fabs-sqr54.9%
add-sqr-sqrt54.9%
Applied egg-rr54.9%
+-commutative54.9%
associate--l+68.1%
metadata-eval68.1%
+-rgt-identity68.1%
Simplified68.1%
if 6e-72 < x Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
expm1-log1p-u93.6%
expm1-udef80.1%
log1p-udef80.1%
add-exp-log86.6%
add-sqr-sqrt10.3%
fabs-sqr10.3%
add-sqr-sqrt10.3%
Applied egg-rr10.3%
+-commutative10.3%
associate--l+10.3%
metadata-eval10.3%
+-rgt-identity10.3%
Simplified10.3%
pow1/210.3%
metadata-eval10.3%
pow-pow54.9%
Applied egg-rr54.9%
Taylor expanded in y around 0 80.0%
pow-base-180.0%
*-lft-identity80.0%
Simplified80.0%
Final simplification71.2%
(FPCore (x y) :precision binary64 (if (<= y 2.5e-154) (sqrt x) (sqrt y)))
double code(double x, double y) {
double tmp;
if (y <= 2.5e-154) {
tmp = sqrt(x);
} else {
tmp = sqrt(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.5d-154) then
tmp = sqrt(x)
else
tmp = sqrt(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.5e-154) {
tmp = Math.sqrt(x);
} else {
tmp = Math.sqrt(y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.5e-154: tmp = math.sqrt(x) else: tmp = math.sqrt(y) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.5e-154) tmp = sqrt(x); else tmp = sqrt(y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.5e-154) tmp = sqrt(x); else tmp = sqrt(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.5e-154], N[Sqrt[x], $MachinePrecision], N[Sqrt[y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{-154}:\\
\;\;\;\;\sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{y}\\
\end{array}
\end{array}
if y < 2.5000000000000001e-154Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
expm1-log1p-u94.4%
expm1-udef70.5%
log1p-udef70.5%
add-exp-log76.1%
add-sqr-sqrt24.7%
fabs-sqr24.7%
add-sqr-sqrt24.7%
Applied egg-rr24.7%
+-commutative24.7%
associate--l+32.1%
metadata-eval32.1%
+-rgt-identity32.1%
Simplified32.1%
pow1/232.1%
metadata-eval32.1%
pow-pow59.0%
Applied egg-rr59.0%
Taylor expanded in y around 0 32.0%
pow-base-132.0%
*-lft-identity32.0%
Simplified32.0%
if 2.5000000000000001e-154 < y Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
expm1-log1p-u93.0%
expm1-udef79.0%
log1p-udef79.0%
add-exp-log86.0%
add-sqr-sqrt78.1%
fabs-sqr78.1%
add-sqr-sqrt78.1%
Applied egg-rr78.1%
+-commutative78.1%
associate--l+92.0%
metadata-eval92.0%
+-rgt-identity92.0%
Simplified92.0%
Taylor expanded in x around 0 75.8%
Final simplification47.0%
(FPCore (x y) :precision binary64 (sqrt x))
double code(double x, double y) {
return sqrt(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(x)
end function
public static double code(double x, double y) {
return Math.sqrt(x);
}
def code(x, y): return math.sqrt(x)
function code(x, y) return sqrt(x) end
function tmp = code(x, y) tmp = sqrt(x); end
code[x_, y_] := N[Sqrt[x], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x}
\end{array}
Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
expm1-log1p-u93.9%
expm1-udef73.4%
log1p-udef73.4%
add-exp-log79.5%
add-sqr-sqrt43.0%
fabs-sqr43.0%
add-sqr-sqrt43.0%
Applied egg-rr43.0%
+-commutative43.0%
associate--l+52.7%
metadata-eval52.7%
+-rgt-identity52.7%
Simplified52.7%
pow1/252.7%
metadata-eval52.7%
pow-pow54.4%
Applied egg-rr54.4%
Taylor expanded in y around 0 24.5%
pow-base-124.5%
*-lft-identity24.5%
Simplified24.5%
Final simplification24.5%
herbie shell --seed 2023297
(FPCore (x y)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, C"
:precision binary64
(sqrt (fabs (- x y))))