
(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 3 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 (* x_m 4.0) 0.25) (pow x_m 0.75)))
x_m = fabs(x);
double code(double x_m) {
return pow((x_m * 4.0), 0.25) * pow(x_m, 0.75);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((x_m * 4.0d0) ** 0.25d0) * (x_m ** 0.75d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow((x_m * 4.0), 0.25) * Math.pow(x_m, 0.75);
}
x_m = math.fabs(x) def code(x_m): return math.pow((x_m * 4.0), 0.25) * math.pow(x_m, 0.75)
x_m = abs(x) function code(x_m) return Float64((Float64(x_m * 4.0) ^ 0.25) * (x_m ^ 0.75)) end
x_m = abs(x); function tmp = code(x_m) tmp = ((x_m * 4.0) ^ 0.25) * (x_m ^ 0.75); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[N[(x$95$m * 4.0), $MachinePrecision], 0.25], $MachinePrecision] * N[Power[x$95$m, 0.75], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(x_m \cdot 4\right)}^{0.25} \cdot {x_m}^{0.75}
\end{array}
Initial program 52.2%
add-sqr-sqrt51.9%
pow251.9%
*-commutative51.9%
*-commutative51.9%
associate-*r*51.9%
sqrt-prod51.8%
sqrt-unprod47.0%
add-sqr-sqrt47.1%
Applied egg-rr47.1%
sqrt-unprod47.2%
pow1/247.2%
sqrt-pow147.2%
metadata-eval47.2%
*-commutative47.2%
Applied egg-rr47.2%
unpow247.2%
swap-sqr47.1%
pow-prod-up47.1%
metadata-eval47.1%
pow1/247.1%
add-sqr-sqrt48.4%
*-commutative48.4%
pow148.4%
metadata-eval48.4%
pow-prod-up47.2%
associate-*r*47.2%
*-commutative47.2%
associate-*r*47.2%
pow1/247.2%
metadata-eval47.2%
pow-prod-up47.2%
pow-prod-down47.2%
metadata-eval47.2%
metadata-eval47.2%
pow-prod-down47.4%
metadata-eval47.4%
Applied egg-rr47.4%
Final simplification47.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt (* x_m 2.0)) (sqrt x_m)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((x_m * 2.0)) * sqrt(x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((x_m * 2.0d0)) * sqrt(x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((x_m * 2.0)) * Math.sqrt(x_m);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((x_m * 2.0)) * math.sqrt(x_m)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(x_m * 2.0)) * sqrt(x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((x_m * 2.0)) * sqrt(x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{x_m \cdot 2} \cdot \sqrt{x_m}
\end{array}
Initial program 52.2%
sqrt-prod47.4%
Applied egg-rr47.4%
*-commutative47.4%
Simplified47.4%
Final simplification47.4%
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 52.2%
associate-*l*52.2%
sqrt-prod51.9%
sqrt-unprod47.1%
add-sqr-sqrt48.4%
Applied egg-rr48.4%
Final simplification48.4%
herbie shell --seed 2024011
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))