
(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 7 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}
(FPCore (x) :precision binary64 (if (<= x -4e-310) (* (sqrt 2.0) (- x)) (* x (sqrt 2.0))))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = sqrt(2.0) * -x;
} else {
tmp = x * sqrt(2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4d-310)) then
tmp = sqrt(2.0d0) * -x
else
tmp = x * sqrt(2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = Math.sqrt(2.0) * -x;
} else {
tmp = x * Math.sqrt(2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4e-310: tmp = math.sqrt(2.0) * -x else: tmp = x * math.sqrt(2.0) return tmp
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(sqrt(2.0) * Float64(-x)); else tmp = Float64(x * sqrt(2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-310) tmp = sqrt(2.0) * -x; else tmp = x * sqrt(2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4e-310], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{2}\\
\end{array}
\end{array}
if x < -3.999999999999988e-310Initial program 58.5%
Taylor expanded in x around -inf 99.3%
mul-1-neg99.3%
distribute-rgt-neg-in99.3%
Simplified99.3%
if -3.999999999999988e-310 < x Initial program 58.4%
Taylor expanded in x around 0 99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (pow (pow (cbrt (* x (sqrt 2.0))) 2.0) 1.5))
double code(double x) {
return pow(pow(cbrt((x * sqrt(2.0))), 2.0), 1.5);
}
public static double code(double x) {
return Math.pow(Math.pow(Math.cbrt((x * Math.sqrt(2.0))), 2.0), 1.5);
}
function code(x) return (cbrt(Float64(x * sqrt(2.0))) ^ 2.0) ^ 1.5 end
code[x_] := N[Power[N[Power[N[Power[N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision], 1.5], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(\sqrt[3]{x \cdot \sqrt{2}}\right)}^{2}\right)}^{1.5}
\end{array}
Initial program 58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
pow257.8%
associate-*l*57.8%
associate-*l*57.8%
Applied egg-rr57.8%
unpow257.8%
rem-sqrt-square57.8%
rem-square-sqrt57.6%
unpow1/257.6%
unpow1/257.6%
fabs-sqr57.6%
unpow1/257.6%
pow-sqr57.8%
metadata-eval57.8%
unpow157.8%
*-commutative57.8%
pow-plus57.8%
metadata-eval57.8%
Simplified57.8%
add-sqr-sqrt57.8%
swap-sqr57.8%
cbrt-unprod97.9%
pow297.9%
*-commutative97.9%
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (* (sqrt 2.0) (pow (fabs (cbrt x)) 3.0)))
double code(double x) {
return sqrt(2.0) * pow(fabs(cbrt(x)), 3.0);
}
public static double code(double x) {
return Math.sqrt(2.0) * Math.pow(Math.abs(Math.cbrt(x)), 3.0);
}
function code(x) return Float64(sqrt(2.0) * (abs(cbrt(x)) ^ 3.0)) end
code[x_] := N[(N[Sqrt[2.0], $MachinePrecision] * N[Power[N[Abs[N[Power[x, 1/3], $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2} \cdot {\left(\left|\sqrt[3]{x}\right|\right)}^{3}
\end{array}
Initial program 58.4%
add-cube-cbrt57.4%
pow357.5%
associate-*l*57.5%
sqrt-prod57.4%
sqrt-unprod46.9%
add-sqr-sqrt48.0%
Applied egg-rr48.0%
add-sqr-sqrt46.9%
associate-*r*47.0%
sqrt-prod46.7%
sqrt-unprod57.5%
associate-*r*57.5%
add-cube-cbrt57.2%
sqrt-prod57.2%
sqrt-unprod57.2%
add-cbrt-cube57.6%
cbrt-prod57.4%
sqrt-prod57.6%
cbrt-prod97.7%
pow297.7%
Applied egg-rr97.7%
unpow297.7%
rem-sqrt-square97.7%
Simplified97.7%
Taylor expanded in x around 0 43.1%
Simplified97.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (pow (fabs (cbrt (* x (sqrt 2.0)))) 3.0))
double code(double x) {
return pow(fabs(cbrt((x * sqrt(2.0)))), 3.0);
}
public static double code(double x) {
return Math.pow(Math.abs(Math.cbrt((x * Math.sqrt(2.0)))), 3.0);
}
function code(x) return abs(cbrt(Float64(x * sqrt(2.0)))) ^ 3.0 end
code[x_] := N[Power[N[Abs[N[Power[N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\left|\sqrt[3]{x \cdot \sqrt{2}}\right|\right)}^{3}
\end{array}
Initial program 58.4%
add-cube-cbrt57.4%
pow357.5%
associate-*l*57.5%
sqrt-prod57.4%
sqrt-unprod46.9%
add-sqr-sqrt48.0%
Applied egg-rr48.0%
add-sqr-sqrt46.9%
associate-*r*47.0%
sqrt-prod46.7%
sqrt-unprod57.5%
associate-*r*57.5%
add-cube-cbrt57.2%
sqrt-prod57.2%
sqrt-unprod57.2%
add-cbrt-cube57.6%
add-sqr-sqrt57.6%
rem-sqrt-square57.6%
add-cbrt-cube57.2%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (x) :precision binary64 (pow (* (cbrt x) (cbrt (+ x x))) 1.5))
double code(double x) {
return pow((cbrt(x) * cbrt((x + x))), 1.5);
}
public static double code(double x) {
return Math.pow((Math.cbrt(x) * Math.cbrt((x + x))), 1.5);
}
function code(x) return Float64(cbrt(x) * cbrt(Float64(x + x))) ^ 1.5 end
code[x_] := N[Power[N[(N[Power[x, 1/3], $MachinePrecision] * N[Power[N[(x + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\sqrt[3]{x} \cdot \sqrt[3]{x + x}\right)}^{1.5}
\end{array}
Initial program 58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
pow257.8%
associate-*l*57.8%
associate-*l*57.8%
Applied egg-rr57.8%
unpow257.8%
rem-sqrt-square57.8%
rem-square-sqrt57.6%
unpow1/257.6%
unpow1/257.6%
fabs-sqr57.6%
unpow1/257.6%
pow-sqr57.8%
metadata-eval57.8%
unpow157.8%
*-commutative57.8%
pow-plus57.8%
metadata-eval57.8%
Simplified57.8%
associate-*r*57.8%
cbrt-prod97.6%
add-log-exp7.2%
*-commutative7.2%
exp-lft-sqr7.1%
log-prod7.1%
add-log-exp13.5%
add-log-exp97.6%
Applied egg-rr97.6%
Final simplification97.6%
(FPCore (x) :precision binary64 (* x (sqrt 2.0)))
double code(double x) {
return x * sqrt(2.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * sqrt(2.0d0)
end function
public static double code(double x) {
return x * Math.sqrt(2.0);
}
def code(x): return x * math.sqrt(2.0)
function code(x) return Float64(x * sqrt(2.0)) end
function tmp = code(x) tmp = x * sqrt(2.0); end
code[x_] := N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sqrt{2}
\end{array}
Initial program 58.4%
Taylor expanded in x around 0 48.7%
Final simplification48.7%
(FPCore (x) :precision binary64 (sqrt x))
double code(double x) {
return sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(x)
end function
public static double code(double x) {
return Math.sqrt(x);
}
def code(x): return math.sqrt(x)
function code(x) return sqrt(x) end
function tmp = code(x) tmp = sqrt(x); end
code[x_] := N[Sqrt[x], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x}
\end{array}
Initial program 58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
pow257.8%
associate-*l*57.8%
associate-*l*57.8%
Applied egg-rr57.8%
unpow257.8%
rem-sqrt-square57.8%
rem-square-sqrt57.6%
unpow1/257.6%
unpow1/257.6%
fabs-sqr57.6%
unpow1/257.6%
pow-sqr57.8%
metadata-eval57.8%
unpow157.8%
*-commutative57.8%
pow-plus57.8%
metadata-eval57.8%
Simplified57.8%
add-sqr-sqrt57.8%
swap-sqr57.8%
cbrt-unprod97.9%
pow297.9%
*-commutative97.9%
Applied egg-rr97.9%
pow-pow48.0%
metadata-eval48.0%
rem-cube-cbrt48.7%
*-commutative48.7%
pow1/248.7%
metadata-eval48.7%
pow-pow48.7%
pow1/348.1%
add-sqr-sqrt47.2%
associate-*r*47.1%
Applied egg-rr0.0%
Simplified3.3%
Final simplification3.3%
herbie shell --seed 2023189
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))