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

Percentage Accurate: 41.5% → 88.2%
Time: 9.1s
Alternatives: 4
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 4 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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 88.2% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 9.50000000000000044e-43

    1. Initial program 53.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. add-sqr-sqrt53.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(\sqrt{im \cdot im + \color{blue}{re \cdot re}} - re\right)} \]
      10. hypot-undefine94.8%

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

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

    if 9.50000000000000044e-43 < re

    1. Initial program 12.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{0.5 \cdot im}{\sqrt{re}}} \]
    8. Step-by-step derivation
      1. *-lft-identity86.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{re}}} \]
      2. *-commutative86.0%

        \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
    9. Simplified86.0%

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

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

Alternative 2: 77.0% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.45 \cdot 10^{+54}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\

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

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


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

    1. Initial program 36.1%

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

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

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

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

    if -1.4499999999999999e54 < re < 3.30000000000000006e-44

    1. Initial program 59.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 81.7%

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

    if 3.30000000000000006e-44 < re

    1. Initial program 12.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{0.5 \cdot im}{\sqrt{re}}} \]
    8. Step-by-step derivation
      1. *-lft-identity86.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{re}}} \]
      2. *-commutative86.0%

        \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
    9. Simplified86.0%

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

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

Alternative 3: 52.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{-311}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -3.99999999999979e-311

    1. Initial program 54.6%

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

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

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

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

    if -3.99999999999979e-311 < re

    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 54.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{0.5 \cdot im}{\sqrt{re}}} \]
    8. Step-by-step derivation
      1. *-lft-identity55.5%

        \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{re}}} \]
      2. *-commutative55.5%

        \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
    9. Simplified55.5%

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

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

Alternative 4: 26.3% accurate, 2.0× speedup?

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

\\
\frac{0.5 \cdot im}{\sqrt{re}}
\end{array}
Derivation
  1. Initial program 42.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1 \cdot \frac{0.5 \cdot im}{\sqrt{re}}} \]
  8. Step-by-step derivation
    1. *-lft-identity28.0%

      \[\leadsto \color{blue}{\frac{0.5 \cdot im}{\sqrt{re}}} \]
    2. *-commutative28.0%

      \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
  9. Simplified28.0%

    \[\leadsto \color{blue}{\frac{im \cdot 0.5}{\sqrt{re}}} \]
  10. Final simplification28.0%

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

Reproduce

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