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

Percentage Accurate: 40.7% → 88.3%
Time: 6.5s
Alternatives: 10
Speedup: 1.9×

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 10 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: 40.7% 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: 88.3% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\

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


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

    1. Initial program 56.6%

      \[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. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
      5. lower-hypot.f6494.1

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

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

    if 7.7999999999999999e46 < re

    1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 79.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -1.55 \cdot 10^{+127}:\\ \;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-157}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(im \cdot {re}^{-0.5}\right) \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -1.55e+127)
   (* 0.5 (sqrt (* -4.0 re)))
   (if (<= re -9e-157)
     (* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
     (if (<= re 7.8e+46)
       (* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
       (* (* im (pow re -0.5)) 0.5)))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.55e+127) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= -9e-157) {
		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
	} else if (re <= 7.8e+46) {
		tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
	} else {
		tmp = (im * pow(re, -0.5)) * 0.5;
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (re <= -1.55e+127)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= -9e-157)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re))));
	elseif (re <= 7.8e+46)
		tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im))));
	else
		tmp = Float64(Float64(im * (re ^ -0.5)) * 0.5);
	end
	return tmp
end
code[re_, im_] := If[LessEqual[re, -1.55e+127], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9e-157], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 4.2%

      \[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. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
      5. lower-hypot.f64100.0

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

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

      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    6. Step-by-step derivation
      1. lower-*.f6485.5

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

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

    if -1.5500000000000001e127 < re < -8.99999999999999997e-157

    1. Initial program 80.5%

      \[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. lift-+.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im} - re\right)} \]
      3. lower-fma.f6480.5

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

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

    if -8.99999999999999997e-157 < re < 7.7999999999999999e46

    1. Initial program 58.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. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
      5. lower-hypot.f6488.7

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \]
      6. lower-*.f6486.6

        \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \]
    7. Applied rewrites86.6%

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

    if 7.7999999999999999e46 < re

    1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -1.55 \cdot 10^{+127}:\\ \;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq -9 \cdot 10^{-157}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -1.55e+127)
   (* 0.5 (sqrt (* -4.0 re)))
   (if (<= re -9e-157)
     (* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
     (if (<= re 7.8e+46)
       (* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
       (* (/ im (sqrt re)) 0.5)))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.55e+127) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= -9e-157) {
		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
	} else if (re <= 7.8e+46) {
		tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
	} else {
		tmp = (im / sqrt(re)) * 0.5;
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (re <= -1.55e+127)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= -9e-157)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re))));
	elseif (re <= 7.8e+46)
		tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im))));
	else
		tmp = Float64(Float64(im / sqrt(re)) * 0.5);
	end
	return tmp
end
code[re_, im_] := If[LessEqual[re, -1.55e+127], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9e-157], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 4.2%

      \[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. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
      5. lower-hypot.f64100.0

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

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

      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    6. Step-by-step derivation
      1. lower-*.f6485.5

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

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

    if -1.5500000000000001e127 < re < -8.99999999999999997e-157

    1. Initial program 80.5%

      \[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. lift-+.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{\color{blue}{re \cdot re} + im \cdot im} - re\right)} \]
      3. lower-fma.f6480.5

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

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

    if -8.99999999999999997e-157 < re < 7.7999999999999999e46

    1. Initial program 58.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. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
      5. lower-hypot.f6488.7

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \]
      6. lower-*.f6486.6

        \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \]
    7. Applied rewrites86.6%

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

    if 7.7999999999999999e46 < re

    1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \frac{im \cdot 1}{\color{blue}{\sqrt{re}}} \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

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

          \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot \frac{1}{2}} \]
        3. lower-*.f6482.7

          \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot 0.5} \]
      3. Applied rewrites82.7%

        \[\leadsto \color{blue}{\frac{im}{\sqrt{re}} \cdot 0.5} \]
    7. Recombined 4 regimes into one program.
    8. Add Preprocessing

    Alternative 4: 76.9% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -3.8 \cdot 10^{+26}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \end{array} \]
    (FPCore (re im)
     :precision binary64
     (if (<= re -3.8e+26)
       (* 0.5 (sqrt (fma -4.0 re (* (/ (- im) re) im))))
       (if (<= re 7.8e+46)
         (* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
         (* (/ im (sqrt re)) 0.5))))
    double code(double re, double im) {
    	double tmp;
    	if (re <= -3.8e+26) {
    		tmp = 0.5 * sqrt(fma(-4.0, re, ((-im / re) * im)));
    	} else if (re <= 7.8e+46) {
    		tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
    	} else {
    		tmp = (im / sqrt(re)) * 0.5;
    	}
    	return tmp;
    }
    
    function code(re, im)
    	tmp = 0.0
    	if (re <= -3.8e+26)
    		tmp = Float64(0.5 * sqrt(fma(-4.0, re, Float64(Float64(Float64(-im) / re) * im))));
    	elseif (re <= 7.8e+46)
    		tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im))));
    	else
    		tmp = Float64(Float64(im / sqrt(re)) * 0.5);
    	end
    	return tmp
    end
    
    code[re_, im_] := If[LessEqual[re, -3.8e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re + N[(N[((-im) / re), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;re \leq -3.8 \cdot 10^{+26}:\\
    \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\
    
    \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
    \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if re < -3.8000000000000002e26

      1. Initial program 40.1%

        \[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. lift-sqrt.f64N/A

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

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

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
        5. lower-hypot.f64100.0

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{1}{2} \cdot \sqrt{\left(-re\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{im}{re}, \frac{im}{re}, 4\right)}} \]
        10. lower-/.f64N/A

          \[\leadsto \frac{1}{2} \cdot \sqrt{\left(-re\right) \cdot \mathsf{fma}\left(\color{blue}{\frac{im}{re}}, \frac{im}{re}, 4\right)} \]
        11. lower-/.f6482.9

          \[\leadsto 0.5 \cdot \sqrt{\left(-re\right) \cdot \mathsf{fma}\left(\frac{im}{re}, \color{blue}{\frac{im}{re}}, 4\right)} \]
      7. Applied rewrites82.9%

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

        \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot re + \color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
      9. Step-by-step derivation
        1. Applied rewrites76.0%

          \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(-4, \color{blue}{re}, \frac{\left(-im\right) \cdot im}{re}\right)} \]
        2. Step-by-step derivation
          1. Applied rewrites82.9%

            \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{im}{re} \cdot \left(-im\right)\right)} \]

          if -3.8000000000000002e26 < re < 7.7999999999999999e46

          1. Initial program 62.9%

            \[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. lift-sqrt.f64N/A

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

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

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
            5. lower-hypot.f6491.8

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

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

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

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

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

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

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\frac{re}{im}} - 2, re, 2 \cdot im\right)} \]
            6. lower-*.f6481.0

              \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, \color{blue}{2 \cdot im}\right)} \]
          7. Applied rewrites81.0%

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

          if 7.7999999999999999e46 < re

          1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto 0.5 \cdot \frac{im \cdot 1}{\color{blue}{\sqrt{re}}} \]
            2. Step-by-step derivation
              1. lift-*.f64N/A

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

                \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot \frac{1}{2}} \]
              3. lower-*.f6482.7

                \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot 0.5} \]
            3. Applied rewrites82.7%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.8 \cdot 10^{+26}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \]
          9. Add Preprocessing

          Alternative 5: 77.2% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -4.2 \cdot 10^{+26}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \end{array} \]
          (FPCore (re im)
           :precision binary64
           (if (<= re -4.2e+26)
             (* 0.5 (sqrt (fma -4.0 re (* (/ (- im) re) im))))
             (if (<= re 7.8e+46)
               (* 0.5 (sqrt (* 2.0 (- im re))))
               (* (/ im (sqrt re)) 0.5))))
          double code(double re, double im) {
          	double tmp;
          	if (re <= -4.2e+26) {
          		tmp = 0.5 * sqrt(fma(-4.0, re, ((-im / re) * im)));
          	} else if (re <= 7.8e+46) {
          		tmp = 0.5 * sqrt((2.0 * (im - re)));
          	} else {
          		tmp = (im / sqrt(re)) * 0.5;
          	}
          	return tmp;
          }
          
          function code(re, im)
          	tmp = 0.0
          	if (re <= -4.2e+26)
          		tmp = Float64(0.5 * sqrt(fma(-4.0, re, Float64(Float64(Float64(-im) / re) * im))));
          	elseif (re <= 7.8e+46)
          		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re))));
          	else
          		tmp = Float64(Float64(im / sqrt(re)) * 0.5);
          	end
          	return tmp
          end
          
          code[re_, im_] := If[LessEqual[re, -4.2e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re + N[(N[((-im) / re), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;re \leq -4.2 \cdot 10^{+26}:\\
          \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\
          
          \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
          \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if re < -4.2000000000000002e26

            1. Initial program 40.1%

              \[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. lift-sqrt.f64N/A

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

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

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

                \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
              5. lower-hypot.f64100.0

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \frac{1}{2} \cdot \sqrt{\left(-re\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{im}{re}, \frac{im}{re}, 4\right)}} \]
              10. lower-/.f64N/A

                \[\leadsto \frac{1}{2} \cdot \sqrt{\left(-re\right) \cdot \mathsf{fma}\left(\color{blue}{\frac{im}{re}}, \frac{im}{re}, 4\right)} \]
              11. lower-/.f6482.9

                \[\leadsto 0.5 \cdot \sqrt{\left(-re\right) \cdot \mathsf{fma}\left(\frac{im}{re}, \color{blue}{\frac{im}{re}}, 4\right)} \]
            7. Applied rewrites82.9%

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

              \[\leadsto \frac{1}{2} \cdot \sqrt{-4 \cdot re + \color{blue}{-1 \cdot \frac{{im}^{2}}{re}}} \]
            9. Step-by-step derivation
              1. Applied rewrites76.0%

                \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(-4, \color{blue}{re}, \frac{\left(-im\right) \cdot im}{re}\right)} \]
              2. Step-by-step derivation
                1. Applied rewrites82.9%

                  \[\leadsto 0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{im}{re} \cdot \left(-im\right)\right)} \]

                if -4.2000000000000002e26 < re < 7.7999999999999999e46

                1. Initial program 62.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}{\left(im + -1 \cdot re\right)}} \]
                4. Step-by-step derivation
                  1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

                if 7.7999999999999999e46 < re

                1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto 0.5 \cdot \frac{im \cdot 1}{\color{blue}{\sqrt{re}}} \]
                  2. Step-by-step derivation
                    1. lift-*.f64N/A

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

                      \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot \frac{1}{2}} \]
                    3. lower-*.f6482.7

                      \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot 0.5} \]
                  3. Applied rewrites82.7%

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.2 \cdot 10^{+26}:\\ \;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\ \mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \]
                9. Add Preprocessing

                Alternative 6: 77.3% accurate, 1.2× speedup?

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

                  1. Initial program 40.1%

                    \[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. lift-sqrt.f64N/A

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

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

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

                      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
                    5. lower-hypot.f64100.0

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

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

                    \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
                  6. Step-by-step derivation
                    1. lower-*.f6482.7

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

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

                  if -4.2000000000000002e26 < re < 7.7999999999999999e46

                  1. Initial program 62.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}{\left(im + -1 \cdot re\right)}} \]
                  4. Step-by-step derivation
                    1. fp-cancel-sign-sub-invN/A

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

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

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

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

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

                  if 7.7999999999999999e46 < re

                  1. Initial program 10.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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto 0.5 \cdot \frac{im \cdot 1}{\color{blue}{\sqrt{re}}} \]
                    2. Step-by-step derivation
                      1. lift-*.f64N/A

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

                        \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot \frac{1}{2}} \]
                      3. lower-*.f6482.7

                        \[\leadsto \color{blue}{\frac{im \cdot 1}{\sqrt{re}} \cdot 0.5} \]
                    3. Applied rewrites82.7%

                      \[\leadsto \color{blue}{\frac{im}{\sqrt{re}} \cdot 0.5} \]
                  7. Recombined 3 regimes into one program.
                  8. Add Preprocessing

                  Alternative 7: 65.1% accurate, 1.3× speedup?

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

                    1. Initial program 40.1%

                      \[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. lift-sqrt.f64N/A

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

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

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

                        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
                      5. lower-hypot.f64100.0

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

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

                      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
                    6. Step-by-step derivation
                      1. lower-*.f6482.7

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

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

                    if -4.2000000000000002e26 < re < 5.09999999999999994e113

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

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

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

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

                        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(im - \color{blue}{re}\right)} \]
                      4. lower--.f6476.8

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

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

                    if 5.09999999999999994e113 < re

                    1. Initial program 7.1%

                      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                    2. Add Preprocessing
                    3. Applied rewrites24.2%

                      \[\leadsto \color{blue}{0} \]
                  3. Recombined 3 regimes into one program.
                  4. Add Preprocessing

                  Alternative 8: 64.7% accurate, 1.5× speedup?

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

                    1. Initial program 40.1%

                      \[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. lift-sqrt.f64N/A

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

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

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

                        \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}} - re\right)} \]
                      5. lower-hypot.f64100.0

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

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

                      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
                    6. Step-by-step derivation
                      1. lower-*.f6482.7

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

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

                    if -3.8000000000000002e26 < re < 5.09999999999999994e113

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

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

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

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

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

                        \[\leadsto 0.5 \cdot \left(\sqrt{2} \cdot \color{blue}{\sqrt{im}}\right) \]
                    5. Applied rewrites75.4%

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

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

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

                        \[\leadsto \color{blue}{\left(\sqrt{2} \cdot \sqrt{im}\right) \cdot 0.5} \]
                    7. Applied rewrites76.0%

                      \[\leadsto \color{blue}{\sqrt{im \cdot 2} \cdot 0.5} \]
                    8. Step-by-step derivation
                      1. Applied rewrites76.0%

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

                      if 5.09999999999999994e113 < re

                      1. Initial program 7.1%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Applied rewrites24.2%

                        \[\leadsto \color{blue}{0} \]
                    9. Recombined 3 regimes into one program.
                    10. Add Preprocessing

                    Alternative 9: 53.5% accurate, 1.9× speedup?

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

                      1. Initial program 37.0%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Applied rewrites26.7%

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

                      if 7e-211 < im

                      1. Initial program 47.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 \color{blue}{\left(\sqrt{im} \cdot \sqrt{2}\right)} \]
                      4. Step-by-step derivation
                        1. *-commutativeN/A

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

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

                          \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\sqrt{2}} \cdot \sqrt{im}\right) \]
                        4. lower-sqrt.f6460.8

                          \[\leadsto 0.5 \cdot \left(\sqrt{2} \cdot \color{blue}{\sqrt{im}}\right) \]
                      5. Applied rewrites60.8%

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

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

                          \[\leadsto \color{blue}{\left(\sqrt{2} \cdot \sqrt{im}\right) \cdot \frac{1}{2}} \]
                        3. lower-*.f6460.8

                          \[\leadsto \color{blue}{\left(\sqrt{2} \cdot \sqrt{im}\right) \cdot 0.5} \]
                      7. Applied rewrites61.3%

                        \[\leadsto \color{blue}{\sqrt{im \cdot 2} \cdot 0.5} \]
                      8. Step-by-step derivation
                        1. Applied rewrites61.3%

                          \[\leadsto \sqrt{im + im} \cdot 0.5 \]
                      9. Recombined 2 regimes into one program.
                      10. Add Preprocessing

                      Alternative 10: 6.4% 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 46.6%

                        \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \]
                      2. Add Preprocessing
                      3. Applied rewrites6.3%

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

                      Reproduce

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