math.sqrt on complex, real part

Percentage Accurate: 42.2% → 87.9%
Time: 11.0s
Alternatives: 9
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 9 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: 42.2% 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: 87.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -6.5 \cdot 10^{-47}:\\
\;\;\;\;{2}^{0.25} \cdot \left(\left(0.5 \cdot \left(im\_m \cdot {\left(\frac{-0.5}{re}\right)}^{0.5}\right)\right) \cdot {2}^{0.25}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -6.5000000000000004e-47

    1. Initial program 10.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. pow1/2N/A

        \[\leadsto \frac{1}{2} \cdot {\left(2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)\right)}^{\color{blue}{\frac{1}{2}}} \]
      2. unpow-prod-downN/A

        \[\leadsto \frac{1}{2} \cdot \left({2}^{\frac{1}{2}} \cdot \color{blue}{{\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}}\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right) \cdot \color{blue}{{\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}} \]
      4. *-commutativeN/A

        \[\leadsto {\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}} \cdot \color{blue}{\left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}\right), \color{blue}{\left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)}\right) \]
      6. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right), \frac{1}{2}\right), \left(\color{blue}{\frac{1}{2}} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(re + \sqrt{re \cdot re + im \cdot im}\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \left(\sqrt{re \cdot re + im \cdot im}\right)\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      9. accelerator-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left({2}^{\frac{1}{2}}\right)}\right)\right) \]
      11. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \left(\sqrt{2}\right)\right)\right) \]
      12. sqrt-lowering-sqrt.f6434.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    4. Applied egg-rr34.1%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{{im}^{2}}{re}\right)}, \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \left(\frac{{im}^{2}}{re}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\left({im}^{2}\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\left(im \cdot im\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      4. *-lowering-*.f6452.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, im\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    7. Simplified52.1%

      \[\leadsto {\color{blue}{\left(-0.5 \cdot \frac{im \cdot im}{re}\right)}}^{0.5} \cdot \left(0.5 \cdot \sqrt{2}\right) \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{im \cdot im}{re} \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{\frac{re}{im \cdot im}} \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\left(\frac{1}{re} \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{re} \cdot \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{re}\right), \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \mathsf{*.f64}\left(\left(im \cdot im\right), \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      10. *-lowering-*.f6452.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    9. Applied egg-rr52.1%

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

        \[\leadsto \left({\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right)}^{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot \color{blue}{\sqrt{2}} \]
      2. pow1/2N/A

        \[\leadsto \left({\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right)}^{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot {2}^{\color{blue}{\frac{1}{2}}} \]
      3. sqr-powN/A

        \[\leadsto \left({\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right)}^{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot \left({2}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \color{blue}{{2}^{\left(\frac{\frac{1}{2}}{2}\right)}}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(\left({\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right)}^{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot {2}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \color{blue}{{2}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\left({\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right)}^{\frac{1}{2}} \cdot \frac{1}{2}\right) \cdot {2}^{\left(\frac{\frac{1}{2}}{2}\right)}\right), \color{blue}{\left({2}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right) \]
    11. Applied egg-rr54.9%

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

    if -6.5000000000000004e-47 < re

    1. Initial program 51.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right), 2\right)\right)\right) \]
      3. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(re + \sqrt{re \cdot re + im \cdot im}\right), 2\right)\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \left(\sqrt{re \cdot re + im \cdot im}\right)\right), 2\right)\right)\right) \]
      5. accelerator-lowering-hypot.f6493.5%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), 2\right)\right)\right) \]
    4. Applied egg-rr93.5%

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

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

Alternative 2: 88.0% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -8.0000000000000001e-51

    1. Initial program 10.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. pow1/2N/A

        \[\leadsto \frac{1}{2} \cdot {\left(2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)\right)}^{\color{blue}{\frac{1}{2}}} \]
      2. unpow-prod-downN/A

        \[\leadsto \frac{1}{2} \cdot \left({2}^{\frac{1}{2}} \cdot \color{blue}{{\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}}\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right) \cdot \color{blue}{{\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}} \]
      4. *-commutativeN/A

        \[\leadsto {\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}} \cdot \color{blue}{\left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({\left(\sqrt{re \cdot re + im \cdot im} + re\right)}^{\frac{1}{2}}\right), \color{blue}{\left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)}\right) \]
      6. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right), \frac{1}{2}\right), \left(\color{blue}{\frac{1}{2}} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(re + \sqrt{re \cdot re + im \cdot im}\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \left(\sqrt{re \cdot re + im \cdot im}\right)\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      9. accelerator-lowering-hypot.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \left(\frac{1}{2} \cdot {2}^{\frac{1}{2}}\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{\left({2}^{\frac{1}{2}}\right)}\right)\right) \]
      11. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \left(\sqrt{2}\right)\right)\right) \]
      12. sqrt-lowering-sqrt.f6434.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    4. Applied egg-rr34.1%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\color{blue}{\left(\frac{-1}{2} \cdot \frac{{im}^{2}}{re}\right)}, \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \left(\frac{{im}^{2}}{re}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\left({im}^{2}\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\left(im \cdot im\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      4. *-lowering-*.f6452.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, im\right), re\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    7. Simplified52.1%

      \[\leadsto {\color{blue}{\left(-0.5 \cdot \frac{im \cdot im}{re}\right)}}^{0.5} \cdot \left(0.5 \cdot \sqrt{2}\right) \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{im \cdot im}{re} \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{\frac{re}{im \cdot im}} \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-/r/N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\left(\frac{1}{re} \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{2}\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\frac{1}{re} \cdot \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{re}\right), \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \left(\frac{-1}{2} \cdot \left(im \cdot im\right)\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \mathsf{*.f64}\left(\left(im \cdot im\right), \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      10. *-lowering-*.f6452.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \frac{-1}{2}\right)\right), \frac{1}{2}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    9. Applied egg-rr52.1%

      \[\leadsto {\color{blue}{\left(\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot -0.5\right)\right)}}^{0.5} \cdot \left(0.5 \cdot \sqrt{2}\right) \]
    10. Step-by-step derivation
      1. unpow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\sqrt{\frac{1}{re} \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right)}\right), \mathsf{*.f64}\left(\color{blue}{\frac{1}{2}}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\sqrt{\left(\left(im \cdot im\right) \cdot \frac{-1}{2}\right) \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\sqrt{\left(im \cdot im\right) \cdot \left(\frac{-1}{2} \cdot \frac{1}{re}\right)}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      4. sqrt-prodN/A

        \[\leadsto \mathsf{*.f64}\left(\left(\sqrt{im \cdot im} \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\color{blue}{\frac{1}{2}}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      5. unpow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\left({\left(im \cdot im\right)}^{\frac{1}{2}} \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      6. pow2N/A

        \[\leadsto \mathsf{*.f64}\left(\left({\left({im}^{2}\right)}^{\frac{1}{2}} \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      7. pow-powN/A

        \[\leadsto \mathsf{*.f64}\left(\left({im}^{\left(2 \cdot \frac{1}{2}\right)} \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\left({im}^{1} \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      9. unpow1N/A

        \[\leadsto \mathsf{*.f64}\left(\left(im \cdot \sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, \left(\sqrt{\frac{-1}{2} \cdot \frac{1}{re}}\right)\right), \mathsf{*.f64}\left(\color{blue}{\frac{1}{2}}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      11. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, \mathsf{sqrt.f64}\left(\left(\frac{-1}{2} \cdot \frac{1}{re}\right)\right)\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      12. un-div-invN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, \mathsf{sqrt.f64}\left(\left(\frac{\frac{-1}{2}}{re}\right)\right)\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      13. /-lowering-/.f6454.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\frac{-1}{2}, re\right)\right)\right), \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    11. Applied egg-rr54.8%

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

    if -8.0000000000000001e-51 < re

    1. Initial program 51.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right), 2\right)\right)\right) \]
      3. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(re + \sqrt{re \cdot re + im \cdot im}\right), 2\right)\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \left(\sqrt{re \cdot re + im \cdot im}\right)\right), 2\right)\right)\right) \]
      5. accelerator-lowering-hypot.f6493.5%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), 2\right)\right)\right) \]
    4. Applied egg-rr93.5%

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

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

Alternative 3: 80.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{-39}:\\
\;\;\;\;0.5 \cdot \sqrt{0 - \frac{im\_m \cdot im\_m}{re}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -3.6000000000000001e-39

    1. Initial program 10.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in re around -inf

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{{im}^{2}}{re}\right)}\right)\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(\mathsf{neg}\left(\frac{{im}^{2}}{re}\right)\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(0 - \frac{{im}^{2}}{re}\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \left(\frac{{im}^{2}}{re}\right)\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left({im}^{2}\right), re\right)\right)\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(im \cdot im\right), re\right)\right)\right)\right) \]
      6. *-lowering-*.f6452.2%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, im\right), re\right)\right)\right)\right) \]
    5. Simplified52.2%

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

    if -3.6000000000000001e-39 < re

    1. Initial program 51.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(\sqrt{re \cdot re + im \cdot im} + re\right), 2\right)\right)\right) \]
      3. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\left(re + \sqrt{re \cdot re + im \cdot im}\right), 2\right)\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \left(\sqrt{re \cdot re + im \cdot im}\right)\right), 2\right)\right)\right) \]
      5. accelerator-lowering-hypot.f6493.5%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right), 2\right)\right)\right) \]
    4. Applied egg-rr93.5%

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

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

Alternative 4: 67.4% accurate, 1.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -3.9 \cdot 10^{-41}:\\ \;\;\;\;0.5 \cdot \sqrt{0 - \frac{im\_m \cdot im\_m}{re}}\\ \mathbf{elif}\;re \leq 1.85 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \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 -3.9e-41)
   (* 0.5 (sqrt (- 0.0 (/ (* im_m im_m) re))))
   (if (<= re 1.85e+140) (* 0.5 (sqrt (* 2.0 (+ re im_m)))) (sqrt re))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (re <= -3.9e-41) {
		tmp = 0.5 * sqrt((0.0 - ((im_m * im_m) / re)));
	} else if (re <= 1.85e+140) {
		tmp = 0.5 * sqrt((2.0 * (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 <= (-3.9d-41)) then
        tmp = 0.5d0 * sqrt((0.0d0 - ((im_m * im_m) / re)))
    else if (re <= 1.85d+140) then
        tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -3.9e-41) {
		tmp = 0.5 * Math.sqrt((0.0 - ((im_m * im_m) / re)));
	} else if (re <= 1.85e+140) {
		tmp = 0.5 * Math.sqrt((2.0 * (re + im_m)));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if re <= -3.9e-41:
		tmp = 0.5 * math.sqrt((0.0 - ((im_m * im_m) / re)))
	elif re <= 1.85e+140:
		tmp = 0.5 * math.sqrt((2.0 * (re + im_m)))
	else:
		tmp = math.sqrt(re)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (re <= -3.9e-41)
		tmp = Float64(0.5 * sqrt(Float64(0.0 - Float64(Float64(im_m * im_m) / re))));
	elseif (re <= 1.85e+140)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -3.9e-41)
		tmp = 0.5 * sqrt((0.0 - ((im_m * im_m) / re)));
	elseif (re <= 1.85e+140)
		tmp = 0.5 * sqrt((2.0 * (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, -3.9e-41], N[(0.5 * N[Sqrt[N[(0.0 - N[(N[(im$95$m * im$95$m), $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.85e+140], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.9 \cdot 10^{-41}:\\
\;\;\;\;0.5 \cdot \sqrt{0 - \frac{im\_m \cdot im\_m}{re}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -3.89999999999999991e-41

    1. Initial program 10.3%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in re around -inf

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{{im}^{2}}{re}\right)}\right)\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(\mathsf{neg}\left(\frac{{im}^{2}}{re}\right)\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(0 - \frac{{im}^{2}}{re}\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \left(\frac{{im}^{2}}{re}\right)\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left({im}^{2}\right), re\right)\right)\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(im \cdot im\right), re\right)\right)\right)\right) \]
      6. *-lowering-*.f6452.2%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, im\right), re\right)\right)\right)\right) \]
    5. Simplified52.2%

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

    if -3.89999999999999991e-41 < re < 1.85000000000000001e140

    1. Initial program 58.8%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(\color{blue}{im}, re\right)\right)\right)\right) \]
    4. Step-by-step derivation
      1. Simplified41.7%

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

      if 1.85000000000000001e140 < re

      1. Initial program 18.8%

        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in re around inf

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
        2. unpow2N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
        3. rem-square-sqrtN/A

          \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
        4. associate-*r*N/A

          \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
        5. metadata-evalN/A

          \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
        6. *-lft-identityN/A

          \[\leadsto \sqrt{re} \]
        7. sqrt-lowering-sqrt.f6485.1%

          \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
      5. Simplified85.1%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    5. Recombined 3 regimes into one program.
    6. Final simplification50.5%

      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.9 \cdot 10^{-41}:\\ \;\;\;\;0.5 \cdot \sqrt{0 - \frac{im \cdot im}{re}}\\ \mathbf{elif}\;re \leq 1.85 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 5: 64.3% accurate, 1.8× speedup?

    \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -7.5 \cdot 10^{+159}:\\ \;\;\;\;0.5 \cdot {\left(\left(im\_m \cdot im\_m\right) \cdot 4\right)}^{0.25}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \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 -7.5e+159)
       (* 0.5 (pow (* (* im_m im_m) 4.0) 0.25))
       (if (<= re 2.1e+140) (* 0.5 (sqrt (* 2.0 (+ re im_m)))) (sqrt re))))
    im_m = fabs(im);
    double code(double re, double im_m) {
    	double tmp;
    	if (re <= -7.5e+159) {
    		tmp = 0.5 * pow(((im_m * im_m) * 4.0), 0.25);
    	} else if (re <= 2.1e+140) {
    		tmp = 0.5 * sqrt((2.0 * (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 <= (-7.5d+159)) then
            tmp = 0.5d0 * (((im_m * im_m) * 4.0d0) ** 0.25d0)
        else if (re <= 2.1d+140) then
            tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -7.5e+159) {
    		tmp = 0.5 * Math.pow(((im_m * im_m) * 4.0), 0.25);
    	} else if (re <= 2.1e+140) {
    		tmp = 0.5 * Math.sqrt((2.0 * (re + im_m)));
    	} else {
    		tmp = Math.sqrt(re);
    	}
    	return tmp;
    }
    
    im_m = math.fabs(im)
    def code(re, im_m):
    	tmp = 0
    	if re <= -7.5e+159:
    		tmp = 0.5 * math.pow(((im_m * im_m) * 4.0), 0.25)
    	elif re <= 2.1e+140:
    		tmp = 0.5 * math.sqrt((2.0 * (re + im_m)))
    	else:
    		tmp = math.sqrt(re)
    	return tmp
    
    im_m = abs(im)
    function code(re, im_m)
    	tmp = 0.0
    	if (re <= -7.5e+159)
    		tmp = Float64(0.5 * (Float64(Float64(im_m * im_m) * 4.0) ^ 0.25));
    	elseif (re <= 2.1e+140)
    		tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -7.5e+159)
    		tmp = 0.5 * (((im_m * im_m) * 4.0) ^ 0.25);
    	elseif (re <= 2.1e+140)
    		tmp = 0.5 * sqrt((2.0 * (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, -7.5e+159], N[(0.5 * N[Power[N[(N[(im$95$m * im$95$m), $MachinePrecision] * 4.0), $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e+140], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
    
    \begin{array}{l}
    im_m = \left|im\right|
    
    \\
    \begin{array}{l}
    \mathbf{if}\;re \leq -7.5 \cdot 10^{+159}:\\
    \;\;\;\;0.5 \cdot {\left(\left(im\_m \cdot im\_m\right) \cdot 4\right)}^{0.25}\\
    
    \mathbf{elif}\;re \leq 2.1 \cdot 10^{+140}:\\
    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\_m\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{re}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if re < -7.4999999999999997e159

      1. Initial program 2.8%

        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in re around 0

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(2 \cdot im\right)}\right)\right) \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(im \cdot 2\right)\right)\right) \]
        2. *-lowering-*.f645.7%

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(im, 2\right)\right)\right) \]
      5. Simplified5.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
      6. Step-by-step derivation
        1. pow1/2N/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(im \cdot 2\right)}^{\color{blue}{\frac{1}{2}}}\right)\right) \]
        2. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(im \cdot 2\right)}^{\left(\frac{1}{4} + \color{blue}{\frac{1}{4}}\right)}\right)\right) \]
        3. pow-prod-upN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(im \cdot 2\right)}^{\frac{1}{4}} \cdot \color{blue}{{\left(im \cdot 2\right)}^{\frac{1}{4}}}\right)\right) \]
        4. pow-prod-downN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(\left(im \cdot 2\right) \cdot \left(im \cdot 2\right)\right)}^{\color{blue}{\frac{1}{4}}}\right)\right) \]
        5. pow-lowering-pow.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\left(\left(im \cdot 2\right) \cdot \left(im \cdot 2\right)\right), \color{blue}{\frac{1}{4}}\right)\right) \]
        6. swap-sqrN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\left(\left(im \cdot im\right) \cdot \left(2 \cdot 2\right)\right), \frac{1}{4}\right)\right) \]
        7. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\left(\left(im \cdot im\right) \cdot 4\right), \frac{1}{4}\right)\right) \]
        8. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\left(\left(im \cdot im\right) \cdot \left(2 + 2\right)\right), \frac{1}{4}\right)\right) \]
        9. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(im \cdot im\right), \left(2 + 2\right)\right), \frac{1}{4}\right)\right) \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \left(2 + 2\right)\right), \frac{1}{4}\right)\right) \]
        11. metadata-eval19.7%

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), 4\right), \frac{1}{4}\right)\right) \]
      7. Applied egg-rr19.7%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\left(im \cdot im\right) \cdot 4\right)}^{0.25}} \]

      if -7.4999999999999997e159 < re < 2.1000000000000002e140

      1. Initial program 50.7%

        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
      2. Add Preprocessing
      3. Taylor expanded in re around 0

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(\color{blue}{im}, re\right)\right)\right)\right) \]
      4. Step-by-step derivation
        1. Simplified36.5%

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

        if 2.1000000000000002e140 < re

        1. Initial program 18.8%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in re around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
          2. unpow2N/A

            \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
          3. rem-square-sqrtN/A

            \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
          4. associate-*r*N/A

            \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
          5. metadata-evalN/A

            \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
          6. *-lft-identityN/A

            \[\leadsto \sqrt{re} \]
          7. sqrt-lowering-sqrt.f6485.1%

            \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
        5. Simplified85.1%

          \[\leadsto \color{blue}{\sqrt{re}} \]
      5. Recombined 3 regimes into one program.
      6. Final simplification40.0%

        \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -7.5 \cdot 10^{+159}:\\ \;\;\;\;0.5 \cdot {\left(\left(im \cdot im\right) \cdot 4\right)}^{0.25}\\ \mathbf{elif}\;re \leq 2.1 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
      7. Add Preprocessing

      Alternative 6: 64.2% accurate, 1.8× speedup?

      \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -2.25 \cdot 10^{-135}:\\ \;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\ \mathbf{elif}\;re \leq 1.85 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \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 -2.25e-135)
         (* 0.5 (sqrt (* im_m 2.0)))
         (if (<= re 1.85e+140) (* 0.5 (sqrt (* 2.0 (+ re im_m)))) (sqrt re))))
      im_m = fabs(im);
      double code(double re, double im_m) {
      	double tmp;
      	if (re <= -2.25e-135) {
      		tmp = 0.5 * sqrt((im_m * 2.0));
      	} else if (re <= 1.85e+140) {
      		tmp = 0.5 * sqrt((2.0 * (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 <= (-2.25d-135)) then
              tmp = 0.5d0 * sqrt((im_m * 2.0d0))
          else if (re <= 1.85d+140) then
              tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -2.25e-135) {
      		tmp = 0.5 * Math.sqrt((im_m * 2.0));
      	} else if (re <= 1.85e+140) {
      		tmp = 0.5 * Math.sqrt((2.0 * (re + im_m)));
      	} else {
      		tmp = Math.sqrt(re);
      	}
      	return tmp;
      }
      
      im_m = math.fabs(im)
      def code(re, im_m):
      	tmp = 0
      	if re <= -2.25e-135:
      		tmp = 0.5 * math.sqrt((im_m * 2.0))
      	elif re <= 1.85e+140:
      		tmp = 0.5 * math.sqrt((2.0 * (re + im_m)))
      	else:
      		tmp = math.sqrt(re)
      	return tmp
      
      im_m = abs(im)
      function code(re, im_m)
      	tmp = 0.0
      	if (re <= -2.25e-135)
      		tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0)));
      	elseif (re <= 1.85e+140)
      		tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -2.25e-135)
      		tmp = 0.5 * sqrt((im_m * 2.0));
      	elseif (re <= 1.85e+140)
      		tmp = 0.5 * sqrt((2.0 * (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, -2.25e-135], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.85e+140], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
      
      \begin{array}{l}
      im_m = \left|im\right|
      
      \\
      \begin{array}{l}
      \mathbf{if}\;re \leq -2.25 \cdot 10^{-135}:\\
      \;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\
      
      \mathbf{elif}\;re \leq 1.85 \cdot 10^{+140}:\\
      \;\;\;\;0.5 \cdot \sqrt{2 \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.24999999999999994e-135

        1. Initial program 16.4%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in re around 0

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(2 \cdot im\right)}\right)\right) \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(im \cdot 2\right)\right)\right) \]
          2. *-lowering-*.f6415.5%

            \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(im, 2\right)\right)\right) \]
        5. Simplified15.5%

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

        if -2.24999999999999994e-135 < re < 1.85000000000000001e140

        1. Initial program 60.4%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in re around 0

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(\color{blue}{im}, re\right)\right)\right)\right) \]
        4. Step-by-step derivation
          1. Simplified43.0%

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

          if 1.85000000000000001e140 < re

          1. Initial program 18.8%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in re around inf

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
            2. unpow2N/A

              \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
            3. rem-square-sqrtN/A

              \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
            4. associate-*r*N/A

              \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
            5. metadata-evalN/A

              \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
            6. *-lft-identityN/A

              \[\leadsto \sqrt{re} \]
            7. sqrt-lowering-sqrt.f6485.1%

              \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
          5. Simplified85.1%

            \[\leadsto \color{blue}{\sqrt{re}} \]
        5. Recombined 3 regimes into one program.
        6. Final simplification38.2%

          \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.25 \cdot 10^{-135}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;re \leq 1.85 \cdot 10^{+140}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
        7. Add Preprocessing

        Alternative 7: 62.8% accurate, 1.9× speedup?

        \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq 2.4 \cdot 10^{+124}:\\ \;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
        im_m = (fabs.f64 im)
        (FPCore (re im_m)
         :precision binary64
         (if (<= re 2.4e+124) (* 0.5 (sqrt (* im_m 2.0))) (sqrt re)))
        im_m = fabs(im);
        double code(double re, double im_m) {
        	double tmp;
        	if (re <= 2.4e+124) {
        		tmp = 0.5 * sqrt((im_m * 2.0));
        	} else {
        		tmp = sqrt(re);
        	}
        	return tmp;
        }
        
        im_m = abs(im)
        real(8) function code(re, im_m)
            real(8), intent (in) :: re
            real(8), intent (in) :: im_m
            real(8) :: tmp
            if (re <= 2.4d+124) then
                tmp = 0.5d0 * sqrt((im_m * 2.0d0))
            else
                tmp = sqrt(re)
            end if
            code = tmp
        end function
        
        im_m = Math.abs(im);
        public static double code(double re, double im_m) {
        	double tmp;
        	if (re <= 2.4e+124) {
        		tmp = 0.5 * Math.sqrt((im_m * 2.0));
        	} else {
        		tmp = Math.sqrt(re);
        	}
        	return tmp;
        }
        
        im_m = math.fabs(im)
        def code(re, im_m):
        	tmp = 0
        	if re <= 2.4e+124:
        		tmp = 0.5 * math.sqrt((im_m * 2.0))
        	else:
        		tmp = math.sqrt(re)
        	return tmp
        
        im_m = abs(im)
        function code(re, im_m)
        	tmp = 0.0
        	if (re <= 2.4e+124)
        		tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0)));
        	else
        		tmp = sqrt(re);
        	end
        	return tmp
        end
        
        im_m = abs(im);
        function tmp_2 = code(re, im_m)
        	tmp = 0.0;
        	if (re <= 2.4e+124)
        		tmp = 0.5 * sqrt((im_m * 2.0));
        	else
        		tmp = sqrt(re);
        	end
        	tmp_2 = tmp;
        end
        
        im_m = N[Abs[im], $MachinePrecision]
        code[re_, im$95$m_] := If[LessEqual[re, 2.4e+124], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
        
        \begin{array}{l}
        im_m = \left|im\right|
        
        \\
        \begin{array}{l}
        \mathbf{if}\;re \leq 2.4 \cdot 10^{+124}:\\
        \;\;\;\;0.5 \cdot \sqrt{im\_m \cdot 2}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sqrt{re}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if re < 2.40000000000000006e124

          1. Initial program 41.4%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in re around 0

            \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(2 \cdot im\right)}\right)\right) \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\left(im \cdot 2\right)\right)\right) \]
            2. *-lowering-*.f6428.5%

              \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(im, 2\right)\right)\right) \]
          5. Simplified28.5%

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

          if 2.40000000000000006e124 < re

          1. Initial program 22.4%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in re around inf

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
            2. unpow2N/A

              \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
            3. rem-square-sqrtN/A

              \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
            4. associate-*r*N/A

              \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
            5. metadata-evalN/A

              \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
            6. *-lft-identityN/A

              \[\leadsto \sqrt{re} \]
            7. sqrt-lowering-sqrt.f6481.8%

              \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
          5. Simplified81.8%

            \[\leadsto \color{blue}{\sqrt{re}} \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 8: 28.5% accurate, 2.0× speedup?

        \[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\ \;\;\;\;{\left(re \cdot re\right)}^{0.25}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
        im_m = (fabs.f64 im)
        (FPCore (re im_m)
         :precision binary64
         (if (<= re -5e-310) (pow (* re re) 0.25) (sqrt re)))
        im_m = fabs(im);
        double code(double re, double im_m) {
        	double tmp;
        	if (re <= -5e-310) {
        		tmp = pow((re * re), 0.25);
        	} else {
        		tmp = sqrt(re);
        	}
        	return tmp;
        }
        
        im_m = abs(im)
        real(8) function code(re, im_m)
            real(8), intent (in) :: re
            real(8), intent (in) :: im_m
            real(8) :: tmp
            if (re <= (-5d-310)) then
                tmp = (re * re) ** 0.25d0
            else
                tmp = sqrt(re)
            end if
            code = tmp
        end function
        
        im_m = Math.abs(im);
        public static double code(double re, double im_m) {
        	double tmp;
        	if (re <= -5e-310) {
        		tmp = Math.pow((re * re), 0.25);
        	} else {
        		tmp = Math.sqrt(re);
        	}
        	return tmp;
        }
        
        im_m = math.fabs(im)
        def code(re, im_m):
        	tmp = 0
        	if re <= -5e-310:
        		tmp = math.pow((re * re), 0.25)
        	else:
        		tmp = math.sqrt(re)
        	return tmp
        
        im_m = abs(im)
        function code(re, im_m)
        	tmp = 0.0
        	if (re <= -5e-310)
        		tmp = Float64(re * re) ^ 0.25;
        	else
        		tmp = sqrt(re);
        	end
        	return tmp
        end
        
        im_m = abs(im);
        function tmp_2 = code(re, im_m)
        	tmp = 0.0;
        	if (re <= -5e-310)
        		tmp = (re * re) ^ 0.25;
        	else
        		tmp = sqrt(re);
        	end
        	tmp_2 = tmp;
        end
        
        im_m = N[Abs[im], $MachinePrecision]
        code[re_, im$95$m_] := If[LessEqual[re, -5e-310], N[Power[N[(re * re), $MachinePrecision], 0.25], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
        
        \begin{array}{l}
        im_m = \left|im\right|
        
        \\
        \begin{array}{l}
        \mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
        \;\;\;\;{\left(re \cdot re\right)}^{0.25}\\
        
        \mathbf{else}:\\
        \;\;\;\;\sqrt{re}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if re < -4.999999999999985e-310

          1. Initial program 25.3%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in re around inf

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
            2. unpow2N/A

              \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
            3. rem-square-sqrtN/A

              \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
            4. associate-*r*N/A

              \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
            5. metadata-evalN/A

              \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
            6. *-lft-identityN/A

              \[\leadsto \sqrt{re} \]
            7. sqrt-lowering-sqrt.f640.0%

              \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
          5. Simplified0.0%

            \[\leadsto \color{blue}{\sqrt{re}} \]
          6. Step-by-step derivation
            1. pow1/2N/A

              \[\leadsto {re}^{\color{blue}{\frac{1}{2}}} \]
            2. sqr-powN/A

              \[\leadsto {re}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \color{blue}{{re}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
            3. pow-prod-downN/A

              \[\leadsto {\left(re \cdot re\right)}^{\color{blue}{\left(\frac{\frac{1}{2}}{2}\right)}} \]
            4. pow-lowering-pow.f64N/A

              \[\leadsto \mathsf{pow.f64}\left(\left(re \cdot re\right), \color{blue}{\left(\frac{\frac{1}{2}}{2}\right)}\right) \]
            5. *-lowering-*.f64N/A

              \[\leadsto \mathsf{pow.f64}\left(\mathsf{*.f64}\left(re, re\right), \left(\frac{\color{blue}{\frac{1}{2}}}{2}\right)\right) \]
            6. metadata-eval4.4%

              \[\leadsto \mathsf{pow.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right) \]
          7. Applied egg-rr4.4%

            \[\leadsto \color{blue}{{\left(re \cdot re\right)}^{0.25}} \]

          if -4.999999999999985e-310 < re

          1. Initial program 51.4%

            \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in re around inf

            \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
            2. unpow2N/A

              \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
            3. rem-square-sqrtN/A

              \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
            4. associate-*r*N/A

              \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
            5. metadata-evalN/A

              \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
            6. *-lft-identityN/A

              \[\leadsto \sqrt{re} \]
            7. sqrt-lowering-sqrt.f6445.0%

              \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
          5. Simplified45.0%

            \[\leadsto \color{blue}{\sqrt{re}} \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 9: 26.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 38.7%

          \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in re around inf

          \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \color{blue}{\sqrt{re}}\right) \]
          2. unpow2N/A

            \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{re}}\right) \]
          3. rem-square-sqrtN/A

            \[\leadsto \frac{1}{2} \cdot \left(2 \cdot \sqrt{\color{blue}{re}}\right) \]
          4. associate-*r*N/A

            \[\leadsto \left(\frac{1}{2} \cdot 2\right) \cdot \color{blue}{\sqrt{re}} \]
          5. metadata-evalN/A

            \[\leadsto 1 \cdot \sqrt{\color{blue}{re}} \]
          6. *-lft-identityN/A

            \[\leadsto \sqrt{re} \]
          7. sqrt-lowering-sqrt.f6423.0%

            \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
        5. Simplified23.0%

          \[\leadsto \color{blue}{\sqrt{re}} \]
        6. Add Preprocessing

        Developer Target 1: 49.3% 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 2024192 
        (FPCore (re im)
          :name "math.sqrt on complex, real part"
          :precision binary64
        
          :alt
          (! :herbie-platform default (if (< re 0) (* 1/2 (* (sqrt 2) (sqrt (/ (* im im) (- (modulus re im) re))))) (* 1/2 (sqrt (* 2 (+ (modulus re im) re))))))
        
          (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))