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

Percentage Accurate: 42.1% → 90.8%
Time: 13.0s
Alternatives: 6
Speedup: 2.1×

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 6 alternatives:

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

Initial Program: 42.1% accurate, 1.0× speedup?

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

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

Alternative 1: 90.8% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 10.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 47.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 76.8% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 31.4%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    4. Step-by-step derivation
      1. *-commutative78.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    5. Simplified78.9%

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

    if -3.10000000000000019e53 < re < 5.4999999999999996e-9

    1. Initial program 60.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(im - re\right)} \cdot 0.5} \]
    11. Simplified83.3%

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

    if 5.4999999999999996e-9 < re

    1. Initial program 15.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{im \cdot 0.5}{\sqrt{re}}} \]
    14. Step-by-step derivation
      1. associate-*r/76.8%

        \[\leadsto \color{blue}{im \cdot \frac{0.5}{\sqrt{re}}} \]
    15. Simplified76.8%

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

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

Alternative 3: 76.8% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 31.4%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    4. Step-by-step derivation
      1. *-commutative78.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    5. Simplified78.9%

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

    if -3.6e53 < re < 5.79999999999999982e-9

    1. Initial program 60.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(im - re\right)} \cdot 0.5} \]
    11. Simplified83.3%

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

    if 5.79999999999999982e-9 < re

    1. Initial program 15.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 64.4% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 31.4%

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

      \[\leadsto 0.5 \cdot \sqrt{\color{blue}{-4 \cdot re}} \]
    4. Step-by-step derivation
      1. *-commutative78.9%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    5. Simplified78.9%

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

    if -3.2e54 < re

    1. Initial program 47.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 55.9% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(im - re\right)} \cdot 0.5} \]
  11. Simplified58.7%

    \[\leadsto \sqrt{\color{blue}{\left(im - re\right)} \cdot 0.5} \]
  12. Final simplification58.7%

    \[\leadsto \sqrt{0.5 \cdot \left(im - re\right)} \]
  13. Add Preprocessing

Alternative 6: 53.6% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\color{blue}{im} \cdot 0.5} \]
  10. Final simplification56.5%

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

Reproduce

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