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

Percentage Accurate: 41.7% → 87.8%
Time: 7.2s
Alternatives: 7
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 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.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: 87.8% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 48.4%

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

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

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

    if 1.12000000000000003e35 < re

    1. Initial program 9.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.f6432.8

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
    4. Applied rewrites32.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 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)} \]
    6. 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. lower-*.f64N/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)} \]
      3. lower-sqrt.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \]
      5. 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) \]
      6. lower-*.f64N/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) \]
      7. lower-*.f64N/A

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

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

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

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

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

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

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

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

Alternative 2: 77.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -6.8 \cdot 10^{+89}:\\ \;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\ \mathbf{elif}\;re \leq -3.2 \cdot 10^{-58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\ \mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\ \;\;\;\;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 -6.8e+89)
   (* (* 0.5 (sqrt 2.0)) (sqrt (* -2.0 re)))
   (if (<= re -3.2e-58)
     (* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
     (if (<= re 8.9e+33)
       (* 0.5 (sqrt (* 2.0 (- im re))))
       (* (/ im (sqrt re)) 0.5)))))
double code(double re, double im) {
	double tmp;
	if (re <= -6.8e+89) {
		tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re));
	} else if (re <= -3.2e-58) {
		tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
	} else if (re <= 8.9e+33) {
		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 <= -6.8e+89)
		tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(-2.0 * re)));
	elseif (re <= -3.2e-58)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re))));
	elseif (re <= 8.9e+33)
		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, -6.8e+89], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-2.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -3.2e-58], 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, 8.9e+33], 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 -6.8 \cdot 10^{+89}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\

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

\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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 4 regimes
  2. if re < -6.8000000000000004e89

    1. Initial program 24.4%

      \[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.f6498.3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sqrt{2}\right)} \cdot {\left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}^{\frac{1}{2}} \]
      14. pow1/2N/A

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

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

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

      \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{-2 \cdot re}} \]
    8. Step-by-step derivation
      1. lower-*.f6480.5

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

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

    if -6.8000000000000004e89 < re < -3.2000000000000001e-58

    1. Initial program 86.3%

      \[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.f6486.3

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

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

    if -3.2000000000000001e-58 < re < 8.9000000000000005e33

    1. Initial program 51.2%

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

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

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

    if 8.9000000000000005e33 < re

    1. Initial program 9.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.f6432.8

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
    4. Applied rewrites32.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 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)} \]
    6. 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. lower-*.f64N/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)} \]
      3. lower-sqrt.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \]
      5. 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) \]
      6. lower-*.f64N/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) \]
      7. lower-*.f64N/A

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6.8 \cdot 10^{+89}:\\ \;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\ \mathbf{elif}\;re \leq -3.2 \cdot 10^{-58}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\ \mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -1.5 \cdot 10^{+32}:\\ \;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\ \mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\ \;\;\;\;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 -1.5e+32)
   (* (* 0.5 (sqrt 2.0)) (sqrt (* -2.0 re)))
   (if (<= re 8.9e+33)
     (* 0.5 (sqrt (* 2.0 (- im re))))
     (* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.5e+32) {
		tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re));
	} else if (re <= 8.9e+33) {
		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 <= (-1.5d+32)) then
        tmp = (0.5d0 * sqrt(2.0d0)) * sqrt(((-2.0d0) * re))
    else if (re <= 8.9d+33) 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 <= -1.5e+32) {
		tmp = (0.5 * Math.sqrt(2.0)) * Math.sqrt((-2.0 * re));
	} else if (re <= 8.9e+33) {
		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 <= -1.5e+32:
		tmp = (0.5 * math.sqrt(2.0)) * math.sqrt((-2.0 * re))
	elif re <= 8.9e+33:
		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 <= -1.5e+32)
		tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(-2.0 * re)));
	elseif (re <= 8.9e+33)
		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 <= -1.5e+32)
		tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re));
	elseif (re <= 8.9e+33)
		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, -1.5e+32], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-2.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.9e+33], 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 -1.5 \cdot 10^{+32}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\

\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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 < -1.5e32

    1. Initial program 35.7%

      \[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.f6498.6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sqrt{2}\right)} \cdot {\left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}^{\frac{1}{2}} \]
      14. pow1/2N/A

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

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

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

      \[\leadsto \left(\frac{1}{2} \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{-2 \cdot re}} \]
    8. Step-by-step derivation
      1. lower-*.f6477.1

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

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

    if -1.5e32 < re < 8.9000000000000005e33

    1. Initial program 55.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}{\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. lower--.f6476.6

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

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

    if 8.9000000000000005e33 < re

    1. Initial program 9.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.f6432.8

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
    4. Applied rewrites32.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 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)} \]
    6. 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. lower-*.f64N/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)} \]
      3. lower-sqrt.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \]
      5. 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) \]
      6. lower-*.f64N/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) \]
      7. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

Alternative 4: 75.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -1.5 \cdot 10^{+32}:\\ \;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\ \mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\ \;\;\;\;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 -1.5e+32)
   (* 0.5 (sqrt (* -4.0 re)))
   (if (<= re 8.9e+33)
     (* 0.5 (sqrt (* 2.0 (- im re))))
     (* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.5e+32) {
		tmp = 0.5 * sqrt((-4.0 * re));
	} else if (re <= 8.9e+33) {
		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 <= (-1.5d+32)) then
        tmp = 0.5d0 * sqrt(((-4.0d0) * re))
    else if (re <= 8.9d+33) 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 <= -1.5e+32) {
		tmp = 0.5 * Math.sqrt((-4.0 * re));
	} else if (re <= 8.9e+33) {
		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 <= -1.5e+32:
		tmp = 0.5 * math.sqrt((-4.0 * re))
	elif re <= 8.9e+33:
		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 <= -1.5e+32)
		tmp = Float64(0.5 * sqrt(Float64(-4.0 * re)));
	elseif (re <= 8.9e+33)
		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 <= -1.5e+32)
		tmp = 0.5 * sqrt((-4.0 * re));
	elseif (re <= 8.9e+33)
		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, -1.5e+32], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.9e+33], 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 -1.5 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\

\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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 < -1.5e32

    1. Initial program 35.7%

      \[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.f6498.6

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

      \[\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-*.f6476.4

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

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

    if -1.5e32 < re < 8.9000000000000005e33

    1. Initial program 55.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}{\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. lower--.f6476.6

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

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

    if 8.9000000000000005e33 < re

    1. Initial program 9.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.f6432.8

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
    4. Applied rewrites32.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 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)} \]
    6. 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. lower-*.f64N/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)} \]
      3. lower-sqrt.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{\color{blue}{\frac{1}{re}}} \cdot \left(im \cdot \left(\sqrt{\frac{1}{2}} \cdot \sqrt{2}\right)\right)\right) \]
      5. 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) \]
      6. lower-*.f64N/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) \]
      7. lower-*.f64N/A

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

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

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

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

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

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

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

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

Alternative 5: 64.2% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -2.4e14

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\mathsf{hypot}\left(re, im\right)} - re\right)} \]
    4. Applied rewrites98.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 -inf

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

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

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

    if -2.4e14 < re

    1. Initial program 39.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 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.f6457.3

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

      \[\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-*.f6457.3

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

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

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

    Alternative 6: 54.0% accurate, 1.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.8 \cdot 10^{-223}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im + im} \cdot 0.5\\ \end{array} \end{array} \]
    (FPCore (re im)
     :precision binary64
     (if (<= im 1.8e-223) 0.0 (* (sqrt (+ im im)) 0.5)))
    double code(double re, double im) {
    	double tmp;
    	if (im <= 1.8e-223) {
    		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 <= 1.8d-223) 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 <= 1.8e-223) {
    		tmp = 0.0;
    	} else {
    		tmp = Math.sqrt((im + im)) * 0.5;
    	}
    	return tmp;
    }
    
    def code(re, im):
    	tmp = 0
    	if im <= 1.8e-223:
    		tmp = 0.0
    	else:
    		tmp = math.sqrt((im + im)) * 0.5
    	return tmp
    
    function code(re, im)
    	tmp = 0.0
    	if (im <= 1.8e-223)
    		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 <= 1.8e-223)
    		tmp = 0.0;
    	else
    		tmp = sqrt((im + im)) * 0.5;
    	end
    	tmp_2 = tmp;
    end
    
    code[re_, im_] := If[LessEqual[im, 1.8e-223], 0.0, N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;im \leq 1.8 \cdot 10^{-223}:\\
    \;\;\;\;0\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{im + im} \cdot 0.5\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if im < 1.8000000000000002e-223

      1. Initial program 33.6%

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

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

      if 1.8000000000000002e-223 < im

      1. Initial program 39.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.f6455.8

          \[\leadsto 0.5 \cdot \left(\sqrt{2} \cdot \color{blue}{\sqrt{im}}\right) \]
      5. Applied rewrites55.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-*.f6455.8

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

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

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

      Alternative 7: 5.9% 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 38.8%

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

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

      Reproduce

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