
(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 5 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 y) -2e-271) (sqrt y) (sqrt (- x y))))
double code(double x, double y) {
double tmp;
if ((x - y) <= -2e-271) {
tmp = sqrt(y);
} else {
tmp = sqrt((x - y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x - y) <= (-2d-271)) then
tmp = sqrt(y)
else
tmp = sqrt((x - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x - y) <= -2e-271) {
tmp = Math.sqrt(y);
} else {
tmp = Math.sqrt((x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x - y) <= -2e-271: tmp = math.sqrt(y) else: tmp = math.sqrt((x - y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(x - y) <= -2e-271) tmp = sqrt(y); else tmp = sqrt(Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x - y) <= -2e-271) tmp = sqrt(y); else tmp = sqrt((x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x - y), $MachinePrecision], -2e-271], N[Sqrt[y], $MachinePrecision], N[Sqrt[N[(x - y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - y \leq -2 \cdot 10^{-271}:\\
\;\;\;\;\sqrt{y}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x - y}\\
\end{array}
\end{array}
if (-.f64 x y) < -1.99999999999999993e-271Initial program 100.0%
add-cbrt-cube76.3%
pow1/371.2%
add-sqr-sqrt71.2%
pow171.2%
pow1/271.2%
pow-prod-up71.2%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.0%
metadata-eval0.0%
Applied egg-rr0.0%
unpow1/30.0%
Simplified0.0%
pow1/30.0%
pow-pow0.0%
metadata-eval0.0%
pow1/20.0%
flip3--0.1%
sqrt-div0.1%
distribute-rgt-in0.1%
+-commutative0.1%
fma-udef0.1%
clear-num0.1%
clear-num0.1%
fma-udef0.1%
+-commutative0.1%
distribute-rgt-in0.1%
Applied egg-rr0.0%
add-log-exp0.0%
remove-double-div0.0%
*-un-lft-identity0.0%
log-prod0.0%
metadata-eval0.0%
add-log-exp0.0%
sub-neg0.0%
add-sqr-sqrt0.0%
sqrt-unprod25.4%
sqr-neg25.4%
sqrt-unprod46.9%
add-sqr-sqrt46.9%
Applied egg-rr46.9%
+-lft-identity46.9%
+-commutative46.9%
Simplified46.9%
Taylor expanded in x around 0 48.4%
if -1.99999999999999993e-271 < (-.f64 x y) Initial program 100.0%
expm1-log1p-u94.8%
expm1-udef66.3%
log1p-udef66.3%
add-exp-log71.4%
add-sqr-sqrt71.4%
fabs-sqr71.4%
add-sqr-sqrt71.4%
Applied egg-rr71.4%
+-commutative71.4%
associate--l+99.2%
metadata-eval99.2%
+-rgt-identity99.2%
Simplified99.2%
Final simplification75.6%
(FPCore (x y) :precision binary64 (if (<= y 2.2e-167) (sqrt x) (sqrt y)))
double code(double x, double y) {
double tmp;
if (y <= 2.2e-167) {
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.2d-167) 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.2e-167) {
tmp = Math.sqrt(x);
} else {
tmp = Math.sqrt(y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.2e-167: tmp = math.sqrt(x) else: tmp = math.sqrt(y) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.2e-167) tmp = sqrt(x); else tmp = sqrt(y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.2e-167) tmp = sqrt(x); else tmp = sqrt(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.2e-167], N[Sqrt[x], $MachinePrecision], N[Sqrt[y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{-167}:\\
\;\;\;\;\sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{y}\\
\end{array}
\end{array}
if y < 2.2e-167Initial program 100.0%
add-cbrt-cube72.2%
pow1/367.5%
add-sqr-sqrt67.5%
pow167.5%
pow1/267.5%
pow-prod-up67.5%
add-sqr-sqrt45.2%
fabs-sqr45.2%
add-sqr-sqrt45.2%
metadata-eval45.2%
Applied egg-rr45.2%
unpow1/348.3%
Simplified48.3%
Taylor expanded in y around 0 30.5%
if 2.2e-167 < y Initial program 100.0%
add-cbrt-cube70.0%
pow1/365.1%
add-sqr-sqrt65.1%
pow165.1%
pow1/265.1%
pow-prod-up65.1%
add-sqr-sqrt7.3%
fabs-sqr7.3%
add-sqr-sqrt7.3%
metadata-eval7.3%
Applied egg-rr7.3%
unpow1/37.9%
Simplified7.9%
pow1/37.3%
pow-pow14.1%
metadata-eval14.1%
pow1/214.1%
flip3--4.1%
sqrt-div4.0%
distribute-rgt-in4.0%
+-commutative4.0%
fma-udef4.0%
clear-num4.1%
clear-num4.0%
fma-udef4.0%
+-commutative4.0%
distribute-rgt-in4.0%
Applied egg-rr14.1%
add-log-exp0.6%
remove-double-div0.6%
*-un-lft-identity0.6%
log-prod0.6%
metadata-eval0.6%
add-log-exp14.1%
sub-neg14.1%
add-sqr-sqrt0.0%
sqrt-unprod51.1%
sqr-neg51.1%
sqrt-unprod81.9%
add-sqr-sqrt81.9%
Applied egg-rr81.9%
+-lft-identity81.9%
+-commutative81.9%
Simplified81.9%
Taylor expanded in x around 0 70.0%
Final simplification42.5%
(FPCore (x y) :precision binary64 (sqrt (+ x y)))
double code(double x, double y) {
return sqrt((x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt((x + y))
end function
public static double code(double x, double y) {
return Math.sqrt((x + y));
}
def code(x, y): return math.sqrt((x + y))
function code(x, y) return sqrt(Float64(x + y)) end
function tmp = code(x, y) tmp = sqrt((x + y)); end
code[x_, y_] := N[Sqrt[N[(x + y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + y}
\end{array}
Initial program 100.0%
add-cbrt-cube71.5%
pow1/366.8%
add-sqr-sqrt66.8%
pow166.8%
pow1/266.8%
pow-prod-up66.8%
add-sqr-sqrt33.7%
fabs-sqr33.7%
add-sqr-sqrt33.7%
metadata-eval33.7%
Applied egg-rr33.7%
unpow1/336.0%
Simplified36.0%
pow1/333.7%
pow-pow53.1%
metadata-eval53.1%
pow1/253.1%
flip3--21.4%
sqrt-div21.3%
distribute-rgt-in21.3%
+-commutative21.3%
fma-udef21.3%
clear-num21.3%
clear-num21.3%
fma-udef21.3%
+-commutative21.3%
distribute-rgt-in21.3%
Applied egg-rr53.0%
add-log-exp4.8%
remove-double-div4.8%
*-un-lft-identity4.8%
log-prod4.8%
metadata-eval4.8%
add-log-exp53.1%
sub-neg53.1%
add-sqr-sqrt42.6%
sqrt-unprod53.9%
sqr-neg53.9%
sqrt-unprod32.2%
add-sqr-sqrt46.2%
Applied egg-rr46.2%
+-lft-identity46.2%
+-commutative46.2%
Simplified46.2%
Final simplification46.2%
(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%
add-cbrt-cube71.5%
pow1/366.8%
add-sqr-sqrt66.8%
pow166.8%
pow1/266.8%
pow-prod-up66.8%
add-sqr-sqrt33.7%
fabs-sqr33.7%
add-sqr-sqrt33.7%
metadata-eval33.7%
Applied egg-rr33.7%
unpow1/336.0%
Simplified36.0%
Taylor expanded in y around 0 26.2%
Final simplification26.2%
herbie shell --seed 2023199
(FPCore (x y)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, C"
:precision binary64
(sqrt (fabs (- x y))))