
(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}
(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 56.1%
add-cube-cbrt55.1%
cbrt-prod55.5%
add-sqr-sqrt55.4%
*-commutative55.4%
pow1/352.9%
pow1/252.9%
pow-pow52.9%
*-commutative52.9%
metadata-eval52.9%
*-commutative52.9%
Applied egg-rr52.9%
unpow1/351.7%
metadata-eval51.7%
pow-sqr51.6%
cube-mult51.6%
exp-to-pow51.8%
metadata-eval51.8%
associate-*l*51.8%
*-commutative51.8%
exp-prod52.1%
unpow1/352.2%
rem-cube-cbrt52.3%
*-commutative52.3%
exp-to-pow56.1%
unpow1/256.1%
*-commutative56.1%
associate-*l*56.1%
count-256.1%
hypot-define100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (+ x x))
double code(double x) {
return x + x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + x
end function
public static double code(double x) {
return x + x;
}
def code(x): return x + x
function code(x) return Float64(x + x) end
function tmp = code(x) tmp = x + x; end
code[x_] := N[(x + x), $MachinePrecision]
\begin{array}{l}
\\
x + x
\end{array}
Initial program 56.1%
Taylor expanded in x around 0 51.1%
*-commutative51.1%
add-sqr-sqrt49.9%
associate-*r*49.8%
sqrt-prod50.1%
count-250.1%
add-log-exp3.2%
*-commutative3.2%
exp-prod3.2%
flip-+1.2%
difference-of-squares1.2%
associate-*r/1.2%
+-inverses1.2%
+-inverses1.2%
flip-+3.5%
sqrt-unprod2.7%
add-sqr-sqrt2.7%
flip-+1.2%
div-inv1.2%
+-inverses1.2%
+-inverses1.2%
Applied egg-rr11.3%
herbie shell --seed 2024097
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))