
(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(2.0 * Float64(x * x))) end
function tmp = code(x) tmp = sqrt((2.0 * (x * x))); end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(x \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 1 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(2.0 * Float64(x * x))) end
function tmp = code(x) tmp = sqrt((2.0 * (x * x))); end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(x \cdot x\right)}
\end{array}
(FPCore (x) :precision binary64 (hypot x x))
double code(double x) {
return hypot(x, x);
}
public static double code(double x) {
return Math.hypot(x, x);
}
def code(x): return math.hypot(x, x)
function code(x) return hypot(x, x) end
function tmp = code(x) tmp = hypot(x, x); end
code[x_] := N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(x, x\right)
\end{array}
Initial program 59.8%
add-sqr-sqrt59.5%
pow259.5%
*-commutative59.5%
sqrt-prod59.4%
sqrt-prod56.7%
add-sqr-sqrt56.8%
Applied egg-rr56.8%
pow1/256.8%
metadata-eval56.8%
metadata-eval56.8%
metadata-eval56.8%
pow-prod-up56.5%
pow-prod-down59.4%
*-commutative59.4%
*-commutative59.4%
swap-sqr59.3%
add-sqr-sqrt59.5%
metadata-eval59.5%
Applied egg-rr59.5%
Taylor expanded in x around 0 52.2%
unpow252.2%
*-commutative52.2%
exp-prod31.1%
*-commutative31.1%
exp-prod31.1%
pow-sqr31.1%
metadata-eval31.1%
distribute-lft-neg-in31.1%
distribute-rgt-neg-out31.1%
log-rec31.1%
Simplified100.0%
Final simplification100.0%
herbie shell --seed 2023182
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2.0 (* x x))))