
(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) -5e-292) (sqrt (* (/ x (+ x y)) (- x))) (sqrt (- x y))))
double code(double x, double y) {
double tmp;
if ((x - y) <= -5e-292) {
tmp = sqrt(((x / (x + 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-292)) then
tmp = sqrt(((x / (x + 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-292) {
tmp = Math.sqrt(((x / (x + y)) * -x));
} else {
tmp = Math.sqrt((x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x - y) <= -5e-292: tmp = math.sqrt(((x / (x + y)) * -x)) else: tmp = math.sqrt((x - y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(x - y) <= -5e-292) tmp = sqrt(Float64(Float64(x / Float64(x + y)) * Float64(-x))); else tmp = sqrt(Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x - y) <= -5e-292) tmp = sqrt(((x / (x + y)) * -x)); else tmp = sqrt((x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x - y), $MachinePrecision], -5e-292], N[Sqrt[N[(N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision] * (-x)), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(x - y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - y \leq -5 \cdot 10^{-292}:\\
\;\;\;\;\sqrt{\frac{x}{x + y} \cdot \left(-x\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x - y}\\
\end{array}
\end{array}
if (-.f64 x y) < -4.99999999999999981e-292Initial program 100.0%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.0%
flip--0.2%
sqrt-div0.1%
Applied egg-rr0.1%
+-commutative0.1%
Simplified0.1%
Taylor expanded in x around inf 1.5%
add-sqr-sqrt1.0%
sqrt-unprod2.1%
sqr-neg2.1%
distribute-frac-neg2.1%
distribute-frac-neg2.1%
frac-times2.0%
sqr-neg2.0%
add-sqr-sqrt2.1%
+-commutative2.1%
Applied egg-rr2.1%
associate-/l*2.1%
associate-/r/2.1%
+-commutative2.1%
Simplified2.1%
associate-*l/2.1%
div-inv2.1%
sqr-neg2.1%
inv-pow2.1%
metadata-eval2.1%
pow-prod-up2.0%
swap-sqr2.1%
distribute-lft-neg-out2.1%
metadata-eval2.1%
pow-flip2.1%
pow1/22.1%
div-inv2.1%
distribute-rgt-neg-out2.1%
Applied egg-rr28.6%
associate-*l/52.8%
distribute-rgt-neg-in52.8%
+-commutative52.8%
Simplified52.8%
if -4.99999999999999981e-292 < (-.f64 x y) Initial program 100.0%
expm1-log1p-u93.7%
expm1-udef75.8%
log1p-udef75.8%
add-exp-log82.0%
add-sqr-sqrt82.0%
fabs-sqr82.0%
add-sqr-sqrt82.0%
Applied egg-rr82.0%
+-commutative82.0%
associate--l+100.0%
metadata-eval100.0%
+-rgt-identity100.0%
Simplified100.0%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (<= (- x y) -5e-292) (sqrt (* x (/ x y))) (sqrt (- x y))))
double code(double x, double y) {
double tmp;
if ((x - y) <= -5e-292) {
tmp = sqrt((x * (x / 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) <= (-5d-292)) then
tmp = sqrt((x * (x / 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) <= -5e-292) {
tmp = Math.sqrt((x * (x / y)));
} else {
tmp = Math.sqrt((x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x - y) <= -5e-292: tmp = math.sqrt((x * (x / y))) else: tmp = math.sqrt((x - y)) return tmp
function code(x, y) tmp = 0.0 if (Float64(x - y) <= -5e-292) tmp = sqrt(Float64(x * Float64(x / y))); else tmp = sqrt(Float64(x - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x - y) <= -5e-292) tmp = sqrt((x * (x / y))); else tmp = sqrt((x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x - y), $MachinePrecision], -5e-292], N[Sqrt[N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(x - y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x - y \leq -5 \cdot 10^{-292}:\\
\;\;\;\;\sqrt{x \cdot \frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x - y}\\
\end{array}
\end{array}
if (-.f64 x y) < -4.99999999999999981e-292Initial program 100.0%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.0%
flip--0.2%
sqrt-div0.1%
Applied egg-rr0.1%
+-commutative0.1%
Simplified0.1%
Taylor expanded in x around inf 1.5%
add-sqr-sqrt1.0%
sqrt-unprod2.1%
sqr-neg2.1%
distribute-frac-neg2.1%
distribute-frac-neg2.1%
frac-times2.0%
sqr-neg2.0%
add-sqr-sqrt2.1%
+-commutative2.1%
Applied egg-rr2.1%
associate-/l*2.1%
associate-/r/2.1%
+-commutative2.1%
Simplified2.1%
Taylor expanded in x around 0 3.4%
unpow23.4%
associate-*r/3.6%
Simplified3.6%
if -4.99999999999999981e-292 < (-.f64 x y) Initial program 100.0%
expm1-log1p-u93.7%
expm1-udef75.8%
log1p-udef75.8%
add-exp-log82.0%
add-sqr-sqrt82.0%
fabs-sqr82.0%
add-sqr-sqrt82.0%
Applied egg-rr82.0%
+-commutative82.0%
associate--l+100.0%
metadata-eval100.0%
+-rgt-identity100.0%
Simplified100.0%
Final simplification55.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%
expm1-log1p-u93.7%
expm1-udef77.2%
log1p-udef77.2%
add-exp-log83.5%
add-sqr-sqrt44.2%
fabs-sqr44.2%
add-sqr-sqrt44.2%
Applied egg-rr44.2%
+-commutative44.2%
associate--l+53.9%
metadata-eval53.9%
+-rgt-identity53.9%
Simplified53.9%
Final simplification53.9%
(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%
expm1-log1p-u93.7%
expm1-udef77.2%
log1p-udef77.2%
add-exp-log83.5%
add-sqr-sqrt44.2%
fabs-sqr44.2%
add-sqr-sqrt44.2%
Applied egg-rr44.2%
+-commutative44.2%
associate--l+53.9%
metadata-eval53.9%
+-rgt-identity53.9%
Simplified53.9%
Taylor expanded in y around 0 29.6%
Final simplification29.6%
herbie shell --seed 2023230
(FPCore (x y)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, C"
:precision binary64
(sqrt (fabs (- x y))))