
(FPCore (x) :precision binary64 (sqrt (* 2.0 (pow x 2.0))))
double code(double x) {
return sqrt((2.0 * pow(x, 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((2.0 * Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((2.0 * math.pow(x, 2.0)))
function code(x) return sqrt(Float64(2.0 * (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt((2.0 * (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(2.0 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot {x}^{2}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (* 2.0 (pow x 2.0))))
double code(double x) {
return sqrt((2.0 * pow(x, 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((2.0 * Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((2.0 * math.pow(x, 2.0)))
function code(x) return sqrt(Float64(2.0 * (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt((2.0 * (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(2.0 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot {x}^{2}}
\end{array}
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 56.7%
unpow256.7%
sqr-neg56.7%
unpow256.7%
unpow256.7%
sqr-neg56.7%
Simplified56.7%
associate-*r*56.7%
sqrt-prod47.0%
Applied egg-rr47.0%
Final simplification47.0%
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 56.7%
unpow256.7%
sqr-neg56.7%
unpow256.7%
unpow256.7%
sqr-neg56.7%
Simplified56.7%
sqrt-prod56.5%
sqrt-prod46.8%
add-sqr-sqrt48.1%
Applied egg-rr48.1%
Final simplification48.1%
herbie shell --seed 2023278
(FPCore (x)
:name "sqrt D (should all be same)"
:precision binary64
(sqrt (* 2.0 (pow x 2.0))))