math.sqrt on complex, real part

Percentage Accurate: 41.8% → 89.5%
Time: 16.2s
Alternatives: 8
Speedup: 2.0×

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 8 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.8% 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.5% accurate, 0.7× speedup?

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

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


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

    1. Initial program 9.5%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    3. Simplified19.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 42.2%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*52.4%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*14.3%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/14.3%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*52.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/52.5%

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot \frac{-im}{re}}} \]
    11. Step-by-step derivation
      1. distribute-frac-neg52.5%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-im \cdot \frac{im}{re}}} \]
      3. mul-1-neg52.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-1 \cdot \left(im \cdot \frac{im}{re}\right)}} \]
      4. *-commutative52.5%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      5. associate-*l*52.5%

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{im} \cdot \sqrt{\frac{im}{re} \cdot -1}\right)} \]
    12. Applied egg-rr50.2%

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

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

        \[\leadsto 0.5 \cdot \left(\sqrt{im} \cdot \sqrt{\color{blue}{\frac{-1 \cdot im}{re}}}\right) \]
      3. neg-mul-150.2%

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

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

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

    1. Initial program 46.6%

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

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

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

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

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

Alternative 2: 83.2% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -2.8e77

    1. Initial program 8.9%

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

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

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

      \[\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.2%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*63.8%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\right)\right)} \]
      2. expm1-udef32.5%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*32.5%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/32.5%

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot \color{blue}{-1}}\right)} - 1\right) \]
    8. Applied egg-rr32.5%

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)\right)} \]
      2. expm1-log1p63.7%

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*63.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/63.7%

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot \frac{-im}{re}}} \]
    11. Taylor expanded in im around 0 59.2%

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

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

        \[\leadsto 0.5 \cdot \sqrt{-\frac{\color{blue}{im \cdot im}}{re}} \]
      3. associate-/l*63.8%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-im}{\frac{re}{im}}}} \]
    13. Simplified63.8%

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

    if -2.8e77 < re

    1. Initial program 46.7%

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

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

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

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

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

Alternative 3: 70.9% accurate, 1.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -4.8 \cdot 10^{+53}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 1.12 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{re \cdot re}{im} + 2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -4.8e+53)
   (* 0.5 (sqrt (/ (- im) (/ re im))))
   (if (<= re 1.12e-44)
     (* 0.5 (sqrt (+ (/ (* re re) im) (* 2.0 (+ re im)))))
     (* 0.5 (* 2.0 (sqrt re))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -4.8e+53) {
		tmp = 0.5 * sqrt((-im / (re / im)));
	} else if (re <= 1.12e-44) {
		tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im))));
	} else {
		tmp = 0.5 * (2.0 * 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+53)) then
        tmp = 0.5d0 * sqrt((-im / (re / im)))
    else if (re <= 1.12d-44) then
        tmp = 0.5d0 * sqrt((((re * re) / im) + (2.0d0 * (re + im))))
    else
        tmp = 0.5d0 * (2.0d0 * 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+53) {
		tmp = 0.5 * Math.sqrt((-im / (re / im)));
	} else if (re <= 1.12e-44) {
		tmp = 0.5 * Math.sqrt((((re * re) / im) + (2.0 * (re + im))));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -4.8e+53:
		tmp = 0.5 * math.sqrt((-im / (re / im)))
	elif re <= 1.12e-44:
		tmp = 0.5 * math.sqrt((((re * re) / im) + (2.0 * (re + im))))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -4.8e+53)
		tmp = Float64(0.5 * sqrt(Float64(Float64(-im) / Float64(re / im))));
	elseif (re <= 1.12e-44)
		tmp = Float64(0.5 * sqrt(Float64(Float64(Float64(re * re) / im) + Float64(2.0 * Float64(re + im)))));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -4.8e+53)
		tmp = 0.5 * sqrt((-im / (re / im)));
	elseif (re <= 1.12e-44)
		tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im))));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -4.8e+53], N[(0.5 * N[Sqrt[N[((-im) / N[(re / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.12e-44], N[(0.5 * N[Sqrt[N[(N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision] + N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.8 \cdot 10^{+53}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\

\mathbf{elif}\;re \leq 1.12 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{re \cdot re}{im} + 2 \cdot \left(re + im\right)}\\

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


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

    1. Initial program 12.0%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*61.9%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\right)\right)} \]
      2. expm1-udef31.7%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*31.7%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/31.7%

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot \color{blue}{-1}}\right)} - 1\right) \]
    8. Applied egg-rr31.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def61.4%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)\right)} \]
      2. expm1-log1p61.9%

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*61.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/61.9%

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \color{blue}{\frac{im \cdot -1}{re}}} \]
      5. *-commutative61.9%

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

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \frac{\color{blue}{-im}}{re}} \]
    10. Simplified61.9%

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot \frac{-im}{re}}} \]
    11. Taylor expanded in im around 0 57.8%

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

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

        \[\leadsto 0.5 \cdot \sqrt{-\frac{\color{blue}{im \cdot im}}{re}} \]
      3. associate-/l*61.9%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-im}{\frac{re}{im}}}} \]
    13. Simplified61.9%

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

    if -4.8e53 < re < 1.1200000000000001e-44

    1. Initial program 49.5%

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

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

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

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

      \[\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. unpow236.1%

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

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

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

    if 1.1200000000000001e-44 < re

    1. Initial program 41.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. +-commutative41.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 76.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.8 \cdot 10^{+53}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 1.12 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{re \cdot re}{im} + 2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 4: 70.7% accurate, 1.9× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -4.2 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq 4.1 \cdot 10^{-45}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -4.2e+47)
   (* 0.5 (sqrt (* im (/ (- im) re))))
   (if (<= re 4.1e-45) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (* 2.0 (sqrt re))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -4.2e+47) {
		tmp = 0.5 * sqrt((im * (-im / re)));
	} else if (re <= 4.1e-45) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * 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.2d+47)) then
        tmp = 0.5d0 * sqrt((im * (-im / re)))
    else if (re <= 4.1d-45) then
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    else
        tmp = 0.5d0 * (2.0d0 * 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.2e+47) {
		tmp = 0.5 * Math.sqrt((im * (-im / re)));
	} else if (re <= 4.1e-45) {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -4.2e+47:
		tmp = 0.5 * math.sqrt((im * (-im / re)))
	elif re <= 4.1e-45:
		tmp = 0.5 * math.sqrt((im * 2.0))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -4.2e+47)
		tmp = Float64(0.5 * sqrt(Float64(im * Float64(Float64(-im) / re))));
	elseif (re <= 4.1e-45)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -4.2e+47)
		tmp = 0.5 * sqrt((im * (-im / re)));
	elseif (re <= 4.1e-45)
		tmp = 0.5 * sqrt((im * 2.0));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -4.2e+47], N[(0.5 * N[Sqrt[N[(im * N[((-im) / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.1e-45], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\

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

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


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

    1. Initial program 12.0%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*61.9%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\right)\right)} \]
      2. expm1-udef31.7%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*31.7%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/31.7%

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot \color{blue}{-1}}\right)} - 1\right) \]
    8. Applied egg-rr31.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def61.4%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)\right)} \]
      2. expm1-log1p61.9%

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*61.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/61.9%

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \color{blue}{\frac{im \cdot -1}{re}}} \]
      5. *-commutative61.9%

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

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \frac{\color{blue}{-im}}{re}} \]
    10. Simplified61.9%

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

    if -4.2e47 < re < 4.0999999999999999e-45

    1. Initial program 49.5%

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

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

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

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

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

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

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

    if 4.0999999999999999e-45 < re

    1. Initial program 41.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. +-commutative41.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 76.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.2 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq 4.1 \cdot 10^{-45}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 5: 70.6% accurate, 1.9× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -1.35 \cdot 10^{+39}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -1.35e+39)
   (* 0.5 (sqrt (/ (- im) (/ re im))))
   (if (<= re 6.6e-44) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (* 2.0 (sqrt re))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -1.35e+39) {
		tmp = 0.5 * sqrt((-im / (re / im)));
	} else if (re <= 6.6e-44) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * 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.35d+39)) then
        tmp = 0.5d0 * sqrt((-im / (re / im)))
    else if (re <= 6.6d-44) then
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    else
        tmp = 0.5d0 * (2.0d0 * 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.35e+39) {
		tmp = 0.5 * Math.sqrt((-im / (re / im)));
	} else if (re <= 6.6e-44) {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -1.35e+39:
		tmp = 0.5 * math.sqrt((-im / (re / im)))
	elif re <= 6.6e-44:
		tmp = 0.5 * math.sqrt((im * 2.0))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -1.35e+39)
		tmp = Float64(0.5 * sqrt(Float64(Float64(-im) / Float64(re / im))));
	elseif (re <= 6.6e-44)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.35e+39)
		tmp = 0.5 * sqrt((-im / (re / im)));
	elseif (re <= 6.6e-44)
		tmp = 0.5 * sqrt((im * 2.0));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -1.35e+39], N[(0.5 * N[Sqrt[N[((-im) / N[(re / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e-44], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.35 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\

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

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


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

    1. Initial program 12.0%

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*61.9%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\right)\right)} \]
      2. expm1-udef31.7%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*31.7%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/31.7%

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot \color{blue}{-1}}\right)} - 1\right) \]
    8. Applied egg-rr31.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def61.4%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)\right)} \]
      2. expm1-log1p61.9%

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*61.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/61.9%

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \color{blue}{\frac{im \cdot -1}{re}}} \]
      5. *-commutative61.9%

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

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \frac{\color{blue}{-im}}{re}} \]
    10. Simplified61.9%

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot \frac{-im}{re}}} \]
    11. Taylor expanded in im around 0 57.8%

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

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

        \[\leadsto 0.5 \cdot \sqrt{-\frac{\color{blue}{im \cdot im}}{re}} \]
      3. associate-/l*61.9%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{-im}{\frac{re}{im}}}} \]
    13. Simplified61.9%

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

    if -1.35000000000000002e39 < re < 6.60000000000000011e-44

    1. Initial program 49.5%

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

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

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

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

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

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

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

    if 6.60000000000000011e-44 < re

    1. Initial program 41.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. +-commutative41.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 76.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.35 \cdot 10^{+39}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{-im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 6.6 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 6: 64.7% accurate, 2.0× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq -1.65 \cdot 10^{+206}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{re}}\\ \mathbf{elif}\;re \leq 3.1 \cdot 10^{-45}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re -1.65e+206)
   (* 0.5 (sqrt (/ (* im im) re)))
   (if (<= re 3.1e-45) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (* 2.0 (sqrt re))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= -1.65e+206) {
		tmp = 0.5 * sqrt(((im * im) / re));
	} else if (re <= 3.1e-45) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * 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.65d+206)) then
        tmp = 0.5d0 * sqrt(((im * im) / re))
    else if (re <= 3.1d-45) then
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    else
        tmp = 0.5d0 * (2.0d0 * 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.65e+206) {
		tmp = 0.5 * Math.sqrt(((im * im) / re));
	} else if (re <= 3.1e-45) {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= -1.65e+206:
		tmp = 0.5 * math.sqrt(((im * im) / re))
	elif re <= 3.1e-45:
		tmp = 0.5 * math.sqrt((im * 2.0))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= -1.65e+206)
		tmp = Float64(0.5 * sqrt(Float64(Float64(im * im) / re)));
	elseif (re <= 3.1e-45)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -1.65e+206)
		tmp = 0.5 * sqrt(((im * im) / re));
	elseif (re <= 3.1e-45)
		tmp = 0.5 * sqrt((im * 2.0));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, -1.65e+206], N[(0.5 * N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.1e-45], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.65 \cdot 10^{+206}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{re}}\\

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

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


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

    1. Initial program 2.2%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    3. Simplified38.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 -inf 48.0%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\frac{\color{blue}{im \cdot im}}{re} \cdot -0.5\right)} \]
      3. associate-/l*58.2%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\left(\frac{im}{\frac{re}{im}} \cdot -0.5\right) \cdot 2}}\right)} - 1\right) \]
      4. associate-*l*43.4%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{im}{\frac{re}{im}} \cdot \left(-0.5 \cdot 2\right)}}\right)} - 1\right) \]
      5. associate-/r/43.4%

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot \color{blue}{-1}}\right)} - 1\right) \]
    8. Applied egg-rr43.4%

      \[\leadsto 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def57.6%

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

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. associate-*l*58.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{im \cdot \left(\frac{im}{re} \cdot -1\right)}} \]
      4. associate-*l/58.2%

        \[\leadsto 0.5 \cdot \sqrt{im \cdot \color{blue}{\frac{im \cdot -1}{re}}} \]
      5. *-commutative58.2%

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot \frac{-im}{re}}} \]
    11. Step-by-step derivation
      1. pow1/258.2%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(im \cdot \frac{-im}{re}\right)}^{0.5}} \]
      2. add-sqr-sqrt58.2%

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

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{\left(im \cdot \frac{-im}{re}\right) \cdot \left(im \cdot \frac{-im}{re}\right)}\right)}}^{0.5} \]
      4. swap-sqr33.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt{\color{blue}{\left(im \cdot im\right) \cdot \left(\frac{-im}{re} \cdot \frac{-im}{re}\right)}}\right)}^{0.5} \]
      5. distribute-frac-neg33.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt{\left(im \cdot im\right) \cdot \left(\color{blue}{\left(-\frac{im}{re}\right)} \cdot \frac{-im}{re}\right)}\right)}^{0.5} \]
      6. distribute-frac-neg33.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt{\left(im \cdot im\right) \cdot \left(\left(-\frac{im}{re}\right) \cdot \color{blue}{\left(-\frac{im}{re}\right)}\right)}\right)}^{0.5} \]
      7. sqr-neg33.8%

        \[\leadsto 0.5 \cdot {\left(\sqrt{\left(im \cdot im\right) \cdot \color{blue}{\left(\frac{im}{re} \cdot \frac{im}{re}\right)}}\right)}^{0.5} \]
      8. swap-sqr38.6%

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

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{im \cdot \frac{im}{re}} \cdot \sqrt{im \cdot \frac{im}{re}}\right)}}^{0.5} \]
      10. add-sqr-sqrt32.6%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(im \cdot \frac{im}{re}\right)}}^{0.5} \]
      11. clear-num32.6%

        \[\leadsto 0.5 \cdot {\left(im \cdot \color{blue}{\frac{1}{\frac{re}{im}}}\right)}^{0.5} \]
      12. un-div-inv32.6%

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\frac{im}{\frac{re}{im}}\right)}}^{0.5} \]
    12. Applied egg-rr32.6%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\frac{im}{\frac{re}{im}}\right)}^{0.5}} \]
    13. Step-by-step derivation
      1. unpow1/232.6%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \]
    14. Simplified32.6%

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

    if -1.64999999999999992e206 < re < 3.1000000000000001e-45

    1. Initial program 43.2%

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    3. Simplified72.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 32.2%

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

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

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

    if 3.1000000000000001e-45 < re

    1. Initial program 41.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. +-commutative41.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 76.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.65 \cdot 10^{+206}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{re}}\\ \mathbf{elif}\;re \leq 3.1 \cdot 10^{-45}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 7: 63.8% accurate, 2.0× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq 2.12 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re 2.12e-44) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (* 2.0 (sqrt re)))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= 2.12e-44) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * 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 <= 2.12d-44) then
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    else
        tmp = 0.5d0 * (2.0d0 * sqrt(re))
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (re <= 2.12e-44) {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= 2.12e-44:
		tmp = 0.5 * math.sqrt((im * 2.0))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= 2.12e-44)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= 2.12e-44)
		tmp = 0.5 * sqrt((im * 2.0));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, 2.12e-44], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.12 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\

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


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

    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. +-commutative38.8%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
    3. Simplified68.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 29.4%

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

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

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

    if 2.1199999999999999e-44 < re

    1. Initial program 41.4%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Step-by-step derivation
      1. +-commutative41.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 76.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.12 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 8: 52.1% accurate, 2.0× speedup?

\[\begin{array}{l} im = |im|\\ \\ 0.5 \cdot \sqrt{im \cdot 2} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
im = abs(im);
double code(double re, double im) {
	return 0.5 * sqrt((im * 2.0));
}
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 = 0.5d0 * sqrt((im * 2.0d0))
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return 0.5 * Math.sqrt((im * 2.0));
}
im = abs(im)
def code(re, im):
	return 0.5 * math.sqrt((im * 2.0))
im = abs(im)
function code(re, im)
	return Float64(0.5 * sqrt(Float64(im * 2.0)))
end
im = abs(im)
function tmp = code(re, im)
	tmp = 0.5 * sqrt((im * 2.0));
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Derivation
  1. Initial program 39.5%

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

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(re + \color{blue}{\mathsf{hypot}\left(re, im\right)}\right)} \]
  3. Simplified76.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 26.6%

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

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

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

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

Developer target: 48.7% 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 2023278 
(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)))))