
(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 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(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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* (pow x 0.75) (sqrt (* 2.0 (sqrt x)))))
x = abs(x);
double code(double x) {
return pow(x, 0.75) * sqrt((2.0 * sqrt(x)));
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** 0.75d0) * sqrt((2.0d0 * sqrt(x)))
end function
x = Math.abs(x);
public static double code(double x) {
return Math.pow(x, 0.75) * Math.sqrt((2.0 * Math.sqrt(x)));
}
x = abs(x) def code(x): return math.pow(x, 0.75) * math.sqrt((2.0 * math.sqrt(x)))
x = abs(x) function code(x) return Float64((x ^ 0.75) * sqrt(Float64(2.0 * sqrt(x)))) end
x = abs(x) function tmp = code(x) tmp = (x ^ 0.75) * sqrt((2.0 * sqrt(x))); end
NOTE: x should be positive before calling this function code[x_] := N[(N[Power[x, 0.75], $MachinePrecision] * N[Sqrt[N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
{x}^{0.75} \cdot \sqrt{2 \cdot \sqrt{x}}
\end{array}
Initial program 55.9%
associate-*r*55.9%
sqrt-prod53.6%
Applied egg-rr53.6%
pow1/253.6%
metadata-eval53.6%
pow-prod-up53.4%
pow-prod-up53.6%
metadata-eval53.6%
pow1/253.6%
add-cbrt-cube33.1%
add-sqr-sqrt33.1%
cbrt-prod53.1%
add-cbrt-cube33.0%
cbrt-prod33.1%
pow133.1%
pow1/233.1%
pow-prod-up33.0%
metadata-eval33.0%
cbrt-unprod18.1%
Applied egg-rr18.1%
*-commutative18.1%
Simplified18.1%
add-sqr-sqrt18.0%
sqrt-unprod18.1%
cbrt-unprod9.9%
swap-sqr9.9%
pow-prod-up9.9%
metadata-eval9.9%
pow39.9%
pow-prod-up22.0%
metadata-eval22.0%
pow322.0%
cbrt-unprod37.6%
add-cbrt-cube37.7%
add-cbrt-cube55.9%
*-commutative55.9%
associate-*l*55.9%
Applied egg-rr53.6%
Final simplification53.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* (sqrt x) (sqrt (* x 2.0))))
x = abs(x);
double code(double x) {
return sqrt(x) * sqrt((x * 2.0));
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(x) * sqrt((x * 2.0d0))
end function
x = Math.abs(x);
public static double code(double x) {
return Math.sqrt(x) * Math.sqrt((x * 2.0));
}
x = abs(x) def code(x): return math.sqrt(x) * math.sqrt((x * 2.0))
x = abs(x) function code(x) return Float64(sqrt(x) * sqrt(Float64(x * 2.0))) end
x = abs(x) function tmp = code(x) tmp = sqrt(x) * sqrt((x * 2.0)); end
NOTE: x should be positive before calling this function code[x_] := N[(N[Sqrt[x], $MachinePrecision] * N[Sqrt[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\sqrt{x} \cdot \sqrt{x \cdot 2}
\end{array}
Initial program 55.9%
associate-*r*55.9%
sqrt-prod53.6%
Applied egg-rr53.6%
Final simplification53.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* x (sqrt 2.0)))
x = abs(x);
double code(double x) {
return x * sqrt(2.0);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = x * sqrt(2.0d0)
end function
x = Math.abs(x);
public static double code(double x) {
return x * Math.sqrt(2.0);
}
x = abs(x) def code(x): return x * math.sqrt(2.0)
x = abs(x) function code(x) return Float64(x * sqrt(2.0)) end
x = abs(x) function tmp = code(x) tmp = x * sqrt(2.0); end
NOTE: x should be positive before calling this function code[x_] := N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x \cdot \sqrt{2}
\end{array}
Initial program 55.9%
sqrt-prod55.6%
sqrt-prod53.4%
add-sqr-sqrt54.5%
Applied egg-rr54.5%
Final simplification54.5%
herbie shell --seed 2023310
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2.0 (* x x))))