
(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 5 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}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (pow 2.0 0.375) (* x_m (pow 2.0 0.125))))
x_m = fabs(x);
double code(double x_m) {
return pow(2.0, 0.375) * (x_m * pow(2.0, 0.125));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (2.0d0 ** 0.375d0) * (x_m * (2.0d0 ** 0.125d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(2.0, 0.375) * (x_m * Math.pow(2.0, 0.125));
}
x_m = math.fabs(x) def code(x_m): return math.pow(2.0, 0.375) * (x_m * math.pow(2.0, 0.125))
x_m = abs(x) function code(x_m) return Float64((2.0 ^ 0.375) * Float64(x_m * (2.0 ^ 0.125))) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.0 ^ 0.375) * (x_m * (2.0 ^ 0.125)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[2.0, 0.375], $MachinePrecision] * N[(x$95$m * N[Power[2.0, 0.125], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{2}^{0.375} \cdot \left(x\_m \cdot {2}^{0.125}\right)
\end{array}
Initial program 54.9%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6447.0
Applied rewrites47.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
sqr-powN/A
lift-pow.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites48.4%
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 54.9%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6447.0
Applied rewrites47.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 54.9%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
unpow-prod-downN/A
pow1/2N/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6448.2
Applied rewrites48.2%
Final simplification48.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* 2.0 x_m))
x_m = fabs(x);
double code(double x_m) {
return 2.0 * x_m;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 2.0d0 * x_m
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 2.0 * x_m;
}
x_m = math.fabs(x) def code(x_m): return 2.0 * x_m
x_m = abs(x) function code(x_m) return Float64(2.0 * x_m) end
x_m = abs(x); function tmp = code(x_m) tmp = 2.0 * x_m; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(2.0 * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
2 \cdot x\_m
\end{array}
Initial program 54.9%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6447.0
Applied rewrites47.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
sqr-powN/A
lift-pow.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites48.4%
Applied rewrites10.9%
Final simplification10.9%
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 54.9%
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6447.0
Applied rewrites47.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
sqr-powN/A
lift-pow.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites48.4%
Applied rewrites10.9%
lift-*.f64N/A
*-rgt-identity10.9
Applied rewrites10.9%
herbie shell --seed 2024214
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))