
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (+ re (sqrt (+ (* re re) (* im_m im_m)))) 0.0) (* 0.5 (pow (* (sqrt im_m) (pow (/ -1.0 re) 0.25)) 2.0)) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im_m)))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = 0.5 * pow((sqrt(im_m) * pow((-1.0 / re), 0.25)), 2.0);
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if ((re + Math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = 0.5 * Math.pow((Math.sqrt(im_m) * Math.pow((-1.0 / re), 0.25)), 2.0);
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if (re + math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0: tmp = 0.5 * math.pow((math.sqrt(im_m) * math.pow((-1.0 / re), 0.25)), 2.0) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(re + sqrt(Float64(Float64(re * re) + Float64(im_m * im_m)))) <= 0.0) tmp = Float64(0.5 * (Float64(sqrt(im_m) * (Float64(-1.0 / re) ^ 0.25)) ^ 2.0)); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im_m))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) tmp = 0.5 * ((sqrt(im_m) * ((-1.0 / re) ^ 0.25)) ^ 2.0); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Power[N[(-1.0 / re), $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re + \sqrt{re \cdot re + im\_m \cdot im\_m} \leq 0:\\
\;\;\;\;0.5 \cdot {\left(\sqrt{im\_m} \cdot {\left(\frac{-1}{re}\right)}^{0.25}\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 9.1%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6417.1%
Simplified17.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64N/A
metadata-eval17.0%
Applied egg-rr17.0%
Taylor expanded in re around -inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6438.0%
Simplified38.0%
Taylor expanded in im around 0
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
pow-lowering-pow.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f6448.4%
Simplified48.4%
if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 49.1%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6492.4%
Simplified92.4%
Final simplification85.4%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (+ re (sqrt (+ (* re re) (* im_m im_m)))) 0.0) (* 0.5 (* (sqrt im_m) (sqrt (- 0.0 (/ im_m re))))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im_m)))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = 0.5 * (sqrt(im_m) * sqrt((0.0 - (im_m / re))));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if ((re + Math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = 0.5 * (Math.sqrt(im_m) * Math.sqrt((0.0 - (im_m / re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if (re + math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0: tmp = 0.5 * (math.sqrt(im_m) * math.sqrt((0.0 - (im_m / re)))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(re + sqrt(Float64(Float64(re * re) + Float64(im_m * im_m)))) <= 0.0) tmp = Float64(0.5 * Float64(sqrt(im_m) * sqrt(Float64(0.0 - Float64(im_m / re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im_m))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) tmp = 0.5 * (sqrt(im_m) * sqrt((0.0 - (im_m / re)))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Sqrt[N[(0.0 - N[(im$95$m / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re + \sqrt{re \cdot re + im\_m \cdot im\_m} \leq 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{im\_m} \cdot \sqrt{0 - \frac{im\_m}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 9.1%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6417.1%
Simplified17.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64N/A
metadata-eval17.0%
Applied egg-rr17.0%
Taylor expanded in re around -inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6438.0%
Simplified38.0%
pow-powN/A
metadata-evalN/A
unpow1/2N/A
sub0-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
sqrt-prodN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f6446.5%
Applied egg-rr46.5%
if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 49.1%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6492.4%
Simplified92.4%
Final simplification85.1%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -2.2e+114) (* 0.5 (sqrt (* 2.0 (* im_m (* im_m (/ -0.5 re)))))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im_m)))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -2.2e+114) {
tmp = 0.5 * sqrt((2.0 * (im_m * (im_m * (-0.5 / re)))));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -2.2e+114) {
tmp = 0.5 * Math.sqrt((2.0 * (im_m * (im_m * (-0.5 / re)))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -2.2e+114: tmp = 0.5 * math.sqrt((2.0 * (im_m * (im_m * (-0.5 / re))))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -2.2e+114) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m * Float64(im_m * Float64(-0.5 / re)))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im_m))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -2.2e+114) tmp = 0.5 * sqrt((2.0 * (im_m * (im_m * (-0.5 / re))))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -2.2e+114], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m * N[(im$95$m * N[(-0.5 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.2 \cdot 10^{+114}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m \cdot \left(im\_m \cdot \frac{-0.5}{re}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if re < -2.2e114Initial program 8.7%
Taylor expanded in re around -inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified15.5%
Taylor expanded in im around inf
distribute-lft1-inN/A
metadata-evalN/A
mul0-lftN/A
neg-sub0N/A
distribute-lft-neg-inN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
distribute-lft-neg-inN/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f6451.8%
Simplified51.8%
if -2.2e114 < re Initial program 48.6%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6489.0%
Simplified89.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -2e+113) (* 0.5 (sqrt (* 2.0 (* im_m (* im_m (/ -0.5 re)))))) (if (<= re 1.85e-84) (* 0.5 (sqrt (* im_m 2.0))) (sqrt re))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -2e+113) {
tmp = 0.5 * sqrt((2.0 * (im_m * (im_m * (-0.5 / re)))));
} else if (re <= 1.85e-84) {
tmp = 0.5 * sqrt((im_m * 2.0));
} else {
tmp = sqrt(re);
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-2d+113)) then
tmp = 0.5d0 * sqrt((2.0d0 * (im_m * (im_m * ((-0.5d0) / re)))))
else if (re <= 1.85d-84) then
tmp = 0.5d0 * sqrt((im_m * 2.0d0))
else
tmp = sqrt(re)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -2e+113) {
tmp = 0.5 * Math.sqrt((2.0 * (im_m * (im_m * (-0.5 / re)))));
} else if (re <= 1.85e-84) {
tmp = 0.5 * Math.sqrt((im_m * 2.0));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -2e+113: tmp = 0.5 * math.sqrt((2.0 * (im_m * (im_m * (-0.5 / re))))) elif re <= 1.85e-84: tmp = 0.5 * math.sqrt((im_m * 2.0)) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -2e+113) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m * Float64(im_m * Float64(-0.5 / re)))))); elseif (re <= 1.85e-84) tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0))); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -2e+113) tmp = 0.5 * sqrt((2.0 * (im_m * (im_m * (-0.5 / re))))); elseif (re <= 1.85e-84) tmp = 0.5 * sqrt((im_m * 2.0)); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -2e+113], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m * N[(im$95$m * N[(-0.5 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.85e-84], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m \cdot \left(im\_m \cdot \frac{-0.5}{re}\right)\right)}\\
\mathbf{elif}\;re \leq 1.85 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -2e113Initial program 8.7%
Taylor expanded in re around -inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified15.5%
Taylor expanded in im around inf
distribute-lft1-inN/A
metadata-evalN/A
mul0-lftN/A
neg-sub0N/A
distribute-lft-neg-inN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
distribute-lft-neg-inN/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f6451.8%
Simplified51.8%
if -2e113 < re < 1.85e-84Initial program 49.4%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6482.6%
Simplified82.6%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6445.9%
Simplified45.9%
if 1.85e-84 < re Initial program 47.3%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6474.9%
Simplified74.9%
*-lft-identityN/A
sqrt-lowering-sqrt.f6474.9%
Applied egg-rr74.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -5.8e+110) (* 0.5 (sqrt (- 0.0 (/ (* im_m im_m) re)))) (if (<= re 2e-84) (* 0.5 (sqrt (* im_m 2.0))) (sqrt re))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -5.8e+110) {
tmp = 0.5 * sqrt((0.0 - ((im_m * im_m) / re)));
} else if (re <= 2e-84) {
tmp = 0.5 * sqrt((im_m * 2.0));
} else {
tmp = sqrt(re);
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-5.8d+110)) then
tmp = 0.5d0 * sqrt((0.0d0 - ((im_m * im_m) / re)))
else if (re <= 2d-84) then
tmp = 0.5d0 * sqrt((im_m * 2.0d0))
else
tmp = sqrt(re)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -5.8e+110) {
tmp = 0.5 * Math.sqrt((0.0 - ((im_m * im_m) / re)));
} else if (re <= 2e-84) {
tmp = 0.5 * Math.sqrt((im_m * 2.0));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -5.8e+110: tmp = 0.5 * math.sqrt((0.0 - ((im_m * im_m) / re))) elif re <= 2e-84: tmp = 0.5 * math.sqrt((im_m * 2.0)) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -5.8e+110) tmp = Float64(0.5 * sqrt(Float64(0.0 - Float64(Float64(im_m * im_m) / re)))); elseif (re <= 2e-84) tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0))); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -5.8e+110) tmp = 0.5 * sqrt((0.0 - ((im_m * im_m) / re))); elseif (re <= 2e-84) tmp = 0.5 * sqrt((im_m * 2.0)); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -5.8e+110], N[(0.5 * N[Sqrt[N[(0.0 - N[(N[(im$95$m * im$95$m), $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2e-84], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.8 \cdot 10^{+110}:\\
\;\;\;\;0.5 \cdot \sqrt{0 - \frac{im\_m \cdot im\_m}{re}}\\
\mathbf{elif}\;re \leq 2 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -5.7999999999999999e110Initial program 8.7%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6430.9%
Simplified30.9%
Taylor expanded in re around -inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6438.7%
Simplified38.7%
if -5.7999999999999999e110 < re < 2.0000000000000001e-84Initial program 49.4%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6482.6%
Simplified82.6%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6445.9%
Simplified45.9%
if 2.0000000000000001e-84 < re Initial program 47.3%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6474.9%
Simplified74.9%
*-lft-identityN/A
sqrt-lowering-sqrt.f6474.9%
Applied egg-rr74.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re 2e-84) (* 0.5 (sqrt (* im_m 2.0))) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 2e-84) {
tmp = 0.5 * sqrt((im_m * 2.0));
} else {
tmp = sqrt(re);
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= 2d-84) then
tmp = 0.5d0 * sqrt((im_m * 2.0d0))
else
tmp = sqrt(re)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= 2e-84) {
tmp = 0.5 * Math.sqrt((im_m * 2.0));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 2e-84: tmp = 0.5 * math.sqrt((im_m * 2.0)) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 2e-84) tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0))); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 2e-84) tmp = 0.5 * sqrt((im_m * 2.0)); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 2e-84], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 2.0000000000000001e-84Initial program 40.6%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6471.4%
Simplified71.4%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6438.3%
Simplified38.3%
if 2.0000000000000001e-84 < re Initial program 47.3%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6474.9%
Simplified74.9%
*-lft-identityN/A
sqrt-lowering-sqrt.f6474.9%
Applied egg-rr74.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -5e-310) (* 0.5 (sqrt 0.0)) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -5e-310) {
tmp = 0.5 * sqrt(0.0);
} else {
tmp = sqrt(re);
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-5d-310)) then
tmp = 0.5d0 * sqrt(0.0d0)
else
tmp = sqrt(re)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -5e-310) {
tmp = 0.5 * Math.sqrt(0.0);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -5e-310: tmp = 0.5 * math.sqrt(0.0) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -5e-310) tmp = Float64(0.5 * sqrt(0.0)); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -5e-310) tmp = 0.5 * sqrt(0.0); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -5e-310], N[(0.5 * N[Sqrt[0.0], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;0.5 \cdot \sqrt{0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.999999999999985e-310Initial program 26.9%
Taylor expanded in re around -inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
Simplified9.7%
Taylor expanded in im around 0
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-eval7.8%
Simplified7.8%
if -4.999999999999985e-310 < re Initial program 57.6%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6452.9%
Simplified52.9%
*-lft-identityN/A
sqrt-lowering-sqrt.f6452.9%
Applied egg-rr52.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (sqrt re))
im_m = fabs(im);
double code(double re, double im_m) {
return sqrt(re);
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = sqrt(re)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.sqrt(re);
}
im_m = math.fabs(im) def code(re, im_m): return math.sqrt(re)
im_m = abs(im) function code(re, im_m) return sqrt(re) end
im_m = abs(im); function tmp = code(re, im_m) tmp = sqrt(re); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\sqrt{re}
\end{array}
Initial program 42.7%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6480.4%
Simplified80.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6427.3%
Simplified27.3%
*-lft-identityN/A
sqrt-lowering-sqrt.f6427.3%
Applied egg-rr27.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t\_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t\_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2024170
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< re 0) (* 1/2 (* (sqrt 2) (sqrt (/ (* im im) (- (modulus re im) re))))) (* 1/2 (sqrt (* 2 (+ (modulus re im) re))))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))