
(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 3 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}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow 2.0 0.125) (* (pow 8.0 0.125) x_m)))
x_m = fabs(x);
double code(double x_m) {
return pow(2.0, 0.125) * (pow(8.0, 0.125) * x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (2.0d0 ** 0.125d0) * ((8.0d0 ** 0.125d0) * x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(2.0, 0.125) * (Math.pow(8.0, 0.125) * x_m);
}
x_m = math.fabs(x) def code(x_m): return math.pow(2.0, 0.125) * (math.pow(8.0, 0.125) * x_m)
x_m = abs(x) function code(x_m) return Float64((2.0 ^ 0.125) * Float64((8.0 ^ 0.125) * x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.0 ^ 0.125) * ((8.0 ^ 0.125) * x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[2.0, 0.125], $MachinePrecision] * N[(N[Power[8.0, 0.125], $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{2}^{0.125} \cdot \left({8}^{0.125} \cdot x\_m\right)
\end{array}
Initial program 56.5%
expm1-log1p-u54.5%
expm1-udef32.5%
log1p-udef32.5%
rem-exp-log34.5%
*-commutative34.5%
sqrt-prod34.3%
unpow234.3%
sqrt-prod27.3%
add-sqr-sqrt28.8%
Applied egg-rr28.8%
add-exp-log26.5%
log1p-udef26.5%
expm1-udef50.8%
expm1-log1p-u53.0%
*-commutative53.0%
pow1/253.0%
metadata-eval53.0%
pow-prod-up52.9%
associate-*r*53.0%
add-sqr-sqrt53.0%
associate-*l*53.1%
sqrt-pow153.1%
metadata-eval53.1%
sqrt-pow153.1%
metadata-eval53.1%
Applied egg-rr53.1%
Taylor expanded in x around 0 53.1%
Final simplification53.1%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt (* 2.0 x_m)) (sqrt x_m)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((2.0 * x_m)) * sqrt(x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((2.0d0 * x_m)) * sqrt(x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((2.0 * x_m)) * Math.sqrt(x_m);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((2.0 * x_m)) * math.sqrt(x_m)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(2.0 * x_m)) * sqrt(x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((2.0 * x_m)) * sqrt(x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{2 \cdot x\_m} \cdot \sqrt{x\_m}
\end{array}
Initial program 56.5%
unpow256.5%
associate-*r*56.5%
sqrt-prod52.0%
Applied egg-rr52.0%
Final simplification52.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m (sqrt 2.0)))
x_m = fabs(x);
double code(double x_m) {
return x_m * sqrt(2.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * sqrt(2.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * Math.sqrt(2.0);
}
x_m = math.fabs(x) def code(x_m): return x_m * math.sqrt(2.0)
x_m = abs(x) function code(x_m) return Float64(x_m * sqrt(2.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * sqrt(2.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot \sqrt{2}
\end{array}
Initial program 56.5%
sqrt-prod56.2%
unpow256.2%
sqrt-prod51.8%
add-sqr-sqrt53.0%
Applied egg-rr53.0%
Final simplification53.0%
herbie shell --seed 2024031
(FPCore (x)
:name "sqrt D (should all be same)"
:precision binary64
(sqrt (* 2.0 (pow x 2.0))))