math.sqrt on complex, real part

Percentage Accurate: 41.3% → 85.0%
Time: 4.9s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 41.3% 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: 85.0% accurate, 0.5× speedup?

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

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

\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 (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0

    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-def8.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 45.1%

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

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

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

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

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

Alternative 2: 51.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{if}\;re \leq -1 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -2.5 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq -5.3 \cdot 10^{-40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 4 \cdot 10^{-85}:\\ \;\;\;\;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} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* im (/ (- im) re))))))
   (if (<= re -1e+100)
     t_0
     (if (<= re -2.5e-7)
       (* 0.5 (sqrt (* 2.0 im)))
       (if (<= re -5.3e-40)
         t_0
         (if (<= re 4e-85)
           (* 0.5 (sqrt (+ (/ (* re re) im) (* 2.0 (+ re im)))))
           (* 0.5 (* 2.0 (sqrt re)))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((im * (-im / re)));
	double tmp;
	if (re <= -1e+100) {
		tmp = t_0;
	} else if (re <= -2.5e-7) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else if (re <= -5.3e-40) {
		tmp = t_0;
	} else if (re <= 4e-85) {
		tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im))));
	} else {
		tmp = 0.5 * (2.0 * sqrt(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 = 0.5d0 * sqrt((im * (-im / re)))
    if (re <= (-1d+100)) then
        tmp = t_0
    else if (re <= (-2.5d-7)) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else if (re <= (-5.3d-40)) then
        tmp = t_0
    else if (re <= 4d-85) 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
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((im * (-im / re)));
	double tmp;
	if (re <= -1e+100) {
		tmp = t_0;
	} else if (re <= -2.5e-7) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else if (re <= -5.3e-40) {
		tmp = t_0;
	} else if (re <= 4e-85) {
		tmp = 0.5 * Math.sqrt((((re * re) / im) + (2.0 * (re + im))));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((im * (-im / re)))
	tmp = 0
	if re <= -1e+100:
		tmp = t_0
	elif re <= -2.5e-7:
		tmp = 0.5 * math.sqrt((2.0 * im))
	elif re <= -5.3e-40:
		tmp = t_0
	elif re <= 4e-85:
		tmp = 0.5 * math.sqrt((((re * re) / im) + (2.0 * (re + im))))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(im * Float64(Float64(-im) / re))))
	tmp = 0.0
	if (re <= -1e+100)
		tmp = t_0;
	elseif (re <= -2.5e-7)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	elseif (re <= -5.3e-40)
		tmp = t_0;
	elseif (re <= 4e-85)
		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
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((im * (-im / re)));
	tmp = 0.0;
	if (re <= -1e+100)
		tmp = t_0;
	elseif (re <= -2.5e-7)
		tmp = 0.5 * sqrt((2.0 * im));
	elseif (re <= -5.3e-40)
		tmp = t_0;
	elseif (re <= 4e-85)
		tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im))));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * N[((-im) / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1e+100], t$95$0, If[LessEqual[re, -2.5e-7], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -5.3e-40], t$95$0, If[LessEqual[re, 4e-85], 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}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\
\mathbf{if}\;re \leq -1 \cdot 10^{+100}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;re \leq -5.3 \cdot 10^{-40}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 4 \cdot 10^{-85}:\\
\;\;\;\;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 4 regimes
  2. if re < -1.00000000000000002e100 or -2.49999999999999989e-7 < re < -5.3000000000000002e-40

    1. Initial program 7.8%

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

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

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

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

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

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

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

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

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

        \[\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. *-commutative38.9%

        \[\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*38.9%

        \[\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/38.9%

        \[\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. *-commutative38.9%

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000002e100 < re < -2.49999999999999989e-7

    1. Initial program 28.7%

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

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

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

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

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

    if -5.3000000000000002e-40 < re < 3.9999999999999999e-85

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

    if 3.9999999999999999e-85 < re

    1. Initial program 50.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1 \cdot 10^{+100}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq -2.5 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq -5.3 \cdot 10^{-40}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq 4 \cdot 10^{-85}:\\ \;\;\;\;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 3: 52.0% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{if}\;re \leq -2.25 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.4 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq -2.35 \cdot 10^{-40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 1.8 \cdot 10^{-85}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* im (/ (- im) re))))))
   (if (<= re -2.25e+101)
     t_0
     (if (<= re -1.4e-7)
       (* 0.5 (sqrt (* 2.0 im)))
       (if (<= re -2.35e-40)
         t_0
         (if (<= re 1.8e-85)
           (* 0.5 (sqrt (* 2.0 (+ re im))))
           (* 0.5 (* 2.0 (sqrt re)))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((im * (-im / re)));
	double tmp;
	if (re <= -2.25e+101) {
		tmp = t_0;
	} else if (re <= -1.4e-7) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else if (re <= -2.35e-40) {
		tmp = t_0;
	} else if (re <= 1.8e-85) {
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	} else {
		tmp = 0.5 * (2.0 * sqrt(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 = 0.5d0 * sqrt((im * (-im / re)))
    if (re <= (-2.25d+101)) then
        tmp = t_0
    else if (re <= (-1.4d-7)) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else if (re <= (-2.35d-40)) then
        tmp = t_0
    else if (re <= 1.8d-85) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
    else
        tmp = 0.5d0 * (2.0d0 * sqrt(re))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((im * (-im / re)));
	double tmp;
	if (re <= -2.25e+101) {
		tmp = t_0;
	} else if (re <= -1.4e-7) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else if (re <= -2.35e-40) {
		tmp = t_0;
	} else if (re <= 1.8e-85) {
		tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((im * (-im / re)))
	tmp = 0
	if re <= -2.25e+101:
		tmp = t_0
	elif re <= -1.4e-7:
		tmp = 0.5 * math.sqrt((2.0 * im))
	elif re <= -2.35e-40:
		tmp = t_0
	elif re <= 1.8e-85:
		tmp = 0.5 * math.sqrt((2.0 * (re + im)))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(im * Float64(Float64(-im) / re))))
	tmp = 0.0
	if (re <= -2.25e+101)
		tmp = t_0;
	elseif (re <= -1.4e-7)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	elseif (re <= -2.35e-40)
		tmp = t_0;
	elseif (re <= 1.8e-85)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im))));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((im * (-im / re)));
	tmp = 0.0;
	if (re <= -2.25e+101)
		tmp = t_0;
	elseif (re <= -1.4e-7)
		tmp = 0.5 * sqrt((2.0 * im));
	elseif (re <= -2.35e-40)
		tmp = t_0;
	elseif (re <= 1.8e-85)
		tmp = 0.5 * sqrt((2.0 * (re + im)));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * N[((-im) / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.25e+101], t$95$0, If[LessEqual[re, -1.4e-7], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.35e-40], t$95$0, If[LessEqual[re, 1.8e-85], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\
\mathbf{if}\;re \leq -2.25 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;re \leq -2.35 \cdot 10^{-40}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 1.8 \cdot 10^{-85}:\\
\;\;\;\;0.5 \cdot \sqrt{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 4 regimes
  2. if re < -2.2500000000000001e101 or -1.4000000000000001e-7 < re < -2.35e-40

    1. Initial program 7.8%

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

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

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

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

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

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

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

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

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

        \[\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. *-commutative38.9%

        \[\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*38.9%

        \[\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/38.9%

        \[\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. *-commutative38.9%

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

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

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

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

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

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

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

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

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

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

    if -2.2500000000000001e101 < re < -1.4000000000000001e-7

    1. Initial program 28.7%

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

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

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

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

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

    if -2.35e-40 < re < 1.7999999999999999e-85

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

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

    if 1.7999999999999999e-85 < re

    1. Initial program 50.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.25 \cdot 10^{+101}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq -1.4 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{elif}\;re \leq -2.35 \cdot 10^{-40}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{-im}{re}}\\ \mathbf{elif}\;re \leq 1.8 \cdot 10^{-85}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \]

Alternative 4: 43.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -2.5 \cdot 10^{+219}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im}{re}}\\ \mathbf{elif}\;re \leq 4 \cdot 10^{-85}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -2.5e+219)
   (* 0.5 (sqrt (* im (/ im re))))
   (if (<= re 4e-85) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
	double tmp;
	if (re <= -2.5e+219) {
		tmp = 0.5 * sqrt((im * (im / re)));
	} else if (re <= 4e-85) {
		tmp = 0.5 * sqrt((2.0 * im));
	} else {
		tmp = 0.5 * (2.0 * sqrt(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.5d+219)) then
        tmp = 0.5d0 * sqrt((im * (im / re)))
    else if (re <= 4d-85) then
        tmp = 0.5d0 * sqrt((2.0d0 * im))
    else
        tmp = 0.5d0 * (2.0d0 * sqrt(re))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -2.5e+219) {
		tmp = 0.5 * Math.sqrt((im * (im / re)));
	} else if (re <= 4e-85) {
		tmp = 0.5 * Math.sqrt((2.0 * im));
	} else {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -2.5e+219:
		tmp = 0.5 * math.sqrt((im * (im / re)))
	elif re <= 4e-85:
		tmp = 0.5 * math.sqrt((2.0 * im))
	else:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -2.5e+219)
		tmp = Float64(0.5 * sqrt(Float64(im * Float64(im / re))));
	elseif (re <= 4e-85)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * im)));
	else
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -2.5e+219)
		tmp = 0.5 * sqrt((im * (im / re)));
	elseif (re <= 4e-85)
		tmp = 0.5 * sqrt((2.0 * im));
	else
		tmp = 0.5 * (2.0 * sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -2.5e+219], N[(0.5 * N[Sqrt[N[(im * N[(im / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4e-85], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.5 \cdot 10^{+219}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im}{re}}\\

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

\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 < -2.5e219

    1. Initial program 2.4%

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\frac{im}{\frac{re}{im}}} \cdot -0.5\right)} \]
    6. Simplified82.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-u80.5%

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

        \[\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. *-commutative74.9%

        \[\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*74.9%

        \[\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/74.9%

        \[\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. *-commutative74.9%

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}} \]
      3. rem-square-sqrt82.1%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left|\sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1} \cdot \sqrt{\left(im \cdot \frac{im}{re}\right) \cdot -1}\right|}} \]
      5. rem-square-sqrt82.1%

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\left|im \cdot \frac{im}{re}\right| \cdot \left|-1\right|}} \]
      7. rem-square-sqrt46.2%

        \[\leadsto 0.5 \cdot \sqrt{\left|\color{blue}{\sqrt{im \cdot \frac{im}{re}} \cdot \sqrt{im \cdot \frac{im}{re}}}\right| \cdot \left|-1\right|} \]
      8. fabs-sqr46.2%

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

        \[\leadsto 0.5 \cdot \sqrt{\left(\sqrt{im \cdot \frac{im}{re}} \cdot \sqrt{im \cdot \frac{im}{re}}\right) \cdot \color{blue}{1}} \]
      10. rem-square-sqrt46.2%

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

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

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

    if -2.5e219 < re < 3.9999999999999999e-85

    1. Initial program 40.0%

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

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

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

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

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

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

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

    if 3.9999999999999999e-85 < re

    1. Initial program 50.3%

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

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

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

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

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

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

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

Alternative 5: 42.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.3 \cdot 10^{-85}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\

\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 < 3.29999999999999973e-85

    1. Initial program 36.4%

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

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

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

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

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

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

    if 3.29999999999999973e-85 < re

    1. Initial program 50.3%

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

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

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

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

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

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

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

Alternative 6: 25.5% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

Developer target: 48.4% 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 2023200 
(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)))))