
(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 4 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 64.0 0.0625) (* (pow 16.0 0.03125) x_m)))
x_m = fabs(x);
double code(double x_m) {
return pow(64.0, 0.0625) * (pow(16.0, 0.03125) * x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (64.0d0 ** 0.0625d0) * ((16.0d0 ** 0.03125d0) * x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(64.0, 0.0625) * (Math.pow(16.0, 0.03125) * x_m);
}
x_m = math.fabs(x) def code(x_m): return math.pow(64.0, 0.0625) * (math.pow(16.0, 0.03125) * x_m)
x_m = abs(x) function code(x_m) return Float64((64.0 ^ 0.0625) * Float64((16.0 ^ 0.03125) * x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (64.0 ^ 0.0625) * ((16.0 ^ 0.03125) * x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[64.0, 0.0625], $MachinePrecision] * N[(N[Power[16.0, 0.03125], $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{64}^{0.0625} \cdot \left({16}^{0.03125} \cdot x\_m\right)
\end{array}
Initial program 53.2%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6450.2
Applied rewrites50.2%
lift-*.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-prod-downN/A
metadata-evalN/A
pow-prod-upN/A
sqr-powN/A
lift-pow.f64N/A
associate-*l*N/A
Applied rewrites51.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt (* x_m 2.0)) (sqrt x_m)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((x_m * 2.0)) * sqrt(x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((x_m * 2.0d0)) * sqrt(x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((x_m * 2.0)) * Math.sqrt(x_m);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((x_m * 2.0)) * math.sqrt(x_m)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(x_m * 2.0)) * sqrt(x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((x_m * 2.0)) * sqrt(x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{x\_m \cdot 2} \cdot \sqrt{x\_m}
\end{array}
Initial program 53.2%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6450.2
Applied rewrites50.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt 2.0) x_m))
x_m = fabs(x);
double code(double x_m) {
return sqrt(2.0) * x_m;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt(2.0d0) * x_m
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt(2.0) * x_m;
}
x_m = math.fabs(x) def code(x_m): return math.sqrt(2.0) * x_m
x_m = abs(x) function code(x_m) return Float64(sqrt(2.0) * x_m) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt(2.0) * x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[2.0], $MachinePrecision] * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{2} \cdot x\_m
\end{array}
Initial program 53.2%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
pow1/2N/A
lift-*.f64N/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6451.3
Applied rewrites51.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 x_m)
x_m = fabs(x);
double code(double x_m) {
return x_m;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m;
}
x_m = math.fabs(x) def code(x_m): return x_m
x_m = abs(x) function code(x_m) return x_m end
x_m = abs(x); function tmp = code(x_m) tmp = x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := x$95$m
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m
\end{array}
Initial program 53.2%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-prod-upN/A
metadata-evalN/A
pow-plusN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
pow-plusN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6427.4
Applied rewrites27.4%
lift-pow.f64N/A
metadata-evalN/A
pow-plusN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f6427.4
Applied rewrites27.4%
Applied rewrites11.5%
lift-*.f64N/A
*-rgt-identity11.5
Applied rewrites11.5%
herbie shell --seed 2024320
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2.0 (* x x))))