
(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 2 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 (* (sqrt (* 2.0 (sqrt x_m))) (pow x_m 0.75)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((2.0 * sqrt(x_m))) * pow(x_m, 0.75);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((2.0d0 * sqrt(x_m))) * (x_m ** 0.75d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((2.0 * Math.sqrt(x_m))) * Math.pow(x_m, 0.75);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((2.0 * math.sqrt(x_m))) * math.pow(x_m, 0.75)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(2.0 * sqrt(x_m))) * (x_m ^ 0.75)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((2.0 * sqrt(x_m))) * (x_m ^ 0.75); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(2.0 * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[x$95$m, 0.75], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{2 \cdot \sqrt{x\_m}} \cdot {x\_m}^{0.75}
\end{array}
Initial program 54.2%
add-cbrt-cube37.8%
pow337.8%
pow1/237.8%
associate-*l*37.8%
*-commutative37.8%
unpow-prod-down37.8%
pow1/237.8%
sqrt-unprod18.5%
add-sqr-sqrt20.1%
pow1/220.1%
Applied egg-rr20.1%
rem-cbrt-cube49.4%
*-commutative49.4%
add-sqr-sqrt47.9%
add-sqr-sqrt47.8%
associate-*r*47.8%
sqrt-prod32.8%
pow132.8%
pow1/232.8%
pow-prod-up32.8%
metadata-eval32.8%
associate-*l*32.8%
sqrt-prod32.9%
*-commutative32.9%
sqrt-prod32.8%
associate-*r*32.9%
pow1/232.9%
sqrt-pow232.9%
metadata-eval32.9%
sqrt-pow148.0%
metadata-eval48.0%
Applied egg-rr48.0%
add-log-exp6.9%
*-un-lft-identity6.9%
log-prod6.9%
metadata-eval6.9%
add-log-exp48.0%
add-sqr-sqrt48.0%
sqrt-unprod48.0%
pow1/248.0%
metadata-eval48.0%
pow-pow48.0%
*-commutative48.0%
pow1/248.0%
metadata-eval48.0%
pow-pow48.0%
*-commutative48.0%
swap-sqr47.9%
Applied egg-rr48.1%
+-lft-identity48.1%
Simplified48.1%
Final simplification48.1%
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 54.2%
associate-*l*54.2%
sqrt-prod54.0%
sqrt-unprod47.9%
add-sqr-sqrt49.4%
Applied egg-rr49.4%
Final simplification49.4%
herbie shell --seed 2024047
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))