math.sqrt on complex, real part

Percentage Accurate: 41.4% → 89.6%
Time: 17.7s
Alternatives: 11
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 41.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \end{array} \]
(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}

Alternative 1: 89.6% accurate, 0.2× speedup?

\[\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[3]{\sqrt{2}} \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im\_m}\right)\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \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
     (*
      (cbrt (sqrt 2.0))
      (*
       (expm1 (log1p (* (pow 0.5 0.16666666666666666) (cbrt im_m))))
       (pow (/ -1.0 re) 0.16666666666666666)))
     3.0))
   (sqrt (* 0.5 (+ 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((cbrt(sqrt(2.0)) * (expm1(log1p((pow(0.5, 0.16666666666666666) * cbrt(im_m)))) * pow((-1.0 / re), 0.16666666666666666))), 3.0);
	} else {
		tmp = sqrt((0.5 * (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.cbrt(Math.sqrt(2.0)) * (Math.expm1(Math.log1p((Math.pow(0.5, 0.16666666666666666) * Math.cbrt(im_m)))) * Math.pow((-1.0 / re), 0.16666666666666666))), 3.0);
	} else {
		tmp = Math.sqrt((0.5 * (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(cbrt(sqrt(2.0)) * Float64(expm1(log1p(Float64((0.5 ^ 0.16666666666666666) * cbrt(im_m)))) * (Float64(-1.0 / re) ^ 0.16666666666666666))) ^ 3.0));
	else
		tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m))));
	end
	return 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[Power[N[Sqrt[2.0], $MachinePrecision], 1/3], $MachinePrecision] * N[(N[(Exp[N[Log[1 + N[(N[Power[0.5, 0.16666666666666666], $MachinePrecision] * N[Power[im$95$m, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * N[Power[N[(-1.0 / re), $MachinePrecision], 0.16666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $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[3]{\sqrt{2}} \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im\_m}\right)\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0

    1. Initial program 7.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified13.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative13.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define7.7%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-cube-cbrt7.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right) \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)} \]
      6. pow37.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)}^{3}} \]
      7. +-commutative7.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + im \cdot im}\right)}}}\right)}^{3} \]
      8. hypot-define13.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)}}\right)}^{3} \]
    6. Applied egg-rr13.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}}\right)}^{3}} \]
    7. Taylor expanded in re around -inf 51.5%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt[3]{\sqrt{2}}\right)}}^{3} \]
    8. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}}^{3} \]
      2. distribute-rgt-in51.4%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot e^{\color{blue}{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666 + \log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}}\right)}^{3} \]
      3. exp-sum52.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \color{blue}{\left(e^{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)}\right)}^{3} \]
      4. exp-to-pow51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{{\left(0.5 \cdot {im}^{2}\right)}^{0.16666666666666666}} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      5. *-commutative51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\color{blue}{\left({im}^{2} \cdot 0.5\right)}}^{0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      6. exp-to-pow51.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot \color{blue}{{\left(\frac{-1}{re}\right)}^{0.16666666666666666}}\right)\right)}^{3} \]
    9. Simplified51.8%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}}^{3} \]
    10. Step-by-step derivation
      1. expm1-log1p-u51.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      2. expm1-undefine19.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\left(e^{\mathsf{log1p}\left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)} - 1\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      3. *-commutative19.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left(e^{\mathsf{log1p}\left({\color{blue}{\left(0.5 \cdot {im}^{2}\right)}}^{0.16666666666666666}\right)} - 1\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      4. unpow-prod-down19.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left(e^{\mathsf{log1p}\left(\color{blue}{{0.5}^{0.16666666666666666} \cdot {\left({im}^{2}\right)}^{0.16666666666666666}}\right)} - 1\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      5. pow-pow10.3%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left(e^{\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \color{blue}{{im}^{\left(2 \cdot 0.16666666666666666\right)}}\right)} - 1\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      6. metadata-eval10.3%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left(e^{\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot {im}^{\color{blue}{0.3333333333333333}}\right)} - 1\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
      7. pow1/313.1%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left(e^{\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \color{blue}{\sqrt[3]{im}}\right)} - 1\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
    11. Applied egg-rr13.1%

      \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\left(e^{\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)} - 1\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
    12. Step-by-step derivation
      1. expm1-define51.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]
    13. Simplified51.5%

      \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]

    if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)

    1. Initial program 45.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define45.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt45.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod45.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative45.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*90.6%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval90.6%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified90.6%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\ \;\;\;\;0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 89.6% accurate, 0.3× speedup?

\[\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({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left(\sqrt[3]{im\_m} \cdot \left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)\right)}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \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 (pow (/ -1.0 re) 0.16666666666666666) 3.0)
     (pow
      (*
       (cbrt im_m)
       (* (pow 0.5 0.16666666666666666) (pow 2.0 0.16666666666666666)))
      3.0)))
   (sqrt (* 0.5 (+ 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(pow((-1.0 / re), 0.16666666666666666), 3.0) * pow((cbrt(im_m) * (pow(0.5, 0.16666666666666666) * pow(2.0, 0.16666666666666666))), 3.0));
	} else {
		tmp = sqrt((0.5 * (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.pow((-1.0 / re), 0.16666666666666666), 3.0) * Math.pow((Math.cbrt(im_m) * (Math.pow(0.5, 0.16666666666666666) * Math.pow(2.0, 0.16666666666666666))), 3.0));
	} else {
		tmp = Math.sqrt((0.5 * (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(((Float64(-1.0 / re) ^ 0.16666666666666666) ^ 3.0) * (Float64(cbrt(im_m) * Float64((0.5 ^ 0.16666666666666666) * (2.0 ^ 0.16666666666666666))) ^ 3.0)));
	else
		tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m))));
	end
	return 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[Power[N[Power[N[(-1.0 / re), $MachinePrecision], 0.16666666666666666], $MachinePrecision], 3.0], $MachinePrecision] * N[Power[N[(N[Power[im$95$m, 1/3], $MachinePrecision] * N[(N[Power[0.5, 0.16666666666666666], $MachinePrecision] * N[Power[2.0, 0.16666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $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({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left(\sqrt[3]{im\_m} \cdot \left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)\right)}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0

    1. Initial program 7.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified13.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative13.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define7.7%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-cube-cbrt7.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right) \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)} \]
      6. pow37.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)}^{3}} \]
      7. +-commutative7.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + im \cdot im}\right)}}}\right)}^{3} \]
      8. hypot-define13.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)}}\right)}^{3} \]
    6. Applied egg-rr13.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}}\right)}^{3}} \]
    7. Taylor expanded in re around -inf 51.5%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt[3]{\sqrt{2}}\right)}}^{3} \]
    8. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}}^{3} \]
      2. distribute-rgt-in51.4%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot e^{\color{blue}{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666 + \log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}}\right)}^{3} \]
      3. exp-sum52.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \color{blue}{\left(e^{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)}\right)}^{3} \]
      4. exp-to-pow51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{{\left(0.5 \cdot {im}^{2}\right)}^{0.16666666666666666}} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      5. *-commutative51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\color{blue}{\left({im}^{2} \cdot 0.5\right)}}^{0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      6. exp-to-pow51.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot \color{blue}{{\left(\frac{-1}{re}\right)}^{0.16666666666666666}}\right)\right)}^{3} \]
    9. Simplified51.8%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}}^{3} \]
    10. Step-by-step derivation
      1. associate-*r*51.8%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\left(\sqrt[3]{\sqrt{2}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}}^{3} \]
      2. unpow-prod-down51.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left({\left(\sqrt[3]{\sqrt{2}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right)} \]
      3. pow1/351.8%

        \[\leadsto 0.5 \cdot \left({\left(\color{blue}{{\left(\sqrt{2}\right)}^{0.3333333333333333}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      4. sqrt-pow251.8%

        \[\leadsto 0.5 \cdot \left({\left(\color{blue}{{2}^{\left(\frac{0.3333333333333333}{2}\right)}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      5. metadata-eval51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{\color{blue}{0.16666666666666666}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      6. *-commutative51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot {\color{blue}{\left(0.5 \cdot {im}^{2}\right)}}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      7. unpow-prod-down51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \color{blue}{\left({0.5}^{0.16666666666666666} \cdot {\left({im}^{2}\right)}^{0.16666666666666666}\right)}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      8. pow-pow48.0%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \color{blue}{{im}^{\left(2 \cdot 0.16666666666666666\right)}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      9. metadata-eval48.0%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot {im}^{\color{blue}{0.3333333333333333}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      10. pow1/351.5%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \color{blue}{\sqrt[3]{im}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
    11. Applied egg-rr51.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right)} \]
    12. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)}^{3}\right)} \]
      2. associate-*r*51.5%

        \[\leadsto 0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\color{blue}{\left(\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right) \cdot \sqrt[3]{im}\right)}}^{3}\right) \]
    13. Simplified51.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left(\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right) \cdot \sqrt[3]{im}\right)}^{3}\right)} \]

    if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)

    1. Initial program 45.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define45.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt45.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod45.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative45.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*90.6%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval90.6%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified90.6%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\ \;\;\;\;0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left(\sqrt[3]{im} \cdot \left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)\right)}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.6% accurate, 0.3× speedup?

\[\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[3]{\sqrt{2}} \cdot \left(\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im\_m}\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \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
     (*
      (cbrt (sqrt 2.0))
      (*
       (* (pow 0.5 0.16666666666666666) (cbrt im_m))
       (pow (/ -1.0 re) 0.16666666666666666)))
     3.0))
   (sqrt (* 0.5 (+ 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((cbrt(sqrt(2.0)) * ((pow(0.5, 0.16666666666666666) * cbrt(im_m)) * pow((-1.0 / re), 0.16666666666666666))), 3.0);
	} else {
		tmp = sqrt((0.5 * (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.cbrt(Math.sqrt(2.0)) * ((Math.pow(0.5, 0.16666666666666666) * Math.cbrt(im_m)) * Math.pow((-1.0 / re), 0.16666666666666666))), 3.0);
	} else {
		tmp = Math.sqrt((0.5 * (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(cbrt(sqrt(2.0)) * Float64(Float64((0.5 ^ 0.16666666666666666) * cbrt(im_m)) * (Float64(-1.0 / re) ^ 0.16666666666666666))) ^ 3.0));
	else
		tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m))));
	end
	return 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[Power[N[Sqrt[2.0], $MachinePrecision], 1/3], $MachinePrecision] * N[(N[(N[Power[0.5, 0.16666666666666666], $MachinePrecision] * N[Power[im$95$m, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[N[(-1.0 / re), $MachinePrecision], 0.16666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $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[3]{\sqrt{2}} \cdot \left(\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im\_m}\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0

    1. Initial program 7.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified13.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative13.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define7.7%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-cube-cbrt7.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right) \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)} \]
      6. pow37.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)}^{3}} \]
      7. +-commutative7.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + im \cdot im}\right)}}}\right)}^{3} \]
      8. hypot-define13.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)}}\right)}^{3} \]
    6. Applied egg-rr13.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}}\right)}^{3}} \]
    7. Taylor expanded in re around -inf 51.5%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt[3]{\sqrt{2}}\right)}}^{3} \]
    8. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}}^{3} \]
      2. distribute-rgt-in51.4%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot e^{\color{blue}{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666 + \log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}}\right)}^{3} \]
      3. exp-sum52.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \color{blue}{\left(e^{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)}\right)}^{3} \]
      4. exp-to-pow51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{{\left(0.5 \cdot {im}^{2}\right)}^{0.16666666666666666}} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      5. *-commutative51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\color{blue}{\left({im}^{2} \cdot 0.5\right)}}^{0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      6. exp-to-pow51.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot \color{blue}{{\left(\frac{-1}{re}\right)}^{0.16666666666666666}}\right)\right)}^{3} \]
    9. Simplified51.8%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}}^{3} \]
    10. Taylor expanded in im around 0 51.5%

      \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3} \]

    if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)

    1. Initial program 45.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define45.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt45.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod45.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative45.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*90.6%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval90.6%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified90.6%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\ \;\;\;\;0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 89.6% accurate, 0.3× speedup?

\[\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({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \left(im\_m \cdot {\left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \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 (pow (/ -1.0 re) 0.16666666666666666) 3.0)
     (*
      im_m
      (pow
       (* (pow 0.5 0.16666666666666666) (pow 2.0 0.16666666666666666))
       3.0))))
   (sqrt (* 0.5 (+ 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(pow((-1.0 / re), 0.16666666666666666), 3.0) * (im_m * pow((pow(0.5, 0.16666666666666666) * pow(2.0, 0.16666666666666666)), 3.0)));
	} else {
		tmp = sqrt((0.5 * (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.pow((-1.0 / re), 0.16666666666666666), 3.0) * (im_m * Math.pow((Math.pow(0.5, 0.16666666666666666) * Math.pow(2.0, 0.16666666666666666)), 3.0)));
	} else {
		tmp = Math.sqrt((0.5 * (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.pow((-1.0 / re), 0.16666666666666666), 3.0) * (im_m * math.pow((math.pow(0.5, 0.16666666666666666) * math.pow(2.0, 0.16666666666666666)), 3.0)))
	else:
		tmp = math.sqrt((0.5 * (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(((Float64(-1.0 / re) ^ 0.16666666666666666) ^ 3.0) * Float64(im_m * (Float64((0.5 ^ 0.16666666666666666) * (2.0 ^ 0.16666666666666666)) ^ 3.0))));
	else
		tmp = sqrt(Float64(0.5 * 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 * ((((-1.0 / re) ^ 0.16666666666666666) ^ 3.0) * (im_m * (((0.5 ^ 0.16666666666666666) * (2.0 ^ 0.16666666666666666)) ^ 3.0)));
	else
		tmp = sqrt((0.5 * (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[Power[N[Power[N[(-1.0 / re), $MachinePrecision], 0.16666666666666666], $MachinePrecision], 3.0], $MachinePrecision] * N[(im$95$m * N[Power[N[(N[Power[0.5, 0.16666666666666666], $MachinePrecision] * N[Power[2.0, 0.16666666666666666], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $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({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \left(im\_m \cdot {\left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)}^{3}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0

    1. Initial program 7.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified13.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative13.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define7.7%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-cube-cbrt7.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right) \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)} \]
      6. pow37.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)}^{3}} \]
      7. +-commutative7.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + im \cdot im}\right)}}}\right)}^{3} \]
      8. hypot-define13.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)}}\right)}^{3} \]
    6. Applied egg-rr13.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}}\right)}^{3}} \]
    7. Taylor expanded in re around -inf 51.5%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt[3]{\sqrt{2}}\right)}}^{3} \]
    8. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}}^{3} \]
      2. distribute-rgt-in51.4%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot e^{\color{blue}{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666 + \log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}}\right)}^{3} \]
      3. exp-sum52.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \color{blue}{\left(e^{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)}\right)}^{3} \]
      4. exp-to-pow51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{{\left(0.5 \cdot {im}^{2}\right)}^{0.16666666666666666}} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      5. *-commutative51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\color{blue}{\left({im}^{2} \cdot 0.5\right)}}^{0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      6. exp-to-pow51.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot \color{blue}{{\left(\frac{-1}{re}\right)}^{0.16666666666666666}}\right)\right)}^{3} \]
    9. Simplified51.8%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}}^{3} \]
    10. Step-by-step derivation
      1. associate-*r*51.8%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\left(\sqrt[3]{\sqrt{2}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right) \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}}^{3} \]
      2. unpow-prod-down51.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left({\left(\sqrt[3]{\sqrt{2}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right)} \]
      3. pow1/351.8%

        \[\leadsto 0.5 \cdot \left({\left(\color{blue}{{\left(\sqrt{2}\right)}^{0.3333333333333333}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      4. sqrt-pow251.8%

        \[\leadsto 0.5 \cdot \left({\left(\color{blue}{{2}^{\left(\frac{0.3333333333333333}{2}\right)}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      5. metadata-eval51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{\color{blue}{0.16666666666666666}} \cdot {\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      6. *-commutative51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot {\color{blue}{\left(0.5 \cdot {im}^{2}\right)}}^{0.16666666666666666}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      7. unpow-prod-down51.8%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \color{blue}{\left({0.5}^{0.16666666666666666} \cdot {\left({im}^{2}\right)}^{0.16666666666666666}\right)}\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      8. pow-pow48.0%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \color{blue}{{im}^{\left(2 \cdot 0.16666666666666666\right)}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      9. metadata-eval48.0%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot {im}^{\color{blue}{0.3333333333333333}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
      10. pow1/351.5%

        \[\leadsto 0.5 \cdot \left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \color{blue}{\sqrt[3]{im}}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right) \]
    11. Applied egg-rr51.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)}^{3} \cdot {\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3}\right)} \]
    12. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\left({2}^{0.16666666666666666} \cdot \left({0.5}^{0.16666666666666666} \cdot \sqrt[3]{im}\right)\right)}^{3}\right)} \]
      2. associate-*r*51.5%

        \[\leadsto 0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot {\color{blue}{\left(\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right) \cdot \sqrt[3]{im}\right)}}^{3}\right) \]
      3. cube-prod51.5%

        \[\leadsto 0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \color{blue}{\left({\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right)}^{3} \cdot {\left(\sqrt[3]{im}\right)}^{3}\right)}\right) \]
      4. rem-cube-cbrt51.4%

        \[\leadsto 0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \left({\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right)}^{3} \cdot \color{blue}{im}\right)\right) \]
    13. Simplified51.4%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \left({\left({2}^{0.16666666666666666} \cdot {0.5}^{0.16666666666666666}\right)}^{3} \cdot im\right)\right)} \]

    if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)

    1. Initial program 45.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define45.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt45.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod45.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative45.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*90.6%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval90.6%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified90.6%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\ \;\;\;\;0.5 \cdot \left({\left({\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)}^{3} \cdot \left(im \cdot {\left({0.5}^{0.16666666666666666} \cdot {2}^{0.16666666666666666}\right)}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 89.6% accurate, 0.4× speedup?

\[\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({\left(\frac{-0.5}{re}\right)}^{0.16666666666666666} \cdot \sqrt[3]{im\_m \cdot \sqrt{2}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \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
     (* (pow (/ -0.5 re) 0.16666666666666666) (cbrt (* im_m (sqrt 2.0))))
     3.0))
   (sqrt (* 0.5 (+ 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((pow((-0.5 / re), 0.16666666666666666) * cbrt((im_m * sqrt(2.0)))), 3.0);
	} else {
		tmp = sqrt((0.5 * (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.pow((-0.5 / re), 0.16666666666666666) * Math.cbrt((im_m * Math.sqrt(2.0)))), 3.0);
	} else {
		tmp = Math.sqrt((0.5 * (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((Float64(-0.5 / re) ^ 0.16666666666666666) * cbrt(Float64(im_m * sqrt(2.0)))) ^ 3.0));
	else
		tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m))));
	end
	return 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[Power[N[(-0.5 / re), $MachinePrecision], 0.16666666666666666], $MachinePrecision] * N[Power[N[(im$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $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({\left(\frac{-0.5}{re}\right)}^{0.16666666666666666} \cdot \sqrt[3]{im\_m \cdot \sqrt{2}}\right)}^{3}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0

    1. Initial program 7.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified13.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative13.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define7.7%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative7.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-cube-cbrt7.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right) \cdot \sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)} \]
      6. pow37.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}\right)}^{3}} \]
      7. +-commutative7.7%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + im \cdot im}\right)}}}\right)}^{3} \]
      8. hypot-define13.5%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)}}\right)}^{3} \]
    6. Applied egg-rr13.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt[3]{\sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}}\right)}^{3}} \]
    7. Taylor expanded in re around -inf 51.5%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt[3]{\sqrt{2}}\right)}}^{3} \]
    8. Step-by-step derivation
      1. *-commutative51.5%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot e^{0.16666666666666666 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}}^{3} \]
      2. distribute-rgt-in51.4%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot e^{\color{blue}{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666 + \log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}}\right)}^{3} \]
      3. exp-sum52.0%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \color{blue}{\left(e^{\log \left(0.5 \cdot {im}^{2}\right) \cdot 0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)}\right)}^{3} \]
      4. exp-to-pow51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left(\color{blue}{{\left(0.5 \cdot {im}^{2}\right)}^{0.16666666666666666}} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      5. *-commutative51.6%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\color{blue}{\left({im}^{2} \cdot 0.5\right)}}^{0.16666666666666666} \cdot e^{\log \left(\frac{-1}{re}\right) \cdot 0.16666666666666666}\right)\right)}^{3} \]
      6. exp-to-pow51.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot \color{blue}{{\left(\frac{-1}{re}\right)}^{0.16666666666666666}}\right)\right)}^{3} \]
    9. Simplified51.8%

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt[3]{\sqrt{2}} \cdot \left({\left({im}^{2} \cdot 0.5\right)}^{0.16666666666666666} \cdot {\left(\frac{-1}{re}\right)}^{0.16666666666666666}\right)\right)}}^{3} \]
    10. Taylor expanded in im around 0 51.4%

      \[\leadsto 0.5 \cdot {\color{blue}{\left({\left(\frac{-0.5}{re}\right)}^{0.16666666666666666} \cdot \sqrt[3]{im \cdot \sqrt{2}}\right)}}^{3} \]

    if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)

    1. Initial program 45.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified90.6%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define45.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative45.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt45.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod45.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative45.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr45.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr90.6%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative90.6%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*90.6%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval90.6%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified90.6%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\ \;\;\;\;0.5 \cdot {\left({\left(\frac{-0.5}{re}\right)}^{0.16666666666666666} \cdot \sqrt[3]{im \cdot \sqrt{2}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.8% accurate, 0.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;\sqrt{\left(re + \sqrt{re \cdot re + im\_m \cdot im\_m}\right) \cdot 2} \leq 0:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{{im\_m}^{2}}{-re}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= (sqrt (* (+ re (sqrt (+ (* re re) (* im_m im_m)))) 2.0)) 0.0)
   (* 0.5 (sqrt (/ (pow im_m 2.0) (- re))))
   (sqrt (* 0.5 (+ re (hypot re im_m))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (sqrt(((re + sqrt(((re * re) + (im_m * im_m)))) * 2.0)) <= 0.0) {
		tmp = 0.5 * sqrt((pow(im_m, 2.0) / -re));
	} else {
		tmp = sqrt((0.5 * (re + hypot(re, im_m))));
	}
	return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (Math.sqrt(((re + Math.sqrt(((re * re) + (im_m * im_m)))) * 2.0)) <= 0.0) {
		tmp = 0.5 * Math.sqrt((Math.pow(im_m, 2.0) / -re));
	} else {
		tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if math.sqrt(((re + math.sqrt(((re * re) + (im_m * im_m)))) * 2.0)) <= 0.0:
		tmp = 0.5 * math.sqrt((math.pow(im_m, 2.0) / -re))
	else:
		tmp = math.sqrt((0.5 * (re + math.hypot(re, im_m))))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (sqrt(Float64(Float64(re + sqrt(Float64(Float64(re * re) + Float64(im_m * im_m)))) * 2.0)) <= 0.0)
		tmp = Float64(0.5 * sqrt(Float64((im_m ^ 2.0) / Float64(-re))));
	else
		tmp = sqrt(Float64(0.5 * 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 (sqrt(((re + sqrt(((re * re) + (im_m * im_m)))) * 2.0)) <= 0.0)
		tmp = 0.5 * sqrt(((im_m ^ 2.0) / -re));
	else
		tmp = sqrt((0.5 * (re + hypot(re, im_m))));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[N[Sqrt[N[(N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(N[Power[im$95$m, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;\sqrt{\left(re + \sqrt{re \cdot re + im\_m \cdot im\_m}\right) \cdot 2} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im\_m}^{2}}{-re}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0

    1. Initial program 8.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in8.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub8.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--8.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative8.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified8.9%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in re around -inf 58.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    6. Step-by-step derivation
      1. mul-1-neg58.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-\frac{{im}^{2}}{re}}} \]
      2. distribute-neg-frac258.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{{im}^{2}}{-re}}} \]
    7. Simplified58.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{{im}^{2}}{-re}}} \]

    if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))

    1. Initial program 44.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in44.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub44.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--44.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative44.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified89.5%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative89.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define44.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative44.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative44.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt44.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod44.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative44.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative44.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr44.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr89.5%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative89.5%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*89.5%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval89.5%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified89.5%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{\left(re + \sqrt{re \cdot re + im \cdot im}\right) \cdot 2} \leq 0:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 79.6% accurate, 1.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 (sqrt (* 0.5 (+ re (hypot re im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	return sqrt((0.5 * (re + hypot(re, im_m))));
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
im_m = math.fabs(im)
def code(re, im_m):
	return math.sqrt((0.5 * (re + math.hypot(re, im_m))))
im_m = abs(im)
function code(re, im_m)
	return sqrt(Float64(0.5 * Float64(re + hypot(re, im_m))))
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = sqrt((0.5 * (re + hypot(re, im_m))));
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}
\end{array}
Derivation
  1. Initial program 40.5%

    \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
  2. Step-by-step derivation
    1. sqr-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
    2. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
    3. sqr-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
    4. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
    5. distribute-rgt-in40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
    6. cancel-sign-sub40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
    7. distribute-rgt-out--40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
    8. sub-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
    9. remove-double-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
    10. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
  3. Simplified79.7%

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. *-commutative79.7%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
    2. hypot-define40.5%

      \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
    3. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
    4. *-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
    5. add-sqr-sqrt40.3%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
    6. sqrt-unprod40.5%

      \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
    7. *-commutative40.5%

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
    8. *-commutative40.5%

      \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
    9. swap-sqr40.5%

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
  6. Applied egg-rr79.7%

    \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
  7. Step-by-step derivation
    1. *-commutative79.7%

      \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
    2. associate-*r*79.7%

      \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    3. metadata-eval79.7%

      \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
  8. Simplified79.7%

    \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  9. Final simplification79.7%

    \[\leadsto \sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
  10. Add Preprocessing

Alternative 8: 63.1% accurate, 1.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -4.5 \cdot 10^{+171}:\\ \;\;\;\;0.5 \cdot \sqrt{0}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot 4 + im\_m \cdot \frac{im\_m}{re}}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= re -4.5e+171)
   (* 0.5 (sqrt 0.0))
   (if (<= re 9e+134)
     (sqrt (* 0.5 (+ re im_m)))
     (* 0.5 (sqrt (+ (* re 4.0) (* im_m (/ im_m re))))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (re <= -4.5e+171) {
		tmp = 0.5 * sqrt(0.0);
	} else if (re <= 9e+134) {
		tmp = sqrt((0.5 * (re + im_m)));
	} else {
		tmp = 0.5 * sqrt(((re * 4.0) + (im_m * (im_m / 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 <= (-4.5d+171)) then
        tmp = 0.5d0 * sqrt(0.0d0)
    else if (re <= 9d+134) then
        tmp = sqrt((0.5d0 * (re + im_m)))
    else
        tmp = 0.5d0 * sqrt(((re * 4.0d0) + (im_m * (im_m / 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 <= -4.5e+171) {
		tmp = 0.5 * Math.sqrt(0.0);
	} else if (re <= 9e+134) {
		tmp = Math.sqrt((0.5 * (re + im_m)));
	} else {
		tmp = 0.5 * Math.sqrt(((re * 4.0) + (im_m * (im_m / re))));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if re <= -4.5e+171:
		tmp = 0.5 * math.sqrt(0.0)
	elif re <= 9e+134:
		tmp = math.sqrt((0.5 * (re + im_m)))
	else:
		tmp = 0.5 * math.sqrt(((re * 4.0) + (im_m * (im_m / re))))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (re <= -4.5e+171)
		tmp = Float64(0.5 * sqrt(0.0));
	elseif (re <= 9e+134)
		tmp = sqrt(Float64(0.5 * Float64(re + im_m)));
	else
		tmp = Float64(0.5 * sqrt(Float64(Float64(re * 4.0) + Float64(im_m * Float64(im_m / re)))));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (re <= -4.5e+171)
		tmp = 0.5 * sqrt(0.0);
	elseif (re <= 9e+134)
		tmp = sqrt((0.5 * (re + im_m)));
	else
		tmp = 0.5 * sqrt(((re * 4.0) + (im_m * (im_m / re))));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[re, -4.5e+171], N[(0.5 * N[Sqrt[0.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9e+134], N[Sqrt[N[(0.5 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[Sqrt[N[(N[(re * 4.0), $MachinePrecision] + N[(im$95$m * N[(im$95$m / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.5 \cdot 10^{+171}:\\
\;\;\;\;0.5 \cdot \sqrt{0}\\

\mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot 4 + im\_m \cdot \frac{im\_m}{re}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -4.49999999999999969e171

    1. Initial program 2.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified31.3%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. hypot-define2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right)} \]
      2. distribute-lft-in2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot re + 2 \cdot \sqrt{re \cdot re + im \cdot im}}} \]
      3. *-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2} + 2 \cdot \sqrt{re \cdot re + im \cdot im}} \]
      4. add-cube-cbrt2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}\right) \cdot \sqrt[3]{re \cdot 2}} + 2 \cdot \sqrt{re \cdot re + im \cdot im}} \]
      5. fma-define2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \sqrt{re \cdot re + im \cdot im}\right)}} \]
      6. hypot-define10.2%

        \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    6. Applied egg-rr10.2%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \mathsf{hypot}\left(re, im\right)\right)}} \]
    7. Taylor expanded in re around -inf 0.0%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \left(re \cdot \left(2 + {\left(\sqrt[3]{-2}\right)}^{3}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*0.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(-1 \cdot re\right) \cdot \left(2 + {\left(\sqrt[3]{-2}\right)}^{3}\right)}} \]
      2. rem-cube-cbrt24.3%

        \[\leadsto 0.5 \cdot \sqrt{\left(-1 \cdot re\right) \cdot \left(2 + \color{blue}{-2}\right)} \]
      3. metadata-eval24.3%

        \[\leadsto 0.5 \cdot \sqrt{\left(-1 \cdot re\right) \cdot \color{blue}{0}} \]
      4. mul0-rgt24.3%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{0}} \]
    9. Simplified24.3%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{0}} \]

    if -4.49999999999999969e171 < re < 8.9999999999999995e134

    1. Initial program 51.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified83.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative83.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define51.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt51.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod51.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative51.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative51.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr51.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr83.0%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative83.0%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*83.0%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval83.0%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified83.0%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    9. Taylor expanded in re around 0 29.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + re\right)}} \]

    if 8.9999999999999995e134 < re

    1. Initial program 9.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 91.3%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{4 \cdot re + \frac{{im}^{2}}{re}}} \]
    6. Step-by-step derivation
      1. unpow291.3%

        \[\leadsto 0.5 \cdot \sqrt{4 \cdot re + \frac{\color{blue}{im \cdot im}}{re}} \]
      2. associate-/l*94.2%

        \[\leadsto 0.5 \cdot \sqrt{4 \cdot re + \color{blue}{im \cdot \frac{im}{re}}} \]
    7. Applied egg-rr94.2%

      \[\leadsto 0.5 \cdot \sqrt{4 \cdot re + \color{blue}{im \cdot \frac{im}{re}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.5 \cdot 10^{+171}:\\ \;\;\;\;0.5 \cdot \sqrt{0}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot 4 + im \cdot \frac{im}{re}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 62.6% accurate, 1.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq 5.8 \cdot 10^{+22} \lor \neg \left(re \leq 1.85 \cdot 10^{+67}\right) \land re \leq 10^{+135}:\\ \;\;\;\;\sqrt{im\_m \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (or (<= re 5.8e+22) (and (not (<= re 1.85e+67)) (<= re 1e+135)))
   (sqrt (* im_m 0.5))
   (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if ((re <= 5.8e+22) || (!(re <= 1.85e+67) && (re <= 1e+135))) {
		tmp = sqrt((im_m * 0.5));
	} 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+22) .or. (.not. (re <= 1.85d+67)) .and. (re <= 1d+135)) then
        tmp = sqrt((im_m * 0.5d0))
    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+22) || (!(re <= 1.85e+67) && (re <= 1e+135))) {
		tmp = Math.sqrt((im_m * 0.5));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if (re <= 5.8e+22) or (not (re <= 1.85e+67) and (re <= 1e+135)):
		tmp = math.sqrt((im_m * 0.5))
	else:
		tmp = math.sqrt(re)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if ((re <= 5.8e+22) || (!(re <= 1.85e+67) && (re <= 1e+135)))
		tmp = sqrt(Float64(im_m * 0.5));
	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+22) || (~((re <= 1.85e+67)) && (re <= 1e+135)))
		tmp = sqrt((im_m * 0.5));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[Or[LessEqual[re, 5.8e+22], And[N[Not[LessEqual[re, 1.85e+67]], $MachinePrecision], LessEqual[re, 1e+135]]], N[Sqrt[N[(im$95$m * 0.5), $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^{+22} \lor \neg \left(re \leq 1.85 \cdot 10^{+67}\right) \land re \leq 10^{+135}:\\
\;\;\;\;\sqrt{im\_m \cdot 0.5}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 5.8e22 or 1.8499999999999999e67 < re < 9.99999999999999962e134

    1. Initial program 44.1%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in44.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub44.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--44.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative44.1%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified75.8%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative75.8%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define44.1%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative44.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative44.1%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt43.8%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod44.1%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative44.1%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative44.1%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr44.1%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr75.8%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative75.8%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*75.8%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval75.8%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified75.8%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    9. Taylor expanded in re around 0 25.7%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{im}} \]

    if 5.8e22 < re < 1.8499999999999999e67 or 9.99999999999999962e134 < re

    1. Initial program 22.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in22.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub22.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--22.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative22.4%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 92.6%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{4 \cdot re + \frac{{im}^{2}}{re}}} \]
    6. Taylor expanded in re around inf 93.7%

      \[\leadsto \color{blue}{\sqrt{re}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification36.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 5.8 \cdot 10^{+22} \lor \neg \left(re \leq 1.85 \cdot 10^{+67}\right) \land re \leq 10^{+135}:\\ \;\;\;\;\sqrt{im \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 63.2% accurate, 1.9× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -2 \cdot 10^{+172}:\\ \;\;\;\;0.5 \cdot \sqrt{0}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= re -2e+172)
   (* 0.5 (sqrt 0.0))
   (if (<= re 9e+134) (sqrt (* 0.5 (+ re im_m))) (sqrt re))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (re <= -2e+172) {
		tmp = 0.5 * sqrt(0.0);
	} else if (re <= 9e+134) {
		tmp = sqrt((0.5 * (re + im_m)));
	} 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+172)) then
        tmp = 0.5d0 * sqrt(0.0d0)
    else if (re <= 9d+134) then
        tmp = sqrt((0.5d0 * (re + im_m)))
    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+172) {
		tmp = 0.5 * Math.sqrt(0.0);
	} else if (re <= 9e+134) {
		tmp = Math.sqrt((0.5 * (re + im_m)));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if re <= -2e+172:
		tmp = 0.5 * math.sqrt(0.0)
	elif re <= 9e+134:
		tmp = math.sqrt((0.5 * (re + im_m)))
	else:
		tmp = math.sqrt(re)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (re <= -2e+172)
		tmp = Float64(0.5 * sqrt(0.0));
	elseif (re <= 9e+134)
		tmp = sqrt(Float64(0.5 * Float64(re + im_m)));
	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+172)
		tmp = 0.5 * sqrt(0.0);
	elseif (re <= 9e+134)
		tmp = sqrt((0.5 * (re + im_m)));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[re, -2e+172], N[(0.5 * N[Sqrt[0.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9e+134], N[Sqrt[N[(0.5 * N[(re + im$95$m), $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^{+172}:\\
\;\;\;\;0.5 \cdot \sqrt{0}\\

\mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -2.0000000000000002e172

    1. Initial program 2.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified31.3%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. hypot-define2.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right)} \]
      2. distribute-lft-in2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot re + 2 \cdot \sqrt{re \cdot re + im \cdot im}}} \]
      3. *-commutative2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2} + 2 \cdot \sqrt{re \cdot re + im \cdot im}} \]
      4. add-cube-cbrt2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}\right) \cdot \sqrt[3]{re \cdot 2}} + 2 \cdot \sqrt{re \cdot re + im \cdot im}} \]
      5. fma-define2.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \sqrt{re \cdot re + im \cdot im}\right)}} \]
      6. hypot-define10.2%

        \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    6. Applied egg-rr10.2%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\sqrt[3]{re \cdot 2} \cdot \sqrt[3]{re \cdot 2}, \sqrt[3]{re \cdot 2}, 2 \cdot \mathsf{hypot}\left(re, im\right)\right)}} \]
    7. Taylor expanded in re around -inf 0.0%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \left(re \cdot \left(2 + {\left(\sqrt[3]{-2}\right)}^{3}\right)\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*0.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(-1 \cdot re\right) \cdot \left(2 + {\left(\sqrt[3]{-2}\right)}^{3}\right)}} \]
      2. rem-cube-cbrt24.3%

        \[\leadsto 0.5 \cdot \sqrt{\left(-1 \cdot re\right) \cdot \left(2 + \color{blue}{-2}\right)} \]
      3. metadata-eval24.3%

        \[\leadsto 0.5 \cdot \sqrt{\left(-1 \cdot re\right) \cdot \color{blue}{0}} \]
      4. mul0-rgt24.3%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{0}} \]
    9. Simplified24.3%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{0}} \]

    if -2.0000000000000002e172 < re < 8.9999999999999995e134

    1. Initial program 51.9%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified83.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-commutative83.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(re + \mathsf{hypot}\left(re, im\right)\right) \cdot 2}} \]
      2. hypot-define51.9%

        \[\leadsto 0.5 \cdot \sqrt{\left(re + \color{blue}{\sqrt{re \cdot re + im \cdot im}}\right) \cdot 2} \]
      3. +-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 2} \]
      4. *-commutative51.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \]
      5. add-sqr-sqrt51.6%

        \[\leadsto \color{blue}{\sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}} \cdot \sqrt{0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}}} \]
      6. sqrt-unprod51.9%

        \[\leadsto \color{blue}{\sqrt{\left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)}} \]
      7. *-commutative51.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)} \cdot \left(0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right)} \]
      8. *-commutative51.9%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right) \cdot \color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot 0.5\right)}} \]
      9. swap-sqr51.9%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\right) \cdot \left(0.5 \cdot 0.5\right)}} \]
    6. Applied egg-rr83.0%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right) \cdot 0.25}} \]
    7. Step-by-step derivation
      1. *-commutative83.0%

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)\right)}} \]
      2. associate-*r*83.0%

        \[\leadsto \sqrt{\color{blue}{\left(0.25 \cdot 2\right) \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
      3. metadata-eval83.0%

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)} \]
    8. Simplified83.0%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    9. Taylor expanded in re around 0 29.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + re\right)}} \]

    if 8.9999999999999995e134 < re

    1. Initial program 9.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. sqr-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
      2. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
      3. sqr-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
      4. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
      5. distribute-rgt-in9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
      6. cancel-sign-sub9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
      7. distribute-rgt-out--9.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
      8. sub-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
      9. remove-double-neg9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
      10. +-commutative9.5%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 91.3%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{4 \cdot re + \frac{{im}^{2}}{re}}} \]
    6. Taylor expanded in re around inf 92.7%

      \[\leadsto \color{blue}{\sqrt{re}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2 \cdot 10^{+172}:\\ \;\;\;\;0.5 \cdot \sqrt{0}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 27.2% accurate, 2.1× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \sqrt{re} \end{array} \]
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}
Derivation
  1. Initial program 40.5%

    \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
  2. Step-by-step derivation
    1. sqr-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{\left(-im\right) \cdot \left(-im\right)}} + re\right)} \]
    2. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \sqrt{re \cdot re + \left(-im\right) \cdot \left(-im\right)}\right)}} \]
    3. sqr-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)} \]
    4. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)} \]
    5. distribute-rgt-in40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 + \sqrt{im \cdot im + re \cdot re} \cdot 2}} \]
    6. cancel-sign-sub40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot 2 - \left(-\sqrt{im \cdot im + re \cdot re}\right) \cdot 2}} \]
    7. distribute-rgt-out--40.5%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot \left(re - \left(-\sqrt{im \cdot im + re \cdot re}\right)\right)}} \]
    8. sub-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + \left(-\left(-\sqrt{im \cdot im + re \cdot re}\right)\right)\right)}} \]
    9. remove-double-neg40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\sqrt{im \cdot im + re \cdot re}}\right)} \]
    10. +-commutative40.5%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)} \]
  3. Simplified79.7%

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in im around 0 26.6%

    \[\leadsto 0.5 \cdot \sqrt{\color{blue}{4 \cdot re + \frac{{im}^{2}}{re}}} \]
  6. Taylor expanded in re around inf 26.8%

    \[\leadsto \color{blue}{\sqrt{re}} \]
  7. Final simplification26.8%

    \[\leadsto \sqrt{re} \]
  8. Add Preprocessing

Developer target: 48.6% accurate, 0.7× speedup?

\[\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} \]
(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}

Reproduce

?
herbie shell --seed 2024109 
(FPCore (re im)
  :name "math.sqrt on complex, real part"
  :precision binary64

  :alt
  (if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))

  (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))