math.sqrt on complex, real part

Percentage Accurate: 40.9% → 90.5%
Time: 9.9s
Alternatives: 6
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 6 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: 40.9% 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: 90.5% accurate, 0.5× speedup?

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

    1. Initial program 9.8%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified9.8%

      \[\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

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)}\right)\right) \]
    6. 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{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)\right)\right)\right) \]
      2. distribute-neg-frac2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(im, im\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(im, 4\right), \frac{-1}{4}\right), \mathsf{*.f64}\left(re, re\right)\right)\right), \left(0 - re\right)\right)\right)\right) \]
      18. --lowering--.f6450.9%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(im, im\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(im, 4\right), \frac{-1}{4}\right), \mathsf{*.f64}\left(re, re\right)\right)\right), \mathsf{\_.f64}\left(0, re\right)\right)\right)\right) \]
    7. Simplified50.9%

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im + \frac{{im}^{4} \cdot -0.25}{re \cdot re}}{0 - re}}} \]
    8. Taylor expanded in im around 0

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\left({im}^{2}\right)}, \mathsf{\_.f64}\left(0, re\right)\right)\right)\right) \]
    9. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{im \cdot im}}{0 - re}} \]
    11. Step-by-step derivation
      1. clear-numN/A

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(0 - re\right)}^{\frac{-1}{2}} \cdot \left(\sqrt{im} \cdot \color{blue}{\sqrt{im}}\right)\right)\right) \]
      8. rem-square-sqrtN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(0 - re\right), \frac{-1}{2}\right), im\right)\right) \]
      11. --lowering--.f6452.7%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{\_.f64}\left(0, re\right), \frac{-1}{2}\right), im\right)\right) \]
    12. Applied egg-rr52.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left(0 - re\right)}^{-0.5} \cdot im\right)} \]
    13. Step-by-step derivation
      1. neg-sub0N/A

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

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

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

    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.1%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified88.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\ \;\;\;\;0.5 \cdot \left(im \cdot {\left(0 - re\right)}^{-0.5}\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: 75.8% accurate, 1.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -4.8 \cdot 10^{-32}:\\ \;\;\;\;\frac{im\_m \cdot 0.5}{{\left(0 - re\right)}^{0.5}}\\ \mathbf{elif}\;re \leq 3.9 \cdot 10^{-22}:\\ \;\;\;\;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 -4.8e-32)
   (/ (* im_m 0.5) (pow (- 0.0 re) 0.5))
   (if (<= re 3.9e-22) (* 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 <= -4.8e-32) {
		tmp = (im_m * 0.5) / pow((0.0 - re), 0.5);
	} else if (re <= 3.9e-22) {
		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 <= (-4.8d-32)) then
        tmp = (im_m * 0.5d0) / ((0.0d0 - re) ** 0.5d0)
    else if (re <= 3.9d-22) 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 <= -4.8e-32) {
		tmp = (im_m * 0.5) / Math.pow((0.0 - re), 0.5);
	} else if (re <= 3.9e-22) {
		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 <= -4.8e-32:
		tmp = (im_m * 0.5) / math.pow((0.0 - re), 0.5)
	elif re <= 3.9e-22:
		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 <= -4.8e-32)
		tmp = Float64(Float64(im_m * 0.5) / (Float64(0.0 - re) ^ 0.5));
	elseif (re <= 3.9e-22)
		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 <= -4.8e-32)
		tmp = (im_m * 0.5) / ((0.0 - re) ^ 0.5);
	elseif (re <= 3.9e-22)
		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, -4.8e-32], N[(N[(im$95$m * 0.5), $MachinePrecision] / N[Power[N[(0.0 - re), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.9e-22], 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 -4.8 \cdot 10^{-32}:\\
\;\;\;\;\frac{im\_m \cdot 0.5}{{\left(0 - re\right)}^{0.5}}\\

\mathbf{elif}\;re \leq 3.9 \cdot 10^{-22}:\\
\;\;\;\;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 < -4.8000000000000003e-32

    1. Initial program 12.7%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified30.6%

      \[\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

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)}\right)\right) \]
    6. 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{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)\right)\right)\right) \]
      2. distribute-neg-frac2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im + \frac{{im}^{4} \cdot -0.25}{re \cdot re}}{0 - re}}} \]
    8. Taylor expanded in im around 0

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\left({im}^{2}\right)}, \mathsf{\_.f64}\left(0, re\right)\right)\right)\right) \]
    9. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{im \cdot im}}{0 - re}} \]
    11. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \sqrt{\frac{im \cdot im}{0 - re}} \cdot \color{blue}{\frac{1}{2}} \]
      2. sqrt-divN/A

        \[\leadsto \frac{\sqrt{im \cdot im}}{\sqrt{0 - re}} \cdot \frac{1}{2} \]
      3. pow1/2N/A

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\left(\left(\sqrt{im} \cdot \sqrt{im}\right) \cdot \frac{1}{2}\right), \left(\sqrt{\color{blue}{0} - re}\right)\right) \]
      8. rem-square-sqrtN/A

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, \frac{1}{2}\right), \mathsf{pow.f64}\left(\left(0 - re\right), \color{blue}{\frac{1}{2}}\right)\right) \]
      12. --lowering--.f6441.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, \frac{1}{2}\right), \mathsf{pow.f64}\left(\mathsf{\_.f64}\left(0, re\right), \frac{1}{2}\right)\right) \]
    12. Applied egg-rr41.0%

      \[\leadsto \color{blue}{\frac{im \cdot 0.5}{{\left(0 - re\right)}^{0.5}}} \]
    13. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, \frac{1}{2}\right), \mathsf{pow.f64}\left(\left(\mathsf{neg}\left(re\right)\right), \frac{1}{2}\right)\right) \]
      2. neg-lowering-neg.f6441.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(im, \frac{1}{2}\right), \mathsf{pow.f64}\left(\mathsf{neg.f64}\left(re\right), \frac{1}{2}\right)\right) \]
    14. Applied egg-rr41.0%

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

    if -4.8000000000000003e-32 < re < 3.89999999999999998e-22

    1. Initial program 55.4%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified90.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 re around 0

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \left(im + re\right)\right)\right)\right) \]
      3. +-lowering-+.f6444.6%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(im, re\right)\right)\right)\right) \]
    7. Simplified44.6%

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

    if 3.89999999999999998e-22 < re

    1. Initial program 40.6%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\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 re around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
    6. 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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
      7. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{*.f64}\left(1, \mathsf{sqrt.f64}\left(re\right)\right) \]
    7. Simplified76.6%

      \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
    8. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto \sqrt{re} \]
      2. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
    9. Applied egg-rr76.6%

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

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

Alternative 3: 75.8% accurate, 1.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -1.2 \cdot 10^{-29}:\\ \;\;\;\;0.5 \cdot \left(im\_m \cdot {\left(0 - re\right)}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 3.6 \cdot 10^{-22}:\\ \;\;\;\;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 -1.2e-29)
   (* 0.5 (* im_m (pow (- 0.0 re) -0.5)))
   (if (<= re 3.6e-22) (* 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 <= -1.2e-29) {
		tmp = 0.5 * (im_m * pow((0.0 - re), -0.5));
	} else if (re <= 3.6e-22) {
		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 <= (-1.2d-29)) then
        tmp = 0.5d0 * (im_m * ((0.0d0 - re) ** (-0.5d0)))
    else if (re <= 3.6d-22) 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 <= -1.2e-29) {
		tmp = 0.5 * (im_m * Math.pow((0.0 - re), -0.5));
	} else if (re <= 3.6e-22) {
		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 <= -1.2e-29:
		tmp = 0.5 * (im_m * math.pow((0.0 - re), -0.5))
	elif re <= 3.6e-22:
		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 <= -1.2e-29)
		tmp = Float64(0.5 * Float64(im_m * (Float64(0.0 - re) ^ -0.5)));
	elseif (re <= 3.6e-22)
		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 <= -1.2e-29)
		tmp = 0.5 * (im_m * ((0.0 - re) ^ -0.5));
	elseif (re <= 3.6e-22)
		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, -1.2e-29], N[(0.5 * N[(im$95$m * N[Power[N[(0.0 - re), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.6e-22], 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 -1.2 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot {\left(0 - re\right)}^{-0.5}\right)\\

\mathbf{elif}\;re \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;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 < -1.19999999999999996e-29

    1. Initial program 12.7%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified30.6%

      \[\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

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(-1 \cdot \frac{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)}\right)\right) \]
    6. 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{\frac{-1}{4} \cdot \frac{{im}^{4}}{{re}^{2}} + {im}^{2}}{re}\right)\right)\right)\right) \]
      2. distribute-neg-frac2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im + \frac{{im}^{4} \cdot -0.25}{re \cdot re}}{0 - re}}} \]
    8. Taylor expanded in im around 0

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{/.f64}\left(\color{blue}{\left({im}^{2}\right)}, \mathsf{\_.f64}\left(0, re\right)\right)\right)\right) \]
    9. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{im \cdot im}}{0 - re}} \]
    11. Step-by-step derivation
      1. clear-numN/A

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \left({\left(0 - re\right)}^{\frac{-1}{2}} \cdot \left(\sqrt{im} \cdot \color{blue}{\sqrt{im}}\right)\right)\right) \]
      8. rem-square-sqrtN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(0 - re\right), \frac{-1}{2}\right), im\right)\right) \]
      11. --lowering--.f6440.9%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{\_.f64}\left(0, re\right), \frac{-1}{2}\right), im\right)\right) \]
    12. Applied egg-rr40.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left(0 - re\right)}^{-0.5} \cdot im\right)} \]
    13. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{pow.f64}\left(\left(\mathsf{neg}\left(re\right)\right), \frac{-1}{2}\right), im\right)\right) \]
      2. neg-lowering-neg.f6440.9%

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

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

    if -1.19999999999999996e-29 < re < 3.5999999999999998e-22

    1. Initial program 55.4%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified90.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 re around 0

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \left(im + re\right)\right)\right)\right) \]
      3. +-lowering-+.f6444.6%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(im, re\right)\right)\right)\right) \]
    7. Simplified44.6%

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

    if 3.5999999999999998e-22 < re

    1. Initial program 40.6%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\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 re around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
    6. 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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
      7. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{*.f64}\left(1, \mathsf{sqrt.f64}\left(re\right)\right) \]
    7. Simplified76.6%

      \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
    8. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto \sqrt{re} \]
      2. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
    9. Applied egg-rr76.6%

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

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

Alternative 4: 64.1% accurate, 1.9× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq 3.5 \cdot 10^{-22}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im\_m}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= re 3.5e-22) (* 0.5 (sqrt (* 2.0 im_m))) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (re <= 3.5e-22) {
		tmp = 0.5 * sqrt((2.0 * 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.5d-22) then
        tmp = 0.5d0 * sqrt((2.0d0 * 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.5e-22) {
		tmp = 0.5 * Math.sqrt((2.0 * im_m));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if re <= 3.5e-22:
		tmp = 0.5 * math.sqrt((2.0 * im_m))
	else:
		tmp = math.sqrt(re)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (re <= 3.5e-22)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * 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.5e-22)
		tmp = 0.5 * sqrt((2.0 * 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.5e-22], N[(0.5 * N[Sqrt[N[(2.0 * 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 3.5 \cdot 10^{-22}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im\_m}\\

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


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

    1. Initial program 38.0%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified65.8%

      \[\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 0

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\color{blue}{\left(2 \cdot im\right)}\right)\right) \]
    6. 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-*.f6432.8%

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

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

    if 3.50000000000000005e-22 < re

    1. Initial program 40.6%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\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 re around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
    6. 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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
      7. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{*.f64}\left(1, \mathsf{sqrt.f64}\left(re\right)\right) \]
    7. Simplified76.6%

      \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
    8. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto \sqrt{re} \]
      2. sqrt-lowering-sqrt.f6476.6%

        \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
    9. Applied egg-rr76.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 3.5 \cdot 10^{-22}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 28.8% accurate, 2.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{0 - re}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= re -5e-310) (sqrt (- 0.0 re)) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (re <= -5e-310) {
		tmp = sqrt((0.0 - re));
	} 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 = sqrt((0.0d0 - re))
    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.sqrt((0.0 - re));
	} 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.sqrt((0.0 - re))
	else:
		tmp = math.sqrt(re)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (re <= -5e-310)
		tmp = sqrt(Float64(0.0 - re));
	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 = sqrt((0.0 - re));
	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[Sqrt[N[(0.0 - re), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{0 - re}\\

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


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

    1. Initial program 28.6%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
    3. Simplified50.8%

      \[\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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
    6. 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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
      7. sqrt-lowering-sqrt.f640.0%

        \[\leadsto \mathsf{*.f64}\left(1, \mathsf{sqrt.f64}\left(re\right)\right) \]
    7. Simplified0.0%

      \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
    8. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto \sqrt{re} \]
      2. pow1/2N/A

        \[\leadsto {re}^{\color{blue}{\frac{1}{2}}} \]
      3. metadata-evalN/A

        \[\leadsto {re}^{\left(\frac{1}{4} + \color{blue}{\frac{1}{4}}\right)} \]
      4. metadata-evalN/A

        \[\leadsto {re}^{\left(\left(\mathsf{neg}\left(\frac{-1}{4}\right)\right) + \frac{1}{4}\right)} \]
      5. metadata-evalN/A

        \[\leadsto {re}^{\left(\left(\mathsf{neg}\left(\frac{-1}{4}\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{4}\right)\right)\right)} \]
      6. pow-prod-upN/A

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(re \cdot re\right)}^{0.25}} \]
    10. Step-by-step derivation
      1. sqr-negN/A

        \[\leadsto {\left(\left(\mathsf{neg}\left(re\right)\right) \cdot \left(\mathsf{neg}\left(re\right)\right)\right)}^{\frac{1}{4}} \]
      2. pow-prod-downN/A

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

        \[\leadsto {\left(\mathsf{neg}\left(re\right)\right)}^{\color{blue}{\left(\frac{1}{4} + \frac{1}{4}\right)}} \]
      4. metadata-evalN/A

        \[\leadsto {\left(\mathsf{neg}\left(re\right)\right)}^{\frac{1}{2}} \]
      5. pow1/2N/A

        \[\leadsto \sqrt{\mathsf{neg}\left(re\right)} \]
      6. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\left(\mathsf{neg}\left(re\right)\right)\right) \]
      7. neg-sub0N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\left(0 - re\right)\right) \]
      8. --lowering--.f645.9%

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{\_.f64}\left(0, re\right)\right) \]
    11. Applied egg-rr5.9%

      \[\leadsto \color{blue}{\sqrt{0 - re}} \]

    if -4.999999999999985e-310 < re

    1. Initial program 48.3%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\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 re around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
    6. 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. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
      7. sqrt-lowering-sqrt.f6454.2%

        \[\leadsto \mathsf{*.f64}\left(1, \mathsf{sqrt.f64}\left(re\right)\right) \]
    7. Simplified54.2%

      \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
    8. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto \sqrt{re} \]
      2. sqrt-lowering-sqrt.f6454.2%

        \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
    9. Applied egg-rr54.2%

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

Alternative 6: 25.9% 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.8%

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \mathsf{sqrt.f64}\left(\mathsf{*.f64}\left(2, \mathsf{+.f64}\left(re, \mathsf{hypot.f64}\left(re, im\right)\right)\right)\right)\right) \]
  3. Simplified76.4%

    \[\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

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sqrt{re} \cdot {\left(\sqrt{2}\right)}^{2}\right)} \]
  6. 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. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(1, \color{blue}{\left(\sqrt{re}\right)}\right) \]
    7. sqrt-lowering-sqrt.f6428.2%

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

    \[\leadsto \color{blue}{1 \cdot \sqrt{re}} \]
  8. Step-by-step derivation
    1. *-lft-identityN/A

      \[\leadsto \sqrt{re} \]
    2. sqrt-lowering-sqrt.f6428.2%

      \[\leadsto \mathsf{sqrt.f64}\left(re\right) \]
  9. Applied egg-rr28.2%

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

Developer Target 1: 48.1% 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 2024155 
(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)))))