math.sqrt on complex, real part

Percentage Accurate: 41.0% → 89.7%
Time: 9.3s
Alternatives: 7
Speedup: 1.8×

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 7 alternatives:

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

Initial Program: 41.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \end{array} \]
(FPCore (re im)
 :precision binary64
 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
	return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
	return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im):
	return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im)
	return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re))))
end
function tmp = code(re, im)
	tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}

Alternative 1: 89.7% accurate, 0.5× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0)
   (/ (* im 0.5) (sqrt (- re)))
   (sqrt (* 0.5 (+ re (hypot re im))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
		tmp = (im * 0.5) / sqrt(-re);
	} else {
		tmp = sqrt((0.5 * (re + hypot(re, im))));
	}
	return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im * im)))))) <= 0.0) {
		tmp = (im * 0.5) / Math.sqrt(-re);
	} else {
		tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im * im)))))) <= 0.0:
		tmp = (im * 0.5) / math.sqrt(-re)
	else:
		tmp = math.sqrt((0.5 * (re + math.hypot(re, im))))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))))) <= 0.0)
		tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re)));
	else
		tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im))));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0)
		tmp = (im * 0.5) / sqrt(-re);
	else
		tmp = sqrt((0.5 * (re + hypot(re, im))));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\

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


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

    1. Initial program 8.0%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/65.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-165.5%

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

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in65.5%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot \left(-im\right)}{re}}} \]
    7. Step-by-step derivation
      1. frac-2neg65.5%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out66.4%

        \[\leadsto 0.5 \cdot \frac{\sqrt{-\color{blue}{\left(-im \cdot im\right)}}}{\sqrt{-re}} \]
      4. remove-double-neg66.4%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{im \cdot im}}}{\sqrt{-re}} \]
      5. sqrt-unprod55.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt60.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr60.4%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{im}{\sqrt{-re}}} \]
    9. Step-by-step derivation
      1. associate-*r/60.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{-re}}} \]
    10. Applied egg-rr60.4%

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

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

    1. Initial program 50.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 72.6% accurate, 1.7× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} t_0 := 2 \cdot \left(re + im\right)\\ t_1 := \sqrt{-re}\\ \mathbf{if}\;re \leq -5.8 \cdot 10^{+142}:\\ \;\;\;\;0.5 \cdot \frac{im}{t_1}\\ \mathbf{elif}\;re \leq -2.9 \cdot 10^{+124}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot \frac{re}{im} + t_0}\\ \mathbf{elif}\;re \leq -2.35 \cdot 10^{+26}:\\ \;\;\;\;\frac{im \cdot 0.5}{t_1}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{re}\\ \mathbf{elif}\;re \leq 1.4 \cdot 10^{-76} \lor \neg \left(re \leq 1.76 \cdot 10^{-6}\right) \land re \leq 9 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{t_0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 2.0 (+ re im))) (t_1 (sqrt (- re))))
   (if (<= re -5.8e+142)
     (* 0.5 (/ im t_1))
     (if (<= re -2.9e+124)
       (* 0.5 (sqrt (+ (* re (/ re im)) t_0)))
       (if (<= re -2.35e+26)
         (/ (* im 0.5) t_1)
         (if (<= re 6.6e-187)
           (* 0.5 (sqrt (* 2.0 im)))
           (if (<= re 1.1e-125)
             (sqrt re)
             (if (or (<= re 1.4e-76) (and (not (<= re 1.76e-6)) (<= re 9e+47)))
               (* 0.5 (sqrt t_0))
               (sqrt re)))))))))
im = abs(im);
double code(double re, double im) {
	double t_0 = 2.0 * (re + im);
	double t_1 = sqrt(-re);
	double tmp;
	if (re <= -5.8e+142) {
		tmp = 0.5 * (im / t_1);
	} else if (re <= -2.9e+124) {
		tmp = 0.5 * sqrt(((re * (re / im)) + t_0));
	} else if (re <= -2.35e+26) {
		tmp = (im * 0.5) / t_1;
	} else if (re <= 6.6e-187) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else if (re <= 1.1e-125) {
		tmp = sqrt(re);
	} else if ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47))) {
		tmp = 0.5 * sqrt(t_0);
	} else {
		tmp = sqrt(re);
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 2.0d0 * (re + im)
    t_1 = sqrt(-re)
    if (re <= (-5.8d+142)) then
        tmp = 0.5d0 * (im / t_1)
    else if (re <= (-2.9d+124)) then
        tmp = 0.5d0 * sqrt(((re * (re / im)) + t_0))
    else if (re <= (-2.35d+26)) then
        tmp = (im * 0.5d0) / t_1
    else if (re <= 6.6d-187) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else if (re <= 1.1d-125) then
        tmp = sqrt(re)
    else if ((re <= 1.4d-76) .or. (.not. (re <= 1.76d-6)) .and. (re <= 9d+47)) then
        tmp = 0.5d0 * sqrt(t_0)
    else
        tmp = sqrt(re)
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double t_0 = 2.0 * (re + im);
	double t_1 = Math.sqrt(-re);
	double tmp;
	if (re <= -5.8e+142) {
		tmp = 0.5 * (im / t_1);
	} else if (re <= -2.9e+124) {
		tmp = 0.5 * Math.sqrt(((re * (re / im)) + t_0));
	} else if (re <= -2.35e+26) {
		tmp = (im * 0.5) / t_1;
	} else if (re <= 6.6e-187) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else if (re <= 1.1e-125) {
		tmp = Math.sqrt(re);
	} else if ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47))) {
		tmp = 0.5 * Math.sqrt(t_0);
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	t_0 = 2.0 * (re + im)
	t_1 = math.sqrt(-re)
	tmp = 0
	if re <= -5.8e+142:
		tmp = 0.5 * (im / t_1)
	elif re <= -2.9e+124:
		tmp = 0.5 * math.sqrt(((re * (re / im)) + t_0))
	elif re <= -2.35e+26:
		tmp = (im * 0.5) / t_1
	elif re <= 6.6e-187:
		tmp = 0.5 * math.sqrt((2.0 * im))
	elif re <= 1.1e-125:
		tmp = math.sqrt(re)
	elif (re <= 1.4e-76) or (not (re <= 1.76e-6) and (re <= 9e+47)):
		tmp = 0.5 * math.sqrt(t_0)
	else:
		tmp = math.sqrt(re)
	return tmp
im = abs(im)
function code(re, im)
	t_0 = Float64(2.0 * Float64(re + im))
	t_1 = sqrt(Float64(-re))
	tmp = 0.0
	if (re <= -5.8e+142)
		tmp = Float64(0.5 * Float64(im / t_1));
	elseif (re <= -2.9e+124)
		tmp = Float64(0.5 * sqrt(Float64(Float64(re * Float64(re / im)) + t_0)));
	elseif (re <= -2.35e+26)
		tmp = Float64(Float64(im * 0.5) / t_1);
	elseif (re <= 6.6e-187)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	elseif (re <= 1.1e-125)
		tmp = sqrt(re);
	elseif ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47)))
		tmp = Float64(0.5 * sqrt(t_0));
	else
		tmp = sqrt(re);
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	t_0 = 2.0 * (re + im);
	t_1 = sqrt(-re);
	tmp = 0.0;
	if (re <= -5.8e+142)
		tmp = 0.5 * (im / t_1);
	elseif (re <= -2.9e+124)
		tmp = 0.5 * sqrt(((re * (re / im)) + t_0));
	elseif (re <= -2.35e+26)
		tmp = (im * 0.5) / t_1;
	elseif (re <= 6.6e-187)
		tmp = 0.5 * sqrt((2.0 * im));
	elseif (re <= 1.1e-125)
		tmp = sqrt(re);
	elseif ((re <= 1.4e-76) || (~((re <= 1.76e-6)) && (re <= 9e+47)))
		tmp = 0.5 * sqrt(t_0);
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := Block[{t$95$0 = N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[(-re)], $MachinePrecision]}, If[LessEqual[re, -5.8e+142], N[(0.5 * N[(im / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.9e+124], N[(0.5 * N[Sqrt[N[(N[(re * N[(re / im), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.35e+26], N[(N[(im * 0.5), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[re, 6.6e-187], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e-125], N[Sqrt[re], $MachinePrecision], If[Or[LessEqual[re, 1.4e-76], And[N[Not[LessEqual[re, 1.76e-6]], $MachinePrecision], LessEqual[re, 9e+47]]], N[(0.5 * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
t_0 := 2 \cdot \left(re + im\right)\\
t_1 := \sqrt{-re}\\
\mathbf{if}\;re \leq -5.8 \cdot 10^{+142}:\\
\;\;\;\;0.5 \cdot \frac{im}{t_1}\\

\mathbf{elif}\;re \leq -2.9 \cdot 10^{+124}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot \frac{re}{im} + t_0}\\

\mathbf{elif}\;re \leq -2.35 \cdot 10^{+26}:\\
\;\;\;\;\frac{im \cdot 0.5}{t_1}\\

\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

\mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\
\;\;\;\;\sqrt{re}\\

\mathbf{elif}\;re \leq 1.4 \cdot 10^{-76} \lor \neg \left(re \leq 1.76 \cdot 10^{-6}\right) \land re \leq 9 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \sqrt{t_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if re < -5.80000000000000027e142

    1. Initial program 2.8%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/59.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-159.9%

        \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{-{im}^{2}}}{re}} \]
      3. unpow259.9%

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in59.9%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot \left(-im\right)}{re}}} \]
    7. Step-by-step derivation
      1. frac-2neg59.9%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out69.6%

        \[\leadsto 0.5 \cdot \frac{\sqrt{-\color{blue}{\left(-im \cdot im\right)}}}{\sqrt{-re}} \]
      4. remove-double-neg69.6%

        \[\leadsto 0.5 \cdot \frac{\sqrt{\color{blue}{im \cdot im}}}{\sqrt{-re}} \]
      5. sqrt-unprod46.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt60.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr60.5%

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

    if -5.80000000000000027e142 < re < -2.90000000000000021e124

    1. Initial program 35.5%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{{re}^{2}}{im} + \left(2 \cdot im + 2 \cdot re\right)}} \]
    5. Step-by-step derivation
      1. unpow280.4%

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{re \cdot re}{im} + 2 \cdot \left(im + re\right)}} \]
    7. Step-by-step derivation
      1. associate-/l*80.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{re}{\frac{im}{re}}} + 2 \cdot \left(im + re\right)} \]
      2. associate-/r/80.4%

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

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

    if -2.90000000000000021e124 < re < -2.3499999999999999e26

    1. Initial program 7.6%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/62.3%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-162.3%

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

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in62.3%

        \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{im \cdot \left(-im\right)}}{re}} \]
    6. Simplified62.3%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out63.9%

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

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt54.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr54.4%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{im}{\sqrt{-re}}} \]
    9. Step-by-step derivation
      1. associate-*r/54.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{-re}}} \]
    10. Applied egg-rr54.4%

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

    if -2.3499999999999999e26 < re < 6.6e-187

    1. Initial program 52.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im}} \]
    5. Step-by-step derivation
      1. *-commutative46.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
    6. Simplified46.4%

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

    if 6.6e-187 < re < 1.09999999999999997e-125 or 1.40000000000000005e-76 < re < 1.7600000000000001e-6 or 8.99999999999999958e47 < re

    1. Initial program 61.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2}\right) \cdot \sqrt{re}} \]
      2. unpow277.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
      3. rem-square-sqrt78.9%

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

        \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
      5. *-lft-identity78.9%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    6. Simplified78.9%

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

    if 1.09999999999999997e-125 < re < 1.40000000000000005e-76 or 1.7600000000000001e-6 < re < 8.99999999999999958e47

    1. Initial program 61.7%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im + 2 \cdot re}} \]
    5. Step-by-step derivation
      1. distribute-lft-out39.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -5.8 \cdot 10^{+142}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq -2.9 \cdot 10^{+124}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot \frac{re}{im} + 2 \cdot \left(re + im\right)}\\ \mathbf{elif}\;re \leq -2.35 \cdot 10^{+26}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{re}\\ \mathbf{elif}\;re \leq 1.4 \cdot 10^{-76} \lor \neg \left(re \leq 1.76 \cdot 10^{-6}\right) \land re \leq 9 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]

Alternative 3: 72.9% accurate, 1.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -4.8 \cdot 10^{+25}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{re}\\ \mathbf{elif}\;re \leq 1.6 \cdot 10^{-77} \lor \neg \left(re \leq 4.2 \cdot 10^{-5}\right) \land re \leq 5.2 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -4.8e+25)
   (/ (* im 0.5) (sqrt (- re)))
   (if (<= re 6.6e-187)
     (* 0.5 (sqrt (* 2.0 im)))
     (if (<= re 1.1e-125)
       (sqrt re)
       (if (or (<= re 1.6e-77) (and (not (<= re 4.2e-5)) (<= re 5.2e+47)))
         (* 0.5 (sqrt (* 2.0 (+ re im))))
         (sqrt re))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -4.8e+25) {
		tmp = (im * 0.5) / sqrt(-re);
	} else if (re <= 6.6e-187) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else if (re <= 1.1e-125) {
		tmp = sqrt(re);
	} else if ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47))) {
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	} else {
		tmp = sqrt(re);
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-4.8d+25)) then
        tmp = (im * 0.5d0) / sqrt(-re)
    else if (re <= 6.6d-187) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else if (re <= 1.1d-125) then
        tmp = sqrt(re)
    else if ((re <= 1.6d-77) .or. (.not. (re <= 4.2d-5)) .and. (re <= 5.2d+47)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
    else
        tmp = sqrt(re)
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (re <= -4.8e+25) {
		tmp = (im * 0.5) / Math.sqrt(-re);
	} else if (re <= 6.6e-187) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else if (re <= 1.1e-125) {
		tmp = Math.sqrt(re);
	} else if ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47))) {
		tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -4.8e+25:
		tmp = (im * 0.5) / math.sqrt(-re)
	elif re <= 6.6e-187:
		tmp = 0.5 * math.sqrt((2.0 * im))
	elif re <= 1.1e-125:
		tmp = math.sqrt(re)
	elif (re <= 1.6e-77) or (not (re <= 4.2e-5) and (re <= 5.2e+47)):
		tmp = 0.5 * math.sqrt((2.0 * (re + im)))
	else:
		tmp = math.sqrt(re)
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -4.8e+25)
		tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re)));
	elseif (re <= 6.6e-187)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	elseif (re <= 1.1e-125)
		tmp = sqrt(re);
	elseif ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47)))
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im))));
	else
		tmp = sqrt(re);
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -4.8e+25)
		tmp = (im * 0.5) / sqrt(-re);
	elseif (re <= 6.6e-187)
		tmp = 0.5 * sqrt((2.0 * im));
	elseif (re <= 1.1e-125)
		tmp = sqrt(re);
	elseif ((re <= 1.6e-77) || (~((re <= 4.2e-5)) && (re <= 5.2e+47)))
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -4.8e+25], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e-187], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e-125], N[Sqrt[re], $MachinePrecision], If[Or[LessEqual[re, 1.6e-77], And[N[Not[LessEqual[re, 4.2e-5]], $MachinePrecision], LessEqual[re, 5.2e+47]]], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.8 \cdot 10^{+25}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\

\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

\mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\
\;\;\;\;\sqrt{re}\\

\mathbf{elif}\;re \leq 1.6 \cdot 10^{-77} \lor \neg \left(re \leq 4.2 \cdot 10^{-5}\right) \land re \leq 5.2 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -4.79999999999999992e25

    1. Initial program 7.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/55.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-155.2%

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

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in55.2%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot \left(-im\right)}{re}}} \]
    7. Step-by-step derivation
      1. frac-2neg55.2%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out62.0%

        \[\leadsto 0.5 \cdot \frac{\sqrt{-\color{blue}{\left(-im \cdot im\right)}}}{\sqrt{-re}} \]
      4. remove-double-neg62.0%

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt54.0%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr54.0%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{im}{\sqrt{-re}}} \]
    9. Step-by-step derivation
      1. associate-*r/54.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{-re}}} \]
    10. Applied egg-rr54.0%

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

    if -4.79999999999999992e25 < re < 6.6e-187

    1. Initial program 52.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im}} \]
    5. Step-by-step derivation
      1. *-commutative46.4%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
    6. Simplified46.4%

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

    if 6.6e-187 < re < 1.09999999999999997e-125 or 1.6e-77 < re < 4.19999999999999977e-5 or 5.20000000000000007e47 < re

    1. Initial program 61.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2}\right) \cdot \sqrt{re}} \]
      2. unpow277.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
      3. rem-square-sqrt78.9%

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

        \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
      5. *-lft-identity78.9%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    6. Simplified78.9%

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

    if 1.09999999999999997e-125 < re < 1.6e-77 or 4.19999999999999977e-5 < re < 5.20000000000000007e47

    1. Initial program 61.7%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im + 2 \cdot re}} \]
    5. Step-by-step derivation
      1. distribute-lft-out39.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.8 \cdot 10^{+25}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{re}\\ \mathbf{elif}\;re \leq 1.6 \cdot 10^{-77} \lor \neg \left(re \leq 4.2 \cdot 10^{-5}\right) \land re \leq 5.2 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]

Alternative 4: 72.1% accurate, 1.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -3.3 \cdot 10^{+28}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.95 \cdot 10^{-78} \lor \neg \left(re \leq 0.0031\right) \land re \leq 1.8 \cdot 10^{+53}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -3.3e+28)
   (* 0.5 (/ im (sqrt (- re))))
   (if (or (<= re 6.6e-187)
           (and (not (<= re 1.1e-125))
                (or (<= re 1.95e-78)
                    (and (not (<= re 0.0031)) (<= re 1.8e+53)))))
     (* 0.5 (sqrt (* 2.0 im)))
     (sqrt re))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -3.3e+28) {
		tmp = 0.5 * (im / sqrt(-re));
	} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53))))) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else {
		tmp = sqrt(re);
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-3.3d+28)) then
        tmp = 0.5d0 * (im / sqrt(-re))
    else if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.95d-78) .or. (.not. (re <= 0.0031d0)) .and. (re <= 1.8d+53)) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else
        tmp = sqrt(re)
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (re <= -3.3e+28) {
		tmp = 0.5 * (im / Math.sqrt(-re));
	} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53))))) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -3.3e+28:
		tmp = 0.5 * (im / math.sqrt(-re))
	elif (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.95e-78) or (not (re <= 0.0031) and (re <= 1.8e+53)))):
		tmp = 0.5 * math.sqrt((2.0 * im))
	else:
		tmp = math.sqrt(re)
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -3.3e+28)
		tmp = Float64(0.5 * Float64(im / sqrt(Float64(-re))));
	elseif ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53)))))
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	else
		tmp = sqrt(re);
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -3.3e+28)
		tmp = 0.5 * (im / sqrt(-re));
	elseif ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.95e-78) || (~((re <= 0.0031)) && (re <= 1.8e+53)))))
		tmp = 0.5 * sqrt((2.0 * im));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -3.3e+28], N[(0.5 * N[(im / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.95e-78], And[N[Not[LessEqual[re, 0.0031]], $MachinePrecision], LessEqual[re, 1.8e+53]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.3 \cdot 10^{+28}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{-re}}\\

\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.95 \cdot 10^{-78} \lor \neg \left(re \leq 0.0031\right) \land re \leq 1.8 \cdot 10^{+53}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

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


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

    1. Initial program 7.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/55.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-155.2%

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

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in55.2%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot \left(-im\right)}{re}}} \]
    7. Step-by-step derivation
      1. frac-2neg55.2%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out62.0%

        \[\leadsto 0.5 \cdot \frac{\sqrt{-\color{blue}{\left(-im \cdot im\right)}}}{\sqrt{-re}} \]
      4. remove-double-neg62.0%

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt54.0%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr54.0%

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

    if -3.3e28 < re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.9500000000000001e-78 or 0.00309999999999999989 < re < 1.8e53

    1. Initial program 54.4%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im}} \]
    5. Step-by-step derivation
      1. *-commutative44.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
    6. Simplified44.2%

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

    if 6.6e-187 < re < 1.09999999999999997e-125 or 1.9500000000000001e-78 < re < 0.00309999999999999989 or 1.8e53 < re

    1. Initial program 61.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2}\right) \cdot \sqrt{re}} \]
      2. unpow277.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
      3. rem-square-sqrt78.9%

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

        \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
      5. *-lft-identity78.9%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    6. Simplified78.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.3 \cdot 10^{+28}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.95 \cdot 10^{-78} \lor \neg \left(re \leq 0.0031\right) \land re \leq 1.8 \cdot 10^{+53}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]

Alternative 5: 72.5% accurate, 1.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -1.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.25 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{-5}\right) \land re \leq 3.5 \cdot 10^{+45}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -1.5e+25)
   (/ (* im 0.5) (sqrt (- re)))
   (if (or (<= re 6.6e-187)
           (and (not (<= re 1.1e-125))
                (or (<= re 1.25e-76)
                    (and (not (<= re 8.5e-5)) (<= re 3.5e+45)))))
     (* 0.5 (sqrt (* 2.0 im)))
     (sqrt re))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -1.5e+25) {
		tmp = (im * 0.5) / sqrt(-re);
	} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45))))) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else {
		tmp = sqrt(re);
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-1.5d+25)) then
        tmp = (im * 0.5d0) / sqrt(-re)
    else if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.25d-76) .or. (.not. (re <= 8.5d-5)) .and. (re <= 3.5d+45)) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else
        tmp = sqrt(re)
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (re <= -1.5e+25) {
		tmp = (im * 0.5) / Math.sqrt(-re);
	} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45))))) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -1.5e+25:
		tmp = (im * 0.5) / math.sqrt(-re)
	elif (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.25e-76) or (not (re <= 8.5e-5) and (re <= 3.5e+45)))):
		tmp = 0.5 * math.sqrt((2.0 * im))
	else:
		tmp = math.sqrt(re)
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -1.5e+25)
		tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re)));
	elseif ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45)))))
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	else
		tmp = sqrt(re);
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.5e+25)
		tmp = (im * 0.5) / sqrt(-re);
	elseif ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.25e-76) || (~((re <= 8.5e-5)) && (re <= 3.5e+45)))))
		tmp = 0.5 * sqrt((2.0 * im));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -1.5e+25], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.25e-76], And[N[Not[LessEqual[re, 8.5e-5]], $MachinePrecision], LessEqual[re, 3.5e+45]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{+25}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\

\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.25 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{-5}\right) \land re \leq 3.5 \cdot 10^{+45}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

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


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

    1. Initial program 7.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
    5. Step-by-step derivation
      1. associate-*r/55.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-1 \cdot {im}^{2}}{re}}} \]
      2. neg-mul-155.2%

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

        \[\leadsto 0.5 \cdot \sqrt{\frac{-\color{blue}{im \cdot im}}{re}} \]
      4. distribute-rgt-neg-in55.2%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot \left(-im\right)}{re}}} \]
    7. Step-by-step derivation
      1. frac-2neg55.2%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{\sqrt{-im \cdot \left(-im\right)}}{\sqrt{-re}}} \]
      3. distribute-rgt-neg-out62.0%

        \[\leadsto 0.5 \cdot \frac{\sqrt{-\color{blue}{\left(-im \cdot im\right)}}}{\sqrt{-re}} \]
      4. remove-double-neg62.0%

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

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{-re}} \]
      6. add-sqr-sqrt54.0%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{im}}{\sqrt{-re}} \]
    8. Applied egg-rr54.0%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{im}{\sqrt{-re}}} \]
    9. Step-by-step derivation
      1. associate-*r/54.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{-re}}} \]
    10. Applied egg-rr54.0%

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

    if -1.50000000000000003e25 < re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.2499999999999999e-76 or 8.500000000000001e-5 < re < 3.50000000000000023e45

    1. Initial program 54.4%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im}} \]
    5. Step-by-step derivation
      1. *-commutative44.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
    6. Simplified44.2%

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

    if 6.6e-187 < re < 1.09999999999999997e-125 or 1.2499999999999999e-76 < re < 8.500000000000001e-5 or 3.50000000000000023e45 < re

    1. Initial program 61.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2}\right) \cdot \sqrt{re}} \]
      2. unpow277.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
      3. rem-square-sqrt78.9%

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

        \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
      5. *-lft-identity78.9%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    6. Simplified78.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.25 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{-5}\right) \land re \leq 3.5 \cdot 10^{+45}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]

Alternative 6: 60.9% accurate, 1.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.85 \cdot 10^{-78} \lor \neg \left(re \leq 2.85 \cdot 10^{-6}\right) \land re \leq 8.8 \cdot 10^{+46}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (or (<= re 6.6e-187)
         (and (not (<= re 1.1e-125))
              (or (<= re 1.85e-78)
                  (and (not (<= re 2.85e-6)) (<= re 8.8e+46)))))
   (* 0.5 (sqrt (* 2.0 im)))
   (sqrt re)))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46))))) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else {
		tmp = sqrt(re);
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.85d-78) .or. (.not. (re <= 2.85d-6)) .and. (re <= 8.8d+46)) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else
        tmp = sqrt(re)
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46))))) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else {
		tmp = Math.sqrt(re);
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.85e-78) or (not (re <= 2.85e-6) and (re <= 8.8e+46)))):
		tmp = 0.5 * math.sqrt((2.0 * im))
	else:
		tmp = math.sqrt(re)
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46)))))
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	else
		tmp = sqrt(re);
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.85e-78) || (~((re <= 2.85e-6)) && (re <= 8.8e+46)))))
		tmp = 0.5 * sqrt((2.0 * im));
	else
		tmp = sqrt(re);
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.85e-78], And[N[Not[LessEqual[re, 2.85e-6]], $MachinePrecision], LessEqual[re, 8.8e+46]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.85 \cdot 10^{-78} \lor \neg \left(re \leq 2.85 \cdot 10^{-6}\right) \land re \leq 8.8 \cdot 10^{+46}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.85000000000000003e-78 or 2.8499999999999998e-6 < re < 8.8000000000000001e46

    1. Initial program 38.2%

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

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{2 \cdot im}} \]
    5. Step-by-step derivation
      1. *-commutative33.8%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot 2}} \]
    6. Simplified33.8%

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

    if 6.6e-187 < re < 1.09999999999999997e-125 or 1.85000000000000003e-78 < re < 2.8499999999999998e-6 or 8.8000000000000001e46 < re

    1. Initial program 61.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot {\left(\sqrt{2}\right)}^{2}\right) \cdot \sqrt{re}} \]
      2. unpow277.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
      3. rem-square-sqrt78.9%

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

        \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
      5. *-lft-identity78.9%

        \[\leadsto \color{blue}{\sqrt{re}} \]
    6. Simplified78.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.85 \cdot 10^{-78} \lor \neg \left(re \leq 2.85 \cdot 10^{-6}\right) \land re \leq 8.8 \cdot 10^{+46}\right):\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{re}\\ \end{array} \]

Alternative 7: 26.7% accurate, 2.1× speedup?

\[\begin{array}{l} im = |im|\\ \\ \sqrt{re} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im) :precision binary64 (sqrt re))
im = abs(im);
double code(double re, double im) {
	return sqrt(re);
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = sqrt(re)
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return Math.sqrt(re);
}
im = abs(im)
def code(re, im):
	return math.sqrt(re)
im = abs(im)
function code(re, im)
	return sqrt(re)
end
im = abs(im)
function tmp = code(re, im)
	tmp = sqrt(re);
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\sqrt{re}
\end{array}
Derivation
  1. Initial program 46.1%

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}\right) \cdot \sqrt{re} \]
    3. rem-square-sqrt29.8%

      \[\leadsto \left(0.5 \cdot \color{blue}{2}\right) \cdot \sqrt{re} \]
    4. metadata-eval29.8%

      \[\leadsto \color{blue}{1} \cdot \sqrt{re} \]
    5. *-lft-identity29.8%

      \[\leadsto \color{blue}{\sqrt{re}} \]
  6. Simplified29.8%

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

    \[\leadsto \sqrt{re} \]

Developer target: 47.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re < 0:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t_0 - re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t_0 + re\right)}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (sqrt (+ (* re re) (* im im)))))
   (if (< re 0.0)
     (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
     (* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
	double t_0 = sqrt(((re * re) + (im * im)));
	double tmp;
	if (re < 0.0) {
		tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
	} else {
		tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt(((re * re) + (im * im)))
    if (re < 0.0d0) then
        tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
    else
        tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sqrt(((re * re) + (im * im)));
	double tmp;
	if (re < 0.0) {
		tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
	} else {
		tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sqrt(((re * re) + (im * im)))
	tmp = 0
	if re < 0.0:
		tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re))))
	else:
		tmp = 0.5 * math.sqrt((2.0 * (t_0 + re)))
	return tmp
function code(re, im)
	t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im)))
	tmp = 0.0
	if (re < 0.0)
		tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re)))));
	else
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sqrt(((re * re) + (im * im)));
	tmp = 0.0;
	if (re < 0.0)
		tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
	else
		tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t_0 + re\right)}\\


\end{array}
\end{array}

Reproduce

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

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

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