
(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 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(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}
(FPCore (x) :precision binary64 (if (<= x -4e-310) (* (sqrt 2.0) (- x)) (* (sqrt 2.0) x)))
double code(double x) {
double tmp;
if (x <= -4e-310) {
tmp = sqrt(2.0) * -x;
} else {
tmp = sqrt(2.0) * x;
}
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 = sqrt(2.0d0) * x
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 = Math.sqrt(2.0) * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -4e-310: tmp = math.sqrt(2.0) * -x else: tmp = math.sqrt(2.0) * x return tmp
function code(x) tmp = 0.0 if (x <= -4e-310) tmp = Float64(sqrt(2.0) * Float64(-x)); else tmp = Float64(sqrt(2.0) * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4e-310) tmp = sqrt(2.0) * -x; else tmp = sqrt(2.0) * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4e-310], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot x\\
\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 (* (sqrt 2.0) x)) 2.0) 1.5))
double code(double x) {
return pow(pow(cbrt((sqrt(2.0) * x)), 2.0), 1.5);
}
public static double code(double x) {
return Math.pow(Math.pow(Math.cbrt((Math.sqrt(2.0) * x)), 2.0), 1.5);
}
function code(x) return (cbrt(Float64(sqrt(2.0) * x)) ^ 2.0) ^ 1.5 end
code[x_] := N[Power[N[Power[N[Power[N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision], 1.5], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(\sqrt[3]{\sqrt{2} \cdot x}\right)}^{2}\right)}^{1.5}
\end{array}
Initial program 58.4%
Taylor expanded in x around -inf 52.6%
mul-1-neg52.6%
distribute-rgt-neg-in52.6%
Simplified52.6%
add-sqr-sqrt51.4%
sqrt-unprod58.1%
sqr-neg58.1%
sqrt-prod58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
sqrt-unprod57.6%
add-sqr-sqrt57.8%
pow157.8%
pow1/257.8%
pow-prod-up57.8%
metadata-eval57.8%
Applied egg-rr57.8%
*-commutative57.8%
cbrt-prod57.4%
cbrt-prod97.5%
add-sqr-sqrt97.5%
cbrt-unprod97.8%
swap-sqr97.7%
cbrt-prod98.2%
cbrt-prod97.9%
pow297.9%
*-commutative97.9%
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (x) :precision binary64 (pow (fabs (cbrt (* (sqrt 2.0) x))) 3.0))
double code(double x) {
return pow(fabs(cbrt((sqrt(2.0) * x))), 3.0);
}
public static double code(double x) {
return Math.pow(Math.abs(Math.cbrt((Math.sqrt(2.0) * x))), 3.0);
}
function code(x) return abs(cbrt(Float64(sqrt(2.0) * x))) ^ 3.0 end
code[x_] := N[Power[N[Abs[N[Power[N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\left|\sqrt[3]{\sqrt{2} \cdot x}\right|\right)}^{3}
\end{array}
Initial program 58.4%
add-cube-cbrt57.4%
pow357.5%
*-commutative57.5%
sqrt-prod57.4%
sqrt-prod46.9%
add-sqr-sqrt48.0%
Applied egg-rr48.0%
add-sqr-sqrt46.8%
sqrt-unprod97.8%
cbrt-prod98.0%
cbrt-prod97.7%
swap-sqr97.6%
cbrt-prod57.6%
cbrt-unprod57.4%
add-sqr-sqrt57.4%
cbrt-prod57.6%
*-commutative57.6%
add-sqr-sqrt57.6%
rem-sqrt-square57.6%
*-commutative57.6%
cbrt-prod57.4%
cbrt-prod97.5%
add-sqr-sqrt97.5%
cbrt-unprod97.6%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (x) :precision binary64 (pow (* (cbrt (+ x x)) (cbrt x)) 1.5))
double code(double x) {
return pow((cbrt((x + x)) * cbrt(x)), 1.5);
}
public static double code(double x) {
return Math.pow((Math.cbrt((x + x)) * Math.cbrt(x)), 1.5);
}
function code(x) return Float64(cbrt(Float64(x + x)) * cbrt(x)) ^ 1.5 end
code[x_] := N[Power[N[(N[Power[N[(x + x), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\sqrt[3]{x + x} \cdot \sqrt[3]{x}\right)}^{1.5}
\end{array}
Initial program 58.4%
Taylor expanded in x around -inf 52.6%
mul-1-neg52.6%
distribute-rgt-neg-in52.6%
Simplified52.6%
add-sqr-sqrt51.4%
sqrt-unprod58.1%
sqr-neg58.1%
sqrt-prod58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
sqrt-unprod57.6%
add-sqr-sqrt57.8%
pow157.8%
pow1/257.8%
pow-prod-up57.8%
metadata-eval57.8%
Applied egg-rr57.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 (if (<= x 3.2e-206) (sqrt (* x 0.0)) (sqrt x)))
double code(double x) {
double tmp;
if (x <= 3.2e-206) {
tmp = sqrt((x * 0.0));
} else {
tmp = sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3.2d-206) then
tmp = sqrt((x * 0.0d0))
else
tmp = sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3.2e-206) {
tmp = Math.sqrt((x * 0.0));
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 3.2e-206: tmp = math.sqrt((x * 0.0)) else: tmp = math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (x <= 3.2e-206) tmp = sqrt(Float64(x * 0.0)); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3.2e-206) tmp = sqrt((x * 0.0)); else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3.2e-206], N[Sqrt[N[(x * 0.0), $MachinePrecision]], $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.2 \cdot 10^{-206}:\\
\;\;\;\;\sqrt{x \cdot 0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
\end{array}
if x < 3.19999999999999976e-206Initial program 53.4%
add-cube-cbrt52.6%
pow352.6%
*-commutative52.6%
sqrt-prod52.6%
sqrt-prod9.9%
add-sqr-sqrt11.7%
Applied egg-rr11.7%
rem-cube-cbrt11.8%
*-commutative11.8%
add-sqr-sqrt10.0%
sqrt-prod53.2%
sqr-neg53.2%
sqrt-unprod88.9%
add-sqr-sqrt88.8%
add-sqr-sqrt89.7%
associate-*l*89.9%
pow1/289.9%
sqrt-pow189.9%
metadata-eval89.9%
pow1/289.9%
sqrt-pow189.9%
metadata-eval89.9%
add-sqr-sqrt88.8%
sqrt-unprod53.1%
sqr-neg53.1%
sqrt-prod10.0%
add-sqr-sqrt11.8%
Applied egg-rr11.8%
associate-*r*11.8%
pow-prod-up11.8%
metadata-eval11.8%
pow1/211.8%
add-sqr-sqrt10.0%
sqrt-prod53.2%
sqrt-prod53.4%
pow1/253.4%
Applied egg-rr53.4%
Simplified4.0%
if 3.19999999999999976e-206 < x Initial program 65.3%
Taylor expanded in x around -inf 1.3%
mul-1-neg1.3%
distribute-rgt-neg-in1.3%
Simplified1.3%
add-sqr-sqrt0.0%
sqrt-unprod64.9%
sqr-neg64.9%
sqrt-prod65.3%
add-cube-cbrt64.4%
sqrt-prod64.5%
sqrt-unprod64.3%
add-sqr-sqrt64.5%
pow164.5%
pow1/264.5%
pow-prod-up64.5%
metadata-eval64.5%
Applied egg-rr64.5%
pow1/359.8%
pow-pow65.3%
metadata-eval65.3%
pow1/265.3%
associate-*r*65.3%
count-265.3%
sqrt-prod99.0%
flip-+0.0%
difference-of-squares0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
+-inverses0.0%
+-inverses0.0%
flip-+7.9%
sqrt-unprod8.1%
add-sqr-sqrt8.1%
Applied egg-rr8.1%
Simplified7.2%
Final simplification5.4%
(FPCore (x) :precision binary64 (* (sqrt 2.0) x))
double code(double x) {
return sqrt(2.0) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(2.0d0) * x
end function
public static double code(double x) {
return Math.sqrt(2.0) * x;
}
def code(x): return math.sqrt(2.0) * x
function code(x) return Float64(sqrt(2.0) * x) end
function tmp = code(x) tmp = sqrt(2.0) * x; end
code[x_] := N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2} \cdot x
\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%
Taylor expanded in x around -inf 52.6%
mul-1-neg52.6%
distribute-rgt-neg-in52.6%
Simplified52.6%
add-sqr-sqrt51.4%
sqrt-unprod58.1%
sqr-neg58.1%
sqrt-prod58.4%
add-cube-cbrt57.7%
sqrt-prod57.8%
sqrt-unprod57.6%
add-sqr-sqrt57.8%
pow157.8%
pow1/257.8%
pow-prod-up57.8%
metadata-eval57.8%
Applied egg-rr57.8%
pow1/353.5%
pow-pow58.4%
metadata-eval58.4%
pow1/258.4%
associate-*r*58.4%
count-258.4%
sqrt-prod47.6%
flip-+0.0%
difference-of-squares0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
+-inverses0.0%
+-inverses0.0%
flip-+3.9%
sqrt-unprod3.9%
add-sqr-sqrt3.9%
Applied egg-rr3.9%
Simplified3.3%
Final simplification3.3%
herbie shell --seed 2023189
(FPCore (x)
:name "sqrt C (should all be same)"
:precision binary64
(sqrt (* 2.0 (* x x))))