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

Percentage Accurate: 42.0% → 90.4%
Time: 10.0s
Alternatives: 8
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 42.0% accurate, 1.0× speedup?

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

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

Alternative 1: 90.4% 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 \left(im \cdot {re}^{-0.5}\right)\\ \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 (pow re -0.5)))
   (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 * pow(re, -0.5));
	} 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.pow(re, -0.5));
	} 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.pow(re, -0.5))
	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 * (re ^ -0.5)));
	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 * (re ^ -0.5));
	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[Power[re, -0.5], $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 \left(im \cdot {re}^{-0.5}\right)\\

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/299.6%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-193.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow93.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log99.8%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified99.8%

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

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

    1. Initial program 39.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 76.2% accurate, 1.0× speedup?

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

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

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

\mathbf{elif}\;re \leq 4.5 \cdot 10^{-28}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\

\mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{im} \cdot \sqrt{2}\right)\\

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


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

    1. Initial program 32.0%

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

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

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

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

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

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

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

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

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

    if -2.59999999999999998e53 < re < 8.2000000000000001e-54

    1. Initial program 53.3%

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

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

    if 8.2000000000000001e-54 < re < 4.4999999999999998e-28

    1. Initial program 4.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/299.7%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-194.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified100.0%

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

    if 4.4999999999999998e-28 < re < 1.1800000000000001e46

    1. Initial program 23.5%

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

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

    if 1.1800000000000001e46 < re

    1. Initial program 10.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.6 \cdot 10^{+53}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-0.5 \cdot \frac{im}{\frac{re}{im}} - re\right) - re\right)}\\ \mathbf{elif}\;re \leq 8.2 \cdot 10^{-54}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 4.5 \cdot 10^{-28}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{im} \cdot \sqrt{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{2 \cdot \frac{0.5}{re}}\right)\\ \end{array} \]

Alternative 3: 75.5% accurate, 1.7× speedup?

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

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

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

\mathbf{elif}\;re \leq 7 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\

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

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


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

    1. Initial program 27.0%

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

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

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

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

    if -6.09999999999999984e96 < re < 3.9499999999999999e-53

    1. Initial program 53.6%

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

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

    if 3.9499999999999999e-53 < re < 6.9999999999999997e-18

    1. Initial program 4.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/299.7%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-194.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified100.0%

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

    if 6.9999999999999997e-18 < re < 1.1800000000000001e46

    1. Initial program 23.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 68.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. unpow268.1%

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

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

    if 1.1800000000000001e46 < re

    1. Initial program 10.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6.1 \cdot 10^{+96}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 3.95 \cdot 10^{-53}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 7 \cdot 10^{-18}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(im + 0.5 \cdot \frac{re \cdot re}{im}\right) - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{2 \cdot \frac{0.5}{re}}\right)\\ \end{array} \]

Alternative 4: 76.1% accurate, 1.7× speedup?

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

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

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

\mathbf{elif}\;re \leq 1.02 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\

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

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


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

    1. Initial program 32.0%

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

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

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

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

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

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

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

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

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

    if -2.70000000000000019e53 < re < 2.15e-54

    1. Initial program 53.3%

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

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

    if 2.15e-54 < re < 1.02000000000000005e-23

    1. Initial program 4.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/299.7%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-194.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified100.0%

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

    if 1.02000000000000005e-23 < re < 1.1800000000000001e46

    1. Initial program 23.5%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Taylor expanded in re around 0 68.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. unpow268.1%

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

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

    if 1.1800000000000001e46 < re

    1. Initial program 10.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.7 \cdot 10^{+53}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-0.5 \cdot \frac{im}{\frac{re}{im}} - re\right) - re\right)}\\ \mathbf{elif}\;re \leq 2.15 \cdot 10^{-54}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 1.02 \cdot 10^{-23}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(im + 0.5 \cdot \frac{re \cdot re}{im}\right) - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{2 \cdot \frac{0.5}{re}}\right)\\ \end{array} \]

Alternative 5: 75.4% accurate, 1.8× speedup?

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

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

\mathbf{elif}\;re \leq 3.5 \cdot 10^{-55}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 9.5 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\

\mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 27.0%

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

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

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

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

    if -9.2000000000000006e96 < re < 3.50000000000000025e-55 or 9.50000000000000029e-17 < re < 1.1800000000000001e46

    1. Initial program 50.5%

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

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

    if 3.50000000000000025e-55 < re < 9.50000000000000029e-17

    1. Initial program 4.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/299.7%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-194.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow94.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified100.0%

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

    if 1.1800000000000001e46 < re

    1. Initial program 10.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -9.2 \cdot 10^{+96}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 3.5 \cdot 10^{-55}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 9.5 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{2 \cdot \frac{0.5}{re}}\right)\\ \end{array} \]

Alternative 6: 75.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -6.4 \cdot 10^{+96}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{-53} \lor \neg \left(re \leq 10^{-20}\right) \land re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -6.4e+96)
   (* 0.5 (sqrt (* 2.0 (* re -2.0))))
   (if (or (<= re 9e-53) (and (not (<= re 1e-20)) (<= re 1.18e+46)))
     (* 0.5 (sqrt (* 2.0 (- im re))))
     (* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
	double tmp;
	if (re <= -6.4e+96) {
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	} else if ((re <= 9e-53) || (!(re <= 1e-20) && (re <= 1.18e+46))) {
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	} else {
		tmp = 0.5 * (im * pow(re, -0.5));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-6.4d+96)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    else if ((re <= 9d-53) .or. (.not. (re <= 1d-20)) .and. (re <= 1.18d+46)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
    else
        tmp = 0.5d0 * (im * (re ** (-0.5d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -6.4e+96) {
		tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	} else if ((re <= 9e-53) || (!(re <= 1e-20) && (re <= 1.18e+46))) {
		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
	} else {
		tmp = 0.5 * (im * Math.pow(re, -0.5));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -6.4e+96:
		tmp = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	elif (re <= 9e-53) or (not (re <= 1e-20) and (re <= 1.18e+46)):
		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
	else:
		tmp = 0.5 * (im * math.pow(re, -0.5))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -6.4e+96)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))));
	elseif ((re <= 9e-53) || (!(re <= 1e-20) && (re <= 1.18e+46)))
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
	else
		tmp = Float64(0.5 * Float64(im * (re ^ -0.5)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -6.4e+96)
		tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
	elseif ((re <= 9e-53) || (~((re <= 1e-20)) && (re <= 1.18e+46)))
		tmp = 0.5 * sqrt((2.0 * (im - re)));
	else
		tmp = 0.5 * (im * (re ^ -0.5));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -6.4e+96], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 9e-53], And[N[Not[LessEqual[re, 1e-20]], $MachinePrecision], LessEqual[re, 1.18e+46]]], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;re \leq 9 \cdot 10^{-53} \lor \neg \left(re \leq 10^{-20}\right) \land re \leq 1.18 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\

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


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

    1. Initial program 27.0%

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

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

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

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

    if -6.40000000000000013e96 < re < 8.9999999999999997e-53 or 9.99999999999999945e-21 < re < 1.1800000000000001e46

    1. Initial program 50.5%

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

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

    if 8.9999999999999997e-53 < re < 9.99999999999999945e-21 or 1.1800000000000001e46 < re

    1. Initial program 9.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/276.3%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-171.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow71.9%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log76.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6.4 \cdot 10^{+96}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 9 \cdot 10^{-53} \lor \neg \left(re \leq 10^{-20}\right) \land re \leq 1.18 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \end{array} \]

Alternative 7: 52.7% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 48.3%

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

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

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

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

    if -4.999999999999985e-310 < re

    1. Initial program 23.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
      7. unpow1/252.1%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      8. exp-to-pow49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      9. log-rec49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
      10. *-commutative49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
      11. neg-mul-149.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      12. associate-*r*49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      13. metadata-eval49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      14. log-pow49.1%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      15. rem-exp-log52.1%

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

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

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

Alternative 8: 25.8% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(im \cdot \sqrt{\frac{\color{blue}{1}}{re}}\right) \]
    7. unpow1/226.8%

      \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
    8. exp-to-pow25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
    9. log-rec25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(-\log re\right)} \cdot 0.5}\right) \]
    10. *-commutative25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \left(-\log re\right)}}\right) \]
    11. neg-mul-125.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
    12. associate-*r*25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
    13. metadata-eval25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
    14. log-pow25.3%

      \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
    15. rem-exp-log26.9%

      \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
  10. Simplified26.9%

    \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot {re}^{-0.5}\right)} \]
  11. Final simplification26.9%

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

Reproduce

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