
(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 2.0 0.125) (* (pow 8.0 0.125) x_m)))
x_m = fabs(x);
double code(double x_m) {
return pow(2.0, 0.125) * (pow(8.0, 0.125) * x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (2.0d0 ** 0.125d0) * ((8.0d0 ** 0.125d0) * x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(2.0, 0.125) * (Math.pow(8.0, 0.125) * x_m);
}
x_m = math.fabs(x) def code(x_m): return math.pow(2.0, 0.125) * (math.pow(8.0, 0.125) * x_m)
x_m = abs(x) function code(x_m) return Float64((2.0 ^ 0.125) * Float64((8.0 ^ 0.125) * x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.0 ^ 0.125) * ((8.0 ^ 0.125) * x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[2.0, 0.125], $MachinePrecision] * N[(N[Power[8.0, 0.125], $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{2}^{0.125} \cdot \left({8}^{0.125} \cdot x_m\right)
\end{array}
Initial program 50.3%
pow1/250.3%
sqr-pow50.1%
pow-prod-down29.9%
pow229.9%
*-commutative29.9%
*-commutative29.9%
associate-*r*29.9%
unpow-prod-down29.9%
pow-prod-down29.9%
pow-prod-up29.9%
metadata-eval29.9%
metadata-eval29.9%
metadata-eval29.9%
Applied egg-rr29.9%
*-commutative29.9%
unpow-prod-down29.8%
metadata-eval29.8%
pow-prod-down29.7%
pow-pow48.5%
metadata-eval48.5%
pow148.5%
associate-*r*48.5%
add-sqr-sqrt48.5%
associate-*l*48.6%
sqrt-pow148.6%
metadata-eval48.6%
sqrt-pow148.6%
metadata-eval48.6%
Applied egg-rr48.6%
Taylor expanded in x around 0 48.7%
Final simplification48.7%
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 50.3%
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 50.3%
associate-*l*50.3%
sqrt-prod50.1%
sqrt-unprod47.2%
add-sqr-sqrt48.6%
Applied egg-rr48.6%
Final simplification48.6%
herbie shell --seed 2023318
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))