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

Percentage Accurate: 41.9% → 90.2%
Time: 30.5s
Alternatives: 7
Speedup: 1.7×

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.9% 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.2% accurate, 0.3× speedup?

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(im \cdot \sqrt{\frac{1}{2}}\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
      3. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
      5. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\left(im \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{re}}\right) \]
      7. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}}\right) \]
      9. /-lowering-/.f6493.1

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

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

        \[\leadsto \color{blue}{\left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \cdot \frac{1}{2}} \]
      2. associate-*l*N/A

        \[\leadsto \color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right)} \]
      3. *-commutativeN/A

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

        \[\leadsto \color{blue}{\left(\left(\sqrt{2} \cdot \sqrt{\frac{1}{2}}\right) \cdot im\right)} \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
      5. sqrt-unprodN/A

        \[\leadsto \left(\color{blue}{\sqrt{2 \cdot \frac{1}{2}}} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \left(\sqrt{\color{blue}{1}} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
      7. metadata-evalN/A

        \[\leadsto \left(\color{blue}{1} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
      8. *-lft-identityN/A

        \[\leadsto \color{blue}{im} \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
      9. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \cdot im} \]
      10. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \cdot im} \]
      11. sqrt-divN/A

        \[\leadsto \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \frac{1}{2}\right) \cdot im \]
      12. metadata-evalN/A

        \[\leadsto \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \frac{1}{2}\right) \cdot im \]
      13. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{1}{2}}{\sqrt{re}}} \cdot im \]
      14. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\sqrt{re}} \cdot im \]
      15. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\sqrt{re}}} \cdot im \]
      16. sqrt-lowering-sqrt.f6494.1

        \[\leadsto \frac{0.5}{\color{blue}{\sqrt{re}}} \cdot im \]
    7. Applied egg-rr94.1%

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

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

    1. Initial program 50.0%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. accelerator-lowering-hypot.f6489.2

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

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

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

Alternative 2: 78.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -2.8 \cdot 10^{+95}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -6.6 \cdot 10^{-116}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 6.8 \cdot 10^{+40}:\\ \;\;\;\;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 -2.8e+95)
   (* 0.5 (sqrt (* re -4.0)))
   (if (<= re -6.6e-116)
     (* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
     (if (<= re 6.8e+40) (* 0.5 (sqrt (* im 2.0))) (/ (* im 0.5) (sqrt re))))))
double code(double re, double im) {
	double tmp;
	if (re <= -2.8e+95) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if (re <= -6.6e-116) {
		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
	} else if (re <= 6.8e+40) {
		tmp = 0.5 * sqrt((im * 2.0));
	} else {
		tmp = (im * 0.5) / sqrt(re);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (re <= -2.8e+95)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif (re <= -6.6e-116)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re))));
	elseif (re <= 6.8e+40)
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	else
		tmp = Float64(Float64(im * 0.5) / sqrt(re));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[re, -2.8e+95], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -6.6e-116], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.8e+40], 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 -2.8 \cdot 10^{+95}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq -6.6 \cdot 10^{-116}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\

\mathbf{elif}\;re \leq 6.8 \cdot 10^{+40}:\\
\;\;\;\;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 4 regimes
  2. if re < -2.7999999999999998e95

    1. Initial program 23.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

      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(re \cdot -2\right)}} \]
      2. *-lowering-*.f6490.7

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

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

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
      3. sqrt-lowering-sqrt.f64N/A

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

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot re\right) \cdot -2}} \cdot \frac{1}{2} \]
      5. *-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(re \cdot 2\right)} \cdot -2} \cdot \frac{1}{2} \]
      6. associate-*l*N/A

        \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
      7. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
      8. metadata-eval90.7

        \[\leadsto \sqrt{re \cdot \color{blue}{-4}} \cdot 0.5 \]
    7. Applied egg-rr90.7%

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

    if -2.7999999999999998e95 < re < -6.60000000000000002e-116

    1. Initial program 80.8%

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \cdot \frac{1}{2}} \]
      3. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \color{blue}{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
      5. --lowering--.f64N/A

        \[\leadsto \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} - re\right)}} \cdot \frac{1}{2} \]
      6. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \sqrt{2 \cdot \left(\color{blue}{\sqrt{re \cdot re + im \cdot im}} - re\right)} \cdot \frac{1}{2} \]
      7. +-commutativeN/A

        \[\leadsto \sqrt{2 \cdot \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}} - re\right)} \cdot \frac{1}{2} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto \sqrt{2 \cdot \left(\sqrt{\color{blue}{\mathsf{fma}\left(im, im, re \cdot re\right)}} - re\right)} \cdot \frac{1}{2} \]
      9. *-lowering-*.f6480.8

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

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

    if -6.60000000000000002e-116 < re < 6.79999999999999977e40

    1. Initial program 57.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

      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
    4. Step-by-step derivation
      1. Simplified80.2%

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

      if 6.79999999999999977e40 < re

      1. Initial program 4.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 inf

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
      4. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(im \cdot \sqrt{\frac{1}{2}}\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        3. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        5. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        6. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\left(im \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        7. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        8. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}}\right) \]
        9. /-lowering-/.f6480.9

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

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

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

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(\sqrt{2} \cdot \sqrt{\frac{1}{2}}\right) \cdot im\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        3. sqrt-unprodN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2 \cdot \frac{1}{2}}} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        4. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{\color{blue}{1}} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        5. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{1} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        6. *-lft-identityN/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{im} \cdot \sqrt{\frac{1}{re}}\right) \]
        7. sqrt-divN/A

          \[\leadsto \frac{1}{2} \cdot \left(im \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{re}}}\right) \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right) \]
        9. un-div-invN/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{im}{\sqrt{re}}} \]
        10. associate-*r/N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot im}{\sqrt{re}}} \]
        11. /-lowering-/.f64N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot im}{\sqrt{re}}} \]
        12. *-commutativeN/A

          \[\leadsto \frac{\color{blue}{im \cdot \frac{1}{2}}}{\sqrt{re}} \]
        13. *-lowering-*.f64N/A

          \[\leadsto \frac{\color{blue}{im \cdot \frac{1}{2}}}{\sqrt{re}} \]
        14. sqrt-lowering-sqrt.f6481.7

          \[\leadsto \frac{im \cdot 0.5}{\color{blue}{\sqrt{re}}} \]
      7. Applied egg-rr81.7%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.8 \cdot 10^{+95}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq -6.6 \cdot 10^{-116}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\ \mathbf{elif}\;re \leq 6.8 \cdot 10^{+40}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 3: 76.0% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -2.7 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 2.9 \cdot 10^{+49}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
    (FPCore (re im)
     :precision binary64
     (if (<= re -2.7e+70)
       (* 0.5 (sqrt (* re -4.0)))
       (if (<= re 2.9e+49)
         (* 0.5 (sqrt (* 2.0 (- im re))))
         (/ (* im 0.5) (sqrt re)))))
    double code(double re, double im) {
    	double tmp;
    	if (re <= -2.7e+70) {
    		tmp = 0.5 * sqrt((re * -4.0));
    	} else if (re <= 2.9e+49) {
    		tmp = 0.5 * sqrt((2.0 * (im - re)));
    	} 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 <= (-2.7d+70)) then
            tmp = 0.5d0 * sqrt((re * (-4.0d0)))
        else if (re <= 2.9d+49) then
            tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
        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 <= -2.7e+70) {
    		tmp = 0.5 * Math.sqrt((re * -4.0));
    	} else if (re <= 2.9e+49) {
    		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
    	} else {
    		tmp = (im * 0.5) / Math.sqrt(re);
    	}
    	return tmp;
    }
    
    def code(re, im):
    	tmp = 0
    	if re <= -2.7e+70:
    		tmp = 0.5 * math.sqrt((re * -4.0))
    	elif re <= 2.9e+49:
    		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
    	else:
    		tmp = (im * 0.5) / math.sqrt(re)
    	return tmp
    
    function code(re, im)
    	tmp = 0.0
    	if (re <= -2.7e+70)
    		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
    	elseif (re <= 2.9e+49)
    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
    	else
    		tmp = Float64(Float64(im * 0.5) / sqrt(re));
    	end
    	return tmp
    end
    
    function tmp_2 = code(re, im)
    	tmp = 0.0;
    	if (re <= -2.7e+70)
    		tmp = 0.5 * sqrt((re * -4.0));
    	elseif (re <= 2.9e+49)
    		tmp = 0.5 * sqrt((2.0 * (im - re)));
    	else
    		tmp = (im * 0.5) / sqrt(re);
    	end
    	tmp_2 = tmp;
    end
    
    code[re_, im_] := If[LessEqual[re, -2.7e+70], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.9e+49], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;re \leq -2.7 \cdot 10^{+70}:\\
    \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
    
    \mathbf{elif}\;re \leq 2.9 \cdot 10^{+49}:\\
    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if re < -2.7e70

      1. Initial program 27.0%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(re \cdot -2\right)}} \]
        2. *-lowering-*.f6491.2

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

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

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        3. sqrt-lowering-sqrt.f64N/A

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

          \[\leadsto \sqrt{\color{blue}{\left(2 \cdot re\right) \cdot -2}} \cdot \frac{1}{2} \]
        5. *-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{\left(re \cdot 2\right)} \cdot -2} \cdot \frac{1}{2} \]
        6. associate-*l*N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        7. *-lowering-*.f64N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        8. metadata-eval91.2

          \[\leadsto \sqrt{re \cdot \color{blue}{-4}} \cdot 0.5 \]
      7. Applied egg-rr91.2%

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

      if -2.7e70 < re < 2.9e49

      1. Initial program 63.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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im + \color{blue}{\left(\mathsf{neg}\left(re\right)\right)}\right)} \]
        2. unsub-negN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im - re\right)}} \]
        3. --lowering--.f6475.2

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

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

      if 2.9e49 < re

      1. Initial program 4.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 inf

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
      4. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(im \cdot \sqrt{\frac{1}{2}}\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        3. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        5. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        6. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\left(im \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        7. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        8. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}}\right) \]
        9. /-lowering-/.f6480.9

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

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

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

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(\sqrt{2} \cdot \sqrt{\frac{1}{2}}\right) \cdot im\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        3. sqrt-unprodN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2 \cdot \frac{1}{2}}} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        4. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{\color{blue}{1}} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        5. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{1} \cdot im\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        6. *-lft-identityN/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{im} \cdot \sqrt{\frac{1}{re}}\right) \]
        7. sqrt-divN/A

          \[\leadsto \frac{1}{2} \cdot \left(im \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{re}}}\right) \]
        8. metadata-evalN/A

          \[\leadsto \frac{1}{2} \cdot \left(im \cdot \frac{\color{blue}{1}}{\sqrt{re}}\right) \]
        9. un-div-invN/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{im}{\sqrt{re}}} \]
        10. associate-*r/N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot im}{\sqrt{re}}} \]
        11. /-lowering-/.f64N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot im}{\sqrt{re}}} \]
        12. *-commutativeN/A

          \[\leadsto \frac{\color{blue}{im \cdot \frac{1}{2}}}{\sqrt{re}} \]
        13. *-lowering-*.f64N/A

          \[\leadsto \frac{\color{blue}{im \cdot \frac{1}{2}}}{\sqrt{re}} \]
        14. sqrt-lowering-sqrt.f6481.7

          \[\leadsto \frac{im \cdot 0.5}{\color{blue}{\sqrt{re}}} \]
      7. Applied egg-rr81.7%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.7 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 2.9 \cdot 10^{+49}:\\ \;\;\;\;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 4: 75.8% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -3.2 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 6 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
    (FPCore (re im)
     :precision binary64
     (if (<= re -3.2e+70)
       (* 0.5 (sqrt (* re -4.0)))
       (if (<= re 6e+58)
         (* 0.5 (sqrt (* 2.0 (- im re))))
         (* im (/ 0.5 (sqrt re))))))
    double code(double re, double im) {
    	double tmp;
    	if (re <= -3.2e+70) {
    		tmp = 0.5 * sqrt((re * -4.0));
    	} else if (re <= 6e+58) {
    		tmp = 0.5 * sqrt((2.0 * (im - re)));
    	} 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 <= (-3.2d+70)) then
            tmp = 0.5d0 * sqrt((re * (-4.0d0)))
        else if (re <= 6d+58) then
            tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
        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 <= -3.2e+70) {
    		tmp = 0.5 * Math.sqrt((re * -4.0));
    	} else if (re <= 6e+58) {
    		tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
    	} else {
    		tmp = im * (0.5 / Math.sqrt(re));
    	}
    	return tmp;
    }
    
    def code(re, im):
    	tmp = 0
    	if re <= -3.2e+70:
    		tmp = 0.5 * math.sqrt((re * -4.0))
    	elif re <= 6e+58:
    		tmp = 0.5 * math.sqrt((2.0 * (im - re)))
    	else:
    		tmp = im * (0.5 / math.sqrt(re))
    	return tmp
    
    function code(re, im)
    	tmp = 0.0
    	if (re <= -3.2e+70)
    		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
    	elseif (re <= 6e+58)
    		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
    	else
    		tmp = Float64(im * Float64(0.5 / sqrt(re)));
    	end
    	return tmp
    end
    
    function tmp_2 = code(re, im)
    	tmp = 0.0;
    	if (re <= -3.2e+70)
    		tmp = 0.5 * sqrt((re * -4.0));
    	elseif (re <= 6e+58)
    		tmp = 0.5 * sqrt((2.0 * (im - re)));
    	else
    		tmp = im * (0.5 / sqrt(re));
    	end
    	tmp_2 = tmp;
    end
    
    code[re_, im_] := If[LessEqual[re, -3.2e+70], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6e+58], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;re \leq -3.2 \cdot 10^{+70}:\\
    \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
    
    \mathbf{elif}\;re \leq 6 \cdot 10^{+58}:\\
    \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if re < -3.2000000000000002e70

      1. Initial program 27.0%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(re \cdot -2\right)}} \]
        2. *-lowering-*.f6491.2

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

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

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        3. sqrt-lowering-sqrt.f64N/A

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

          \[\leadsto \sqrt{\color{blue}{\left(2 \cdot re\right) \cdot -2}} \cdot \frac{1}{2} \]
        5. *-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{\left(re \cdot 2\right)} \cdot -2} \cdot \frac{1}{2} \]
        6. associate-*l*N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        7. *-lowering-*.f64N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        8. metadata-eval91.2

          \[\leadsto \sqrt{re \cdot \color{blue}{-4}} \cdot 0.5 \]
      7. Applied egg-rr91.2%

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

      if -3.2000000000000002e70 < re < 6.0000000000000005e58

      1. Initial program 63.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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im + -1 \cdot re\right)}} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im + \color{blue}{\left(\mathsf{neg}\left(re\right)\right)}\right)} \]
        2. unsub-negN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(im - re\right)}} \]
        3. --lowering--.f6475.2

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

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

      if 6.0000000000000005e58 < re

      1. Initial program 4.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 inf

        \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right)} \]
      4. Step-by-step derivation
        1. *-lowering-*.f64N/A

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

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\left(im \cdot \sqrt{\frac{1}{2}}\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        3. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right)} \cdot \sqrt{\frac{1}{re}}\right) \]
        5. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        6. *-lowering-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\left(im \cdot \sqrt{\frac{1}{2}}\right)}\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        7. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \]
        8. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \frac{1}{2} \cdot \left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \color{blue}{\sqrt{\frac{1}{re}}}\right) \]
        9. /-lowering-/.f6480.9

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

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

          \[\leadsto \color{blue}{\left(\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \cdot \frac{1}{2}} \]
        2. associate-*l*N/A

          \[\leadsto \color{blue}{\left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{1}{2}}\right)\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right)} \]
        3. *-commutativeN/A

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

          \[\leadsto \color{blue}{\left(\left(\sqrt{2} \cdot \sqrt{\frac{1}{2}}\right) \cdot im\right)} \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
        5. sqrt-unprodN/A

          \[\leadsto \left(\color{blue}{\sqrt{2 \cdot \frac{1}{2}}} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
        6. metadata-evalN/A

          \[\leadsto \left(\sqrt{\color{blue}{1}} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
        7. metadata-evalN/A

          \[\leadsto \left(\color{blue}{1} \cdot im\right) \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
        8. *-lft-identityN/A

          \[\leadsto \color{blue}{im} \cdot \left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \]
        9. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \cdot im} \]
        10. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \frac{1}{2}\right) \cdot im} \]
        11. sqrt-divN/A

          \[\leadsto \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \frac{1}{2}\right) \cdot im \]
        12. metadata-evalN/A

          \[\leadsto \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \frac{1}{2}\right) \cdot im \]
        13. associate-*l/N/A

          \[\leadsto \color{blue}{\frac{1 \cdot \frac{1}{2}}{\sqrt{re}}} \cdot im \]
        14. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{\sqrt{re}} \cdot im \]
        15. /-lowering-/.f64N/A

          \[\leadsto \color{blue}{\frac{\frac{1}{2}}{\sqrt{re}}} \cdot im \]
        16. sqrt-lowering-sqrt.f6481.6

          \[\leadsto \frac{0.5}{\color{blue}{\sqrt{re}}} \cdot im \]
      7. Applied egg-rr81.6%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.2 \cdot 10^{+70}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 6 \cdot 10^{+58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 5: 63.9% accurate, 1.7× speedup?

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

      1. Initial program 30.3%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(-2 \cdot re\right)}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\left(re \cdot -2\right)}} \]
        2. *-lowering-*.f6489.6

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

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

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        2. *-lowering-*.f64N/A

          \[\leadsto \color{blue}{\sqrt{2 \cdot \left(re \cdot -2\right)} \cdot \frac{1}{2}} \]
        3. sqrt-lowering-sqrt.f64N/A

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

          \[\leadsto \sqrt{\color{blue}{\left(2 \cdot re\right) \cdot -2}} \cdot \frac{1}{2} \]
        5. *-commutativeN/A

          \[\leadsto \sqrt{\color{blue}{\left(re \cdot 2\right)} \cdot -2} \cdot \frac{1}{2} \]
        6. associate-*l*N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        7. *-lowering-*.f64N/A

          \[\leadsto \sqrt{\color{blue}{re \cdot \left(2 \cdot -2\right)}} \cdot \frac{1}{2} \]
        8. metadata-eval89.6

          \[\leadsto \sqrt{re \cdot \color{blue}{-4}} \cdot 0.5 \]
      7. Applied egg-rr89.6%

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

      if -2.80000000000000014e62 < re

      1. Initial program 47.6%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
      4. Step-by-step derivation
        1. Simplified61.0%

          \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{im}} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification66.0%

        \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -2.8 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]
      7. Add Preprocessing

      Alternative 6: 53.0% accurate, 1.7× speedup?

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

        1. Initial program 33.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

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

            \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{re} - re\right)} \]
          2. Step-by-step derivation
            1. pow1/2N/A

              \[\leadsto \frac{1}{2} \cdot \color{blue}{{\left(2 \cdot \left(re - re\right)\right)}^{\frac{1}{2}}} \]
            2. *-commutativeN/A

              \[\leadsto \frac{1}{2} \cdot {\color{blue}{\left(\left(re - re\right) \cdot 2\right)}}^{\frac{1}{2}} \]
            3. +-inversesN/A

              \[\leadsto \frac{1}{2} \cdot {\left(\color{blue}{0} \cdot 2\right)}^{\frac{1}{2}} \]
            4. metadata-evalN/A

              \[\leadsto \frac{1}{2} \cdot {\color{blue}{0}}^{\frac{1}{2}} \]
            5. metadata-evalN/A

              \[\leadsto \frac{1}{2} \cdot \color{blue}{0} \]
            6. metadata-eval38.3

              \[\leadsto \color{blue}{0} \]
          3. Applied egg-rr38.3%

            \[\leadsto \color{blue}{0} \]

          if 6.5999999999999999e-269 < im

          1. Initial program 45.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

            \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{im}} \]
          4. Step-by-step derivation
            1. Simplified56.8%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 6.6 \cdot 10^{-269}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]
          7. Add Preprocessing

          Alternative 7: 6.0% accurate, 47.0× speedup?

          \[\begin{array}{l} \\ 0 \end{array} \]
          (FPCore (re im) :precision binary64 0.0)
          double code(double re, double im) {
          	return 0.0;
          }
          
          real(8) function code(re, im)
              real(8), intent (in) :: re
              real(8), intent (in) :: im
              code = 0.0d0
          end function
          
          public static double code(double re, double im) {
          	return 0.0;
          }
          
          def code(re, im):
          	return 0.0
          
          function code(re, im)
          	return 0.0
          end
          
          function tmp = code(re, im)
          	tmp = 0.0;
          end
          
          code[re_, im_] := 0.0
          
          \begin{array}{l}
          
          \\
          0
          \end{array}
          
          Derivation
          1. Initial program 44.6%

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

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

              \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{re} - re\right)} \]
            2. Step-by-step derivation
              1. pow1/2N/A

                \[\leadsto \frac{1}{2} \cdot \color{blue}{{\left(2 \cdot \left(re - re\right)\right)}^{\frac{1}{2}}} \]
              2. *-commutativeN/A

                \[\leadsto \frac{1}{2} \cdot {\color{blue}{\left(\left(re - re\right) \cdot 2\right)}}^{\frac{1}{2}} \]
              3. +-inversesN/A

                \[\leadsto \frac{1}{2} \cdot {\left(\color{blue}{0} \cdot 2\right)}^{\frac{1}{2}} \]
              4. metadata-evalN/A

                \[\leadsto \frac{1}{2} \cdot {\color{blue}{0}}^{\frac{1}{2}} \]
              5. metadata-evalN/A

                \[\leadsto \frac{1}{2} \cdot \color{blue}{0} \]
              6. metadata-eval6.5

                \[\leadsto \color{blue}{0} \]
            3. Applied egg-rr6.5%

              \[\leadsto \color{blue}{0} \]
            4. Add Preprocessing

            Reproduce

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