
(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 6 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-243) (sqrt y) (sqrt (- x y))))
double code(double x, double y) {
double tmp;
if ((x - y) <= -2e-243) {
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-243)) 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-243) {
tmp = Math.sqrt(y);
} else {
tmp = Math.sqrt((x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x - y) <= -2e-243: tmp = math.sqrt(y) else: tmp = math.sqrt((x - y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(x - y) <= -2e-243) 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-243) tmp = sqrt(y); else tmp = sqrt((x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x - y), $MachinePrecision], -2e-243], 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^{-243}:\\
\;\;\;\;\sqrt{y}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x - y}\\
\end{array}
\end{array}
if (-.f64 x y) < -1.99999999999999999e-243Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
unsub-neg100.0%
fabs-sub100.0%
rem-square-sqrt100.0%
fabs-sqr100.0%
rem-sqrt-square100.0%
unpow1100.0%
sqr-pow99.4%
fabs-sqr99.4%
sqr-pow100.0%
unpow1100.0%
Simplified100.0%
Taylor expanded in x around 0 41.1%
if -1.99999999999999999e-243 < (-.f64 x y) Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
pow1/2100.0%
add-cube-cbrt98.8%
fabs-mul98.8%
unpow-prod-down98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 0.6%
unpow1/30.6%
sub-neg0.6%
mul-1-neg0.6%
mul-1-neg0.6%
sub-neg0.6%
unpow1/398.7%
Simplified98.7%
rem-cube-cbrt98.3%
sqr-pow0.7%
fabs-sqr0.7%
unpow20.7%
fabs-sqr0.7%
pow-prod-down98.3%
add-cube-cbrt97.7%
add-cube-cbrt97.3%
swap-sqr97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 99.3%
mul-1-neg99.3%
unsub-neg99.3%
Simplified99.3%
Final simplification72.9%
(FPCore (x y) :precision binary64 (if (<= (- x y) -5e-251) (sqrt (- y x)) (sqrt (- x y))))
double code(double x, double y) {
double tmp;
if ((x - y) <= -5e-251) {
tmp = sqrt((y - x));
} 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) <= (-5d-251)) then
tmp = sqrt((y - x))
else
tmp = sqrt((x - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x - y) <= -5e-251) {
tmp = Math.sqrt((y - x));
} else {
tmp = Math.sqrt((x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x - y) <= -5e-251: tmp = math.sqrt((y - x)) else: tmp = math.sqrt((x - y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(x - y) <= -5e-251) tmp = sqrt(Float64(y - x)); else tmp = sqrt(Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x - y) <= -5e-251) tmp = sqrt((y - x)); else tmp = sqrt((x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x - y), $MachinePrecision], -5e-251], N[Sqrt[N[(y - x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(x - y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - y \leq -5 \cdot 10^{-251}:\\
\;\;\;\;\sqrt{y - x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x - y}\\
\end{array}
\end{array}
if (-.f64 x y) < -5.0000000000000003e-251Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
unsub-neg100.0%
fabs-sub100.0%
rem-square-sqrt100.0%
fabs-sqr100.0%
rem-sqrt-square100.0%
unpow1100.0%
sqr-pow99.4%
fabs-sqr99.4%
sqr-pow100.0%
unpow1100.0%
Simplified100.0%
if -5.0000000000000003e-251 < (-.f64 x y) Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
pow1/2100.0%
add-cube-cbrt98.8%
fabs-mul98.8%
unpow-prod-down98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 0.0%
unpow1/30.0%
sub-neg0.0%
mul-1-neg0.0%
mul-1-neg0.0%
sub-neg0.0%
unpow1/398.8%
Simplified98.8%
rem-cube-cbrt98.3%
sqr-pow0.0%
fabs-sqr0.0%
unpow20.0%
fabs-sqr0.0%
pow-prod-down98.3%
add-cube-cbrt97.7%
add-cube-cbrt97.3%
swap-sqr97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.25e-45) (sqrt (- y)) (if (<= y 1.7e+97) (sqrt x) (sqrt y))))
double code(double x, double y) {
double tmp;
if (y <= -2.25e-45) {
tmp = sqrt(-y);
} else if (y <= 1.7e+97) {
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.25d-45)) then
tmp = sqrt(-y)
else if (y <= 1.7d+97) 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.25e-45) {
tmp = Math.sqrt(-y);
} else if (y <= 1.7e+97) {
tmp = Math.sqrt(x);
} else {
tmp = Math.sqrt(y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.25e-45: tmp = math.sqrt(-y) elif y <= 1.7e+97: tmp = math.sqrt(x) else: tmp = math.sqrt(y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.25e-45) tmp = sqrt(Float64(-y)); elseif (y <= 1.7e+97) tmp = sqrt(x); else tmp = sqrt(y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.25e-45) tmp = sqrt(-y); elseif (y <= 1.7e+97) tmp = sqrt(x); else tmp = sqrt(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.25e-45], N[Sqrt[(-y)], $MachinePrecision], If[LessEqual[y, 1.7e+97], N[Sqrt[x], $MachinePrecision], N[Sqrt[y], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{-45}:\\
\;\;\;\;\sqrt{-y}\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+97}:\\
\;\;\;\;\sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{y}\\
\end{array}
\end{array}
if y < -2.2499999999999999e-45Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
pow1/2100.0%
add-cube-cbrt98.8%
fabs-mul98.8%
unpow-prod-down98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 18.6%
unpow1/318.8%
sub-neg18.8%
mul-1-neg18.8%
mul-1-neg18.8%
sub-neg18.8%
unpow1/398.8%
Simplified98.8%
rem-cube-cbrt98.5%
sqr-pow20.3%
fabs-sqr20.3%
unpow220.3%
fabs-sqr20.3%
pow-prod-down98.5%
add-cube-cbrt97.8%
add-cube-cbrt97.3%
swap-sqr97.2%
Applied egg-rr97.3%
Taylor expanded in y around -inf 66.9%
mul-1-neg66.9%
Simplified66.9%
if -2.2499999999999999e-45 < y < 1.70000000000000005e97Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
pow1/2100.0%
add-cube-cbrt98.7%
fabs-mul98.7%
unpow-prod-down98.7%
pow298.7%
Applied egg-rr98.7%
Taylor expanded in y around 0 42.1%
unpow1/342.4%
sub-neg42.4%
mul-1-neg42.4%
mul-1-neg42.4%
sub-neg42.4%
unpow1/398.7%
Simplified98.7%
rem-cube-cbrt98.3%
sqr-pow45.1%
fabs-sqr45.1%
unpow245.1%
fabs-sqr45.1%
pow-prod-down98.2%
add-cube-cbrt97.7%
add-cube-cbrt97.3%
swap-sqr97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 48.4%
if 1.70000000000000005e97 < y Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
unsub-neg100.0%
fabs-sub100.0%
rem-square-sqrt90.2%
fabs-sqr90.2%
rem-sqrt-square90.2%
unpow190.2%
sqr-pow89.7%
fabs-sqr89.7%
sqr-pow90.2%
unpow190.2%
Simplified90.2%
Taylor expanded in x around 0 73.7%
Final simplification57.7%
(FPCore (x y) :precision binary64 (if (<= x 2.55e-248) (sqrt y) (sqrt x)))
double code(double x, double y) {
double tmp;
if (x <= 2.55e-248) {
tmp = sqrt(y);
} 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 <= 2.55d-248) then
tmp = sqrt(y)
else
tmp = sqrt(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.55e-248) {
tmp = Math.sqrt(y);
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.55e-248: tmp = math.sqrt(y) else: tmp = math.sqrt(x) return tmp
function code(x, y) tmp = 0.0 if (x <= 2.55e-248) tmp = sqrt(y); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.55e-248) tmp = sqrt(y); else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.55e-248], N[Sqrt[y], $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.55 \cdot 10^{-248}:\\
\;\;\;\;\sqrt{y}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
\end{array}
if x < 2.54999999999999986e-248Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
unsub-neg100.0%
fabs-sub100.0%
rem-square-sqrt77.7%
fabs-sqr77.7%
rem-sqrt-square77.7%
unpow177.7%
sqr-pow77.2%
fabs-sqr77.2%
sqr-pow77.7%
unpow177.7%
Simplified77.7%
Taylor expanded in x around 0 24.7%
if 2.54999999999999986e-248 < x Initial program 100.0%
fabs-sub100.0%
Simplified100.0%
pow1/2100.0%
add-cube-cbrt98.8%
fabs-mul98.8%
unpow-prod-down98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 11.5%
unpow1/311.6%
sub-neg11.6%
mul-1-neg11.6%
mul-1-neg11.6%
sub-neg11.6%
unpow1/398.8%
Simplified98.8%
rem-cube-cbrt98.4%
sqr-pow12.5%
fabs-sqr12.5%
unpow212.5%
fabs-sqr12.5%
pow-prod-down98.3%
add-cube-cbrt97.8%
add-cube-cbrt97.3%
swap-sqr97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 66.6%
Final simplification45.3%
(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%
pow1/2100.0%
add-cube-cbrt98.7%
fabs-mul98.7%
unpow-prod-down98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in y around 0 41.7%
unpow1/342.1%
sub-neg42.1%
mul-1-neg42.1%
mul-1-neg42.1%
sub-neg42.1%
unpow1/398.7%
Simplified98.7%
rem-cube-cbrt98.4%
sqr-pow45.0%
fabs-sqr45.0%
unpow245.0%
fabs-sqr45.0%
pow-prod-down98.3%
add-cube-cbrt97.8%
add-cube-cbrt97.3%
swap-sqr97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 33.0%
Final simplification33.0%
herbie shell --seed 2023318
(FPCore (x y)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, C"
:precision binary64
(sqrt (fabs (- x y))))