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

Percentage Accurate: 41.3% → 89.9%
Time: 13.0s
Alternatives: 7
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 41.3% accurate, 1.0× speedup?

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

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

Alternative 1: 89.9% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 10.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \left(\left(im \cdot \color{blue}{1}\right) \cdot \sqrt{\frac{1}{re}}\right)}\right)}^{3} \]
      7. *-rgt-identity92.5%

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

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

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right)}\right)}^{3} \]
      10. un-div-inv92.3%

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \color{blue}{\frac{im}{\sqrt{re}}}}\right)}^{3} \]
    9. Applied egg-rr92.3%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{0.5 \cdot \frac{im}{\sqrt{re}}}\right)}^{3}} \]
    10. Step-by-step derivation
      1. rem-cube-cbrt93.9%

        \[\leadsto \color{blue}{0.5 \cdot \frac{im}{\sqrt{re}}} \]
      2. clear-num93.9%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1}{\frac{\sqrt{re}}{im}}} \]
      3. un-div-inv93.9%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{\sqrt{re}}{im}}} \]
    11. Applied egg-rr93.9%

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

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

    1. Initial program 48.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\left(\sqrt{{re}^{2} + \color{blue}{{im}^{2}}} - re\right) \cdot \left(2 \cdot 0.25\right)} \]
      5. +-commutative48.9%

        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{{im}^{2} + {re}^{2}}} - re\right) \cdot \left(2 \cdot 0.25\right)} \]
      6. unpow248.9%

        \[\leadsto \sqrt{\left(\sqrt{\color{blue}{im \cdot im} + {re}^{2}} - re\right) \cdot \left(2 \cdot 0.25\right)} \]
      7. unpow248.9%

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

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

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

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

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

Alternative 2: 75.1% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{if}\;re \leq -8 \cdot 10^{+34}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq -2.6 \cdot 10^{-40}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq -2.15 \cdot 10^{-70}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{-86}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 3.4 \cdot 10^{+30}:\\ \;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\ \mathbf{elif}\;re \leq 1.65 \cdot 10^{+58}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* 2.0 (- im re)))))
        (t_1 (* 0.5 (sqrt (* 2.0 (* re -2.0))))))
   (if (<= re -8e+34)
     t_1
     (if (<= re -2.6e-40)
       t_0
       (if (<= re -2.15e-70)
         t_1
         (if (<= re 8.5e-86)
           t_0
           (if (<= re 3.4e+30)
             (/ 0.5 (/ (sqrt re) im))
             (if (<= re 1.65e+58) t_0 (/ (* im 0.5) (sqrt re))))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((2.0 * (im - re)));
	double t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -8e+34) {
		tmp = t_1;
	} else if (re <= -2.6e-40) {
		tmp = t_0;
	} else if (re <= -2.15e-70) {
		tmp = t_1;
	} else if (re <= 8.5e-86) {
		tmp = t_0;
	} else if (re <= 3.4e+30) {
		tmp = 0.5 / (sqrt(re) / im);
	} else if (re <= 1.65e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / sqrt(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt((2.0d0 * (im - re)))
    t_1 = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    if (re <= (-8d+34)) then
        tmp = t_1
    else if (re <= (-2.6d-40)) then
        tmp = t_0
    else if (re <= (-2.15d-70)) then
        tmp = t_1
    else if (re <= 8.5d-86) then
        tmp = t_0
    else if (re <= 3.4d+30) then
        tmp = 0.5d0 / (sqrt(re) / im)
    else if (re <= 1.65d+58) then
        tmp = t_0
    else
        tmp = (im * 0.5d0) / sqrt(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 t_1 = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -8e+34) {
		tmp = t_1;
	} else if (re <= -2.6e-40) {
		tmp = t_0;
	} else if (re <= -2.15e-70) {
		tmp = t_1;
	} else if (re <= 8.5e-86) {
		tmp = t_0;
	} else if (re <= 3.4e+30) {
		tmp = 0.5 / (Math.sqrt(re) / im);
	} else if (re <= 1.65e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / Math.sqrt(re);
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((2.0 * (im - re)))
	t_1 = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	tmp = 0
	if re <= -8e+34:
		tmp = t_1
	elif re <= -2.6e-40:
		tmp = t_0
	elif re <= -2.15e-70:
		tmp = t_1
	elif re <= 8.5e-86:
		tmp = t_0
	elif re <= 3.4e+30:
		tmp = 0.5 / (math.sqrt(re) / im)
	elif re <= 1.65e+58:
		tmp = t_0
	else:
		tmp = (im * 0.5) / math.sqrt(re)
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))))
	t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))))
	tmp = 0.0
	if (re <= -8e+34)
		tmp = t_1;
	elseif (re <= -2.6e-40)
		tmp = t_0;
	elseif (re <= -2.15e-70)
		tmp = t_1;
	elseif (re <= 8.5e-86)
		tmp = t_0;
	elseif (re <= 3.4e+30)
		tmp = Float64(0.5 / Float64(sqrt(re) / im));
	elseif (re <= 1.65e+58)
		tmp = t_0;
	else
		tmp = Float64(Float64(im * 0.5) / sqrt(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((2.0 * (im - re)));
	t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	tmp = 0.0;
	if (re <= -8e+34)
		tmp = t_1;
	elseif (re <= -2.6e-40)
		tmp = t_0;
	elseif (re <= -2.15e-70)
		tmp = t_1;
	elseif (re <= 8.5e-86)
		tmp = t_0;
	elseif (re <= 3.4e+30)
		tmp = 0.5 / (sqrt(re) / im);
	elseif (re <= 1.65e+58)
		tmp = t_0;
	else
		tmp = (im * 0.5) / sqrt(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]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -8e+34], t$95$1, If[LessEqual[re, -2.6e-40], t$95$0, If[LessEqual[re, -2.15e-70], t$95$1, If[LessEqual[re, 8.5e-86], t$95$0, If[LessEqual[re, 3.4e+30], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.65e+58], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{if}\;re \leq -8 \cdot 10^{+34}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq -2.6 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq -2.15 \cdot 10^{-70}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq 8.5 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq 3.4 \cdot 10^{+30}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\

\mathbf{elif}\;re \leq 1.65 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -7.99999999999999956e34 or -2.6000000000000001e-40 < re < -2.15e-70

    1. Initial program 49.4%

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

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

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

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

    if -7.99999999999999956e34 < re < -2.6000000000000001e-40 or -2.15e-70 < re < 8.499999999999999e-86 or 3.4000000000000002e30 < re < 1.64999999999999991e58

    1. Initial program 57.1%

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

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

    if 8.499999999999999e-86 < re < 3.4000000000000002e30

    1. Initial program 34.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \left(im \cdot \left(\sqrt{2} \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
    8. Step-by-step derivation
      1. add-cube-cbrt59.3%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right)}\right)}^{3} \]
      10. un-div-inv59.7%

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \color{blue}{\frac{im}{\sqrt{re}}}}\right)}^{3} \]
    9. Applied egg-rr59.7%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{0.5 \cdot \frac{im}{\sqrt{re}}}\right)}^{3}} \]
    10. Step-by-step derivation
      1. rem-cube-cbrt60.7%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1}{\frac{\sqrt{re}}{im}}} \]
      3. un-div-inv60.8%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{\sqrt{re}}{im}}} \]
    11. Applied egg-rr60.8%

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

    if 1.64999999999999991e58 < re

    1. Initial program 9.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{im} \cdot 0.5}{\sqrt{re}} \]
    9. Applied egg-rr88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -8 \cdot 10^{+34}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq -2.6 \cdot 10^{-40}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -2.15 \cdot 10^{-70}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{-86}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 3.4 \cdot 10^{+30}:\\ \;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\ \mathbf{elif}\;re \leq 1.65 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{if}\;re \leq -1.6 \cdot 10^{+35}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq -1.52 \cdot 10^{-43}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq -1.45 \cdot 10^{-70}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq 8 \cdot 10^{-86}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 3.6 \cdot 10^{+30}:\\ \;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* 2.0 (- im re)))))
        (t_1 (* 0.5 (sqrt (* 2.0 (* re -2.0))))))
   (if (<= re -1.6e+35)
     t_1
     (if (<= re -1.52e-43)
       t_0
       (if (<= re -1.45e-70)
         t_1
         (if (<= re 8e-86)
           t_0
           (if (<= re 3.6e+30)
             (/ 0.5 (/ (sqrt re) im))
             (if (<= re 1.5e+58) t_0 (* (* im 0.5) (sqrt (/ 1.0 re)))))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((2.0 * (im - re)));
	double t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -1.6e+35) {
		tmp = t_1;
	} else if (re <= -1.52e-43) {
		tmp = t_0;
	} else if (re <= -1.45e-70) {
		tmp = t_1;
	} else if (re <= 8e-86) {
		tmp = t_0;
	} else if (re <= 3.6e+30) {
		tmp = 0.5 / (sqrt(re) / im);
	} else if (re <= 1.5e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) * sqrt((1.0 / re));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt((2.0d0 * (im - re)))
    t_1 = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    if (re <= (-1.6d+35)) then
        tmp = t_1
    else if (re <= (-1.52d-43)) then
        tmp = t_0
    else if (re <= (-1.45d-70)) then
        tmp = t_1
    else if (re <= 8d-86) then
        tmp = t_0
    else if (re <= 3.6d+30) then
        tmp = 0.5d0 / (sqrt(re) / im)
    else if (re <= 1.5d+58) then
        tmp = t_0
    else
        tmp = (im * 0.5d0) * sqrt((1.0d0 / 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 t_1 = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -1.6e+35) {
		tmp = t_1;
	} else if (re <= -1.52e-43) {
		tmp = t_0;
	} else if (re <= -1.45e-70) {
		tmp = t_1;
	} else if (re <= 8e-86) {
		tmp = t_0;
	} else if (re <= 3.6e+30) {
		tmp = 0.5 / (Math.sqrt(re) / im);
	} else if (re <= 1.5e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) * Math.sqrt((1.0 / re));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((2.0 * (im - re)))
	t_1 = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	tmp = 0
	if re <= -1.6e+35:
		tmp = t_1
	elif re <= -1.52e-43:
		tmp = t_0
	elif re <= -1.45e-70:
		tmp = t_1
	elif re <= 8e-86:
		tmp = t_0
	elif re <= 3.6e+30:
		tmp = 0.5 / (math.sqrt(re) / im)
	elif re <= 1.5e+58:
		tmp = t_0
	else:
		tmp = (im * 0.5) * math.sqrt((1.0 / re))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))))
	t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))))
	tmp = 0.0
	if (re <= -1.6e+35)
		tmp = t_1;
	elseif (re <= -1.52e-43)
		tmp = t_0;
	elseif (re <= -1.45e-70)
		tmp = t_1;
	elseif (re <= 8e-86)
		tmp = t_0;
	elseif (re <= 3.6e+30)
		tmp = Float64(0.5 / Float64(sqrt(re) / im));
	elseif (re <= 1.5e+58)
		tmp = t_0;
	else
		tmp = Float64(Float64(im * 0.5) * sqrt(Float64(1.0 / re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((2.0 * (im - re)));
	t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	tmp = 0.0;
	if (re <= -1.6e+35)
		tmp = t_1;
	elseif (re <= -1.52e-43)
		tmp = t_0;
	elseif (re <= -1.45e-70)
		tmp = t_1;
	elseif (re <= 8e-86)
		tmp = t_0;
	elseif (re <= 3.6e+30)
		tmp = 0.5 / (sqrt(re) / im);
	elseif (re <= 1.5e+58)
		tmp = t_0;
	else
		tmp = (im * 0.5) * sqrt((1.0 / 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]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.6e+35], t$95$1, If[LessEqual[re, -1.52e-43], t$95$0, If[LessEqual[re, -1.45e-70], t$95$1, If[LessEqual[re, 8e-86], t$95$0, If[LessEqual[re, 3.6e+30], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.5e+58], t$95$0, N[(N[(im * 0.5), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{if}\;re \leq -1.6 \cdot 10^{+35}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq -1.52 \cdot 10^{-43}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq -1.45 \cdot 10^{-70}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq 8 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq 3.6 \cdot 10^{+30}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\

\mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -1.59999999999999991e35 or -1.52e-43 < re < -1.44999999999999986e-70

    1. Initial program 49.4%

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

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

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

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

    if -1.59999999999999991e35 < re < -1.52e-43 or -1.44999999999999986e-70 < re < 8.00000000000000068e-86 or 3.6000000000000002e30 < re < 1.5000000000000001e58

    1. Initial program 57.1%

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

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

    if 8.00000000000000068e-86 < re < 3.6000000000000002e30

    1. Initial program 34.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \left(im \cdot \left(\sqrt{2} \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{\frac{1}{re}}} \]
    8. Step-by-step derivation
      1. add-cube-cbrt59.3%

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right)}\right)}^{3} \]
      10. un-div-inv59.7%

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \color{blue}{\frac{im}{\sqrt{re}}}}\right)}^{3} \]
    9. Applied egg-rr59.7%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{0.5 \cdot \frac{im}{\sqrt{re}}}\right)}^{3}} \]
    10. Step-by-step derivation
      1. rem-cube-cbrt60.7%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1}{\frac{\sqrt{re}}{im}}} \]
      3. un-div-inv60.8%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{\sqrt{re}}{im}}} \]
    11. Applied egg-rr60.8%

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

    if 1.5000000000000001e58 < re

    1. Initial program 9.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.6 \cdot 10^{+35}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq -1.52 \cdot 10^{-43}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq -1.45 \cdot 10^{-70}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 8 \cdot 10^{-86}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 3.6 \cdot 10^{+30}:\\ \;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 74.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sqrt{im \cdot 2}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{if}\;re \leq -3.6 \cdot 10^{+35}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{-89}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sqrt (* im 2.0))))
        (t_1 (* 0.5 (sqrt (* 2.0 (* re -2.0))))))
   (if (<= re -3.6e+35)
     t_1
     (if (<= re -3.8e-44)
       t_0
       (if (<= re -1.6e-89)
         t_1
         (if (<= re 1.5e+58) t_0 (/ (* im 0.5) (sqrt re))))))))
double code(double re, double im) {
	double t_0 = 0.5 * sqrt((im * 2.0));
	double t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -3.6e+35) {
		tmp = t_1;
	} else if (re <= -3.8e-44) {
		tmp = t_0;
	} else if (re <= -1.6e-89) {
		tmp = t_1;
	} else if (re <= 1.5e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / sqrt(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt((im * 2.0d0))
    t_1 = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
    if (re <= (-3.6d+35)) then
        tmp = t_1
    else if (re <= (-3.8d-44)) then
        tmp = t_0
    else if (re <= (-1.6d-89)) then
        tmp = t_1
    else if (re <= 1.5d+58) then
        tmp = t_0
    else
        tmp = (im * 0.5d0) / sqrt(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.sqrt((im * 2.0));
	double t_1 = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
	double tmp;
	if (re <= -3.6e+35) {
		tmp = t_1;
	} else if (re <= -3.8e-44) {
		tmp = t_0;
	} else if (re <= -1.6e-89) {
		tmp = t_1;
	} else if (re <= 1.5e+58) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / Math.sqrt(re);
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.sqrt((im * 2.0))
	t_1 = 0.5 * math.sqrt((2.0 * (re * -2.0)))
	tmp = 0
	if re <= -3.6e+35:
		tmp = t_1
	elif re <= -3.8e-44:
		tmp = t_0
	elif re <= -1.6e-89:
		tmp = t_1
	elif re <= 1.5e+58:
		tmp = t_0
	else:
		tmp = (im * 0.5) / math.sqrt(re)
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * sqrt(Float64(im * 2.0)))
	t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0))))
	tmp = 0.0
	if (re <= -3.6e+35)
		tmp = t_1;
	elseif (re <= -3.8e-44)
		tmp = t_0;
	elseif (re <= -1.6e-89)
		tmp = t_1;
	elseif (re <= 1.5e+58)
		tmp = t_0;
	else
		tmp = Float64(Float64(im * 0.5) / sqrt(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * sqrt((im * 2.0));
	t_1 = 0.5 * sqrt((2.0 * (re * -2.0)));
	tmp = 0.0;
	if (re <= -3.6e+35)
		tmp = t_1;
	elseif (re <= -3.8e-44)
		tmp = t_0;
	elseif (re <= -1.6e-89)
		tmp = t_1;
	elseif (re <= 1.5e+58)
		tmp = t_0;
	else
		tmp = (im * 0.5) / sqrt(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -3.6e+35], t$95$1, If[LessEqual[re, -3.8e-44], t$95$0, If[LessEqual[re, -1.6e-89], t$95$1, If[LessEqual[re, 1.5e+58], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot 2}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{if}\;re \leq -3.6 \cdot 10^{+35}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq -1.6 \cdot 10^{-89}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -3.6e35 or -3.8000000000000001e-44 < re < -1.59999999999999999e-89

    1. Initial program 50.8%

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

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

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

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

    if -3.6e35 < re < -3.8000000000000001e-44 or -1.59999999999999999e-89 < re < 1.5000000000000001e58

    1. Initial program 51.7%

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

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

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

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{im \cdot 2}\right)}}^{1} \]
    5. Applied egg-rr73.0%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt{im \cdot 2}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow173.0%

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

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

    if 1.5000000000000001e58 < re

    1. Initial program 9.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{im} \cdot 0.5}{\sqrt{re}} \]
    9. Applied egg-rr88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.6 \cdot 10^{+35}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{-89}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.5 \cdot 10^{+58}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 1.5000000000000001e58

    1. Initial program 51.4%

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

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

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

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{im \cdot 2}\right)}}^{1} \]
    5. Applied egg-rr54.0%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt{im \cdot 2}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow154.0%

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

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

    if 1.5000000000000001e58 < re

    1. Initial program 9.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right)}\right)}^{3} \]
      10. un-div-inv87.4%

        \[\leadsto {\left(\sqrt[3]{0.5 \cdot \color{blue}{\frac{im}{\sqrt{re}}}}\right)}^{3} \]
    9. Applied egg-rr87.4%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{0.5 \cdot \frac{im}{\sqrt{re}}}\right)}^{3}} \]
    10. Step-by-step derivation
      1. rem-cube-cbrt88.5%

        \[\leadsto \color{blue}{0.5 \cdot \frac{im}{\sqrt{re}}} \]
      2. clear-num86.9%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{1}{\frac{\sqrt{re}}{im}}} \]
      3. un-div-inv86.9%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{\sqrt{re}}{im}}} \]
    11. Applied egg-rr86.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 63.1% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.5 \cdot 10^{+58}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 1.5000000000000001e58

    1. Initial program 51.4%

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

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

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

        \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{im \cdot 2}\right)}}^{1} \]
    5. Applied egg-rr54.0%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt{im \cdot 2}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow154.0%

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

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

    if 1.5000000000000001e58 < re

    1. Initial program 9.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{im} \cdot 0.5}{\sqrt{re}} \]
    9. Applied egg-rr88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 51.6% accurate, 2.0× speedup?

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

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

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

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

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

      \[\leadsto 0.5 \cdot {\color{blue}{\left(\sqrt{im \cdot 2}\right)}}^{1} \]
  5. Applied egg-rr45.6%

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

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

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

    \[\leadsto 0.5 \cdot \sqrt{im \cdot 2} \]
  9. Add Preprocessing

Reproduce

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