?

Average Error: 38.8 → 23.6
Time: 4.6s
Precision: binary64
Cost: 27016

?

\[0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \]
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ t_2 := 0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ \mathbf{if}\;im \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ \mathbf{elif}\;im \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5 + \frac{{im}^{4}}{{re}^{3}} \cdot 0.125\right)}\\ \mathbf{elif}\;im \leq -4.2 \cdot 10^{-159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.22 \cdot 10^{-202}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{-77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 2.2 \cdot 10^{-59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 0.22:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+112}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
        (t_1 (* 0.5 (sqrt (* 2.0 (+ re im)))))
        (t_2 (* 0.5 (sqrt (* 2.0 (+ re re))))))
   (if (<= im -2.4e+62)
     (* 0.5 (sqrt (* 2.0 (+ (* im -1.0) re))))
     (if (<= im -1.15e+52)
       (*
        0.5
        (sqrt
         (*
          2.0
          (+
           (* (/ (pow im 2.0) re) -0.5)
           (* (/ (pow im 4.0) (pow re 3.0)) 0.125)))))
       (if (<= im -4.2e-159)
         t_0
         (if (<= im 1.22e-202)
           t_2
           (if (<= im 2.6e-77)
             t_0
             (if (<= im 2.2e-59)
               t_2
               (if (<= im 0.22) t_1 (if (<= im 5e+112) t_0 t_1))))))))))
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 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
	double t_1 = 0.5 * sqrt((2.0 * (re + im)));
	double t_2 = 0.5 * sqrt((2.0 * (re + re)));
	double tmp;
	if (im <= -2.4e+62) {
		tmp = 0.5 * sqrt((2.0 * ((im * -1.0) + re)));
	} else if (im <= -1.15e+52) {
		tmp = 0.5 * sqrt((2.0 * (((pow(im, 2.0) / re) * -0.5) + ((pow(im, 4.0) / pow(re, 3.0)) * 0.125))));
	} else if (im <= -4.2e-159) {
		tmp = t_0;
	} else if (im <= 1.22e-202) {
		tmp = t_2;
	} else if (im <= 2.6e-77) {
		tmp = t_0;
	} else if (im <= 2.2e-59) {
		tmp = t_2;
	} else if (im <= 0.22) {
		tmp = t_1;
	} else if (im <= 5e+112) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_2
    real(8) :: tmp
    t_0 = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
    t_1 = 0.5d0 * sqrt((2.0d0 * (re + im)))
    t_2 = 0.5d0 * sqrt((2.0d0 * (re + re)))
    if (im <= (-2.4d+62)) then
        tmp = 0.5d0 * sqrt((2.0d0 * ((im * (-1.0d0)) + re)))
    else if (im <= (-1.15d+52)) then
        tmp = 0.5d0 * sqrt((2.0d0 * ((((im ** 2.0d0) / re) * (-0.5d0)) + (((im ** 4.0d0) / (re ** 3.0d0)) * 0.125d0))))
    else if (im <= (-4.2d-159)) then
        tmp = t_0
    else if (im <= 1.22d-202) then
        tmp = t_2
    else if (im <= 2.6d-77) then
        tmp = t_0
    else if (im <= 2.2d-59) then
        tmp = t_2
    else if (im <= 0.22d0) then
        tmp = t_1
    else if (im <= 5d+112) then
        tmp = t_0
    else
        tmp = t_1
    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 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
	double t_1 = 0.5 * Math.sqrt((2.0 * (re + im)));
	double t_2 = 0.5 * Math.sqrt((2.0 * (re + re)));
	double tmp;
	if (im <= -2.4e+62) {
		tmp = 0.5 * Math.sqrt((2.0 * ((im * -1.0) + re)));
	} else if (im <= -1.15e+52) {
		tmp = 0.5 * Math.sqrt((2.0 * (((Math.pow(im, 2.0) / re) * -0.5) + ((Math.pow(im, 4.0) / Math.pow(re, 3.0)) * 0.125))));
	} else if (im <= -4.2e-159) {
		tmp = t_0;
	} else if (im <= 1.22e-202) {
		tmp = t_2;
	} else if (im <= 2.6e-77) {
		tmp = t_0;
	} else if (im <= 2.2e-59) {
		tmp = t_2;
	} else if (im <= 0.22) {
		tmp = t_1;
	} else if (im <= 5e+112) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
	t_1 = 0.5 * math.sqrt((2.0 * (re + im)))
	t_2 = 0.5 * math.sqrt((2.0 * (re + re)))
	tmp = 0
	if im <= -2.4e+62:
		tmp = 0.5 * math.sqrt((2.0 * ((im * -1.0) + re)))
	elif im <= -1.15e+52:
		tmp = 0.5 * math.sqrt((2.0 * (((math.pow(im, 2.0) / re) * -0.5) + ((math.pow(im, 4.0) / math.pow(re, 3.0)) * 0.125))))
	elif im <= -4.2e-159:
		tmp = t_0
	elif im <= 1.22e-202:
		tmp = t_2
	elif im <= 2.6e-77:
		tmp = t_0
	elif im <= 2.2e-59:
		tmp = t_2
	elif im <= 0.22:
		tmp = t_1
	elif im <= 5e+112:
		tmp = t_0
	else:
		tmp = t_1
	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 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re))))
	t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im))))
	t_2 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + re))))
	tmp = 0.0
	if (im <= -2.4e+62)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im * -1.0) + re))));
	elseif (im <= -1.15e+52)
		tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(Float64((im ^ 2.0) / re) * -0.5) + Float64(Float64((im ^ 4.0) / (re ^ 3.0)) * 0.125)))));
	elseif (im <= -4.2e-159)
		tmp = t_0;
	elseif (im <= 1.22e-202)
		tmp = t_2;
	elseif (im <= 2.6e-77)
		tmp = t_0;
	elseif (im <= 2.2e-59)
		tmp = t_2;
	elseif (im <= 0.22)
		tmp = t_1;
	elseif (im <= 5e+112)
		tmp = t_0;
	else
		tmp = t_1;
	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 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
	t_1 = 0.5 * sqrt((2.0 * (re + im)));
	t_2 = 0.5 * sqrt((2.0 * (re + re)));
	tmp = 0.0;
	if (im <= -2.4e+62)
		tmp = 0.5 * sqrt((2.0 * ((im * -1.0) + re)));
	elseif (im <= -1.15e+52)
		tmp = 0.5 * sqrt((2.0 * ((((im ^ 2.0) / re) * -0.5) + (((im ^ 4.0) / (re ^ 3.0)) * 0.125))));
	elseif (im <= -4.2e-159)
		tmp = t_0;
	elseif (im <= 1.22e-202)
		tmp = t_2;
	elseif (im <= 2.6e-77)
		tmp = t_0;
	elseif (im <= 2.2e-59)
		tmp = t_2;
	elseif (im <= 0.22)
		tmp = t_1;
	elseif (im <= 5e+112)
		tmp = t_0;
	else
		tmp = t_1;
	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[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4e+62], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im * -1.0), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -1.15e+52], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(N[(N[Power[im, 2.0], $MachinePrecision] / re), $MachinePrecision] * -0.5), $MachinePrecision] + N[(N[(N[Power[im, 4.0], $MachinePrecision] / N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -4.2e-159], t$95$0, If[LessEqual[im, 1.22e-202], t$95$2, If[LessEqual[im, 2.6e-77], t$95$0, If[LessEqual[im, 2.2e-59], t$95$2, If[LessEqual[im, 0.22], t$95$1, If[LessEqual[im, 5e+112], t$95$0, t$95$1]]]]]]]]]]]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
t_2 := 0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\
\mathbf{if}\;im \leq -2.4 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\

\mathbf{elif}\;im \leq -1.15 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5 + \frac{{im}^{4}}{{re}^{3}} \cdot 0.125\right)}\\

\mathbf{elif}\;im \leq -4.2 \cdot 10^{-159}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 1.22 \cdot 10^{-202}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;im \leq 2.6 \cdot 10^{-77}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 2.2 \cdot 10^{-59}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;im \leq 0.22:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+112}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.8
Target33.5
Herbie23.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 < -2.4e62

    1. Initial program 47.6

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

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

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

      [Start]12.5

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

      rational.json-simplify-2 [=>]12.5

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

    if -2.4e62 < im < -1.15e52

    1. Initial program 22.1

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

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

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

      [Start]49.1

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

      rational.json-simplify-1 [=>]49.1

      \[ 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(-0.5 \cdot \frac{{im}^{2}}{re} + 0.125 \cdot \frac{{im}^{4}}{{re}^{3}}\right)}} \]

      rational.json-simplify-2 [=>]49.1

      \[ 0.5 \cdot \sqrt{2 \cdot \left(\color{blue}{\frac{{im}^{2}}{re} \cdot -0.5} + 0.125 \cdot \frac{{im}^{4}}{{re}^{3}}\right)} \]

      rational.json-simplify-2 [=>]49.1

      \[ 0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5 + \color{blue}{\frac{{im}^{4}}{{re}^{3}} \cdot 0.125}\right)} \]

    if -1.15e52 < im < -4.1999999999999998e-159 or 1.2200000000000001e-202 < im < 2.6000000000000001e-77 or 0.220000000000000001 < im < 5e112

    1. Initial program 26.3

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

    if -4.1999999999999998e-159 < im < 1.2200000000000001e-202 or 2.6000000000000001e-77 < im < 2.1999999999999999e-59

    1. Initial program 42.6

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

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

    if 2.1999999999999999e-59 < im < 0.220000000000000001 or 5e112 < im

    1. Initial program 48.4

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

      \[\leadsto 0.5 \cdot \sqrt{2 \cdot \color{blue}{\left(re + im\right)}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification23.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ \mathbf{elif}\;im \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5 + \frac{{im}^{4}}{{re}^{3}} \cdot 0.125\right)}\\ \mathbf{elif}\;im \leq -4.2 \cdot 10^{-159}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{elif}\;im \leq 1.22 \cdot 10^{-202}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{-77}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{elif}\;im \leq 2.2 \cdot 10^{-59}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ \mathbf{elif}\;im \leq 0.22:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+112}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error23.9
Cost14688
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ t_2 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\ \mathbf{if}\;im \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ \mathbf{elif}\;im \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5\right)}\\ \mathbf{elif}\;im \leq -4.4 \cdot 10^{-121}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 3.1 \cdot 10^{-202}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 2.8 \cdot 10^{-77}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 6.2 \cdot 10^{-60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 0.19:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 2.8 \cdot 10^{+120}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error26.2
Cost14044
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ t_2 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{if}\;im \leq -2.4 \cdot 10^{+62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{{im}^{2}}{re} \cdot -0.5\right)}\\ \mathbf{elif}\;im \leq -1.25 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 3.3 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 2.9 \cdot 10^{-79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 1.95 \cdot 10^{-60}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.85 \cdot 10^{-39}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error25.9
Cost13780
\[\begin{array}{l} t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ t_1 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \mathbf{if}\;im \leq -2.75 \cdot 10^{-111}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ \mathbf{elif}\;im \leq 3.45 \cdot 10^{-193}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 2.8 \cdot 10^{-77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 5.2 \cdot 10^{-60}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.85 \cdot 10^{-39}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error25.8
Cost7112
\[\begin{array}{l} \mathbf{if}\;im \leq -4.4 \cdot 10^{-114}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot -1 + re\right)}\\ \mathbf{elif}\;im \leq 2.95 \cdot 10^{-193}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]
Alternative 5
Error36.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;im \leq 3.6 \cdot 10^{-193}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\ \end{array} \]
Alternative 6
Error44.8
Cost6848
\[0.5 \cdot \sqrt{2 \cdot \left(re + im\right)} \]

Error

Reproduce?

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