math.sqrt on complex, imaginary part, im greater than 0 branch

Percentage Accurate: 42.4% → 88.6%
Time: 9.4s
Alternatives: 7
Speedup: 2.0×

Specification

?
\[im > 0\]
\[\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: 42.4% accurate, 1.0× speedup?

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

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

Alternative 1: 88.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\ \mathbf{if}\;re \leq 2.2 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{-53}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{elif}\;re \leq 750000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{0.5}{re}}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
   (if (<= re 2.2e-66)
     t_0
     (if (<= re 6.5e-53)
       (* 0.5 (* im (sqrt (/ 1.0 re))))
       (if (<= re 750000000000.0)
         t_0
         (* 0.5 (* (sqrt 2.0) (* im (sqrt (/ 0.5 re))))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
	double tmp;
	if (re <= 2.2e-66) {
		tmp = t_0;
	} else if (re <= 6.5e-53) {
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	} else if (re <= 750000000000.0) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (sqrt(2.0) * (im * sqrt((0.5 / re))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
	double tmp;
	if (re <= 2.2e-66) {
		tmp = t_0;
	} else if (re <= 6.5e-53) {
		tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
	} else if (re <= 750000000000.0) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (Math.sqrt(2.0) * (im * Math.sqrt((0.5 / re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re)))
	tmp = 0
	if re <= 2.2e-66:
		tmp = t_0
	elif re <= 6.5e-53:
		tmp = 0.5 * (im * math.sqrt((1.0 / re)))
	elif re <= 750000000000.0:
		tmp = t_0
	else:
		tmp = 0.5 * (math.sqrt(2.0) * (im * math.sqrt((0.5 / re))))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re))))
	tmp = 0.0
	if (re <= 2.2e-66)
		tmp = t_0;
	elseif (re <= 6.5e-53)
		tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re))));
	elseif (re <= 750000000000.0)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(sqrt(2.0) * Float64(im * sqrt(Float64(0.5 / re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
	tmp = 0.0;
	if (re <= 2.2e-66)
		tmp = t_0;
	elseif (re <= 6.5e-53)
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	elseif (re <= 750000000000.0)
		tmp = t_0;
	else
		tmp = 0.5 * (sqrt(2.0) * (im * sqrt((0.5 / re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, 2.2e-66], t$95$0, If[LessEqual[re, 6.5e-53], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 750000000000.0], t$95$0, N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[(im * N[Sqrt[N[(0.5 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{if}\;re \leq 2.2 \cdot 10^{-66}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 6.5 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\

\mathbf{elif}\;re \leq 750000000000:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < 2.2000000000000001e-66 or 6.4999999999999997e-53 < re < 7.5e11

    1. Initial program 47.3%

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

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

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

    if 2.2000000000000001e-66 < re < 6.4999999999999997e-53

    1. Initial program 4.8%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
      2. expm1-log1p-u4.8%

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    3. Applied egg-rr4.8%

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    4. Step-by-step derivation
      1. pow1/24.8%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right)}^{0.5}} \]
      2. pow-to-exp4.8%

        \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right) \cdot 0.5}} \]
      3. expm1-log1p-u4.8%

        \[\leadsto 0.5 \cdot e^{\log \left(2 \cdot \color{blue}{\left(\mathsf{hypot}\left(re, im\right) - re\right)}\right) \cdot 0.5} \]
      4. *-commutative4.8%

        \[\leadsto 0.5 \cdot e^{\log \color{blue}{\left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right)} \cdot 0.5} \]
    5. Applied egg-rr4.8%

      \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right) \cdot 0.5}} \]
    6. Taylor expanded in im around 0 100.0%

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

    if 7.5e11 < re

    1. Initial program 8.8%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in im around 0 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.2 \cdot 10^{-66}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{-53}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{elif}\;re \leq 750000000000:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{0.5}{re}}\right)\right)\\ \end{array} \]

Alternative 2: 90.5% accurate, 0.7× speedup?

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

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

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


\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 4.4%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    4. Step-by-step derivation
      1. pow1/210.1%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right)}^{0.5}} \]
      2. pow-to-exp9.7%

        \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right) \cdot 0.5}} \]
      3. expm1-log1p-u9.7%

        \[\leadsto 0.5 \cdot e^{\log \left(2 \cdot \color{blue}{\left(\mathsf{hypot}\left(re, im\right) - re\right)}\right) \cdot 0.5} \]
      4. *-commutative9.7%

        \[\leadsto 0.5 \cdot e^{\log \color{blue}{\left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right)} \cdot 0.5} \]
    5. Applied egg-rr9.7%

      \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right) \cdot 0.5}} \]
    6. Taylor expanded in im around 0 94.8%

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

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

    1. Initial program 40.9%

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

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

        \[\leadsto 0.5 \cdot {\left(2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)\right)}^{0.5} \]
    3. Applied egg-rr85.9%

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

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

Alternative 3: 88.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 2.45 \cdot 10^{-64}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\ \mathbf{elif}\;re \leq 4.6 \cdot 10^{-53} \lor \neg \left(re \leq 1.05 \cdot 10^{+32}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re 2.45e-64)
   (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))
   (if (or (<= re 4.6e-53) (not (<= re 1.05e+32)))
     (* 0.5 (* im (sqrt (/ 1.0 re))))
     (* 0.5 (sqrt (* im 2.0))))))
double code(double re, double im) {
	double tmp;
	if (re <= 2.45e-64) {
		tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
	} else if ((re <= 4.6e-53) || !(re <= 1.05e+32)) {
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	} else {
		tmp = 0.5 * sqrt((im * 2.0));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (re <= 2.45e-64) {
		tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
	} else if ((re <= 4.6e-53) || !(re <= 1.05e+32)) {
		tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
	} else {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= 2.45e-64:
		tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re)))
	elif (re <= 4.6e-53) or not (re <= 1.05e+32):
		tmp = 0.5 * (im * math.sqrt((1.0 / re)))
	else:
		tmp = 0.5 * math.sqrt((im * 2.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= 2.45e-64)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re))));
	elseif ((re <= 4.6e-53) || !(re <= 1.05e+32))
		tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re))));
	else
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= 2.45e-64)
		tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
	elseif ((re <= 4.6e-53) || ~((re <= 1.05e+32)))
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	else
		tmp = 0.5 * sqrt((im * 2.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, 2.45e-64], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 4.6e-53], N[Not[LessEqual[re, 1.05e+32]], $MachinePrecision]], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.45 \cdot 10^{-64}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\

\mathbf{elif}\;re \leq 4.6 \cdot 10^{-53} \lor \neg \left(re \leq 1.05 \cdot 10^{+32}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\


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

    1. Initial program 47.0%

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

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

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

    if 2.4500000000000001e-64 < re < 4.6000000000000003e-53 or 1.05e32 < re

    1. Initial program 8.8%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    4. Step-by-step derivation
      1. pow1/231.2%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right)}^{0.5}} \]
      2. pow-to-exp30.9%

        \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right) \cdot 0.5}} \]
      3. expm1-log1p-u31.0%

        \[\leadsto 0.5 \cdot e^{\log \left(2 \cdot \color{blue}{\left(\mathsf{hypot}\left(re, im\right) - re\right)}\right) \cdot 0.5} \]
      4. *-commutative31.0%

        \[\leadsto 0.5 \cdot e^{\log \color{blue}{\left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right)} \cdot 0.5} \]
    5. Applied egg-rr31.0%

      \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right) \cdot 0.5}} \]
    6. Taylor expanded in im around 0 79.7%

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

    if 4.6000000000000003e-53 < re < 1.05e32

    1. Initial program 41.0%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 77.2%

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{im}\right)\right)} \]
      2. expm1-udef69.0%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{im} \cdot \sqrt{2}}\right)} - 1\right) \]
      4. sqrt-unprod69.0%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{im \cdot 2}}\right)} - 1\right) \]
    4. Applied egg-rr69.0%

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot 2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.45 \cdot 10^{-64}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\ \mathbf{elif}\;re \leq 4.6 \cdot 10^{-53} \lor \neg \left(re \leq 1.05 \cdot 10^{+32}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]

Alternative 4: 76.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -9.6 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 1.86 \cdot 10^{-65}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 5.8 \cdot 10^{-53} \lor \neg \left(re \leq 1.4 \cdot 10^{+36}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -9.6e+70)
   (* 0.5 (sqrt (* 2.0 (* re -2.0))))
   (if (<= re 1.86e-65)
     (* 0.5 (sqrt (* 2.0 (- im re))))
     (if (or (<= re 5.8e-53) (not (<= re 1.4e+36)))
       (* 0.5 (* im (sqrt (/ 1.0 re))))
       (* 0.5 (sqrt (* im 2.0)))))))
double code(double re, double im) {
	double tmp;
	if (re <= -9.6e+70) {
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	} else if (re <= 1.86e-65) {
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	} else if ((re <= 5.8e-53) || !(re <= 1.4e+36)) {
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	} else {
		tmp = 0.5 * sqrt((im * 2.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-9.6d+70)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    else if (re <= 1.86d-65) then
        tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
    else if ((re <= 5.8d-53) .or. (.not. (re <= 1.4d+36))) then
        tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
    else
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -9.6e+70) {
		tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	} else if (re <= 1.86e-65) {
		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
	} else if ((re <= 5.8e-53) || !(re <= 1.4e+36)) {
		tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
	} else {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -9.6e+70:
		tmp = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	elif re <= 1.86e-65:
		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
	elif (re <= 5.8e-53) or not (re <= 1.4e+36):
		tmp = 0.5 * (im * math.sqrt((1.0 / re)))
	else:
		tmp = 0.5 * math.sqrt((im * 2.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -9.6e+70)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))));
	elseif (re <= 1.86e-65)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
	elseif ((re <= 5.8e-53) || !(re <= 1.4e+36))
		tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re))));
	else
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -9.6e+70)
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	elseif (re <= 1.86e-65)
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	elseif ((re <= 5.8e-53) || ~((re <= 1.4e+36)))
		tmp = 0.5 * (im * sqrt((1.0 / re)));
	else
		tmp = 0.5 * sqrt((im * 2.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -9.6e+70], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.86e-65], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 5.8e-53], N[Not[LessEqual[re, 1.4e+36]], $MachinePrecision]], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -9.6 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\

\mathbf{elif}\;re \leq 1.86 \cdot 10^{-65}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\

\mathbf{elif}\;re \leq 5.8 \cdot 10^{-53} \lor \neg \left(re \leq 1.4 \cdot 10^{+36}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\


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

    1. Initial program 28.2%

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
    3. Step-by-step derivation
      1. *-commutative89.6%

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

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

    if -9.59999999999999947e70 < re < 1.86000000000000006e-65

    1. Initial program 54.0%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 81.0%

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

    if 1.86000000000000006e-65 < re < 5.7999999999999996e-53 or 1.4e36 < re

    1. Initial program 8.8%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    4. Step-by-step derivation
      1. pow1/231.2%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right)}^{0.5}} \]
      2. pow-to-exp30.9%

        \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(2 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(re, im\right) - re\right)\right)\right) \cdot 0.5}} \]
      3. expm1-log1p-u31.0%

        \[\leadsto 0.5 \cdot e^{\log \left(2 \cdot \color{blue}{\left(\mathsf{hypot}\left(re, im\right) - re\right)}\right) \cdot 0.5} \]
      4. *-commutative31.0%

        \[\leadsto 0.5 \cdot e^{\log \color{blue}{\left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right)} \cdot 0.5} \]
    5. Applied egg-rr31.0%

      \[\leadsto 0.5 \cdot \color{blue}{e^{\log \left(\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2\right) \cdot 0.5}} \]
    6. Taylor expanded in im around 0 79.7%

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

    if 5.7999999999999996e-53 < re < 1.4e36

    1. Initial program 41.0%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 77.2%

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{im}\right)\right)} \]
      2. expm1-udef69.0%

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{im} \cdot \sqrt{2}}\right)} - 1\right) \]
      4. sqrt-unprod69.0%

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{im \cdot 2}}\right)} - 1\right) \]
    4. Applied egg-rr69.0%

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot 2}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -9.6 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 1.86 \cdot 10^{-65}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 5.8 \cdot 10^{-53} \lor \neg \left(re \leq 1.4 \cdot 10^{+36}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]

Alternative 5: 69.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -2.55 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 280000000000:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -2.55e+70)
   (* 0.5 (sqrt (* 2.0 (* re -2.0))))
   (if (<= re 280000000000.0)
     (* 0.5 (sqrt (* 2.0 (- im re))))
     (* 0.5 (sqrt (/ (* im im) re))))))
double code(double re, double im) {
	double tmp;
	if (re <= -2.55e+70) {
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	} else if (re <= 280000000000.0) {
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	} else {
		tmp = 0.5 * sqrt(((im * im) / re));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-2.55d+70)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    else if (re <= 280000000000.0d0) then
        tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
    else
        tmp = 0.5d0 * sqrt(((im * im) / re))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -2.55e+70) {
		tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	} else if (re <= 280000000000.0) {
		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
	} else {
		tmp = 0.5 * Math.sqrt(((im * im) / re));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -2.55e+70:
		tmp = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	elif re <= 280000000000.0:
		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
	else:
		tmp = 0.5 * math.sqrt(((im * im) / re))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -2.55e+70)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))));
	elseif (re <= 280000000000.0)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
	else
		tmp = Float64(0.5 * sqrt(Float64(Float64(im * im) / re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -2.55e+70)
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	elseif (re <= 280000000000.0)
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	else
		tmp = 0.5 * sqrt(((im * im) / re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -2.55e+70], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 280000000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.55 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\

\mathbf{elif}\;re \leq 280000000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\

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


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

    1. Initial program 28.2%

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
    3. Step-by-step derivation
      1. *-commutative89.6%

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

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

    if -2.55000000000000007e70 < re < 2.8e11

    1. Initial program 51.7%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 78.2%

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

    if 2.8e11 < re

    1. Initial program 8.8%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in im around 0 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{im}^{2}} \cdot \frac{1}{re}} \]
      2. associate-*r/48.6%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{{im}^{2} \cdot 1}{re}}} \]
      3. *-rgt-identity48.6%

        \[\leadsto 0.5 \cdot \sqrt{\frac{\color{blue}{{im}^{2}}}{re}} \]
      4. unpow248.6%

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

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

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

Alternative 6: 64.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+71}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -3.6e+71)
   (* 0.5 (sqrt (* 2.0 (* re -2.0))))
   (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
	double tmp;
	if (re <= -3.6e+71) {
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	} else {
		tmp = 0.5 * sqrt((im * 2.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-3.6d+71)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    else
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -3.6e+71) {
		tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	} else {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -3.6e+71:
		tmp = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	else:
		tmp = 0.5 * math.sqrt((im * 2.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -3.6e+71)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))));
	else
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -3.6e+71)
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	else
		tmp = 0.5 * sqrt((im * 2.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -3.6e+71], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\


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

    1. Initial program 28.2%

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
    3. Step-by-step derivation
      1. *-commutative89.6%

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

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

    if -3.6e71 < re

    1. Initial program 37.1%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 59.0%

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot 2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.6%

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

Alternative 7: 53.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \sqrt{im \cdot 2} \end{array} \]
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
double code(double re, double im) {
	return 0.5 * sqrt((im * 2.0));
}
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
public static double code(double re, double im) {
	return 0.5 * Math.sqrt((im * 2.0));
}
def code(re, im):
	return 0.5 * math.sqrt((im * 2.0))
function code(re, im)
	return Float64(0.5 * sqrt(Float64(im * 2.0)))
end
function tmp = code(re, im)
	tmp = 0.5 * sqrt((im * 2.0));
end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Derivation
  1. Initial program 35.6%

    \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
  2. Taylor expanded in re around 0 51.7%

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

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{im}\right)\right)} \]
    2. expm1-udef42.6%

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

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

      \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{im \cdot 2}}\right)} - 1\right) \]
  4. Applied egg-rr42.6%

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

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

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

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

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

Reproduce

?
herbie shell --seed 2023196 
(FPCore (re im)
  :name "math.sqrt on complex, imaginary part, im greater than 0 branch"
  :precision binary64
  :pre (> im 0.0)
  (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))