
(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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* (pow 2.0 0.125) (* (pow 8.0 0.125) x)))
x = abs(x);
double code(double x) {
return pow(2.0, 0.125) * (pow(8.0, 0.125) * x);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 ** 0.125d0) * ((8.0d0 ** 0.125d0) * x)
end function
x = Math.abs(x);
public static double code(double x) {
return Math.pow(2.0, 0.125) * (Math.pow(8.0, 0.125) * x);
}
x = abs(x) def code(x): return math.pow(2.0, 0.125) * (math.pow(8.0, 0.125) * x)
x = abs(x) function code(x) return Float64((2.0 ^ 0.125) * Float64((8.0 ^ 0.125) * x)) end
x = abs(x) function tmp = code(x) tmp = (2.0 ^ 0.125) * ((8.0 ^ 0.125) * x); end
NOTE: x should be positive before calling this function code[x_] := N[(N[Power[2.0, 0.125], $MachinePrecision] * N[(N[Power[8.0, 0.125], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
{2}^{0.125} \cdot \left({8}^{0.125} \cdot x\right)
\end{array}
Initial program 54.4%
add-sqr-sqrt54.0%
pow254.0%
associate-*l*54.0%
sqrt-prod54.0%
sqrt-unprod52.0%
add-sqr-sqrt52.2%
Applied egg-rr52.2%
pow1/252.2%
metadata-eval52.2%
metadata-eval52.2%
metadata-eval52.2%
pow-prod-up51.9%
pow-prod-down54.0%
swap-sqr53.9%
add-sqr-sqrt54.0%
metadata-eval54.0%
Applied egg-rr54.0%
*-commutative54.0%
unpow-prod-down53.9%
pow-prod-down52.0%
pow-prod-up52.1%
metadata-eval52.1%
pow1/252.1%
*-commutative52.1%
unpow252.1%
swap-sqr52.1%
add-sqr-sqrt53.4%
associate-*r*53.5%
add-sqr-sqrt53.5%
associate-*l*53.6%
sqrt-pow153.6%
metadata-eval53.6%
sqrt-pow153.6%
metadata-eval53.6%
Applied egg-rr53.6%
Taylor expanded in x around 0 53.7%
Final simplification53.7%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (* (sqrt (* 2.0 x)) (sqrt x)))
x = abs(x);
double code(double x) {
return sqrt((2.0 * x)) * sqrt(x);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 * x)) * sqrt(x)
end function
x = Math.abs(x);
public static double code(double x) {
return Math.sqrt((2.0 * x)) * Math.sqrt(x);
}
x = abs(x) def code(x): return math.sqrt((2.0 * x)) * math.sqrt(x)
x = abs(x) function code(x) return Float64(sqrt(Float64(2.0 * x)) * sqrt(x)) end
x = abs(x) function tmp = code(x) tmp = sqrt((2.0 * x)) * sqrt(x); end
NOTE: x should be positive before calling this function code[x_] := N[(N[Sqrt[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\sqrt{2 \cdot x} \cdot \sqrt{x}
\end{array}
Initial program 54.4%
sqrt-prod52.4%
Applied egg-rr52.4%
Final simplification52.4%
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 54.4%
associate-*l*54.4%
sqrt-prod54.2%
sqrt-unprod52.2%
add-sqr-sqrt53.5%
Applied egg-rr53.5%
Final simplification53.5%
herbie shell --seed 2023292
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))