
(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 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(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 (* (* x_m (pow 64.0 0.0625)) (pow 4.0 0.0625)))
x_m = fabs(x);
double code(double x_m) {
return (x_m * pow(64.0, 0.0625)) * pow(4.0, 0.0625);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m * (64.0d0 ** 0.0625d0)) * (4.0d0 ** 0.0625d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (x_m * Math.pow(64.0, 0.0625)) * Math.pow(4.0, 0.0625);
}
x_m = math.fabs(x) def code(x_m): return (x_m * math.pow(64.0, 0.0625)) * math.pow(4.0, 0.0625)
x_m = abs(x) function code(x_m) return Float64(Float64(x_m * (64.0 ^ 0.0625)) * (4.0 ^ 0.0625)) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m * (64.0 ^ 0.0625)) * (4.0 ^ 0.0625); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(x$95$m * N[Power[64.0, 0.0625], $MachinePrecision]), $MachinePrecision] * N[Power[4.0, 0.0625], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\left(x\_m \cdot {64}^{0.0625}\right) \cdot {4}^{0.0625}
\end{array}
Initial program 49.4%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
associate-*r*N/A
associate-*r*N/A
sqr-powN/A
*-commutativeN/A
sqr-powN/A
Applied rewrites52.4%
Taylor expanded in x around 0
lower-*.f64N/A
lower-pow.f6452.5
Applied rewrites52.5%
Final simplification52.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (sqrt (* 2.0 (sqrt x_m))) (pow x_m 0.75)))
x_m = fabs(x);
double code(double x_m) {
return sqrt((2.0 * sqrt(x_m))) * pow(x_m, 0.75);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = sqrt((2.0d0 * sqrt(x_m))) * (x_m ** 0.75d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.sqrt((2.0 * Math.sqrt(x_m))) * Math.pow(x_m, 0.75);
}
x_m = math.fabs(x) def code(x_m): return math.sqrt((2.0 * math.sqrt(x_m))) * math.pow(x_m, 0.75)
x_m = abs(x) function code(x_m) return Float64(sqrt(Float64(2.0 * sqrt(x_m))) * (x_m ^ 0.75)) end
x_m = abs(x); function tmp = code(x_m) tmp = sqrt((2.0 * sqrt(x_m))) * (x_m ^ 0.75); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Sqrt[N[(2.0 * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[x$95$m, 0.75], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\sqrt{2 \cdot \sqrt{x\_m}} \cdot {x\_m}^{0.75}
\end{array}
Initial program 49.4%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
rem-square-sqrtN/A
pow1/2N/A
pow1/2N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
rem-square-sqrtN/A
sqrt-prodN/A
pow1/2N/A
pow-prod-downN/A
sqrt-pow1N/A
pow-prod-downN/A
unpow-prod-downN/A
sqr-powN/A
*-commutativeN/A
Applied rewrites51.3%
Final simplification51.3%
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 49.4%
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.f6452.4
Applied rewrites52.4%
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 49.4%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
rem-square-sqrtN/A
pow1/2N/A
pow1/2N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
rem-square-sqrtN/A
sqrt-prodN/A
pow1/2N/A
pow-prod-downN/A
sqrt-pow1N/A
pow-prod-downN/A
unpow-prod-downN/A
sqr-powN/A
*-commutativeN/A
Applied rewrites51.3%
Applied rewrites11.6%
lift-*.f64N/A
*-rgt-identity11.6
Applied rewrites11.6%
herbie shell --seed 2024273
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))