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

Percentage Accurate: 40.7% → 89.5%
Time: 11.9s
Alternatives: 8
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 8 alternatives:

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

Initial Program: 40.7% accurate, 1.0× speedup?

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

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

Alternative 1: 89.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\ \;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\ \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)
   (* (pow re -0.5) (* im 0.5))
   (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 = pow(re, -0.5) * (im * 0.5);
	} 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 = Math.pow(re, -0.5) * (im * 0.5);
	} 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 = math.pow(re, -0.5) * (im * 0.5)
	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((re ^ -0.5) * Float64(im * 0.5));
	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 = (re ^ -0.5) * (im * 0.5);
	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[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $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:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\

\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 8.3%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg8.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-neg8.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-neg8.3%

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

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

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

      \[\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)} \]
    5. Step-by-step derivation
      1. associate-*r*93.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{re}} \cdot \left(\left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{2}\right)\right)\right)} \]
      2. expm1-udef10.9%

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*10.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr10.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def94.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p94.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(im \cdot \sqrt{0.5}\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}{\sqrt{re}}} \]
    11. Step-by-step derivation
      1. clear-num93.5%

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

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

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

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

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

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

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

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

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \left(0.5 \cdot 0.5\right)}}\right)\right) \]
      10. rem-square-sqrt93.9%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{2} \cdot \left(0.5 \cdot 0.5\right)}\right)\right) \]
      11. metadata-eval93.9%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{2 \cdot \color{blue}{0.25}}\right)\right) \]
      12. metadata-eval93.9%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{0.5}}\right)\right) \]
      13. rem-square-sqrt95.4%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \color{blue}{0.5}\right) \]
    12. Applied egg-rr95.4%

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

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

    1. Initial program 47.5%

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

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

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

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

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

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

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

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

        \[\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. *-commutative90.6%

        \[\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. *-commutative90.6%

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

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

        \[\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. metadata-eval90.6%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*90.6%

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

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

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

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

Alternative 2: 75.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -9.5 \cdot 10^{-10}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.55 \cdot 10^{-74} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\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 -9.5e-10)
   (* 0.5 (sqrt (* re -4.0)))
   (if (or (<= re 1.55e-74) (and (not (<= re 8.5e+142)) (<= re 6.5e+172)))
     (sqrt (* 0.5 (- im re)))
     (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
	double tmp;
	if (re <= -9.5e-10) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
		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 <= (-9.5d-10)) then
        tmp = 0.5d0 * sqrt((re * (-4.0d0)))
    else if ((re <= 1.55d-74) .or. (.not. (re <= 8.5d+142)) .and. (re <= 6.5d+172)) 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 <= -9.5e-10) {
		tmp = 0.5 * Math.sqrt((re * -4.0));
	} else if ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
		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 <= -9.5e-10:
		tmp = 0.5 * math.sqrt((re * -4.0))
	elif (re <= 1.55e-74) or (not (re <= 8.5e+142) and (re <= 6.5e+172)):
		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 <= -9.5e-10)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172)))
		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 <= -9.5e-10)
		tmp = 0.5 * sqrt((re * -4.0));
	elseif ((re <= 1.55e-74) || (~((re <= 8.5e+142)) && (re <= 6.5e+172)))
		tmp = sqrt((0.5 * (im - re)));
	else
		tmp = im * (0.5 / sqrt(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -9.5e-10], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.55e-74], And[N[Not[LessEqual[re, 8.5e+142]], $MachinePrecision], LessEqual[re, 6.5e+172]]], 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 -9.5 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq 1.55 \cdot 10^{-74} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;\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 < -9.50000000000000028e-10

    1. Initial program 37.1%

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.6%

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

    if -9.50000000000000028e-10 < re < 1.5500000000000001e-74 or 8.49999999999999955e142 < re < 6.4999999999999997e172

    1. Initial program 55.5%

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

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

        \[\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-neg55.5%

        \[\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-neg55.5%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt91.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-unprod92.2%

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

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

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

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

        \[\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. metadata-eval92.2%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*92.2%

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

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

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

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

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

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

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

    if 1.5500000000000001e-74 < re < 8.49999999999999955e142 or 6.4999999999999997e172 < re

    1. Initial program 20.4%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg20.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-neg20.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-neg20.4%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Taylor expanded in im around 0 77.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)} \]
    5. Step-by-step derivation
      1. associate-*r*77.8%

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr26.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def77.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p78.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\left(im \cdot \sqrt{0.5}\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-udef26.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\left(im \cdot \sqrt{0.5}\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    12. Applied egg-rr26.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{im}{\frac{\sqrt{re}}{0.5}}\right)} - 1} \]
    13. Step-by-step derivation
      1. expm1-def78.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{im}{\frac{\sqrt{re}}{0.5}}\right)\right)} \]
      2. expm1-log1p78.9%

        \[\leadsto \color{blue}{\frac{im}{\frac{\sqrt{re}}{0.5}}} \]
      3. associate-/l*78.9%

        \[\leadsto \color{blue}{\frac{im \cdot 0.5}{\sqrt{re}}} \]
      4. associate-*r/78.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -9.5 \cdot 10^{-10}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.55 \cdot 10^{-74} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\ \end{array} \]

Alternative 3: 75.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.3 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\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 -4.5e-9)
   (* 0.5 (sqrt (* re -4.0)))
   (if (or (<= re 1.3e-76) (and (not (<= re 8.5e+142)) (<= re 6.5e+172)))
     (sqrt (* 0.5 (- im re)))
     (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
	double tmp;
	if (re <= -4.5e-9) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
		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 <= (-4.5d-9)) then
        tmp = 0.5d0 * sqrt((re * (-4.0d0)))
    else if ((re <= 1.3d-76) .or. (.not. (re <= 8.5d+142)) .and. (re <= 6.5d+172)) 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 <= -4.5e-9) {
		tmp = 0.5 * Math.sqrt((re * -4.0));
	} else if ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
		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 <= -4.5e-9:
		tmp = 0.5 * math.sqrt((re * -4.0))
	elif (re <= 1.3e-76) or (not (re <= 8.5e+142) and (re <= 6.5e+172)):
		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 <= -4.5e-9)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172)))
		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 <= -4.5e-9)
		tmp = 0.5 * sqrt((re * -4.0));
	elseif ((re <= 1.3e-76) || (~((re <= 8.5e+142)) && (re <= 6.5e+172)))
		tmp = sqrt((0.5 * (im - re)));
	else
		tmp = (im * 0.5) / sqrt(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -4.5e-9], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.3e-76], And[N[Not[LessEqual[re, 8.5e+142]], $MachinePrecision], LessEqual[re, 6.5e+172]]], 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 -4.5 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq 1.3 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;\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 < -4.49999999999999976e-9

    1. Initial program 37.1%

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.6%

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

    if -4.49999999999999976e-9 < re < 1.3e-76 or 8.49999999999999955e142 < re < 6.4999999999999997e172

    1. Initial program 55.5%

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

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

        \[\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-neg55.5%

        \[\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-neg55.5%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt91.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-unprod92.2%

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

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

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

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

        \[\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. metadata-eval92.2%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*92.2%

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

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

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

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

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

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

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

    if 1.3e-76 < re < 8.49999999999999955e142 or 6.4999999999999997e172 < re

    1. Initial program 20.4%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg20.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-neg20.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-neg20.4%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Taylor expanded in im around 0 77.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)} \]
    5. Step-by-step derivation
      1. associate-*r*77.8%

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*26.0%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr26.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def77.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p78.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \left(0.5 \cdot 0.5\right)}}\right)}{\sqrt{re}} \]
      5. rem-square-sqrt77.9%

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

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

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

        \[\leadsto \frac{im \cdot \color{blue}{0.5}}{\sqrt{re}} \]
      9. expm1-log1p-u77.2%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      10. expm1-udef35.7%

        \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    12. Applied egg-rr35.7%

      \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    13. Step-by-step derivation
      1. expm1-def77.2%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      2. expm1-log1p78.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.3 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]

Alternative 4: 75.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{if}\;re \leq -8.5 \cdot 10^{-9}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.45 \cdot 10^{-74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (sqrt (* 0.5 (- im re)))))
   (if (<= re -8.5e-9)
     (* 0.5 (sqrt (* re -4.0)))
     (if (<= re 1.45e-74)
       t_0
       (if (<= re 8.5e+142)
         (* 0.5 (* im (pow re -0.5)))
         (if (<= re 6.5e+172) t_0 (/ (* im 0.5) (sqrt re))))))))
double code(double re, double im) {
	double t_0 = sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -8.5e-9) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if (re <= 1.45e-74) {
		tmp = t_0;
	} else if (re <= 8.5e+142) {
		tmp = 0.5 * (im * pow(re, -0.5));
	} else if (re <= 6.5e+172) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((0.5d0 * (im - re)))
    if (re <= (-8.5d-9)) then
        tmp = 0.5d0 * sqrt((re * (-4.0d0)))
    else if (re <= 1.45d-74) then
        tmp = t_0
    else if (re <= 8.5d+142) then
        tmp = 0.5d0 * (im * (re ** (-0.5d0)))
    else if (re <= 6.5d+172) then
        tmp = t_0
    else
        tmp = (im * 0.5d0) / sqrt(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -8.5e-9) {
		tmp = 0.5 * Math.sqrt((re * -4.0));
	} else if (re <= 1.45e-74) {
		tmp = t_0;
	} else if (re <= 8.5e+142) {
		tmp = 0.5 * (im * Math.pow(re, -0.5));
	} else if (re <= 6.5e+172) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / Math.sqrt(re);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sqrt((0.5 * (im - re)))
	tmp = 0
	if re <= -8.5e-9:
		tmp = 0.5 * math.sqrt((re * -4.0))
	elif re <= 1.45e-74:
		tmp = t_0
	elif re <= 8.5e+142:
		tmp = 0.5 * (im * math.pow(re, -0.5))
	elif re <= 6.5e+172:
		tmp = t_0
	else:
		tmp = (im * 0.5) / math.sqrt(re)
	return tmp
function code(re, im)
	t_0 = sqrt(Float64(0.5 * Float64(im - re)))
	tmp = 0.0
	if (re <= -8.5e-9)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif (re <= 1.45e-74)
		tmp = t_0;
	elseif (re <= 8.5e+142)
		tmp = Float64(0.5 * Float64(im * (re ^ -0.5)));
	elseif (re <= 6.5e+172)
		tmp = t_0;
	else
		tmp = Float64(Float64(im * 0.5) / sqrt(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sqrt((0.5 * (im - re)));
	tmp = 0.0;
	if (re <= -8.5e-9)
		tmp = 0.5 * sqrt((re * -4.0));
	elseif (re <= 1.45e-74)
		tmp = t_0;
	elseif (re <= 8.5e+142)
		tmp = 0.5 * (im * (re ^ -0.5));
	elseif (re <= 6.5e+172)
		tmp = t_0;
	else
		tmp = (im * 0.5) / sqrt(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -8.5e-9], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.45e-74], t$95$0, If[LessEqual[re, 8.5e+142], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e+172], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -8.5 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq 1.45 \cdot 10^{-74}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\

\mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -8.5e-9

    1. Initial program 37.1%

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.6%

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

    if -8.5e-9 < re < 1.45e-74 or 8.49999999999999955e142 < re < 6.4999999999999997e172

    1. Initial program 55.5%

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

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

        \[\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-neg55.5%

        \[\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-neg55.5%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt91.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-unprod92.2%

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

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

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

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

        \[\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. metadata-eval92.2%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*92.2%

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

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

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

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

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

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

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

    if 1.45e-74 < re < 8.49999999999999955e142

    1. Initial program 32.9%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg32.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-neg32.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-neg32.9%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt35.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-unprod35.5%

        \[\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. *-commutative35.5%

        \[\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. *-commutative35.5%

        \[\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-sqr35.5%

        \[\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-sqrt35.5%

        \[\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. metadata-eval35.5%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*35.5%

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{\left(\frac{1}{re}\right)}^{0.5}}\right) \]
      6. exp-to-pow70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{e^{\log \left(\frac{1}{re}\right) \cdot 0.5}}\right) \]
      7. *-commutative70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{0.5 \cdot \log \left(\frac{1}{re}\right)}}\right) \]
      8. log-rec70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-\log re\right)}}\right) \]
      9. neg-mul-170.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{0.5 \cdot \color{blue}{\left(-1 \cdot \log re\right)}}\right) \]
      10. associate-*r*70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\left(0.5 \cdot -1\right) \cdot \log re}}\right) \]
      11. metadata-eval70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{-0.5} \cdot \log re}\right) \]
      12. log-pow70.8%

        \[\leadsto 0.5 \cdot \left(im \cdot e^{\color{blue}{\log \left({re}^{-0.5}\right)}}\right) \]
      13. rem-exp-log74.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{{re}^{-0.5}}\right) \]
    10. Simplified74.9%

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

    if 6.4999999999999997e172 < re

    1. Initial program 3.0%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg3.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-neg3.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-neg3.0%

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

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

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

      \[\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)} \]
    5. Step-by-step derivation
      1. associate-*r*83.5%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{re}} \cdot \left(\left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{2}\right)\right)\right)} \]
      2. expm1-udef44.2%

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr44.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def82.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p84.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{im \cdot \left(\sqrt{0.5} \cdot \color{blue}{\sqrt{\left(\sqrt{2} \cdot 0.5\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}}\right)}{\sqrt{re}} \]
      4. swap-sqr83.6%

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

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

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

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

        \[\leadsto \frac{im \cdot \color{blue}{0.5}}{\sqrt{re}} \]
      9. expm1-log1p-u80.9%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      10. expm1-udef57.6%

        \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    12. Applied egg-rr57.6%

      \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    13. Step-by-step derivation
      1. expm1-def80.9%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      2. expm1-log1p84.7%

        \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
    14. Simplified84.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -8.5 \cdot 10^{-9}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 1.45 \cdot 10^{-74}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]

Alternative 5: 75.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{if}\;re \leq -4.4 \cdot 10^{-11}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 8.4 \cdot 10^{-75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\ \;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (sqrt (* 0.5 (- im re)))))
   (if (<= re -4.4e-11)
     (* 0.5 (sqrt (* re -4.0)))
     (if (<= re 8.4e-75)
       t_0
       (if (<= re 8.5e+142)
         (* (pow re -0.5) (* im 0.5))
         (if (<= re 6.5e+172) t_0 (/ (* im 0.5) (sqrt re))))))))
double code(double re, double im) {
	double t_0 = sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -4.4e-11) {
		tmp = 0.5 * sqrt((re * -4.0));
	} else if (re <= 8.4e-75) {
		tmp = t_0;
	} else if (re <= 8.5e+142) {
		tmp = pow(re, -0.5) * (im * 0.5);
	} else if (re <= 6.5e+172) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((0.5d0 * (im - re)))
    if (re <= (-4.4d-11)) then
        tmp = 0.5d0 * sqrt((re * (-4.0d0)))
    else if (re <= 8.4d-75) then
        tmp = t_0
    else if (re <= 8.5d+142) then
        tmp = (re ** (-0.5d0)) * (im * 0.5d0)
    else if (re <= 6.5d+172) then
        tmp = t_0
    else
        tmp = (im * 0.5d0) / sqrt(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sqrt((0.5 * (im - re)));
	double tmp;
	if (re <= -4.4e-11) {
		tmp = 0.5 * Math.sqrt((re * -4.0));
	} else if (re <= 8.4e-75) {
		tmp = t_0;
	} else if (re <= 8.5e+142) {
		tmp = Math.pow(re, -0.5) * (im * 0.5);
	} else if (re <= 6.5e+172) {
		tmp = t_0;
	} else {
		tmp = (im * 0.5) / Math.sqrt(re);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sqrt((0.5 * (im - re)))
	tmp = 0
	if re <= -4.4e-11:
		tmp = 0.5 * math.sqrt((re * -4.0))
	elif re <= 8.4e-75:
		tmp = t_0
	elif re <= 8.5e+142:
		tmp = math.pow(re, -0.5) * (im * 0.5)
	elif re <= 6.5e+172:
		tmp = t_0
	else:
		tmp = (im * 0.5) / math.sqrt(re)
	return tmp
function code(re, im)
	t_0 = sqrt(Float64(0.5 * Float64(im - re)))
	tmp = 0.0
	if (re <= -4.4e-11)
		tmp = Float64(0.5 * sqrt(Float64(re * -4.0)));
	elseif (re <= 8.4e-75)
		tmp = t_0;
	elseif (re <= 8.5e+142)
		tmp = Float64((re ^ -0.5) * Float64(im * 0.5));
	elseif (re <= 6.5e+172)
		tmp = t_0;
	else
		tmp = Float64(Float64(im * 0.5) / sqrt(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sqrt((0.5 * (im - re)));
	tmp = 0.0;
	if (re <= -4.4e-11)
		tmp = 0.5 * sqrt((re * -4.0));
	elseif (re <= 8.4e-75)
		tmp = t_0;
	elseif (re <= 8.5e+142)
		tmp = (re ^ -0.5) * (im * 0.5);
	elseif (re <= 6.5e+172)
		tmp = t_0;
	else
		tmp = (im * 0.5) / sqrt(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -4.4e-11], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.4e-75], t$95$0, If[LessEqual[re, 8.5e+142], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e+172], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -4.4 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\

\mathbf{elif}\;re \leq 8.4 \cdot 10^{-75}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\

\mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if re < -4.4000000000000003e-11

    1. Initial program 37.1%

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.6%

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

    if -4.4000000000000003e-11 < re < 8.4000000000000004e-75 or 8.49999999999999955e142 < re < 6.4999999999999997e172

    1. Initial program 55.5%

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

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

        \[\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-neg55.5%

        \[\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-neg55.5%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt91.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-unprod92.2%

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

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

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

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

        \[\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. metadata-eval92.2%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*92.2%

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

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

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

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

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

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

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

    if 8.4000000000000004e-75 < re < 8.49999999999999955e142

    1. Initial program 32.9%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg32.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-neg32.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-neg32.9%

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

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

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
    4. Taylor expanded in im around 0 73.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)} \]
    5. Step-by-step derivation
      1. associate-*r*73.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{re}} \cdot \left(\left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{2}\right)\right)\right)} \]
      2. expm1-udef12.9%

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*12.9%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr12.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def74.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p74.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(im \cdot \sqrt{0.5}\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}{\sqrt{re}}} \]
    11. Step-by-step derivation
      1. clear-num73.2%

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

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

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

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

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

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

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

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \color{blue}{\sqrt{\left(\sqrt{2} \cdot 0.5\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}}\right)\right) \]
      9. swap-sqr73.8%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \left(0.5 \cdot 0.5\right)}}\right)\right) \]
      10. rem-square-sqrt73.8%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{2} \cdot \left(0.5 \cdot 0.5\right)}\right)\right) \]
      11. metadata-eval73.8%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{2 \cdot \color{blue}{0.25}}\right)\right) \]
      12. metadata-eval73.8%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{\color{blue}{0.5}}\right)\right) \]
      13. rem-square-sqrt74.9%

        \[\leadsto {re}^{-0.5} \cdot \left(im \cdot \color{blue}{0.5}\right) \]
    12. Applied egg-rr74.9%

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

    if 6.4999999999999997e172 < re

    1. Initial program 3.0%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg3.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-neg3.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-neg3.0%

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

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

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

      \[\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)} \]
    5. Step-by-step derivation
      1. associate-*r*83.5%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{re}} \cdot \left(\left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right) \cdot \sqrt{2}\right)\right)\right)} \]
      2. expm1-udef44.2%

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right) \cdot \sqrt{2}}\right)} - 1 \]
      4. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2} \cdot \left(\sqrt{\frac{1}{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)}\right)} - 1 \]
      5. sqrt-div44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{re}}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      6. metadata-eval44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \left(\frac{\color{blue}{1}}{\sqrt{re}} \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)\right)\right)} - 1 \]
      7. associate-*l/44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \color{blue}{\frac{1 \cdot \left(0.5 \cdot \left(im \cdot \sqrt{0.5}\right)\right)}{\sqrt{re}}}\right)} - 1 \]
      8. *-un-lft-identity44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{0.5 \cdot \left(im \cdot \sqrt{0.5}\right)}}{\sqrt{re}}\right)} - 1 \]
      9. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(im \cdot \sqrt{0.5}\right) \cdot 0.5}}{\sqrt{re}}\right)} - 1 \]
      10. *-commutative44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\left(\sqrt{0.5} \cdot im\right)} \cdot 0.5}{\sqrt{re}}\right)} - 1 \]
      11. associate-*l*44.2%

        \[\leadsto e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\color{blue}{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}}{\sqrt{re}}\right)} - 1 \]
    8. Applied egg-rr44.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def82.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot \left(im \cdot 0.5\right)}{\sqrt{re}}\right)\right)} \]
      2. expm1-log1p84.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{im \cdot \left(\sqrt{0.5} \cdot \color{blue}{\sqrt{\left(\sqrt{2} \cdot 0.5\right) \cdot \left(\sqrt{2} \cdot 0.5\right)}}\right)}{\sqrt{re}} \]
      4. swap-sqr83.6%

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

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

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

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

        \[\leadsto \frac{im \cdot \color{blue}{0.5}}{\sqrt{re}} \]
      9. expm1-log1p-u80.9%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      10. expm1-udef57.6%

        \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    12. Applied egg-rr57.6%

      \[\leadsto \frac{\color{blue}{e^{\mathsf{log1p}\left(im \cdot 0.5\right)} - 1}}{\sqrt{re}} \]
    13. Step-by-step derivation
      1. expm1-def80.9%

        \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(im \cdot 0.5\right)\right)}}{\sqrt{re}} \]
      2. expm1-log1p84.7%

        \[\leadsto \frac{\color{blue}{im \cdot 0.5}}{\sqrt{re}} \]
    14. Simplified84.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.4 \cdot 10^{-11}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{elif}\;re \leq 8.4 \cdot 10^{-75}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\ \;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\ \mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\ \end{array} \]

Alternative 6: 64.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -3.95 \cdot 10^{-13}:\\ \;\;\;\;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.95e-13) (* 0.5 (sqrt (* re -4.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
	double tmp;
	if (re <= -3.95e-13) {
		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.95d-13)) 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.95e-13) {
		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.95e-13:
		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.95e-13)
		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.95e-13)
		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.95e-13], 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.95 \cdot 10^{-13}:\\
\;\;\;\;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.94999999999999983e-13

    1. Initial program 37.1%

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

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

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{re \cdot -4}} \]
    4. Simplified76.6%

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

    if -3.94999999999999983e-13 < re

    1. Initial program 43.0%

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

        \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\sqrt{re \cdot re + im \cdot im} + \left(-re\right)\right)}} \]
      2. sqr-neg43.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-neg43.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-neg43.0%

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

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

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

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

        \[\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. *-commutative71.6%

        \[\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. *-commutative71.6%

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

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

        \[\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. metadata-eval71.6%

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

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

        \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
      2. associate-*r*71.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -3.95 \cdot 10^{-13}:\\ \;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{im \cdot 0.5}\\ \end{array} \]

Alternative 7: 53.8% 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 41.5%

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

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

      \[\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-neg41.5%

      \[\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-neg41.5%

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

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

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt78.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-unprod79.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. *-commutative79.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. *-commutative79.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-sqr79.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-sqrt79.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. metadata-eval79.1%

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

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

      \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    2. associate-*r*79.1%

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

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

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

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

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

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(im - re\right)}} \]
  10. Simplified53.6%

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

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

Alternative 8: 51.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 41.5%

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

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

      \[\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-neg41.5%

      \[\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-neg41.5%

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

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

    \[\leadsto \color{blue}{0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt78.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-unprod79.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. *-commutative79.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. *-commutative79.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-sqr79.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-sqrt79.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. metadata-eval79.1%

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

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

      \[\leadsto \sqrt{\color{blue}{0.25 \cdot \left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}} \]
    2. associate-*r*79.1%

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

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

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

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{im}} \]
  9. Final simplification50.9%

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

Reproduce

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