
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((2.0d0 * x) * x))
end function
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
def code(x): return math.sqrt(((2.0 * x) * x))
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot x\right) \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((2.0d0 * x) * x))
end function
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
def code(x): return math.sqrt(((2.0 * x) * x))
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(2 \cdot x\right) \cdot x}
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow 2.0 0.375) (* x_m (pow 2.0 0.125))))
x_m = fabs(x);
double code(double x_m) {
return pow(2.0, 0.375) * (x_m * pow(2.0, 0.125));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (2.0d0 ** 0.375d0) * (x_m * (2.0d0 ** 0.125d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(2.0, 0.375) * (x_m * Math.pow(2.0, 0.125));
}
x_m = math.fabs(x) def code(x_m): return math.pow(2.0, 0.375) * (x_m * math.pow(2.0, 0.125))
x_m = abs(x) function code(x_m) return Float64((2.0 ^ 0.375) * Float64(x_m * (2.0 ^ 0.125))) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.0 ^ 0.375) * (x_m * (2.0 ^ 0.125)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[2.0, 0.375], $MachinePrecision] * N[(x$95$m * N[Power[2.0, 0.125], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{2}^{0.375} \cdot \left(x_m \cdot {2}^{0.125}\right)
\end{array}
Initial program 51.8%
add-sqr-sqrt51.5%
pow251.5%
*-commutative51.5%
*-commutative51.5%
associate-*r*51.4%
sqrt-prod51.3%
sqrt-unprod51.0%
add-sqr-sqrt51.1%
Applied egg-rr51.1%
sqrt-unprod51.0%
pow1/251.0%
sqrt-pow151.0%
metadata-eval51.0%
*-commutative51.0%
Applied egg-rr51.0%
unpow251.0%
swap-sqr51.0%
add-sqr-sqrt52.3%
associate-*r*52.3%
metadata-eval52.3%
pow-prod-up52.3%
associate-*r*52.4%
*-commutative52.4%
associate-*r*52.5%
associate-*l*52.5%
pow-prod-up52.5%
metadata-eval52.5%
Applied egg-rr52.5%
Final simplification52.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow 2.0 0.125) (* x_m (pow 8.0 0.125))))
x_m = fabs(x);
double code(double x_m) {
return pow(2.0, 0.125) * (x_m * pow(8.0, 0.125));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (2.0d0 ** 0.125d0) * (x_m * (8.0d0 ** 0.125d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(2.0, 0.125) * (x_m * Math.pow(8.0, 0.125));
}
x_m = math.fabs(x) def code(x_m): return math.pow(2.0, 0.125) * (x_m * math.pow(8.0, 0.125))
x_m = abs(x) function code(x_m) return Float64((2.0 ^ 0.125) * Float64(x_m * (8.0 ^ 0.125))) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.0 ^ 0.125) * (x_m * (8.0 ^ 0.125)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[2.0, 0.125], $MachinePrecision] * N[(x$95$m * N[Power[8.0, 0.125], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{2}^{0.125} \cdot \left(x_m \cdot {8}^{0.125}\right)
\end{array}
Initial program 51.8%
pow1/251.8%
sqr-pow51.5%
pow-prod-down28.2%
pow228.2%
*-commutative28.2%
*-commutative28.2%
associate-*r*28.2%
unpow-prod-down28.2%
pow-prod-down28.2%
pow-prod-up28.2%
metadata-eval28.2%
metadata-eval28.2%
metadata-eval28.2%
Applied egg-rr28.2%
*-commutative28.2%
unpow-prod-down28.1%
metadata-eval28.1%
pow-prod-down28.0%
pow-pow52.3%
metadata-eval52.3%
pow152.3%
associate-*r*52.3%
add-sqr-sqrt52.3%
associate-*l*52.4%
sqrt-pow152.4%
metadata-eval52.4%
sqrt-pow152.4%
metadata-eval52.4%
Applied egg-rr52.4%
Taylor expanded in x around 0 52.5%
Final simplification52.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt (* 2.0 x_m)) (sqrt x_m)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((2.0 * x_m)) * sqrt(x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((2.0d0 * x_m)) * sqrt(x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((2.0 * x_m)) * Math.sqrt(x_m);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((2.0 * x_m)) * math.sqrt(x_m)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(2.0 * x_m)) * sqrt(x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((2.0 * x_m)) * sqrt(x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{2 \cdot x_m} \cdot \sqrt{x_m}
\end{array}
Initial program 51.8%
sqrt-prod51.3%
Applied egg-rr51.3%
*-commutative51.3%
Simplified51.3%
Final simplification51.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m (sqrt 2.0)))
x_m = fabs(x);
double code(double x_m) {
return x_m * sqrt(2.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * sqrt(2.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * Math.sqrt(2.0);
}
x_m = math.fabs(x) def code(x_m): return x_m * math.sqrt(2.0)
x_m = abs(x) function code(x_m) return Float64(x_m * sqrt(2.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * sqrt(2.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_m \cdot \sqrt{2}
\end{array}
Initial program 51.8%
associate-*l*51.7%
sqrt-prod51.5%
sqrt-unprod51.1%
add-sqr-sqrt52.4%
Applied egg-rr52.4%
Final simplification52.4%
herbie shell --seed 2024014
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))