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

Percentage Accurate: 41.5% → 90.3%
Time: 9.5s
Alternatives: 7
Speedup: 2.1×

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: 41.5% accurate, 1.0× speedup?

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

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

Alternative 1: 90.3% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\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 9.6%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u60.1%

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{re}}\right)} - 1\right) \]
      5. add-sqr-sqrt14.4%

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{im}{\sqrt{re}}} \]
    8. Simplified99.7%

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

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

    1. Initial program 49.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
      7. metadata-eval89.0%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*89.0%

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

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)} \]
    7. Simplified89.0%

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

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

Alternative 2: 75.4% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.7 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq -2.5 \cdot 10^{+27}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\

\mathbf{elif}\;re \leq -3.7 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if re < -2.7e62

    1. Initial program 34.6%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    3. Step-by-step derivation
      1. *-commutative82.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified82.2%

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

    if -2.7e62 < re < -2.4999999999999999e27

    1. Initial program 68.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
      7. metadata-eval100.0%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    8. Taylor expanded in re around 0 80.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
    9. Step-by-step derivation
      1. neg-mul-180.3%

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

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

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

    if -2.4999999999999999e27 < re < -3.6999999999999998e-72

    1. Initial program 86.9%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re + -1 \cdot \frac{{im}^{2}}{re}}} \]
    3. Step-by-step derivation
      1. mul-1-neg67.0%

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

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

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

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

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

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

    if -3.6999999999999998e-72 < re < 3500

    1. Initial program 54.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3500 < re

    1. Initial program 12.3%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u51.2%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 75.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\ t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{if}\;re \leq -2.7 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -3.4 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -8.3 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 6 \cdot 10^{-37}\right) \land re \leq 2700:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (sqrt (* 0.5 (- im re)))))
   (if (<= re -2.7e+62)
     t_0
     (if (<= re -3.4e+28)
       t_1
       (if (<= re -8.3e-44)
         t_0
         (if (or (<= re 1.95e-92) (and (not (<= re 6e-37)) (<= re 2700.0)))
           t_1
           (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((re * -4.0));
	double t_1 = sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -2.7e+62) {
		tmp = t_0;
	} else if (re <= -3.4e+28) {
		tmp = t_1;
	} else if (re <= -8.3e-44) {
		tmp = t_0;
	} else if ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0))) {
		tmp = t_1;
	} else {
		tmp = 0.5 * (im / 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) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
    t_1 = sqrt((0.5d0 * (im - re)))
    if (re <= (-2.7d+62)) then
        tmp = t_0
    else if (re <= (-3.4d+28)) then
        tmp = t_1
    else if (re <= (-8.3d-44)) then
        tmp = t_0
    else if ((re <= 1.95d-92) .or. (.not. (re <= 6d-37)) .and. (re <= 2700.0d0)) then
        tmp = t_1
    else
        tmp = 0.5d0 * (im / sqrt(re))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((re * -4.0));
	double t_1 = Math.sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -2.7e+62) {
		tmp = t_0;
	} else if (re <= -3.4e+28) {
		tmp = t_1;
	} else if (re <= -8.3e-44) {
		tmp = t_0;
	} else if ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0))) {
		tmp = t_1;
	} else {
		tmp = 0.5 * (im / Math.sqrt(re));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((re * -4.0))
	t_1 = math.sqrt((0.5 * (im - re)))
	tmp = 0
	if re <= -2.7e+62:
		tmp = t_0
	elif re <= -3.4e+28:
		tmp = t_1
	elif re <= -8.3e-44:
		tmp = t_0
	elif (re <= 1.95e-92) or (not (re <= 6e-37) and (re <= 2700.0)):
		tmp = t_1
	else:
		tmp = 0.5 * (im / math.sqrt(re))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(re * -4.0)))
	t_1 = sqrt(Float64(0.5 * Float64(im - re)))
	tmp = 0.0
	if (re <= -2.7e+62)
		tmp = t_0;
	elseif (re <= -3.4e+28)
		tmp = t_1;
	elseif (re <= -8.3e-44)
		tmp = t_0;
	elseif ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0)))
		tmp = t_1;
	else
		tmp = Float64(0.5 * Float64(im / sqrt(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((re * -4.0));
	t_1 = sqrt((0.5 * (im - re)));
	tmp = 0.0;
	if (re <= -2.7e+62)
		tmp = t_0;
	elseif (re <= -3.4e+28)
		tmp = t_1;
	elseif (re <= -8.3e-44)
		tmp = t_0;
	elseif ((re <= 1.95e-92) || (~((re <= 6e-37)) && (re <= 2700.0)))
		tmp = t_1;
	else
		tmp = 0.5 * (im / sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -2.7e+62], t$95$0, If[LessEqual[re, -3.4e+28], t$95$1, If[LessEqual[re, -8.3e-44], t$95$0, If[Or[LessEqual[re, 1.95e-92], And[N[Not[LessEqual[re, 6e-37]], $MachinePrecision], LessEqual[re, 2700.0]]], t$95$1, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -2.7 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq -3.4 \cdot 10^{+28}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;re \leq -8.3 \cdot 10^{-44}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 6 \cdot 10^{-37}\right) \land re \leq 2700:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -2.7e62 or -3.4e28 < re < -8.2999999999999999e-44

    1. Initial program 49.7%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    3. Step-by-step derivation
      1. *-commutative78.5%

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

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

    if -2.7e62 < re < -3.4e28 or -8.2999999999999999e-44 < re < 1.9499999999999998e-92 or 6e-37 < re < 2700

    1. Initial program 59.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*94.1%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    8. Taylor expanded in re around 0 82.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
    9. Step-by-step derivation
      1. neg-mul-182.3%

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

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

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

    if 1.9499999999999998e-92 < re < 6e-37 or 2700 < re

    1. Initial program 18.2%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u48.1%

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{re}}\right)} - 1\right) \]
      5. add-sqr-sqrt22.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.7 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -3.4 \cdot 10^{+28}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -8.3 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 6 \cdot 10^{-37}\right) \land re \leq 2700:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\ \end{array} \]

Alternative 4: 75.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{if}\;re \leq -2.75 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -1.9 \cdot 10^{+26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 1.1 \cdot 10^{-37}\right) \land re \leq 2700:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (sqrt (* 0.5 (- im re)))))
   (if (<= re -2.75e+62)
     (* 0.5 (sqrt (* re -4.0)))
     (if (<= re -1.9e+26)
       t_0
       (if (<= re -3.8e-44)
         (* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
         (if (or (<= re 1.95e-92) (and (not (<= re 1.1e-37)) (<= re 2700.0)))
           t_0
           (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
	double t_0 = sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -2.75e+62) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if (re <= -1.9e+26) {
		tmp = t_0;
	} else if (re <= -3.8e-44) {
		tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
	} else if ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0))) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (im / 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 = sqrt((0.5d0 * (im - re)))
    if (re <= (-2.75d+62)) then
        tmp = 0.5d0 * sqrt((re * (-4.0d0)))
    else if (re <= (-1.9d+26)) then
        tmp = t_0
    else if (re <= (-3.8d-44)) then
        tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
    else if ((re <= 1.95d-92) .or. (.not. (re <= 1.1d-37)) .and. (re <= 2700.0d0)) then
        tmp = t_0
    else
        tmp = 0.5d0 * (im / sqrt(re))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -2.75e+62) {
		tmp = 0.5 * Math.sqrt((re * -4.0));
	} else if (re <= -1.9e+26) {
		tmp = t_0;
	} else if (re <= -3.8e-44) {
		tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
	} else if ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0))) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (im / Math.sqrt(re));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sqrt((0.5 * (im - re)))
	tmp = 0
	if re <= -2.75e+62:
		tmp = 0.5 * math.sqrt((re * -4.0))
	elif re <= -1.9e+26:
		tmp = t_0
	elif re <= -3.8e-44:
		tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im))))
	elif (re <= 1.95e-92) or (not (re <= 1.1e-37) and (re <= 2700.0)):
		tmp = t_0
	else:
		tmp = 0.5 * (im / math.sqrt(re))
	return tmp
function code(re, im)
	t_0 = sqrt(Float64(0.5 * Float64(im - re)))
	tmp = 0.0
	if (re <= -2.75e+62)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif (re <= -1.9e+26)
		tmp = t_0;
	elseif (re <= -3.8e-44)
		tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im)))));
	elseif ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0)))
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(im / sqrt(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sqrt((0.5 * (im - re)));
	tmp = 0.0;
	if (re <= -2.75e+62)
		tmp = 0.5 * sqrt((re * -4.0));
	elseif (re <= -1.9e+26)
		tmp = t_0;
	elseif (re <= -3.8e-44)
		tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
	elseif ((re <= 1.95e-92) || (~((re <= 1.1e-37)) && (re <= 2700.0)))
		tmp = t_0;
	else
		tmp = 0.5 * (im / sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -2.75e+62], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.9e+26], t$95$0, If[LessEqual[re, -3.8e-44], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.95e-92], And[N[Not[LessEqual[re, 1.1e-37]], $MachinePrecision], LessEqual[re, 2700.0]]], t$95$0, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -2.75 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq -1.9 \cdot 10^{+26}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\

\mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 1.1 \cdot 10^{-37}\right) \land re \leq 2700:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 34.6%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    3. Step-by-step derivation
      1. *-commutative82.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified82.2%

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

    if -2.7499999999999998e62 < re < -1.9000000000000001e26 or -3.8000000000000001e-44 < re < 1.9499999999999998e-92 or 1.10000000000000001e-37 < re < 2700

    1. Initial program 59.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*94.1%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    8. Taylor expanded in re around 0 82.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
    9. Step-by-step derivation
      1. neg-mul-182.3%

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

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

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

    if -1.9000000000000001e26 < re < -3.8000000000000001e-44

    1. Initial program 84.0%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re + -1 \cdot \frac{{im}^{2}}{re}}} \]
    3. Step-by-step derivation
      1. mul-1-neg69.9%

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

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

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

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

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

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

    if 1.9499999999999998e-92 < re < 1.10000000000000001e-37 or 2700 < re

    1. Initial program 18.2%

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

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

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\frac{im \cdot im}{re}}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u48.1%

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{im} \cdot \sqrt{im}}}{\sqrt{re}}\right)} - 1\right) \]
      5. add-sqr-sqrt22.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.75 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -1.9 \cdot 10^{+26}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\ \mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 1.1 \cdot 10^{-37}\right) \land re \leq 2700:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\ \end{array} \]

Alternative 5: 63.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{if}\;re \leq -5.8 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{+24}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -2.3 \cdot 10^{-67}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im \cdot 0.5}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* re -4.0)))))
   (if (<= re -5.8e+63)
     t_0
     (if (<= re -1.6e+24)
       (sqrt (* 0.5 (- im re)))
       (if (<= re -2.3e-67) t_0 (sqrt (* im 0.5)))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((re * -4.0));
	double tmp;
	if (re <= -5.8e+63) {
		tmp = t_0;
	} else if (re <= -1.6e+24) {
		tmp = sqrt((0.5 * (im - re)));
	} else if (re <= -2.3e-67) {
		tmp = t_0;
	} else {
		tmp = sqrt((im * 0.5));
	}
	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((re * (-4.0d0)))
    if (re <= (-5.8d+63)) then
        tmp = t_0
    else if (re <= (-1.6d+24)) then
        tmp = sqrt((0.5d0 * (im - re)))
    else if (re <= (-2.3d-67)) then
        tmp = t_0
    else
        tmp = sqrt((im * 0.5d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((re * -4.0));
	double tmp;
	if (re <= -5.8e+63) {
		tmp = t_0;
	} else if (re <= -1.6e+24) {
		tmp = Math.sqrt((0.5 * (im - re)));
	} else if (re <= -2.3e-67) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt((im * 0.5));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((re * -4.0))
	tmp = 0
	if re <= -5.8e+63:
		tmp = t_0
	elif re <= -1.6e+24:
		tmp = math.sqrt((0.5 * (im - re)))
	elif re <= -2.3e-67:
		tmp = t_0
	else:
		tmp = math.sqrt((im * 0.5))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(re * -4.0)))
	tmp = 0.0
	if (re <= -5.8e+63)
		tmp = t_0;
	elseif (re <= -1.6e+24)
		tmp = sqrt(Float64(0.5 * Float64(im - re)));
	elseif (re <= -2.3e-67)
		tmp = t_0;
	else
		tmp = sqrt(Float64(im * 0.5));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((re * -4.0));
	tmp = 0.0;
	if (re <= -5.8e+63)
		tmp = t_0;
	elseif (re <= -1.6e+24)
		tmp = sqrt((0.5 * (im - re)));
	elseif (re <= -2.3e-67)
		tmp = t_0;
	else
		tmp = sqrt((im * 0.5));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -5.8e+63], t$95$0, If[LessEqual[re, -1.6e+24], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -2.3e-67], t$95$0, N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{if}\;re \leq -5.8 \cdot 10^{+63}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq -1.6 \cdot 10^{+24}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\

\mathbf{elif}\;re \leq -2.3 \cdot 10^{-67}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -5.7999999999999999e63 or -1.5999999999999999e24 < re < -2.3e-67

    1. Initial program 52.9%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    3. Step-by-step derivation
      1. *-commutative76.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.9%

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

    if -5.7999999999999999e63 < re < -1.5999999999999999e24

    1. Initial program 68.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
      7. metadata-eval100.0%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    8. Taylor expanded in re around 0 80.3%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
    9. Step-by-step derivation
      1. neg-mul-180.3%

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

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

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

    if -2.3e-67 < re

    1. Initial program 39.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
      7. metadata-eval67.9%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*67.9%

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

        \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)} \]
    7. Simplified67.9%

      \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    8. Taylor expanded in re around 0 57.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -5.8 \cdot 10^{+63}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{+24}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -2.3 \cdot 10^{-67}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im \cdot 0.5}\\ \end{array} \]

Alternative 6: 54.9% accurate, 2.0× speedup?

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

\\
\sqrt{0.5 \cdot \left(im - re\right)}
\end{array}
Derivation
  1. Initial program 43.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
    7. metadata-eval76.9%

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

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

      \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    2. associate-*r*76.9%

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

      \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)} \]
  7. Simplified76.9%

    \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
  8. Taylor expanded in re around 0 52.7%

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
  9. Step-by-step derivation
    1. neg-mul-152.7%

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

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

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im - re\right)}} \]
  11. Final simplification52.7%

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

Alternative 7: 52.6% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)} \cdot \left(0.5 \cdot 0.5\right)} \]
    7. metadata-eval76.9%

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

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

      \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    2. associate-*r*76.9%

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

      \[\leadsto \sqrt{\color{blue}{0.5} \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)} \]
  7. Simplified76.9%

    \[\leadsto \color{blue}{\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
  8. Taylor expanded in re around 0 50.5%

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{im}} \]
  9. Final simplification50.5%

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

Reproduce

?
herbie shell --seed 2023285 
(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)))))