
(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}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow (* x_m 4.0) 0.25) (pow x_m 0.75)))
x_m = fabs(x);
double code(double x_m) {
return pow((x_m * 4.0), 0.25) * pow(x_m, 0.75);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((x_m * 4.0d0) ** 0.25d0) * (x_m ** 0.75d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow((x_m * 4.0), 0.25) * Math.pow(x_m, 0.75);
}
x_m = math.fabs(x) def code(x_m): return math.pow((x_m * 4.0), 0.25) * math.pow(x_m, 0.75)
x_m = abs(x) function code(x_m) return Float64((Float64(x_m * 4.0) ^ 0.25) * (x_m ^ 0.75)) end
x_m = abs(x); function tmp = code(x_m) tmp = ((x_m * 4.0) ^ 0.25) * (x_m ^ 0.75); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[N[(x$95$m * 4.0), $MachinePrecision], 0.25], $MachinePrecision] * N[Power[x$95$m, 0.75], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(x\_m \cdot 4\right)}^{0.25} \cdot {x\_m}^{0.75}
\end{array}
Initial program 53.4%
pow1/2N/A
rem-square-sqrtN/A
pow1/2N/A
pow1/2N/A
associate-*l*N/A
associate-*r*N/A
unpow-prod-downN/A
unpow-prod-downN/A
pow1/2N/A
sqrt-pow2N/A
*-commutativeN/A
*-lowering-*.f64N/A
Applied egg-rr52.5%
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 53.4%
sqrt-prodN/A
pow1/2N/A
sqrt-prodN/A
rem-square-sqrtN/A
*-lowering-*.f64N/A
pow1/2N/A
sqrt-lowering-sqrt.f6453.4%
Applied egg-rr53.4%
Final simplification53.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (* x_m x_m) (* 4.0 (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
return (x_m * x_m) * (4.0 * (x_m * x_m));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m * x_m) * (4.0d0 * (x_m * x_m))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (x_m * x_m) * (4.0 * (x_m * x_m));
}
x_m = math.fabs(x) def code(x_m): return (x_m * x_m) * (4.0 * (x_m * x_m))
x_m = abs(x) function code(x_m) return Float64(Float64(x_m * x_m) * Float64(4.0 * Float64(x_m * x_m))) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m * x_m) * (4.0 * (x_m * x_m)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(4.0 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\left(x\_m \cdot x\_m\right) \cdot \left(4 \cdot \left(x\_m \cdot x\_m\right)\right)
\end{array}
Initial program 53.4%
pow1/2N/A
rem-square-sqrtN/A
pow1/2N/A
pow1/2N/A
associate-*l*N/A
associate-*r*N/A
unpow-prod-downN/A
unpow-prod-downN/A
pow1/2N/A
sqrt-pow2N/A
*-commutativeN/A
*-lowering-*.f64N/A
Applied egg-rr52.5%
Applied egg-rr5.9%
herbie shell --seed 2024155
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2.0 (* x x))))