
(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 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(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 x_m 0.75) (pow (* x_m 4.0) 0.25)))
x_m = fabs(x);
double code(double x_m) {
return pow(x_m, 0.75) * pow((x_m * 4.0), 0.25);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m ** 0.75d0) * ((x_m * 4.0d0) ** 0.25d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(x_m, 0.75) * Math.pow((x_m * 4.0), 0.25);
}
x_m = math.fabs(x) def code(x_m): return math.pow(x_m, 0.75) * math.pow((x_m * 4.0), 0.25)
x_m = abs(x) function code(x_m) return Float64((x_m ^ 0.75) * (Float64(x_m * 4.0) ^ 0.25)) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m ^ 0.75) * ((x_m * 4.0) ^ 0.25); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[x$95$m, 0.75], $MachinePrecision] * N[Power[N[(x$95$m * 4.0), $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{x\_m}^{0.75} \cdot {\left(x\_m \cdot 4\right)}^{0.25}
\end{array}
Initial program 53.3%
add-cbrt-cube38.1%
pow338.1%
pow1/238.1%
associate-*l*38.1%
*-commutative38.1%
unpow-prod-down38.1%
pow1/238.1%
sqrt-unprod19.5%
add-sqr-sqrt20.7%
pow1/220.7%
Applied egg-rr20.7%
rem-cbrt-cube50.3%
add-sqr-sqrt49.1%
associate-*r*49.1%
sqrt-prod49.3%
*-commutative49.3%
add-sqr-sqrt49.1%
associate-*l*49.1%
pow1/249.1%
sqrt-pow149.2%
metadata-eval49.2%
pow1/249.2%
sqrt-pow149.2%
metadata-eval49.2%
Applied egg-rr49.2%
Taylor expanded in x around 0 45.0%
distribute-rgt-in45.0%
*-commutative45.0%
prod-exp45.4%
exp-to-pow45.4%
associate-*r*45.4%
metadata-eval45.4%
*-commutative45.4%
exp-to-pow49.3%
Simplified49.3%
add-log-exp4.0%
*-un-lft-identity4.0%
log-prod4.0%
metadata-eval4.0%
add-log-exp49.3%
associate-*r*49.2%
*-commutative49.2%
unpow-prod-down49.1%
associate-*l*49.1%
pow-prod-down49.3%
pow-prod-down49.4%
metadata-eval49.4%
Applied egg-rr49.4%
+-lft-identity49.4%
Simplified49.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.3%
sqrt-prod49.3%
Applied egg-rr49.3%
*-commutative49.3%
Simplified49.3%
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.3%
associate-*l*53.3%
sqrt-prod53.1%
sqrt-unprod49.1%
add-sqr-sqrt50.3%
Applied egg-rr50.3%
Final simplification50.3%
herbie shell --seed 2024103
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))