?

Average Error: 39.2 → 24.6
Time: 12.2s
Precision: binary64
Cost: 14424

?

\[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
\[\begin{array}{l} t_0 := 0.5 \cdot \left(-im \cdot \sqrt{-\frac{1}{re}}\right)\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{if}\;im \leq -3 \cdot 10^{-29}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{elif}\;im \leq -5.8 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -2.5 \cdot 10^{-272}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 6.9 \cdot 10^{-130}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]
(FPCore (re im)
 :precision binary64
 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (- (* im (sqrt (- (/ 1.0 re)))))))
        (t_1 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re))))))
   (if (<= im -3e-29)
     (* 0.5 (sqrt (* 2.0 (+ (- im) re))))
     (if (<= im -5.8e-118)
       t_0
       (if (<= im -4.9e-157)
         t_1
         (if (<= im -2.5e-272)
           t_0
           (if (<= im 6.9e-130)
             (* 0.5 (* 2.0 (sqrt re)))
             (if (<= im 9e+96) t_1 (* 0.5 (sqrt (* im 2.0)))))))))))
double code(double re, double im) {
	return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
double code(double re, double im) {
	double t_0 = 0.5 * -(im * sqrt(-(1.0 / re)));
	double t_1 = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
	double tmp;
	if (im <= -3e-29) {
		tmp = 0.5 * sqrt((2.0 * (-im + re)));
	} else if (im <= -5.8e-118) {
		tmp = t_0;
	} else if (im <= -4.9e-157) {
		tmp = t_1;
	} else if (im <= -2.5e-272) {
		tmp = t_0;
	} else if (im <= 6.9e-130) {
		tmp = 0.5 * (2.0 * sqrt(re));
	} else if (im <= 9e+96) {
		tmp = t_1;
	} else {
		tmp = 0.5 * sqrt((im * 2.0));
	}
	return tmp;
}
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
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * -(im * sqrt(-(1.0d0 / re)))
    t_1 = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
    if (im <= (-3d-29)) then
        tmp = 0.5d0 * sqrt((2.0d0 * (-im + re)))
    else if (im <= (-5.8d-118)) then
        tmp = t_0
    else if (im <= (-4.9d-157)) then
        tmp = t_1
    else if (im <= (-2.5d-272)) then
        tmp = t_0
    else if (im <= 6.9d-130) then
        tmp = 0.5d0 * (2.0d0 * sqrt(re))
    else if (im <= 9d+96) then
        tmp = t_1
    else
        tmp = 0.5d0 * sqrt((im * 2.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
public static double code(double re, double im) {
	double t_0 = 0.5 * -(im * Math.sqrt(-(1.0 / re)));
	double t_1 = 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
	double tmp;
	if (im <= -3e-29) {
		tmp = 0.5 * Math.sqrt((2.0 * (-im + re)));
	} else if (im <= -5.8e-118) {
		tmp = t_0;
	} else if (im <= -4.9e-157) {
		tmp = t_1;
	} else if (im <= -2.5e-272) {
		tmp = t_0;
	} else if (im <= 6.9e-130) {
		tmp = 0.5 * (2.0 * Math.sqrt(re));
	} else if (im <= 9e+96) {
		tmp = t_1;
	} else {
		tmp = 0.5 * Math.sqrt((im * 2.0));
	}
	return tmp;
}
def code(re, im):
	return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
def code(re, im):
	t_0 = 0.5 * -(im * math.sqrt(-(1.0 / re)))
	t_1 = 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
	tmp = 0
	if im <= -3e-29:
		tmp = 0.5 * math.sqrt((2.0 * (-im + re)))
	elif im <= -5.8e-118:
		tmp = t_0
	elif im <= -4.9e-157:
		tmp = t_1
	elif im <= -2.5e-272:
		tmp = t_0
	elif im <= 6.9e-130:
		tmp = 0.5 * (2.0 * math.sqrt(re))
	elif im <= 9e+96:
		tmp = t_1
	else:
		tmp = 0.5 * math.sqrt((im * 2.0))
	return tmp
function code(re, im)
	return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re))))
end
function code(re, im)
	t_0 = Float64(0.5 * Float64(-Float64(im * sqrt(Float64(-Float64(1.0 / re))))))
	t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re))))
	tmp = 0.0
	if (im <= -3e-29)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(-im) + re))));
	elseif (im <= -5.8e-118)
		tmp = t_0;
	elseif (im <= -4.9e-157)
		tmp = t_1;
	elseif (im <= -2.5e-272)
		tmp = t_0;
	elseif (im <= 6.9e-130)
		tmp = Float64(0.5 * Float64(2.0 * sqrt(re)));
	elseif (im <= 9e+96)
		tmp = t_1;
	else
		tmp = Float64(0.5 * sqrt(Float64(im * 2.0)));
	end
	return tmp
end
function tmp = code(re, im)
	tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * -(im * sqrt(-(1.0 / re)));
	t_1 = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
	tmp = 0.0;
	if (im <= -3e-29)
		tmp = 0.5 * sqrt((2.0 * (-im + re)));
	elseif (im <= -5.8e-118)
		tmp = t_0;
	elseif (im <= -4.9e-157)
		tmp = t_1;
	elseif (im <= -2.5e-272)
		tmp = t_0;
	elseif (im <= 6.9e-130)
		tmp = 0.5 * (2.0 * sqrt(re));
	elseif (im <= 9e+96)
		tmp = t_1;
	else
		tmp = 0.5 * sqrt((im * 2.0));
	end
	tmp_2 = tmp;
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]
code[re_, im_] := Block[{t$95$0 = N[(0.5 * (-N[(im * N[Sqrt[(-N[(1.0 / re), $MachinePrecision])], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]}, Block[{t$95$1 = 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]}, If[LessEqual[im, -3e-29], N[(0.5 * N[Sqrt[N[(2.0 * N[((-im) + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -5.8e-118], t$95$0, If[LessEqual[im, -4.9e-157], t$95$1, If[LessEqual[im, -2.5e-272], t$95$0, If[LessEqual[im, 6.9e-130], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 9e+96], t$95$1, N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
t_0 := 0.5 \cdot \left(-im \cdot \sqrt{-\frac{1}{re}}\right)\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\
\mathbf{if}\;im \leq -3 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\

\mathbf{elif}\;im \leq -5.8 \cdot 10^{-118}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -4.9 \cdot 10^{-157}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -2.5 \cdot 10^{-272}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 9 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.2
Target34.0
Herbie24.6
\[\begin{array}{l} \mathbf{if}\;re < 0:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{\sqrt{re \cdot re + im \cdot im} - re}}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \end{array} \]

Derivation?

  1. Split input into 5 regimes
  2. if im < -3.0000000000000003e-29

    1. Initial program 41.5

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{-1 \cdot im} + re\right)} \]
    3. Simplified16.6

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

      [Start]16.6

      \[ 0.5 \cdot \sqrt{2 \cdot \left(-1 \cdot im + re\right)} \]

      rational_best-simplify-2 [=>]16.6

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

      rational_best-simplify-12 [=>]16.6

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

    if -3.0000000000000003e-29 < im < -5.79999999999999961e-118 or -4.8999999999999998e-157 < im < -2.49999999999999991e-272

    1. Initial program 37.4

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

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

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

      [Start]53.1

      \[ 0.5 \cdot \sqrt{2 \cdot \left(-0.5 \cdot \frac{{im}^{2}}{re}\right)} \]

      rational_best-simplify-2 [=>]53.1

      \[ 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(\frac{{im}^{2}}{re} \cdot -0.5\right)}} \]
    4. Taylor expanded in im around -inf 64.0

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

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

      [Start]64.0

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

      rational_best-simplify-2 [=>]64.0

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

      rational_best-simplify-12 [=>]64.0

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

      rational_best-simplify-2 [=>]64.0

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

      rational_best-simplify-2 [=>]64.0

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

      rational_best-simplify-44 [=>]64.0

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

      exponential-simplify-19 [=>]39.0

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

      rational_best-simplify-2 [=>]39.0

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

      rational_best-simplify-12 [=>]39.0

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

    if -5.79999999999999961e-118 < im < -4.8999999999999998e-157 or 6.90000000000000035e-130 < im < 8.99999999999999914e96

    1. Initial program 24.7

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]

    if -2.49999999999999991e-272 < im < 6.90000000000000035e-130

    1. Initial program 42.2

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Taylor expanded in im around 0 36.4

      \[\leadsto 0.5 \cdot \color{blue}{\left({\left(\sqrt{2}\right)}^{2} \cdot \sqrt{re}\right)} \]
    3. Simplified35.9

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

      [Start]36.4

      \[ 0.5 \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot \sqrt{re}\right) \]

      exponential-simplify-24 [=>]35.9

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

      metadata-eval [=>]35.9

      \[ 0.5 \cdot \left(\sqrt{\color{blue}{4}} \cdot \sqrt{re}\right) \]

      metadata-eval [=>]35.9

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

    if 8.99999999999999914e96 < im

    1. Initial program 52.7

      \[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
    2. Taylor expanded in re around 0 11.1

      \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{im}\right)} \]
    3. Simplified10.8

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt{im \cdot 2}} \]
      Proof

      [Start]11.1

      \[ 0.5 \cdot \left(\sqrt{2} \cdot \sqrt{im}\right) \]

      exponential-simplify-19 [=>]10.8

      \[ 0.5 \cdot \color{blue}{\sqrt{im \cdot 2}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification24.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3 \cdot 10^{-29}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{elif}\;im \leq -5.8 \cdot 10^{-118}:\\ \;\;\;\;0.5 \cdot \left(-im \cdot \sqrt{-\frac{1}{re}}\right)\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{-157}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{elif}\;im \leq -2.5 \cdot 10^{-272}:\\ \;\;\;\;0.5 \cdot \left(-im \cdot \sqrt{-\frac{1}{re}}\right)\\ \mathbf{elif}\;im \leq 6.9 \cdot 10^{-130}:\\ \;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+96}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]

Alternatives

Alternative 1
Error31.6
Cost13704
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ t_1 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;re \leq -7.8 \cdot 10^{+146}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{-\frac{1}{re}}\right)\\ \mathbf{elif}\;re \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5\right)}\\ \mathbf{elif}\;re \leq 5.5 \cdot 10^{-299}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\ \mathbf{elif}\;re \leq 1.52 \cdot 10^{-172}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 1.7 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq 5.6 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error31.7
Cost13512
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ t_1 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;re \leq -3.75 \cdot 10^{+146}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{-\frac{1}{re}}\right)\\ \mathbf{elif}\;re \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;0.5 \cdot \sqrt{-\frac{{im}^{2}}{re}}\\ \mathbf{elif}\;re \leq 3.4 \cdot 10^{-308}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\ \mathbf{elif}\;re \leq 2.9 \cdot 10^{-173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 1.15 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq 5.6 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error32.3
Cost8036
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ t_1 := 0.5 \cdot \sqrt{im \cdot -2}\\ t_2 := im \cdot \sqrt{-\frac{1}{re}}\\ t_3 := 0.5 \cdot \left(-t_2\right)\\ t_4 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;re \leq -2.4 \cdot 10^{+119}:\\ \;\;\;\;0.5 \cdot t_2\\ \mathbf{elif}\;re \leq -8.6 \cdot 10^{+24}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;re \leq -2.5 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -5 \cdot 10^{-110}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;re \leq -6.1 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 1.4 \cdot 10^{-296}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq 1.8 \cdot 10^{-172}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 4.3 \cdot 10^{-55}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;re \leq 5.8 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 4
Error28.2
Cost7640
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{im \cdot -2}\\ t_1 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;im \leq -1.6 \cdot 10^{-38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.7 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -2.8 \cdot 10^{-267}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{-118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 3.6 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;im \leq 7500:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]
Alternative 5
Error28.4
Cost7512
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{im \cdot -2}\\ t_1 := 0.5 \cdot \sqrt{im \cdot 2}\\ t_2 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;im \leq -2.15 \cdot 10^{-38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -3.9 \cdot 10^{-106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq -2.8 \cdot 10^{-267}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 8.5 \cdot 10^{-115}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 2.8 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 3.4:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error31.6
Cost7508
\[\begin{array}{l} t_0 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{if}\;re \leq -45:\\ \;\;\;\;0.5 \cdot \left(im \cdot \sqrt{-\frac{1}{re}}\right)\\ \mathbf{elif}\;re \leq 2 \cdot 10^{-300}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\ \mathbf{elif}\;re \leq 1.8 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq 1.42 \cdot 10^{-55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq 7.2 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error27.0
Cost7376
\[\begin{array}{l} t_0 := 0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\ \mathbf{if}\;im \leq -2.9 \cdot 10^{-254}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(-im\right) + re\right)}\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 4 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \mathbf{elif}\;im \leq 420:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]
Alternative 8
Error31.0
Cost6852
\[\begin{array}{l} \mathbf{if}\;im \leq -2 \cdot 10^{-310}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\ \end{array} \]
Alternative 9
Error47.6
Cost6720
\[0.5 \cdot \sqrt{im \cdot -2} \]

Error

Reproduce?

herbie shell --seed 2023092 
(FPCore (re im)
  :name "math.sqrt on complex, real part"
  :precision binary64

  :herbie-target
  (if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))

  (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))